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

Revision 1328, 11.2 KB checked in by naka, 20 years ago (diff)

* empty log message *

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