- Timestamp:
- 2006/10/13 18:21:56 (20 years ago)
- File:
-
- 1 edited
-
temp/trunk/data/update/admin/products/category.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
temp/trunk/data/update/admin/products/category.php
r6330 r6331 1 1 <?php 2 print("test"); 2 /* 3 * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved. 4 * 5 * http://www.lockon.co.jp/ 6 */ 7 8 class UC_Page { 9 function UC_Page() { 10 $this->tpl_mainpage = 'products/category.tpl'; 11 $this->tpl_subnavi = 'products/subnavi.tpl'; 12 $this->tpl_mainno = 'products'; 13 $this->tpl_subno = 'category'; 14 $this->tpl_onload = " fnSetFocus('category_name'); "; 15 $this->tpl_subtitle = '¥«¥Æ¥´¥ê¡¼ÅÐÏ¿'; 16 } 17 } 18 19 $conn = new SC_DBConn(); 20 $objPage = new UC_Page(); 21 $objView = new SC_AdminView(); 22 $objSess = new SC_Session(); 23 24 // ǧ¾Ú²ÄÈݤÎȽÄê 25 sfIsSuccess($objSess); 26 27 // ¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹ 28 $objFormParam = new SC_FormParam(); 29 // ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½ 30 lfInitParam(); 31 // POSTÃͤμèÆÀ 32 $objFormParam->setParam($_POST); 33 34 // Ä̾ï»þ¤Ï¿Æ¥«¥Æ¥´¥ê¤ò0¤ËÀßÄꤹ¤ë¡£ 35 $objPage->arrForm['parent_category_id'] = $_POST['parent_category_id']; 36 37 switch($_POST['mode']) { 38 case 'edit': 39 $objFormParam->convParam(); 40 $arrRet = $objFormParam->getHashArray(); 41 $objPage->arrErr = lfCheckError($arrRet); 42 43 if(count($objPage->arrErr) == 0) { 44 if($_POST['category_id'] == "") { 45 $objQuery = new SC_Query(); 46 $count = $objQuery->count("dtb_category"); 47 if($count < CATEGORY_MAX) { 48 lfInsertCat($_POST['parent_category_id']); 49 } else { 50 print("¥«¥Æ¥´¥ê¤ÎÅÐÏ¿ºÇÂç¿ô¤òͤ¨¤Þ¤·¤¿¡£"); 51 } 52 } else { 53 lfUpdateCat($_POST['category_id']); 54 } 55 } else { 56 $objPage->arrForm = array_merge($objPage->arrForm, $objFormParam->getHashArray()); 57 $objPage->arrForm['category_id'] = $_POST['category_id']; 58 } 59 break; 60 case 'pre_edit': 61 // ÊÔ½¸¹àÌܤΥ«¥Æ¥´¥ê̾¤òDB¤è¤ê¼èÆÀ¤¹¤ë¡£ 62 $oquery = new SC_Query(); 63 $where = "category_id = ?"; 64 $cat_name = $oquery->get("dtb_category", "category_name", $where, array($_POST['category_id'])); 65 // ÆþÎϹàÌܤ˥«¥Æ¥´¥ê̾¤òÆþÎϤ¹¤ë¡£ 66 $objPage->arrForm['category_name'] = $cat_name; 67 // POST¥Ç¡¼¥¿¤ò°ú¤·Ñ¤° 68 $objPage->arrForm['category_id'] = $_POST['category_id']; 69 break; 70 case 'delete': 71 $objQuery = new SC_Query(); 72 // »Ò¥«¥Æ¥´¥ê¤Î¥Á¥§¥Ã¥¯ 73 $where = "parent_category_id = ? AND del_flg = 0"; 74 $count = $objQuery->count("dtb_category", $where, array($_POST['category_id'])); 75 if($count != 0) { 76 $objPage->arrErr['category_name'] = "¢¨ »Ò¥«¥Æ¥´¥ê¤¬Â¸ºß¤¹¤ë¤¿¤áºï½ü¤Ç¤¤Þ¤»¤ó¡£<br>"; 77 } 78 // ÅÐÏ¿¾¦ÉʤΥÁ¥§¥Ã¥¯ 79 $where = "category_id = ? AND del_flg = 0"; 80 $count = $objQuery->count("dtb_products", $where, array($_POST['category_id'])); 81 if($count != 0) { 82 $objPage->arrErr['category_name'] = "¢¨ ¥«¥Æ¥´¥êÆâ¤Ë¾¦Éʤ¬Â¸ºß¤¹¤ë¤¿¤áºï½ü¤Ç¤¤Þ¤»¤ó¡£<br>"; 83 } 84 85 if(!isset($objPage->arrErr['category_name'])) { 86 // ¥é¥ó¥¯ÉÕ¤¥ì¥³¡¼¥É¤Îºï½ü(¢¨½èÍýÉé²Ù¤ò¹Íθ¤·¤Æ¥ì¥³¡¼¥É¤´¤Èºï½ü¤¹¤ë¡£) 87 sfDeleteRankRecord("dtb_category", "category_id", $_POST['category_id'], "", true); 88 } 89 break; 90 case 'up': 91 $objQuery = new SC_Query(); 92 $objQuery->begin(); 93 $up_id = lfGetUpRankID($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']); 94 if($up_id != "") { 95 // ¾å¤Î¥°¥ë¡¼¥×¤Îrank¤«¤é¸º»»¤¹¤ë¿ô 96 $my_count = lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']); 97 // ¼«Ê¬¤Î¥°¥ë¡¼¥×¤Îrank¤Ë²Ã»»¤¹¤ë¿ô 98 $up_count = lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $up_id); 99 if($my_count > 0 && $up_count > 0) { 100 // ¼«Ê¬¤Î¥°¥ë¡¼¥×¤Ë²Ã»» 101 lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id'], $up_count); 102 // ¾å¤Î¥°¥ë¡¼¥×¤«¤é¸º»» 103 lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $up_id, $my_count); 104 } 105 } 106 $objQuery->commit(); 107 break; 108 case 'down': 109 $objQuery = new SC_Query(); 110 $objQuery->begin(); 111 $down_id = lfGetDownRankID($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']); 112 if($down_id != "") { 113 // ²¼¤Î¥°¥ë¡¼¥×¤Îrank¤Ë²Ã»»¤¹¤ë¿ô 114 $my_count = lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id']); 115 // ¼«Ê¬¤Î¥°¥ë¡¼¥×¤Îrank¤«¤é¸º»»¤¹¤ë¿ô 116 $down_count = lfCountChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $down_id); 117 if($my_count > 0 && $down_count > 0) { 118 // ¼«Ê¬¤Î¥°¥ë¡¼¥×¤«¤é¸º»» 119 lfUpRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $down_id, $my_count); 120 // ²¼¤Î¥°¥ë¡¼¥×¤Ë²Ã»» 121 lfDownRankChilds($objQuery, "dtb_category", "parent_category_id", "category_id", $_POST['category_id'], $down_count); 122 } 123 } 124 $objQuery->commit(); 125 break; 126 case 'tree': 127 break; 128 default: 129 $objPage->arrForm['parent_category_id'] = 0; 130 break; 131 } 132 133 $objPage->arrList = lfGetCat($objPage->arrForm['parent_category_id']); 134 $objPage->arrTree = sfGetCatTree($objPage->arrForm['parent_category_id']); 135 136 $objView->assignobj($objPage); 137 $objView->display(MAIN_FRAME); 138 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 $col = "category_id, category_name, level, rank"; 196 $where = "del_flg = 0 AND parent_category_id = ?"; 197 $objQuery->setoption("ORDER BY rank DESC"); 198 $arrRet = $objQuery->select($col, "dtb_category", $where, array($parent_category_id)); 199 return $arrRet; 200 } 201 202 /* ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½ */ 203 function lfInitParam() { 204 global $objFormParam; 205 $objFormParam->addParam("¥«¥Æ¥´¥ê̾", "category_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); 206 } 207 208 /* ÆþÎÏÆâÍÆ¤Î¥Á¥§¥Ã¥¯ */ 209 function lfCheckError($array) { 210 global $objFormParam; 211 $objErr = new SC_CheckError($array); 212 $objErr->arrErr = $objFormParam->checkError(); 213 214 // ³¬ÁØ¥Á¥§¥Ã¥¯ 215 if(!isset($objErr->arrErr['category_name'])) { 216 $objQuery = new SC_Query(); 217 $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($_POST['parent_category_id'])); 218 219 if($level >= LEVEL_MAX) { 220 $objErr->arrErr['category_name'] = "¢¨ ".LEVEL_MAX."³¬Áذʾå¤ÎÅÐÏ¿¤Ï¤Ç¤¤Þ¤»¤ó¡£<br>"; 221 } 222 } 223 224 // ½ÅÊ£¥Á¥§¥Ã¥¯ 225 if(!isset($objErr->arrErr['category_name'])) { 226 $objQuery = new SC_Query(); 227 $where = "parent_category_id = ? AND category_name = ?"; 228 $arrRet = $objQuery->select("category_id, category_name", "dtb_category", $where, array($_POST['parent_category_id'], $array['category_name'])); 229 // ÊÔ½¸Ãæ¤Î¥ì¥³¡¼¥É°Ê³°¤ËƱ¤¸Ì¾¾Î¤¬Â¸ºß¤¹¤ë¾ì¹ç 230 if ($arrRet[0]['category_id'] != $_POST['category_id'] && $arrRet[0]['category_name'] == $_POST['category_name']) { 231 $objErr->arrErr['category_name'] = "¢¨ ´û¤ËƱ¤¸ÆâÍÆ¤ÎÅÐÏ¿¤¬Â¸ºß¤·¤Þ¤¹¡£<br>"; 232 } 233 } 234 235 return $objErr->arrErr; 236 } 237 238 239 // ʤӤ¬1¤Ä²¼¤ÎID¤ò¼èÆÀ¤¹¤ë¡£ 240 function lfGetDownRankID($objQuery, $table, $pid_name, $id_name, $id) { 241 // ¿ÆID¤ò¼èÆÀ¤¹¤ë¡£ 242 $col = "$pid_name"; 243 $where = "$id_name = ?"; 244 $pid = $objQuery->get($table, $col, $where, $id); 245 // ¤¹¤Ù¤Æ¤Î»Ò¤ò¼èÆÀ¤¹¤ë¡£ 246 $col = "$id_name"; 247 $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; 248 $arrRet = $objQuery->select($col, $table, $where, array($pid)); 249 $max = count($arrRet); 250 $down_id = ""; 251 for($cnt = 0; $cnt < $max; $cnt++) { 252 if($arrRet[$cnt][$id_name] == $id) { 253 $down_id = $arrRet[($cnt + 1)][$id_name]; 254 break; 255 } 256 } 257 return $down_id; 258 } 259 260 // ʤӤ¬1¤Ä¾å¤ÎID¤ò¼èÆÀ¤¹¤ë¡£ 261 function lfGetUpRankID($objQuery, $table, $pid_name, $id_name, $id) { 262 // ¿ÆID¤ò¼èÆÀ¤¹¤ë¡£ 263 $col = "$pid_name"; 264 $where = "$id_name = ?"; 265 $pid = $objQuery->get($table, $col, $where, $id); 266 // ¤¹¤Ù¤Æ¤Î»Ò¤ò¼èÆÀ¤¹¤ë¡£ 267 $col = "$id_name"; 268 $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; 269 $arrRet = $objQuery->select($col, $table, $where, array($pid)); 270 $max = count($arrRet); 271 $up_id = ""; 272 for($cnt = 0; $cnt < $max; $cnt++) { 273 if($arrRet[$cnt][$id_name] == $id) { 274 $up_id = $arrRet[($cnt - 1)][$id_name]; 275 break; 276 } 277 } 278 return $up_id; 279 } 280 281 function lfCountChilds($objQuery, $table, $pid_name, $id_name, $id) { 282 // »ÒID°ìÍ÷¤ò¼èÆÀ 283 $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id); 284 return count($arrRet); 285 } 286 287 function lfUpRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) { 288 // »ÒID°ìÍ÷¤ò¼èÆÀ 289 $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id); 290 $line = sfGetCommaList($arrRet); 291 $sql = "UPDATE $table SET rank = (rank + $count) WHERE $id_name IN ($line) "; 292 $sql.= "AND del_flg = 0"; 293 $ret = $objQuery->exec($sql); 294 return $ret; 295 } 296 297 function lfDownRankChilds($objQuery, $table, $pid_name, $id_name, $id, $count) { 298 // »ÒID°ìÍ÷¤ò¼èÆÀ 299 $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id); 300 $line = sfGetCommaList($arrRet); 301 $sql = "UPDATE $table SET rank = (rank - $count) WHERE $id_name IN ($line) "; 302 $sql.= "AND del_flg = 0"; 303 $ret = $objQuery->exec($sql); 304 return $ret; 305 } 3 306 ?>
Note: See TracChangeset
for help on using the changeset viewer.
