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-2011 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_m_adtagWidgetContainer.php 4194 2011-06-14 06:00:32Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
18 class admin_m_adtagWidgetContainer extends BaseAdminWidgetContainer
20 private $sysDb; // DB接続オブジェクト
21 private $serialNo; // 選択中の項目のシリアル番号
22 private $serialArray = array(); // 表示中のシリアル番号
24 private $configId; // 定義ID
25 private $paramObj; // パラメータ保存用オブジェクト
26 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
31 function __construct()
34 parent::__construct();
37 $this->sysDb = $this->gInstance->getSytemDbObject();
42 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
43 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
45 * @param RequestManager $request HTTPリクエスト処理クラス
46 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
47 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
49 function _setTemplate($request, &$param)
51 $task = $request->trimValueOf('task');
52 if ($task == 'list'){ // 一覧画面
53 return 'admin_list.tmpl.html';
55 return 'admin.tmpl.html';
61 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
63 * @param RequestManager $request HTTPリクエスト処理クラス
64 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
67 function _assign($request, &$param)
69 $task = $request->trimValueOf('task');
70 if ($task == 'list'){ // 一覧画面
71 return $this->createList($request);
73 return $this->createDetail($request);
79 * @param RequestManager $request HTTPリクエスト処理クラス
82 function createDetail($request)
84 // ページ定義IDとページ定義のレコードシリアル番号を取得
85 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
87 $userId = $this->gEnv->getCurrentUserId();
88 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
89 $act = $request->trimValueOf('act');
90 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
93 $name = $request->trimValueOf('item_name'); // ヘッダタイトル
94 $content = $request->valueOf('item_content'); // タグ内容
95 $this->configId = $request->trimValueOf('item_id'); // 定義ID
96 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
98 $replaceNew = false; // データを再取得するかどうか
99 if (empty($act)){// 初期起動時
101 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
102 $replaceNew = true; // データ再取得
103 } else if ($act == 'add'){// 新規追加
105 $this->checkInput($name, '名前');
106 $this->checkInput($content, 'タグ内容');
109 for ($i = 0; $i < count($this->paramObj); $i++){
110 $targetObj = $this->paramObj[$i]->object;
111 if ($name == $targetObj->name){ // 定義名
112 $this->setUserErrorMsg('名前が重複しています');
118 if ($this->getMsgCount() == 0){
120 $newObj = new stdClass;
121 $newObj->name = $name;// 表示名
122 $newObj->content = $content; // タグ内容
124 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
126 $this->setGuidanceMsg('データを追加しました');
128 $this->configId = $defConfigId; // 定義定義IDを更新
129 $replaceNew = true; // データ再取得
131 $this->setAppErrorMsg('データ追加に失敗しました');
134 } else if ($act == 'update'){ // 設定更新のとき
136 $this->checkInput($content, 'タグ内容');
138 if ($this->getMsgCount() == 0){ // エラーのないとき
140 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
143 $targetObj->content = $content; // タグ内容
147 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
149 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
151 $replaceNew = true; // データ再取得
153 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
156 } else if ($act == 'select'){ // 定義IDを変更
157 $replaceNew = true; // データ再取得
161 $this->createItemMenu();
164 if (empty($this->configId)){ // 新規登録の場合
165 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
166 if ($replaceNew){ // データ再取得時
167 $name = $this->createDefaultName(); // デフォルト登録項目名
168 $content = ''; // タグ内容
173 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
175 $name = $targetObj->name;// 名前
176 $content = $targetObj->content; // タグ内容
179 $this->serialNo = $this->configId;
181 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
182 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
186 $this->tmpl->addVar("item_name_visible", "name", $name); // 名前
187 $this->tmpl->addVar("_widget", "content", $content); // タグ内容
189 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
192 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
193 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
195 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
197 // ページ定義IDとページ定義のレコードシリアル番号を更新
198 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
205 function createItemMenu()
207 for ($i = 0; $i < count($this->paramObj); $i++){
208 $id = $this->paramObj[$i]->id;// 定義ID
209 $targetObj = $this->paramObj[$i]->object;
210 $name = $targetObj->name;// 定義名
213 if ($this->configId == $id) $selected = 'selected';
215 'name' => $name, // 名前
216 'value' => $id, // 定義ID
217 'selected' => $selected // 選択中の項目かどうか
219 $this->tmpl->addVars('title_list', $row);
220 $this->tmpl->parseTemplate('title_list', 'a');
226 * @return string デフォルト名
228 function createDefaultName()
230 $name = self::DEFAULT_NAME_HEAD;
231 for ($j = 1; $j < 100; $j++){
232 $name = self::DEFAULT_NAME_HEAD . $j;
234 for ($i = 0; $i < count($this->paramObj); $i++){
235 $targetObj = $this->paramObj[$i]->object;
236 if ($name == $targetObj->name){ // 定義名
241 if ($i == count($this->paramObj)) break;
248 * @param RequestManager $request HTTPリクエスト処理クラス
251 function createList($request)
253 // ページ定義IDとページ定義のレコードシリアル番号を取得
254 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
256 $userId = $this->gEnv->getCurrentUserId();
257 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
258 $act = $request->trimValueOf('act');
260 if ($act == 'delete'){ // メニュー項目の削除
261 $listedItem = explode(',', $request->trimValueOf('seriallist'));
263 for ($i = 0; $i < count($listedItem); $i++){
265 $itemName = 'item' . $i . '_selected';
266 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
268 if ($itemValue){ // チェック項目
269 $delItems[] = $listedItem[$i];
272 if (count($delItems) > 0){
273 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
274 if ($ret){ // データ削除成功のとき
275 $this->setGuidanceMsg('データを削除しました');
277 $this->setAppErrorMsg('データ削除に失敗しました');
282 $this->createItemList();
285 if (count($this->serialArray) == 0) $this->tmpl->setAttribute('itemlist', 'visibility', 'hidden');
287 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
289 // ページ定義IDとページ定義のレコードシリアル番号を更新
290 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
297 function createItemList()
299 for ($i = 0; $i < count($this->paramObj); $i++){
300 $id = $this->paramObj[$i]->id;// 定義ID
301 $targetObj = $this->paramObj[$i]->object;
302 $name = $targetObj->name;// 定義名
306 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
308 $operationDisagled = '';
309 if ($defCount > 0) $operationDisagled = 'disabled';
312 'ope_disabled' => $operationDisagled, // 選択可能かどうか
313 'name' => $this->convertToDispString($name), // 名前
314 'def_count' => $defCount // 使用数
316 $this->tmpl->addVars('itemlist', $row);
317 $this->tmpl->parseTemplate('itemlist', 'a');
320 $this->serialArray[] = $id;