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

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