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 |
---|
25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
26 | require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_FileManager_Ex.php'; |
---|
27 | |
---|
28 | /** |
---|
29 | * ヘッダ, フッタ編集 のページクラス. |
---|
30 | * |
---|
31 | * @package Page |
---|
32 | * @author LOCKON CO.,LTD. |
---|
33 | * @version $Id$ |
---|
34 | */ |
---|
35 | class LC_Page_Admin_Design_Header extends LC_Page_Admin_Ex { |
---|
36 | |
---|
37 | // }}} |
---|
38 | // {{{ functions |
---|
39 | |
---|
40 | /** |
---|
41 | * Page を初期化する. |
---|
42 | * |
---|
43 | * @return void |
---|
44 | */ |
---|
45 | function init() { |
---|
46 | parent::init(); |
---|
47 | $this->tpl_mainpage = 'design/header.tpl'; |
---|
48 | $this->header_row = 13; |
---|
49 | $this->footer_row = 13; |
---|
50 | $this->tpl_subno = 'header'; |
---|
51 | $this->tpl_mainno = 'design'; |
---|
52 | $this->tpl_maintitle = 'デザイン管理'; |
---|
53 | $this->tpl_subtitle = 'ヘッダー/フッター設定'; |
---|
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 | * @return void |
---|
72 | */ |
---|
73 | function action() { |
---|
74 | $objFormParam = new SC_FormParam_Ex(); |
---|
75 | $this->lfInitParam($objFormParam); |
---|
76 | $objFormParam->setParam($_REQUEST); |
---|
77 | $objFormParam->convParam(); |
---|
78 | $this->arrErr = $objFormParam->checkError(); |
---|
79 | $is_error = (!SC_Utils_Ex::isBlank($this->arrErr)); |
---|
80 | |
---|
81 | $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); |
---|
82 | |
---|
83 | switch ($this->getMode()) { |
---|
84 | // 登録 |
---|
85 | case 'regist': |
---|
86 | $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr); |
---|
87 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
88 | if ($this->doRegister($objFormParam)) { |
---|
89 | $this->tpl_onload = "alert('登録が完了しました。');"; |
---|
90 | } |
---|
91 | } |
---|
92 | break; |
---|
93 | |
---|
94 | default: |
---|
95 | break; |
---|
96 | } |
---|
97 | |
---|
98 | if (!$is_error) { |
---|
99 | // テキストエリアに表示 |
---|
100 | $header_path = $this->getTemplatePath($this->device_type_id, 'header'); |
---|
101 | $footer_path = $this->getTemplatePath($this->device_type_id, 'footer'); |
---|
102 | if ($header_path === false || $footer_path === false) { |
---|
103 | $this->arrErr['err'] = '※ ファイルの取得に失敗しました<br />'; |
---|
104 | } else { |
---|
105 | $this->header_data = file_get_contents($header_path); |
---|
106 | $this->footer_data = file_get_contents($footer_path); |
---|
107 | } |
---|
108 | } else { |
---|
109 | // 画面にエラー表示しないため, ログ出力 |
---|
110 | GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true)); |
---|
111 | } |
---|
112 | |
---|
113 | //サブタイトルの追加 |
---|
114 | $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle; |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * デストラクタ. |
---|
119 | * |
---|
120 | * @return void |
---|
121 | */ |
---|
122 | function destroy() { |
---|
123 | parent::destroy(); |
---|
124 | } |
---|
125 | |
---|
126 | /** |
---|
127 | * パラメーター情報の初期化 |
---|
128 | * |
---|
129 | * @param object $objFormParam SC_FormParamインスタンス |
---|
130 | * @return void |
---|
131 | */ |
---|
132 | function lfInitParam(&$objFormParam) { |
---|
133 | $objFormParam->addParam("端末種別ID", 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
134 | $objFormParam->addParam('division', 'division', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK')); |
---|
135 | $objFormParam->addParam("ヘッダデータ", 'header'); |
---|
136 | $objFormParam->addParam("フッタデータ", 'footer'); |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * エラーチェックを行う. |
---|
141 | * |
---|
142 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
143 | * @return array エラーメッセージの配列 |
---|
144 | */ |
---|
145 | function lfCheckError(&$objFormParam, &$arrErr) { |
---|
146 | $arrParams = $objFormParam->getHashArray(); |
---|
147 | $objErr = new SC_CheckError_Ex($arrParams); |
---|
148 | $objErr->arrErr =& $arrErr; |
---|
149 | $objErr->doFunc(array('division', 'division', STEXT_LEN), array('EXIST_CHECK')); |
---|
150 | return $objErr->arrErr; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * 登録を実行する. |
---|
155 | * |
---|
156 | * ファイルの作成に失敗した場合は, エラーメッセージを出力する. |
---|
157 | * |
---|
158 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
159 | * @return integer|boolean 登録が成功した場合 true; 失敗した場合 false |
---|
160 | */ |
---|
161 | function doRegister(&$objFormParam) { |
---|
162 | $division = $objFormParam->getValue('division'); |
---|
163 | $contents = $objFormParam->getValue($division); |
---|
164 | $tpl_path = $this->getTemplatePath($objFormParam->getValue('device_type_id'), $division); |
---|
165 | if ($tpl_path === false |
---|
166 | || !SC_Helper_FileManager_Ex::sfWriteFile($tpl_path, $contents)) { |
---|
167 | $this->arrErr['err'] = '※ ファイルの書き込みに失敗しました<br />'; |
---|
168 | return false; |
---|
169 | } |
---|
170 | return true; |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * テンプレートパスを取得する. |
---|
175 | * |
---|
176 | * @param integer $device_type_id 端末種別ID |
---|
177 | * @param string $division 'header' or 'footer' |
---|
178 | * @return string|boolean 成功した場合, テンプレートのパス; 失敗した場合 false |
---|
179 | */ |
---|
180 | function getTemplatePath($device_type_id, $division) { |
---|
181 | $tpl_path = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id) . '/' . $division . '.tpl'; |
---|
182 | if (file_exists($tpl_path)) { |
---|
183 | return $tpl_path; |
---|
184 | } else { |
---|
185 | return false; |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|