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

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