- Timestamp:
- 2007/08/30 22:33:52 (17 years ago)
- Location:
- branches/feature-module-update
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/html/admin/products/category.php
r15080 r15518 5 5 * http://www.lockon.co.jp/ 6 6 */ 7 require_once("../require.php");8 7 9 class LC_Page { 10 function LC_Page() { 11 $this->tpl_mainpage = 'products/category.tpl'; 12 $this->tpl_subnavi = 'products/subnavi.tpl'; 13 $this->tpl_mainno = 'products'; 14 $this->tpl_subno = 'category'; 15 $this->tpl_onload = " fnSetFocus('category_name'); "; 16 $this->tpl_subtitle = 'カテゴリー登録'; 17 } 18 } 8 // {{{ requires 9 require_once("../../require.php"); 10 require_once(CLASS_PATH . "page_extends/admin/products/LC_Page_Admin_Products_Category_Ex.php"); 19 11 20 $conn = new SC_DBConn(); 21 $objPage = new LC_Page(); 22 $objView = new SC_AdminView(); 23 $objSess = new SC_Session(); 12 // }}} 13 // {{{ generate page 24 14 25 // 認証可否の判定 26 sfIsSuccess($objSess); 27 28 // パラメータ管理クラス 29 $objFormParam = new SC_FormParam(); 30 // パラメータ情報の初期化 31 lfInitParam(); 32 // POST値の取得 33 $objFormParam->setParam($_POST); 34 35 // 通常時は親カテゴリを0に設定する。 36 $objPage->arrForm['parent_category_id'] = $_POST['parent_category_id']; 37 38 switch($_POST['mode']) { 39 case 'edit': 40 $objFormParam->convParam(); 41 $arrRet = $objFormParam->getHashArray(); 42 $objPage->arrErr = lfCheckError($arrRet); 43 44 if(count($objPage->arrErr) == 0) { 45 if($_POST['category_id'] == "") { 46 $objQuery = new SC_Query(); 47 $count = $objQuery->count("dtb_category"); 48 if($count < CATEGORY_MAX) { 49 lfInsertCat($_POST['parent_category_id']); 50 } else { 51 print("カテゴリの登録最大数を超えました。"); 52 } 53 } else { 54 lfUpdateCat($_POST['category_id']); 55 } 56 } else { 57 $objPage->arrForm = array_merge($objPage->arrForm, $objFormParam->getHashArray()); 58 $objPage->arrForm['category_id'] = $_POST['category_id']; 59 } 60 break; 61 case 'pre_edit': 62 // 編集項目のカテゴリ名をDBより取得する。 63 $oquery = new SC_Query(); 64 $where = "category_id = ?"; 65 $cat_name = $oquery->get("dtb_category", "category_name", $where, array($_POST['category_id'])); 66 // 入力項目にカテゴリ名を入力する。 67 $objPage->arrForm['category_name'] = $cat_name; 68 // POSTデータを引き継ぐ 69 $objPage->arrForm['category_id'] = $_POST['category_id']; 70 break; 71 case 'delete': 72 $objQuery = new SC_Query(); 73 // 子カテゴリのチェック 74 $where = "parent_category_id = ? AND del_flg = 0"; 75 $count = $objQuery->count("dtb_category", $where, array($_POST['category_id'])); 76 if($count != 0) { 77 $objPage->arrErr['category_name'] = "※ 子カテゴリが存在するため削除できません。<br>"; 78 } 79 // 登録商品のチェック 80 $where = "category_id = ? AND del_flg = 0"; 81 $count = $objQuery->count("dtb_products", $where, array($_POST['category_id'])); 82 if($count != 0) { 83 $objPage->arrErr['category_name'] = "※ カテゴリ内に商品が存在するため削除できません。<br>"; 84 } 85 86 if(!isset($objPage->arrErr['category_name'])) { 87 // ランク付きレコードの削除(※処理負荷を考慮してレコードごと削除する。) 88 sfDeleteRankRecord("dtb_category", "category_id", $_POST['category_id'], "", true); 89 } 90 break; 91 case 'up': 92 $objQuery = new SC_Query(); 93 $objQuery->begin(); 94 $up_id = lfGetUpRankID($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']); 95 if($up_id != "") { 96 // 上のグループのrankから減算する数 97 $my_count = lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']); 98 // 自分のグループのrankに加算する数 99 $up_count = lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $up_id); 100 if($my_count > 0 && $up_count > 0) { 101 // 自分のグループに加算 102 lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id'], $up_count); 103 // 上のグループから減算 104 lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $up_id, $my_count); 105 } 106 } 107 $objQuery->commit(); 108 break; 109 case 'down': 110 $objQuery = new SC_Query(); 111 $objQuery->begin(); 112 $down_id = lfGetDownRankID($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']); 113 if($down_id != "") { 114 // 下のグループのrankに加算する数 115 $my_count = lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']); 116 // 自分のグループのrankから減算する数 117 $down_count = lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $down_id); 118 if($my_count > 0 && $down_count > 0) { 119 // 自分のグループから減算 120 lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $down_id, $my_count); 121 // 下のグループに加算 122 lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id'], $down_count); 123 } 124 } 125 $objQuery->commit(); 126 break; 127 case 'tree': 128 break; 129 default: 130 $objPage->arrForm['parent_category_id'] = 0; 131 break; 132 } 133 134 $objPage->arrList = lfGetCat($objPage->arrForm['parent_category_id']); 135 $objPage->arrTree = sfGetCatTree($objPage->arrForm['parent_category_id']); 136 137 $objView->assignobj($objPage); 138 $objView->display(MAIN_FRAME); 139 //----------------------------------------------------------------------------------------------------------------------------------- 140 141 // カテゴリの新規追加 142 function lfInsertCat($parent_category_id) { 143 global $objFormParam; 144 145 $objQuery = new SC_Query(); 146 $objQuery->begin(); // トランザクションの開始 147 148 149 if($parent_category_id == 0) { 150 // ROOT階層で最大のランクを取得する。 151 $where = "parent_category_id = ?"; 152 $rank = $objQuery->max("dtb_category", "rank", $where, array($parent_category_id)) + 1; 153 } else { 154 // 親のランクを自分のランクとする。 155 $where = "category_id = ?"; 156 $rank = $objQuery->get("dtb_category", "rank", $where, array($parent_category_id)); 157 // 追加レコードのランク以上のレコードを一つあげる。 158 $sqlup = "UPDATE dtb_category SET rank = (rank + 1) WHERE rank >= ?"; 159 $objQuery->exec($sqlup, array($rank)); 160 } 161 162 $where = "category_id = ?"; 163 // 自分のレベルを取得する(親のレベル + 1) 164 $level = $objQuery->get("dtb_category", "level", $where, array($parent_category_id)) + 1; 165 166 // 入力データを渡す。 167 $sqlval = $objFormParam->getHashArray(); 168 $sqlval['create_date'] = "Now()"; 169 $sqlval['update_date'] = "Now()"; 170 $sqlval['creator_id'] = $_SESSION['member_id']; 171 $sqlval['parent_category_id'] = $parent_category_id; 172 $sqlval['rank'] = $rank; 173 $sqlval['level'] = $level; 174 175 // INSERTの実行 176 $objQuery->insert("dtb_category", $sqlval); 177 178 $objQuery->commit(); // トランザクションの終了 179 } 180 181 // カテゴリの編集 182 function lfUpdateCat($category_id) { 183 global $objFormParam; 184 $objQuery = new SC_Query(); 185 // 入力データを渡す。 186 $sqlval = $objFormParam->getHashArray(); 187 $sqlval['update_date'] = "Now()"; 188 $where = "category_id = ?"; 189 $objQuery->update("dtb_category", $sqlval, $where, array($category_id)); 190 } 191 192 // カテゴリの取得 193 function lfGetCat($parent_category_id) { 194 $objQuery = new SC_Query(); 195 196 if($parent_category_id == "") { 197 $parent_category_id = '0'; 198 } 199 200 $col = "category_id, category_name, level, rank"; 201 $where = "del_flg = 0 AND parent_category_id = ?"; 202 $objQuery->setoption("ORDER BY rank DESC"); 203 $arrRet = $objQuery->select($col, "dtb_category", $where, array($parent_category_id)); 204 return $arrRet; 205 } 206 207 /* パラメータ情報の初期化 */ 208 function lfInitParam() { 209 global $objFormParam; 210 $objFormParam->addParam("カテゴリ名", "category_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); 211 } 212 213 /* 入力内容のチェック */ 214 function lfCheckError($array) { 215 global $objFormParam; 216 $objErr = new SC_CheckError($array); 217 $objErr->arrErr = $objFormParam->checkError(); 218 219 // 階層チェック 220 if(!isset($objErr->arrErr['category_name'])) { 221 $objQuery = new SC_Query(); 222 $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($_POST['parent_category_id'])); 223 224 if($level >= LEVEL_MAX) { 225 $objErr->arrErr['category_name'] = "※ ".LEVEL_MAX."階層以上の登録はできません。<br>"; 226 } 227 } 228 229 // 重複チェック 230 if(!isset($objErr->arrErr['category_name'])) { 231 $objQuery = new SC_Query(); 232 $where = "parent_category_id = ? AND category_name = ?"; 233 $arrRet = $objQuery->select("category_id, category_name", "dtb_category", $where, array($_POST['parent_category_id'], $array['category_name'])); 234 // 編集中のレコード以外に同じ名称が存在する場合 235 if ($arrRet[0]['category_id'] != $_POST['category_id'] && $arrRet[0]['category_name'] == $_POST['category_name']) { 236 $objErr->arrErr['category_name'] = "※ 既に同じ内容の登録が存在します。<br>"; 237 } 238 } 239 240 return $objErr->arrErr; 241 } 242 243 244 // 並びが1つ下のIDを取得する。 245 function lfGetDownRankID($objQuery, $table, $pid_name, $id_name, $id) { 246 // 親IDを取得する。 247 $col = "$pid_name"; 248 $where = "$id_name = ?"; 249 $pid = $objQuery->get($table, $col, $where, $id); 250 // すべての子を取得する。 251 $col = "$id_name"; 252 $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; 253 $arrRet = $objQuery->select($col, $table, $where, array($pid)); 254 $max = count($arrRet); 255 $down_id = ""; 256 for($cnt = 0; $cnt < $max; $cnt++) { 257 if($arrRet[$cnt][$id_name] == $id) { 258 $down_id = $arrRet[($cnt + 1)][$id_name]; 259 break; 260 } 261 } 262 return $down_id; 263 } 264 265 // 並びが1つ上のIDを取得する。 266 function lfGetUpRankID($objQuery, $table, $pid_name, $id_name, $id) { 267 // 親IDを取得する。 268 $col = "$pid_name"; 269 $where = "$id_name = ?"; 270 $pid = $objQuery->get($table, $col, $where, $id); 271 // すべての子を取得する。 272 $col = "$id_name"; 273 $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; 274 $arrRet = $objQuery->select($col, $table, $where, array($pid)); 275 $max = count($arrRet); 276 $up_id = ""; 277 for($cnt = 0; $cnt < $max; $cnt++) { 278 if($arrRet[$cnt][$id_name] == $id) { 279 $up_id = $arrRet[($cnt - 1)][$id_name]; 280 break; 281 } 282 } 283 return $up_id; 284 } 285 286 function lfCountChilds($objQuery, $table, $pid_name, $id_name, $id) { 287 // 子ID一覧を取得 288 $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id); 289 return count($arrRet); 290 } 291 292 function lfUpRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) { 293 // 子ID一覧を取得 294 $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id); 295 $line = sfGetCommaList($arrRet); 296 $sql = "UPDATE $table SET rank = (rank + $count) WHERE $id_name IN ($line) "; 297 $sql.= "AND del_flg = 0"; 298 $ret = $objQuery->exec($sql); 299 return $ret; 300 } 301 302 function lfDownRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) { 303 // 子ID一覧を取得 304 $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id); 305 $line = sfGetCommaList($arrRet); 306 $sql = "UPDATE $table SET rank = (rank - $count) WHERE $id_name IN ($line) "; 307 $sql.= "AND del_flg = 0"; 308 $ret = $objQuery->exec($sql); 309 return $ret; 310 } 15 $objPage = new LC_Page_Admin_Products_Category_Ex(); 16 $objPage->init(); 17 $objPage->process(); 18 register_shutdown_function(array($objPage, "destroy")); 311 19 ?>
Note: See TracChangeset
for help on using the changeset viewer.