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

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