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-2008 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: admin_reserve_mainResourceWidgetContainer.php 642 2008-05-22 12:25:05Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_reserve_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/reserve_mainDb.php');
19 class admin_reserve_mainResourceWidgetContainer extends admin_reserve_mainBaseWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $mainDb; // DB接続オブジェクト
23 private $sysDb; // システムDBオブジェクト
24 private $serialNo; // シリアル番号
25 private $firstNo; // 項目番号
26 private $configType; // 設定タイプ
27 private $serialArray = array(); // 表示されている項目シリアル番号
28 const DEFAULT_RES_TYPE = 0; // デフォルトの設定タイプ(常設)
29 const DEFAULT_CONFIG_ID = 0; // デフォルトの設定ID
30 const DEFAULT_LIST_COUNT = 20; // 最大リスト表示数
35 function __construct()
37 global $gInstanceManager;
40 parent::__construct();
43 $this->db = new reserve_mainDb();
44 $this->sysDb = $gInstanceManager->getSytemDbObject();
49 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
50 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
52 * @param RequestManager $request HTTPリクエスト処理クラス
53 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
54 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
56 function _setTemplate($request, &$param)
58 $task = $request->trimValueOf('task');
59 if ($task == 'resource_detail'){ // 詳細画面
60 return 'admin_resource_detail.tmpl.html';
62 return 'admin_resource.tmpl.html';
68 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
70 * @param RequestManager $request HTTPリクエスト処理クラス
71 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
74 function _assign($request, &$param)
76 $task = $request->trimValueOf('task');
77 if ($task == 'resource_detail'){ // 詳細画面
78 return $this->createDetail($request);
80 return $this->createList($request);
86 * @param RequestManager $request HTTPリクエスト処理クラス
89 function createList($request)
93 $pageNo = $request->trimValueOf('page'); // ページ番号
94 if (empty($pageNo)) $pageNo = 1;
97 $maxListCount = self::DEFAULT_LIST_COUNT; // 表示項目数
99 $act = $request->trimValueOf('act');
100 if ($act == 'delete'){ // 項目削除の場合
101 $listedItem = explode(',', $request->trimValueOf('seriallist'));
103 for ($i = 0; $i < count($listedItem); $i++){
105 $itemName = 'item' . $i . '_selected';
106 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
108 if ($itemValue){ // チェック項目
109 $delItems[] = $listedItem[$i];
112 if (count($delItems) > 0){
113 $ret = $this->db->deleteResourceById($delItems);
114 if ($ret){ // データ削除成功のとき
115 $this->setGuidanceMsg('データを削除しました');
117 $this->setAppErrorMsg('データ削除に失敗しました');
122 $totalCount = $this->db->getAllResourceListCount(self::DEFAULT_RES_TYPE, self::DEFAULT_CONFIG_ID);
125 $pageCount = (int)(($totalCount -1) / $maxListCount) + 1; // 総ページ数
126 if ($pageNo < 1) $pageNo = 1;
127 if ($pageNo > $pageCount) $pageNo = $pageCount;
128 $this->firstNo = ($pageNo -1) * $maxListCount + 1; // 先頭番号
131 $this->db->getAllResourceList(self::DEFAULT_RES_TYPE, self::DEFAULT_CONFIG_ID, $maxListCount, ($pageNo -1) * $maxListCount, array($this, 'resourceListLoop'));
135 if ($pageCount > 1){ // ページが2ページ以上のときリンクを作成
136 for ($i = 1; $i <= $pageCount; $i++){
137 //$linkUrl = $this->currentPageUrl . '&category=' . $this->categoryId . '&page=' . $i;
139 $link = ' ' . $i;
141 //$link = ' <a href="' . $linkUrl . '" >' . $i . '</a>';
142 $link = ' <a href="#" onclick="selpage(\'' . $i . '\');return false;">' . $i . '</a>';
147 $this->tmpl->addVar("_widget", "page_link", $pageLink);
148 $this->tmpl->addVar("_widget", "page", $pageNo); // 現在のページ番号
150 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
155 * @param RequestManager $request HTTPリクエスト処理クラス
158 function createDetail($request)
163 $now = date("Y/m/d H:i:s"); // 現在日時
164 $userId = $gEnvManager->getCurrentUserId();
165 $langId = $gEnvManager->getCurrentLanguage(); // 表示言語を取得
167 $act = $request->trimValueOf('act');
168 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号(シリアル番号はリソースIDを使用する)
170 $name = $request->trimValueOf('item_name'); // 名前
171 $desc = $request->trimValueOf('item_desc'); // 説明
172 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0; // 表示状態
173 $index = $request->trimValueOf('item_index'); // ソート順
175 $replaceNew = false; // データを再取得するかどうか
176 if ($act == 'add'){ // 項目追加の場合
178 $this->checkInput($name, '名前');
179 $this->checkNumeric($index, '表示順');
182 if ($this->getMsgCount() == 0){
183 $ret = $this->db->updateResource(0/*新規追加*/, self::DEFAULT_RES_TYPE, self::DEFAULT_CONFIG_ID, $name, $desc, $visible, $index, $newResourceId);
185 $this->setGuidanceMsg('データを追加しました');
187 $this->serialNo = $newResourceId;
189 $this->setAppErrorMsg('データ追加に失敗しました');
192 } else if ($act == 'update'){ // 項目更新の場合
193 if (empty($this->serialNo)){
194 $this->setUserErrorMsg('更新するリソースが選択されていません');
197 $this->checkInput($name, '名前');
198 $this->checkNumeric($index, '表示順');
201 if ($this->getMsgCount() == 0){
202 $ret = $this->db->updateResource($this->serialNo, self::DEFAULT_RES_TYPE, self::DEFAULT_CONFIG_ID, $name, $desc, $visible, $index, $newResourceId);
204 $this->setGuidanceMsg('データを更新しました');
205 $replaceNew = true; // 会員情報を再取得
207 $this->setAppErrorMsg('データ更新に失敗しました');
210 } else if ($act == 'delete'){ // 項目削除の場合
211 if (empty($this->serialNo)){
212 $this->setUserErrorMsg('削除するリソースが選択されていません');
215 if ($this->getMsgCount() == 0){
216 $ret = $this->db->deleteResourceById(array($this->serialNo));
217 if ($ret){ // データ削除成功のとき
218 $this->setGuidanceMsg('データを削除しました');
220 $this->setAppErrorMsg('データ削除に失敗しました');
223 } else if ($act == 'search'){ // 検索再実行
225 if (empty($this->serialNo)){
227 $index = $this->db->getMaxResourceIndex(self::DEFAULT_RES_TYPE, self::DEFAULT_CONFIG_ID) + 1;
228 $visible = 1; // 表示状態
230 $replaceNew = true; // 会員情報を再取得
235 $ret = $this->db->getResourceById($this->serialNo, $row);
238 $name = $this->convertToDispString($row['rr_name']); // 名前
239 $desc = $this->convertToDispString($row['rr_description']); // 説明
240 $index = $this->convertToDispString($row['rr_sort_order']); // 表示順
241 $visible = $row['rr_visible']; // 表示状態
245 // #### 更新、新規登録部をを作成 ####
246 $this->tmpl->addVar("_widget", "name", $name); // 名前
247 $this->tmpl->addVar("_widget", "desc", $desc); // 説明
248 $this->tmpl->addVar("_widget", "index", $index); // 表示順
250 if ($visible){ // 項目の表示
251 $visibleStr = 'checked';
253 $this->tmpl->addVar("_widget", "visible", $visibleStr); // 表示状態
256 if (empty($this->serialNo)){ // 新規追加項目を選択しているとき
257 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 「新規追加」ボタン
260 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 更新、削除ボタン
263 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
266 * 取得したデータをテンプレートに設定する
268 * @param int $index 行番号(0~)
269 * @param array $fetchedRow フェッチ取得した行
270 * @param object $param 未使用
271 * @return bool true=処理続行の場合、false=処理終了の場合
273 function resourceListLoop($index, $fetchedRow, $param)
279 if ($index % 2 != 0){
280 $lineColor = 'class="even"'; // 偶数行
282 $serial = $fetchedRow['rr_id'];// リソースIDをシリアル番号とする
284 if ($fetchedRow['rr_visible']){ // 項目の表示
285 $visible = 'checked';
288 'line_color' => $lineColor, // 行のカラー
289 'no' => $this->firstNo + $index, // 行番号
290 'index' => $index, // 項目番号
291 'serial' => $serial, // シリアル番号
293 'view_index' => $this->convertToDispString($fetchedRow['rr_sort_order']), // 表示順
294 'name' => $this->convertToDispString($fetchedRow['rr_name']), // 名前
295 'visible' => $visible // 公開
297 $this->tmpl->addVars('itemlist', $row);
298 $this->tmpl->parseTemplate('itemlist', 'a');
301 $this->serialArray[] = $serial;