source: branches/version-2_11-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Template.php @ 20970

Revision 20970, 12.0 KB checked in by Seasoft, 13 years ago (diff)

#1288 (「-er」カタカナ表記の統一)

  • 現状で混在が発生しているもののみ改修。
  • 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';
26require_once DATA_REALDIR . 'module/Tar.php';
27require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_FileManager_Ex.php';
28
29/**
30 * テンプレート設定 のページクラス.
31 *
32 * @package Page
33 * @author LOCKON CO.,LTD.
34 * @version $Id$
35 */
36class LC_Page_Admin_Design_Template extends LC_Page_Admin_Ex {
37
38    // }}}
39    // {{{ functions
40
41    /**
42     * Page を初期化する.
43     *
44     * @return void
45     */
46    function init() {
47        parent::init();
48        $this->tpl_mainpage = 'design/template.tpl';
49        $this->tpl_subno    = 'template';
50        $this->tpl_mainno   = 'design';
51        $this->tpl_maintitle = 'デザイン管理';
52        $this->tpl_subtitle = 'テンプレート設定';
53        $this->arrErr  = array();
54        $this->arrForm = array();
55        ini_set("max_execution_time", 300);
56        $masterData = new SC_DB_MasterData_Ex();
57        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
58    }
59
60    /**
61     * Page のプロセス.
62     *
63     * @return void
64     */
65    function process() {
66        $this->action();
67        $this->sendResponse();
68    }
69
70    /**
71     * Page のアクション.
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        $this->tpl_select = $this->getTemplateName($this->device_type_id);
83        $template_code = $objFormParam->getValue('template_code');
84
85        switch($this->getMode()) {
86
87        // 登録ボタン押下時
88        case 'register':
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                }
95            }
96            break;
97
98        // 削除ボタン押下時
99        case 'delete':
100            if ($objFormParam->checkError()) {
101                SC_Utils_Ex::sfDispError('');
102            }
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                }
108            }
109            break;
110
111        // downloadボタン押下時
112        case 'download':
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            }
120            break;
121
122        default:
123            break;
124        }
125
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        }
132        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
133    }
134
135    /**
136     * デストラクタ.
137     *
138     * @return void
139     */
140    function destroy() {
141        parent::destroy();
142    }
143
144    /**
145     * パラメーター情報の初期化
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"));
153    }
154
155    /**
156     * 使用するテンプレートを設定する.
157     *
158     * テンプレートをマスターデータに登録する.
159     *
160     * @param string $template_code テンプレートコード
161     * @param integer $device_type_id 端末種別ID
162     * @return void
163     */
164    function doUpdateMasterData($template_code, $device_type_id) {
165        $masterData = new SC_DB_MasterData_Ex();
166
167        $defineName = 'TEMPLATE_NAME';
168        switch ($device_type_id) {
169        case DEVICE_TYPE_MOBILE:
170            $defineName = 'MOBILE_' . $defineName;
171            break;
172
173        case DEVICE_TYPE_SMARTPHONE:
174            $defineName = 'SMARTPHONE_' . $defineName;
175            break;
176
177        case DEVICE_TYPE_PC:
178        default:
179        }
180
181        // DBのデータを更新
182        $arrData = array($defineName => var_export($template_code, true));
183        $masterData->updateMasterData('mtb_constants', array(), $arrData);
184
185        // キャッシュを生成
186        $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks'));
187    }
188
189    /**
190     * ブロック位置の更新.
191     *
192     * ブロック位置を更新する SQL を実行する.
193     * この SQL は, 各端末に合わせて実行する必要がある
194     *
195     * @param string $filepath SQLのファイルパス
196     * @return void
197     */
198    function updateBloc($filepath) {
199        $sql = file_get_contents($filepath);
200        if ($sql !== false) {
201            // 改行、タブを1スペースに変換
202            $sql = preg_replace("/[\r\n\t]/", " " ,$sql);
203            $sql_split = explode(";", $sql);
204            $objQuery =& SC_Query_Ex::getSingletonInstance();
205            foreach($sql_split as $val){
206                if (trim($val) != "") {
207                    $objQuery->query($val);
208                }
209            }
210        }
211    }
212
213    /**
214     * テンプレートパッケージの削除.
215     *
216     * @param string $template_code テンプレートコード
217     * @param integer $device_type_id 端末種別ID
218     * @return boolean 成功した場合 true; 失敗した場合 false
219     */
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));
230
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            }
246
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        }
257    }
258
259    /**
260     * 登録を実行する.
261     *
262     * 失敗した場合は, エラーメッセージを出力し, false を返す.
263     *
264     * @param string $template_code テンプレートコード
265     * @param integer $device_type_id 端末種別ID
266     * @return boolean 成功した場合 true; 失敗した場合 false
267     */
268    function doRegister($template_code, $device_type_id) {
269
270        $tpl_dir = USER_TEMPLATE_REALDIR . $template_code . '/';
271        if (!is_dir($tpl_dir)) {
272            $this->arrErr['err'] = '※ ' . $tpl_dir . 'が見つかりません<br />';
273            return false;
274        }
275
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;
287    }
288
289    /**
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    /**
325     * テンプレート名を返す.
326     *
327     * @param integer $device_type_id 端末種別ID
328     * @param boolean $isDefault デフォルトテンプレート名を返す場合 true
329     * @return string テンプレート名
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    }
346}
347?>
Note: See TracBrowser for help on using the repository browser.