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

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