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

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