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 |
---|
25 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
26 | require_once(DATA_PATH . "module/Tar.php"); |
---|
27 | |
---|
28 | /** |
---|
29 | * テンプレート設定 のページクラス. |
---|
30 | * |
---|
31 | * @package Page |
---|
32 | * @author LOCKON CO.,LTD. |
---|
33 | * @version $Id$ |
---|
34 | */ |
---|
35 | class LC_Page_Admin_Design_Template extends LC_Page { |
---|
36 | |
---|
37 | // }}} |
---|
38 | // {{{ functions |
---|
39 | |
---|
40 | /** テンプレートデータ種別 */ |
---|
41 | var $arrSubnavi = array( |
---|
42 | 'title' => array( |
---|
43 | 1 => 'top', |
---|
44 | 2 => 'product', |
---|
45 | 3 => 'detail', |
---|
46 | 4 => 'mypage' |
---|
47 | ), |
---|
48 | 'name' =>array( |
---|
49 | 1 => 'TOPページ', |
---|
50 | 2 => '商品一覧ページ', |
---|
51 | 3 => '商品詳細ページ', |
---|
52 | 4 => 'MYページ' |
---|
53 | ) |
---|
54 | ); |
---|
55 | |
---|
56 | /** |
---|
57 | * Page を初期化する. |
---|
58 | * |
---|
59 | * @return void |
---|
60 | */ |
---|
61 | function init() { |
---|
62 | parent::init(); |
---|
63 | $this->arrTemplateName = $this->arrSubnavi; |
---|
64 | $this->tpl_mainpage = 'design/template.tpl'; |
---|
65 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
66 | $this->tpl_subno = 'template'; |
---|
67 | $this->tpl_subno_template = $this->arrSubnavi['title'][1]; |
---|
68 | $this->tpl_TemplateName = $this->arrTemplateName['name'][1]; |
---|
69 | $this->tpl_mainno = "design"; |
---|
70 | $this->tpl_subtitle = 'テンプレート設定'; |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * Page のプロセス. |
---|
75 | * |
---|
76 | * @return void |
---|
77 | */ |
---|
78 | function process() { |
---|
79 | $objView = new SC_AdminView(); |
---|
80 | $objSess = new SC_Session(); |
---|
81 | |
---|
82 | // 認証可否の判定 |
---|
83 | $objSess = new SC_Session(); |
---|
84 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
85 | |
---|
86 | // GETの値を受け取る |
---|
87 | $get_tpl_subno_template = isset($_GET['tpl_subno_template']) |
---|
88 | ? $_GET['tpl_subno_template'] : ""; |
---|
89 | if (!isset($_POST['tpl_subno_template'])) $_POST['tpl_subno_template'] = ""; |
---|
90 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
91 | |
---|
92 | // GETで値が送られている場合にはその値を元に画面表示を切り替える |
---|
93 | if ($get_tpl_subno_template != ""){ |
---|
94 | // 送られてきた値が配列に登録されていなければTOPを表示 |
---|
95 | if (in_array($get_tpl_subno_template,$this->arrSubnavi['title'])){ |
---|
96 | $tpl_subno_template = $get_tpl_subno_template; |
---|
97 | }else{ |
---|
98 | $tpl_subno_template = $this->arrSubnavi['title'][1]; |
---|
99 | } |
---|
100 | } else { |
---|
101 | // GETで値がなければPOSTの値を使用する |
---|
102 | if ($_POST['tpl_subno_template'] != ""){ |
---|
103 | $tpl_subno_template = $_POST['tpl_subno_template']; |
---|
104 | }else{ |
---|
105 | $tpl_subno_template = $this->arrSubnavi['title'][1]; |
---|
106 | } |
---|
107 | } |
---|
108 | $this->tpl_subno_template = $tpl_subno_template; |
---|
109 | $key = array_keys($this->arrSubnavi['title'], $tpl_subno_template); |
---|
110 | $this->template_name = $this->arrSubnavi['name'][$key[0]]; |
---|
111 | |
---|
112 | // 登録を押された場合にはDBへデータを更新に行く |
---|
113 | switch($_POST['mode']) { |
---|
114 | case 'confirm': |
---|
115 | // DBへデータ更新 |
---|
116 | $this->lfUpdData(); |
---|
117 | |
---|
118 | // テンプレートの上書き |
---|
119 | $this->lfChangeTemplate(); |
---|
120 | |
---|
121 | // 完了メッセージ |
---|
122 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
123 | break; |
---|
124 | case 'download': |
---|
125 | $this->lfDownloadTemplate($_POST['check_template']); |
---|
126 | break; |
---|
127 | default: |
---|
128 | break; |
---|
129 | } |
---|
130 | |
---|
131 | // POST値の引き継ぎ |
---|
132 | $this->arrForm = $_POST; |
---|
133 | |
---|
134 | // 画像取得 |
---|
135 | $tpl_arrTemplate = array(); |
---|
136 | $this->arrTemplate = $this->lfgetTemplate(); |
---|
137 | |
---|
138 | // デフォルトチェック取得 |
---|
139 | $this->MainImage = $this->arrTemplate['check']; |
---|
140 | $this->arrTemplate['check'] = array($this->arrTemplate['check']=>"check"); |
---|
141 | |
---|
142 | // 画面の表示 |
---|
143 | $objView->assignobj($this); |
---|
144 | $objView->display(MAIN_FRAME); |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | * デストラクタ. |
---|
150 | * |
---|
151 | * @return void |
---|
152 | */ |
---|
153 | function destroy() { |
---|
154 | parent::destroy(); |
---|
155 | } |
---|
156 | |
---|
157 | /** |
---|
158 | * 画面に表示する画像を取得する. |
---|
159 | * |
---|
160 | * @return array 画面に表示する画像の配列 |
---|
161 | */ |
---|
162 | function lfgetTemplate(){ |
---|
163 | $filepath = "user_data/templates/"; |
---|
164 | |
---|
165 | $arrTemplateImage = array(); // 画面表示画像格納用 |
---|
166 | $Image = ""; // イメージの配列要素名格納用 |
---|
167 | $disp = ""; |
---|
168 | $arrDefcheck = array(); // radioボタンのデフォルトチェック格納用 |
---|
169 | |
---|
170 | // DBから現在選択されているデータ取得 |
---|
171 | $arrDefcheck = $this->lfgetTemplaeBaseData(); |
---|
172 | |
---|
173 | // テンプレートデータを取得する |
---|
174 | $objQuery = new SC_Query(); |
---|
175 | $sql = "SELECT template_code,template_name FROM dtb_templates ORDER BY create_date DESC"; |
---|
176 | $arrTemplate = $objQuery->getall($sql); |
---|
177 | |
---|
178 | switch($this->tpl_subno_template) { |
---|
179 | // TOP |
---|
180 | case $this->arrSubnavi['title'][1]: |
---|
181 | $Image = "TopImage.jpg"; // イメージの配列要素名格納用 |
---|
182 | $disp = $this->arrSubnavi['title'][1]; |
---|
183 | break; |
---|
184 | |
---|
185 | // 商品一覧 |
---|
186 | case $this->arrSubnavi['title'][2]: |
---|
187 | $Image = "ProdImage.jpg"; // イメージの配列要素名格納用 |
---|
188 | $disp = $this->arrSubnavi['title'][2]; |
---|
189 | break; |
---|
190 | |
---|
191 | // 商品詳細 |
---|
192 | case $this->arrSubnavi['title'][3]: |
---|
193 | $Image = "DetailImage.jpg"; // イメージの配列要素名格納用 |
---|
194 | $disp = $this->arrSubnavi['title'][3]; |
---|
195 | break; |
---|
196 | |
---|
197 | // MYページ |
---|
198 | case $this->arrSubnavi['title'][4]: |
---|
199 | $Image = "MypageImage.jpg"; //イメージの配列要素名格納用 |
---|
200 | $disp = $this->arrSubnavi['title'][4]; |
---|
201 | break; |
---|
202 | } |
---|
203 | |
---|
204 | // 画像表示配列作成 |
---|
205 | foreach($arrTemplate as $key => $val){ |
---|
206 | $arrTemplateImage['image'][$val['template_code']] = $filepath . $val['template_code'] . "/" . $Image; |
---|
207 | $arrTemplateImage['code'][$key] = $val['template_code']; |
---|
208 | $arrTemplateImage['name'][$key] = $val['template_name']; |
---|
209 | } |
---|
210 | |
---|
211 | // 初期チェック |
---|
212 | if (isset($arrDefcheck[$disp])){ |
---|
213 | $arrTemplateImage['check'] = $arrDefcheck[$disp]; |
---|
214 | }else{ |
---|
215 | $arrTemplateImage['check'] = 1; |
---|
216 | } |
---|
217 | |
---|
218 | return $arrTemplateImage; |
---|
219 | } |
---|
220 | |
---|
221 | /** |
---|
222 | * DBに保存されているテンプレートデータを取得する. |
---|
223 | * |
---|
224 | * @return array DBに保存されているテンプレートデータの配列 |
---|
225 | */ |
---|
226 | function lfgetTemplaeBaseData(){ |
---|
227 | $objDBConn = new SC_DbConn; // DB操作オブジェクト |
---|
228 | $sql = ""; // データ取得SQL生成用 |
---|
229 | $arrRet = array(); // データ取得用 |
---|
230 | |
---|
231 | $sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo"; |
---|
232 | $arrRet = $objDBConn->getAll($sql); |
---|
233 | |
---|
234 | return $arrRet[0]; |
---|
235 | } |
---|
236 | |
---|
237 | /** |
---|
238 | * DBにデータを保存する. |
---|
239 | * |
---|
240 | * @return integer 成功した場合 1 |
---|
241 | */ |
---|
242 | function lfUpdData(){ |
---|
243 | $objDBConn = new SC_DbConn; // DB操作オブジェクト |
---|
244 | $sql = ""; // データ取得SQL生成用 |
---|
245 | $arrRet = array(); // データ取得用(更新判定) |
---|
246 | |
---|
247 | // データ取得 |
---|
248 | $sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo"; |
---|
249 | $arrRet = $objDBConn->getAll($sql); |
---|
250 | |
---|
251 | $chk_tpl = $_POST['check_template']; |
---|
252 | // データが取得できなければINSERT、できればUPDATE |
---|
253 | if (isset($arrRet[0])){ |
---|
254 | // UPDATE |
---|
255 | $arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl); |
---|
256 | $sql= "update dtb_baseinfo set top_tpl = ?, product_tpl = ?, detail_tpl = ?, mypage_tpl = ?, update_date = now()"; |
---|
257 | }else{ |
---|
258 | // INSERT |
---|
259 | $arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl); |
---|
260 | $sql= "insert into dtb_baseinfo (top_tpl,product_tpl,detail_tpl,mypage_tpl, update_date) values (?,?,?,?,now());"; |
---|
261 | } |
---|
262 | |
---|
263 | // SQL実行 |
---|
264 | $arrRet = $objDBConn->query($sql,$arrVal); |
---|
265 | |
---|
266 | return $arrRet; |
---|
267 | } |
---|
268 | |
---|
269 | /** |
---|
270 | * テンプレートを変更する. |
---|
271 | * |
---|
272 | * @return void |
---|
273 | */ |
---|
274 | function lfChangeTemplate(){ |
---|
275 | $data = array(); |
---|
276 | $masterData = new SC_DB_MasterData_Ex(); |
---|
277 | |
---|
278 | // FIXME DBのデータを更新 |
---|
279 | $masterData->updateMasterData("mtb_constants", array(), |
---|
280 | array("TEMPLATE_NAME" => '"' . $_POST['check_template'] . '"')); |
---|
281 | |
---|
282 | // 更新したデータを取得 |
---|
283 | $mtb_constants = $masterData->getDBMasterData("mtb_constants"); |
---|
284 | |
---|
285 | // キャッシュを生成 |
---|
286 | $masterData->clearCache("mtb_constants"); |
---|
287 | $masterData->createCache("mtb_constants", $mtb_constants, true, |
---|
288 | array("id", "remarks", "rank")); |
---|
289 | } |
---|
290 | |
---|
291 | /** |
---|
292 | * テンプレートファイル圧縮してダウンロードする. |
---|
293 | * |
---|
294 | * @param string テンプレートコード |
---|
295 | * @return void |
---|
296 | */ |
---|
297 | function lfDownloadTemplate($template_code){ |
---|
298 | require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_FileManager_Ex.php"); |
---|
299 | $objFileManager = new SC_Helper_FileManager_Ex(); |
---|
300 | $filename = $template_code. ".tar.gz"; |
---|
301 | $dl_file = USER_TEMPLATE_PATH.$filename; |
---|
302 | $target_path = USER_TEMPLATE_PATH . $template_code . "/"; |
---|
303 | |
---|
304 | $mess = ""; |
---|
305 | // Smarty テンプレートをコピー |
---|
306 | $target_smarty = $target_path . "Smarty/"; |
---|
307 | $mess .= SC_Utils_Ex::sfCopyDir(DATA_PATH . "Smarty/templates/" . $template_code . "/", $target_smarty, $mess); |
---|
308 | |
---|
309 | // ファイルの圧縮 |
---|
310 | $tar = new Archive_Tar($dl_file, TRUE); |
---|
311 | // ファイル一覧取得 |
---|
312 | $arrFileHash = $objFileManager->sfGetFileList(USER_TEMPLATE_PATH.$template_code); |
---|
313 | foreach($arrFileHash as $val) { |
---|
314 | $arrFileList[] = $val['file_name']; |
---|
315 | } |
---|
316 | // ディレクトリを移動 |
---|
317 | chdir(USER_TEMPLATE_PATH.$template_code); |
---|
318 | |
---|
319 | //圧縮をおこなう |
---|
320 | $zip = $tar->create($arrFileList); |
---|
321 | |
---|
322 | // ダウンロード開始 |
---|
323 | Header("Content-disposition: attachment; filename=${filename}"); |
---|
324 | Header("Content-type: application/octet-stream; name=${dl_file}"); |
---|
325 | header("Content-Length: " .filesize($dl_file)); |
---|
326 | readfile ($dl_file); |
---|
327 | // 圧縮ファイル削除 |
---|
328 | unlink($dl_file); |
---|
329 | |
---|
330 | exit(); |
---|
331 | } |
---|
332 | } |
---|
333 | ?> |
---|