source: temp/trunk/html/admin/design/index.php @ 3577

Revision 3577, 11.9 KB checked in by kakinaka, 20 years ago (diff)

blank

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