source: branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design_Upload.php @ 16582

Revision 16582, 8.8 KB checked in by nanasess, 17 years ago (diff)

ライセンス表記変更

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 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_PATH . "pages/LC_Page.php");
26require_once(DATA_PATH. "module/Tar.php");
27
28/**
29 * テンプレートアップロード のページクラス.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class LC_Page_Admin_Design_Upload extends LC_Page {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46        parent::init();
47        $this->tpl_mainpage = 'design/upload.tpl';
48        $this->tpl_subnavi = 'design/subnavi.tpl';
49        $this->tpl_subno = 'template';
50        $this->tpl_subno_template = 'upload';
51        $this->tpl_mainno = "design";
52        $this->tpl_subtitle = 'アップロード';
53        $this->template_name = 'アップロード';
54    }
55
56    /**
57     * Page のプロセス.
58     *
59     * @return void
60     */
61    function process() {
62        $objView = new SC_AdminView();
63        $objSess = new SC_Session();
64        $objQuery = new SC_Query();
65
66        // 認証可否の判定
67        $objSess = new SC_Session();
68        SC_Utils_Ex::sfIsSuccess($objSess);
69
70        if (!isset($_POST['template_code'])) $_POST['template_code'] = "";
71        if (!isset($_POST['mode'])) $_POST['mode'] = "";
72
73        // アップロードしたファイルを格納するディレクトリ
74        $new_file_dir = USER_TEMPLATE_PATH . $_POST['template_code'];
75        // ファイル管理クラス
76        $objUpFile = new SC_UploadFile(TEMPLATE_TEMP_DIR, $new_file_dir);
77        // ファイル情報の初期化
78        $this->lfInitFile($objUpFile);
79        // パラメータ管理クラス
80        $objFormParam = new SC_FormParam();
81        // パラメータ情報の初期化
82        $this->lfInitParam($objFormParam);
83
84        switch($_POST['mode']) {
85        case 'upload':
86            $objFormParam->setParam($_POST);
87            $arrRet = $objFormParam->getHashArray();
88
89            $this->arrErr = $this->lfErrorCheck($arrRet, $objQuery, $objFormParam);
90
91            // ファイルを一時フォルダへ保存
92            $ret = $objUpFile->makeTempFile('template_file', false);
93            if($ret != "") {
94                $this->arrErr['template_file'] = $ret;
95            } else if(count($this->arrErr) <= 0) {
96                // フォルダ作成
97                $ret = @mkdir($new_file_dir);
98                // 一時フォルダから保存ディレクトリへ移動
99                $objUpFile->moveTempFile();
100                // 解凍
101                $this->lfUnpacking($new_file_dir, $_FILES['template_file']['name'], $new_file_dir."/");
102
103                $mess = "";
104                // Smarty テンプレートをコピー
105                $target_smarty = $new_file_dir . "/Smarty/";
106                $mess .= SC_Utils_Ex::sfCopyDir($target_smarty, DATA_PATH . "Smarty/templates/" . $_POST['template_code'] . "/", $mess);
107                // コピー済みファイルを削除
108                SC_Utils_Ex::sfDelFile($target_smarty);
109                // DBにテンプレート情報を保存
110                $this->lfRegistTemplate($arrRet, $objQuery);
111                // 完了表示javascript
112                $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');";
113                // フォーム値をクリア
114                $objFormParam->setParam(array('template_code' => "", 'template_name' => ""));
115            }
116            break;
117        default:
118            break;
119        }
120        // 画面の表示
121        $this->arrForm = $objFormParam->getFormParamList();
122        $objView->assignobj($this);
123        $objView->display(MAIN_FRAME);
124    }
125
126    /**
127     * デストラクタ.
128     *
129     * @return void
130     */
131    function destroy() {
132        parent::destroy();
133    }
134
135    /**
136     * ファイル情報の初期化を行う.
137     *
138     * @param SC_UploadFile $objUpFile SC_UploadFile インスタンス
139     * @return void
140     */
141    function lfInitFile(&$objUpFile) {
142        $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
143    }
144
145    /**
146     * パラメータ情報の初期化を行う.
147     *
148     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
149     * @return void
150     */
151    function lfInitParam(&$objFormParam) {
152
153        $objFormParam->addParam("テンプレートコード", "template_code", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK"));
154        $objFormParam->addParam("テンプレート名", "template_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
155    }
156
157    /**
158     * エラーチェックを行う.
159     *
160     * @param array $arrList フォームの値の配列
161     * @param SC_Query $objQuery SC_Query インスタンス
162     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
163     * @return array エラー情報の配列
164     */
165    function lfErrorCheck($arrList, &$objQuery, &$objFormParam) {
166
167        $objErr = new SC_CheckError($arrList);
168        $objErr->arrErr = $objFormParam->checkError();
169
170        if(count($objErr->arrErr) <= 0) {
171            // 同名のフォルダが存在する場合はエラー
172            if(file_exists(USER_TEMPLATE_PATH.$arrList['template_code'])) {
173                $objErr->arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
174            }
175            // DBにすでに登録されていないかチェック
176            $ret = $objQuery->get("dtb_templates", "template_code", "template_code = ?", array($arrList['template_code']));
177            if($ret != "") {
178                $objErr->arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
179            }
180            // ファイルの拡張子チェック(.tar/tar.gzのみ許可)
181            $errFlag = true;
182            $array_ext = explode(".", $_FILES['template_file']['name']);
183            $ext = $array_ext[ count ( $array_ext ) - 1 ];
184            $ext = strtolower($ext);
185            // .tarチェック
186            if ($ext == 'tar') {
187                $errFlag = false;
188            }
189
190            $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
191            $ext = strtolower($ext);
192            // .tar.gzチェック
193            if ($ext== 'tar.gz') {
194                $errFlag = false;
195            }
196
197            if($errFlag) {
198                $objErr->arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";
199            }
200        }
201
202        return $objErr->arrErr;
203    }
204
205    /**
206     * テンプレートデータを登録する.
207     *
208     * @param array $arrList 登録するデータの配列
209     * @param SC_Query $objQuery SC_Query インスタンス
210     * @return void
211     */
212    function lfRegistTemplate($arrList, &$objQuery) {
213
214        // INSERTする値を作成する。
215        $sqlval['template_code'] = $arrList['template_code'];
216        $sqlval['template_name'] = $arrList['template_name'];
217        $sqlval['create_date'] = "now()";
218        $sqlval['update_date'] = "now()";
219
220        $objQuery->insert("dtb_templates", $sqlval);
221    }
222
223    /**
224     * テンプレートのアーカイブを展開する.
225     *
226     * @param string ディレクトリ名
227     * @param string ファイル名
228     * @param string 展開先ディレクトリ
229     * @return void
230     */
231    function lfUnpacking($dir, $file_name, $unpacking_dir) {
232
233        // 圧縮フラグTRUEはgzip解凍をおこなう
234        $tar = new Archive_Tar("$dir/$file_name", TRUE);
235
236        // 拡張子を切り取る
237        $unpacking_name = ereg_replace("\.tar$", "", $file_name);
238        $unpacking_name = ereg_replace("\.tar\.gz$", "", $file_name);
239
240        // 指定されたフォルダ内に解凍する
241        $err = $tar->extractModify($unpacking_dir, $unpacking_name);
242
243        // フォルダ削除
244        @SC_Utils_Ex::sfDelFile("$dir/$unpacking_name");
245        // 圧縮ファイル削除
246        @unlink("$dir/$file_name");
247
248        return $err;
249    }
250}
251?>
Note: See TracBrowser for help on using the repository browser.