OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / contactus_freelayout3 / include / container / admin_contactus_freelayout3WidgetContainer.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    フリーレイアウトお問い合わせ
10  * @author     株式会社 毎日メディアサービス
11  * @copyright  Copyright 2009-2013 株式会社 毎日メディアサービス.
12  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
13  * @version    SVN: $Id: admin_contactus_freelayout3WidgetContainer.php 5824 2013-03-14 05:45:38Z fishbone $
14  * @link       http://www.m-media.co.jp
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17
18 class admin_contactus_freelayout3WidgetContainer 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 $typeArray;             // 項目タイプ
27         private $fieldInfoArray = array();                      // お問い合わせ項目情報
28         private $confirmButtonId;               // 確認ボタンのタグID
29         private $sendButtonId;          // 送信ボタンのタグID
30         private $cancelButtonId;                // 送信キャンセルボタンのタグID
31         private $resetButtonId;         // エリアリセットボタンのタグID
32         const DEFAULT_NAME_HEAD = '名称未設定';                    // デフォルトの設定名
33         const DEFAULT_USER_EMAIL_SUBJECT = '送信内容ご確認(自動送信メール)';
34         const DEFAULT_USER_EMAIL_FORMAT = "以下の内容でお問い合わせを送信しました。\n\n[#BODY#]";
35         
36         /**
37          * コンストラクタ
38          */
39         function __construct()
40         {
41                 // 親クラスを呼び出す
42                 parent::__construct();
43                 
44                 // DBオブジェクト作成
45                 $this->sysDb = $this->gInstance->getSytemDbObject();
46                 
47                 // お問い合わせ項目タイプ
48                 $this->typeArray = array(       array(  'name' => 'テキストボックス',                   'value' => 'text'),
49                                                                         array(  'name' => 'テキストボックス(Eメール)',       'value' => 'email'),
50                                                                         array(  'name' => 'テキストボックス(計算)',           'value' => 'calc'),
51                                                                         array(  'name' => 'テキストエリア',                              'value' => 'textarea'),
52                                                                         array(  'name' => 'セレクトメニュー',                   'value' => 'select'),
53                                                                         array(  'name' => 'チェックボックス',                   'value' => 'checkbox'),
54                                                                         array(  'name' => 'ラジオボタン',                         'value' => 'radio'));
55         }
56         /**
57          * テンプレートファイルを設定
58          *
59          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
60          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
61          *
62          * @param RequestManager $request               HTTPリクエスト処理クラス
63          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
64          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
65          */
66         function _setTemplate($request, &$param)
67         {
68                 $task = $request->trimValueOf('task');
69                 if ($task == 'list'){           // 一覧画面
70                         return 'admin_list.tmpl.html';
71                 } else {                        // 一覧画面
72                         return 'admin.tmpl.html';
73                 }
74         }
75         /**
76          * テンプレートにデータ埋め込む
77          *
78          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
79          *
80          * @param RequestManager $request               HTTPリクエスト処理クラス
81          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
82          * @param                                                               なし
83          */
84         function _assign($request, &$param)
85         {
86                 $task = $request->trimValueOf('task');
87                 if ($task == 'list'){           // 一覧画面
88                         return $this->createList($request);
89                 } else {                        // 詳細設定画面
90                         return $this->createDetail($request);
91                 }
92         }
93         /**
94          * 詳細画面作成
95          *
96          * @param RequestManager $request               HTTPリクエスト処理クラス
97          * @param                                                               なし
98          */
99         function createDetail($request)
100         {
101                 // ページ定義IDとページ定義のレコードシリアル番号を取得
102                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
103                 
104                 $userId         = $this->gEnv->getCurrentUserId();
105                 $this->langId   = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
106                 $act = $request->trimValueOf('act');
107                 $this->serialNo = $request->trimValueOf('serial');              // 選択項目のシリアル番号
108                 $this->configId = $request->trimValueOf('item_id');             // 定義ID
109                 if (empty($this->configId)) $this->configId = $defConfigId;             // 呼び出しウィンドウから引き継いだ定義ID
110                 
111                 // 入力値を取得
112                 $name   = $request->trimValueOf('item_name');                   // 定義名
113                 $baseTemplate = $request->valueOf('item_html');         // 入力エリア作成用ベーステンプレート
114                 $this->css      = $request->valueOf('item_css');                // 入力エリア作成用CSS
115                 $this->confirmButtonId = $request->trimValueOf('item_confirm_button');          // 確認ボタンのタグID
116                 $this->sendButtonId = $request->trimValueOf('item_send_button');                // 送信ボタンのタグID
117                 $this->cancelButtonId = $request->trimValueOf('item_cancel_button');            // 送信キャンセルボタンのタグID
118                 $this->resetButtonId = $request->trimValueOf('item_reset_button');              // エリアリセットボタンのタグID
119                 $fieldCount = intval($request->trimValueOf('fieldcount'));              // お問い合わせ項目数
120                 $titles = $request->trimValueOf('item_title');          // お問い合わせ項目タイトル
121                 $descs = $request->trimValueOf('item_desc');            // お問い合わせ項目説明
122                 $types  = $request->trimValueOf('item_type');           // お問い合わせ項目タイプ
123                 $defs = $request->trimValueOf('item_def');              // お問い合わせ項目定義
124                 $values = $request->trimValueOf('required');            // お問い合わせ項目必須入力
125                 $requireds = array();
126                 if (strlen($values) > 0) $requireds = explode(',', $values);
127                 $values = $request->trimValueOf('disabled');            // 編集不可
128                 $disableds = array();
129                 if (strlen($values) > 0) $disableds = explode(',', $values);
130                 $values = $request->trimValueOf('titlevisible');                // お問い合わせ項目タイトル表示制御
131                 $titleVisibles = array();
132                 if (strlen($values) > 0) $titleVisibles = explode(',', $values);
133                 $values = $request->trimValueOf('alphabet');            // 入力制限半角英字
134                 $alphabets = array();
135                 if (strlen($values) > 0) $alphabets = explode(',', $values);
136                 $values = $request->trimValueOf('number');              // 入力制限半角数値
137                 $numbers = array();
138                 if (strlen($values) > 0) $numbers = explode(',', $values);
139                 $defaults = $request->trimValueOf('item_default');              // お問い合わせ項目デフォルト値
140                 $fieldIds = $request->trimValueOf('item_field_id');             // お問い合わせ項目フィールドID
141                 $calcs = $request->trimValueOf('item_calc');            // お問い合わせ項目計算式
142                 $emailSubject = $request->trimValueOf('item_email_subject');            // メールタイトル
143                 $emailReceiver = trim($request->valueOf('item_email_receiver'));        // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
144                 $sendUserEmail = ($request->trimValueOf('item_send_user_email') == 'on') ? 1 : 0;       // 入力ユーザ向けメールを送信するかどうか
145                 $userEmailReply = $request->trimValueOf('item_user_email_reply');                                       // 入力ユーザ向けメール返信先メールアドレス
146                 $userEmailSubject = $request->trimValueOf('item_user_email_subject');                           // 入力ユーザ向けメールタイトル
147                 $userEmailFormat = $request->trimValueOf('item_user_email_format');                                     // 入力ユーザ向けメール本文フォーマット
148                 $useArtisteer = ($request->trimValueOf('item_use_artisteer') == 'on') ? 1 : 0;                                  // Artisteer対応デザイン
149                 
150                 // 入力データを取得
151                 $this->fieldInfoArray = array();
152                 for ($i = 0; $i < $fieldCount; $i++){
153                         $newInfoObj = new stdClass;
154                         $newInfoObj->title      = $titles[$i];
155                         $newInfoObj->desc       = $descs[$i];
156                         $newInfoObj->type       = $types[$i];
157                         $newInfoObj->def        = $defs[$i];
158                         $newInfoObj->required   = $requireds[$i];
159                         $newInfoObj->disabled   = $disableds[$i];
160                         $newInfoObj->titleVisible       = $titleVisibles[$i];
161                         $newInfoObj->alphabet   = $alphabets[$i];
162                         $newInfoObj->number             = $numbers[$i];
163                         $newInfoObj->default    = $defaults[$i];
164                         $newInfoObj->fieldId    = $fieldIds[$i];
165                         $newInfoObj->calc               = $calcs[$i];
166                         $this->fieldInfoArray[] = $newInfoObj;
167                 }
168                                 
169                 // Pタグを除去
170                 $baseTemplate = $this->gInstance->getTextConvManager()->deleteTag($baseTemplate, 'p');
171                 
172                 $replaceNew = false;            // データを再取得するかどうか
173                 if ($act == 'add'){// 新規追加
174                         // 入力値のエラーチェック
175                         for ($i = 0; $i < $fieldCount; $i++){
176                                 if (empty($titles[$i])){
177                                         $this->setUserErrorMsg('タイトルが入力されていません');
178                                         break;
179                                 }
180                         }
181                         // フィールドIDのチェック
182                         for ($i = 0; $i < $fieldCount; $i++){
183                                 if (!empty($fieldIds[$i])){
184                                         if (preg_match("/[^a-z]/", $fieldIds[$i])){
185                                                 $this->setUserErrorMsg('フィールドIDは英小文字が使用可能です');
186                                                 break;
187                                         }
188                                 }
189                         }
190                         // 計算式のチェック
191                         for ($i = 0; $i < $fieldCount; $i++){
192                                 if (!empty($calcs[$i])){
193                                         if (preg_match("/[^0-9a-z-\+\*\/()]/", $calcs[$i])){
194                                                 $this->setUserErrorMsg('計算式はフィールドID、演算子「+-*/」、括弧「()」、数値が使用可能です');
195                                                 break;
196                                         }
197                                 }
198                         }
199                                                                 
200                         // 設定名の重複チェック
201                         for ($i = 0; $i < count($this->paramObj); $i++){
202                                 $targetObj = $this->paramObj[$i]->object;
203                                 if ($name == $targetObj->name){         // 定義名
204                                         $this->setUserErrorMsg('名前が重複しています');
205                                         break;
206                                 }
207                         }
208                         
209                         // 確認メール用の設定のチェック
210                         if (!empty($sendUserEmail)){
211                                 $this->checkInput($userEmailSubject, '確認メール件名');
212                                 $this->checkInput($userEmailFormat, '確認メール本文');
213                         }
214
215                         // エラーなしの場合は、データを登録
216                         if ($this->getMsgCount() == 0){
217                                 // 追加オブジェクト作成
218                                 $newObj = new stdClass;
219                                 $newObj->name           = $name;// 表示名
220                                 $newObj->baseTemplate = $baseTemplate;          // 入力エリア作成用ベーステンプレート
221                                 $newObj->css    = $this->css;                                   // 入力エリア用CSS
222                                 $newObj->confirmButtonId = $this->confirmButtonId;              // 確認ボタンのタグID
223                                 $newObj->sendButtonId   = $this->sendButtonId;          // 送信ボタンのタグID
224                                 $newObj->cancelButtonId = $this->cancelButtonId;                // 送信キャンセルボタンのタグID
225                                 $newObj->resetButtonId  = $this->resetButtonId;         // エリアリセットボタンのタグID
226                                 $newObj->emailSubject = $emailSubject;          // メールタイトル
227                                 $newObj->emailReceiver = $emailReceiver;        // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
228                                 $newObj->sendUserEmail = $sendUserEmail;        // 入力ユーザ向けメールを送信するかどうか
229                                 $newObj->userEmailReply = $userEmailReply;                                      // 入力ユーザ向けメール返信先メールアドレス
230                                 $newObj->userEmailSubject = $userEmailSubject;                          // 入力ユーザ向けメールタイトル
231                                 $newObj->userEmailFormat = $userEmailFormat;                            // 入力ユーザ向けメール本文フォーマット
232                                 $newObj->useArtisteer = $useArtisteer;                                  // Artisteer対応デザイン
233                                 $newObj->fieldInfo      = $this->fieldInfoArray;                // フィールド定義
234                                 
235                                 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
236                                 if ($ret){
237                                         $this->setGuidanceMsg('データを追加しました');
238                                         
239                                         $this->configId = $defConfigId;         // 定義定義IDを更新
240                                         $replaceNew = true;                     // データ再取得
241                                 } else {
242                                         $this->setAppErrorMsg('データ追加に失敗しました');
243                                 }
244                         }
245                 } else if ($act == 'update'){           // 設定更新のとき
246                         // 入力値のエラーチェック
247                         for ($i = 0; $i < $fieldCount; $i++){
248                                 if (empty($titles[$i])){
249                                         $this->setUserErrorMsg('タイトルが入力されていません');
250                                         break;
251                                 }
252                         }
253                         // フィールドIDのチェック
254                         for ($i = 0; $i < $fieldCount; $i++){
255                                 if (!empty($fieldIds[$i])){
256                                         if (preg_match("/[^a-z]/", $fieldIds[$i])){
257                                                 $this->setUserErrorMsg('フィールドIDは英小文字が使用可能です');
258                                                 break;
259                                         }
260                                 }
261                         }
262                         // 計算式のチェック
263                         for ($i = 0; $i < $fieldCount; $i++){
264                                 if (!empty($calcs[$i])){
265                                         if (preg_match("/[^0-9a-z-\+\*\/()]/", $calcs[$i])){
266                                                 $this->setUserErrorMsg('計算式はフィールドID、演算子「+-*/」、括弧「()」、数値が使用可能です');
267                                                 break;
268                                         }
269                                 }
270                         }
271                         
272                         // 確認メール用の設定のチェック
273                         if (!empty($sendUserEmail)){
274                                 $this->checkInput($userEmailSubject, '確認メール件名');
275                                 $this->checkInput($userEmailFormat, '確認メール本文');
276                         }
277
278                         if ($this->getMsgCount() == 0){                 // エラーのないとき
279                                 // 現在の設定値を取得
280                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
281                                 if ($ret){
282                                         // ウィジェットオブジェクト更新
283                                         $targetObj->baseTemplate = $baseTemplate;               // 入力エリア作成用ベーステンプレート
284                                         $targetObj->css                 = $this->css;                                   // 入力エリア作成用CSS
285                                         $targetObj->confirmButtonId = $this->confirmButtonId;           // 確認ボタンのタグID
286                                         $targetObj->sendButtonId        = $this->sendButtonId;          // 送信ボタンのタグID
287                                         $targetObj->cancelButtonId      = $this->cancelButtonId;                // 送信キャンセルボタンのタグID
288                                         $targetObj->resetButtonId       = $this->resetButtonId;         // エリアリセットボタンのタグID
289                                         $targetObj->emailSubject = $emailSubject;               // メールタイトル
290                                         $targetObj->emailReceiver = $emailReceiver;     // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
291                                         $targetObj->sendUserEmail = $sendUserEmail;     // 入力ユーザ向けメールを送信するかどうか
292                                         $targetObj->userEmailSubject = $userEmailSubject;                               // 入力ユーザ向けメールタイトル
293                                         $targetObj->userEmailReply = $userEmailReply;                                   // 入力ユーザ向けメール返信先メールアドレス
294                                         $targetObj->userEmailFormat = $userEmailFormat;                         // 入力ユーザ向けメール本文フォーマット
295                                         $targetObj->useArtisteer = $useArtisteer;                                       // Artisteer対応デザイン
296                                         $targetObj->fieldInfo   = $this->fieldInfoArray;                // フィールド定義
297                                 }
298                                 
299                                 // 設定値を更新
300                                 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
301                                 if ($ret){
302                                         $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
303                                         $replaceNew = true;                     // データ再取得
304                                 } else {
305                                         $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
306                                 }
307                         }
308                 } else if ($act == 'select'){   // 定義IDを変更
309                         $replaceNew = true;                     // データ再取得
310                 } else {        // 初期起動時、または上記以外の場合
311                         // デフォルト値設定
312                         $this->configId = $defConfigId;         // 呼び出しウィンドウから引き継いだ定義ID
313                         $replaceNew = true;                     // データ再取得
314                 }
315                 // 設定項目選択メニュー作成
316                 $this->createItemMenu();
317                                 
318                 // 表示用データを取得
319                 if (empty($this->configId)){            // 新規登録の場合
320                         $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
321                         if ($replaceNew){               // データ再取得時
322                                 $name = $this->createDefaultName();                     // デフォルト登録項目名
323                                 
324                                 $this->css = $this->getParsedTemplateData('default.tmpl.css', array($this, 'makeCss'));// デフォルト用のCSSを取得
325                                 $emailSubject = '';             // メールタイトル
326                                 $emailReceiver = '';    // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
327                                 $sendUserEmail = 0;     // 入力ユーザ向けメールを送信するかどうか
328                                 $userEmailReply = '';                                   // 入力ユーザ向けメール返信先メールアドレス
329                                 $userEmailSubject = self::DEFAULT_USER_EMAIL_SUBJECT;                           // 入力ユーザ向けメールタイトル
330                                 $userEmailFormat = self::DEFAULT_USER_EMAIL_FORMAT;                             // 入力ユーザ向けメール本文フォーマット
331                                 $useArtisteer = 0;                                      // Artisteer対応デザイン
332                                 $this->fieldInfoArray = array();                        // お問い合わせ項目情報
333                                 
334                                 // デフォルトのテンプレート作成
335                                 $tagHead = $this->createTagIdHead();
336                                 $this->confirmButtonId = $tagHead . '_confirm';         // 確認ボタンのタグID
337                                 $this->sendButtonId = $tagHead . '_send';               // 送信用ボタンのタグID
338                                 $this->cancelButtonId   = $tagHead . '_cancel';         // 送信キャンセルボタンのタグID
339                                 $this->resetButtonId = $tagHead . '_reset';             // エリアリセットボタンのタグID
340                                 $baseTemplate = $this->getParsedTemplateData('default.tmpl.html', array($this, 'makeBaseTemplate'));// デフォルトの入力エリア作成用ベーステンプレート
341                         }
342                         $this->serialNo = 0;
343                 } else {
344                         if ($replaceNew){// データ再取得時
345                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
346                                 if ($ret){
347                                         $name   = $targetObj->name;// 名前
348                                         $baseTemplate = $targetObj->baseTemplate;               // 入力エリア作成用ベーステンプレート
349                                         $this->css              = $targetObj->css;                                      // 入力エリア作成用CSS
350                                         $this->confirmButtonId = $targetObj->confirmButtonId;           // 確認ボタンのタグID
351                                         $this->sendButtonId = $targetObj->sendButtonId;         // 送信ボタンのタグID
352                                         $this->cancelButtonId = $targetObj->cancelButtonId;             // 送信キャンセルボタンのタグID
353                                         $this->resetButtonId = $targetObj->resetButtonId;               // エリアリセットボタンのタグID
354                                         $emailSubject = $targetObj->emailSubject;               // メールタイトル
355                                         $emailReceiver = $targetObj->emailReceiver;     // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
356                                         $sendUserEmail = $targetObj->sendUserEmail;     // 入力ユーザ向けメールを送信するかどうか
357                                         $userEmailReply = $targetObj->userEmailReply;                                   // 入力ユーザ向けメール返信先メールアドレス
358                                         $userEmailSubject = $targetObj->userEmailSubject;                               // 入力ユーザ向けメールタイトル
359                                         $userEmailFormat = $targetObj->userEmailFormat;                         // 入力ユーザ向けメール本文フォーマット
360                                         $useArtisteer = $targetObj->useArtisteer;                                       // Artisteer対応デザイン
361                                         if (!empty($targetObj->fieldInfo)) $this->fieldInfoArray = $targetObj->fieldInfo;                       // お問い合わせ項目情報
362                                 }
363                         }
364                         $this->serialNo = $this->configId;
365                                 
366                         // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
367                         if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
368                 }
369                                 
370                 // 追加用タイプメニュー作成
371                 $this->createTypeMenu1();
372                 
373                 // お問い合わせ項目一覧作成
374                 $this->createFieldList();
375                 if (empty($this->fieldInfoArray)) $this->tmpl->setAttribute('field_list', 'visibility', 'hidden');// お問い合わせ項目情報一覧
376                 
377                 // 画面にデータを埋め込む
378                 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId);             // 定義ID
379                 $this->tmpl->addVar("item_name_visible", "name",        $name);
380                 $this->tmpl->addVar("_widget", "html",  $baseTemplate);         // 入力エリア作成用ベーステンプレート
381                 $this->tmpl->addVar("_widget", "css",   $this->css);            // 入力エリア作成用CSS
382                 $this->tmpl->addVar("_widget", "confirm_button",        $this->confirmButtonId);                // 確認ボタンのタグID
383                 $this->tmpl->addVar("_widget", "send_button",   $this->sendButtonId);           // 送信ボタンのタグID
384                 $this->tmpl->addVar("_widget", "cancel_button", $this->cancelButtonId);         // 送信キャンセルボタンのタグID
385                 $this->tmpl->addVar("_widget", "reset_button",  $this->resetButtonId);          // エリアリセットボタンのタグID
386                 $tagStr = $this->confirmButtonId . '(確認ボタンのID), ' . $this->sendButtonId . '(送信ボタンのID), ' . 
387                                                 $this->cancelButtonId . '(送信キャンセルボタンのID), ' . $this->resetButtonId . '(リセットボタンのID)';
388                 $this->tmpl->addVar("_widget", "tag_id_str", $tagStr);// タグIDの表示
389                 $this->tmpl->addVar("_widget", "email_subject", $emailSubject);         // メールタイトル
390                 $this->tmpl->addVar("_widget", "email_receiver",        $emailReceiver);        // メール受信者(aaaa<xxx@xxx.xxx>形式が可能)
391                 $visibleStr = '';
392                 if (!empty($sendUserEmail)) $visibleStr = 'checked';    
393                 $this->tmpl->addVar("_widget", "send_user_email", $visibleStr);                                         // 入力ユーザ向けメールを送信するかどうか
394                 $this->tmpl->addVar("_widget", "user_email_reply",      $userEmailReply);               // 入力ユーザ向けメール返信先メールアドレス
395                 $this->tmpl->addVar("_widget", "user_email_subject",    $userEmailSubject);             // 入力ユーザ向けメールタイトル
396                 $this->tmpl->addVar("_widget", "user_email_format",     $userEmailFormat);              // 入力ユーザ向けメール本文フォーマット
397                 $checked = '';
398                 if (!empty($useArtisteer)) $checked = 'checked';                                        
399                 $this->tmpl->addVar("_widget", "use_artisteer", $checked);// Artisteer対応デザイン
400                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
401                 $this->tmpl->addVar('_widget', 'tag_start', M3_TAG_START . M3_TAG_MACRO_ITEM_KEY);              // 置換タグ(前)
402                 $this->tmpl->addVar('_widget', 'tag_end', M3_TAG_END);          // 置換タグ(後)
403                 
404                 // ボタンの表示制御
405                 if (empty($this->serialNo)){            // 新規追加項目を選択しているとき
406                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
407                         
408                         // プレビューボタン作成
409                         $this->tmpl->addVar("_widget", "preview_disabled", 'disabled ');// 「プレビュー」ボタン
410                 } else {
411                         $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
412                         
413                         // このウィジェットがマップされているページサブIDを取得
414                         $subPageId = $this->gPage->getPageSubIdByWidget($this->gEnv->getDefaultPageId(), $this->gEnv->getCurrentWidgetId(), $defConfigId);
415                         $previewUrl = $this->gEnv->getDefaultUrl();
416                         if (!empty($subPageId)) $previewUrl .= '?sub=' . $subPageId;
417                         $this->tmpl->addVar("_widget", "preview_url", $this->getUrl($previewUrl));
418                         
419                         // ヘルプの追加
420                         $this->convertHelp('update_button');
421                 }
422                 
423                 // ページ定義IDとページ定義のレコードシリアル番号を更新
424                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
425         }
426         /**
427          * 選択用メニューを作成
428          *
429          * @return なし                                               
430          */
431         function createItemMenu()
432         {
433                 for ($i = 0; $i < count($this->paramObj); $i++){
434                         $id = $this->paramObj[$i]->id;// 定義ID
435                         $targetObj = $this->paramObj[$i]->object;
436                         $name = $targetObj->name;// 定義名
437                         $selected = '';
438                         if ($this->configId == $id) $selected = 'selected';
439
440                         $row = array(
441                                 'name' => $name,                // 名前
442                                 'value' => $id,         // 定義ID
443                                 'selected' => $selected // 選択中の項目かどうか
444                         );
445                         $this->tmpl->addVars('title_list', $row);
446                         $this->tmpl->parseTemplate('title_list', 'a');
447                 }
448         }
449         /**
450          * お問い合わせ項目一覧を作成
451          *
452          * @return なし                                               
453          */
454         function createFieldList()
455         {
456                 $fieldCount = count($this->fieldInfoArray);
457                 for ($i = 0; $i < $fieldCount; $i++){
458                         $infoObj = $this->fieldInfoArray[$i];
459                         $title = $infoObj->title;// タイトル名
460                         $desc = $infoObj->desc;         // 説明
461                         $type = $infoObj->type;         // 項目タイプ
462                         $def = $infoObj->def;           // 項目定義
463                         $requiredCheck = '';
464                         if (!empty($infoObj->required)) $requiredCheck = 'checked';
465                         $disabledCheck = '';                                                    // 編集不可
466                         if (!empty($infoObj->disabled)) $disabledCheck = 'checked';
467                         $titleVisibleCheck = '';
468                         if (!empty($infoObj->titleVisible)) $titleVisibleCheck = 'checked';
469                         $alphabetCheck = '';
470                         if (!empty($infoObj->alphabet)) $alphabetCheck = 'checked';
471                         $numberCheck = '';
472                         if (!empty($infoObj->number)) $numberCheck = 'checked';
473                         $default        = $infoObj->default;            // デフォルト値
474                         $fieldId        = $infoObj->fieldId;            // フィールドID
475                         $calc           = $infoObj->calc;                       // 計算式
476                         
477                         // 行を作成
478                         $this->tmpl->clearTemplate('type_list2');
479                         
480                         for ($j = 0; $j < count($this->typeArray); $j++){
481                                 $value = $this->typeArray[$j]['value'];
482                                 $name = $this->typeArray[$j]['name'];
483
484                                 $selected = '';
485                                 if ($value == $type) $selected = 'selected';
486
487                                 $tableLine = array(
488                                         'value'    => $value,                   // タイプ値
489                                         'name'     => $this->convertToDispString($name),                        // タイプ名
490                                         'selected' => $selected                 // 選択中かどうか
491                                 );
492                                 $this->tmpl->addVars('type_list2', $tableLine);
493                                 $this->tmpl->parseTemplate('type_list2', 'a');
494                         }
495                         
496                         $row = array(
497                                 'title' => $this->convertToDispString($title),  // タイトル名
498                                 'desc' => $this->convertToDispString($desc),    // 説明
499                                 'def' => $this->convertToDispString($def),              // 定義情報
500                                 'required' => $requiredCheck,                                                   // 必須入力
501                                 'disabled' => $disabledCheck,                                                   // 編集不可
502                                 'title_visible' => $titleVisibleCheck,                  // タイトル表示制御
503                                 'alphabet' => $alphabetCheck,                   // 入力制限半角英字
504                                 'number' => $numberCheck,                       // 入力制限半角数値
505                                 'default' => $this->convertToDispString($default),      // デフォルト値
506                                 'field_id' => $this->convertToDispString($fieldId),             // フィールドID
507                                 'calc' => $this->convertToDispString($calc),                    // 計算式
508                                 'root_url' => $this->convertToDispString($this->getUrl($this->gEnv->getRootUrl()))
509                         );
510                         $this->tmpl->addVars('field_list', $row);
511                         $this->tmpl->parseTemplate('field_list', 'a');
512                 }
513         }
514         /**
515          * デフォルトの名前を取得
516          *
517          * @return string       デフォルト名                                              
518          */
519         function createDefaultName()
520         {
521                 $name = self::DEFAULT_NAME_HEAD;
522                 for ($j = 1; $j < 100; $j++){
523                         $name = self::DEFAULT_NAME_HEAD . $j;
524                         // 設定名の重複チェック
525                         for ($i = 0; $i < count($this->paramObj); $i++){
526                                 $targetObj = $this->paramObj[$i]->object;
527                                 if ($name == $targetObj->name){         // 定義名
528                                         break;
529                                 }
530                         }
531                         // 重複なしのときは終了
532                         if ($i == count($this->paramObj)) break;
533                 }
534                 return $name;
535         }
536         /**
537          * 一覧画面作成
538          *
539          * @param RequestManager $request               HTTPリクエスト処理クラス
540          * @param                                                               なし
541          */
542         function createList($request)
543         {
544                 // ページ定義IDとページ定義のレコードシリアル番号を取得
545                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
546                 
547                 $userId         = $this->gEnv->getCurrentUserId();
548                 $langId = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
549                 $act = $request->trimValueOf('act');
550                 
551                 if ($act == 'delete'){          // メニュー項目の削除
552                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
553                         $delItems = array();
554                         for ($i = 0; $i < count($listedItem); $i++){
555                                 // 項目がチェックされているかを取得
556                                 $itemName = 'item' . $i . '_selected';
557                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
558                                 
559                                 if ($itemValue){                // チェック項目
560                                         $delItems[] = $listedItem[$i];
561                                 }
562                         }
563                         if (count($delItems) > 0){
564                                 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
565                                 if ($ret){              // データ削除成功のとき
566                                         $this->setGuidanceMsg('データを削除しました');
567                                 } else {
568                                         $this->setAppErrorMsg('データ削除に失敗しました');
569                                 }
570                         }
571                 }
572                 // 定義一覧作成
573                 $this->createItemList();
574                 
575                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
576                 
577                 // ページ定義IDとページ定義のレコードシリアル番号を更新
578                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
579         }
580         /**
581          * 定義一覧作成
582          *
583          * @return なし                                               
584          */
585         function createItemList()
586         {
587                 for ($i = 0; $i < count($this->paramObj); $i++){
588                         $id                     = $this->paramObj[$i]->id;// 定義ID
589                         $targetObj      = $this->paramObj[$i]->object;
590                         $name = $targetObj->name;// 定義名
591                         $emailReceiver  = $targetObj->emailReceiver;            // 受信メールアドレス
592                 
593                         // 使用数
594                         $defCount = 0;
595                         if (!empty($id)){
596                                 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
597                         }
598                         $operationDisagled = '';
599                         if ($defCount > 0) $operationDisagled = 'disabled';
600                         
601                         $row = array(
602                                 'index' => $i,
603                                 'id' => $id,
604                                 'ope_disabled' => $operationDisagled,                   // 選択可能かどうか
605                                 'name' => $this->convertToDispString($name),            // 名前
606                                 'email_receiver' => $this->convertToDispString($emailReceiver), // 受信メールアドレス
607                                 'def_count' => $defCount                                                        // 使用数
608                         );
609                         $this->tmpl->addVars('itemlist', $row);
610                         $this->tmpl->parseTemplate('itemlist', 'a');
611                         
612                         // シリアル番号を保存
613                         $this->serialArray[] = $id;
614                 }
615         }
616         /**
617          * タイプ選択メニュー作成
618          *
619          * @return なし
620          */
621         function createTypeMenu1()
622         {
623                 for ($i = 0; $i < count($this->typeArray); $i++){
624                         $value = $this->typeArray[$i]['value'];
625                         $name = $this->typeArray[$i]['name'];
626                         
627                         $row = array(
628                                 'value'    => $value,                   // タイプ値
629                                 'name'     => $this->convertToDispString($name),                        // タイプ名
630                                 'selected' => $selected                 // 選択中かどうか
631                         );
632                         $this->tmpl->addVars('type_list1', $row);
633                         $this->tmpl->parseTemplate('type_list1', 'a');
634                 }
635         }
636         /**
637          * テンプレートデータ作成処理コールバック
638          *
639          * @param object         $tmpl                  テンプレートオブジェクト
640          * @param                                                               なし
641          */
642         function makeBaseTemplate($tmpl)
643         {
644                 $tmpl->addVar("_tmpl", "widget_url",    $this->gEnv->getCurrentWidgetRootUrl());                // ウィジェットのURL
645                 $tmpl->addVar("_tmpl", "confirm_button_id",     $this->confirmButtonId);        // 確認用ボタンのタグID
646                 $tmpl->addVar("_tmpl", "send_button_id",        $this->sendButtonId);           // 送信用ボタンのタグID
647                 $tmpl->addVar("_tmpl", "cancel_button_id",      $this->cancelButtonId);         // 送信キャンセル用ボタンのタグID
648                 $tmpl->addVar("_tmpl", "reset_button_id",       $this->resetButtonId);          // エリアリセットボタンのタグID
649         }
650         /**
651          * CSSデータ作成処理コールバック
652          *
653          * @param object         $tmpl                  テンプレートオブジェクト
654          * @param                                                               なし
655          */
656         function makeCss($tmpl)
657         {
658         }
659         /**
660          * inputタグID用のヘッダ文字列を作成
661          *
662          * @return string       ID
663          */
664         function createTagIdHead()
665         {
666                 return $this->gEnv->getCurrentWidgetId() . '_' . $this->getTempConfigId($this->paramObj);
667         }
668 }
669 ?>