- Timestamp:
- 2007/09/01 21:54:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/html/admin/products/product_class.php
r15532 r15559 5 5 * http://www.lockon.co.jp/ 6 6 */ 7 require_once("../require.php");8 7 9 class LC_Page { 10 var $arrCatList; 11 var $arrSRANK; 12 var $arrForm; 13 var $arrSubList; 14 var $arrHidden; 15 var $arrTempImage; 16 var $arrSaveImage; 17 var $tpl_mode; 18 var $arrSearchHidden; 19 function LC_Page() { 20 $this->tpl_mainpage = 'products/product_class.tpl'; 21 $this->tpl_subnavi = 'products/subnavi.tpl'; 22 $this->tpl_mainno = 'products'; 23 $this->tpl_subno = 'product'; 24 $this->tpl_subtitle = '商品登録'; 25 global $arrSRANK; 26 $this->arrSRANK = $arrSRANK; 27 global $arrDISP; 28 $this->arrDISP = $arrDISP; 29 global $arrCLASS; 30 $this->arrCLASS = $arrCLASS; 31 global $arrSTATUS; 32 $this->arrSTATUS = $arrSTATUS; 33 $this->tpl_onload = ""; 34 } 35 } 8 // {{{ requires 9 require_once("../../require.php"); 10 require_once(CLASS_PATH . "page_extends/admin/products/LC_Page_Admin_Products_ProductClass_Ex.php"); 36 11 37 $objPage = new LC_Page(); 38 $objView = new SC_AdminView(); 39 // 認証可否の判定 40 $objSess = new SC_Session(); 41 sfIsSuccess($objSess); 12 // }}} 13 // {{{ generate page 42 14 43 // 検索パラメータの引き継ぎ 44 foreach ($_POST as $key => $val) { 45 if (ereg("^search_", $key)) { 46 $objPage->arrSearchHidden[$key] = $val; 47 } 48 } 49 50 $objPage->tpl_product_id = $_POST['product_id']; 51 $objPage->tpl_pageno = $_POST['pageno']; 52 53 switch($_POST['mode']) { 54 // 規格削除要求 55 case 'delete': 56 $objQuery = new SC_Query(); 57 58 $objQuery->setLimitOffset(1); 59 $where = "product_id = ? AND NOT (classcategory_id1 = 0 AND classcategory_id2 = 0)"; 60 $objQuery->setOrder("rank1 DESC, rank2 DESC"); 61 $arrRet = $objQuery->select("*", "vw_cross_products_class AS crs_prd", $where, array($_POST['product_id'])); 62 63 if(count($arrRet) > 0) { 64 65 $sqlval['product_id'] = $arrRet[0]['product_id']; 66 $sqlval['classcategory_id1'] = '0'; 67 $sqlval['classcategory_id2'] = '0'; 68 $sqlval['product_code'] = $arrRet[0]['product_code']; 69 $sqlval['stock'] = $arrRet[0]['stock']; 70 $sqlval['price01'] = $arrRet[0]['price01']; 71 $sqlval['price02'] = $arrRet[0]['price02']; 72 $sqlval['creator_id'] = $_SESSION['member_id']; 73 $sqlval['create_date'] = "now()"; 74 $sqlval['update_date'] = "now()"; 75 76 $objQuery->begin(); 77 $where = "product_id = ?"; 78 $objQuery->delete("dtb_products_class", $where, array($_POST['product_id'])); 79 $objQuery->insert("dtb_products_class", $sqlval); 80 81 $objQuery->commit(); 82 } 83 84 lfProductClassPage(); // 規格登録ページ 85 break; 86 87 // 編集要求 88 case 'pre_edit': 89 $objQuery = new SC_Query(); 90 $where = "product_id = ? AND NOT(classcategory_id1 = 0 AND classcategory_id2 = 0) "; 91 $ret = $objQuery->count("dtb_products_class", $where, array($_POST['product_id'])); 92 93 if($ret > 0) { 94 // 規格組み合わせ一覧の取得(DBの値を優先する。) 95 $objPage->arrClassCat = lfGetClassCatListEdit($_POST['product_id']); 96 } 97 98 lfProductClassPage(); // 規格登録ページ 99 break; 100 // 規格組み合わせ表示 101 case 'disp': 102 $objPage->arrForm['select_class_id1'] = $_POST['select_class_id1']; 103 $objPage->arrForm['select_class_id2'] = $_POST['select_class_id2']; 104 105 $objPage->arrErr = lfClassError(); 106 if (count($objPage->arrErr) == 0) { 107 // 規格組み合わせ一覧の取得 108 $objPage->arrClassCat = lfGetClassCatListDisp($_POST['select_class_id1'], $_POST['select_class_id2']); 109 } 110 111 lfProductClassPage(); // 規格登録ページ 112 break; 113 // 規格登録要求 114 case 'edit': 115 // 入力値の変換 116 $objPage->arrForm = lfConvertParam($_POST); 117 // エラーチェック 118 $objPage->arrErr = lfProductClassError($objPage->arrForm); 119 120 if(count($objPage->arrErr) == 0) { 121 // 確認ページ設定 122 $objPage->tpl_mainpage = 'products/product_class_confirm.tpl'; 123 lfProductConfirmPage(); // 確認ページ表示 124 } else { 125 // 規格組み合わせ一覧の取得 126 $objPage->arrClassCat = lfGetClassCatListDisp($_POST['class_id1'], $_POST['class_id2'], false); 127 lfProductClassPage(); // 規格登録ページ 128 } 129 break; 130 // 確認ページからの戻り 131 case 'confirm_return': 132 // フォームパラメータの引き継ぎ 133 $objPage->arrForm = $_POST; 134 // 規格の選択情報は引き継がない。 135 $objPage->arrForm['select_class_id1'] = ""; 136 $objPage->arrForm['select_class_id2'] = ""; 137 // 規格組み合わせ一覧の取得(デフォルト値は出力しない) 138 $objPage->arrClassCat = lfGetClassCatListDisp($_POST['class_id1'], $_POST['class_id2'], false); 139 lfProductClassPage(); // 規格登録ページ 140 break; 141 case 'complete': 142 // 完了ページ設定 143 $objPage->tpl_mainpage = 'products/product_class_complete.tpl'; 144 // 商品規格の登録 145 lfInsertProductClass($_POST, $_POST['product_id']); 146 break; 147 default: 148 lfProductClassPage(); // 規格登録ページ 149 break; 150 } 151 152 $objView->assignobj($objPage); 153 $objView->display(MAIN_FRAME); 154 //----------------------------------------------------------------------------------------------------------------------------- 155 /* 規格登録ページ表示用 */ 156 function lfProductClassPage() { 157 global $objPage; 158 $objPage->arrHidden = $_POST; 159 $objPage->arrHidden['select_class_id1'] = ""; 160 $objPage->arrHidden['select_class_id2'] = ""; 161 $arrClass = sfGetIDValueList("dtb_class", 'class_id', 'name'); 162 163 // 規格分類が登録されていない規格は表示しないようにする。 164 $arrClassCatCount = sfGetClassCatCount(); 165 166 foreach($arrClass as $key => $val) { 167 if($arrClassCatCount[$key] > 0) { 168 $objPage->arrClass[$key] = $arrClass[$key]; 169 } 170 } 171 172 // 商品名を取得 173 $objQuery = new SC_Query(); 174 $product_name = $objQuery->getOne("SELECT name FROM dtb_products WHERE product_id = ?", array($_POST['product_id'])); 175 $objPage->arrForm['product_name'] = $product_name; 176 } 177 178 function lfSetDefaultClassCat($objQuery, $product_id, $max) { 179 global $objPage; 180 181 // デフォルト値の読込 182 $col = "product_code, price01, price02, stock, stock_unlimited"; 183 $arrRet = $objQuery->select($col, "dtb_products_class", "product_id = ? AND classcategory_id1 = 0 AND classcategory_id2 = 0", array($product_id));; 184 185 if(count($arrRet) > 0) { 186 $no = 1; 187 for($cnt = 0; $cnt < $max; $cnt++) { 188 $objPage->arrForm["product_code:".$no] = $arrRet[0]['product_code']; 189 $objPage->arrForm['stock:'.$no] = $arrRet[0]['stock']; 190 $objPage->arrForm['price01:'.$no] = $arrRet[0]['price01']; 191 $objPage->arrForm['price02:'.$no] = $arrRet[0]['price02']; 192 $objPage->arrForm['stock_unlimited:'.$no] = $arrRet[0]['stock_unlimited']; 193 $no++; 194 } 195 } 196 } 197 198 /* 規格組み合わせ一覧の取得 */ 199 function lfGetClassCatListDisp($class_id1, $class_id2, $default = true) { 200 global $objPage; 201 $objQuery = new SC_Query(); 202 203 if($class_id2 != "") { 204 // 規格1と規格2 205 $sql = "SELECT * "; 206 $sql.= "FROM vw_cross_class AS crs_cls "; 207 $sql.= "WHERE class_id1 = ? AND class_id2 = ? ORDER BY rank1 DESC, rank2 DESC;"; 208 $arrRet = $objQuery->getall($sql, array($class_id1, $class_id2)); 209 } else { 210 // 規格1のみ 211 $sql = "SELECT * "; 212 $sql.= "FROM vw_cross_class AS crs_cls "; 213 $sql.= "WHERE class_id1 = ? AND class_id2 = 0 ORDER BY rank1 DESC;"; 214 $arrRet = $objQuery->getall($sql, array($class_id1)); 215 216 } 217 218 $max = count($arrRet); 219 220 if($default) { 221 // デフォルト値を設定 222 lfSetDefaultClassCat($objQuery, $_POST['product_id'], $max); 223 } 224 225 $objPage->arrForm["class_id1"] = $arrRet[0]['class_id1']; 226 $objPage->arrForm["class_id2"] = $arrRet[0]['class_id2']; 227 $objPage->tpl_onload.= "fnCheckAllStockLimit('$max', '" . DISABLED_RGB . "');"; 228 229 return $arrRet; 230 } 231 232 /* 規格組み合わせ一覧の取得(編集画面) */ 233 function lfGetClassCatListEdit($product_id) { 234 global $objPage; 235 // 既存編集の場合 236 $objQuery = new SC_Query(); 237 238 $col = "class_id1, class_id2, name1, name2, rank1, rank2, "; 239 $col.= "product_class_id, product_id, T1_classcategory_id AS classcategory_id1, T2_classcategory_id AS classcategory_id2, "; 240 $col.= "product_code, stock, stock_unlimited, sale_limit, price01, price02, status"; 241 242 $sql = "SELECT $col FROM "; 243 $sql.= "( "; 244 $sql.= "SELECT T1.class_id AS class_id1, T2.class_id AS class_id2, T1.classcategory_id AS T1_classcategory_id, T2.classcategory_id AS T2_classcategory_id, T1.name AS name1, T2.name AS name2, T1.rank AS rank1, T2.rank AS rank2 "; 245 $sql.= "FROM dtb_classcategory AS T1, dtb_classcategory AS T2 "; 246 $sql.= "WHERE T1.class_id IN (SELECT class_id1 FROM vw_cross_products_class AS crs_prd WHERE product_id = ? GROUP BY class_id1, class_id2) AND T2.class_id IN (SELECT class_id2 FROM vw_cross_products_class AS crs_prd WHERE product_id = ? GROUP BY class_id1, class_id2)"; 247 $sql.= ") AS T1 "; 248 249 $sql.= "LEFT JOIN (SELECT * FROM dtb_products_class WHERE product_id = ?) AS T3 "; 250 $sql.= "ON T1_classcategory_id = T3.classcategory_id1 AND T2_classcategory_id = T3.classcategory_id2 "; 251 $sql.= "ORDER BY rank1 DESC, rank2 DESC"; 252 253 $arrList = $objQuery->getAll($sql, array($product_id, $product_id, $product_id)); 254 255 $objPage->arrForm["class_id1"] = $arrList[0]['class_id1']; 256 $objPage->arrForm["class_id2"] = $arrList[0]['class_id2']; 257 258 $max = count($arrList); 259 260 // デフォルト値を設定 261 lfSetDefaultClassCat($objQuery, $product_id, $max); 262 263 $no = 1; 264 265 for($cnt = 0; $cnt < $max; $cnt++) { 266 $objPage->arrForm["classcategory_id1:".$no] = $arrList[$cnt]['classcategory_id1']; 267 $objPage->arrForm["classcategory_id2:".$no] = $arrList[$cnt]['classcategory_id2']; 268 if($arrList[$cnt]['product_id'] != "") { 269 $objPage->arrForm["product_code:".$no] = $arrList[$cnt]['product_code']; 270 $objPage->arrForm['stock:'.$no] = $arrList[$cnt]['stock']; 271 $objPage->arrForm['stock_unlimited:'.$no] = $arrList[$cnt]['stock_unlimited']; 272 $objPage->arrForm['price01:'.$no] = $arrList[$cnt]['price01']; 273 $objPage->arrForm['price02:'.$no] = $arrList[$cnt]['price02']; 274 // JavaScript初期化用文字列 275 $line.= "'check:".$no."',"; 276 } 277 $no++; 278 } 279 280 $line = ereg_replace(",$", "", $line); 281 $objPage->tpl_javascript = "list = new Array($line);"; 282 $color = DISABLED_RGB; 283 $objPage->tpl_onload.= "fnListCheck(list); fnCheckAllStockLimit('$max', '$color');"; 284 285 return $arrList; 286 } 287 288 /* 規格の登録 */ 289 function lfInsertProductClass($arrList, $product_id) { 290 $objQuery = new SC_Query(); 291 292 $objQuery->begin(); 293 294 // 既存規格の削除 295 $where = "product_id = ?"; 296 $objQuery->delete("dtb_products_class", $where, array($product_id)); 297 298 $cnt = 1; 299 // すべての規格を登録する。 300 while($arrList["classcategory_id1:".$cnt] != "") { 301 if($arrList["check:".$cnt] == 1) { 302 $sqlval['product_id'] = $product_id; 303 $sqlval['classcategory_id1'] = $arrList["classcategory_id1:".$cnt]; 304 $sqlval['classcategory_id2'] = $arrList["classcategory_id2:".$cnt]; 305 $sqlval['product_code'] = $arrList["product_code:".$cnt]; 306 $sqlval['stock'] = $arrList["stock:".$cnt]; 307 $sqlval['stock_unlimited'] = $arrList["stock_unlimited:".$cnt]; 308 $sqlval['price01'] = $arrList['price01:'.$cnt]; 309 $sqlval['price02'] = $arrList['price02:'.$cnt]; 310 $sqlval['creator_id'] = $_SESSION['member_id']; 311 $sqlval['create_date'] = "now()"; 312 $sqlval['update_date'] = "now()"; 313 // INSERTの実行 314 $objQuery->insert("dtb_products_class", $sqlval); 315 } 316 $cnt++; 317 } 318 319 $objQuery->commit(); 320 } 321 322 // 規格選択エラーチェック 323 function lfClassError() { 324 $objErr = new SC_CheckError(); 325 $objErr->doFunc(array("規格1", "select_class_id1"), array("EXIST_CHECK")); 326 $objErr->doFunc(array("規格", "select_class_id1", "select_class_id2"), array("TOP_EXIST_CHECK")); 327 $objErr->doFunc(array("規格1", "規格2", "select_class_id1", "select_class_id2"), array("DIFFERENT_CHECK")); 328 return $objErr->arrErr; 329 } 330 331 /* 取得文字列の変換 */ 332 function lfConvertParam($array) { 333 /* 334 * 文字列の変換 335 * K : 「半角(ハンカク)片仮名」を「全角片仮名」に変換 336 * C : 「全角ひら仮名」を「全角かた仮名」に変換 337 * V : 濁点付きの文字を一文字に変換。"K","H"と共に使用します 338 * n : 「全角」数字を「半角(ハンカク)」に変換 339 */ 340 341 $no = 1; 342 while($array["classcategory_id1:".$no] != "") { 343 $arrConvList["product_code:".$no] = "KVa"; 344 $arrConvList["price01:".$no] = "n"; 345 $arrConvList["price02:".$no] = "n"; 346 $arrConvList["stock:".$no] = "n"; 347 $no++; 348 } 349 350 // 文字変換 351 foreach ($arrConvList as $key => $val) { 352 // POSTされてきた値のみ変換する。 353 if(isset($array[$key])) { 354 $array[$key] = mb_convert_kana($array[$key] ,$val); 355 } 356 } 357 return $array; 358 } 359 360 // 商品規格エラーチェック 361 function lfProductClassError($array) { 362 $objErr = new SC_CheckError($array); 363 $no = 1; 364 365 while($array["classcategory_id1:".$no] != "") { 366 if($array["check:".$no] == 1) { 367 $objErr->doFunc(array("商品コード", "product_code:".$no, STEXT_LEN), array("MAX_LENGTH_CHECK")); 368 $objErr->doFunc(array(NORMAL_PRICE_TITLE, "price01:".$no, PRICE_LEN), array("ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); 369 $objErr->doFunc(array(SALE_PRICE_TITLE, "price02:".$no, PRICE_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); 370 371 if($array["stock_unlimited:".$no] != '1') { 372 $objErr->doFunc(array("在庫数", "stock:".$no, AMOUNT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); 373 } 374 } 375 if(count($objErr->arrErr) > 0) { 376 $objErr->arrErr["error:".$no] = $objErr->arrErr["product_code:".$no]; 377 $objErr->arrErr["error:".$no].= $objErr->arrErr["price01:".$no]; 378 $objErr->arrErr["error:".$no].= $objErr->arrErr["price02:".$no]; 379 $objErr->arrErr["error:".$no].= $objErr->arrErr["stock:".$no]; 380 } 381 $no++; 382 } 383 return $objErr->arrErr; 384 } 385 386 /* 確認ページ表示用 */ 387 function lfProductConfirmPage() { 388 global $objPage; 389 $objPage->arrForm['mode'] = 'complete'; 390 $objPage->arrClass = sfGetIDValueList("dtb_class", 'class_id', 'name'); 391 $cnt = 0; 392 $check = 0; 393 $no = 1; 394 while($_POST["classcategory_id1:".$no] != "") { 395 if($_POST["check:".$no] != "") { 396 $check++; 397 } 398 $no++; 399 $cnt++; 400 } 401 $objPage->tpl_check = $check; 402 $objPage->tpl_count = $cnt; 403 } 15 $objPage = new LC_Page_Admin_Products_ProductClass_Ex(); 16 $objPage->init(); 17 $objPage->process(); 18 register_shutdown_function(array($objPage, "destroy")); 404 19 ?>
Note: See TracChangeset
for help on using the changeset viewer.