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

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