Changeset 798
- Timestamp:
- Jun 30, 2005, 11:00:07 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/cat_list.php
r792 r798 31 31 } 32 32 include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); 33 34 // +-----------------------------------------------------------------------+ 35 // | functions | 36 // +-----------------------------------------------------------------------+ 37 38 /** 39 * save the rank depending on given categories order 40 * 41 * The list of ordered categories id is supposed to be in the same parent 42 * category 43 * 44 * @param array categories 45 * @return void 46 */ 47 function save_categories_order($categories) 48 { 49 $current_rank = 0; 50 $datas = array(); 51 foreach ($categories as $id) 52 { 53 array_push($datas, array('id' => $id, 'rank' => ++$current_rank)); 54 } 55 $fields = array('primary' => array('id'), 'update' => array('rank')); 56 mass_updates(CATEGORIES_TABLE, $fields, $datas); 57 58 update_global_rank(@$_GET['parent_id']); 59 } 60 33 61 // +-----------------------------------------------------------------------+ 34 62 // | initialization | … … 48 76 } 49 77 // request to add a virtual category 50 else if (isset($_POST['submit ']))78 else if (isset($_POST['submitAdd'])) 51 79 { 52 80 // is the given category name only containing blank spaces ? … … 138 166 } 139 167 } 168 else if (isset($_POST['submitOrder'])) 169 { 170 asort($_POST['catOrd'], SORT_NUMERIC); 171 save_categories_order(array_keys($_POST['catOrd'])); 172 } 140 173 // +-----------------------------------------------------------------------+ 141 174 // | Cache management | … … 180 213 false); 181 214 } 182 // +-----------------------------------------------------------------------+183 // | rank updates |184 // +-----------------------------------------------------------------------+185 $current_rank = 0;186 if (isset($_GET['up']) and is_numeric($_GET['up']))187 {188 // 1. searching the id of the category just above at the same level189 while (list ($id,$current) = each($categories))190 {191 if ($current['id'] == $_GET['up'])192 {193 $current_rank = $current['rank'];194 break;195 }196 }197 if ($current_rank > 1)198 {199 // 2. Exchanging ranks between the two categories200 $query = '201 UPDATE '.CATEGORIES_TABLE.'202 SET rank = '.($current_rank-1).'203 WHERE id = '.$_GET['up'].'204 ;';205 pwg_query($query);206 $query = '207 UPDATE '.CATEGORIES_TABLE.'208 SET rank = '.$current_rank.'209 WHERE id = '.$categories[($current_rank-1)]['id'].'210 ;';211 pwg_query($query);212 // 3. Updating the cache array213 $categories[$current_rank] = $categories[($current_rank-1)];214 $categories[($current_rank-1)] = $current;215 }216 else217 {218 // 2. Updating the rank of our category to be after the previous max rank219 $query = '220 UPDATE '.CATEGORIES_TABLE.'221 SET rank = '.(count($categories) + 1).'222 WHERE id = '.$_GET['up'].'223 ;';224 pwg_query($query);225 $query = '226 UPDATE '.CATEGORIES_TABLE.'227 SET rank = rank-1228 WHERE id_uppercat ';229 if (empty($_GET['parent_id']))230 {231 $query.= 'IS NULL';232 }233 else234 {235 $query.= '= '.$_GET['parent_id'];236 }237 $query.= '238 ;';239 pwg_query($query);240 // 3. Updating the cache array241 array_push($categories, $current);242 array_shift($categories);243 }244 update_global_rank(@$_GET['parent_id']);245 }246 else if (isset($_GET['down']) and is_numeric($_GET['down']))247 {248 // 1. searching the id of the category just above at the same level249 while (list ($id,$current) = each($categories))250 {251 if ($current['id'] == $_GET['down'])252 {253 $current_rank = $current['rank'];254 break;255 }256 }257 if ($current_rank < count($categories))258 {259 // 2. Exchanging ranks between the two categories260 $query = '261 UPDATE '.CATEGORIES_TABLE.'262 SET rank = '.($current_rank+1).'263 WHERE id = '.$_GET['down'].'264 ;';265 pwg_query($query);266 $query = '267 UPDATE '.CATEGORIES_TABLE.'268 SET rank = '.$current_rank.'269 WHERE id = '.$categories[($current_rank+1)]['id'].'270 ;';271 pwg_query($query);272 // 3. Updating the cache array273 $categories[$current_rank]=$categories[($current_rank+1)];274 $categories[($current_rank+1)] = $current;275 }276 else277 {278 // 2. updating the rank of our category to be the first one279 $query = '280 UPDATE '.CATEGORIES_TABLE.'281 SET rank = 0282 WHERE id = '.$_GET['down'].'283 ;';284 pwg_query($query);285 $query = '286 UPDATE '.CATEGORIES_TABLE.'287 SET rank = rank+1288 WHERE id_uppercat ';289 if (empty($_GET['parent_id']))290 {291 $query.= 'IS NULL';292 }293 else294 {295 $query.= '= '.$_GET['parent_id'];296 }297 $query.= '298 ;';299 pwg_query($query);300 // 3. Updating the cache array301 array_unshift($categories, $current);302 array_pop($categories);303 }304 update_global_rank(@$_GET['parent_id']);305 }306 reset($categories);307 215 // +-----------------------------------------------------------------------+ 308 216 // | template initialization | … … 345 253 // | Categories display | 346 254 // +-----------------------------------------------------------------------+ 347 $ranks = array(); 255 256 $categories = array(); 257 258 $query = ' 259 SELECT id, name, dir, rank, nb_images, status 260 FROM '.CATEGORIES_TABLE; 261 if (!isset($_GET['parent_id'])) 262 { 263 $query.= ' 264 WHERE id_uppercat IS NULL'; 265 } 266 else 267 { 268 $query.= ' 269 WHERE id_uppercat = '.$_GET['parent_id']; 270 } 271 $query.= ' 272 ORDER BY rank ASC 273 ;'; 274 $result = pwg_query($query); 275 while ($row = mysql_fetch_array($result)) 276 { 277 $categories[$row['id']] = $row; 278 // by default, let's consider there is no sub-categories. This will be 279 // calculated after. 280 $categories[$row['id']]['nb_subcats'] = 0; 281 } 348 282 349 283 if (count($categories) > 0) 350 284 { 351 foreach ($categories as $category)352 {353 $ranks[$category['id']] = $category['rank'];354 }355 356 285 $query = ' 357 286 SELECT id_uppercat, COUNT(*) AS nb_subcats 358 287 FROM '. CATEGORIES_TABLE.' 359 WHERE id_uppercat IN ('.implode(',', array_keys($ ranks)).')288 WHERE id_uppercat IN ('.implode(',', array_keys($categories)).') 360 289 GROUP BY id_uppercat 361 290 ;'; … … 363 292 while ($row = mysql_fetch_array($result)) 364 293 { 365 $categories[$ranks[$row['id_uppercat']]]['nb_subcats'] 366 = $row['nb_subcats']; 294 $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats']; 367 295 } 368 296 } … … 373 301 $images_folder.= $user['template'].'/admin/images'; 374 302 375 if ($category['visible'] == 'false')376 {377 $image_src = $images_folder.'/icon_folder_lock.gif';378 $image_alt = $lang['cat_private'];379 $image_title = $lang['cat_private'];380 }381 else if (empty($category['dir']))382 {383 $image_src = $images_folder.'/icon_folder_link.gif';384 $image_alt = $lang['cat_virtual'];385 $image_title = $lang['cat_virtual'];386 }387 else388 {389 if ($category['nb_subcats'] > 0)390 {391 $image_src = $images_folder.'/icon_subfolder.gif';392 }393 else394 {395 $image_src = $images_folder.'/icon_folder.gif';396 }397 $image_alt = '';398 $image_title = '';399 }400 401 303 $base_url = PHPWG_ROOT_PATH.'admin.php?page='; 402 304 $cat_list_url = $base_url.'cat_list'; … … 411 313 'category', 412 314 array( 413 ' CATEGORY_IMG_SRC'=>$image_src,414 ' CATEGORY_IMG_ALT'=>$image_alt,415 ' CATEGORY_IMG_TITLE'=>$image_title,416 'CATEGORY_NAME'=>$category['name'], 417 ' CATEGORY_DIR'=>@$category['dir'],418 'CATEGORY_NB_IMG'=>$category['nb_images'],315 'NAME'=>$category['name'], 316 'ID'=>$category['id'], 317 'RANK'=>$category['rank']*10, 318 319 'U_JUMPTO'=> 320 add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']), 419 321 420 'U_C ATEGORY'=>322 'U_CHILDREN'=> 421 323 add_session_id($cat_list_url.'&parent_id='.$category['id']), 422 324 423 'U_MOVE_UP'=>add_session_id($self_url.'&up='.$category['id']), 424 425 'U_MOVE_DOWN'=>add_session_id($self_url.'&down='.$category['id']), 426 427 'U_CAT_EDIT'=> 428 add_session_id($base_url.'cat_modify&cat_id='.$category['id']), 429 430 'U_CAT_DELETE'=>add_session_id($self_url.'&delete='.$category['id']), 431 432 'U_INFO_IMG' 433 => add_session_id($base_url.'element_set&cat='.$category['id']) 434 )); 435 436 if (!empty($category['dir'])) 437 { 438 $template->assign_block_vars('category.storage' ,array()); 439 } 440 else 441 { 442 $template->assign_block_vars('category.virtual' ,array()); 325 'U_EDIT'=> 326 add_session_id($base_url.'cat_modify&cat_id='.$category['id']) 327 ) 328 ); 329 330 if (empty($category['dir'])) 331 { 332 $template->assign_block_vars( 333 'category.delete', 334 array( 335 'URL'=>add_session_id($self_url.'&delete='.$category['id']) 336 ) 337 ); 443 338 } 444 339 445 340 if ($category['nb_images'] > 0) 446 341 { 447 $template->assign_block_vars('category.image_info' ,array()); 448 } 449 else 450 { 451 $template->assign_block_vars('category.no_image_info' ,array()); 342 $template->assign_block_vars( 343 'category.elements', 344 array( 345 'URL'=>add_session_id($base_url.'element_set&cat='.$category['id']) 346 ) 347 ); 348 } 349 350 if ('private' == $category['status']) 351 { 352 $template->assign_block_vars( 353 'category.permissions', 354 array( 355 'URL'=>add_session_id($base_url.'cat_perm&cat='.$category['id']) 356 ) 357 ); 452 358 } 453 359 } -
trunk/doc/ChangeLog
r797 r798 1 2005-06-30 Pierrick LE GALL 2 3 * categories management : new display with icon for actions 4 (delete, sub-categories, elements, edit, jump to, permissions) 5 6 * categories management : semantic HTML layout (using common 7 lists) 8 9 * categories management : new way to order categories of the same 10 level : a text field let the admin reorder all categories at once. 11 1 12 2005-06-25 Pierrick LE GALL 2 13 -
trunk/template/default/admin/cat_list.tpl
r792 r798 1 1 <div class="admin">{CATEGORIES_NAV}</div> 2 <table style="width:100%;"> 3 <!-- BEGIN category --> 4 <tr> 5 <td style="width:1px;padding:5px;"><img src="{category.CATEGORY_IMG_SRC}" alt="{category.CATEGORY_IMG_ALT}" title="{category.CATEGORY_IMG_TITLE}" /></td> 6 <td style="width:60%;text-align:left;"><a class="titreImg" href="{category.U_CATEGORY}">{category.CATEGORY_NAME}</a> 7 <br /> 8 <!-- BEGIN storage --> 9 {L_STORAGE} : {category.CATEGORY_DIR} - 10 <!-- END storage --> 11 {L_NB_IMG} : {category.CATEGORY_NB_IMG} 12 </td> 13 <td class="row1" style="width:10%;white-space:nowrap;text-align:center;"> 14 <a href="{category.U_MOVE_UP}">{L_MOVE_UP}</a><br /> 15 <a href="{category.U_MOVE_DOWN}">{L_MOVE_DOWN}</a> 16 </td> 17 <td class="row1" style="width:10%;white-space:nowrap;text-align:center;"> 18 <a href="{category.U_CAT_EDIT}">{L_EDIT}</a> 19 </td> 20 <td class="row1" style="width:10%;white-space:nowrap;text-align:center;"> 21 <!-- BEGIN image_info --> 22 <a href="{category.U_INFO_IMG}">{L_INFO_IMG}</a> 23 <!-- END image_info --> 24 <!-- BEGIN no_image_info --> 25 <span style="color:darkgray;">{L_INFO_IMG}</span> 26 <!-- END no_image_info --> 27 </td> 28 <td class="row1" style="width:10%;white-space:nowrap;text-align:center;"> 29 <!-- BEGIN virtual --> 30 <a href="{category.U_CAT_DELETE}">{L_DELETE}</a> 31 <!-- END virtual --> 32 <!-- BEGIN storage --> 33 <span style="color:darkgray;">{L_DELETE}</span> 34 <!-- END storage --> 35 </td> 36 <tr> 37 <!-- END category --> 38 </table> 2 3 <form id="categoryOrdering" action="" method="post"> 4 5 <ul> 6 7 <!-- BEGIN category --> 8 <li> <!-- category {category.ID} --> 9 10 <ul class="categoryActions"> 11 <li><a href="{category.U_JUMPTO}" title="{lang:jump to category}"><img src="./template/default/theme/category_jump-to.png" alt="{lang:jump to}" /></a></li> 12 <li><a href="{category.U_EDIT}" title="{lang:edit category informations}"><img src="./template/default/theme/category_edit.png" alt="{lang:edit}"/></a></li> 13 <!-- BEGIN elements --> 14 <li><a href="{category.elements.URL}" title="{lang:manage category elements}"><img src="./template/default/theme/category_elements.png" alt="{lang:elements}" /></a></li> 15 <!-- END elements --> 16 <li><a href="{category.U_CHILDREN}" title="{lang:manage sub-categories}"><img src="./template/default/theme/category_children.png" alt="{lang:sub-categories}" /></a></li> 17 <!-- BEGIN delete --> 18 <li><a href="{category.delete.URL}" title="{lang:delete category}"><img src="./template/default/theme/category_delete.png" alt="{lang:delete}" /></a></li> 19 <!-- END delete --> 20 </ul> 21 22 <p><strong>{category.NAME}</strong></p> 23 24 <p> 25 <label> 26 {lang:Position} : 27 <input type="text" size="4" name="catOrd[{category.ID}]" maxlength="4" value="{category.RANK}" /> 28 </label> 29 </p> 30 31 </li> 32 <!-- END category --> 33 34 <p><input name="submitOrder" type="submit" class="bouton" value="{lang:Save order}" /></p> 35 36 </form> 37 39 38 <form action="{F_ACTION}" method="post"> 40 39 {L_ADD_VIRTUAL} : <input type="text" name="virtual_name" /> 41 40 <input type="hidden" name="rank" value="{NEXT_RANK}"/> 42 <input type="submit" value="{L_SUBMIT}" class="bouton" name="submit " />41 <input type="submit" value="{L_SUBMIT}" class="bouton" name="submitAdd" /> 43 42 </form> -
trunk/template/default/default.css
r796 r798 381 381 label:hover { 382 382 cursor: pointer; 383 } 384 385 /** 386 * Categories management 387 */ 388 389 form#categoryOrdering>ul { 390 list-style: none; 391 padding: 0; 392 margin: 0; 393 } 394 395 form#categoryOrdering>ul>li { 396 border: 1px solid grey; 397 padding: 0px 5px; 398 margin-bottom: 5px; 399 } 400 401 form#categoryOrdering ul.categoryActions { 402 float: right; 403 margin-top: 5px; 404 } 405 406 ul.categoryActions>li { 407 display: inline; 408 } 409 410 ul.categoryActions a img { 411 border: none; 383 412 } 384 413
Note: See TracChangeset
for help on using the changeset viewer.