Changeset 798


Ignore:
Timestamp:
Jun 30, 2005, 11:00:07 PM (19 years ago)
Author:
plg
Message:
  • categories management : new display with icon for actions (delete, sub-categories, elements, edit, jump to, permissions)
  • categories management : semantic HTML layout (using common lists)
  • categories management : new way to order categories of the same level : a text field let the admin reorder all categories at once.
Location:
trunk
Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_list.php

    r792 r798  
    3131}
    3232include_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 */
     47function 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
    3361// +-----------------------------------------------------------------------+
    3462// |                            initialization                             |
     
    4876}
    4977// request to add a virtual category
    50 else if (isset($_POST['submit']))
     78else if (isset($_POST['submitAdd']))
    5179{
    5280  // is the given category name only containing blank spaces ?
     
    138166  }
    139167}
     168else if (isset($_POST['submitOrder']))
     169{
     170  asort($_POST['catOrd'], SORT_NUMERIC);
     171  save_categories_order(array_keys($_POST['catOrd']));
     172}
    140173// +-----------------------------------------------------------------------+
    141174// |                           Cache management                            |
     
    180213                                     false);
    181214}
    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 level
    189   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 categories
    200     $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 array
    213     $categories[$current_rank] = $categories[($current_rank-1)];
    214     $categories[($current_rank-1)] = $current;
    215   }
    216   else
    217   {
    218     // 2. Updating the rank of our category to be after the previous max rank
    219     $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-1
    228   WHERE id_uppercat ';
    229     if (empty($_GET['parent_id']))
    230     {
    231       $query.= 'IS NULL';
    232     }
    233     else
    234     {
    235       $query.= '= '.$_GET['parent_id'];
    236     }
    237     $query.= '
    238 ;';
    239     pwg_query($query);
    240     // 3. Updating the cache array
    241     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 level
    249   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 categories
    260     $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 array
    273     $categories[$current_rank]=$categories[($current_rank+1)];
    274     $categories[($current_rank+1)] = $current;
    275   }
    276   else
    277   {
    278     // 2. updating the rank of our category to be the first one
    279     $query = '
    280 UPDATE '.CATEGORIES_TABLE.'
    281   SET rank = 0
    282   WHERE id = '.$_GET['down'].'
    283 ;';
    284     pwg_query($query);
    285     $query = '
    286 UPDATE '.CATEGORIES_TABLE.'
    287   SET rank = rank+1
    288   WHERE id_uppercat ';
    289     if (empty($_GET['parent_id']))
    290     {
    291       $query.= 'IS NULL';
    292     }
    293     else
    294     {
    295       $query.= '= '.$_GET['parent_id'];
    296     }
    297     $query.= '
    298 ;';
    299     pwg_query($query);
    300     // 3. Updating the cache array
    301     array_unshift($categories, $current);
    302     array_pop($categories);
    303   }
    304   update_global_rank(@$_GET['parent_id']);
    305 }
    306 reset($categories);
    307215// +-----------------------------------------------------------------------+
    308216// |                       template initialization                         |
     
    345253// |                          Categories display                           |
    346254// +-----------------------------------------------------------------------+
    347 $ranks = array();
     255
     256$categories = array();
     257
     258$query = '
     259SELECT id, name, dir, rank, nb_images, status
     260  FROM '.CATEGORIES_TABLE;
     261if (!isset($_GET['parent_id']))
     262{
     263  $query.= '
     264  WHERE id_uppercat IS NULL';
     265}
     266else
     267{
     268  $query.= '
     269  WHERE id_uppercat = '.$_GET['parent_id'];
     270}
     271$query.= '
     272  ORDER BY rank ASC
     273;';
     274$result = pwg_query($query);
     275while ($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}
    348282
    349283if (count($categories) > 0)
    350284{
    351   foreach ($categories as $category)
    352   {
    353     $ranks[$category['id']] = $category['rank'];
    354   }
    355 
    356285  $query = '
    357286SELECT id_uppercat, COUNT(*) AS nb_subcats
    358287  FROM '. CATEGORIES_TABLE.'
    359   WHERE id_uppercat IN ('.implode(',', array_keys($ranks)).')
     288  WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
    360289  GROUP BY id_uppercat
    361290;';
     
    363292  while ($row = mysql_fetch_array($result))
    364293  {
    365     $categories[$ranks[$row['id_uppercat']]]['nb_subcats']
    366       = $row['nb_subcats'];
     294    $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
    367295  }
    368296}
     
    373301  $images_folder.= $user['template'].'/admin/images';
    374302 
    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   else
    388   {
    389     if ($category['nb_subcats'] > 0)
    390     {
    391       $image_src = $images_folder.'/icon_subfolder.gif';
    392     }
    393     else
    394     {
    395       $image_src = $images_folder.'/icon_folder.gif';
    396     }
    397     $image_alt = '';
    398     $image_title = '';
    399   }
    400 
    401303  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
    402304  $cat_list_url = $base_url.'cat_list';
     
    411313    'category',
    412314    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']),
    419321     
    420       'U_CATEGORY'=>
     322      'U_CHILDREN'=>
    421323      add_session_id($cat_list_url.'&amp;parent_id='.$category['id']),
    422324     
    423       'U_MOVE_UP'=>add_session_id($self_url.'&amp;up='.$category['id']),
    424      
    425       'U_MOVE_DOWN'=>add_session_id($self_url.'&amp;down='.$category['id']),
    426      
    427       'U_CAT_EDIT'=>
    428       add_session_id($base_url.'cat_modify&amp;cat_id='.$category['id']),
    429      
    430       'U_CAT_DELETE'=>add_session_id($self_url.'&amp;delete='.$category['id']),
    431      
    432       'U_INFO_IMG'
    433       => add_session_id($base_url.'element_set&amp;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&amp;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.'&amp;delete='.$category['id'])
     336        )
     337      );
    443338  }
    444339 
    445340  if ($category['nb_images'] > 0)
    446341  {
    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&amp;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&amp;cat='.$category['id'])
     356        )
     357      );
    452358  }
    453359}
  • trunk/doc/ChangeLog

    r797 r798  
     12005-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       
    1122005-06-25 Pierrick LE GALL
    213
  • trunk/template/default/admin/cat_list.tpl

    r792 r798  
    11<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
    3938<form action="{F_ACTION}" method="post">
    4039  {L_ADD_VIRTUAL} : <input type="text" name="virtual_name" />
    4140  <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" />
    4342</form>
  • trunk/template/default/default.css

    r796 r798  
    381381label:hover {
    382382  cursor: pointer;
     383}
     384
     385/**
     386 * Categories management
     387 */
     388
     389form#categoryOrdering>ul {
     390  list-style: none;
     391  padding: 0;
     392  margin: 0;
     393}
     394
     395form#categoryOrdering>ul>li {
     396  border: 1px solid grey;
     397  padding: 0px 5px;
     398  margin-bottom: 5px;
     399}
     400
     401form#categoryOrdering ul.categoryActions {
     402  float: right;
     403  margin-top: 5px;
     404}
     405
     406ul.categoryActions>li {
     407  display: inline;
     408}
     409
     410ul.categoryActions a img {
     411  border: none;
    383412}
    384413
Note: See TracChangeset for help on using the changeset viewer.