aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2003-09-11 21:54:04 +0000
committerz0rglub <z0rglub@piwigo.org>2003-09-11 21:54:04 +0000
commit2bea069d54d190eaad4ed7c6cd9b594e6009ebbc (patch)
treea1e3294419f3042e6444c8112aada4c0553b5eb8 /admin
parentc2fe5824a6404ed4936bb66013c79ee40c4a72ff (diff)
- Bug correction : when adding a new category, the program enters an
infinite loop -> we have to refresh the $page['plain_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 git-svn-id: http://piwigo.org/svn/trunk@88 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r--admin/update.php40
1 files changed, 21 insertions, 19 deletions
diff --git a/admin/update.php b/admin/update.php
index d11415311..1a042256c 100644
--- a/admin/update.php
+++ b/admin/update.php
@@ -21,7 +21,7 @@ include_once( './include/isadmin.inc.php' );
//------------------------------------------------------------------- functions
function insert_local_category( $cat_id )
{
- global $conf, $page, $user;
+ global $conf, $page, $user, $lang;
$site_id = 1;
@@ -70,52 +70,54 @@ function insert_local_category( $cat_id )
if ( !is_dir( $rep ) ) delete_category( $row['id'] );
}
// 4. retrieving the sub-directories
- $sub_rep = array();
- $i = 0;
+ $subdirs = array();
$dirs = '';
- if ( $opendir = opendir ( $cat_directory ) )
+ if ( $opendir = opendir( $cat_directory ) )
{
- while ( $file = readdir ( $opendir ) )
+ while ( $file = readdir( $opendir ) )
{
if ( $file != '.'
and $file != '..'
and is_dir ( $cat_directory.'/'.$file )
and $file != 'thumbnail' )
{
- $sub_rep[$i++] = $file;
+ if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $file ) )
+ array_push( $subdirs, $file );
+ else
+ {
+ $output.= '<span style="color:red;">"'.$file.'" : ';
+ $output.= $lang['update_wrong_dirname'].'</span><br />';
+ }
}
}
}
- for ( $i = 0; $i < sizeof( $sub_rep ); $i++ )
- {
+ foreach ( $subdirs as $subdir ) {
// 5. Is the category already existing ? we create a subcat if not
// existing
$category_id = '';
$query = 'SELECT id';
$query.= ' FROM '.PREFIX_TABLE.'categories';
$query.= ' WHERE site_id = '.$site_id;
- $query.= " AND dir = '".$sub_rep[$i]."'";
- if ( !is_numeric( $cat_id ) )
- {
- $query.= ' AND id_uppercat IS NULL';
- }
- else
- {
- $query.= ' AND id_uppercat = '.$cat_id;
- }
+ $query.= " AND dir = '".$subdir."'";
+ $query.= ' AND id_uppercat';
+ if ( !is_numeric( $cat_id ) ) $query.= ' IS NULL';
+ else $query.= ' = '.$cat_id;
$query.= ';';
$result = mysql_query( $query );
if ( mysql_num_rows( $result ) == 0 )
{
+ $name = str_replace( '_', ' ', $subdir );
// we have to create the category
$query = 'INSERT INTO '.PREFIX_TABLE.'categories';
- $query.= ' (dir,site_id,id_uppercat) VALUES';
- $query.= " ('".$sub_rep[$i]."','".$site_id."'";
+ $query.= ' (dir,name,site_id,id_uppercat) VALUES';
+ $query.= " ('".$subdir."','".$name."','".$site_id."'";
if ( !is_numeric( $cat_id ) ) $query.= ',NULL';
else $query.= ",'".$cat_id."'";
$query.= ');';
mysql_query( $query );
$category_id = mysql_insert_id();
+ // regeneration of the plain_structure to integrate the new category
+ $page['plain_structure'] = get_plain_structure();
}
else
{