OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / m / contactus_custom / include / container / admin_m_contactus_customWidgetContainer.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_m_contactus_customWidgetContainer.php 2307 2009-09-13 04:03:00Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/contactus_customDb.php');
18
19 class admin_m_contactus_customWidgetContainer extends BaseAdminWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $sysDb; // DB接続オブジェクト
23         private $serialNo;              // 選択中の項目のシリアル番号
24         private $serialArray = array();                 // 表示中のシリアル番号
25         private $langId;
26         private $configId;              // 定義ID
27         private $paramObj;              // パラメータ保存用オブジェクト
28         private $typeArray;             // 項目タイプ
29         private $fieldInfoArray = array();                      // お問い合わせ項目情報
30         const DEFAULT_NAME_HEAD = '名称未設定';                    // デフォルトの設定名
31         const DEFAULT_TITLE_NAME = 'お問い合わせ';        // デフォルトのタイトル名
32         
33         /**
34          * コンストラクタ
35          */
36         function __construct()
37         {
38                 // 親クラスを呼び出す
39                 parent::__construct();
40                 
41                 // DBオブジェクト作成
42                 $this->db = new contactus_customDb();
43                 $this->sysDb = $this->gInstance->getSytemDbObject();
44                 
45                 // お問い合わせ項目タイプ
46                 $this->typeArray = array(       array(  'name' => 'テキストボックス',   'value' => 'text'),
47                                                                         array(  'name' => 'テキストエリア',              'value' => 'textarea'),
48                                                                         array(  'name' => 'セレクトメニュー',   'value' => 'select'),
49                                                                         array(  'name' => 'チェックボックス',   'value' => 'checkbox'),
50                                                                         array(  'name' => 'ラジオボタン',         'value' => 'radio'));
51         }
52         /**
53          * テンプレートファイルを設定
54          *
55          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
56          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
57          *
58          * @param RequestManager $request               HTTPリクエスト処理クラス
59          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
60          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
61          */
62         function _setTemplate($request, &$param)
63         {
64                 $task = $request->trimValueOf('task');
65                 if ($task == 'list'){           // 一覧画面
66                         return 'admin_list.tmpl.html';
67                 } else {                        // 一覧画面
68                         return 'admin.tmpl.html';
69                 }
70         }
71         /**
72          * テンプレートにデータ埋め込む
73          *
74          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
75          *
76          * @param RequestManager $request               HTTPリクエスト処理クラス
77          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
78          * @param                                                               なし
79          */
80         function _assign($request, &$param)
81         {
82                 $task = $request->trimValueOf('task');
83                 if ($task == 'list'){           // 一覧画面
84                         return $this->createList($request);
85                 } else {                        // 詳細設定画面
86                         return $this->createDetail($request);
87                 }
88         }
89         /**
90          * 詳細画面作成
91          *
92          * @param RequestManager $request               HTTPリクエスト処理クラス
93          * @param                                                               なし
94          */
95         function createDetail($request)
96         {
97                 // ページ定義IDとページ定義のレコードシリアル番号を取得
98                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
99                 
100                 $userId         = $this->gEnv->getCurrentUserId();
101                 $this->langId   = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
102                 $act = $request->trimValueOf('act');
103                 $this->serialNo = $request->trimValueOf('serial');              // 選択項目のシリアル番号
104                 $this->configId = $request->trimValueOf('item_id');             // 定義ID
105                 if (empty($this->configId)) $this->configId = $defConfigId;             // 呼び出しウィンドウから引き継いだ定義ID
106                 
107                 // 入力値を取得
108                 $name   = $request->trimValueOf('item_name');                   // 定義名
109                 $showTitle = ($request->trimValueOf('show_title') == 'on') ? 1 : 0;             // タイトルの表示
110                 $titleName = $request->trimValueOf('title_name');                               // タイトル名
111                 $titleBgColor = $request->trimValueOf('item_title_bgcolor');            // タイトルバックグランドカラー
112                 $explanation = trim($request->valueOf('explanation'));                          // 説明
113                 $fieldCount = $request->trimValueOf('fieldcount');              // お問い合わせ項目数
114                 $titles = $request->trimValueOf('item_title');          // お問い合わせ項目タイトル
115                 $descs = $request->trimValueOf('item_desc');            // お問い合わせ項目説明
116                 $types  = $request->trimValueOf('item_type');           // お問い合わせ項目タイプ
117                 $defs = $request->trimValueOf('item_def');              // お問い合わせ項目定義
118                 $values = $request->trimValueOf('required');            // お問い合わせ項目必須入力
119                 $requireds = array();
120                 if (!empty($values)) $requireds = explode(',', $values);
121                 $emailSubject = $request->trimValueOf('email_subject');         // メールタイトル
122                 $emailReceiver = trim($request->valueOf('email_receiver'));     // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
123                 
124                 $replaceNew = false;            // データを再取得するかどうか
125                 if ($act == 'add'){// 新規追加
126                         // 入力値のエラーチェック
127                         
128                         // 設定名の重複チェック
129                         for ($i = 0; $i < count($this->paramObj); $i++){
130                                 $targetObj = $this->paramObj[$i]->object;
131                                 if ($name == $targetObj->name){         // 定義名
132                                         $this->setUserErrorMsg('名前が重複しています');
133                                         break;
134                                 }
135                         }
136                         
137                         // エラーなしの場合は、データを登録
138                         if ($this->getMsgCount() == 0){
139                                 // 追加オブジェクト作成
140                                 $newObj = new stdClass;
141                                 $newObj->name           = $name;// 表示名
142                                 $newObj->showTitle              = $showTitle;           // タイトルの表示
143                                 $newObj->titleName              = $titleName;                           // タイトル名
144                                 $newObj->titleBgColor           = $titleBgColor;                // タイトルバックグランドカラー
145                                 $newObj->explanation    = $explanation;                         // 説明
146                                 $newObj->emailSubject = $emailSubject;          // メールタイトル
147                                 $newObj->emailReceiver = $emailReceiver;        // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
148                                 $newObj->fieldInfo      = array();
149                                 
150                                 for ($i = 0; $i < $fieldCount; $i++){
151                                         $newInfoObj = new stdClass;
152                                         $newInfoObj->title      = $titles[$i];
153                                         $newInfoObj->desc       = $descs[$i];
154                                         $newInfoObj->type       = $types[$i];
155                                         $newInfoObj->def        = $defs[$i];
156                                         $newInfoObj->required   = $requireds[$i];
157                                         $newObj->fieldInfo[] = $newInfoObj;
158                                 }
159                                 
160                                 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
161                                 if ($ret){
162                                         $this->setGuidanceMsg('データを追加しました');
163                                         
164                                         $this->configId = $defConfigId;         // 定義定義IDを更新
165                                         $replaceNew = true;                     // データ再取得
166                                 } else {
167                                         $this->setAppErrorMsg('データ追加に失敗しました');
168                                 }
169                         }
170                 } else if ($act == 'update'){           // 設定更新のとき
171                         // 入力値のエラーチェック
172                         
173                         if ($this->getMsgCount() == 0){                 // エラーのないとき
174                                 // 現在の設定値を取得
175                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
176                                 if ($ret){
177                                         // ウィジェットオブジェクト更新
178                                         $targetObj->showTitle           = $showTitle;           // タイトルの表示
179                                         $targetObj->titleName           = $titleName;                           // タイトル名
180                                         $targetObj->titleBgColor                = $titleBgColor;                // タイトルバックグランドカラー
181                                         $targetObj->explanation = $explanation;                         // 説明
182                                         $targetObj->emailSubject = $emailSubject;               // メールタイトル
183                                         $targetObj->emailReceiver = $emailReceiver;     // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
184                                         $targetObj->fieldInfo   = array();
185                                 
186                                         for ($i = 0; $i < $fieldCount; $i++){
187                                                 $newInfoObj = new stdClass;
188                                                 $newInfoObj->title      = $titles[$i];
189                                                 $newInfoObj->desc       = $descs[$i];
190                                                 $newInfoObj->type       = $types[$i];
191                                                 $newInfoObj->def        = $defs[$i];
192                                                 $newInfoObj->required   = $requireds[$i];
193                                                 $targetObj->fieldInfo[] = $newInfoObj;
194                                         }
195                                 }
196                                 
197                                 // 設定値を更新
198                                 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
199                                 if ($ret){
200                                         $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
201                                         $replaceNew = true;                     // データ再取得
202                                 } else {
203                                         $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
204                                 }
205                         }
206                 } else if ($act == 'select'){   // 定義IDを変更
207                         $replaceNew = true;                     // データ再取得
208                 } else {        // 初期起動時、または上記以外の場合
209                         // デフォルト値設定
210                         $this->configId = $defConfigId;         // 呼び出しウィンドウから引き継いだ定義ID
211                         $replaceNew = true;                     // データ再取得
212                 }
213                 // 設定項目選択メニュー作成
214                 $this->createItemMenu();
215                                 
216                 // 表示用データを取得
217                 if (empty($this->configId)){            // 新規登録の場合
218                         $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
219                         if ($replaceNew){               // データ再取得時
220                                 $name = $this->createDefaultName();                     // デフォルト登録項目名
221                                 $showTitle = 0;         // タイトルの表示
222                                 $titleName = self::DEFAULT_TITLE_NAME;                          // タイトル名
223                                 $titleBgColor = '';             // タイトルバックグランドカラー
224                                 $explanation = '';                              // 説明
225                                 $emailSubject = '';             // メールタイトル
226                                 $emailReceiver = '';    // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
227                                 $this->fieldInfoArray = array();                        // お問い合わせ項目情報
228                         }
229                         $this->serialNo = 0;
230                 } else {
231                         if ($replaceNew){// データ再取得時
232                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
233                                 if ($ret){
234                                         $name   = $targetObj->name;// 名前
235                                         $showTitle = $targetObj->showTitle;             // タイトルの表示
236                                         $titleName = $targetObj->titleName;                             // タイトル名
237                                         $titleBgColor = $targetObj->titleBgColor;               // タイトルバックグランドカラー
238                                         $explanation = $targetObj->explanation;                         // 説明
239                                         $emailSubject = $targetObj->emailSubject;               // メールタイトル
240                                         $emailReceiver = $targetObj->emailReceiver;     // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
241                                         if (!empty($targetObj->fieldInfo)) $this->fieldInfoArray = $targetObj->fieldInfo;                       // お問い合わせ項目情報
242                                 }
243                         }
244                         $this->serialNo = $this->configId;
245                                 
246                         // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
247                         if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
248                 }
249                 
250                 // 追加用タイプメニュー作成
251                 $this->createTypeMenu1();
252                 
253                 // お問い合わせ項目一覧作成
254                 $this->createFieldList();
255                 if (empty($this->fieldInfoArray)) $this->tmpl->setAttribute('field_list', 'visibility', 'hidden');// お問い合わせ項目情報一覧
256                 
257                 // 画面にデータを埋め込む
258                 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId);             // 定義ID
259                 $this->tmpl->addVar("item_name_visible", "name",        $name);
260                 if (!empty($showTitle)) $this->tmpl->addVar("_widget", "show_title",    'checked');             // タイトルの表示
261                 $this->tmpl->addVar("_widget", "title_name",    $this->convertToDispString($titleName));                                // タイトル名
262                 $this->tmpl->addVar("_widget", "title_bgcolor", $titleBgColor);         // タイトルバックグランドカラー
263                 $this->tmpl->addVar("_widget", "explanation",   $explanation);                          // 説明
264                 $this->tmpl->addVar("_widget", "email_subject", $emailSubject);         // メールタイトル
265                 $this->tmpl->addVar("_widget", "email_receiver",        $emailReceiver);        // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
266                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
267                 
268                 // ボタンの表示制御
269                 if (empty($this->serialNo)){            // 新規追加項目を選択しているとき
270                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
271                 } else {
272                         $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
273                         
274                         // ヘルプの追加
275                         $this->convertHelp('update_button');
276                 }
277                 
278                 // ページ定義IDとページ定義のレコードシリアル番号を更新
279                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
280         }
281         /**
282          * 選択用メニューを作成
283          *
284          * @return なし                                               
285          */
286         function createItemMenu()
287         {
288                 for ($i = 0; $i < count($this->paramObj); $i++){
289                         $id = $this->paramObj[$i]->id;// 定義ID
290                         $targetObj = $this->paramObj[$i]->object;
291                         $name = $targetObj->name;// 定義名
292                         $selected = '';
293                         if ($this->configId == $id) $selected = 'selected';
294
295                         $row = array(
296                                 'name' => $name,                // 名前
297                                 'value' => $id,         // 定義ID
298                                 'selected' => $selected // 選択中の項目かどうか
299                         );
300                         $this->tmpl->addVars('title_list', $row);
301                         $this->tmpl->parseTemplate('title_list', 'a');
302                 }
303         }
304         /**
305          * お問い合わせ項目一覧を作成
306          *
307          * @return なし                                               
308          */
309         function createFieldList()
310         {
311                 $fieldCount = count($this->fieldInfoArray);
312                 for ($i = 0; $i < $fieldCount; $i++){
313                         $infoObj = $this->fieldInfoArray[$i];
314                         $title = $infoObj->title;// タイトル名
315                         $desc = $infoObj->desc;         // 説明
316                         $type = $infoObj->type;         // 項目タイプ
317                         $def = $infoObj->def;           // 項目定義
318                         $requiredCheck = '';
319                         if (!empty($infoObj->required)) $requiredCheck = 'checked';
320                         
321                         // 行を作成
322                         $this->tmpl->clearTemplate('type_list2');
323                         
324                         for ($j = 0; $j < count($this->typeArray); $j++){
325                                 $value = $this->typeArray[$j]['value'];
326                                 $name = $this->typeArray[$j]['name'];
327
328                                 $selected = '';
329                                 if ($value == $type) $selected = 'selected';
330
331                                 $tableLine = array(
332                                         'value'    => $value,                   // タイプ値
333                                         'name'     => $this->convertToDispString($name),                        // タイプ名
334                                         'selected' => $selected                 // 選択中かどうか
335                                 );
336                                 $this->tmpl->addVars('type_list2', $tableLine);
337                                 $this->tmpl->parseTemplate('type_list2', 'a');
338                         }
339                         $rootUrl = $this->convertToDispString($this->getUrl($this->gEnv->getRootUrl()));
340                         $row = array(
341                                 'title' => $this->convertToDispString($title),  // タイトル名
342                                 'desc' => $this->convertToDispString($desc),    // 説明
343                                 'def' => $this->convertToDispString($def),              // 定義情報
344                                 'required' => $requiredCheck,                                                   // 必須入力
345                                 'root_url' => $rootUrl
346                         );
347                         $this->tmpl->addVars('field_list', $row);
348                         $this->tmpl->parseTemplate('field_list', 'a');
349                 }
350         }
351         /**
352          * デフォルトの名前を取得
353          *
354          * @return string       デフォルト名                                              
355          */
356         function createDefaultName()
357         {
358                 $name = self::DEFAULT_NAME_HEAD;
359                 for ($j = 1; $j < 100; $j++){
360                         $name = self::DEFAULT_NAME_HEAD . $j;
361                         // 設定名の重複チェック
362                         for ($i = 0; $i < count($this->paramObj); $i++){
363                                 $targetObj = $this->paramObj[$i]->object;
364                                 if ($name == $targetObj->name){         // 定義名
365                                         break;
366                                 }
367                         }
368                         // 重複なしのときは終了
369                         if ($i == count($this->paramObj)) break;
370                 }
371                 return $name;
372         }
373         /**
374          * 一覧画面作成
375          *
376          * @param RequestManager $request               HTTPリクエスト処理クラス
377          * @param                                                               なし
378          */
379         function createList($request)
380         {
381                 // ページ定義IDとページ定義のレコードシリアル番号を取得
382                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
383                 
384                 $userId         = $this->gEnv->getCurrentUserId();
385                 $langId = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
386                 $act = $request->trimValueOf('act');
387                 
388                 if ($act == 'delete'){          // メニュー項目の削除
389                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
390                         $delItems = array();
391                         for ($i = 0; $i < count($listedItem); $i++){
392                                 // 項目がチェックされているかを取得
393                                 $itemName = 'item' . $i . '_selected';
394                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
395                                 
396                                 if ($itemValue){                // チェック項目
397                                         $delItems[] = $listedItem[$i];
398                                 }
399                         }
400                         if (count($delItems) > 0){
401                                 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
402                                 if ($ret){              // データ削除成功のとき
403                                         $this->setGuidanceMsg('データを削除しました');
404                                 } else {
405                                         $this->setAppErrorMsg('データ削除に失敗しました');
406                                 }
407                         }
408                 }
409                 // 定義一覧作成
410                 $this->createItemList();
411                 
412                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
413                 
414                 // ページ定義IDとページ定義のレコードシリアル番号を更新
415                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
416         }
417         /**
418          * 定義一覧作成
419          *
420          * @return なし                                               
421          */
422         function createItemList()
423         {
424                 for ($i = 0; $i < count($this->paramObj); $i++){
425                         $id                     = $this->paramObj[$i]->id;// 定義ID
426                         $targetObj      = $this->paramObj[$i]->object;
427                         $name = $targetObj->name;// 定義名
428                         $emailReceiver  = $targetObj->emailReceiver;            // 受信メールアドレス
429                 
430                         // 使用数
431                         $defCount = 0;
432                         if (!empty($id)){
433                                 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
434                         }
435                         $operationDisagled = '';
436                         if ($defCount > 0) $operationDisagled = 'disabled';
437                         
438                         $row = array(
439                                 'index' => $i,
440                                 'id' => $id,
441                                 'ope_disabled' => $operationDisagled,                   // 選択可能かどうか
442                                 'name' => $this->convertToDispString($name),            // 名前
443                                 'email_receiver' => $this->convertToDispString($emailReceiver), // 受信メールアドレス
444                                 'def_count' => $defCount                                                        // 使用数
445                         );
446                         $this->tmpl->addVars('itemlist', $row);
447                         $this->tmpl->parseTemplate('itemlist', 'a');
448                         
449                         // シリアル番号を保存
450                         $this->serialArray[] = $id;
451                 }
452         }
453         /**
454          * タイプ選択メニュー作成
455          *
456          * @return なし
457          */
458         function createTypeMenu1()
459         {
460                 for ($i = 0; $i < count($this->typeArray); $i++){
461                         $value = $this->typeArray[$i]['value'];
462                         $name = $this->typeArray[$i]['name'];
463                         
464                         $row = array(
465                                 'value'    => $value,                   // タイプ値
466                                 'name'     => $this->convertToDispString($name),                        // タイプ名
467                                 'selected' => $selected                 // 選択中かどうか
468                         );
469                         $this->tmpl->addVars('type_list1', $row);
470                         $this->tmpl->parseTemplate('type_list1', 'a');
471                 }
472         }
473 }
474 ?>