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

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