[15680] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[20764] | 5 | * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved. |
---|
[15680] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
[15680] | 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
[15680] | 26 | |
---|
| 27 | /** |
---|
| 28 | * デザイン管理 のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
| 32 | * @version $Id$ |
---|
| 33 | */ |
---|
[20345] | 34 | class LC_Page_Admin_Design extends LC_Page_Admin_Ex { |
---|
[15680] | 35 | |
---|
[18212] | 36 | // }}} |
---|
| 37 | // {{{ functions |
---|
[15680] | 38 | |
---|
[18212] | 39 | /** |
---|
| 40 | * Page を初期化する. |
---|
| 41 | * |
---|
| 42 | * @return void |
---|
| 43 | */ |
---|
| 44 | function init() { |
---|
| 45 | parent::init(); |
---|
| 46 | $this->tpl_mainpage = 'design/index.tpl'; |
---|
[20538] | 47 | $this->tpl_subno = 'layout'; |
---|
| 48 | $this->tpl_mainno = 'design'; |
---|
[20911] | 49 | $this->tpl_maintitle = 'デザイン管理'; |
---|
[19719] | 50 | $this->tpl_subtitle = 'レイアウト設定'; |
---|
[19713] | 51 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 52 | $this->arrTarget = $masterData->getMasterData("mtb_target"); |
---|
[20560] | 53 | $this->arrDeviceType = $masterData->getMasterData('mtb_device_type'); |
---|
[18212] | 54 | } |
---|
[15680] | 55 | |
---|
[18212] | 56 | /** |
---|
| 57 | * Page のプロセス. |
---|
| 58 | * |
---|
| 59 | * @return void |
---|
| 60 | */ |
---|
| 61 | function process() { |
---|
[19661] | 62 | $this->action(); |
---|
| 63 | $this->sendResponse(); |
---|
| 64 | } |
---|
[15680] | 65 | |
---|
[19661] | 66 | /** |
---|
| 67 | * Page のアクション. |
---|
| 68 | * |
---|
| 69 | * @return void |
---|
| 70 | */ |
---|
| 71 | function action() { |
---|
[18212] | 72 | $objLayout = new SC_Helper_PageLayout_Ex(); |
---|
[20830] | 73 | $objFormParam = new SC_FormParam_Ex(); |
---|
| 74 | $this->lfInitParam($objFormParam, intval($_REQUEST['bloc_cnt'])); |
---|
| 75 | $objFormParam->setParam($_REQUEST); |
---|
[15680] | 76 | |
---|
[20830] | 77 | $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); |
---|
| 78 | $this->page_id = $objFormParam->getValue('page_id', 1); |
---|
[15680] | 79 | |
---|
[20041] | 80 | switch ($this->getMode()) { |
---|
[18212] | 81 | // 新規ブロック作成 |
---|
[19713] | 82 | case 'new_bloc': |
---|
[20830] | 83 | SC_Response_Ex::sendRedirect('bloc.php', array("device_type_id" => $this->device_type_id)); |
---|
[18212] | 84 | exit; |
---|
[19713] | 85 | break; |
---|
[16935] | 86 | |
---|
[18212] | 87 | // 新規ページ作成 |
---|
[19713] | 88 | case 'new_page': |
---|
[20830] | 89 | SC_Response_Ex::sendRedirect('main_edit.php', array("device_type_id" => $this->device_type_id)); |
---|
[18212] | 90 | exit; |
---|
[19713] | 91 | break; |
---|
[15680] | 92 | |
---|
[20830] | 93 | // プレビュー |
---|
[19713] | 94 | case 'preview': |
---|
[20830] | 95 | $this->placingBlocs($objFormParam, true); |
---|
| 96 | $filename = $this->savePreviewData($this->page_id, $objLayout); |
---|
| 97 | $_SESSION['preview'] = 'ON'; |
---|
| 98 | SC_Response_Ex::sendRedirectFromUrlPath('preview/' . DIR_INDEX_PATH, array('filename' => $filename)); |
---|
| 99 | exit; |
---|
[15680] | 100 | |
---|
[20830] | 101 | // 編集実行 |
---|
| 102 | case 'confirm': |
---|
| 103 | $this->placingBlocs($objFormParam); |
---|
| 104 | $arrQueryString = array("device_type_id" => $this->device_type_id, "page_id" => $this->page_id, 'msg' => 'on'); |
---|
| 105 | SC_Response_Ex::reload($arrQueryString, true); |
---|
| 106 | exit; |
---|
[15680] | 107 | |
---|
[19713] | 108 | break; |
---|
[15680] | 109 | |
---|
[19713] | 110 | // データ削除処理 |
---|
| 111 | case 'delete': |
---|
| 112 | //ベースデータでなければファイルを削除 |
---|
[20830] | 113 | if ($objLayout->isEditablePage($this->device_type_id, $this->page_id)) { |
---|
| 114 | $objLayout->lfDelPageData($this->page_id, $this->device_type_id); |
---|
| 115 | SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id), true); |
---|
[19713] | 116 | exit; |
---|
| 117 | } |
---|
| 118 | break; |
---|
| 119 | |
---|
| 120 | default: |
---|
[20830] | 121 | // 完了メッセージ表示 |
---|
| 122 | if (isset($_GET['msg']) && $_GET['msg'] == 'on') { |
---|
| 123 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
[18212] | 124 | } |
---|
| 125 | } |
---|
[15680] | 126 | |
---|
[20830] | 127 | $this->arrBlocs = $this->getLayout($this->device_type_id, $this->page_id, $objLayout); |
---|
| 128 | $this->bloc_cnt = count($this->arrBlocs); |
---|
| 129 | // 編集中のページ |
---|
| 130 | $this->arrPageData = $objLayout->getPageProperties($this->device_type_id, $this->page_id); |
---|
| 131 | // 編集可能ページ一覧 |
---|
| 132 | $this->arrEditPage = $objLayout->getPageProperties($this->device_type_id, null); |
---|
| 133 | //サブタイトルを取得 |
---|
[20911] | 134 | $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle; |
---|
[19661] | 135 | } |
---|
[15680] | 136 | |
---|
[18212] | 137 | /** |
---|
| 138 | * デストラクタ. |
---|
| 139 | * |
---|
| 140 | * @return void |
---|
[18211] | 141 | */ |
---|
| 142 | function destroy() { |
---|
| 143 | parent::destroy(); |
---|
| 144 | } |
---|
[15680] | 145 | |
---|
[18211] | 146 | /** |
---|
[20830] | 147 | * フォームパラメータの初期化を行う. |
---|
[18211] | 148 | * |
---|
[20830] | 149 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス. |
---|
| 150 | * @param integer $bloc_cnt ブロック数 |
---|
| 151 | * @return void |
---|
[18211] | 152 | */ |
---|
[20830] | 153 | function lfInitParam(&$objFormParam, $bloc_cnt = 0) { |
---|
| 154 | $objFormParam->addParam("ページID", "page_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 155 | $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 156 | $objFormParam->addParam("ブロック数", "bloc_cnt", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
[15680] | 157 | |
---|
[20830] | 158 | for ($i = 1; $i <= $bloc_cnt; $i++) { |
---|
| 159 | $objFormParam->addParam("ブロック名", "name_" . $i, STEXT_LEN, 'a', array("MAX_LENGTH_CHECK", "GRAPH_CHECK")); |
---|
| 160 | $objFormParam->addParam("ブロックID", "id_" . $i, INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 161 | $objFormParam->addParam("ターゲットID", "target_id_" . $i, STEXT_LEN, 'a', array("MAX_LENGTH_CHECK", "ALNUM_CHECK")); |
---|
| 162 | $objFormParam->addParam("TOP座標", "top_" . $i, INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 163 | $objFormParam->addParam("全ページ", "anywhere_" . $i, INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
[18211] | 164 | } |
---|
[20830] | 165 | } |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | * ブロックのレイアウト情報を取得する. |
---|
| 169 | * |
---|
| 170 | * @param integer $device_type_id 端末種別ID |
---|
| 171 | * @param integer $page_id ページID |
---|
| 172 | * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス |
---|
| 173 | * @return array レイアウト情報の配列 |
---|
| 174 | */ |
---|
| 175 | function getLayout($device_type_id, $page_id, &$objLayout) { |
---|
| 176 | $arrResults = array(); |
---|
| 177 | $i = 0; |
---|
| 178 | |
---|
| 179 | // レイアウト済みのブロックデータを追加 |
---|
| 180 | $arrBlocPos = $objLayout->getBlocPositions($device_type_id, $page_id); |
---|
| 181 | foreach($arrBlocPos as $arrBloc){ |
---|
| 182 | $this->copyBloc($arrResults, $arrBloc, $i); |
---|
| 183 | $i++; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | // 未使用のブロックデータを追加 |
---|
| 187 | $arrBloc = $objLayout->getBlocs($device_type_id); |
---|
| 188 | foreach($arrBloc as $arrBloc){ |
---|
| 189 | if (!$this->existsBloc($arrBloc, $arrResults)) { |
---|
| 190 | $arrBloc['target_id'] = TARGET_ID_UNUSED; |
---|
| 191 | $this->copyBloc($arrResults, $arrBloc, $i); |
---|
| 192 | $i++; |
---|
[18211] | 193 | } |
---|
| 194 | } |
---|
[20830] | 195 | return $arrResults; |
---|
| 196 | } |
---|
[15680] | 197 | |
---|
[20830] | 198 | /** |
---|
| 199 | * ブロック情報の配列をコピーする. |
---|
| 200 | * |
---|
| 201 | * @param array $arrDest コピー先ブロック情報 |
---|
| 202 | * @param array $arrFrom コピー元ブロック情報 |
---|
| 203 | * @param integer $cnt 配列番号 |
---|
| 204 | * @return void |
---|
| 205 | */ |
---|
| 206 | function copyBloc(&$arrDest, $arrFrom, $cnt) { |
---|
| 207 | $arrDest[$cnt]['target_id'] = $this->arrTarget[$arrFrom['target_id']]; |
---|
| 208 | $arrDest[$cnt]['bloc_id'] = $arrFrom['bloc_id']; |
---|
| 209 | $arrDest[$cnt]['bloc_row'] = $arrFrom['bloc_row']; |
---|
| 210 | $arrDest[$cnt]['anywhere'] = $arrFrom['anywhere']; |
---|
| 211 | $arrDest[$cnt]['name'] = $arrFrom['bloc_name']; |
---|
[18211] | 212 | } |
---|
[15680] | 213 | |
---|
[18211] | 214 | /** |
---|
[20830] | 215 | * ブロックIDがコピー先の配列に追加されているかのチェックを行う. |
---|
[18211] | 216 | * |
---|
[20830] | 217 | * @param array $arrBloc ブロックの配列 |
---|
| 218 | * @param array $arrToBlocs チェックを行うデータ配列 |
---|
[18211] | 219 | * @return bool 存在する場合 true |
---|
| 220 | */ |
---|
[20830] | 221 | function existsBloc($arrBloc, $arrToBlocs) { |
---|
| 222 | foreach($arrToBlocs as $arrToBloc){ |
---|
| 223 | if ($arrBloc['bloc_id'] === $arrToBloc['bloc_id'] ) { |
---|
[18211] | 224 | return true; |
---|
| 225 | } |
---|
| 226 | } |
---|
| 227 | return false; |
---|
| 228 | } |
---|
[15829] | 229 | |
---|
[18211] | 230 | /** |
---|
[20830] | 231 | * プレビューするデータを DB に保存する. |
---|
[18211] | 232 | * |
---|
[20830] | 233 | * @param integer $page_id プレビューを行うページID |
---|
| 234 | * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス |
---|
| 235 | * @return string プレビューを行う tpl_mainpage ファイル名 |
---|
[18211] | 236 | */ |
---|
[20830] | 237 | function savePreviewData($page_id, &$objLayout){ |
---|
| 238 | $arrPageData = $objLayout->getPageProperties(DEVICE_TYPE_PC, $page_id); |
---|
| 239 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 240 | $arrPageData[0]['page_id'] = 0; |
---|
| 241 | $objQuery->update('dtb_pagelayout', $arrPageData[0], 'page_id = 0 AND device_type_id = ?', array(DEVICE_TYPE_PC)); |
---|
| 242 | return $arrPageData[0]['filename']; |
---|
[18211] | 243 | } |
---|
[16396] | 244 | |
---|
[18211] | 245 | /** |
---|
[20830] | 246 | * ブロックを配置する. |
---|
[18211] | 247 | * |
---|
[20830] | 248 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 249 | * @param boolean $is_preview プレビュー時の場合 true |
---|
[18211] | 250 | * @return void |
---|
| 251 | */ |
---|
[20830] | 252 | function placingBlocs(&$objFormParam, $is_preview = false) { |
---|
| 253 | $page_id = $is_preview ? 0 : $objFormParam->getValue('page_id'); |
---|
| 254 | $device_type_id = $objFormParam->getValue('device_type_id'); |
---|
| 255 | $bloc_cnt = $objFormParam->getValue('bloc_cnt'); |
---|
| 256 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 257 | $objQuery->begin(); |
---|
| 258 | $objQuery->delete("dtb_blocposition", "page_id = ? AND device_type_id = ?", |
---|
| 259 | array($page_id, $device_type_id)); |
---|
| 260 | $arrTargetFlip = array_flip($this->arrTarget); |
---|
| 261 | for ($i = 1; $i <= $bloc_cnt; $i++) { |
---|
| 262 | // bloc_id が取得できない場合は INSERT しない |
---|
| 263 | $id = $objFormParam->getValue('id_' . $i); |
---|
| 264 | if (SC_Utils_Ex::isBlank($id)) { |
---|
| 265 | continue; |
---|
| 266 | } |
---|
| 267 | // 未使用は INSERT しない |
---|
| 268 | $arrParams['target_id'] = $arrTargetFlip[$objFormParam->getValue('target_id_' . $i)]; |
---|
| 269 | if ($arrParams['target_id'] == TARGET_ID_UNUSED) { |
---|
| 270 | continue; |
---|
| 271 | } |
---|
[15680] | 272 | |
---|
[20830] | 273 | // 他のページに anywhere が存在する場合は INSERT しない |
---|
| 274 | $arrParams['anywhere'] = intval($objFormParam->getValue('anywhere_' . $i)); |
---|
| 275 | if ($arrParams['anywhere'] == 1) { |
---|
| 276 | $count = $objQuery->count('dtb_blocposition', 'anywhere = 1 AND bloc_id = ? AND device_type_id = ?', |
---|
| 277 | array($id, $device_type_id)); |
---|
| 278 | if ($count > 0) { |
---|
| 279 | continue; |
---|
| 280 | } |
---|
| 281 | } |
---|
[16935] | 282 | |
---|
[20830] | 283 | $arrParams['device_type_id'] = $device_type_id; |
---|
| 284 | $arrParams['page_id'] = $page_id; |
---|
| 285 | $arrParams['bloc_id'] = $id; |
---|
| 286 | $arrParams['bloc_row'] = $objFormParam->getValue('top_' . $i); |
---|
[16935] | 287 | |
---|
[20830] | 288 | $objQuery->insert("dtb_blocposition", $arrParams); |
---|
[18211] | 289 | } |
---|
[20830] | 290 | $objQuery->commit(); |
---|
[18211] | 291 | } |
---|
[15680] | 292 | } |
---|
| 293 | ?> |
---|