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_printWidgetContainer.php 2263 2009-08-28 05:21:34Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
18 class admin_printWidgetContainer 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 = '名称未設定'; // デフォルトの設定名
27 const DEFAULT_PRINT_TAG = 'print'; // デフォルトの印刷タグID
32 function __construct()
35 parent::__construct();
38 $this->sysDb = $this->gInstance->getSytemDbObject();
43 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
44 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
46 * @param RequestManager $request HTTPリクエスト処理クラス
47 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
48 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
50 function _setTemplate($request, &$param)
52 $task = $request->trimValueOf('task');
53 if ($task == 'list'){ // 一覧画面
54 return 'admin_list.tmpl.html';
56 return 'admin.tmpl.html';
62 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
64 * @param RequestManager $request HTTPリクエスト処理クラス
65 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
68 function _assign($request, &$param)
70 $task = $request->trimValueOf('task');
71 if ($task == 'list'){ // 一覧画面
72 return $this->createList($request);
74 return $this->createDetail($request);
80 * @param RequestManager $request HTTPリクエスト処理クラス
83 function createDetail($request)
85 // ページ定義IDとページ定義のレコードシリアル番号を取得
86 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
88 $userId = $this->gEnv->getCurrentUserId();
89 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
90 $act = $request->trimValueOf('act');
91 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
94 $name = $request->trimValueOf('item_name'); // ヘッダタイトル
95 $tagId = $request->trimValueOf('item_tag_id'); // 印刷範囲のタグID
96 $this->configId = $request->trimValueOf('item_id'); // 定義ID
97 if (empty($this->configId)) $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
99 $replaceNew = false; // データを再取得するかどうか
100 if (empty($act)){// 初期起動時
102 $this->configId = $defConfigId; // 呼び出しウィンドウから引き継いだ定義ID
103 $replaceNew = true; // データ再取得
104 } else if ($act == 'add'){// 新規追加
106 $this->checkInput($name, '名前');
107 $this->checkInput($tagId, 'タグID');
110 for ($i = 0; $i < count($this->paramObj); $i++){
111 $targetObj = $this->paramObj[$i]->object;
112 if ($name == $targetObj->name){ // 定義名
113 $this->setUserErrorMsg('名前が重複しています');
119 if ($this->getMsgCount() == 0){
121 $newObj = new stdClass;
122 $newObj->name = $name;// 表示名
123 $newObj->tagId = $tagId; // 印刷範囲のタグID
125 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
127 $this->setGuidanceMsg('データを追加しました');
129 $this->configId = $defConfigId; // 定義定義IDを更新
130 $replaceNew = true; // データ再取得
132 $this->setAppErrorMsg('データ追加に失敗しました');
135 } else if ($act == 'update'){ // 設定更新のとき
137 $this->checkInput($tagId, 'タグID');
139 if ($this->getMsgCount() == 0){ // エラーのないとき
141 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
144 $targetObj->tagId = $tagId; // 印刷範囲のタグID
148 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
150 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
152 $replaceNew = true; // データ再取得
154 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
157 } else if ($act == 'select'){ // 定義IDを変更
158 $replaceNew = true; // データ再取得
162 $this->createItemMenu();
165 if (empty($this->configId)){ // 新規登録の場合
166 $this->tmpl->setAttribute('item_name_visible', 'visibility', 'visible');// 名前入力フィールド表示
167 if ($replaceNew){ // データ再取得時
168 $name = $this->createDefaultName(); // デフォルト登録項目名
169 $tagId = self::DEFAULT_PRINT_TAG; // YouTubeのタグID
174 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
176 $name = $targetObj->name;// 名前
177 $tagId = $targetObj->tagId; // 選択範囲のタグID
180 $this->serialNo = $this->configId;
182 // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
183 if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
187 $this->tmpl->addVar("item_name_visible", "name", $name); // 名前
188 $this->tmpl->addVar("_widget", "tag_id", $tagId); // タグID
190 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
193 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
194 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
196 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
198 // ページ定義IDとページ定義のレコードシリアル番号を更新
199 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
206 function createItemMenu()
208 for ($i = 0; $i < count($this->paramObj); $i++){
209 $id = $this->paramObj[$i]->id;// 定義ID
210 $targetObj = $this->paramObj[$i]->object;
211 $name = $targetObj->name;// 定義名
214 if ($this->configId == $id) $selected = 'selected';
216 'name' => $name, // 名前
217 'value' => $id, // 定義ID
218 'selected' => $selected // 選択中の項目かどうか
220 $this->tmpl->addVars('title_list', $row);
221 $this->tmpl->parseTemplate('title_list', 'a');
227 * @return string デフォルト名
229 function createDefaultName()
231 $name = self::DEFAULT_NAME_HEAD;
232 for ($j = 1; $j < 100; $j++){
233 $name = self::DEFAULT_NAME_HEAD . $j;
235 for ($i = 0; $i < count($this->paramObj); $i++){
236 $targetObj = $this->paramObj[$i]->object;
237 if ($name == $targetObj->name){ // 定義名
242 if ($i == count($this->paramObj)) break;
249 * @param RequestManager $request HTTPリクエスト処理クラス
252 function createList($request)
254 // ページ定義IDとページ定義のレコードシリアル番号を取得
255 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
257 $userId = $this->gEnv->getCurrentUserId();
258 $langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
259 $act = $request->trimValueOf('act');
261 if ($act == 'delete'){ // メニュー項目の削除
262 $listedItem = explode(',', $request->trimValueOf('seriallist'));
264 for ($i = 0; $i < count($listedItem); $i++){
266 $itemName = 'item' . $i . '_selected';
267 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
269 if ($itemValue){ // チェック項目
270 $delItems[] = $listedItem[$i];
273 if (count($delItems) > 0){
274 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
275 if ($ret){ // データ削除成功のとき
276 $this->setGuidanceMsg('データを削除しました');
278 $this->setAppErrorMsg('データ削除に失敗しました');
283 $this->createItemList();
285 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
287 // ページ定義IDとページ定義のレコードシリアル番号を更新
288 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
295 function createItemList()
297 for ($i = 0; $i < count($this->paramObj); $i++){
298 $id = $this->paramObj[$i]->id;// 定義ID
299 $targetObj = $this->paramObj[$i]->object;
300 $name = $targetObj->name;// 定義名
304 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
306 $operationDisagled = '';
307 if ($defCount > 0) $operationDisagled = 'disabled';
310 'ope_disabled' => $operationDisagled, // 選択可能かどうか
311 'name' => $this->convertToDispString($name), // 名前
312 'tag_id' => $this->convertToDispString($targetObj->tagId), // タグID
313 'def_count' => $defCount // 使用数
315 $this->tmpl->addVars('itemlist', $row);
316 $this->tmpl->parseTemplate('itemlist', 'a');
319 $this->serialArray[] = $id;