7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2010 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_pdf_listWidgetContainer.php 2883 2010-02-28 14:54:34Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
18 class admin_pdf_listWidgetContainer extends BaseAdminWidgetContainer
20 private $sysDb; // DB接続オブジェクト
21 private $serialNo; // 選択中の項目のシリアル番号
22 private $serialArray = array(); // 表示中のシリアル番号
24 private $configId; // 定義ID
25 private $paramObj; // パラメータ保存用オブジェクト
26 private $fieldInfoArray = array(); // お問い合わせ項目情報
27 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
28 const DEFAULT_TITLE_NAME = 'お問い合わせ'; // デフォルトのタイトル名
33 function __construct()
36 parent::__construct();
39 $this->sysDb = $this->gInstance->getSytemDbObject();
44 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
45 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
47 * @param RequestManager $request HTTPリクエスト処理クラス
48 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
49 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
51 function _setTemplate($request, &$param)
53 $task = $request->trimValueOf('task');
54 if ($task == 'list'){ // 一覧画面
55 return 'admin_list.tmpl.html';
57 return 'admin.tmpl.html';
63 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
65 * @param RequestManager $request HTTPリクエスト処理クラス
66 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
69 function _assign($request, &$param)
71 $task = $request->trimValueOf('task');
72 if ($task == 'list'){ // 一覧画面
73 return $this->createList($request);
75 return $this->createDetail($request);
81 * @param RequestManager $request HTTPリクエスト処理クラス
84 function createDetail($request)
86 // ページ定義IDとページ定義のレコードシリアル番号を取得
87 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
89 $userId = $this->gEnv->getCurrentUserId();
90 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
91 $act = $request->trimValueOf('act');
92 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
93 $this->configId = $request->trimValueOf('item_id'); // 定義ID
94 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
97 $defName = $request->trimValueOf('item_def_name'); // 定義名
98 $fieldCount = $request->trimValueOf('fieldcount'); // 表示項目数
99 $names = $request->trimValueOf('item_name'); // 表示項目、名前
100 $addresses = $request->trimValueOf('item_address'); // 表示項目、住所
101 $phones = $request->trimValueOf('item_phone'); // 表示項目、電話番号
103 $replaceNew = false; // データを再取得するかどうか
104 if ($act == 'add'){// 新規追加
108 for ($i = 0; $i < count($this->paramObj); $i++){
109 $targetObj = $this->paramObj[$i]->object;
110 if ($defName == $targetObj->name){ // 定義名
111 $this->setUserErrorMsg('名前が重複しています');
117 if ($this->getMsgCount() == 0){
119 $newObj = new stdClass;
120 $newObj->name = $defName;// 表示名
121 $newObj->fieldInfo = array();
123 for ($i = 0; $i < $fieldCount; $i++){
124 $newInfoObj = new stdClass;
125 $newInfoObj->name = $names[$i];
126 $newInfoObj->address = $addresses[$i];
127 $newInfoObj->phone = $phones[$i];
128 $newObj->fieldInfo[] = $newInfoObj;
131 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
133 $this->setGuidanceMsg('データを追加しました');
135 $this->configId = $defConfigId; // 定義定義IDを更新
136 $replaceNew = true; // データ再取得
138 $this->setAppErrorMsg('データ追加に失敗しました');
141 } else if ($act == 'update'){ // 設定更新のとき
144 if ($this->getMsgCount() == 0){ // エラーのないとき
146 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
149 $targetObj->fieldInfo = array();
151 for ($i = 0; $i < $fieldCount; $i++){
152 $newInfoObj = new stdClass;
153 $newInfoObj->name = $names[$i];
154 $newInfoObj->address = $addresses[$i];
155 $newInfoObj->phone = $phones[$i];
156 $targetObj->fieldInfo[] = $newInfoObj;
161 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
163 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
164 $replaceNew = true; // データ再取得
166 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
169 } else if ($act == 'select'){ // 定義IDを変更
170 $replaceNew = true; // データ再取得
171 } else { // 初期起動時、または上記以外の場合
173 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
174 $replaceNew = true; // データ再取得
177 $this->createItemMenu();
180 if (empty($this->configId)){ // 新規登録の場合
181 $this->tmpl->setAttribute('item_def_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
182 if ($replaceNew){ // データ再取得時
183 $defName = $this->createDefaultName(); // デフォルト登録項目名
184 $this->fieldInfoArray = array(); // お問い合わせ項目情報
188 if ($replaceNew){// データ再取得時
189 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
191 $defName = $targetObj->name;// 名前
192 if (!empty($targetObj->fieldInfo)) $this->fieldInfoArray = $targetObj->fieldInfo; // お問い合わせ項目情報
195 $this->serialNo = $this->configId;
197 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
198 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
202 $this->createFieldList();
203 if (empty($this->fieldInfoArray)) $this->tmpl->setAttribute('field_list', 'visibility', 'hidden');// 表示項目一覧を表示
206 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId); // 定義ID
207 $this->tmpl->addVar("item_def_name_visible", "def_name", $defName);
208 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
211 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
212 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
215 $this->tmpl->addVar("_widget", "preview_disabled", 'disabled ');// 「プレビュー」ボタン
217 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
219 // このウィジェットがマップされているページサブIDを取得
220 $subPageId = $this->gPage->getPageSubIdByWidget($this->gEnv->getDefaultPageId(), $this->gEnv->getCurrentWidgetId(), $defConfigId);
221 $previewUrl = $this->gEnv->getDefaultUrl();
222 if (!empty($subPageId)) $previewUrl .= '?sub=' . $subPageId;
223 $this->tmpl->addVar("_widget", "preview_url", $this->getUrl($previewUrl));
226 $this->convertHelp('update_button');
229 // ページ定義IDとページ定義のレコードシリアル番号を更新
230 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
237 function createItemMenu()
239 for ($i = 0; $i < count($this->paramObj); $i++){
240 $id = $this->paramObj[$i]->id;// 定義ID
241 $targetObj = $this->paramObj[$i]->object;
242 $defName = $targetObj->name;// 定義名
244 if ($this->configId == $id) $selected = 'selected';
247 'name' => $defName, // 名前
248 'value' => $id, // 定義ID
249 'selected' => $selected // 選択中の項目かどうか
251 $this->tmpl->addVars('title_list', $row);
252 $this->tmpl->parseTemplate('title_list', 'a');
260 function createFieldList()
262 $fieldCount = count($this->fieldInfoArray);
263 for ($i = 0; $i < $fieldCount; $i++){
264 $infoObj = $this->fieldInfoArray[$i];
265 $name = $infoObj->name;// 名前
266 $address = $infoObj->address; // 住所
267 $phone = $infoObj->phone; // 電話番号
270 'name' => $this->convertToDispString($name), // 名前
271 'address' => $this->convertToDispString($address), // 住所
272 'phone' => $this->convertToDispString($phone), // 電話番号
273 'root_url' => $this->convertToDispString($this->getUrl($this->gEnv->getRootUrl()))
275 $this->tmpl->addVars('field_list', $row);
276 $this->tmpl->parseTemplate('field_list', 'a');
282 * @return string デフォルト名
284 function createDefaultName()
286 $name = self::DEFAULT_NAME_HEAD;
287 for ($j = 1; $j < 100; $j++){
288 $name = self::DEFAULT_NAME_HEAD . $j;
290 for ($i = 0; $i < count($this->paramObj); $i++){
291 $targetObj = $this->paramObj[$i]->object;
292 if ($name == $targetObj->name){ // 定義名
297 if ($i == count($this->paramObj)) break;
304 * @param RequestManager $request HTTPリクエスト処理クラス
307 function createList($request)
309 // ページ定義IDとページ定義のレコードシリアル番号を取得
310 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
312 $userId = $this->gEnv->getCurrentUserId();
313 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
314 $act = $request->trimValueOf('act');
316 if ($act == 'delete'){ // メニュー項目の削除
317 $listedItem = explode(',', $request->trimValueOf('seriallist'));
319 for ($i = 0; $i < count($listedItem); $i++){
321 $itemName = 'item' . $i . '_selected';
322 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
324 if ($itemValue){ // チェック項目
325 $delItems[] = $listedItem[$i];
328 if (count($delItems) > 0){
329 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
330 if ($ret){ // データ削除成功のとき
331 $this->setGuidanceMsg('データを削除しました');
333 $this->setAppErrorMsg('データ削除に失敗しました');
338 $this->createItemList();
340 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
342 // ページ定義IDとページ定義のレコードシリアル番号を更新
343 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
350 function createItemList()
352 for ($i = 0; $i < count($this->paramObj); $i++){
353 $id = $this->paramObj[$i]->id;// 定義ID
354 $targetObj = $this->paramObj[$i]->object;
355 $defName = $targetObj->name;// 定義名
360 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
362 $operationDisagled = '';
363 if ($defCount > 0) $operationDisagled = 'disabled';
368 'ope_disabled' => $operationDisagled, // 選択可能かどうか
369 'name' => $this->convertToDispString($defName), // 名前
370 'def_count' => $defCount // 使用数
372 $this->tmpl->addVars('itemlist', $row);
373 $this->tmpl->parseTemplate('itemlist', 'a');
376 $this->serialArray[] = $id;