Changeset 642 for trunk/admin/update.php


Ignore:
Timestamp:
Dec 12, 2004, 10:06:39 PM (19 years ago)
Author:
plg
Message:
  • in admin menu, status option for categories is not "permissions" but "private or public" choice = different language item
  • get_cat_display_name changed : use $conflevel_separator to unify presentation
  • default values for category properties commentable, uploadable, status and visible (set in include/config.inc.php) used for category creation (admin/update, admin/remote_site, admin/cat_list)
  • use mass_inserts in admin/update for inserting new categories
  • only one query for counting the number of sub categories in admin/cat_list
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/update.php

    r638 r642  
    4848  if (is_numeric($id_uppercat))
    4949  {
    50     $query = 'SELECT name,uppercats,dir FROM '.CATEGORIES_TABLE;
    51     $query.= ' WHERE id = '.$id_uppercat;
    52     $query.= ';';
    53     $row = mysql_fetch_array( pwg_query( $query));
    54     $uppercats = $row['uppercats'];
    55     $name      = $row['name'];
    56     $dir       = $row['dir'];
    57 
    58     $upper_array = explode( ',', $uppercats);
     50    $query = '
     51SELECT id,name,uppercats,dir,visible,status
     52  FROM '.CATEGORIES_TABLE.'
     53  WHERE id = '.$id_uppercat.'
     54;';
     55    $row = mysql_fetch_array(pwg_query($query));
     56    $parent = array('id' => $row['id'],
     57                    'name' => $row['name'],
     58                    'dir' => $row['dir'],
     59                    'uppercats' => $row['uppercats'],
     60                    'visible' => $row['visible'],
     61                    'status' => $row['status']);
     62
     63    $upper_array = explode( ',', $parent['uppercats']);
    5964
    6065    $local_dir = '';
     
    6267    $database_dirs = array();
    6368    $query = '
    64 SELECT id,dir FROM '.CATEGORIES_TABLE.'
    65   WHERE id IN ('.$uppercats.')
    66 ;';
    67     $result = pwg_query( $query);
     69SELECT id,dir
     70  FROM '.CATEGORIES_TABLE.'
     71  WHERE id IN ('.$parent['uppercats'].')
     72;';
     73    $result = pwg_query($query);
    6874    while ($row = mysql_fetch_array($result))
    6975    {
     
    7985    // 1. display the category name to update
    8086    $output = '<ul class="menu">';
    81     $output.= '<li><strong>'.$name.'</strong>';
    82     $output.= ' [ '.$dir.' ]';
     87    $output.= '<li><strong>'.$parent['name'].'</strong>';
     88    $output.= ' [ '.$parent['dir'].' ]';
    8389    $output.= '</li>';
    8490
     
    95101  $sub_category_dirs = array();
    96102  $query = '
    97 SELECT id,dir FROM '.CATEGORIES_TABLE.'
     103SELECT id,dir
     104  FROM '.CATEGORIES_TABLE.'
    98105  WHERE site_id = 1
    99106';
     
    132139  // array of new categories to insert
    133140  $inserts = array();
     141
     142  // calculate default value at category creation
     143  $create_values = array();
     144  if (isset($parent))
     145  {
     146    // at creation, must a category be visible or not ? Warning : if
     147    // the parent category is invisible, the category is automatically
     148    // create invisible. (invisible = locked)
     149    if ('false' == $parent['visible'])
     150    {
     151      $create_values{'visible'} = 'false';
     152    }
     153    else
     154    {
     155      $create_values{'visible'} = $conf['newcat_default_visible'];
     156    }
     157    // at creation, must a category be public or private ? Warning :
     158    // if the parent category is private, the category is
     159    // automatically create private.
     160    if ('private' == $parent['status'])
     161    {
     162      $create_values{'status'} = 'private';
     163    }
     164    else
     165    {
     166      $create_values{'status'} = $conf['newcat_default_status'];
     167    }
     168  }
     169  else
     170  {
     171    $create_values{'visible'} = $conf['newcat_default_visible'];
     172    $create_values{'status'} = $conf['newcat_default_status'];
     173  }
    134174 
    135175  foreach ($fs_subdirs as $fs_subdir)
     
    140180    if (!is_numeric($category_id))
    141181    {
     182      $insert = array();
     183     
    142184      if (preg_match('/^[a-zA-Z0-9-_.]+$/', $fs_subdir))
    143185      {
    144186        $name = str_replace('_', ' ', $fs_subdir);
    145187
    146         $value = "('".$fs_subdir."','".$name."',1";
    147         if (!is_numeric($id_uppercat))
    148         {
    149           $value.= ',NULL';
    150         }
    151         else
    152         {
    153           $value.= ','.$id_uppercat;
    154         }
    155         $value.= ",'undef'";
    156         $value.= ')';
    157         array_push($inserts, $value);
     188        $insert{'dir'} = $fs_subdir;
     189        $insert{'name'} = $name;
     190        $insert{'site_id'} = 1;
     191        $insert{'uppercats'} = 'undef';
     192        $insert{'commentable'} = $conf['newcat_default_commentable'];
     193        $insert{'uploadable'} = $conf['newcat_default_uploadable'];
     194        $insert{'status'} = $create_values{'status'};
     195        $insert{'visible'} = $create_values{'visible'};
     196
     197        if (isset($parent))
     198        {
     199          $insert{'id_uppercat'} = $parent['id'];
     200        }
     201       
     202        array_push($inserts, $insert);
    158203      }
    159204      else
     
    168213  if (count($inserts) > 0)
    169214  {
    170     $query = '
    171 INSERT INTO '.CATEGORIES_TABLE.'
    172   (dir,name,site_id,id_uppercat,uppercats) VALUES
    173 ';
    174     $query.= implode(',', $inserts);
    175     $query.= '
    176 ;';
    177     pwg_query($query);
    178 
     215    $dbfields = array(
     216      'dir','name','site_id','id_uppercat','uppercats','commentable',
     217      'uploadable','visible','status'
     218      );
     219    mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
     220   
    179221    $counts['new_categories']+= count($inserts);
    180222    // updating uppercats field
    181223    $query = '
    182 UPDATE '.CATEGORIES_TABLE.'
    183   SET uppercats = ';
    184     if ($uppercats != '')
    185     {
    186       $query.= "CONCAT('".$uppercats."',',',id)";
     224UPDATE '.CATEGORIES_TABLE;
     225    if (isset($parent))
     226    {
     227      $query.= "
     228  SET uppercats = CONCAT('".$parent['uppercats']."',',',id)
     229  WHERE id_uppercat = ".$parent['id'];
    187230    }
    188231    else
    189232    {
    190       $query.= 'id';
    191     }
    192     $query.= '
    193   WHERE id_uppercat ';
    194     if (!is_numeric($id_uppercat))
    195     {
    196       $query.= 'IS NULL';
    197     }
    198     else
    199     {
    200       $query.= '= '.$id_uppercat;
     233      $query.= '
     234  SET uppercats = id
     235  WHERE id_uppercat IS NULL';
    201236    }
    202237    $query.= '
Note: See TracChangeset for help on using the changeset viewer.