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_effect_nicejformsWidgetContainer.php 2266 2009-08-28 08:25:59Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
18 class admin_effect_nicejformsWidgetContainer extends BaseAdminWidgetContainer
20 private $sysDb; // DB接続オブジェクト
21 private $serialNo; // 選択中の項目のシリアル番号
22 private $serialArray = array(); // 表示中のシリアル番号
24 private $configId; // 定義ID
25 private $paramObj; // パラメータ保存用オブジェクト
26 private $colorType; // カラータイプ
27 private $colorTypeDef; // カラータイプ選択用メニュー定義
28 const DEFAULT_NAME_HEAD = '名称未設定'; // デフォルトの設定名
29 const DEFAULT_COLOR_TYPE = '0';
34 function __construct()
37 parent::__construct();
40 $this->sysDb = $this->gInstance->getSytemDbObject();
43 $this->colorTypeDef = array( array( 'name' => '青', 'value' => '0', 'filename' => 'niceforms-default.css', 'image_dir' => 'default'),
44 array( 'name' => '緑', 'value' => '1', 'filename' => 'niceforms-green.css', 'image_dir' => 'greentheme'),
45 array( 'name' => '赤', 'value' => '2', 'filename' => 'niceforms-red.css', 'image_dir' => 'redtheme'));
50 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
51 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
53 * @param RequestManager $request HTTPリクエスト処理クラス
54 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
55 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
57 function _setTemplate($request, &$param)
59 $task = $request->trimValueOf('task');
60 if ($task == 'list'){ // 一覧画面
61 return 'admin_list.tmpl.html';
63 return 'admin.tmpl.html';
69 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
71 * @param RequestManager $request HTTPリクエスト処理クラス
72 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
75 function _assign($request, &$param)
77 $task = $request->trimValueOf('task');
78 if ($task == 'list'){ // 一覧画面
79 return $this->createList($request);
81 return $this->createDetail($request);
87 * @param RequestManager $request HTTPリクエスト処理クラス
90 function createDetail($request)
92 // ページ定義IDとページ定義のレコードシリアル番号を取得
93 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
95 $userId = $this->gEnv->getCurrentUserId();
96 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
97 $act = $request->trimValueOf('act');
98 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
99 $this->configId = $request->trimValueOf('item_id'); // 定義ID
100 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
103 $name = $request->trimValueOf('item_name'); // 定義名
104 $this->colorType = $request->trimValueOf('item_color_type'); // カラータイプ
106 $replaceNew = false; // データを再取得するかどうか
107 if ($act == 'add'){// 新規追加
109 $this->checkInput($name, '名前');
112 for ($i = 0; $i < count($this->paramObj); $i++){
113 $targetObj = $this->paramObj[$i]->object;
114 if ($name == $targetObj->name){ // 定義名
115 $this->setUserErrorMsg('名前が重複しています');
121 if ($this->getMsgCount() == 0){
123 $newObj = new stdClass;
124 $newObj->name = $name;// 表示名
125 $newObj->colorType = $this->colorType; // カラータイプ
127 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
129 $this->setGuidanceMsg('データを追加しました');
131 $this->configId = $defConfigId; // 定義定義IDを更新
132 $replaceNew = true; // データ再取得
134 $this->setAppErrorMsg('データ追加に失敗しました');
137 } else if ($act == 'update'){ // 設定更新のとき
140 if ($this->getMsgCount() == 0){ // エラーのないとき
142 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
145 $targetObj->colorType = $this->colorType; // カラータイプ
149 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
151 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
152 $replaceNew = true; // データ再取得
154 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
157 } else if ($act == 'select'){ // 定義IDを変更
158 $replaceNew = true; // データ再取得
159 } else { // 初期起動時、または上記以外の場合
161 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
162 $replaceNew = true; // データ再取得
165 $this->createItemMenu();
168 if (empty($this->configId)){ // 新規登録の場合
169 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
170 if ($replaceNew){ // データ再取得時
171 $name = $this->createDefaultName(); // デフォルト登録項目名
172 $this->colorType = self::DEFAULT_COLOR_TYPE; // カラータイプ
176 if ($replaceNew){// データ再取得時
177 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
179 $name = $targetObj->name; // 名前
180 $this->colorType = $targetObj->colorType; // カラータイプ
183 $this->serialNo = $this->configId;
185 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
186 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
190 $this->createColorTypeMenu();
193 if (!empty($this->configId)) $this->tmpl->addVar("_widget", "id", $this->configId); // 定義ID
194 $this->tmpl->addVar("item_name_visible", "name", $name);
195 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
198 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
199 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
201 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
204 $this->convertHelp('update_button');
207 // ページ定義IDとページ定義のレコードシリアル番号を更新
208 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
215 function createItemMenu()
217 for ($i = 0; $i < count($this->paramObj); $i++){
218 $id = $this->paramObj[$i]->id;// 定義ID
219 $targetObj = $this->paramObj[$i]->object;
220 $name = $targetObj->name;// 定義名
222 if ($this->configId == $id) $selected = 'selected';
225 'name' => $name, // 名前
226 'value' => $id, // 定義ID
227 'selected' => $selected // 選択中の項目かどうか
229 $this->tmpl->addVars('title_list', $row);
230 $this->tmpl->parseTemplate('title_list', 'a');
236 * @return string デフォルト名
238 function createDefaultName()
240 $name = self::DEFAULT_NAME_HEAD;
241 for ($j = 1; $j < 100; $j++){
242 $name = self::DEFAULT_NAME_HEAD . $j;
244 for ($i = 0; $i < count($this->paramObj); $i++){
245 $targetObj = $this->paramObj[$i]->object;
246 if ($name == $targetObj->name){ // 定義名
251 if ($i == count($this->paramObj)) break;
258 * @param RequestManager $request HTTPリクエスト処理クラス
261 function createList($request)
263 // ページ定義IDとページ定義のレコードシリアル番号を取得
264 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
266 $userId = $this->gEnv->getCurrentUserId();
267 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
268 $act = $request->trimValueOf('act');
270 if ($act == 'delete'){ // メニュー項目の削除
271 $listedItem = explode(',', $request->trimValueOf('seriallist'));
273 for ($i = 0; $i < count($listedItem); $i++){
275 $itemName = 'item' . $i . '_selected';
276 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
278 if ($itemValue){ // チェック項目
279 $delItems[] = $listedItem[$i];
282 if (count($delItems) > 0){
283 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
284 if ($ret){ // データ削除成功のとき
285 $this->setGuidanceMsg('データを削除しました');
287 $this->setAppErrorMsg('データ削除に失敗しました');
292 $this->createItemList();
294 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
296 // ページ定義IDとページ定義のレコードシリアル番号を更新
297 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
304 function createItemList()
306 for ($i = 0; $i < count($this->paramObj); $i++){
307 $id = $this->paramObj[$i]->id;// 定義ID
308 $targetObj = $this->paramObj[$i]->object;
309 $name = $targetObj->name;// 定義名
314 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
316 $operationDisagled = '';
317 if ($defCount > 0) $operationDisagled = 'disabled';
322 'ope_disabled' => $operationDisagled, // 選択可能かどうか
323 'name' => $this->convertToDispString($name), // 名前
324 'def_count' => $defCount // 使用数
326 $this->tmpl->addVars('itemlist', $row);
327 $this->tmpl->parseTemplate('itemlist', 'a');
330 $this->serialArray[] = $id;
338 function createColorTypeMenu()
340 for ($i = 0; $i < count($this->colorTypeDef); $i++){
341 $value = $this->colorTypeDef[$i]['value'];
342 $name = $this->colorTypeDef[$i]['name'];
345 if ($value == $this->colorType) $selected = 'selected';
348 'value' => $value, // 値
349 'name' => $name, // 名前
350 'selected' => $selected // 選択中かどうか
352 $this->tmpl->addVars('color_type_list', $row);
353 $this->tmpl->parseTemplate('color_type_list', 'a');