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

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