7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-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
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/contactus_customDb.php');
19 class admin_m_contactus_customWidgetContainer extends BaseAdminWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $sysDb; // DB接続オブジェクト
23 private $serialNo; // 選択中の項目のシリアル番号
24 private $serialArray = array(); // 表示中のシリアル番号
26 private $configId; // 定義ID
27 private $paramObj; // パラメータ保存用オブジェクト
28 private $typeArray; // 項目タイプ
29 private $fieldInfoArray = array(); // お問い合わせ項目情報
30 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
31 const DEFAULT_TITLE_NAME = 'お問い合わせ'; // デフォルトのタイトル名
36 function __construct()
39 parent::__construct();
42 $this->db = new contactus_customDb();
43 $this->sysDb = $this->gInstance->getSytemDbObject();
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'));
55 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
56 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
58 * @param RequestManager $request HTTPリクエスト処理クラス
59 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
60 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
62 function _setTemplate($request, &$param)
64 $task = $request->trimValueOf('task');
65 if ($task == 'list'){ // 一覧画面
66 return 'admin_list.tmpl.html';
68 return 'admin.tmpl.html';
74 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
76 * @param RequestManager $request HTTPリクエスト処理クラス
77 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
80 function _assign($request, &$param)
82 $task = $request->trimValueOf('task');
83 if ($task == 'list'){ // 一覧画面
84 return $this->createList($request);
86 return $this->createDetail($request);
92 * @param RequestManager $request HTTPリクエスト処理クラス
95 function createDetail($request)
97 // ページ定義IDとページ定義のレコードシリアル番号を取得
98 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
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
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>形式が可能)
124 $replaceNew = false; // データを再取得するかどうか
125 if ($act == 'add'){// 新規追加
129 for ($i = 0; $i < count($this->paramObj); $i++){
130 $targetObj = $this->paramObj[$i]->object;
131 if ($name == $targetObj->name){ // 定義名
132 $this->setUserErrorMsg('名前が重複しています');
138 if ($this->getMsgCount() == 0){
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();
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;
160 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
162 $this->setGuidanceMsg('データを追加しました');
164 $this->configId = $defConfigId; // 定義定義IDを更新
165 $replaceNew = true; // データ再取得
167 $this->setAppErrorMsg('データ追加に失敗しました');
170 } else if ($act == 'update'){ // 設定更新のとき
173 if ($this->getMsgCount() == 0){ // エラーのないとき
175 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
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();
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;
198 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
200 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
201 $replaceNew = true; // データ再取得
203 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
206 } else if ($act == 'select'){ // 定義IDを変更
207 $replaceNew = true; // データ再取得
208 } else { // 初期起動時、または上記以外の場合
210 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
211 $replaceNew = true; // データ再取得
214 $this->createItemMenu();
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(); // お問い合わせ項目情報
231 if ($replaceNew){// データ再取得時
232 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
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; // お問い合わせ項目情報
244 $this->serialNo = $this->configId;
246 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
247 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
251 $this->createTypeMenu1();
254 $this->createFieldList();
255 if (empty($this->fieldInfoArray)) $this->tmpl->setAttribute('field_list', 'visibility', 'hidden');// お問い合わせ項目情報一覧
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を設定
269 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
270 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
272 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
275 // ページ定義IDとページ定義のレコードシリアル番号を更新
276 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
283 function createItemMenu()
285 for ($i = 0; $i < count($this->paramObj); $i++){
286 $id = $this->paramObj[$i]->id;// 定義ID
287 $targetObj = $this->paramObj[$i]->object;
288 $name = $targetObj->name;// 定義名
290 if ($this->configId == $id) $selected = 'selected';
293 'name' => $name, // 名前
294 'value' => $id, // 定義ID
295 'selected' => $selected // 選択中の項目かどうか
297 $this->tmpl->addVars('title_list', $row);
298 $this->tmpl->parseTemplate('title_list', 'a');
306 function createFieldList()
308 $fieldCount = count($this->fieldInfoArray);
309 for ($i = 0; $i < $fieldCount; $i++){
310 $infoObj = $this->fieldInfoArray[$i];
311 $title = $infoObj->title;// タイトル名
312 $desc = $infoObj->desc; // 説明
313 $type = $infoObj->type; // 項目タイプ
314 $def = $infoObj->def; // 項目定義
316 if (!empty($infoObj->required)) $requiredCheck = 'checked';
319 $this->tmpl->clearTemplate('type_list2');
321 for ($j = 0; $j < count($this->typeArray); $j++){
322 $value = $this->typeArray[$j]['value'];
323 $name = $this->typeArray[$j]['name'];
326 if ($value == $type) $selected = 'selected';
329 'value' => $value, // タイプ値
330 'name' => $this->convertToDispString($name), // タイプ名
331 'selected' => $selected // 選択中かどうか
333 $this->tmpl->addVars('type_list2', $tableLine);
334 $this->tmpl->parseTemplate('type_list2', 'a');
336 $rootUrl = $this->convertToDispString($this->getUrl($this->gEnv->getRootUrl()));
338 'title' => $this->convertToDispString($title), // タイトル名
339 'desc' => $this->convertToDispString($desc), // 説明
340 'def' => $this->convertToDispString($def), // 定義情報
341 'required' => $requiredCheck, // 必須入力
342 'root_url' => $rootUrl
344 $this->tmpl->addVars('field_list', $row);
345 $this->tmpl->parseTemplate('field_list', 'a');
351 * @return string デフォルト名
353 function createDefaultName()
355 $name = self::DEFAULT_NAME_HEAD;
356 for ($j = 1; $j < 100; $j++){
357 $name = self::DEFAULT_NAME_HEAD . $j;
359 for ($i = 0; $i < count($this->paramObj); $i++){
360 $targetObj = $this->paramObj[$i]->object;
361 if ($name == $targetObj->name){ // 定義名
366 if ($i == count($this->paramObj)) break;
373 * @param RequestManager $request HTTPリクエスト処理クラス
376 function createList($request)
378 // ページ定義IDとページ定義のレコードシリアル番号を取得
379 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
381 $userId = $this->gEnv->getCurrentUserId();
382 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
383 $act = $request->trimValueOf('act');
385 if ($act == 'delete'){ // メニュー項目の削除
386 $listedItem = explode(',', $request->trimValueOf('seriallist'));
388 for ($i = 0; $i < count($listedItem); $i++){
390 $itemName = 'item' . $i . '_selected';
391 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
393 if ($itemValue){ // チェック項目
394 $delItems[] = $listedItem[$i];
397 if (count($delItems) > 0){
398 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
399 if ($ret){ // データ削除成功のとき
400 $this->setGuidanceMsg('データを削除しました');
402 $this->setAppErrorMsg('データ削除に失敗しました');
407 $this->createItemList();
409 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
411 // ページ定義IDとページ定義のレコードシリアル番号を更新
412 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
419 function createItemList()
421 for ($i = 0; $i < count($this->paramObj); $i++){
422 $id = $this->paramObj[$i]->id;// 定義ID
423 $targetObj = $this->paramObj[$i]->object;
424 $name = $targetObj->name;// 定義名
425 $emailReceiver = $targetObj->emailReceiver; // 受信メールアドレス
430 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
432 $operationDisagled = '';
433 if ($defCount > 0) $operationDisagled = 'disabled';
438 'ope_disabled' => $operationDisagled, // 選択可能かどうか
439 'name' => $this->convertToDispString($name), // 名前
440 'email_receiver' => $this->convertToDispString($emailReceiver), // 受信メールアドレス
441 'def_count' => $defCount // 使用数
443 $this->tmpl->addVars('itemlist', $row);
444 $this->tmpl->parseTemplate('itemlist', 'a');
447 $this->serialArray[] = $id;
455 function createTypeMenu1()
457 for ($i = 0; $i < count($this->typeArray); $i++){
458 $value = $this->typeArray[$i]['value'];
459 $name = $this->typeArray[$i]['name'];
462 'value' => $value, // タイプ値
463 'name' => $this->convertToDispString($name), // タイプ名
464 'selected' => $selected // 選択中かどうか
466 $this->tmpl->addVars('type_list1', $row);
467 $this->tmpl->parseTemplate('type_list1', 'a');