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

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