Changeset 88


Ignore:
Timestamp:
Sep 11, 2003, 11:54:04 PM (21 years ago)
Author:
z0rglub
Message:
  • Bug correction : when adding a new category, the program enters an infinite loop -> we have to refresh the $pageplain_structure for each new category added
  • Categories.name becomes not nullable, so a default name is given when a new category is added
  • If a directory doesn't correspond to the regular format [A-Za-z0-9-_.], an error message is displayed, and the category not added
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/update.php

    r81 r88  
    2222function insert_local_category( $cat_id )
    2323{
    24   global $conf, $page, $user;
     24  global $conf, $page, $user, $lang;
    2525               
    2626  $site_id = 1;
     
    7171  }
    7272  // 4. retrieving the sub-directories
    73   $sub_rep = array();
    74   $i = 0;
     73  $subdirs = array();
    7574  $dirs = '';
    76   if ( $opendir = opendir ( $cat_directory ) )
    77   {
    78     while ( $file = readdir ( $opendir ) )
     75  if ( $opendir = opendir( $cat_directory ) )
     76  {
     77    while ( $file = readdir( $opendir ) )
    7978    {
    8079      if ( $file != '.'
     
    8382           and $file != 'thumbnail' )
    8483      {
    85         $sub_rep[$i++] = $file;
     84        if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $file ) )
     85          array_push( $subdirs, $file );
     86        else
     87        {
     88          $output.= '<span style="color:red;">"'.$file.'" : ';
     89          $output.= $lang['update_wrong_dirname'].'</span><br />';
     90        }
    8691      }
    8792    }
    8893  }
    89   for ( $i = 0; $i < sizeof( $sub_rep ); $i++ )
    90   {
     94  foreach ( $subdirs as $subdir ) {
    9195    // 5. Is the category already existing ? we create a subcat if not
    9296    //    existing
     
    9599    $query.= ' FROM '.PREFIX_TABLE.'categories';
    96100    $query.= ' WHERE site_id = '.$site_id;
    97     $query.= " AND dir = '".$sub_rep[$i]."'";
    98     if ( !is_numeric( $cat_id ) )
    99     {
    100       $query.= ' AND id_uppercat IS NULL';
    101     }
    102     else
    103     {
    104       $query.= ' AND id_uppercat = '.$cat_id;
    105     }
     101    $query.= " AND dir = '".$subdir."'";
     102    $query.= ' AND id_uppercat';
     103    if ( !is_numeric( $cat_id ) ) $query.= ' IS NULL';
     104    else                          $query.= ' = '.$cat_id;
    106105    $query.= ';';
    107106    $result = mysql_query( $query );
    108107    if ( mysql_num_rows( $result ) == 0 )
    109108    {
     109      $name = str_replace( '_', ' ', $subdir );
    110110      // we have to create the category
    111111      $query = 'INSERT INTO '.PREFIX_TABLE.'categories';
    112       $query.= ' (dir,site_id,id_uppercat) VALUES';
    113       $query.= " ('".$sub_rep[$i]."','".$site_id."'";
     112      $query.= ' (dir,name,site_id,id_uppercat) VALUES';
     113      $query.= " ('".$subdir."','".$name."','".$site_id."'";
    114114      if ( !is_numeric( $cat_id ) ) $query.= ',NULL';
    115115      else                          $query.= ",'".$cat_id."'";
     
    117117      mysql_query( $query );
    118118      $category_id = mysql_insert_id();
     119      // regeneration of the plain_structure to integrate the new category
     120      $page['plain_structure'] = get_plain_structure();
    119121    }
    120122    else
Note: See TracChangeset for help on using the changeset viewer.