[16677] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[21867] | 5 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
---|
[16677] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
| 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. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
[16677] | 26 | |
---|
| 27 | /** |
---|
| 28 | * テンプレートアップロード のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
[20116] | 32 | * @version $Id$ |
---|
[16677] | 33 | */ |
---|
[20543] | 34 | class LC_Page_Admin_Design_UpDown extends LC_Page_Admin_Ex { |
---|
[16677] | 35 | |
---|
| 36 | // }}} |
---|
| 37 | // {{{ functions |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Page を初期化する. |
---|
| 41 | * |
---|
| 42 | * @return void |
---|
| 43 | */ |
---|
| 44 | function init() { |
---|
| 45 | parent::init(); |
---|
[19966] | 46 | $this->tpl_mainpage = 'design/up_down.tpl'; |
---|
| 47 | $this->tpl_subno = 'up_down'; |
---|
[20538] | 48 | $this->tpl_mainno = 'design'; |
---|
[22100] | 49 | $this->tpl_maintitle = t('TPL_MAINTITLE_003'); |
---|
| 50 | $this->tpl_subtitle = t('LC_Page_Admin_Design_UpDown_002'); |
---|
[19966] | 51 | $this->arrErr = array(); |
---|
| 52 | $this->arrForm = array(); |
---|
[21481] | 53 | ini_set('max_execution_time', 300); |
---|
[20560] | 54 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 55 | $this->arrDeviceType = $masterData->getMasterData('mtb_device_type'); |
---|
[16677] | 56 | } |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * Page のプロセス. |
---|
| 60 | * |
---|
| 61 | * @return void |
---|
| 62 | */ |
---|
[18233] | 63 | function process() { |
---|
[19661] | 64 | $this->action(); |
---|
| 65 | $this->sendResponse(); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * Page のアクション. |
---|
| 70 | * |
---|
[19713] | 71 | * FIXME ロジックを見直し |
---|
| 72 | * |
---|
[19661] | 73 | * @return void |
---|
| 74 | */ |
---|
| 75 | function action() { |
---|
[21591] | 76 | |
---|
[20863] | 77 | $objFormParam = new SC_FormParam_Ex(); |
---|
| 78 | $this->lfInitParam($objFormParam); |
---|
| 79 | $objFormParam->setParam($_REQUEST); |
---|
| 80 | $objFormParam->convParam(); |
---|
[19966] | 81 | |
---|
[20863] | 82 | $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); |
---|
[20560] | 83 | |
---|
[21441] | 84 | switch ($this->getMode()) { |
---|
[21526] | 85 | // アップロードボタン押下時の処理 |
---|
| 86 | case 'upload': |
---|
| 87 | $objUpFile = $this->lfInitUploadFile($objFormParam); |
---|
| 88 | $this->arrErr = $this->lfCheckError($objFormParam, $objUpFile); |
---|
| 89 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
| 90 | if ($this->doUpload($objFormParam, $objUpFile)) { |
---|
[22100] | 91 | $this->tpl_onload = "alert('" . t('ALERT_012') . "');"; |
---|
[21526] | 92 | $objFormParam->setValue('template_name', ''); |
---|
| 93 | $objFormParam->setValue('template_code', ''); |
---|
| 94 | } |
---|
[20863] | 95 | } |
---|
[21526] | 96 | break; |
---|
[19966] | 97 | |
---|
[21526] | 98 | default: |
---|
| 99 | break; |
---|
[19966] | 100 | } |
---|
[20863] | 101 | //サブタイトルの追加 |
---|
[20911] | 102 | $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle; |
---|
[20863] | 103 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
[21591] | 104 | |
---|
[16677] | 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * デストラクタ. |
---|
| 109 | * |
---|
| 110 | * @return void |
---|
| 111 | */ |
---|
| 112 | function destroy() { |
---|
| 113 | parent::destroy(); |
---|
| 114 | } |
---|
| 115 | |
---|
[19966] | 116 | /** |
---|
| 117 | * SC_UploadFileクラスの初期化. |
---|
| 118 | * |
---|
| 119 | * @param object $objForm SC_FormParamのインスタンス |
---|
| 120 | * @return object SC_UploadFileのインスタンス |
---|
| 121 | */ |
---|
| 122 | function lfInitUploadFile($objForm) { |
---|
| 123 | $pkg_dir = SMARTY_TEMPLATES_REALDIR . $objForm->getValue('template_code'); |
---|
[20497] | 124 | $objUpFile = new SC_UploadFile_Ex(TEMPLATE_TEMP_REALDIR, $pkg_dir); |
---|
[22100] | 125 | $objUpFile->addFile(t('PARAM_LABEL_TEMPLATE_FILE'), 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false); |
---|
[19966] | 126 | return $objUpFile; |
---|
| 127 | } |
---|
[20863] | 128 | |
---|
[19966] | 129 | /** |
---|
| 130 | * SC_FormParamクラスの初期化. |
---|
| 131 | * |
---|
[20863] | 132 | * @param SC_FormParam $objFormParam SC_FormParamのインスタンス |
---|
| 133 | * @return void |
---|
[19966] | 134 | */ |
---|
[20863] | 135 | function lfInitParam(&$objFormParam) { |
---|
[22100] | 136 | $objFormParam->addParam(t('PARAM_LABEL_TEMPLATE_CODE'), 'template_code', STEXT_LEN, 'a', array('EXIST_CHECK', 'SPTAB_CHECK','MAX_LENGTH_CHECK', 'ALNUM_CHECK')); |
---|
| 137 | $objFormParam->addParam(t('PARAM_LABEL_TEMPLATE_NAME'), 'template_name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK','MAX_LENGTH_CHECK')); |
---|
| 138 | $objFormParam->addParam(t('PARAM_LABEL_DEVICE_TYPE_ID'), 'device_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
[20863] | 139 | } |
---|
[19966] | 140 | |
---|
| 141 | /** |
---|
[20970] | 142 | * uploadモードのパラメーター検証を行う. |
---|
[19966] | 143 | * |
---|
[20863] | 144 | * @param object $objFormParam SC_FormParamのインスタンス |
---|
| 145 | * @param object $objUpFile SC_UploadFileのインスタンス |
---|
[19966] | 146 | * @return array エラー情報を格納した連想配列, エラーが無ければ(多分)nullを返す |
---|
| 147 | */ |
---|
[20863] | 148 | function lfCheckError(&$objFormParam, &$objUpFile) { |
---|
| 149 | $arrErr = $objFormParam->checkError(); |
---|
| 150 | $template_code = $objFormParam->getValue('template_code'); |
---|
[19966] | 151 | |
---|
| 152 | // 同名のフォルダが存在する場合はエラー |
---|
[20863] | 153 | if (file_exists(USER_TEMPLATE_REALDIR . $template_code)) { |
---|
[22100] | 154 | $arrErr['template_code'] = t('LC_Page_Admin_Design_UpDown_003'); |
---|
[19966] | 155 | } |
---|
| 156 | |
---|
| 157 | // 登録不可の文字列チェック |
---|
| 158 | $arrIgnoreCode = array('admin', |
---|
| 159 | MOBILE_DEFAULT_TEMPLATE_NAME, |
---|
| 160 | SMARTPHONE_DEFAULT_TEMPLATE_NAME, |
---|
| 161 | DEFAULT_TEMPLATE_NAME); |
---|
[20863] | 162 | if (in_array($template_code, $arrIgnoreCode)) { |
---|
[22100] | 163 | $arrErr['template_code'] = t('LC_Page_Admin_Design_UpDown_004'); |
---|
[19966] | 164 | } |
---|
| 165 | |
---|
| 166 | // DBにすでに登録されていないかチェック |
---|
[20863] | 167 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21514] | 168 | $exists = $objQuery->exists('dtb_templates', 'template_code = ?', array($template_code)); |
---|
[21376] | 169 | if ($exists) { |
---|
[22100] | 170 | $arrErr['template_code'] = t('LC_Page_Admin_Design_UpDown_005'); |
---|
[19966] | 171 | } |
---|
| 172 | |
---|
[20863] | 173 | /* |
---|
| 174 | * ファイル形式チェック |
---|
| 175 | * ファイルが壊れていることも考慮して, 展開可能かチェックする. |
---|
| 176 | */ |
---|
| 177 | $tar = new Archive_Tar($_FILES['template_file']['tmp_name'], true); |
---|
| 178 | $arrArchive = $tar->listContent(); |
---|
| 179 | if (!is_array($arrArchive)) { |
---|
[22100] | 180 | $arrErr['template_file'] = t('LC_Page_Admin_Design_UpDown_006'); |
---|
[20864] | 181 | } else { |
---|
[20885] | 182 | $make_temp_error = $objUpFile->makeTempFile('template_file', false); |
---|
| 183 | if (!SC_Utils_Ex::isBlank($make_temp_error)) { |
---|
| 184 | $arrErr['template_file'] = $make_temp_error; |
---|
| 185 | } |
---|
[19966] | 186 | } |
---|
| 187 | return $arrErr; |
---|
| 188 | } |
---|
[20863] | 189 | |
---|
[19966] | 190 | /** |
---|
[20011] | 191 | * DBおよびファイルシステムにテンプレートパッケージを追加する. |
---|
[19966] | 192 | * |
---|
[20863] | 193 | * エラーが発生した場合は, エラーを出力し, false を返す. |
---|
| 194 | * |
---|
| 195 | * @param object $objFormParam SC_FormParamのインスタンス |
---|
[19966] | 196 | * @param object $objUpFile SC_UploadFileのインスタンス |
---|
[20863] | 197 | * @return boolean 成功した場合 true; 失敗した場合 false |
---|
[19966] | 198 | */ |
---|
[20863] | 199 | function doUpload($objFormParam, $objUpFile) { |
---|
| 200 | $template_code = $objFormParam->getValue('template_code'); |
---|
| 201 | $template_name = $objFormParam->getValue('template_name'); |
---|
| 202 | $device_type_id = $objFormParam->getValue('device_type_id'); |
---|
| 203 | |
---|
[19966] | 204 | $template_dir = SMARTY_TEMPLATES_REALDIR . $template_code; |
---|
[21514] | 205 | $compile_dir = DATA_REALDIR . 'Smarty/templates_c/' . $template_code; |
---|
[20863] | 206 | |
---|
| 207 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 208 | $objQuery->begin(); |
---|
| 209 | |
---|
[21527] | 210 | $arrValues = array( |
---|
| 211 | 'template_code' => $template_code, |
---|
| 212 | 'device_type_id' => $device_type_id, |
---|
| 213 | 'template_name' => $template_name, |
---|
| 214 | 'create_date' => 'CURRENT_TIMESTAMP', |
---|
| 215 | 'update_date' => 'CURRENT_TIMESTAMP', |
---|
| 216 | ); |
---|
[20863] | 217 | $objQuery->insert('dtb_templates', $arrValues); |
---|
| 218 | |
---|
| 219 | $is_error = false; |
---|
[19966] | 220 | // フォルダ作成 |
---|
[20863] | 221 | if (!file_exists($template_dir)) { |
---|
| 222 | if (!mkdir($template_dir)) { |
---|
[22100] | 223 | $this->arrErr['err'] = t('LC_Page_Admin_Design_UpDown_007'); |
---|
[20863] | 224 | $objQuery->rollback(); |
---|
| 225 | return false; |
---|
| 226 | } |
---|
[19966] | 227 | } |
---|
[20863] | 228 | if (!file_exists($compile_dir)) { |
---|
| 229 | if (!mkdir($compile_dir)) { |
---|
[22100] | 230 | $this->arrErr['err'] = t('LC_Page_Admin_Design_UpDown_008'); |
---|
[20863] | 231 | $objQuery->rollback(); |
---|
| 232 | return false; |
---|
| 233 | } |
---|
[19966] | 234 | } |
---|
| 235 | |
---|
| 236 | // 一時フォルダから保存ディレクトリへ移動 |
---|
| 237 | $objUpFile->moveTempFile(); |
---|
| 238 | |
---|
| 239 | // 解凍 |
---|
[21514] | 240 | if (!SC_Helper_FileManager_Ex::unpackFile($template_dir . '/' . $_FILES['template_file']['name'])) { |
---|
[22100] | 241 | $this->arrErr['err'] = t('LC_Page_Admin_Design_UpDown_009'); |
---|
[20863] | 242 | $objQuery->rollback(); |
---|
| 243 | return false; |
---|
| 244 | } |
---|
[19966] | 245 | // ユーザデータの下のファイルをコピーする |
---|
[21514] | 246 | $from_dir = SMARTY_TEMPLATES_REALDIR . $template_code . '/_packages/'; |
---|
| 247 | $to_dir = USER_REALDIR . 'packages/' . $template_code . '/'; |
---|
[20863] | 248 | if (!SC_Utils_Ex::recursiveMkdir($to_dir)) { |
---|
[22100] | 249 | $this->arrErr['err'] = t('LC_Page_Admin_Design_UpDown_010', array('T_FIELD' => $to_dir)); |
---|
[22067] | 250 | |
---|
[20863] | 251 | $objQuery->rollback(); |
---|
| 252 | return false; |
---|
| 253 | } |
---|
[20484] | 254 | SC_Utils_Ex::sfCopyDir($from_dir, $to_dir); |
---|
[19966] | 255 | |
---|
[20863] | 256 | $objQuery->commit(); |
---|
| 257 | return true; |
---|
[19966] | 258 | } |
---|
[16677] | 259 | } |
---|