source: branches/beta/html/admin/design/index.php @ 15825

Revision 15825, 13.1 KB checked in by adachi, 19 years ago (diff)

*feature-templatesブランチをマージ r15704-15822
・テンプレート機能改善
・テンプレート変数$URL_DIR, $TPL_PKG_URLの追加

*細かな修正
・myページのforgot/index.phpへのリンクを修正
・使用していないファイルの削除 test/*, faq/*, fax/*, upgrade/*
・user_dataにtplファイルへのアクセスをはじくhtaccessを設置

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 . "include/page_layout.inc");
9
10// ǧ¾ÚȽÄê
11sfIsSuccess(new SC_Session());
12
13class LC_Page {
14    var $arrForm;
15    var $arrHidden;
16
17    function LC_Page() {
18        $this->tpl_mainpage = 'design/index.tpl';
19        $this->tpl_subnavi = 'design/subnavi.tpl';
20        $this->tpl_subno = "layout";
21        $this->tpl_mainno = "design";
22        $this->tpl_subtitle = '¥ì¥¤¥¢¥¦¥ÈÊÔ½¸';
23    }
24}
25
26$objPage = new LC_Page();
27$objView = new SC_AdminView();
28
29// ¥Ú¡¼¥¸ID¤ò¼èÆÀ
30if (isset($_GET['page_id'])) {
31    $page_id = $_GET['page_id'];
32}else if ($_POST['page_id']){
33    $page_id = $_POST['page_id'];
34}else{
35    $page_id = 1;
36}
37
38// ÊÔ½¸²Äǽ¥Ú¡¼¥¸¤ò¼èÆÀ
39$objPage->arrEditPage = lfgetPageData();
40
41// ¥Ö¥í¥Ã¥¯ÇÛÃÖÍѥǡ¼¥¿¤ò¼èÆÀ
42$sel   = ", pos.target_id, pos.bloc_id, pos.bloc_row ";
43$from  = ", dtb_blocposition AS pos";
44$where = " where ";
45$where .= " lay.page_id = ? AND ";
46$where .= "lay.page_id = pos.page_id AND exists (select bloc_id from dtb_bloc as blc where pos.bloc_id = blc.bloc_id) ORDER BY lay.page_id,pos.target_id, pos.bloc_row, pos.bloc_id ";
47$arrData = array($page_id);
48$arrBlocPos = lfgetLayoutData($sel, $from, $where, $arrData );
49
50// ¥Ç¡¼¥¿¤Î¸ºß¥Á¥§¥Ã¥¯¤ò¹Ô¤¦
51$arrPageData = lfgetPageData("page_id = ?", array($page_id));
52if (count($arrPageData) <= 0) {
53    $exists_page = 0;
54}else{
55    $exists_page = 1;
56}
57$objPage->exists_page = $exists_page;
58
59// ¥á¥Ã¥»¡¼¥¸É½¼¨
60if ($_GET['msg'] == "on") {
61    $objPage->complate_msg="alert('ÅÐÏ¿¤¬´°Î»¤·¤Þ¤·¤¿¡£');";
62}
63
64// ¥Ö¥í¥Ã¥¯¤ò¼èÆÀ
65$arrBloc = lfgetBlocData();
66
67// ¿·µ¬¥Ö¥í¥Ã¥¯ºîÀ®
68if ($_POST['mode'] == 'new_bloc') {
69    header("location: ./bloc.php");
70}
71
72// ¿·µ¬¥Ú¡¼¥¸ºîÀ®
73if ($_POST['mode'] == 'new_page') {
74    header("location: ./main_edit.php");
75}
76
77// ¥Ç¡¼¥¿ÅÐÏ¿½èÍý
78if ($_POST['mode'] == 'confirm' or $_POST['mode'] == 'preview') {
79
80    $arrPageData = array();
81    if ($_POST['mode'] == 'preview') {
82        $arrPageData = lfgetPageData(" page_id = ? " , array($page_id));
83        $page_id = "0";
84        $_POST['page_id'] = "0";
85    }
86
87    // ¹¹¿·ÍѤ˥ǡ¼¥¿¤òÀ°¤¨¤ë
88    $arrUpdBlocData = array();
89    $arrTargetFlip = array_flip($arrTarget);
90
91    $upd_cnt = 1;
92    $arrUpdData[$upd_cnt]['page_id'] = $_POST['page_id'];
93
94    // POST¤Î¥Ç¡¼¥¿¤ò»È¤¤¤ä¤¹¤¤¤è¤¦¤Ë½¤Àµ
95    for($upd_cnt = 1; $upd_cnt <= $_POST['bloc_cnt']; $upd_cnt++){
96        if (!isset($_POST['id_'.$upd_cnt])) {
97            break;
98        }
99        $arrUpdBlocData[$upd_cnt]['name']       = $_POST['name_'.$upd_cnt];                         // ¥Ö¥í¥Ã¥¯Ì¾¾Î
100        $arrUpdBlocData[$upd_cnt]['id']         = $_POST['id_'.$upd_cnt];                           // ¥Ö¥í¥Ã¥¯ID
101        $arrUpdBlocData[$upd_cnt]['target_id']  = $arrTargetFlip[$_POST['target_id_'.$upd_cnt]];    // ¥¿¡¼¥²¥Ã¥ÈID
102        $arrUpdBlocData[$upd_cnt]['top']        = $_POST['top_'.$upd_cnt];                          // TOPºÂɸ
103        $arrUpdBlocData[$upd_cnt]['update_url'] = $_SERVER['HTTP_REFERER'];                         // ¹¹¿·URL
104    }
105
106    // ¥Ç¡¼¥¿¤Î¹¹¿·¤ò¹Ô¤¦
107    $objDBConn = new SC_DbConn;     // DBÁàºî¥ª¥Ö¥¸¥§¥¯¥È
108    $arrRet = array();              // ¥Ç¡¼¥¿¼èÆÀÍÑ
109
110    // delete¼Â¹Ô
111    $del_sql = "";
112    $del_sql .= "DELETE FROM dtb_blocposition WHERE page_id = ? ";
113    $arrRet = $objDBConn->query($del_sql,array($page_id));
114
115    // ¥Ö¥í¥Ã¥¯¤Î½ç½ø¤ò¼èÆÀ¤·¡¢¹¹¿·¤ò¹Ô¤¦
116    foreach($arrUpdBlocData as $key => $val){
117        // ¥Ö¥í¥Ã¥¯¤Î½ç½ø¤ò¼èÆÀ
118        $bloc_row = lfGetRowID($arrUpdBlocData, $val);
119        $arrUpdBlocData[$key]['bloc_row'] = $bloc_row;
120        $arrUpdBlocData[$key]['page_id']    = $_POST['page_id'];    // ¥Ú¡¼¥¸ID
121
122        if ($arrUpdBlocData[$key]['target_id'] == 5) {
123            $arrUpdBlocData[$key]['bloc_row'] = "0";
124        }
125
126        // insertʸÀ¸À®
127        $ins_sql = "";
128        $ins_sql .= "INSERT INTO dtb_blocposition ";
129        $ins_sql .= " values ( ";
130        $ins_sql .= "   ?  ";           // ¥Ú¡¼¥¸ID
131        $ins_sql .= "   ,? ";           // ¥¿¡¼¥²¥Ã¥ÈID
132        $ins_sql .= "   ,? ";           // ¥Ö¥í¥Ã¥¯ID
133        $ins_sql .= "   ,? ";           // ¥Ö¥í¥Ã¥¯¤ÎÊÂ¤Ó½ç½ø
134        $ins_sql .= "   ,(SELECT filename FROM dtb_bloc WHERE bloc_id = ?) ";           // ¥Õ¥¡¥¤¥ë̾¾Î
135        $ins_sql .= "   )  ";
136
137        // insert¥Ç¡¼¥¿À¸À®
138        $arrInsData = array($page_id,
139                             $arrUpdBlocData[$key]['target_id'],
140                             $arrUpdBlocData[$key]['id'],
141                             $arrUpdBlocData[$key]['bloc_row'],
142                             $arrUpdBlocData[$key]['id']
143                            );
144        // SQL¼Â¹Ô
145        $arrRet = $objDBConn->query($ins_sql,$arrInsData);
146    }
147
148    // ¥×¥ì¥Ó¥å¡¼½èÍý
149    if ($_POST['mode'] == 'preview') {
150        if ($page_id === "") {
151            header("location: ./index.php");
152        }
153        lfSetPreData($arrPageData);
154
155        $_SESSION['preview'] = "ON";
156        header("Location: ". URL_DIR . "preview/index.php");
157    }else{
158        header("Location: ./index.php?page_id=$page_id&msg=on");
159    }
160}
161
162// ¥Ç¡¼¥¿ºï½ü½èÍý ¥Ù¡¼¥¹¥Ç¡¼¥¿¤Ç¤Ê¤±¤ì¤Ð¥Õ¥¡¥¤¥ë¤òºï½ü
163if ($_POST['mode'] == 'delete' and  !lfCheckBaseData($page_id)) {
164    lfDelPageData($page_id);
165}
166
167// ¥Ö¥í¥Ã¥¯¾ðÊó¤ò²èÌÌÇÛÃÖÍѤËÊÔ½¸
168$tpl_arrBloc = array();
169$cnt = 0;
170// »ÈÍѤµ¤ì¤Æ¤¤¤ë¥Ö¥í¥Ã¥¯¥Ç¡¼¥¿¤òÀ¸À®
171foreach($arrBlocPos as $key => $val){
172    if ($val['page_id'] == $page_id) {
173        $tpl_arrBloc = lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt);
174        $cnt++;
175    }
176}
177
178// ̤»ÈÍѤΥ֥í¥Ã¥¯¥Ç¡¼¥¿¤òÄɲÃ
179foreach($arrBloc as $key => $val){
180    if (!lfChkBloc($val, $tpl_arrBloc)) {
181        $val['target_id'] = 5;  // ̤»ÈÍѤËÄɲ乤ë
182        $tpl_arrBloc = lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt);
183        $cnt++;
184    }
185}
186
187$objPage->tpl_arrBloc = $tpl_arrBloc;
188$objPage->bloc_cnt = count($tpl_arrBloc);
189$objPage->page_id = $page_id;
190
191// ¥Ú¡¼¥¸Ì¾¾Î¤ò¼èÆÀ
192$arrPageData = lfgetPageData(' page_id = ?', array($page_id));
193$objPage->arrPageData = $arrPageData[0];
194
195global $GLOBAL_ERR;
196$errCnt = 0;
197if ($GLOBAL_ERR != "") {
198    $arrGlobalErr = explode("\n",$GLOBAL_ERR);
199    $errCnt = count($arrGlobalErr) - 8;
200    if ($errCnt < 0 ) {
201        $errCnt = 0;
202    }
203}
204$objPage->errCnt = $errCnt;
205
206// ²èÌ̤Îɽ¼¨
207$objView->assignobj($objPage);
208$objView->display(MAIN_FRAME);
209
210//---------------------------------------------------------------------------------------------------------------------------------------------------------
211
212/**************************************************************************************************************
213 * ´Ø¿ô̾   ¡§lfgetLayoutData
214 * ½èÍýÆâÍÆ ¡§ÊÔ½¸²Äǽ¤Ê¥Ú¡¼¥¸¾ðÊó¤ò¼èÆÀ¤¹¤ë
215 * °ú¿ô1    ¡§$sel    ޥޥޥ Select¶çʸ
216 * °ú¿ô2    ¡§$where  ޥޥޥ Where¶çʸ
217 * °ú¿ô3    ¡§$arrVal ޥޥޥ Where¶ç¤Î¹Ê¹þ¾ò·ïÃÍ
218 * Ìá¤êÃÍ   ¡§¥Ú¡¼¥¸¥ì¥¤¥¢¥¦¥È¾ðÊó
219 **************************************************************************************************************/
220function lfgetLayoutData($sel = '' , $from = '', $where = '', $arrVal = ''){
221    $objDBConn = new SC_DbConn;     // DBÁàºî¥ª¥Ö¥¸¥§¥¯¥È
222    $sql = "";                      // ¥Ç¡¼¥¿¼èÆÀSQLÀ¸À®ÍÑ
223    $arrRet = array();              // ¥Ç¡¼¥¿¼èÆÀÍÑ
224
225    // SQLÀ¸À®
226
227    $sql = "";
228    $sql .= " select ";
229    $sql .= "     lay.page_id ";
230    $sql .= "     ,lay.page_name ";
231    $sql .= "     ,lay.url ";
232    $sql .= "     ,lay.author ";
233    $sql .= "     ,lay.description ";
234    $sql .= "     ,lay.keyword ";
235    $sql .= "     ,lay.update_url ";
236    $sql .= "     ,lay.create_date ";
237    $sql .= "     ,lay.update_date ";
238
239    // Select¶ç¤Î»ØÄ꤬¤¢¤ì¤ÐÄɲÃ
240    if ($sel != '') {
241        $sql .= $sel;
242    }
243
244    $sql .= " from dtb_pagelayout AS lay ";
245    // From¶ç¤Î»ØÄ꤬¤¢¤ì¤ÐÄɲÃ
246    if ($from != '') {
247        $sql .= $from;
248    }
249
250    // where¶ç¤Î»ØÄ꤬¤¢¤ì¤ÐÄɲÃ
251    if ($where != '') {
252        $sql .= $where;
253    }else{
254        $sql .= " ORDER BY lay.page_id ";
255    }
256
257    $arrRet = $objDBConn->getAll($sql, $arrVal);
258
259    return $arrRet;
260}
261
262/**************************************************************************************************************
263 * ´Ø¿ô̾   ¡§lfgetBlocData
264 * ½èÍýÆâÍÆ ¡§¥Ö¥í¥Ã¥¯¾ðÊó¤ò¼èÆÀ¤¹¤ë
265 * °ú¿ô1    ¡§$where  ޥޥޥ Where¶çʸ
266 * °ú¿ô2    ¡§$arrVal ޥޥޥ Where¶ç¤Î¹Ê¹þ¾ò·ïÃÍ
267 * Ìá¤êÃÍ   ¡§¥Ö¥í¥Ã¥¯¾ðÊó
268 **************************************************************************************************************/
269function lfgetBlocData($where = '', $arrVal = ''){
270    $objDBConn = new SC_DbConn;     // DBÁàºî¥ª¥Ö¥¸¥§¥¯¥È
271    $sql = "";                      // ¥Ç¡¼¥¿¼èÆÀSQLÀ¸À®ÍÑ
272    $arrRet = array();              // ¥Ç¡¼¥¿¼èÆÀÍÑ
273
274    // SQLÀ¸À®
275    $sql = "";
276    $sql .= " SELECT ";
277    $sql .= "   bloc_id";
278    $sql .= "   ,bloc_name";
279    $sql .= "   ,tpl_path";
280    $sql .= "   ,filename";
281    $sql .= "   ,update_date";
282    $sql .= " FROM ";
283    $sql .= "   dtb_bloc";
284
285    // where¶ç¤Î»ØÄ꤬¤¢¤ì¤ÐÄɲÃ
286    if ($where != '') {
287        $sql .= " WHERE " . $where;
288    }
289
290    $sql .= " ORDER BY  bloc_id";
291
292    $arrRet = $objDBConn->getAll($sql, $arrVal);
293
294    return $arrRet;
295}
296
297/**************************************************************************************************************
298 * ´Ø¿ô̾   ¡§lfSetBlocData
299 * ½èÍýÆâÍÆ ¡§¥Ö¥í¥Ã¥¯¾ðÊó¤ÎÇÛÎó¤òÀ¸À®¤¹¤ë
300 * °ú¿ô1    ¡§$arrBloc      ޥޥޥ Bloc¾ðÊó
301 * °ú¿ô2    ¡§$tpl_arrBloc  ޥޥޥ ¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤¹¤ëÇÛÎó
302 * °ú¿ô3    ¡§$cnt          ޥޥޥ ÇÛÎóÈÖ¹æ
303 * Ìá¤êÃÍ   ¡§¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤·¤¿ÇÛÎó
304 **************************************************************************************************************/
305function lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt) {
306    global $arrTarget;
307
308    $tpl_arrBloc[$cnt]['target_id'] = $arrTarget[$val['target_id']];
309    $tpl_arrBloc[$cnt]['bloc_id'] = $val['bloc_id'];
310    $tpl_arrBloc[$cnt]['bloc_row'] = $val['bloc_row'];
311
312    foreach($arrBloc as $bloc_key => $bloc_val){
313        if ($bloc_val['bloc_id'] == $val['bloc_id']) {
314            $bloc_name = $bloc_val['bloc_name'];
315            break;
316        }
317    }
318    $tpl_arrBloc[$cnt]['name'] = $bloc_name;
319
320    return $tpl_arrBloc;
321}
322
323/**************************************************************************************************************
324 * ´Ø¿ô̾   ¡§lfChkBloc
325 * ½èÍýÆâÍÆ ¡§¥Ö¥í¥Ã¥¯ID¤¬ÇÛÎó¤ËÄɲäµ¤ì¤Æ¤¤¤ë¤«¤Î¥Á¥§¥Ã¥¯¤ò¹Ô¤¦
326 * °ú¿ô1    ¡§$arrBloc    ޥޥޥ Bloc¾ðÊó
327 * °ú¿ô2    ¡§$arrChkData ޥޥޥ ¥Á¥§¥Ã¥¯¤ò¹Ô¤¦¥Ç¡¼¥¿ÇÛÎó
328 * Ìá¤êÃÍ   ¡§True  ޥޥޥ ¸ºß¤¹¤ë
329 *          ¡¡False ޥޥޥ ¸ºß¤·¤Ê¤¤
330 **************************************************************************************************************/
331function lfChkBloc($arrBloc, $arrChkData) {
332    foreach($arrChkData as $key => $val){
333        if ($val['bloc_id'] === $arrBloc['bloc_id'] ) {
334            // ÇÛÎó¤Ë¸ºß¤¹¤ì¤ÐTrue¤òÊÖ¤¹
335            return true;
336        }
337    }
338
339    // ÇÛÎó¤Ë¸ºß¤·¤Ê¤±¤ì¤ÐFlase¤òÊÖ¤¹
340    return false;
341}
342
343/**************************************************************************************************************
344 * ´Ø¿ô̾   ¡§lfGetRowID
345 * ½èÍýÆâÍÆ ¡§¥Ö¥í¥Ã¥¯ID¤¬²¿ÈÖÌܤËÇÛÃÖ¤µ¤ì¤Æ¤¤¤ë¤«¤òÄ´¤Ù¤ë
346 * °ú¿ô1    ¡§$arrUpdData   Ž¥Ž¥Ž¥ ¹¹¿·¾ðÊó
347 * °ú¿ô2    ¡§$arrObj       Ž¥Ž¥Ž¥ ¥Á¥§¥Ã¥¯¤ò¹Ô¤¦¥Ç¡¼¥¿ÇÛÎó
348 * Ìá¤êÃÍ   ¡§½çÈÖ
349 **************************************************************************************************************/
350function lfGetRowID($arrUpdData, $arrObj){
351    $no = 0; // ¥«¥¦¥ó¥ÈÍÑ¡ÊÆ±¤¸¥Ç¡¼¥¿¤¬É¬¤º1·ï¤¢¤ë¤Î¤Ç¡¢½é´üÃͤÏ0¡Ë
352
353    // Âоݥǡ¼¥¿¤¬²¿ÈÖÌܤËÇÛÃÖ¤µ¤ì¤Æ¤¤¤ë¤Î¤«¤ò¼èÆÀ¤¹¤ë¡£
354    foreach ($arrUpdData as $key => $val) {
355        if ($val['target_id'] === $arrObj['target_id'] and $val['top'] <= $arrObj['top']){
356            $no++;
357        }
358    }
359    // ÈÖ¹æ¤òÊÖ¤¹
360    return $no;
361}
362
363/**************************************************************************************************************
364 * ´Ø¿ô̾   ¡§lfGetRowID
365 * ½èÍýÆâÍÆ ¡§¥Ö¥í¥Ã¥¯ID¤¬²¿ÈÖÌܤËÇÛÃÖ¤µ¤ì¤Æ¤¤¤ë¤«¤òÄ´¤Ù¤ë
366 * °ú¿ô1    ¡§$arrUpdData   Ž¥Ž¥Ž¥ ¹¹¿·¾ðÊó
367 * °ú¿ô2    ¡§$arrObj       Ž¥Ž¥Ž¥ ¥Á¥§¥Ã¥¯¤ò¹Ô¤¦¥Ç¡¼¥¿ÇÛÎó
368 * Ìá¤êÃÍ   ¡§½çÈÖ
369 **************************************************************************************************************/
370function lfSetPreData($arrPageData){
371    $objDBConn = new SC_DbConn;     // DBÁàºî¥ª¥Ö¥¸¥§¥¯¥È
372    $sql = "";                      // ¥Ç¡¼¥¿¹¹¿·SQLÀ¸À®ÍÑ
373    $ret = "";                      // ¥Ç¡¼¥¿¹¹¿··ë²Ì³ÊǼÍÑ
374    $arrUpdData = array();          // ¹¹¿·¥Ç¡¼¥¿À¸À®ÍÑ
375    $filename = uniqid("");
376
377    $arrPreData = lfgetPageData(" page_id = ? " , array("0"));
378
379    // tpl¥Õ¥¡¥¤¥ë¤Îºï½ü
380    $del_tpl = USER_PATH . "templates/" . $arrPreData[0]['filename'] . '.tpl';
381    if (file_exists($del_tpl)){
382        unlink($del_tpl);
383    }
384
385    // ¥×¥ì¥Ó¥å¡¼ÍÑtpl¥Õ¥¡¥¤¥ë¤Î¥³¥Ô¡¼
386    $tplfile = $arrPageData[0]['tpl_dir'] . $arrPageData[0]['filename'];
387
388    if($tplfile == ""){
389        // tpl¥Õ¥¡¥¤¥ë¤¬¶õ¤Î¾ì¹ç¤Ë¤ÏMY¥Ú¡¼¥¸¤ÈȽÃÇ
390        $tplfile = "user_data/templates/mypage/index";
391    }
392    copy(HTML_PATH . $tplfile . ".tpl", USER_PATH . "templates/" . $filename . ".tpl");
393
394    // ¹¹¿·¥Ç¡¼¥¿¤Î¼èÆÀ
395    $sql = "select page_name, header_chk, footer_chk from dtb_pagelayout where page_id = ?";
396    $ret = $objDBConn->getAll($sql, array($arrPageData[0]['page_id']));
397
398    // db¥Ç¡¼¥¿¤Î¥³¥Ô¡¼
399    $sql = " update dtb_pagelayout set ";
400    $sql .= "     page_name = ?";
401    $sql .= "     ,header_chk = ?";
402    $sql .= "     ,footer_chk = ?";
403    $sql .= "     ,url = ?";
404    $sql .= "     ,tpl_dir = ?";
405    $sql .= "     ,filename = ?";
406    $sql .= " where page_id = 0";
407
408    $arrUpdData = array($ret[0]['page_id']
409                        ,$ret[0]['page_id']
410                        ,$ret[0]['page_id']
411                        ,USER_DIR."templates/"
412                        ,USER_DIR."templates/"
413                        ,$filename
414                        );
415
416    $objDBConn->query($sql,$arrUpdData);
417}
Note: See TracBrowser for help on using the repository browser.