Ignore:
Timestamp:
2007/09/11 22:27:00 (17 years ago)
Author:
nanasess
Message:

クラス化に伴う修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/feature-module-update/html/admin/design/index.php

    r15532 r15680  
    55 * http://www.lockon.co.jp/ 
    66 */ 
     7 
     8// {{{ requires 
    79require_once("../../require.php"); 
    8 require_once(DATA_PATH . "include/page_layout.inc"); 
     10require_once(CLASS_PATH . "page_extends/admin/design/LC_Page_Admin_Design_Ex.php"); 
    911 
    10 class LC_Page { 
    11     var $arrForm; 
    12     var $arrHidden; 
     12// }}} 
     13// {{{ generate page 
    1314 
    14     function LC_Page() { 
    15         $this->tpl_mainpage = 'design/index.tpl'; 
    16         $this->tpl_subnavi = 'design/subnavi.tpl'; 
    17         $this->tpl_subno = "layout";         
    18         $this->tpl_mainno = "design"; 
    19         $this->tpl_subtitle = 'レイアウト編集'; 
    20     } 
    21 } 
    22  
    23 $objPage = new LC_Page(); 
    24 $objView = new SC_AdminView(); 
    25 $objSess = new SC_Session(); 
    26  
    27 // ページIDを取得 
    28 if (isset($_GET['page_id'])) { 
    29     $page_id = $_GET['page_id']; 
    30 }else if ($_POST['page_id']){ 
    31     $page_id = $_POST['page_id']; 
    32 }else{ 
    33     $page_id = 1; 
    34 } 
    35  
    36 // 編集可能ページを取得 
    37 $objPage->arrEditPage = lfgetPageData(); 
    38  
    39 // ブロック配置用データを取得 
    40 $sel   = ", pos.target_id, pos.bloc_id, pos.bloc_row "; 
    41 $from  = ", dtb_blocposition AS pos"; 
    42 $where = " where "; 
    43 $where .= " lay.page_id = ? AND "; 
    44 $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 "; 
    45 $arrData = array($page_id); 
    46 $arrBlocPos = lfgetLayoutData($sel, $from, $where, $arrData ); 
    47  
    48 // データの存在チェックを行う 
    49 $arrPageData = lfgetPageData("page_id = ?", array($page_id)); 
    50 if (count($arrPageData) <= 0) { 
    51     $exists_page = 0; 
    52 }else{ 
    53     $exists_page = 1; 
    54 } 
    55 $objPage->exists_page = $exists_page; 
    56  
    57 // メッセージ表示 
    58 if ($_GET['msg'] == "on") { 
    59     $objPage->complate_msg="alert('登録が完了しました。');"; 
    60 } 
    61  
    62 // ブロックを取得 
    63 $arrBloc = lfgetBlocData(); 
    64  
    65 // 新規ブロック作成 
    66 if ($_POST['mode'] == 'new_bloc') { 
    67     header("location: ./bloc.php"); 
    68 } 
    69  
    70 // 新規ページ作成 
    71 if ($_POST['mode'] == 'new_page') { 
    72     header("location: ./main_edit.php"); 
    73 } 
    74  
    75 // データ登録処理 
    76 if ($_POST['mode'] == 'confirm' or $_POST['mode'] == 'preview') { 
    77      
    78     $arrPageData = array(); 
    79     if ($_POST['mode'] == 'preview') { 
    80         $arrPageData = lfgetPageData(" page_id = ? " , array($page_id)); 
    81         $page_id = "0"; 
    82         $_POST['page_id'] = "0"; 
    83     } 
    84      
    85     // 更新用にデータを整える 
    86     $arrUpdBlocData = array(); 
    87     $arrTargetFlip = array_flip($arrTarget); 
    88      
    89     $upd_cnt = 1; 
    90     $arrUpdData[$upd_cnt]['page_id'] = $_POST['page_id']; 
    91      
    92     // POSTのデータを使いやすいように修正 
    93     for($upd_cnt = 1; $upd_cnt <= $_POST['bloc_cnt']; $upd_cnt++){ 
    94         if (!isset($_POST['id_'.$upd_cnt])) { 
    95             break; 
    96         } 
    97         $arrUpdBlocData[$upd_cnt]['name']       = $_POST['name_'.$upd_cnt];                         // ブロック名称 
    98         $arrUpdBlocData[$upd_cnt]['id']         = $_POST['id_'.$upd_cnt];                           // ブロックID  
    99         $arrUpdBlocData[$upd_cnt]['target_id']  = $arrTargetFlip[$_POST['target_id_'.$upd_cnt]];    // ターゲットID 
    100         $arrUpdBlocData[$upd_cnt]['top']        = $_POST['top_'.$upd_cnt];                          // TOP座標 
    101         $arrUpdBlocData[$upd_cnt]['update_url'] = $_SERVER['HTTP_REFERER'];                         // 更新URL 
    102     } 
    103  
    104     // データの更新を行う 
    105     $objDBConn = new SC_DbConn;     // DB操作オブジェクト 
    106     $arrRet = array();              // データ取得用 
    107      
    108     // delete実行 
    109     $del_sql = ""; 
    110     $del_sql .= "DELETE FROM dtb_blocposition WHERE page_id = ? "; 
    111     $arrRet = $objDBConn->query($del_sql,array($page_id)); 
    112      
    113     // ブロックの順序を取得し、更新を行う 
    114     foreach($arrUpdBlocData as $key => $val){ 
    115         // ブロックの順序を取得 
    116         $bloc_row = lfGetRowID($arrUpdBlocData, $val); 
    117         $arrUpdBlocData[$key]['bloc_row'] = $bloc_row; 
    118         $arrUpdBlocData[$key]['page_id']    = $_POST['page_id'];    // ページID 
    119          
    120         if ($arrUpdBlocData[$key]['target_id'] == 5) { 
    121             $arrUpdBlocData[$key]['bloc_row'] = "0"; 
    122         } 
    123          
    124         // insert文生成 
    125         $ins_sql = ""; 
    126         $ins_sql .= "INSERT INTO dtb_blocposition "; 
    127         $ins_sql .= " values ( "; 
    128         $ins_sql .= "   ?  ";           // ページID 
    129         $ins_sql .= "   ,? ";           // ターゲットID 
    130         $ins_sql .= "   ,? ";           // ブロックID 
    131         $ins_sql .= "   ,? ";           // ブロックの並び順序 
    132         $ins_sql .= "   ,(SELECT filename FROM dtb_bloc WHERE bloc_id = ?) ";           // ファイル名称 
    133         $ins_sql .= "   )  "; 
    134  
    135         // insertデータ生成 
    136         $arrInsData = array($page_id, 
    137                              $arrUpdBlocData[$key]['target_id'], 
    138                              $arrUpdBlocData[$key]['id'], 
    139                              $arrUpdBlocData[$key]['bloc_row'], 
    140                              $arrUpdBlocData[$key]['id'] 
    141                             ); 
    142         // SQL実行 
    143         $arrRet = $objDBConn->query($ins_sql,$arrInsData); 
    144     } 
    145  
    146     // プレビュー処理 
    147     if ($_POST['mode'] == 'preview') { 
    148         if ($page_id === "") { 
    149             header("location: ./index.php"); 
    150         } 
    151         lfSetPreData($arrPageData); 
    152          
    153         $_SESSION['preview'] = "ON"; 
    154         header("Location: ". URL_DIR . "preview/index.php"); 
    155     }else{ 
    156         header("Location: ./index.php?page_id=$page_id&msg=on"); 
    157     } 
    158 } 
    159  
    160 // データ削除処理 ベースデータでなければファイルを削除 
    161 if ($_POST['mode'] == 'delete' and  !lfCheckBaseData($page_id)) { 
    162     lfDelPageData($page_id); 
    163 } 
    164  
    165 // ブロック情報を画面配置用に編集 
    166 $tpl_arrBloc = array(); 
    167 $cnt = 0; 
    168 // 使用されているブロックデータを生成 
    169 foreach($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 // 未使用のブロックデータを追加 
    177 foreach($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  
    185 $objPage->tpl_arrBloc = $tpl_arrBloc; 
    186 $objPage->bloc_cnt = count($tpl_arrBloc); 
    187 $objPage->page_id = $page_id; 
    188  
    189 // ページ名称を取得 
    190 $arrPageData = lfgetPageData(' page_id = ?', array($page_id)); 
    191 $objPage->arrPageData = $arrPageData[0]; 
    192  
    193 // 認証可否の判定 
    194 $objSess = new SC_Session(); 
    195 sfIsSuccess($objSess); 
    196  
    197 global $GLOBAL_ERR; 
    198 $errCnt = 0; 
    199 if ($GLOBAL_ERR != "") { 
    200     $arrGlobalErr = explode("\n",$GLOBAL_ERR); 
    201     $errCnt = count($arrGlobalErr) - 8; 
    202     if ($errCnt < 0 ) { 
    203         $errCnt = 0; 
    204     } 
    205 } 
    206 $objPage->errCnt = $errCnt; 
    207  
    208 // 画面の表示 
    209 $objView->assignobj($objPage); 
    210 $objView->display(MAIN_FRAME); 
    211  
    212 //--------------------------------------------------------------------------------------------------------------------------------------------------------- 
    213  
    214 /************************************************************************************************************** 
    215  * 関数名  :lfgetLayoutData 
    216  * 処理内容 :編集可能なページ情報を取得する 
    217  * 引数1  :$sel    ・・・ Select句文 
    218  * 引数2  :$where  ・・・ Where句文 
    219  * 引数3  :$arrVal ・・・ Where句の絞込条件値 
    220  * 戻り値  :ページレイアウト情報 
    221  **************************************************************************************************************/ 
    222 function lfgetLayoutData($sel = '' , $from = '', $where = '', $arrVal = ''){ 
    223     $objDBConn = new SC_DbConn;     // DB操作オブジェクト 
    224     $sql = "";                      // データ取得SQL生成用 
    225     $arrRet = array();              // データ取得用 
    226      
    227     // SQL生成 
    228  
    229     $sql = ""; 
    230     $sql .= " select ";  
    231     $sql .= "     lay.page_id "; 
    232     $sql .= "     ,lay.page_name "; 
    233     $sql .= "     ,lay.url "; 
    234     $sql .= "     ,lay.author "; 
    235     $sql .= "     ,lay.description "; 
    236     $sql .= "     ,lay.keyword "; 
    237     $sql .= "     ,lay.update_url "; 
    238     $sql .= "     ,lay.create_date "; 
    239     $sql .= "     ,lay.update_date "; 
    240      
    241     // Select句の指定があれば追加  
    242     if ($sel != '') { 
    243         $sql .= $sel; 
    244     } 
    245      
    246     $sql .= " from dtb_pagelayout AS lay "; 
    247     // From句の指定があれば追加    
    248     if ($from != '') { 
    249         $sql .= $from; 
    250     } 
    251  
    252     // where句の指定があれば追加   
    253     if ($where != '') { 
    254         $sql .= $where; 
    255     }else{ 
    256         $sql .= " ORDER BY lay.page_id "; 
    257     } 
    258      
    259     $arrRet = $objDBConn->getAll($sql, $arrVal); 
    260      
    261     return $arrRet; 
    262 } 
    263  
    264 /************************************************************************************************************** 
    265  * 関数名  :lfgetBlocData 
    266  * 処理内容 :ブロック情報を取得する 
    267  * 引数1  :$where  ・・・ Where句文 
    268  * 引数2  :$arrVal ・・・ Where句の絞込条件値 
    269  * 戻り値  :ブロック情報 
    270  **************************************************************************************************************/ 
    271 function lfgetBlocData($where = '', $arrVal = ''){ 
    272     $objDBConn = new SC_DbConn;     // DB操作オブジェクト 
    273     $sql = "";                      // データ取得SQL生成用 
    274     $arrRet = array();              // データ取得用 
    275      
    276     // SQL生成 
    277     $sql = ""; 
    278     $sql .= " SELECT "; 
    279     $sql .= "   bloc_id"; 
    280     $sql .= "   ,bloc_name"; 
    281     $sql .= "   ,tpl_path"; 
    282     $sql .= "   ,filename"; 
    283     $sql .= "   ,update_date"; 
    284     $sql .= " FROM "; 
    285     $sql .= "   dtb_bloc"; 
    286  
    287     // where句の指定があれば追加   
    288     if ($where != '') { 
    289         $sql .= " WHERE " . $where; 
    290     } 
    291      
    292     $sql .= " ORDER BY  bloc_id"; 
    293      
    294     $arrRet = $objDBConn->getAll($sql, $arrVal); 
    295      
    296     return $arrRet; 
    297 } 
    298  
    299 /************************************************************************************************************** 
    300  * 関数名  :lfSetBlocData 
    301  * 処理内容 :ブロック情報の配列を生成する 
    302  * 引数1  :$arrBloc       ・・・ Bloc情報 
    303  * 引数2  :$tpl_arrBloc   ・・・ データをセットする配列 
    304  * 引数3  :$cnt           ・・・ 配列番号 
    305  * 戻り値  :データをセットした配列 
    306  **************************************************************************************************************/ 
    307 function lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt) { 
    308     global $arrTarget; 
    309      
    310     $tpl_arrBloc[$cnt]['target_id'] = $arrTarget[$val['target_id']]; 
    311     $tpl_arrBloc[$cnt]['bloc_id'] = $val['bloc_id']; 
    312     $tpl_arrBloc[$cnt]['bloc_row'] = $val['bloc_row']; 
    313  
    314     foreach($arrBloc as $bloc_key => $bloc_val){ 
    315         if ($bloc_val['bloc_id'] == $val['bloc_id']) { 
    316             $bloc_name = $bloc_val['bloc_name']; 
    317             break; 
    318         } 
    319     } 
    320     $tpl_arrBloc[$cnt]['name'] = $bloc_name; 
    321      
    322     return $tpl_arrBloc; 
    323 } 
    324  
    325 /************************************************************************************************************** 
    326  * 関数名  :lfChkBloc 
    327  * 処理内容 :ブロックIDが配列に追加されているかのチェックを行う 
    328  * 引数1  :$arrBloc    ・・・ Bloc情報 
    329  * 引数2  :$arrChkData ・・・ チェックを行うデータ配列 
    330  * 戻り値  :True   ・・・ 存在する 
    331  *           False  ・・・ 存在しない 
    332  **************************************************************************************************************/ 
    333 function lfChkBloc($arrBloc, $arrChkData) { 
    334     foreach($arrChkData as $key => $val){ 
    335         if ($val['bloc_id'] === $arrBloc['bloc_id'] ) { 
    336             // 配列に存在すればTrueを返す 
    337             return true; 
    338         } 
    339     } 
    340      
    341     // 配列に存在しなければFlaseを返す 
    342     return false; 
    343 } 
    344  
    345 /************************************************************************************************************** 
    346  * 関数名  :lfGetRowID 
    347  * 処理内容 :ブロックIDが何番目に配置されているかを調べる 
    348  * 引数1  :$arrUpdData   ・・・ 更新情報 
    349  * 引数2  :$arrObj        ・・・ チェックを行うデータ配列 
    350  * 戻り値  :順番 
    351  **************************************************************************************************************/ 
    352 function lfGetRowID($arrUpdData, $arrObj){ 
    353     $no = 0; // カウント用(同じデータが必ず1件あるので、初期値は0) 
    354      
    355     // 対象データが何番目に配置されているのかを取得する。 
    356     foreach ($arrUpdData as $key => $val) { 
    357         if ($val['target_id'] === $arrObj['target_id'] and $val['top'] <= $arrObj['top']){ 
    358             $no++; 
    359         } 
    360     } 
    361     // 番号を返す 
    362     return $no; 
    363 } 
    364  
    365 /************************************************************************************************************** 
    366  * 関数名  :lfGetRowID 
    367  * 処理内容 :ブロックIDが何番目に配置されているかを調べる 
    368  * 引数1  :$arrUpdData   ・・・ 更新情報 
    369  * 引数2  :$arrObj        ・・・ チェックを行うデータ配列 
    370  * 戻り値  :順番 
    371  **************************************************************************************************************/ 
    372 function lfSetPreData($arrPageData){ 
    373     $objDBConn = new SC_DbConn;     // DB操作オブジェクト 
    374     $sql = "";                      // データ更新SQL生成用 
    375     $ret = "";                      // データ更新結果格納用 
    376     $arrUpdData = array();          // 更新データ生成用 
    377     $filename = uniqid(""); 
    378  
    379     $arrPreData = lfgetPageData(" page_id = ? " , array("0")); 
    380  
    381     // tplファイルの削除 
    382     $del_tpl = USER_PATH . "templates/" . $arrPreData[0]['filename'] . '.tpl'; 
    383     if (file_exists($del_tpl)){ 
    384         unlink($del_tpl);    
    385     } 
    386      
    387     // プレビュー用tplファイルのコピー 
    388     $tplfile = $arrPageData[0]['tpl_dir'] . $arrPageData[0]['filename']; 
    389      
    390     if($tplfile == ""){ 
    391         // tplファイルが空の場合にはMYページと判断 
    392         $tplfile = "user_data/templates/mypage/index"; 
    393     } 
    394     copy(HTML_PATH . $tplfile . ".tpl", USER_PATH . "templates/" . $filename . ".tpl"); 
    395      
    396     // 更新データの取得 
    397     $sql = "select page_name, header_chk, footer_chk from dtb_pagelayout where page_id = ?"; 
    398     $ret = $objDBConn->getAll($sql, array($arrPageData[0]['page_id'])); 
    399  
    400     // dbデータのコピー 
    401     $sql = " update dtb_pagelayout set "; 
    402     $sql .= "     page_name = ?"; 
    403     $sql .= "     ,header_chk = ?"; 
    404     $sql .= "     ,footer_chk = ?"; 
    405     $sql .= "     ,url = ?"; 
    406     $sql .= "     ,tpl_dir = ?"; 
    407     $sql .= "     ,filename = ?"; 
    408     $sql .= " where page_id = 0"; 
    409      
    410     $arrUpdData = array($ret[0]['page_id'] 
    411                         ,$ret[0]['page_id'] 
    412                         ,$ret[0]['page_id'] 
    413                         ,USER_DIR."templates/" 
    414                         ,USER_DIR."templates/" 
    415                         ,$filename 
    416                         ); 
    417      
    418     $objDBConn->query($sql,$arrUpdData); 
    419 } 
     15$objPage = new LC_Page_Admin_Design_Ex(); 
     16$objPage->init(); 
     17$objPage->process(); 
     18register_shutdown_function(array($objPage, "destroy")); 
     19?> 
Note: See TracChangeset for help on using the changeset viewer.