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-2015 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/admin_ec_mainBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/ec_mainDelivMethodDb.php');
19 class admin_ec_mainDelivmethodWidgetContainer extends admin_ec_mainBaseWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $langId; // 表示言語
23 private $iWidgetId; // インナーウィジェットID
24 private $serialNo; // 選択中の項目のシリアル番号
25 private $serialArray = array(); // 表示されている項目シリアル番号
26 const IWIDGET_TYPE = 'DELIVERY'; // 配送方法用インナーウィジェット
27 const DELIV_TASK = 'delivmethod'; // 配送方法選択画面表示用
32 function __construct()
35 parent::__construct();
38 $this->db = new ec_mainDelivMethodDb();
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 == 'delivmethod_detail'){ // 詳細画面
54 return 'admin_delivery_detail.tmpl.html';
56 return 'admin_delivery.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 == 'delivmethod_detail'){ // 詳細画面
72 return $this->createDetail($request);
74 return $this->createList($request);
80 * @param RequestManager $request HTTPリクエスト処理クラス
83 function createList($request)
85 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
86 $act = $request->trimValueOf('act');
88 if ($act == 'delete'){ // 項目削除の場合
89 $listedItem = explode(',', $request->trimValueOf('seriallist'));
91 for ($i = 0; $i < count($listedItem); $i++){
93 $itemName = 'item' . $i . '_selected';
94 $itemValue = ($request->trimValueOf($itemName) == 'on') ? 1 : 0;
96 if ($itemValue){ // チェック項目
97 $delItems[] = $listedItem[$i];
100 if (count($delItems) > 0){
101 $ret = $this->db->deleteDelivMethodDefBySerial($delItems);
102 if ($ret){ // データ削除成功のとき
103 $this->setGuidanceMsg('データを削除しました');
105 $this->setAppErrorMsg('データ削除に失敗しました');
110 $this->db->getAllDelivMethodDef($this->langId, 0/*デフォルトのセットID*/, array($this, 'delivDefLoop'));
112 $this->tmpl->addVar("_widget", "serial_list", implode($this->serialArray, ','));// 表示項目のシリアル番号を設定
115 $url = $this->gPage->createWidgetCmdUrl($this->gEnv->getCurrentWidgetId(), ''/*送信元ウィジェット指定なし*/,
116 'task=' . self::DELIV_TASK . '&' . M3_REQUEST_PARAM_OPERATION_COMMAND . '=' . M3_REQUEST_CMD_PREVIEW, $this->gEnv->getDefaultPageId());
117 $this->tmpl->addVar("_widget", "url", $this->getUrl($url, true));
122 * @param RequestManager $request HTTPリクエスト処理クラス
125 function createDetail($request)
127 $this->langId = $this->gEnv->getCurrentLanguage(); // 表示言語を取得
128 $act = $request->trimValueOf('act');
129 $this->serialNo = $request->trimValueOf('serial'); // 選択項目のシリアル番号
130 if (empty($this->serialNo)) $this->serialNo = 0;
132 $this->id = $request->trimValueOf('id'); // ID
133 $addid = $request->trimValueOf('item_id'); // ID
134 $name = $request->trimValueOf('item_name'); // 名前
135 $desc = $request->valueOf('item_desc'); // 説明
136 $index = $request->trimValueOf('item_index'); // 表示順
137 $visible = ($request->trimValueOf('item_visible') == 'on') ? 1 : 0; // 表示状態
138 $this->iWidgetId = $request->trimValueOf('item_iwidget'); // インナーウィジェットID
139 $param = ''; // インナーウィジェット用パラメータ
141 $replaceNew = false; // データを再取得するかどうか
142 if ($act == 'add'){ // 新規追加のとき
144 $this->checkSingleByte($addid, 'ID');
145 $this->checkInput($name, '表示名');
146 $this->checkNumeric($index, '表示順');
149 if ($this->db->isExistsDelivMethodId($this->langId, 0/*デフォルトのセットID*/, $addid)) $this->setMsg(self::MSG_USER_ERR, 'IDが重複しています');
152 if ($this->getMsgCount() == 0){
153 if (!empty($this->iWidgetId)){
154 // インナーウィジェットでのパラメータの更新に成功した場合
155 $this->updateIWidgetParam($this->iWidgetId, $this->id, $param, $optionParam, true);
157 // インナーウィジェット内で発生したエラーを取得
158 $this->getGlobalMsg();
163 if ($this->getMsgCount() == 0){
164 $ret = $this->db->updateDelivMethodDef($addid, $this->langId, 0/*デフォルトのセットID*/, $name, $desc, $index, $visible, $this->iWidgetId, $param);
165 if ($ret){ // データ追加成功のとき
166 $this->setMsg(self::MSG_GUIDANCE, 'データを追加しました');
168 $this->id = $addid; // 新規IDに更新
169 $replaceNew = true; // データを再取得
171 $this->setMsg(self::MSG_APP_ERR, 'データ追加に失敗しました');
174 } else if ($act == 'update'){ // 行更新のとき
176 $this->checkInput($name, '表示名');
177 $this->checkNumeric($index, '表示順');
180 if ($this->getMsgCount() == 0){
181 if (!empty($this->iWidgetId)){
182 // インナーウィジェットでのパラメータの更新に成功した場合
183 $this->updateIWidgetParam($this->iWidgetId, $this->id, $param, $optionParam, true);
185 // インナーウィジェット内で発生したエラーを取得
186 $this->getGlobalMsg();
191 if ($this->getMsgCount() == 0){
192 $ret = $this->db->updateDelivMethodDef($this->id, $this->langId, 0/*デフォルトのセットID*/, $name, $desc, $index, $visible, $this->iWidgetId, $param);
193 if ($ret){ // 更新成功のとき
194 $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
195 $replaceNew = true; // データを再取得
197 $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
200 } else if ($act == 'delete'){ // 削除のとき
201 $ret = $this->db->deleteDelivMethodDefBySerial(array($this->serialNo));
202 if ($ret){ // データ更新成功のとき
203 $this->setMsg(self::MSG_GUIDANCE, '項目を削除しました');
205 $this->setMsg(self::MSG_APP_ERR, '項目削除に失敗しました');
207 } else if ($act == 'selectcalc'){ // 計算方法選択のとき
208 if (!empty($this->iWidgetId)){
209 // パラメータをインナーウィジェットに設定
210 $optionParam = new stdClass;
211 $optionParam->init = true; // 初期データ取得
212 $this->setIWidgetParam($this->iWidgetId, $this->id, $row['do_param'], $optionParam, true);
216 $this->id = $this->db->getDelivMethodDefIdBySerial($this->serialNo); // 選択中の配送項目ID
217 if (empty($this->id)){ // 空のときは新規とする
223 $index = $this->db->getMaxDelivMethodIndex($this->langId, 0/*デフォルトのセットID*/) + 1; // 表示順
224 $visible = 1; // 表示状態
225 $this->iWidgetId = ''; // インナーウィジェットID
227 $replaceNew = true; // データを再取得
232 $ret = $this->db->getDelivMethodDef($this->id, $this->langId, 0/*デフォルトのセットID*/, $row);
234 $this->serialNo = $row['do_serial']; // シリアル番号
235 $addid = $row['do_id']; // ID
236 $name = $row['do_name']; // 名前
237 $desc = $row['do_description']; // 説明
238 $index = $row['do_index']; // 表示順
239 $visible = $row['do_visible']; // 表示状態
240 $this->iWidgetId = $row['do_iwidget_id']; // インナーウィジェットID
241 if (!empty($this->iWidgetId)){
242 // パラメータをインナーウィジェットに設定
243 $optionParam = new stdClass;
244 $optionParam->init = true; // 初期データ取得
245 $this->setIWidgetParam($this->iWidgetId, $this->id, $row['do_param'], $optionParam, true);
250 if (empty($this->serialNo)){ // シリアル番号が空のときは新規とする
251 $this->tmpl->addVar("_widget", "id_label", ''); // 選択項目のIDラベル
252 $this->tmpl->addVar("_widget", "new_selected", 'checked');// ユーザIDが0のときは新規追加をチェック状態にする
254 $this->tmpl->setAttribute('add_id_field', 'visibility', 'visible');// 新規ID入力フィールド表示
255 $this->tmpl->setAttribute('add_button', 'visibility', 'visible');// 新規登録ボタン表示
257 $this->tmpl->addVar("_widget", "id_label", $this->id); // 選択項目のIDラベル
258 $this->tmpl->setAttribute('update_button', 'visibility', 'visible');// 更新ボタン表示
260 $this->tmpl->addVar("_widget", "serial", $this->serialNo);
261 $this->tmpl->addVar("_widget", "id", $this->id); // ID
262 $this->tmpl->addVar("add_id_field", "add_id", $addid); // 追加ID
263 $this->tmpl->addVar("_widget", "name", $name); // 名前
264 $this->tmpl->addVar("_widget", "index", $index); // 表示順
265 $this->tmpl->addVar("_widget", "desc", $desc); // 説明
267 if ($visible){ // 項目の表示
268 $visibleStr = 'checked';
270 $this->tmpl->addVar("_widget", "visible", $visibleStr); // 表示状態
272 // インナーウィジェット選択メニューを作成
273 $this->_db->getAllIWidgetListByType($this->gEnv->getCurrentWidgetId(), self::IWIDGET_TYPE, array($this, 'iWidgetLoop'));
275 // 選択中のインナーウィジェットの管理画面を取得
276 if (!empty($this->iWidgetId)){
277 $innerContent = $this->getIWidgetContent($this->iWidgetId, $this->id, true); // 管理者画面を取得
278 $this->tmpl->addVar("_widget", "iwidget", $innerContent);
282 //$this->tmpl->addVar("_widget", "root_url", $this->gEnv->getRootUrl());
283 //$this->tmpl->addVar("_widget", "widget_sc_url", $this->gEnv->getCurrentWidgetScriptsUrl());
286 * 取得した配送方法定義をテンプレートに設定する
288 * @param int $index 行番号(0~)
289 * @param array $fetchedRow フェッチ取得した行
290 * @param object $param 未使用
291 * @return bool true=処理続行の場合、false=処理終了の場合
293 function delivDefLoop($index, $fetchedRow, $param)
296 if ($fetchedRow['do_id'] == $this->id){
297 $checked = 'checked';
300 if ($fetchedRow['do_visible']){ // 項目の表示
301 $visible = 'checked';
304 'serial' => $fetchedRow['do_serial'], // シリアル番号
305 'index' => $index, // 項目番号
306 'id' => $this->convertToDispString($fetchedRow['do_id']), // ID
307 'name' => $this->convertToDispString($fetchedRow['do_name']), // 表示名
308 'view_index' => $this->convertToDispString($fetchedRow['do_index']), // 表示順
309 'visible' => $visible, // メニュー項目表示制御
310 'checked' => $checked // 選択中かどうか
312 $this->tmpl->addVars('delivmethod_list', $row);
313 $this->tmpl->parseTemplate('delivmethod_list', 'a');
316 $this->serialArray[] = $fetchedRow['do_serial'];
320 * 取得した配送方法インナーウィジェットをテンプレートに設定する
322 * @param int $index 行番号(0~)
323 * @param array $fetchedRow フェッチ取得した行
324 * @param object $param 未使用
325 * @return bool true=処理続行の場合、false=処理終了の場合
327 function iWidgetLoop($index, $fetchedRow, $param)
329 $id = $fetchedRow['iw_widget_id'] . ',' . $fetchedRow['iw_id'];
331 if ($id == $this->iWidgetId){ // 選択中のインナーウィジェット
332 $selected = 'selected';
336 'value' => $id, // ID
337 'name' => $this->convertToDispString($fetchedRow['iw_name']), // 表示名
338 'selected' => $selected // 選択中かどうか
340 $this->tmpl->addVars('iwidget_list', $row);
341 $this->tmpl->parseTemplate('iwidget_list', 'a');