[16430] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 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 |
---|
[19805] | 25 | require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.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 | */ |
---|
[19661] | 36 | class LC_Page_Admin_Design_Template extends LC_Page_Admin { |
---|
[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_subnavi = 'design/subnavi.tpl'; |
---|
| 50 | $this->tpl_subno = 'template'; |
---|
| 51 | $this->tpl_mainno = "design"; |
---|
| 52 | $this->tpl_subtitle = 'テンプレート設定'; |
---|
| 53 | $this->arrErr = array(); |
---|
| 54 | $this->arrForm = array(); |
---|
| 55 | ini_set("max_execution_time", 300); |
---|
[16430] | 56 | } |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * Page のプロセス. |
---|
| 60 | * |
---|
| 61 | * @return void |
---|
| 62 | */ |
---|
| 63 | function process() { |
---|
[19661] | 64 | $this->action(); |
---|
| 65 | $this->sendResponse(); |
---|
| 66 | } |
---|
[16768] | 67 | |
---|
[19661] | 68 | /** |
---|
| 69 | * Page のアクション. |
---|
| 70 | * |
---|
[19713] | 71 | * FIXME ロジックを見直し |
---|
| 72 | * |
---|
[19661] | 73 | * @return void |
---|
| 74 | */ |
---|
| 75 | function action() { |
---|
| 76 | // 認証可否の判定 |
---|
[19966] | 77 | $objSession = new SC_Session(); |
---|
| 78 | SC_Utils::sfIsSuccess($objSession); |
---|
[16768] | 79 | |
---|
[19966] | 80 | // 端末種別IDを取得 |
---|
| 81 | if (isset($_REQUEST['device_type_id']) |
---|
| 82 | && is_numeric($_REQUEST['device_type_id'])) { |
---|
| 83 | $device_type_id = $_REQUEST['device_type_id']; |
---|
| 84 | } else { |
---|
| 85 | $device_type_id = DEVICE_TYPE_PC; |
---|
| 86 | } |
---|
[16768] | 87 | |
---|
[19966] | 88 | $this->tpl_select = $this->getTemplateName($device_type_id); |
---|
[16768] | 89 | |
---|
[19966] | 90 | // uniqidをテンプレートへ埋め込み |
---|
| 91 | $this->uniqid = $objSession->getUniqId(); |
---|
[16768] | 92 | |
---|
[19966] | 93 | $objView = new SC_AdminView(); |
---|
| 94 | |
---|
| 95 | switch($this->lfGetMode()) { |
---|
| 96 | |
---|
[19725] | 97 | // 登録ボタン押下時 |
---|
[19966] | 98 | case 'register': |
---|
| 99 | // 画面遷移の正当性チェック |
---|
| 100 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 101 | sfDispError(''); |
---|
| 102 | } |
---|
| 103 | // パラメータ検証 |
---|
| 104 | $objForm = $this->lfInitRegister(); |
---|
| 105 | if ($objForm->checkError()) { |
---|
| 106 | SC_Utils_Ex::sfDispError(''); |
---|
| 107 | } |
---|
[16768] | 108 | |
---|
[19966] | 109 | $template_code = $objForm->getValue('template_code'); |
---|
| 110 | $this->tpl_select = $template_code; |
---|
[16768] | 111 | |
---|
[19966] | 112 | if($template_code == "") { |
---|
| 113 | $template_code = $this->getTemplateName($device_type_id, true); |
---|
| 114 | } |
---|
[16768] | 115 | |
---|
[19966] | 116 | // DBへ使用するテンプレートを登録 |
---|
| 117 | $this->lfRegisterTemplate($template_code); |
---|
[16768] | 118 | |
---|
[19966] | 119 | // XXX コンパイルファイルのクリア処理を行う |
---|
| 120 | $objView->_smarty->clear_compiled_tpl(); |
---|
[19628] | 121 | |
---|
[19966] | 122 | // ブロック位置を更新 |
---|
| 123 | $this->lfChangeBloc($template_code); |
---|
[17136] | 124 | |
---|
[19966] | 125 | // 完了メッセージ |
---|
| 126 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
| 127 | break; |
---|
[16768] | 128 | |
---|
[19725] | 129 | // 削除ボタン押下時 |
---|
[19966] | 130 | case 'delete': |
---|
| 131 | // 画面遷移の正当性チェック |
---|
| 132 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 133 | SC_Utils::sfDispError(''); |
---|
| 134 | } |
---|
| 135 | // パラメータ検証 |
---|
| 136 | $objForm = $this->lfInitDelete(); |
---|
| 137 | if ($objForm->checkError()) { |
---|
| 138 | SC_Utils::sfDispError(''); |
---|
| 139 | } |
---|
[19725] | 140 | |
---|
[19966] | 141 | //現在使用中のテンプレートとデフォルトのテンプレートは削除できないようにする |
---|
| 142 | $template_code = $objForm->getValue('template_code_temp'); |
---|
| 143 | if ($template_code == $this->getTemplateName($device_type_id) |
---|
| 144 | || $template_code == $this->getTemplateName($device_type_id, true)) { |
---|
| 145 | $this->tpl_onload = "alert('デフォルトテンプレートと、選択中のテンプレートは削除出来ません');"; |
---|
[19725] | 146 | break; |
---|
[19966] | 147 | } |
---|
| 148 | $this->lfDeleteTemplate($template_code); |
---|
| 149 | break; |
---|
[16768] | 150 | |
---|
[19725] | 151 | // downloadボタン押下時 |
---|
[19966] | 152 | case 'download': |
---|
| 153 | // 画面遷移の正当性チェック |
---|
| 154 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
| 155 | SC_Utils::sfDispError(''); |
---|
| 156 | } |
---|
| 157 | // パラメータ検証 |
---|
| 158 | $objForm = $this->lfInitDownload(); |
---|
| 159 | $template_code = $objForm->getValue('template_code_temp'); |
---|
| 160 | // ユーザデータの下のファイルも保存する。 |
---|
| 161 | $from_dir = USER_TEMPLATE_REALDIR . $template_code . "/"; |
---|
| 162 | $to_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/"; |
---|
| 163 | SC_Utils::sfMakeDir($to_dir); |
---|
| 164 | SC_Utils::sfCopyDir($from_dir, $to_dir); |
---|
| 165 | SC_Helper_FileManager::downloadArchiveFiles(SMARTY_TEMPLATES_REALDIR . $template_code); |
---|
| 166 | break; |
---|
[16768] | 167 | |
---|
[19725] | 168 | // プレビューボタン押下時 |
---|
[19966] | 169 | case 'preview': |
---|
| 170 | break; |
---|
[16768] | 171 | |
---|
[19966] | 172 | default: |
---|
| 173 | break; |
---|
| 174 | } |
---|
[16768] | 175 | |
---|
[19966] | 176 | $this->templates = $this->lfGetAllTemplates($device_type_id); |
---|
| 177 | $this->now_template = TEMPLATE_NAME; |
---|
| 178 | $this->device_type_id = $device_type_id; |
---|
[16430] | 179 | } |
---|
| 180 | |
---|
| 181 | /** |
---|
| 182 | * デストラクタ. |
---|
| 183 | * |
---|
| 184 | * @return void |
---|
| 185 | */ |
---|
| 186 | function destroy() { |
---|
| 187 | parent::destroy(); |
---|
| 188 | } |
---|
| 189 | |
---|
[19725] | 190 | function lfGetMode(){ |
---|
| 191 | if (isset($_POST['mode'])) return $_POST['mode']; |
---|
| 192 | } |
---|
[16768] | 193 | |
---|
[19725] | 194 | function lfInitRegister() { |
---|
| 195 | $objForm = new SC_FormParam(); |
---|
| 196 | $objForm->addParam( |
---|
| 197 | 'template_code', 'template_code', STEXT_LEN, '', |
---|
| 198 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 199 | ); |
---|
| 200 | $objForm->setParam($_POST); |
---|
[16768] | 201 | |
---|
[19725] | 202 | return $objForm; |
---|
| 203 | } |
---|
[16768] | 204 | |
---|
[19725] | 205 | function lfInitDelete() { |
---|
| 206 | $objForm = new SC_FormParam(); |
---|
| 207 | $objForm->addParam( |
---|
| 208 | 'template_code_temp', 'template_code_temp', STEXT_LEN, '', |
---|
| 209 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 210 | ); |
---|
| 211 | $objForm->setParam($_POST); |
---|
[16768] | 212 | |
---|
[19725] | 213 | return $objForm; |
---|
| 214 | } |
---|
[16768] | 215 | |
---|
[19725] | 216 | function lfInitDownload() { |
---|
| 217 | $objForm = new SC_FormParam(); |
---|
| 218 | $objForm->addParam( |
---|
| 219 | 'template_code_temp', 'template_code_temp', STEXT_LEN, '', |
---|
| 220 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
| 221 | ); |
---|
| 222 | $objForm->setParam($_POST); |
---|
[16768] | 223 | |
---|
[19725] | 224 | return $objForm; |
---|
| 225 | } |
---|
[16768] | 226 | |
---|
[18571] | 227 | /** |
---|
| 228 | * 使用するテンプレートをDBへ登録する |
---|
| 229 | */ |
---|
[19966] | 230 | function lfRegisterTemplate($template_code, $device_type_id) { |
---|
[18571] | 231 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[17136] | 232 | |
---|
[19966] | 233 | $defineName = 'TEMPLATE_NAME'; |
---|
| 234 | switch ($device_type_id) { |
---|
| 235 | case DEVICE_TYPE_MOBILE: |
---|
| 236 | $defineName = 'MOBILE_' . $defineName; |
---|
| 237 | break; |
---|
[18571] | 238 | |
---|
[19966] | 239 | case DEVICE_TYPE_SMARTPHONE: |
---|
| 240 | $defineName = 'SMARTPHONE_' . $defineName; |
---|
| 241 | break; |
---|
| 242 | case DEVICE_TYPE_PC: |
---|
| 243 | default: |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | $data = array($defineName => var_export($template_code, TRUE)); |
---|
| 247 | |
---|
[18571] | 248 | // DBのデータを更新 |
---|
| 249 | $masterData->updateMasterData('mtb_constants', array(), $data); |
---|
| 250 | |
---|
| 251 | // キャッシュを生成 |
---|
| 252 | $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks')); |
---|
| 253 | } |
---|
[19725] | 254 | |
---|
| 255 | /** |
---|
| 256 | * ブロック位置の更新 |
---|
| 257 | */ |
---|
| 258 | function lfChangeBloc($template_code) { |
---|
| 259 | $objQuery = new SC_Query(); |
---|
[19966] | 260 | /* |
---|
| 261 | * FIXME 各端末に合わせて作成する必要あり |
---|
| 262 | * $filepath = USER_TEMPLATE_REALDIR. $template_code. "/sql/update_bloc.sql"; |
---|
| 263 | */ |
---|
[19725] | 264 | |
---|
| 265 | // ブロック位置更新SQLファイル有 |
---|
| 266 | if(file_exists($filepath)) { |
---|
| 267 | if($fp = fopen($filepath, "r")) { |
---|
| 268 | $sql = fread($fp, filesize($filepath)); |
---|
| 269 | fclose($fp); |
---|
| 270 | } |
---|
| 271 | // 改行、タブを1スペースに変換 |
---|
| 272 | $sql = preg_replace("/[\r\n\t]/", " " ,$sql); |
---|
| 273 | $sql_split = split(";", $sql); |
---|
| 274 | foreach($sql_split as $key => $val){ |
---|
| 275 | if (trim($val) != "") { |
---|
| 276 | $objQuery->query($val); |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | } |
---|
[16768] | 281 | |
---|
[19725] | 282 | /** |
---|
| 283 | * テンプレートパッケージの削除 |
---|
| 284 | */ |
---|
| 285 | function lfDeleteTemplate($template_code) { |
---|
| 286 | // DB更新 |
---|
| 287 | $objQuery = new SC_Query(); |
---|
| 288 | $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code)); |
---|
| 289 | // テンプレート削除 |
---|
[19805] | 290 | $templates_dir = SMARTY_TEMPLATES_REALDIR. $template_code. "/"; |
---|
[19725] | 291 | SC_Utils_Ex::sfDelFile($templates_dir); |
---|
| 292 | // コンパイル削除 |
---|
[19805] | 293 | $templates_c_dir = DATA_REALDIR. "Smarty/templates_c/". $template_code. "/"; |
---|
[19725] | 294 | SC_Utils_Ex::sfDelFile($templates_c_dir); |
---|
| 295 | // ユーザーデータ削除 |
---|
[19807] | 296 | $user_dir = USER_TEMPLATE_REALDIR. $template_code. "/"; |
---|
[19725] | 297 | SC_Utils_Ex::sfDelFile($user_dir); |
---|
| 298 | } |
---|
[17136] | 299 | |
---|
[19966] | 300 | function lfGetAllTemplates($device_type_id) { |
---|
[19725] | 301 | $objQuery = new SC_Query(); |
---|
[19966] | 302 | $arrRet = $objQuery->select('*', 'dtb_templates', "device_type_id = ?", array($device_type_id)); |
---|
[19725] | 303 | if (empty($arrRet)) return array(); |
---|
[16768] | 304 | |
---|
[19725] | 305 | return $arrRet; |
---|
| 306 | } |
---|
[19628] | 307 | |
---|
[17673] | 308 | /* |
---|
| 309 | * 関数名:lfGetFileContents() |
---|
| 310 | * 引数1 :ファイルパス |
---|
| 311 | * 説明 :ファイル読込 |
---|
| 312 | * 戻り値:無し |
---|
| 313 | */ |
---|
| 314 | function lfGetFileContents($read_file) { |
---|
| 315 | |
---|
| 316 | if(file_exists($read_file)) { |
---|
| 317 | $contents = file_get_contents($read_file); |
---|
| 318 | } else { |
---|
| 319 | $contents = ""; |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | return $contents; |
---|
| 323 | } |
---|
[19966] | 324 | |
---|
| 325 | /** |
---|
| 326 | * テンプレート名を返す. |
---|
| 327 | */ |
---|
| 328 | function getTemplateName($device_type_id, $isDefault = false) { |
---|
| 329 | switch ($device_type_id) { |
---|
| 330 | case DEVICE_TYPE_MOBILE: |
---|
| 331 | return $isDefault ? MOBILE_DEFAULT_TEMPLATE_NAME : MOBILE_TEMPLATE_NAME; |
---|
| 332 | break; |
---|
| 333 | |
---|
| 334 | case DEVICE_TYPE_SMARTPHONE: |
---|
| 335 | return $isDefault ? SMARTPHONE_DEFAULT_TEMPLATE_NAME : SMARTPHONE_TEMPLATE_NAME; |
---|
| 336 | break; |
---|
| 337 | |
---|
| 338 | case DEVICE_TYPE_PC: |
---|
| 339 | default: |
---|
| 340 | } |
---|
| 341 | return $isDefault ? DEFAULT_TEMPLATE_NAME : TEMPLATE_NAME; |
---|
| 342 | } |
---|
[16430] | 343 | } |
---|
| 344 | ?> |
---|