Ignore:
Timestamp:
Mar 5, 2006, 12:31:46 AM (18 years ago)
Author:
plg
Message:

new feature: source/destination links between categories. Will we keep this
feature? Code is complicated and very few people will understand how it
works...

modification: #images.storage_category_id replaced by
#image_category.is_storage

improvement: many code refactoring to improve readibility

improvement: virtual category creation code was moved to a dedicated
function in order to be called from admin/cat_list.php and
admin/cat_modify.php (create a new destination category)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_list.php

    r1004 r1064  
    8484else if (isset($_POST['submitAdd']))
    8585{
    86   // is the given category name only containing blank spaces ?
    87   if (preg_match('/^\s*$/', $_POST['virtual_name']))
    88   {
    89     array_push($page['errors'], $lang['cat_error_name']);
    90   }
    91        
    92   if (!count($page['errors']))
    93   {
    94     $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL';
    95    
    96     if ($parent_id != 'NULL')
    97     {
    98       $query = '
    99 SELECT id,uppercats,global_rank,visible,status
    100   FROM '.CATEGORIES_TABLE.'
    101   WHERE id = '.$parent_id.'
    102 ;';
    103       $row = mysql_fetch_array(pwg_query($query));
    104       $parent = array('id' => $row['id'],
    105                       'uppercats' => $row['uppercats'],
    106                       'visible' => $row['visible'],
    107                       'status' => $row['status'],
    108                       'global_rank' => $row['global_rank']);
    109     }
    110 
    111     // what will be the inserted id ?
    112     $query = '
    113 SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1)
    114   FROM '.CATEGORIES_TABLE.'
    115 ;';
    116     list($next_id) = mysql_fetch_array(pwg_query($query));
    117    
    118     $insert = array();
    119     $insert{'id'} = $next_id++;
    120     $insert{'name'} = $_POST['virtual_name'];
    121     $insert{'rank'} = $_POST['rank'];
    122     $insert{'commentable'} = $conf['newcat_default_commentable'];
    123 
    124     // a virtual category can't be uploadable
    125     $insert{'uploadable'} = 'false';
    126    
    127     if (isset($parent))
    128     {
    129       $insert{'id_uppercat'} = $parent{'id'};
    130       $insert{'uppercats'}   = $parent{'uppercats'}.','.$insert{'id'};
    131       $insert{'global_rank'} = $parent{'global_rank'}.'.'.$insert{'rank'};
    132       // at creation, must a category be visible or not ? Warning : if
    133       // the parent category is invisible, the category is automatically
    134       // create invisible. (invisible = locked)
    135       if ('false' == $parent['visible'])
    136       {
    137         $insert{'visible'} = 'false';
    138       }
    139       else
    140       {
    141         $insert{'visible'} = $conf['newcat_default_visible'];
    142       }
    143       // at creation, must a category be public or private ? Warning :
    144       // if the parent category is private, the category is
    145       // automatically create private.
    146       if ('private' == $parent['status'])
    147       {
    148         $insert{'status'} = 'private';
    149       }
    150       else
    151       {
    152         $insert{'status'} = $conf['newcat_default_status'];
    153       }
    154     }
    155     else
    156     {
    157       $insert{'visible'} = $conf['newcat_default_visible'];
    158       $insert{'status'} = $conf['newcat_default_status'];
    159       $insert{'uppercats'} = $insert{'id'};
    160       $insert{'global_rank'} = $insert{'rank'};
    161     }
    162 
    163     $inserts = array($insert);
    164    
    165     // we have then to add the virtual category
    166     $dbfields = array('id','site_id','name','id_uppercat','rank',
    167                       'commentable','uploadable','visible','status',
    168                       'uppercats','global_rank');
    169     mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
    170 
    171     array_push($page['infos'], $lang['cat_virtual_added']);
     86  $output_create = create_virtual_category(
     87    $_POST['virtual_name'],
     88    @$_GET['parent_id']
     89    );
     90
     91  if (isset($output_create['error']))
     92  {
     93    array_push($page['errors'], $output_create['error']);
     94  }
     95  else
     96  {
     97    array_push($page['infos'], $output_create['info']);
    17298  }
    17399}
     
    212138
    213139  $current_category = get_cat_info($_GET['parent_id']);
    214   $navigation.= get_cat_display_name($current_category['name'],
    215                                      $base_url.'&parent_id=',
    216                                      false);
     140 
     141  $navigation.= get_cat_display_name(
     142    $current_category['name'],
     143    $base_url.'&parent_id=',
     144    false
     145    );
    217146}
    218147// +-----------------------------------------------------------------------+
     
    227156}
    228157
    229 if (count($categories) > 0)
    230 {
    231   $next_rank = max(array_keys($categories)) + 1;
    232 }
    233 else
    234 {
    235   $next_rank = 1;
    236 }
    237 
    238158$template->assign_vars(array(
    239159  'CATEGORIES_NAV'=>$navigation,
    240   'NEXT_RANK'=>$next_rank,
    241160  'F_ACTION'=>$form_action,
    242161 
Note: See TracChangeset for help on using the changeset viewer.