source: branches/comu-utf8/html/admin/design/template.php @ 15099

Revision 15099, 12.9 KB checked in by Yammy, 17 years ago (diff)

UTF-8変換済みファイルインポート
1.3.4ベース

Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../../require.php");
8require_once(DATA_PATH . "module/Tar.php");
9require_once(DATA_PATH . "include/file_manager.inc");
10require_once(DATA_PATH . "module/SearchReplace.php");
11
12class LC_Page {
13    var $arrForm;
14    var $arrHidden;
15    var $arrSubnavi = array(
16        'title' => array(
17            1 => 'top',
18            2 => 'product',
19            3 => 'detail',
20            4 => 'mypage'
21        ),
22        'name' =>array(
23            1 => 'TOPページ',
24            2 => '商品一覧ページ',
25            3 => '商品詳細ページ',
26            4 => 'MYページ'
27        )
28    );
29
30    function LC_Page() {
31        $this->tpl_mainpage = 'design/template.tpl';
32        $this->tpl_subnavi = 'design/subnavi.tpl';
33        $this->tpl_subno = 'template';
34        $this->tpl_subno_template = $this->arrSubnavi['title'][1];
35        $this->tpl_TemplateName = $this->arrTemplateName['name'][1];
36        $this->tpl_mainno = "design";
37        $this->tpl_subtitle = 'テンプレート設定';
38    }
39}
40
41$objPage = new LC_Page();
42$objView = new SC_AdminView();
43$objSess = new SC_Session();
44
45// 認証可否の判定
46$objSess = new SC_Session();
47sfIsSuccess($objSess);
48
49// GETの値を受け取る
50$get_tpl_subno_template = $_GET['tpl_subno_template'];
51
52// GETで値が送られている場合にはその値を元に画面表示を切り替える
53if ($get_tpl_subno_template != ""){
54    // 送られてきた値が配列に登録されていなければTOPを表示
55    if (in_array($get_tpl_subno_template,$objPage->arrSubnavi['title'])){
56        $tpl_subno_template = $get_tpl_subno_template;
57    }else{
58        $tpl_subno_template = $objPage->arrSubnavi['title'][1];
59    }
60} else {
61    // GETで値がなければPOSTの値を使用する
62    if ($_POST['tpl_subno_template'] != ""){
63        $tpl_subno_template = $_POST['tpl_subno_template'];
64    }else{
65        $tpl_subno_template = $objPage->arrSubnavi['title'][1];
66    }
67}
68$objPage->tpl_subno_template = $tpl_subno_template;
69$key = array_keys($objPage->arrSubnavi['title'], $tpl_subno_template);
70$objPage->template_name = $objPage->arrSubnavi['name'][$key[0]];
71
72// 登録を押されたばあにはDBへデータを更新に行く
73switch($_POST['mode']) {
74case 'confirm':
75    // DBへデータ更新
76    lfUpdData();
77   
78    // テンプレートの上書き
79    lfChangeTemplate();
80   
81    // 完了メッセージ
82    $objPage->tpl_onload="alert('登録が完了しました。');";
83    break;
84case 'download':
85    lfDownloadTemplate($_POST['check_template']);
86    break;
87default:
88    break;
89}
90
91// POST値の引き継ぎ
92$objPage->arrForm = $_POST;
93
94// 画像取得
95$tpl_arrTemplate = array();
96$objPage->arrTemplate = lfgetTemplate();
97
98// デフォルトチェック取得
99$objPage->MainImage = $objPage->arrTemplate['check'];
100$objPage->arrTemplate['check'] = array($objPage->arrTemplate['check']=>"check");
101
102// 画面の表示
103$objView->assignobj($objPage);
104$objView->display(MAIN_FRAME);
105
106//---------------------------------------------------------------------------------------------------------------------------------------------------------
107
108/**************************************************************************************************************
109 * 関数名  :lfgetTemplate
110 * 処理内容 :画面に表示する画像を取得する
111 * 引数       :なし
112 * 戻り値  :画面に表示する画像(配列)
113 **************************************************************************************************************/
114function lfgetTemplate(){
115    global $objPage;
116    $filepath = "user_data/templates/";
117   
118    $arrTemplateImage = array();    // 画面表示画像格納用
119    $Image = "";                    // イメージの配列要素名格納用
120    $disp = "";
121    $arrDefcheck = array();         // radioボタンのデフォルトチェック格納用
122   
123    // DBから現在選択されているデータ取得
124    $arrDefcheck = lfgetTemplaeBaseData();
125   
126    // テンプレートデータを取得する
127    $objQuery = new SC_Query();
128    $sql = "SELECT template_code,template_name FROM dtb_templates ORDER BY create_date DESC";
129    $arrTemplate = $objQuery->getall($sql);
130   
131    switch($objPage->tpl_subno_template) {
132        // TOP
133        case $objPage->arrSubnavi['title'][1]:
134            $Image = "TopImage.jpg";            // イメージの配列要素名格納用
135            $disp = $objPage->arrSubnavi['title'][1];
136            break;
137           
138        // 商品一覧
139        case $objPage->arrSubnavi['title'][2]:
140            $Image = "ProdImage.jpg";           // イメージの配列要素名格納用
141            $disp = $objPage->arrSubnavi['title'][2];
142            break;
143           
144        // 商品詳細
145        case $objPage->arrSubnavi['title'][3]:
146            $Image = "DetailImage.jpg";         // イメージの配列要素名格納用
147            $disp = $objPage->arrSubnavi['title'][3];
148            break;
149           
150        // MYページ
151        case $objPage->arrSubnavi['title'][4]:
152            $Image = "MypageImage.jpg";         //イメージの配列要素名格納用
153            $disp = $objPage->arrSubnavi['title'][4];
154            break;
155    }
156
157    // 画像表示配列作成
158    foreach($arrTemplate as $key => $val){
159        $arrTemplateImage['image'][$val['template_code']] = $filepath . $val['template_code'] . "/" . $Image;
160        $arrTemplateImage['code'][$key] = $val['template_code'];
161    }
162   
163    // 初期チェック
164    if (isset($arrDefcheck[$disp])){
165        $arrTemplateImage['check'] = $arrDefcheck[$disp];
166    }else{
167        $arrTemplateImage['check'] = 1;
168    }
169   
170    return $arrTemplateImage;
171}
172
173/**************************************************************************************************************
174 * 関数名  :lfgetTemplaeBaseData
175 * 処理内容 :DBに保存されているテンプレートデータを取得する
176 * 引数       :なし
177 * 戻り値  :DBに保存されているテンプレートデータ(配列)
178 **************************************************************************************************************/
179function lfgetTemplaeBaseData(){
180    $objDBConn = new SC_DbConn;     // DB操作オブジェクト
181    $sql = "";                      // データ取得SQL生成用
182    $arrRet = array();              // データ取得用
183   
184    $sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo";
185    $arrRet = $objDBConn->getAll($sql);
186   
187    return $arrRet[0];
188}
189
190/**************************************************************************************************************
191 * 関数名  :lfUpdData
192 * 処理内容 :DBにデータを保存する
193 * 引数       :なし
194 * 戻り値  :成功 TRUE、エラー FALSE
195 **************************************************************************************************************/
196function lfUpdData(){
197    global $objPage;
198    $objDBConn = new SC_DbConn;     // DB操作オブジェクト
199    $sql = "";                      // データ取得SQL生成用
200    $arrRet = array();              // データ取得用(更新判定)
201
202    // データ取得   
203    $sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo";
204    $arrRet = $objDBConn->getAll($sql);
205
206    $chk_tpl = $_POST['check_template'];
207    // データが取得できなければINSERT、できればUPDATE
208    if (isset($arrRet[0])){
209        // UPDATE
210        $arrVal = $arrRet[0];
211       
212        // TOPを変更した場合には全画面変更
213        if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){
214            $arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl);
215        }else{
216            $arrVal[$objPage->tpl_subno_template] = $chk_tpl;
217        }
218        $sql= "update dtb_baseinfo set top_tpl = ?, product_tpl = ?, detail_tpl = ?, mypage_tpl = ?, update_date = now()";
219    }else{
220        // INSERT
221        $arrVal = array(null,null,null,null);
222       
223        // TOPを変更した場合には全画面変更
224        if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){
225            $arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl);
226        }else{
227            $arrVal[$chk_tpl-1] =$chk_tpl;
228        }
229        $sql= "insert into dtb_baseinfo (top_tpl,product_tpl,detail_tpl,mypage_tpl, update_date) values (?,?,?,?,now());";
230    }
231
232    // SQL実行   
233    $arrRet = $objDBConn->query($sql,$arrVal);
234   
235    return $arrRet;
236}
237
238/**************************************************************************************************************
239 * 関数名  :lfChangeTemplate
240 * 処理内容 :テンプレートファイルを上書きする
241 * 引数       :なし
242 * 戻り値  :成功 TRUE、エラー FALSE
243 **************************************************************************************************************/
244function lfChangeTemplate(){
245    global $objPage;
246    $tpl_path = USER_PATH . "templates/";
247    $inc_path = USER_PATH . "include/";
248    $css_path = USER_PATH . "css/";
249   
250    $tpl_name = "";
251    $tpl_element = "";
252   
253    $chk_tpl = $_POST['check_template'];
254    $path = $tpl_path . $chk_tpl . "/";
255    $taget_tpl_path = $path . "/templates/";
256    $taget_inc_path = $path . "/include/";
257    $taget_css_path = $path . "/css/";
258    $save_tpl_path = $tpl_path;
259   
260    switch($objPage->tpl_subno_template) {
261        // TOP
262        case $objPage->arrSubnavi['title'][1]:
263            $tpl_element = "TopTemplate";           // イメージの配列要素名格納用
264            $tpl_name = "top.tpl";
265            break;
266           
267        // 商品一覧
268        case $objPage->arrSubnavi['title'][2]:
269            $tpl_element = "ProdTemplate";          // イメージの配列要素名格納用
270            $tpl_name = "list.tpl";
271            break;
272           
273        // 商品詳細
274        case $objPage->arrSubnavi['title'][3]:
275            $tpl_element = "DetailTemplate";            // イメージの配列要素名格納用
276            $tpl_name = "detail.tpl";
277            break;
278           
279        // MYページ
280        case $objPage->arrSubnavi['title'][4]:
281            $tpl_element = "MypageTemplate";            //イメージの配列要素名格納用
282            $tpl_name = "mypage.tpl";
283            break;
284
285        default:
286            break;
287    }
288
289    // 画像パスを書き換え
290    $img_path = '<!--{$smarty.const.URL_DIR}-->img/';
291    $displace_path = '<!--{$smarty.const.URL_DIR}-->'. USER_DIR . 'templates/' . $chk_tpl . '/img/';
292    $fs = new File_SearchReplace($img_path, $displace_path, "", $path, true);
293    $fs->doSearch();
294   
295    // TOPを変更した場合には全画面変更
296    if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){
297        // テンプレートファイルをコピー
298        copy($taget_tpl_path . "top.tpl", $save_tpl_path . "top.tpl");
299        copy($taget_tpl_path . "list.tpl", $save_tpl_path . "list.tpl");
300        copy($taget_tpl_path . "detail.tpl", $save_tpl_path . "detail.tpl");
301
302        // mypageはフォルダごとコピー
303        lfFolderCopy($taget_tpl_path."mypage/", $save_tpl_path . "mypage/");
304
305        // ブロックデータのコピー
306        lfFolderCopy($taget_inc_path."bloc/", $inc_path . "bloc/");
307
308        // ヘッダー,フッターコピー
309        copy($taget_inc_path . "header.tpl", $inc_path . "header.tpl");
310        copy($taget_inc_path . "footer.tpl", $inc_path . "footer.tpl");
311       
312        // CSSファイルのコピー
313        copy($taget_css_path . "contents.css", $css_path . "contents.css");
314
315    // mypageの場合にはフォルダごとコピーする
316    }elseif($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][4]){
317        lfFolderCopy($taget_tpl_path."mypage/", $save_tpl_path."mypage/");
318    }else{
319        // テンプレートファイルをコピー
320        copy($taget_tpl_path . $tpl_name, $save_tpl_path . $tpl_name);
321    }
322
323    // 画像パスを元に戻す   
324    $fs = new File_SearchReplace($displace_path, $img_path, "", $path, true);
325    $fs->doSearch();
326}
327
328/**************************************************************************************************************
329 * 関数名  :lfDownloadTemplate
330 * 処理内容 :テンプレートファイル圧縮してダウンロードする
331 * 引数1  :テンプレートコード
332 * 戻り値  :なし
333 **************************************************************************************************************/
334function lfDownloadTemplate($template_code){
335    $filename = $template_code. ".tar.gz";
336    $dl_file = USER_TEMPLATE_PATH.$filename;
337   
338    // IMGフォルダをコピー
339    $mess = "";
340    $mess = sfCopyDir(HTML_PATH."img/", USER_TEMPLATE_PATH.$template_code."/img/", $mess);
341   
342    // ファイルの圧縮
343    $tar = new Archive_Tar($dl_file, TRUE);
344    // ファイル一覧取得
345    $arrFileHash = sfGetFileList(USER_TEMPLATE_PATH.$template_code);
346    foreach($arrFileHash as $val) {
347        $arrFileList[] = $val['file_name'];
348    }
349    // ディレクトリを移動
350    chdir(USER_TEMPLATE_PATH.$template_code);
351   
352    //圧縮をおこなう
353    $zip = $tar->create($arrFileList);
354       
355    // ダウンロード開始
356    Header("Content-disposition: attachment; filename=${filename}");
357    Header("Content-type: application/octet-stream; name=${dl_file}");
358    header("Content-Length: " .filesize($dl_file));
359    readfile ($dl_file);
360    // 圧縮ファイル削除
361    unlink($dl_file);
362   
363    exit();
364}
365
366/**************************************************************************************************************
367 * 関数名  :lfFolderCopy
368 * 処理内容 :フォルダをコピーする
369 * 引数1  :コピー元パス
370 * 引数2  :コピー先パス
371 * 戻り値  :なし
372 **************************************************************************************************************/
373function lfFolderCopy($taget_path, $save_path){
374
375    // フォルダ内のファイルを取得する
376    $arrMypage=glob($taget_path . "*" );
377   
378    // フォルダがなければ作成する
379    if(!is_dir($save_path)){
380        mkdir($save_path);
381    }
382
383    // フォルダ内を全てコピー
384    foreach($arrMypage as $key => $val){
385        $matches = array();
386        mb_ereg("^(.*[\/])(.*)",$val, $matches);
387        $data=$matches[2];
388        copy($val, $save_path . $data);
389    }
390}
Note: See TracBrowser for help on using the repository browser.