[16430] | 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. |
---|
[16430] | 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. |
---|
[16430] | 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
| 26 | require_once DATA_REALDIR . 'module/Tar.php'; |
---|
| 27 | require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_FileManager_Ex.php'; |
---|
[16430] | 28 | |
---|
| 29 | /** |
---|
| 30 | * テンプレート設定 のページクラス. |
---|
| 31 | * |
---|
| 32 | * @package Page |
---|
| 33 | * @author LOCKON CO.,LTD. |
---|
| 34 | * @version $Id$ |
---|
| 35 | */ |
---|
[20345] | 36 | class LC_Page_Admin_Design_Template extends LC_Page_Admin_Ex { |
---|
[16430] | 37 | |
---|
| 38 | // }}} |
---|
| 39 | // {{{ functions |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Page を初期化する. |
---|
| 43 | * |
---|
| 44 | * @return void |
---|
| 45 | */ |
---|
| 46 | function init() { |
---|
| 47 | parent::init(); |
---|
[19725] | 48 | $this->tpl_mainpage = 'design/template.tpl'; |
---|
| 49 | $this->tpl_subno = 'template'; |
---|
[20538] | 50 | $this->tpl_mainno = 'design'; |
---|
[20911] | 51 | $this->tpl_maintitle = 'デザイン管理'; |
---|
[19725] | 52 | $this->tpl_subtitle = 'テンプレート設定'; |
---|
| 53 | $this->arrErr = array(); |
---|
| 54 | $this->arrForm = array(); |
---|
| 55 | ini_set("max_execution_time", 300); |
---|
[20560] | 56 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 57 | $this->arrDeviceType = $masterData->getMasterData('mtb_device_type'); |
---|
[16430] | 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * Page のプロセス. |
---|
| 62 | * |
---|
| 63 | * @return void |
---|
| 64 | */ |
---|
| 65 | function process() { |
---|
[19661] | 66 | $this->action(); |
---|
| 67 | $this->sendResponse(); |
---|
| 68 | } |
---|
[16768] | 69 | |
---|
[19661] | 70 | /** |
---|
| 71 | * Page のアクション. |
---|
| 72 | * |
---|
| 73 | * @return void |
---|
| 74 | */ |
---|
| 75 | function action() { |
---|
[20863] | 76 | $objFormParam = new SC_FormParam_Ex(); |
---|
| 77 | $this->lfInitParam($objFormParam); |
---|
| 78 | $objFormParam->setParam($_REQUEST); |
---|
| 79 | $objFormParam->convParam(); |
---|
[16768] | 80 | |
---|
[20863] | 81 | $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); |
---|
| 82 | $this->tpl_select = $this->getTemplateName($this->device_type_id); |
---|
| 83 | $template_code = $objFormParam->getValue('template_code'); |
---|
[16768] | 84 | |
---|
[21441] | 85 | switch ($this->getMode()) { |
---|
[19966] | 86 | |
---|
[20863] | 87 | // 登録ボタン押下時 |
---|
[19966] | 88 | case 'register': |
---|
[20863] | 89 | $this->arrErr = $objFormParam->checkError(); |
---|
| 90 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
| 91 | if ($this->doRegister($template_code, $this->device_type_id)) { |
---|
| 92 | $this->tpl_select = $template_code; |
---|
| 93 | $this->tpl_onload = "alert('登録が完了しました。');"; |
---|
| 94 | } |
---|
[19966] | 95 | } |
---|
| 96 | break; |
---|
[16768] | 97 | |
---|
[20863] | 98 | // 削除ボタン押下時 |
---|
[19966] | 99 | case 'delete': |
---|
[20863] | 100 | if ($objFormParam->checkError()) { |
---|
[20484] | 101 | SC_Utils_Ex::sfDispError(''); |
---|
[19966] | 102 | } |
---|
[20863] | 103 | $this->arrErr = $objFormParam->checkError(); |
---|
| 104 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
| 105 | if ($this->doDelete($template_code, $this->device_type_id)) { |
---|
| 106 | $this->tpl_onload = "alert('削除が完了しました。');"; |
---|
| 107 | } |
---|
[19966] | 108 | } |
---|
| 109 | break; |
---|
[16768] | 110 | |
---|
[20863] | 111 | // downloadボタン押下時 |
---|
[19966] | 112 | case 'download': |
---|
[20863] | 113 | $this->arrErr = $objFormParam->checkError(); |
---|
| 114 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
| 115 | if ($this->doDownload($template_code) !== false) { |
---|
| 116 | // ブラウザに出力し, 終了する |
---|
| 117 | exit; |
---|
| 118 | } |
---|
| 119 | } |
---|
[19966] | 120 | break; |
---|
[16768] | 121 | |
---|
[19966] | 122 | default: |
---|
| 123 | break; |
---|
| 124 | } |
---|
[16768] | 125 | |
---|
[20863] | 126 | if (!$is_error) { |
---|
| 127 | $this->templates = $this->getAllTemplates($this->device_type_id); |
---|
| 128 | } else { |
---|
| 129 | // 画面にエラー表示しないため, ログ出力 |
---|
| 130 | GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true)); |
---|
| 131 | } |
---|
[20911] | 132 | $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle; |
---|
[16430] | 133 | } |
---|
| 134 | |
---|
| 135 | /** |
---|
| 136 | * デストラクタ. |
---|
| 137 | * |
---|
| 138 | * @return void |
---|
| 139 | */ |
---|
| 140 | function destroy() { |
---|
| 141 | parent::destroy(); |
---|
| 142 | } |
---|
| 143 | |
---|
[20863] | 144 | /** |
---|
[20970] | 145 | * パラメーター情報の初期化 |
---|
[20863] | 146 | * |
---|
| 147 | * @param object $objFormParam SC_FormParamインスタンス |
---|
| 148 | * @return void |
---|
| 149 | */ |
---|
| 150 | function lfInitParam(&$objFormParam) { |
---|
| 151 | $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 152 | $objFormParam->addParam('template_code', 'template_code', STEXT_LEN, 'a', array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")); |
---|
[19725] | 153 | } |
---|
[16768] | 154 | |
---|
[18571] | 155 | /** |
---|
[20863] | 156 | * 使用するテンプレートを設定する. |
---|
| 157 | * |
---|
[20970] | 158 | * テンプレートをマスターデータに登録する. |
---|
[20863] | 159 | * |
---|
| 160 | * @param string $template_code テンプレートコード |
---|
| 161 | * @param integer $device_type_id 端末種別ID |
---|
| 162 | * @return void |
---|
[18571] | 163 | */ |
---|
[20863] | 164 | function doUpdateMasterData($template_code, $device_type_id) { |
---|
[18571] | 165 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[17136] | 166 | |
---|
[19966] | 167 | $defineName = 'TEMPLATE_NAME'; |
---|
| 168 | switch ($device_type_id) { |
---|
| 169 | case DEVICE_TYPE_MOBILE: |
---|
| 170 | $defineName = 'MOBILE_' . $defineName; |
---|
| 171 | break; |
---|
[18571] | 172 | |
---|
[19966] | 173 | case DEVICE_TYPE_SMARTPHONE: |
---|
| 174 | $defineName = 'SMARTPHONE_' . $defineName; |
---|
| 175 | break; |
---|
[20863] | 176 | |
---|
[19966] | 177 | case DEVICE_TYPE_PC: |
---|
| 178 | default: |
---|
| 179 | } |
---|
| 180 | |
---|
[18571] | 181 | // DBのデータを更新 |
---|
[20863] | 182 | $arrData = array($defineName => var_export($template_code, true)); |
---|
| 183 | $masterData->updateMasterData('mtb_constants', array(), $arrData); |
---|
[18571] | 184 | |
---|
| 185 | // キャッシュを生成 |
---|
| 186 | $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks')); |
---|
| 187 | } |
---|
[20041] | 188 | |
---|
[19725] | 189 | /** |
---|
[20863] | 190 | * ブロック位置の更新. |
---|
| 191 | * |
---|
| 192 | * ブロック位置を更新する SQL を実行する. |
---|
| 193 | * この SQL は, 各端末に合わせて実行する必要がある |
---|
| 194 | * |
---|
| 195 | * @param string $filepath SQLのファイルパス |
---|
| 196 | * @return void |
---|
[19725] | 197 | */ |
---|
[20863] | 198 | function updateBloc($filepath) { |
---|
| 199 | $sql = file_get_contents($filepath); |
---|
| 200 | if ($sql !== false) { |
---|
[19725] | 201 | // 改行、タブを1スペースに変換 |
---|
| 202 | $sql = preg_replace("/[\r\n\t]/", " " ,$sql); |
---|
[20428] | 203 | $sql_split = explode(";", $sql); |
---|
[20863] | 204 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21441] | 205 | foreach ($sql_split as $val) { |
---|
[19725] | 206 | if (trim($val) != "") { |
---|
| 207 | $objQuery->query($val); |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | } |
---|
[16768] | 212 | |
---|
[19725] | 213 | /** |
---|
[20863] | 214 | * テンプレートパッケージの削除. |
---|
| 215 | * |
---|
| 216 | * @param string $template_code テンプレートコード |
---|
| 217 | * @param integer $device_type_id 端末種別ID |
---|
| 218 | * @return boolean 成功した場合 true; 失敗した場合 false |
---|
[19725] | 219 | */ |
---|
[20863] | 220 | function doDelete($template_code, $device_type_id) { |
---|
| 221 | if ($template_code == $this->getTemplateName($device_type_id) |
---|
| 222 | || $template_code == $this->getTemplateName($device_type_id, true)) { |
---|
| 223 | $this->arrErr['err'] = "※ デフォルトテンプレートと、選択中のテンプレートは削除出来ません<br />"; |
---|
| 224 | return false; |
---|
| 225 | } else { |
---|
| 226 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 227 | $objQuery->begin(); |
---|
| 228 | $objQuery->delete('dtb_templates', 'template_code = ? AND device_type_id = ?', |
---|
| 229 | array($template_code, $device_type_id)); |
---|
[17136] | 230 | |
---|
[20863] | 231 | $error = "※ テンプレートの削除ができませんでした<br />"; |
---|
| 232 | // テンプレート削除 |
---|
| 233 | $templates_dir = SMARTY_TEMPLATES_REALDIR . $template_code. "/"; |
---|
| 234 | if (SC_Utils_Ex::sfDelFile($templates_dir) === false) { |
---|
| 235 | $this->arrErr['err'] = $error; |
---|
| 236 | $objQuery->rollback(); |
---|
| 237 | return false; |
---|
| 238 | } |
---|
| 239 | // ユーザーデータ削除 |
---|
| 240 | $user_dir = USER_TEMPLATE_REALDIR. $template_code. "/"; |
---|
| 241 | if (SC_Utils_Ex::sfDelFile($user_dir) === false) { |
---|
| 242 | $this->arrErr['err'] = $error; |
---|
| 243 | $objQuery->rollback(); |
---|
| 244 | return false; |
---|
| 245 | } |
---|
[16768] | 246 | |
---|
[20863] | 247 | // コンパイル削除 |
---|
| 248 | $templates_c_dir = DATA_REALDIR. "Smarty/templates_c/". $template_code. "/"; |
---|
| 249 | if (SC_Utils_Ex::sfDelFile($templates_c_dir) === false) { |
---|
| 250 | $this->arrErr['err'] = $error; |
---|
| 251 | $objQuery->rollback(); |
---|
| 252 | return false; |
---|
| 253 | } |
---|
| 254 | $objQuery->commit(); |
---|
| 255 | return true; |
---|
| 256 | } |
---|
[19725] | 257 | } |
---|
[19628] | 258 | |
---|
[20863] | 259 | /** |
---|
| 260 | * 登録を実行する. |
---|
| 261 | * |
---|
| 262 | * 失敗した場合は, エラーメッセージを出力し, false を返す. |
---|
| 263 | * |
---|
| 264 | * @param string $template_code テンプレートコード |
---|
| 265 | * @param integer $device_type_id 端末種別ID |
---|
| 266 | * @return boolean 成功した場合 true; 失敗した場合 false |
---|
[17673] | 267 | */ |
---|
[20863] | 268 | function doRegister($template_code, $device_type_id) { |
---|
[17673] | 269 | |
---|
[20863] | 270 | $tpl_dir = USER_TEMPLATE_REALDIR . $template_code . '/'; |
---|
| 271 | if (!is_dir($tpl_dir)) { |
---|
| 272 | $this->arrErr['err'] = '※ ' . $tpl_dir . 'が見つかりません<br />'; |
---|
| 273 | return false; |
---|
[17673] | 274 | } |
---|
| 275 | |
---|
[20863] | 276 | // 更新SQLファイルが存在する場合はブロック位置を更新 |
---|
| 277 | $sql_file = $tpl_dir . "sql/update_bloc.sql"; |
---|
| 278 | if (file_exists($sql_file)) { |
---|
| 279 | $this->updateBloc($sql_file); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | $this->doUpdateMasterData($template_code, $device_type_id); |
---|
| 283 | // コンパイルファイルのクリア処理 |
---|
| 284 | $objView = new SC_AdminView_Ex(); |
---|
| 285 | $objView->_smarty->clear_compiled_tpl(); |
---|
| 286 | return true; |
---|
[17673] | 287 | } |
---|
[19966] | 288 | |
---|
| 289 | /** |
---|
[20863] | 290 | * ダウンロードを実行する. |
---|
| 291 | * |
---|
| 292 | * 指定のテンプレートをアーカイブし, ブラウザに出力する. |
---|
| 293 | * 失敗した場合は, エラーメッセージを出力し, false を返す. |
---|
| 294 | * |
---|
| 295 | * @param string $template_code テンプレートコード |
---|
| 296 | * @return boolean 成功した場合 true; 失敗した場合 false |
---|
| 297 | */ |
---|
| 298 | function doDownload($template_code) { |
---|
| 299 | $from_dir = USER_TEMPLATE_REALDIR . $template_code . "/"; |
---|
| 300 | $to_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/"; |
---|
| 301 | if (SC_Utils_Ex::recursiveMkdir($to_dir) === false) { |
---|
| 302 | $this->arrErr['err'] = '※ ディレクトリの作成に失敗しました<br />'; |
---|
| 303 | return false; |
---|
| 304 | } |
---|
| 305 | SC_Utils_Ex::sfCopyDir($from_dir, $to_dir); |
---|
| 306 | if (SC_Helper_FileManager_Ex::downloadArchiveFiles(SMARTY_TEMPLATES_REALDIR . $template_code, $template_code) === false) { |
---|
| 307 | $this->arrErr['err'] = '※ アーカイブファイルの作成に失敗しました<br />'; |
---|
| 308 | return false; |
---|
| 309 | } |
---|
| 310 | return true; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | /** |
---|
| 314 | * テンプレート情報を取得する. |
---|
| 315 | * |
---|
| 316 | * @param integer $device_type_id 端末種別ID |
---|
| 317 | * @return array テンプレート情報の配列 |
---|
| 318 | */ |
---|
| 319 | function getAllTemplates($device_type_id) { |
---|
| 320 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 321 | return $objQuery->select('*', 'dtb_templates', "device_type_id = ?", array($device_type_id)); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | /** |
---|
[19966] | 325 | * テンプレート名を返す. |
---|
[20863] | 326 | * |
---|
| 327 | * @param integer $device_type_id 端末種別ID |
---|
| 328 | * @param boolean $isDefault デフォルトテンプレート名を返す場合 true |
---|
| 329 | * @return string テンプレート名 |
---|
[19966] | 330 | */ |
---|
| 331 | function getTemplateName($device_type_id, $isDefault = false) { |
---|
| 332 | switch ($device_type_id) { |
---|
| 333 | case DEVICE_TYPE_MOBILE: |
---|
| 334 | return $isDefault ? MOBILE_DEFAULT_TEMPLATE_NAME : MOBILE_TEMPLATE_NAME; |
---|
| 335 | break; |
---|
| 336 | |
---|
| 337 | case DEVICE_TYPE_SMARTPHONE: |
---|
| 338 | return $isDefault ? SMARTPHONE_DEFAULT_TEMPLATE_NAME : SMARTPHONE_TEMPLATE_NAME; |
---|
| 339 | break; |
---|
| 340 | |
---|
| 341 | case DEVICE_TYPE_PC: |
---|
| 342 | default: |
---|
| 343 | } |
---|
| 344 | return $isDefault ? DEFAULT_TEMPLATE_NAME : TEMPLATE_NAME; |
---|
| 345 | } |
---|
[16430] | 346 | } |
---|