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 $this->convertHelp('update_button');
278 // ページ定義IDとページ定義のレコードシリアル番号を更新
279 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
286 function createItemMenu()
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;// 定義名
293 if ($this->configId == $id) $selected = 'selected';
296 'name' => $name, // 名前
297 'value' => $id, // 定義ID
298 'selected' => $selected // 選択中の項目かどうか
300 $this->tmpl->addVars('title_list', $row);
301 $this->tmpl->parseTemplate('title_list', 'a');
309 function createFieldList()
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; // 項目定義
319 if (!empty($infoObj->required)) $requiredCheck = 'checked';
322 $this->tmpl->clearTemplate('type_list2');
324 for ($j = 0; $j < count($this->typeArray); $j++){
325 $value = $this->typeArray[$j]['value'];
326 $name = $this->typeArray[$j]['name'];
329 if ($value == $type) $selected = 'selected';
332 'value' => $value, // タイプ値
333 'name' => $this->convertToDispString($name), // タイプ名
334 'selected' => $selected // 選択中かどうか
336 $this->tmpl->addVars('type_list2', $tableLine);
337 $this->tmpl->parseTemplate('type_list2', 'a');
339 $rootUrl = $this->convertToDispString($this->getUrl($this->gEnv->getRootUrl()));
341 'title' => $this->convertToDispString($title), // タイトル名
342 'desc' => $this->convertToDispString($desc), // 説明
343 'def' => $this->convertToDispString($def), // 定義情報
344 'required' => $requiredCheck, // 必須入力
345 'root_url' => $rootUrl
347 $this->tmpl->addVars('field_list', $row);
348 $this->tmpl->parseTemplate('field_list', 'a');
354 * @return string デフォルト名
356 function createDefaultName()
358 $name = self::DEFAULT_NAME_HEAD;
359 for ($j = 1; $j < 100; $j++){
360 $name = self::DEFAULT_NAME_HEAD . $j;
362 for ($i = 0; $i < count($this->paramObj); $i++){
363 $targetObj = $this->paramObj[$i]->object;
364 if ($name == $targetObj->name){ // 定義名
369 if ($i == count($this->paramObj)) break;
376 * @param RequestManager $request HTTPリクエスト処理クラス
379 function createList($request)
381 // ページ定義IDとページ定義のレコードシリアル番号を取得
382 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
384 $userId = $this->gEnv->getCurrentUserId();
385 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
386 $act = $request->trimValueOf('act');
388 if ($act == 'delete'){ // メニュー項目の削除
389 $listedItem = explode(',', $request->trimValueOf('seriallist'));
391 for ($i = 0; $i < count($listedItem); $i++){
393 $itemName = 'item' . $i . '_selected';
394 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
396 if ($itemValue){ // チェック項目
397 $delItems[] = $listedItem[$i];
400 if (count($delItems) > 0){
401 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
402 if ($ret){ // データ削除成功のとき
403 $this->setGuidanceMsg('データを削除しました');
405 $this->setAppErrorMsg('データ削除に失敗しました');
410 $this->createItemList();
412 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
414 // ページ定義IDとページ定義のレコードシリアル番号を更新
415 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
422 function createItemList()
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; // 受信メールアドレス
433 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
435 $operationDisagled = '';
436 if ($defCount > 0) $operationDisagled = 'disabled';
441 'ope_disabled' => $operationDisagled, // 選択可能かどうか
442 'name' => $this->convertToDispString($name), // 名前
443 'email_receiver' => $this->convertToDispString($emailReceiver), // 受信メールアドレス
444 'def_count' => $defCount // 使用数
446 $this->tmpl->addVars('itemlist', $row);
447 $this->tmpl->parseTemplate('itemlist', 'a');
450 $this->serialArray[] = $id;
458 function createTypeMenu1()
460 for ($i = 0; $i < count($this->typeArray); $i++){
461 $value = $this->typeArray[$i]['value'];
462 $name = $this->typeArray[$i]['name'];
465 'value' => $value, // タイプ値
466 'name' => $this->convertToDispString($name), // タイプ名
467 'selected' => $selected // 選択中かどうか
469 $this->tmpl->addVars('type_list1', $row);
470 $this->tmpl->parseTemplate('type_list1', 'a');