OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / pdf_list / include / container / admin_pdf_listWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
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
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17
18 class admin_pdf_listWidgetContainer extends BaseAdminWidgetContainer
19 {
20         private $sysDb; // DB接続オブジェクト
21         private $serialNo;              // 選択中の項目のシリアル番号
22         private $serialArray = array();                 // 表示中のシリアル番号
23         private $langId;
24         private $configId;              // 定義ID
25         private $paramObj;              // パラメータ保存用オブジェクト
26         private $fieldInfoArray = array();                      // お問い合わせ項目情報
27         const DEFAULT_NAME_HEAD = '名称未設定';                    // デフォルトの設定名
28         const DEFAULT_TITLE_NAME = 'お問い合わせ';        // デフォルトのタイトル名
29         
30         /**
31          * コンストラクタ
32          */
33         function __construct()
34         {
35                 // 親クラスを呼び出す
36                 parent::__construct();
37                 
38                 // DBオブジェクト作成
39                 $this->sysDb = $this->gInstance->getSytemDbObject();
40         }
41         /**
42          * テンプレートファイルを設定
43          *
44          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
45          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
46          *
47          * @param RequestManager $request               HTTPリクエスト処理クラス
48          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
49          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
50          */
51         function _setTemplate($request, &$param)
52         {
53                 $task = $request->trimValueOf('task');
54                 if ($task == 'list'){           // 一覧画面
55                         return 'admin_list.tmpl.html';
56                 } else {                        // 一覧画面
57                         return 'admin.tmpl.html';
58                 }
59         }
60         /**
61          * テンプレートにデータ埋め込む
62          *
63          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
64          *
65          * @param RequestManager $request               HTTPリクエスト処理クラス
66          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
67          * @param                                                               なし
68          */
69         function _assign($request, &$param)
70         {
71                 $task = $request->trimValueOf('task');
72                 if ($task == 'list'){           // 一覧画面
73                         return $this->createList($request);
74                 } else {                        // 詳細設定画面
75                         return $this->createDetail($request);
76                 }
77         }
78         /**
79          * 詳細画面作成
80          *
81          * @param RequestManager $request               HTTPリクエスト処理クラス
82          * @param                                                               なし
83          */
84         function createDetail($request)
85         {
86                 // ページ定義IDとページ定義のレコードシリアル番号を取得
87                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
88                 
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
95                 
96                 // 入力値を取得
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');          // 表示項目、電話番号
102                 
103                 $replaceNew = false;            // データを再取得するかどうか
104                 if ($act == 'add'){// 新規追加
105                         // 入力値のエラーチェック
106                         
107                         // 設定名の重複チェック
108                         for ($i = 0; $i < count($this->paramObj); $i++){
109                                 $targetObj = $this->paramObj[$i]->object;
110                                 if ($defName == $targetObj->name){              // 定義名
111                                         $this->setUserErrorMsg('名前が重複しています');
112                                         break;
113                                 }
114                         }
115                         
116                         // エラーなしの場合は、データを登録
117                         if ($this->getMsgCount() == 0){
118                                 // 追加オブジェクト作成
119                                 $newObj = new stdClass;
120                                 $newObj->name           = $defName;// 表示名
121                                 $newObj->fieldInfo      = array();
122                                 
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;
129                                 }
130                                 
131                                 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
132                                 if ($ret){
133                                         $this->setGuidanceMsg('データを追加しました');
134                                         
135                                         $this->configId = $defConfigId;         // 定義定義IDを更新
136                                         $replaceNew = true;                     // データ再取得
137                                 } else {
138                                         $this->setAppErrorMsg('データ追加に失敗しました');
139                                 }
140                         }
141                 } else if ($act == 'update'){           // 設定更新のとき
142                         // 入力値のエラーチェック
143                         
144                         if ($this->getMsgCount() == 0){                 // エラーのないとき
145                                 // 現在の設定値を取得
146                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
147                                 if ($ret){
148                                         // ウィジェットオブジェクト更新
149                                         $targetObj->fieldInfo   = array();
150                                 
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;
157                                         }
158                                 }
159                                 
160                                 // 設定値を更新
161                                 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
162                                 if ($ret){
163                                         $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
164                                         $replaceNew = true;                     // データ再取得
165                                 } else {
166                                         $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
167                                 }
168                         }
169                 } else if ($act == 'select'){   // 定義IDを変更
170                         $replaceNew = true;                     // データ再取得
171                 } else {        // 初期起動時、または上記以外の場合
172                         // デフォルト値設定
173                         $this->configId = $defConfigId;         // 呼び出しウィンドウから引き継いだ定義ID
174                         $replaceNew = true;                     // データ再取得
175                 }
176                 // 設定項目選択メニュー作成
177                 $this->createItemMenu();
178                                 
179                 // 表示用データを取得
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();                        // お問い合わせ項目情報
185                         }
186                         $this->serialNo = 0;
187                 } else {
188                         if ($replaceNew){// データ再取得時
189                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
190                                 if ($ret){
191                                         $defName        = $targetObj->name;// 名前
192                                         if (!empty($targetObj->fieldInfo)) $this->fieldInfoArray = $targetObj->fieldInfo;                       // お問い合わせ項目情報
193                                 }
194                         }
195                         $this->serialNo = $this->configId;
196                                 
197                         // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
198                         if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
199                 }
200                 
201                 // 表示項目一覧作成
202                 $this->createFieldList();
203                 if (empty($this->fieldInfoArray)) $this->tmpl->setAttribute('field_list', 'visibility', 'hidden');// 表示項目一覧を表示
204                 
205                 // 画面にデータを埋め込む
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を設定
209                 
210                 // ボタンの表示制御
211                 if (empty($this->serialNo)){            // 新規追加項目を選択しているとき
212                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
213                         
214                         // プレビューボタン作成
215                         $this->tmpl->addVar("_widget", "preview_disabled", 'disabled ');// 「プレビュー」ボタン
216                 } else {
217                         $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
218                         
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));
224                         
225                         // ヘルプの追加
226                         $this->convertHelp('update_button');
227                 }
228                 
229                 // ページ定義IDとページ定義のレコードシリアル番号を更新
230                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
231         }
232         /**
233          * 選択用メニューを作成
234          *
235          * @return なし                                               
236          */
237         function createItemMenu()
238         {
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;// 定義名
243                         $selected = '';
244                         if ($this->configId == $id) $selected = 'selected';
245
246                         $row = array(
247                                 'name' => $defName,             // 名前
248                                 'value' => $id,         // 定義ID
249                                 'selected' => $selected // 選択中の項目かどうか
250                         );
251                         $this->tmpl->addVars('title_list', $row);
252                         $this->tmpl->parseTemplate('title_list', 'a');
253                 }
254         }
255         /**
256          * 表示項目一覧を作成
257          *
258          * @return なし                                               
259          */
260         function createFieldList()
261         {
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;               // 電話番号
268                         
269                         $row = array(
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()))
274                         );
275                         $this->tmpl->addVars('field_list', $row);
276                         $this->tmpl->parseTemplate('field_list', 'a');
277                 }
278         }
279         /**
280          * デフォルトの名前を取得
281          *
282          * @return string       デフォルト名                                              
283          */
284         function createDefaultName()
285         {
286                 $name = self::DEFAULT_NAME_HEAD;
287                 for ($j = 1; $j < 100; $j++){
288                         $name = self::DEFAULT_NAME_HEAD . $j;
289                         // 設定名の重複チェック
290                         for ($i = 0; $i < count($this->paramObj); $i++){
291                                 $targetObj = $this->paramObj[$i]->object;
292                                 if ($name == $targetObj->name){         // 定義名
293                                         break;
294                                 }
295                         }
296                         // 重複なしのときは終了
297                         if ($i == count($this->paramObj)) break;
298                 }
299                 return $name;
300         }
301         /**
302          * 一覧画面作成
303          *
304          * @param RequestManager $request               HTTPリクエスト処理クラス
305          * @param                                                               なし
306          */
307         function createList($request)
308         {
309                 // ページ定義IDとページ定義のレコードシリアル番号を取得
310                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
311                 
312                 $userId         = $this->gEnv->getCurrentUserId();
313                 $langId = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
314                 $act = $request->trimValueOf('act');
315                 
316                 if ($act == 'delete'){          // メニュー項目の削除
317                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
318                         $delItems = array();
319                         for ($i = 0; $i < count($listedItem); $i++){
320                                 // 項目がチェックされているかを取得
321                                 $itemName = 'item' . $i . '_selected';
322                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
323                                 
324                                 if ($itemValue){                // チェック項目
325                                         $delItems[] = $listedItem[$i];
326                                 }
327                         }
328                         if (count($delItems) > 0){
329                                 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
330                                 if ($ret){              // データ削除成功のとき
331                                         $this->setGuidanceMsg('データを削除しました');
332                                 } else {
333                                         $this->setAppErrorMsg('データ削除に失敗しました');
334                                 }
335                         }
336                 }
337                 // 定義一覧作成
338                 $this->createItemList();
339                 
340                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
341                 
342                 // ページ定義IDとページ定義のレコードシリアル番号を更新
343                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
344         }
345         /**
346          * 定義一覧作成
347          *
348          * @return なし                                               
349          */
350         function createItemList()
351         {
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;// 定義名
356                 
357                         // 使用数
358                         $defCount = 0;
359                         if (!empty($id)){
360                                 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
361                         }
362                         $operationDisagled = '';
363                         if ($defCount > 0) $operationDisagled = 'disabled';
364                         
365                         $row = array(
366                                 'index' => $i,
367                                 'id' => $id,
368                                 'ope_disabled' => $operationDisagled,                   // 選択可能かどうか
369                                 'name' => $this->convertToDispString($defName),         // 名前
370                                 'def_count' => $defCount                                                        // 使用数
371                         );
372                         $this->tmpl->addVars('itemlist', $row);
373                         $this->tmpl->parseTemplate('itemlist', 'a');
374                         
375                         // シリアル番号を保存
376                         $this->serialArray[] = $id;
377                 }
378         }
379 }
380 ?>