OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / effect_nicejforms / include / container / admin_effect_nicejformsWidgetContainer.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-2009 Magic3 Project.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: admin_effect_nicejformsWidgetContainer.php 2266 2009-08-28 08:25:59Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17
18 class admin_effect_nicejformsWidgetContainer 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 $colorType;                     // カラータイプ
27         private $colorTypeDef;          // カラータイプ選択用メニュー定義
28         const DEFAULT_NAME_HEAD = '名称未設定';                    // デフォルトの設定名
29         const DEFAULT_COLOR_TYPE = '0';
30         
31         /**
32          * コンストラクタ
33          */
34         function __construct()
35         {
36                 // 親クラスを呼び出す
37                 parent::__construct();
38                 
39                 // DBオブジェクト作成
40                 $this->sysDb = $this->gInstance->getSytemDbObject();
41                 
42                 // カラータイプ選択用メニュー定義
43                 $this->colorTypeDef = array(    array(  'name' => '青',                'value' => '0',         'filename' => 'niceforms-default.css',  'image_dir' => 'default'),
44                                                                                 array(  'name' => '緑',                'value' => '1',         'filename' => 'niceforms-green.css',    'image_dir' => 'greentheme'),
45                                                                                 array(  'name' => '赤',                'value' => '2',         'filename' => 'niceforms-red.css',              'image_dir' => 'redtheme'));
46         }
47         /**
48          * テンプレートファイルを設定
49          *
50          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
51          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
52          *
53          * @param RequestManager $request               HTTPリクエスト処理クラス
54          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
55          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
56          */
57         function _setTemplate($request, &$param)
58         {
59                 $task = $request->trimValueOf('task');
60                 if ($task == 'list'){           // 一覧画面
61                         return 'admin_list.tmpl.html';
62                 } else {                        // 一覧画面
63                         return 'admin.tmpl.html';
64                 }
65         }
66         /**
67          * テンプレートにデータ埋め込む
68          *
69          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
70          *
71          * @param RequestManager $request               HTTPリクエスト処理クラス
72          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
73          * @param                                                               なし
74          */
75         function _assign($request, &$param)
76         {
77                 $task = $request->trimValueOf('task');
78                 if ($task == 'list'){           // 一覧画面
79                         return $this->createList($request);
80                 } else {                        // 詳細設定画面
81                         return $this->createDetail($request);
82                 }
83         }
84         /**
85          * 詳細画面作成
86          *
87          * @param RequestManager $request               HTTPリクエスト処理クラス
88          * @param                                                               なし
89          */
90         function createDetail($request)
91         {
92                 // ページ定義IDとページ定義のレコードシリアル番号を取得
93                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
94                 
95                 $userId         = $this->gEnv->getCurrentUserId();
96                 $this->langId   = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
97                 $act = $request->trimValueOf('act');
98                 $this->serialNo = $request->trimValueOf('serial');              // 選択項目のシリアル番号
99                 $this->configId = $request->trimValueOf('item_id');             // 定義ID
100                 if (empty($this->configId)) $this->configId = $defConfigId;             // 呼び出しウィンドウから引き継いだ定義ID
101                 
102                 // 入力値を取得
103                 $name   = $request->trimValueOf('item_name');                   // 定義名
104                 $this->colorType        = $request->trimValueOf('item_color_type');             // カラータイプ
105                 
106                 $replaceNew = false;            // データを再取得するかどうか
107                 if ($act == 'add'){// 新規追加
108                         // 入力チェック
109                         $this->checkInput($name, '名前');
110                         
111                         // 設定名の重複チェック
112                         for ($i = 0; $i < count($this->paramObj); $i++){
113                                 $targetObj = $this->paramObj[$i]->object;
114                                 if ($name == $targetObj->name){         // 定義名
115                                         $this->setUserErrorMsg('名前が重複しています');
116                                         break;
117                                 }
118                         }
119                         
120                         // エラーなしの場合は、データを登録
121                         if ($this->getMsgCount() == 0){
122                                 // 追加オブジェクト作成
123                                 $newObj = new stdClass;
124                                 $newObj->name   = $name;// 表示名
125                                 $newObj->colorType      = $this->colorType;                                     // カラータイプ
126                                 
127                                 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
128                                 if ($ret){
129                                         $this->setGuidanceMsg('データを追加しました');
130                                         
131                                         $this->configId = $defConfigId;         // 定義定義IDを更新
132                                         $replaceNew = true;                     // データ再取得
133                                 } else {
134                                         $this->setAppErrorMsg('データ追加に失敗しました');
135                                 }
136                         }
137                 } else if ($act == 'update'){           // 設定更新のとき
138                         // 入力値のエラーチェック
139                         
140                         if ($this->getMsgCount() == 0){                 // エラーのないとき
141                                 // 現在の設定値を取得
142                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
143                                 if ($ret){
144                                         // ウィジェットオブジェクト更新
145                                         $targetObj->colorType           = $this->colorType;                                     // カラータイプ
146                                 }
147                                 
148                                 // 設定値を更新
149                                 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
150                                 if ($ret){
151                                         $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
152                                         $replaceNew = true;                     // データ再取得
153                                 } else {
154                                         $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
155                                 }
156                         }
157                 } else if ($act == 'select'){   // 定義IDを変更
158                         $replaceNew = true;                     // データ再取得
159                 } else {        // 初期起動時、または上記以外の場合
160                         // デフォルト値設定
161                         $this->configId = $defConfigId;         // 呼び出しウィンドウから引き継いだ定義ID
162                         $replaceNew = true;                     // データ再取得
163                 }
164                 // 設定項目選択メニュー作成
165                 $this->createItemMenu();
166                 
167                 // 表示用データを取得
168                 if (empty($this->configId)){            // 新規登録の場合
169                         $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
170                         if ($replaceNew){               // データ再取得時
171                                 $name = $this->createDefaultName();                     // デフォルト登録項目名
172                                 $this->colorType                = self::DEFAULT_COLOR_TYPE;                                     // カラータイプ
173                         }
174                         $this->serialNo = 0;
175                 } else {
176                         if ($replaceNew){// データ再取得時
177                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
178                                 if ($ret){
179                                         $name           = $targetObj->name;     // 名前
180                                         $this->colorType        = $targetObj->colorType;        // カラータイプ
181                                 }
182                         }
183                         $this->serialNo = $this->configId;
184                                 
185                         // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
186                         if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
187                 }
188                 
189                 // カラー選択メニュー作成
190                 $this->createColorTypeMenu();
191                 
192                 // 画面にデータを埋め込む
193                 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId);             // 定義ID
194                 $this->tmpl->addVar("item_name_visible", "name",        $name);
195                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
196                 
197                 // ボタンの表示制御
198                 if (empty($this->serialNo)){            // 新規追加項目を選択しているとき
199                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
200                 } else {
201                         $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
202                         
203                         // ヘルプの追加
204                         $this->convertHelp('update_button');
205                 }
206                 
207                 // ページ定義IDとページ定義のレコードシリアル番号を更新
208                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
209         }
210         /**
211          * 選択用メニューを作成
212          *
213          * @return なし                                               
214          */
215         function createItemMenu()
216         {
217                 for ($i = 0; $i < count($this->paramObj); $i++){
218                         $id = $this->paramObj[$i]->id;// 定義ID
219                         $targetObj = $this->paramObj[$i]->object;
220                         $name = $targetObj->name;// 定義名
221                         $selected = '';
222                         if ($this->configId == $id) $selected = 'selected';
223
224                         $row = array(
225                                 'name' => $name,                // 名前
226                                 'value' => $id,         // 定義ID
227                                 'selected' => $selected // 選択中の項目かどうか
228                         );
229                         $this->tmpl->addVars('title_list', $row);
230                         $this->tmpl->parseTemplate('title_list', 'a');
231                 }
232         }
233         /**
234          * デフォルトの名前を取得
235          *
236          * @return string       デフォルト名                                              
237          */
238         function createDefaultName()
239         {
240                 $name = self::DEFAULT_NAME_HEAD;
241                 for ($j = 1; $j < 100; $j++){
242                         $name = self::DEFAULT_NAME_HEAD . $j;
243                         // 設定名の重複チェック
244                         for ($i = 0; $i < count($this->paramObj); $i++){
245                                 $targetObj = $this->paramObj[$i]->object;
246                                 if ($name == $targetObj->name){         // 定義名
247                                         break;
248                                 }
249                         }
250                         // 重複なしのときは終了
251                         if ($i == count($this->paramObj)) break;
252                 }
253                 return $name;
254         }
255         /**
256          * 一覧画面作成
257          *
258          * @param RequestManager $request               HTTPリクエスト処理クラス
259          * @param                                                               なし
260          */
261         function createList($request)
262         {
263                 // ページ定義IDとページ定義のレコードシリアル番号を取得
264                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
265                 
266                 $userId         = $this->gEnv->getCurrentUserId();
267                 $langId = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
268                 $act = $request->trimValueOf('act');
269                 
270                 if ($act == 'delete'){          // メニュー項目の削除
271                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
272                         $delItems = array();
273                         for ($i = 0; $i < count($listedItem); $i++){
274                                 // 項目がチェックされているかを取得
275                                 $itemName = 'item' . $i . '_selected';
276                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
277                                 
278                                 if ($itemValue){                // チェック項目
279                                         $delItems[] = $listedItem[$i];
280                                 }
281                         }
282                         if (count($delItems) > 0){
283                                 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
284                                 if ($ret){              // データ削除成功のとき
285                                         $this->setGuidanceMsg('データを削除しました');
286                                 } else {
287                                         $this->setAppErrorMsg('データ削除に失敗しました');
288                                 }
289                         }
290                 }
291                 // 定義一覧作成
292                 $this->createItemList();
293                 
294                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
295                 
296                 // ページ定義IDとページ定義のレコードシリアル番号を更新
297                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
298         }
299         /**
300          * 定義一覧作成
301          *
302          * @return なし                                               
303          */
304         function createItemList()
305         {
306                 for ($i = 0; $i < count($this->paramObj); $i++){
307                         $id                     = $this->paramObj[$i]->id;// 定義ID
308                         $targetObj      = $this->paramObj[$i]->object;
309                         $name = $targetObj->name;// 定義名
310                 
311                         // 使用数
312                         $defCount = 0;
313                         if (!empty($id)){
314                                 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
315                         }
316                         $operationDisagled = '';
317                         if ($defCount > 0) $operationDisagled = 'disabled';
318                         
319                         $row = array(
320                                 'index' => $i,
321                                 'id' => $id,
322                                 'ope_disabled' => $operationDisagled,                   // 選択可能かどうか
323                                 'name' => $this->convertToDispString($name),            // 名前
324                                 'def_count' => $defCount                                                        // 使用数
325                         );
326                         $this->tmpl->addVars('itemlist', $row);
327                         $this->tmpl->parseTemplate('itemlist', 'a');
328                         
329                         // シリアル番号を保存
330                         $this->serialArray[] = $id;
331                 }
332         }
333         /**
334          * カラー選択メニュー作成
335          *
336          * @return なし
337          */
338         function createColorTypeMenu()
339         {
340                 for ($i = 0; $i < count($this->colorTypeDef); $i++){
341                         $value = $this->colorTypeDef[$i]['value'];
342                         $name = $this->colorTypeDef[$i]['name'];
343                         
344                         $selected = '';
345                         if ($value == $this->colorType) $selected = 'selected';
346                         
347                         $row = array(
348                                 'value'    => $value,                   // 値
349                                 'name'     => $name,                    // 名前
350                                 'selected' => $selected                                                                                                         // 選択中かどうか
351                         );
352                         $this->tmpl->addVars('color_type_list', $row);
353                         $this->tmpl->parseTemplate('color_type_list', 'a');
354                 }
355         }
356 }
357 ?>