diff options
author | plegall <plg@piwigo.org> | 2004-12-12 21:06:39 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2004-12-12 21:06:39 +0000 |
commit | 391fac78a80c9317e764a13d742c88d8fe0866fc (patch) | |
tree | 178c3f72dd0356c4c6ad05adae9d974dedbfa506 /admin/update.php | |
parent | 9037726f5a658dc156ef444f2d90271ee2102711 (diff) |
- in admin menu, status option for categories is not "permissions" but
"private or public" choice = different language item
- get_cat_display_name changed : use $conf['level_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
git-svn-id: http://piwigo.org/svn/trunk@642 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/update.php')
-rw-r--r-- | admin/update.php | 131 |
1 files changed, 83 insertions, 48 deletions
diff --git a/admin/update.php b/admin/update.php index e540065e2..b59f6e7b5 100644 --- a/admin/update.php +++ b/admin/update.php @@ -47,24 +47,30 @@ function insert_local_category($id_uppercat) $cat_directory = PHPWG_ROOT_PATH.'galleries'; if (is_numeric($id_uppercat)) { - $query = 'SELECT name,uppercats,dir FROM '.CATEGORIES_TABLE; - $query.= ' WHERE id = '.$id_uppercat; - $query.= ';'; - $row = mysql_fetch_array( pwg_query( $query)); - $uppercats = $row['uppercats']; - $name = $row['name']; - $dir = $row['dir']; + $query = ' +SELECT id,name,uppercats,dir,visible,status + FROM '.CATEGORIES_TABLE.' + WHERE id = '.$id_uppercat.' +;'; + $row = mysql_fetch_array(pwg_query($query)); + $parent = array('id' => $row['id'], + 'name' => $row['name'], + 'dir' => $row['dir'], + 'uppercats' => $row['uppercats'], + 'visible' => $row['visible'], + 'status' => $row['status']); - $upper_array = explode( ',', $uppercats); + $upper_array = explode( ',', $parent['uppercats']); $local_dir = ''; $database_dirs = array(); $query = ' -SELECT id,dir FROM '.CATEGORIES_TABLE.' - WHERE id IN ('.$uppercats.') +SELECT id,dir + FROM '.CATEGORIES_TABLE.' + WHERE id IN ('.$parent['uppercats'].') ;'; - $result = pwg_query( $query); + $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { $database_dirs[$row['id']] = $row['dir']; @@ -78,8 +84,8 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' // 1. display the category name to update $output = '<ul class="menu">'; - $output.= '<li><strong>'.$name.'</strong>'; - $output.= ' [ '.$dir.' ]'; + $output.= '<li><strong>'.$parent['name'].'</strong>'; + $output.= ' [ '.$parent['dir'].' ]'; $output.= '</li>'; // 2. we search pictures of the category only if the update is for all @@ -94,7 +100,8 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' $sub_category_dirs = array(); $query = ' -SELECT id,dir FROM '.CATEGORIES_TABLE.' +SELECT id,dir + FROM '.CATEGORIES_TABLE.' WHERE site_id = 1 '; if (!is_numeric($id_uppercat)) @@ -131,6 +138,39 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' // array of new categories to insert $inserts = array(); + + // calculate default value at category creation + $create_values = array(); + if (isset($parent)) + { + // at creation, must a category be visible or not ? Warning : if + // the parent category is invisible, the category is automatically + // create invisible. (invisible = locked) + if ('false' == $parent['visible']) + { + $create_values{'visible'} = 'false'; + } + else + { + $create_values{'visible'} = $conf['newcat_default_visible']; + } + // at creation, must a category be public or private ? Warning : + // if the parent category is private, the category is + // automatically create private. + if ('private' == $parent['status']) + { + $create_values{'status'} = 'private'; + } + else + { + $create_values{'status'} = $conf['newcat_default_status']; + } + } + else + { + $create_values{'visible'} = $conf['newcat_default_visible']; + $create_values{'status'} = $conf['newcat_default_status']; + } foreach ($fs_subdirs as $fs_subdir) { @@ -139,22 +179,27 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' $category_id = array_search($fs_subdir, $sub_category_dirs); if (!is_numeric($category_id)) { + $insert = array(); + if (preg_match('/^[a-zA-Z0-9-_.]+$/', $fs_subdir)) { $name = str_replace('_', ' ', $fs_subdir); - $value = "('".$fs_subdir."','".$name."',1"; - if (!is_numeric($id_uppercat)) - { - $value.= ',NULL'; - } - else + $insert{'dir'} = $fs_subdir; + $insert{'name'} = $name; + $insert{'site_id'} = 1; + $insert{'uppercats'} = 'undef'; + $insert{'commentable'} = $conf['newcat_default_commentable']; + $insert{'uploadable'} = $conf['newcat_default_uploadable']; + $insert{'status'} = $create_values{'status'}; + $insert{'visible'} = $create_values{'visible'}; + + if (isset($parent)) { - $value.= ','.$id_uppercat; + $insert{'id_uppercat'} = $parent['id']; } - $value.= ",'undef'"; - $value.= ')'; - array_push($inserts, $value); + + array_push($inserts, $insert); } else { @@ -167,37 +212,27 @@ SELECT id,dir FROM '.CATEGORIES_TABLE.' // we have to create the category if (count($inserts) > 0) { - $query = ' -INSERT INTO '.CATEGORIES_TABLE.' - (dir,name,site_id,id_uppercat,uppercats) VALUES -'; - $query.= implode(',', $inserts); - $query.= ' -;'; - pwg_query($query); - + $dbfields = array( + 'dir','name','site_id','id_uppercat','uppercats','commentable', + 'uploadable','visible','status' + ); + mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); + $counts['new_categories']+= count($inserts); // updating uppercats field $query = ' -UPDATE '.CATEGORIES_TABLE.' - SET uppercats = '; - if ($uppercats != '') - { - $query.= "CONCAT('".$uppercats."',',',id)"; - } - else - { - $query.= 'id'; - } - $query.= ' - WHERE id_uppercat '; - if (!is_numeric($id_uppercat)) +UPDATE '.CATEGORIES_TABLE; + if (isset($parent)) { - $query.= 'IS NULL'; + $query.= " + SET uppercats = CONCAT('".$parent['uppercats']."',',',id) + WHERE id_uppercat = ".$parent['id']; } else { - $query.= '= '.$id_uppercat; + $query.= ' + SET uppercats = id + WHERE id_uppercat IS NULL'; } $query.= ' ;'; |