OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / print / include / container / admin_printWidgetContainer.php
1 <?php
2 /**
3  * コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
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
15  */
16 require_once($gEnvManager->getContainerPath() . '/baseAdminWidgetContainer.php');
17
18 class admin_printWidgetContainer extends BaseAdminWidgetContainer
19 {
20         private $sysDb; // DB接続オブジェクト
21         private $serialNo;              // 選択中の項目のシリアル番号
22         private $serialArray = array();                 // 表示中のシリアル番号
23         private $langId;
24         private $configId;              // 定義ID
25         private $paramObj;              // パラメータ保存用オブジェクト
26         const DEFAULT_NAME_HEAD = '名称未設定';                    // デフォルトの設定名
27         const DEFAULT_PRINT_TAG = 'print';                      // デフォルトの印刷タグID
28         
29         /**
30          * コンストラクタ
31          */
32         function __construct()
33         {
34                 // 親クラスを呼び出す
35                 parent::__construct();
36                 
37                 // DBオブジェクト作成
38                 $this->sysDb = $this->gInstance->getSytemDbObject();
39         }
40         /**
41          * テンプレートファイルを設定
42          *
43          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
44          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
45          *
46          * @param RequestManager $request               HTTPリクエスト処理クラス
47          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
48          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
49          */
50         function _setTemplate($request, &$param)
51         {
52                 $task = $request->trimValueOf('task');
53                 if ($task == 'list'){           // 一覧画面
54                         return 'admin_list.tmpl.html';
55                 } else {                        // 一覧画面
56                         return 'admin.tmpl.html';
57                 }
58         }
59         /**
60          * テンプレートにデータ埋め込む
61          *
62          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
63          *
64          * @param RequestManager $request               HTTPリクエスト処理クラス
65          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
66          * @param                                                               なし
67          */
68         function _assign($request, &$param)
69         {
70                 $task = $request->trimValueOf('task');
71                 if ($task == 'list'){           // 一覧画面
72                         return $this->createList($request);
73                 } else {                        // 詳細設定画面
74                         return $this->createDetail($request);
75                 }
76         }
77         /**
78          * 詳細画面作成
79          *
80          * @param RequestManager $request               HTTPリクエスト処理クラス
81          * @param                                                               なし
82          */
83         function createDetail($request)
84         {
85                 // ページ定義IDとページ定義のレコードシリアル番号を取得
86                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
87                 
88                 $userId         = $this->gEnv->getCurrentUserId();
89                 $this->langId   = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
90                 $act = $request->trimValueOf('act');
91                 $this->serialNo = $request->trimValueOf('serial');              // 選択項目のシリアル番号
92
93                 // 入力値を取得
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
98                 
99                 $replaceNew = false;            // データを再取得するかどうか
100                 if (empty($act)){// 初期起動時
101                         // デフォルト値設定
102                         $this->configId = $defConfigId;         // 呼び出しウィンドウから引き継いだ定義ID
103                         $replaceNew = true;                     // データ再取得
104                 } else if ($act == 'add'){// 新規追加
105                         // 入力チェック
106                         $this->checkInput($name, '名前');
107                         $this->checkInput($tagId, 'タグID');
108                         
109                         // 設定名の重複チェック
110                         for ($i = 0; $i < count($this->paramObj); $i++){
111                                 $targetObj = $this->paramObj[$i]->object;
112                                 if ($name == $targetObj->name){         // 定義名
113                                         $this->setUserErrorMsg('名前が重複しています');
114                                         break;
115                                 }
116                         }
117                         
118                         // エラーなしの場合は、データを登録
119                         if ($this->getMsgCount() == 0){
120                                 // 追加オブジェクト作成
121                                 $newObj = new stdClass;
122                                 $newObj->name   = $name;// 表示名
123                                 $newObj->tagId = $tagId;                // 印刷範囲のタグID
124                                 
125                                 $ret = $this->addPageDefParam($defSerial, $defConfigId, $this->paramObj, $newObj);
126                                 if ($ret){
127                                         $this->setGuidanceMsg('データを追加しました');
128                                         
129                                         $this->configId = $defConfigId;         // 定義定義IDを更新
130                                         $replaceNew = true;                     // データ再取得
131                                 } else {
132                                         $this->setAppErrorMsg('データ追加に失敗しました');
133                                 }
134                         }
135                 } else if ($act == 'update'){           // 設定更新のとき
136                         // 入力値のエラーチェック
137                         $this->checkInput($tagId, 'タグID');
138                         
139                         if ($this->getMsgCount() == 0){                 // エラーのないとき
140                                 // 現在の設定値を取得
141                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
142                                 if ($ret){
143                                         // ウィジェットオブジェクト更新
144                                         $targetObj->tagId       = $tagId;               // 印刷範囲のタグID
145                                 }
146                                 
147                                 // 設定値を更新
148                                 if ($ret) $ret = $this->updatePageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
149                                 if ($ret){
150                                         $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
151                                         
152                                         $replaceNew = true;                     // データ再取得
153                                 } else {
154                                         $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
155                                 }
156                         }
157                 } else if ($act == 'select'){   // 定義IDを変更
158                         $replaceNew = true;                     // データ再取得
159                 }
160                 
161                 // 設定項目選択メニュー作成
162                 $this->createItemMenu();
163                 
164                 // 表示用データを取得
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
170                         }
171                         $this->serialNo = 0;
172                 } else {
173                         if ($replaceNew){
174                                 $ret = $this->getPageDefParam($defSerial, $defConfigId, $this->paramObj, $this->configId, $targetObj);
175                                 if ($ret){
176                                         $name = $targetObj->name;// 名前
177                                         $tagId = $targetObj->tagId;             // 選択範囲のタグID                              
178                                 }
179                         }
180                         $this->serialNo = $this->configId;
181                                 
182                         // 新規作成でないときは、メニューを変更不可にする(画面作成から呼ばれている場合のみ)
183                         if (!empty($defConfigId) && !empty($defSerial)) $this->tmpl->addVar("_widget", "id_disabled", 'disabled');
184                 }
185                 
186                 // 画面にデータを埋め込む
187                 $this->tmpl->addVar("item_name_visible", "name", $name);                // 名前
188                 $this->tmpl->addVar("_widget", "tag_id",        $tagId);                        // タグID
189                                 
190                 $this->tmpl->addVar("_widget", "serial", $this->serialNo);// 選択中のシリアル番号、IDを設定
191                 
192                 // ボタンの表示制御
193                 if (empty($this->serialNo)){            // 新規追加項目を選択しているとき
194                         $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
195                 } else {
196                         $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 「更新」ボタン
197                 }
198                 // ページ定義IDとページ定義のレコードシリアル番号を更新
199                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
200         }
201         /**
202          * 選択用メニューを作成
203          *
204          * @return なし                                               
205          */
206         function createItemMenu()
207         {
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;// 定義名
212                         $selected = '';
213
214                         if ($this->configId == $id) $selected = 'selected';
215                         $row = array(
216                                 'name' => $name,                // 名前
217                                 'value' => $id,         // 定義ID
218                                 'selected' => $selected // 選択中の項目かどうか
219                         );
220                         $this->tmpl->addVars('title_list', $row);
221                         $this->tmpl->parseTemplate('title_list', 'a');
222                 }
223         }
224         /**
225          * デフォルトの名前を取得
226          *
227          * @return string       デフォルト名                                              
228          */
229         function createDefaultName()
230         {
231                 $name = self::DEFAULT_NAME_HEAD;
232                 for ($j = 1; $j < 100; $j++){
233                         $name = self::DEFAULT_NAME_HEAD . $j;
234                         // 設定名の重複チェック
235                         for ($i = 0; $i < count($this->paramObj); $i++){
236                                 $targetObj = $this->paramObj[$i]->object;
237                                 if ($name == $targetObj->name){         // 定義名
238                                         break;
239                                 }
240                         }
241                         // 重複なしのときは終了
242                         if ($i == count($this->paramObj)) break;
243                 }
244                 return $name;
245         }
246         /**
247          * 一覧画面作成
248          *
249          * @param RequestManager $request               HTTPリクエスト処理クラス
250          * @param                                                               なし
251          */
252         function createList($request)
253         {
254                 // ページ定義IDとページ定義のレコードシリアル番号を取得
255                 $this->startPageDefParam($defSerial, $defConfigId, $this->paramObj);
256                 
257                 $userId         = $this->gEnv->getCurrentUserId();
258                 $langId = $this->gEnv->getCurrentLanguage();            // 表示言語を取得
259                 $act = $request->trimValueOf('act');
260                 
261                 if ($act == 'delete'){          // メニュー項目の削除
262                         $listedItem = explode(',', $request->trimValueOf('seriallist'));
263                         $delItems = array();
264                         for ($i = 0; $i < count($listedItem); $i++){
265                                 // 項目がチェックされているかを取得
266                                 $itemName = 'item' . $i . '_selected';
267                                 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
268                                 
269                                 if ($itemValue){                // チェック項目
270                                         $delItems[] = $listedItem[$i];
271                                 }
272                         }
273                         if (count($delItems) > 0){
274                                 $ret = $this->delPageDefParam($defSerial, $defConfigId, $this->paramObj, $delItems);
275                                 if ($ret){              // データ削除成功のとき
276                                         $this->setGuidanceMsg('データを削除しました');
277                                 } else {
278                                         $this->setAppErrorMsg('データ削除に失敗しました');
279                                 }
280                         }
281                 }
282                 // 定義一覧作成
283                 $this->createItemList();
284                 
285                 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
286                 
287                 // ページ定義IDとページ定義のレコードシリアル番号を更新
288                 $this->endPageDefParam($defSerial, $defConfigId, $this->paramObj);
289         }
290         /**
291          * 定義一覧作成
292          *
293          * @return なし                                               
294          */
295         function createItemList()
296         {
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;// 定義名
301                         
302                         $defCount = 0;
303                         if (!empty($id)){
304                                 $defCount = $this->sysDb->getPageDefCount($this->gEnv->getCurrentWidgetId(), $id);
305                         }
306                         $operationDisagled = '';
307                         if ($defCount > 0) $operationDisagled = 'disabled';
308                         $row = array(
309                                 'index' => $i,
310                                 'ope_disabled' => $operationDisagled,                   // 選択可能かどうか
311                                 'name' => $this->convertToDispString($name),            // 名前
312                                 'tag_id' => $this->convertToDispString($targetObj->tagId),      // タグID
313                                 'def_count' => $defCount                                                        // 使用数
314                         );
315                         $this->tmpl->addVars('itemlist', $row);
316                         $this->tmpl->parseTemplate('itemlist', 'a');
317                         
318                         // シリアル番号を保存
319                         $this->serialArray[] = $id;
320                 }
321         }
322 }
323 ?>