source: branches/version-2_12-dev/data/class/pages/admin/design/LC_Page_Admin_Design_UpDown.php @ 21514

Revision 21514, 9.6 KB checked in by Seasoft, 12 years ago (diff)

#1625 (typo修正・ソース整形・ソースコメントの改善)

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