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

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