Changeset 16430
- Timestamp:
- 2007/10/15 19:38:23 (17 years ago)
- Location:
- branches/feature-module-update
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/html/admin/design/template.php
r15532 r16430 5 5 * http://www.lockon.co.jp/ 6 6 */ 7 8 // {{{ requires 7 9 require_once("../../require.php"); 8 require_once(DATA_PATH . "module/Tar.php"); 9 require_once(DATA_PATH . "include/file_manager.inc"); 10 require_once(DATA_PATH . "module/SearchReplace.php"); 10 require_once(CLASS_EX_PATH . "page_extends/admin/design/LC_Page_Admin_Design_Template_Ex.php"); 11 11 12 class LC_Page { 13 var $arrForm; 14 var $arrHidden; 15 var $arrSubnavi = array( 16 'title' => array( 17 1 => 'top', 18 2 => 'product', 19 3 => 'detail', 20 4 => 'mypage' 21 ), 22 'name' =>array( 23 1 => 'TOPページ', 24 2 => '商品一覧ページ', 25 3 => '商品詳細ページ', 26 4 => 'MYページ' 27 ) 28 ); 12 // }}} 13 // {{{ generate page 29 14 30 function LC_Page() { 31 $this->tpl_mainpage = 'design/template.tpl'; 32 $this->tpl_subnavi = 'design/subnavi.tpl'; 33 $this->tpl_subno = 'template'; 34 $this->tpl_subno_template = $this->arrSubnavi['title'][1]; 35 $this->tpl_TemplateName = $this->arrTemplateName['name'][1]; 36 $this->tpl_mainno = "design"; 37 $this->tpl_subtitle = 'テンプレート設定'; 38 } 39 } 40 41 $objPage = new LC_Page(); 42 $objView = new SC_AdminView(); 43 $objSess = new SC_Session(); 44 45 // 認証可否の判定 46 $objSess = new SC_Session(); 47 sfIsSuccess($objSess); 48 49 // GETの値を受け取る 50 $get_tpl_subno_template = $_GET['tpl_subno_template']; 51 52 // GETで値が送られている場合にはその値を元に画面表示を切り替える 53 if ($get_tpl_subno_template != ""){ 54 // 送られてきた値が配列に登録されていなければTOPを表示 55 if (in_array($get_tpl_subno_template,$objPage->arrSubnavi['title'])){ 56 $tpl_subno_template = $get_tpl_subno_template; 57 }else{ 58 $tpl_subno_template = $objPage->arrSubnavi['title'][1]; 59 } 60 } else { 61 // GETで値がなければPOSTの値を使用する 62 if ($_POST['tpl_subno_template'] != ""){ 63 $tpl_subno_template = $_POST['tpl_subno_template']; 64 }else{ 65 $tpl_subno_template = $objPage->arrSubnavi['title'][1]; 66 } 67 } 68 $objPage->tpl_subno_template = $tpl_subno_template; 69 $key = array_keys($objPage->arrSubnavi['title'], $tpl_subno_template); 70 $objPage->template_name = $objPage->arrSubnavi['name'][$key[0]]; 71 72 // 登録を押されたばあにはDBへデータを更新に行く 73 switch($_POST['mode']) { 74 case 'confirm': 75 // DBへデータ更新 76 lfUpdData(); 77 78 // テンプレートの上書き 79 lfChangeTemplate(); 80 81 // 完了メッセージ 82 $objPage->tpl_onload="alert('登録が完了しました。');"; 83 break; 84 case 'download': 85 lfDownloadTemplate($_POST['check_template']); 86 break; 87 default: 88 break; 89 } 90 91 // POST値の引き継ぎ 92 $objPage->arrForm = $_POST; 93 94 // 画像取得 95 $tpl_arrTemplate = array(); 96 $objPage->arrTemplate = lfgetTemplate(); 97 98 // デフォルトチェック取得 99 $objPage->MainImage = $objPage->arrTemplate['check']; 100 $objPage->arrTemplate['check'] = array($objPage->arrTemplate['check']=>"check"); 101 102 // 画面の表示 103 $objView->assignobj($objPage); 104 $objView->display(MAIN_FRAME); 105 106 //--------------------------------------------------------------------------------------------------------------------------------------------------------- 107 108 /************************************************************************************************************** 109 * 関数名 :lfgetTemplate 110 * 処理内容 :画面に表示する画像を取得する 111 * 引数 :なし 112 * 戻り値 :画面に表示する画像(配列) 113 **************************************************************************************************************/ 114 function lfgetTemplate(){ 115 global $objPage; 116 $filepath = "user_data/templates/"; 117 118 $arrTemplateImage = array(); // 画面表示画像格納用 119 $Image = ""; // イメージの配列要素名格納用 120 $disp = ""; 121 $arrDefcheck = array(); // radioボタンのデフォルトチェック格納用 122 123 // DBから現在選択されているデータ取得 124 $arrDefcheck = lfgetTemplaeBaseData(); 125 126 // テンプレートデータを取得する 127 $objQuery = new SC_Query(); 128 $sql = "SELECT template_code,template_name FROM dtb_templates ORDER BY create_date DESC"; 129 $arrTemplate = $objQuery->getall($sql); 130 131 switch($objPage->tpl_subno_template) { 132 // TOP 133 case $objPage->arrSubnavi['title'][1]: 134 $Image = "TopImage.jpg"; // イメージの配列要素名格納用 135 $disp = $objPage->arrSubnavi['title'][1]; 136 break; 137 138 // 商品一覧 139 case $objPage->arrSubnavi['title'][2]: 140 $Image = "ProdImage.jpg"; // イメージの配列要素名格納用 141 $disp = $objPage->arrSubnavi['title'][2]; 142 break; 143 144 // 商品詳細 145 case $objPage->arrSubnavi['title'][3]: 146 $Image = "DetailImage.jpg"; // イメージの配列要素名格納用 147 $disp = $objPage->arrSubnavi['title'][3]; 148 break; 149 150 // MYページ 151 case $objPage->arrSubnavi['title'][4]: 152 $Image = "MypageImage.jpg"; //イメージの配列要素名格納用 153 $disp = $objPage->arrSubnavi['title'][4]; 154 break; 155 } 156 157 // 画像表示配列作成 158 foreach($arrTemplate as $key => $val){ 159 $arrTemplateImage['image'][$val['template_code']] = $filepath . $val['template_code'] . "/" . $Image; 160 $arrTemplateImage['code'][$key] = $val['template_code']; 161 } 162 163 // 初期チェック 164 if (isset($arrDefcheck[$disp])){ 165 $arrTemplateImage['check'] = $arrDefcheck[$disp]; 166 }else{ 167 $arrTemplateImage['check'] = 1; 168 } 169 170 return $arrTemplateImage; 171 } 172 173 /************************************************************************************************************** 174 * 関数名 :lfgetTemplaeBaseData 175 * 処理内容 :DBに保存されているテンプレートデータを取得する 176 * 引数 :なし 177 * 戻り値 :DBに保存されているテンプレートデータ(配列) 178 **************************************************************************************************************/ 179 function lfgetTemplaeBaseData(){ 180 $objDBConn = new SC_DbConn; // DB操作オブジェクト 181 $sql = ""; // データ取得SQL生成用 182 $arrRet = array(); // データ取得用 183 184 $sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo"; 185 $arrRet = $objDBConn->getAll($sql); 186 187 return $arrRet[0]; 188 } 189 190 /************************************************************************************************************** 191 * 関数名 :lfUpdData 192 * 処理内容 :DBにデータを保存する 193 * 引数 :なし 194 * 戻り値 :成功 TRUE、エラー FALSE 195 **************************************************************************************************************/ 196 function lfUpdData(){ 197 global $objPage; 198 $objDBConn = new SC_DbConn; // DB操作オブジェクト 199 $sql = ""; // データ取得SQL生成用 200 $arrRet = array(); // データ取得用(更新判定) 201 202 // データ取得 203 $sql = "SELECT top_tpl AS top, product_tpl AS product, detail_tpl AS detail, mypage_tpl AS mypage FROM dtb_baseinfo"; 204 $arrRet = $objDBConn->getAll($sql); 205 206 $chk_tpl = $_POST['check_template']; 207 // データが取得できなければINSERT、できればUPDATE 208 if (isset($arrRet[0])){ 209 // UPDATE 210 $arrVal = $arrRet[0]; 211 212 // TOPを変更した場合には全画面変更 213 if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){ 214 $arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl); 215 }else{ 216 $arrVal[$objPage->tpl_subno_template] = $chk_tpl; 217 } 218 $sql= "update dtb_baseinfo set top_tpl = ?, product_tpl = ?, detail_tpl = ?, mypage_tpl = ?, update_date = now()"; 219 }else{ 220 // INSERT 221 $arrVal = array(null,null,null,null); 222 223 // TOPを変更した場合には全画面変更 224 if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){ 225 $arrVal = array($chk_tpl,$chk_tpl,$chk_tpl,$chk_tpl); 226 }else{ 227 $arrVal[$chk_tpl-1] =$chk_tpl; 228 } 229 $sql= "insert into dtb_baseinfo (top_tpl,product_tpl,detail_tpl,mypage_tpl, update_date) values (?,?,?,?,now());"; 230 } 231 232 // SQL実行 233 $arrRet = $objDBConn->query($sql,$arrVal); 234 235 return $arrRet; 236 } 237 238 /************************************************************************************************************** 239 * 関数名 :lfChangeTemplate 240 * 処理内容 :テンプレートファイルを上書きする 241 * 引数 :なし 242 * 戻り値 :成功 TRUE、エラー FALSE 243 **************************************************************************************************************/ 244 function lfChangeTemplate(){ 245 global $objPage; 246 $tpl_path = USER_PATH . "templates/"; 247 $inc_path = USER_PATH . "include/"; 248 $css_path = USER_PATH . "css/"; 249 250 $tpl_name = ""; 251 $tpl_element = ""; 252 253 $chk_tpl = $_POST['check_template']; 254 $path = $tpl_path . $chk_tpl . "/"; 255 $taget_tpl_path = $path . "/templates/"; 256 $taget_inc_path = $path . "/include/"; 257 $taget_css_path = $path . "/css/"; 258 $save_tpl_path = $tpl_path; 259 260 switch($objPage->tpl_subno_template) { 261 // TOP 262 case $objPage->arrSubnavi['title'][1]: 263 $tpl_element = "TopTemplate"; // イメージの配列要素名格納用 264 $tpl_name = "top.tpl"; 265 break; 266 267 // 商品一覧 268 case $objPage->arrSubnavi['title'][2]: 269 $tpl_element = "ProdTemplate"; // イメージの配列要素名格納用 270 $tpl_name = "list.tpl"; 271 break; 272 273 // 商品詳細 274 case $objPage->arrSubnavi['title'][3]: 275 $tpl_element = "DetailTemplate"; // イメージの配列要素名格納用 276 $tpl_name = "detail.tpl"; 277 break; 278 279 // MYページ 280 case $objPage->arrSubnavi['title'][4]: 281 $tpl_element = "MypageTemplate"; //イメージの配列要素名格納用 282 $tpl_name = "mypage.tpl"; 283 break; 284 285 default: 286 break; 287 } 288 289 // 画像パスを書き換え 290 $img_path = '<!--{$smarty.const.URL_DIR}-->img/'; 291 $displace_path = '<!--{$smarty.const.URL_DIR}-->'. USER_DIR . 'templates/' . $chk_tpl . '/img/'; 292 $fs = new File_SearchReplace($img_path, $displace_path, "", $path, true); 293 $fs->doSearch(); 294 295 // TOPを変更した場合には全画面変更 296 if ($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][1]){ 297 // テンプレートファイルをコピー 298 copy($taget_tpl_path . "top.tpl", $save_tpl_path . "top.tpl"); 299 copy($taget_tpl_path . "list.tpl", $save_tpl_path . "list.tpl"); 300 copy($taget_tpl_path . "detail.tpl", $save_tpl_path . "detail.tpl"); 301 302 // mypageはフォルダごとコピー 303 lfFolderCopy($taget_tpl_path."mypage/", $save_tpl_path . "mypage/"); 304 305 // ブロックデータのコピー 306 lfFolderCopy($taget_inc_path."bloc/", $inc_path . "bloc/"); 307 308 // ヘッダー,フッターコピー 309 copy($taget_inc_path . "header.tpl", $inc_path . "header.tpl"); 310 copy($taget_inc_path . "footer.tpl", $inc_path . "footer.tpl"); 311 312 // CSSファイルのコピー 313 copy($taget_css_path . "contents.css", $css_path . "contents.css"); 314 315 // mypageの場合にはフォルダごとコピーする 316 }elseif($objPage->tpl_subno_template == $objPage->arrSubnavi['title'][4]){ 317 lfFolderCopy($taget_tpl_path."mypage/", $save_tpl_path."mypage/"); 318 }else{ 319 // テンプレートファイルをコピー 320 copy($taget_tpl_path . $tpl_name, $save_tpl_path . $tpl_name); 321 } 322 323 // 画像パスを元に戻す 324 $fs = new File_SearchReplace($displace_path, $img_path, "", $path, true); 325 $fs->doSearch(); 326 } 327 328 /************************************************************************************************************** 329 * 関数名 :lfDownloadTemplate 330 * 処理内容 :テンプレートファイル圧縮してダウンロードする 331 * 引数1 :テンプレートコード 332 * 戻り値 :なし 333 **************************************************************************************************************/ 334 function lfDownloadTemplate($template_code){ 335 $filename = $template_code. ".tar.gz"; 336 $dl_file = USER_TEMPLATE_PATH.$filename; 337 338 // IMGフォルダをコピー 339 $mess = ""; 340 $mess = sfCopyDir(HTML_PATH."img/", USER_TEMPLATE_PATH.$template_code."/img/", $mess); 341 342 // ファイルの圧縮 343 $tar = new Archive_Tar($dl_file, TRUE); 344 // ファイル一覧取得 345 $arrFileHash = sfGetFileList(USER_TEMPLATE_PATH.$template_code); 346 foreach($arrFileHash as $val) { 347 $arrFileList[] = $val['file_name']; 348 } 349 // ディレクトリを移動 350 chdir(USER_TEMPLATE_PATH.$template_code); 351 352 //圧縮をおこなう 353 $zip = $tar->create($arrFileList); 354 355 // ダウンロード開始 356 Header("Content-disposition: attachment; filename=${filename}"); 357 Header("Content-type: application/octet-stream; name=${dl_file}"); 358 header("Content-Length: " .filesize($dl_file)); 359 readfile ($dl_file); 360 // 圧縮ファイル削除 361 unlink($dl_file); 362 363 exit(); 364 } 365 366 /************************************************************************************************************** 367 * 関数名 :lfFolderCopy 368 * 処理内容 :フォルダをコピーする 369 * 引数1 :コピー元パス 370 * 引数2 :コピー先パス 371 * 戻り値 :なし 372 **************************************************************************************************************/ 373 function lfFolderCopy($taget_path, $save_path){ 374 375 // フォルダ内のファイルを取得する 376 $arrMypage=glob($taget_path . "*" ); 377 378 // フォルダがなければ作成する 379 if(!is_dir($save_path)){ 380 mkdir($save_path); 381 } 382 383 // フォルダ内を全てコピー 384 foreach($arrMypage as $key => $val){ 385 $matches = array(); 386 mb_ereg("^(.*[\/])(.*)",$val, $matches); 387 $data=$matches[2]; 388 copy($val, $save_path . $data); 389 } 390 } 15 $objPage = new LC_Page_Admin_Design_Template_Ex(); 16 $objPage->init(); 17 $objPage->process(); 18 register_shutdown_function(array($objPage, "destroy")); 19 ?> -
branches/feature-module-update/html/admin/design/upload.php
r15532 r16430 5 5 * http://www.lockon.co.jp/ 6 6 */ 7 8 // {{{ requires 7 9 require_once("../../require.php"); 8 require_once( DATA_PATH. "module/Tar.php");10 require_once(CLASS_EX_PATH . "page_extends/admin/design/LC_Page_Admin_Design_Upload_Ex.php"); 9 11 10 class LC_Page { 12 // }}} 13 // {{{ generate page 11 14 12 function LC_Page() { 13 $this->tpl_mainpage = 'design/upload.tpl'; 14 $this->tpl_subnavi = 'design/subnavi.tpl'; 15 $this->tpl_subno = 'template'; 16 $this->tpl_subno_template = 'upload'; 17 $this->tpl_mainno = "design"; 18 $this->tpl_subtitle = 'アップロード'; 19 $this->template_name = 'アップロード'; 20 } 21 } 22 23 $objPage = new LC_Page(); 24 $objView = new SC_AdminView(); 25 $objSess = new SC_Session(); 26 $objQuery = new SC_Query(); 27 28 // 認証可否の判定 29 $objSess = new SC_Session(); 30 sfIsSuccess($objSess); 31 32 // アップロードしたファイルをフォルダ 33 $new_file_dir = USER_TEMPLATE_PATH.$_POST['template_code']; 34 35 // ファイル管理クラス 36 $objUpFile = new SC_UploadFile(TEMPLATE_TEMP_DIR, $new_file_dir); 37 // ファイル情報の初期化 38 lfInitFile(); 39 // パラメータ管理クラス 40 $objFormParam = new SC_FormParam(); 41 // パラメータ情報の初期化 42 lfInitParam(); 43 44 switch($_POST['mode']) { 45 case 'upload': 46 $objFormParam->setParam($_POST); 47 $arrRet = $objFormParam->getHashArray(); 48 49 $objPage->arrErr = lfErrorCheck($arrRet); 50 51 // ファイルを一時フォルダへ保存 52 $ret = $objUpFile->makeTempFile('template_file', false); 53 if($ret != "") { 54 $objPage->arrErr['template_file'] = $ret; 55 } else if(count($objPage->arrErr) <= 0) { 56 // フォルダ作成 57 $ret = @mkdir($new_file_dir); 58 // 一時フォルダから保存ディレクトリへ移動 59 $objUpFile->moveTempFile(); 60 // 解凍 61 lfUnpacking($new_file_dir, $_FILES['template_file']['name'], $new_file_dir."/"); 62 // DBにテンプレート情報を保存 63 lfRegistTemplate($arrRet); 64 // 完了表示javascript 65 $objPage->tpl_onload = "alert('テンプレートファイルをアップロードしました。');"; 66 // フォーム値をクリア 67 $objFormParam->setParam(array('template_code' => "", 'template_name' => "")); 68 } 69 break; 70 default: 71 break; 72 } 73 // 画面の表示 74 $objPage->arrForm = $objFormParam->getFormParamList(); 75 $objView->assignobj($objPage); 76 $objView->display(MAIN_FRAME); 77 78 //--------------------------------------------------------------------------------------------------------------------------------------------------------- 79 80 /* 81 * 関数名:lfInitFile() 82 * 説明 :ファイル情報の初期化 83 */ 84 function lfInitFile() { 85 global $objUpFile; 86 87 $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false); 88 } 89 90 /* 91 * 関数名:lfInitParam() 92 * 説明 :パラメータ情報の初期化 93 */ 94 function lfInitParam() { 95 global $objFormParam; 96 97 $objFormParam->addParam("テンプレートコード", "template_code", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")); 98 $objFormParam->addParam("テンプレート名", "template_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); 99 } 100 101 /* 102 * 関数名:lfErrorCheck() 103 * 引数1 :フォームの値 104 * 説明 :エラーチェック 105 */ 106 function lfErrorCheck($arrList) { 107 global $objQuery; 108 global $objFormParam; 109 110 $objErr = new SC_CheckError($arrList); 111 $objErr->arrErr = $objFormParam->checkError(); 112 113 if(count($objErr->arrErr) <= 0) { 114 // 同名のフォルダが存在する場合はエラー 115 if(file_exists(USER_TEMPLATE_PATH.$arrList['template_code'])) { 116 $objErr->arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>"; 117 } 118 // DBにすでに登録されていないかチェック 119 $ret = $objQuery->get("dtb_templates", "template_code", "template_code = ?", array($arrList['template_code'])); 120 if($ret != "") { 121 $objErr->arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>"; 122 } 123 // ファイルの拡張子チェック(.tar/tar.gzのみ許可) 124 $errFlag = true; 125 $array_ext = explode(".", $_FILES['template_file']['name']); 126 $ext = $array_ext[ count ( $array_ext ) - 1 ]; 127 $ext = strtolower($ext); 128 // .tarチェック 129 if ($ext == 'tar') { 130 $errFlag = false; 131 } 132 133 $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext; 134 $ext = strtolower($ext); 135 // .tar.gzチェック 136 if ($ext== 'tar.gz') { 137 $errFlag = false; 138 } 139 140 if($errFlag) { 141 $objErr->arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />"; 142 } 143 } 144 145 return $objErr->arrErr; 146 } 147 148 /* 149 * 関数名:lfErrorCheck() 150 * 引数1 :パラメータ 151 * 説明 :テンプレートデータ登録 152 */ 153 function lfRegistTemplate($arrList) { 154 global $objQuery; 155 156 // INSERTする値を作成する。 157 $sqlval['template_code'] = $arrList['template_code']; 158 $sqlval['template_name'] = $arrList['template_name']; 159 $sqlval['create_date'] = "now()"; 160 $sqlval['update_date'] = "now()"; 161 162 $objQuery->insert("dtb_templates", $sqlval); 163 } 164 165 /* 166 * 関数名:lfUnpacking 167 * 引数1 :ディレクトリ 168 * 引数2 :ファイルネーム 169 * 引数3 :解凍ディレクトリ 170 * 説明 :テンプレートデータ登録 171 */ 172 function lfUnpacking($dir, $file_name, $unpacking_dir) { 173 174 // 圧縮フラグTRUEはgzip解凍をおこなう 175 $tar = new Archive_Tar("$dir/$file_name", TRUE); 176 177 // 拡張子を切り取る 178 $unpacking_name = ereg_replace("\.tar$", "", $file_name); 179 $unpacking_name = ereg_replace("\.tar\.gz$", "", $file_name); 180 181 // 指定されたフォルダ内に解凍する 182 $err = $tar->extractModify($unpacking_dir, $unpacking_name); 183 184 // フォルダ削除 185 @sfDelFile("$dir/$unpacking_name"); 186 // 圧縮ファイル削除 187 @unlink("$dir/$file_name"); 188 189 return $err; 190 } 15 $objPage = new LC_Page_Admin_Design_Upload_Ex(); 16 $objPage->init(); 17 $objPage->process(); 18 register_shutdown_function(array($objPage, "destroy")); 19 ?>
Note: See TracChangeset
for help on using the changeset viewer.