source: branches/rel/html/admin/design/template.php @ 12157

Revision 12157, 11.9 KB checked in by uehara, 16 years ago (diff)
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.