From 391fac78a80c9317e764a13d742c88d8fe0866fc Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 12 Dec 2004 21:06:39 +0000 Subject: - 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 --- admin.php | 5 +- admin/cat_list.php | 135 ++++++++++++++++++++----------- admin/cat_modify.php | 3 +- admin/group_perm.php | 3 +- admin/include/functions.php | 2 +- admin/infos_images.php | 4 +- admin/picture_modify.php | 6 +- admin/remote_site.php | 80 ++++++++++++------ admin/update.php | 131 +++++++++++++++++++----------- admin/user_perm.php | 3 +- admin/user_search.php | 18 +++-- admin/waiting.php | 2 +- comments.php | 2 +- include/category_calendar.inc.php | 6 +- include/category_recent_cats.inc.php | 3 + include/config.inc.php | 37 +++++---- include/functions_category.inc.php | 2 - include/functions_html.inc.php | 11 ++- include/functions_xml.inc.php | 1 + language/en_UK.iso-8859-1/admin.lang.php | 1 + picture.php | 16 ++-- template/default/picture.tpl | 2 +- tools/create_listing_file.php | 2 +- upload.php | 2 +- 24 files changed, 299 insertions(+), 178 deletions(-) diff --git a/admin.php b/admin.php index 3a19def75..ebed49524 100644 --- a/admin.php +++ b/admin.php @@ -30,7 +30,6 @@ define('PHPWG_ROOT_PATH','./'); define('IN_ADMIN', true); include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' ); - //--------------------------------------- validating page and creation of title $page_valide = false; $title = ''; @@ -85,7 +84,7 @@ switch ( $_GET['page'] ) if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) { $result = get_cat_info( $page['cat'] ); - $name = get_cat_display_name( $result['name'],' > ', '' ); + $name = get_cat_display_name($result['name'], ''); $title.= ' "'.$name.'"'; } } @@ -202,7 +201,7 @@ $template->assign_vars(array( 'L_CAT_UPLOAD'=>$lang['upload'], 'L_CAT_COMMENTS'=>$lang['comments'], 'L_CAT_VISIBLE'=>$lang['lock'], - 'L_CAT_STATUS'=>$lang['permissions'], + 'L_CAT_STATUS'=>$lang['admin_menu_cat_status'], 'U_CONFIG_GENERAL'=>add_session_id($conf_link.'general' ), 'U_CONFIG_COMMENTS'=>add_session_id($conf_link.'comments' ), diff --git a/admin/cat_list.php b/admin/cat_list.php index 72862b484..d92575fe8 100644 --- a/admin/cat_list.php +++ b/admin/cat_list.php @@ -59,58 +59,88 @@ else if (isset($_POST['submit'])) if (!count($errors)) { - $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; - // As we don't create a virtual category every day, let's do (far) too - // much queries - - // we have then to add the virtual category - $query = ' -INSERT INTO '.CATEGORIES_TABLE.' - (name,id_uppercat,rank,site_id) - VALUES - (\''.$_POST['virtual_name'].'\','.$parent_id.','.$_POST['rank'].',NULL) -;'; - pwg_query($query); - - // And last we update the uppercats - $query = ' -SELECT MAX(id) - FROM '.CATEGORIES_TABLE.' -;'; - $my_id = array_pop(mysql_fetch_array(pwg_query($query))); + $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; if ($parent_id != 'NULL') { $query = ' -SELECT uppercats, global_rank +SELECT id,uppercats,global_rank,visible,status FROM '.CATEGORIES_TABLE.' WHERE id = '.$parent_id.' ;'; - $result = pwg_query($query); - $row = mysql_fetch_array($result); - - $parent_uppercats = $row['uppercats']; - $parent_global_rank = $row['global_rank']; + $row = mysql_fetch_array(pwg_query($query)); + $parent = array('id' => $row['id'], + 'uppercats' => $row['uppercats'], + 'visible' => $row['visible'], + 'status' => $row['status'], + 'global_rank' => $row['global_rank']); } - $query = ' -UPDATE '.CATEGORIES_TABLE.' -'; - if (!empty($parent_uppercats)) + $insert = array(); + $insert{'name'} = $_POST['virtual_name']; + $insert{'rank'} = $_POST['rank']; + $insert{'commentable'} = $conf['newcat_default_commentable']; + $insert{'uploadable'} = $conf['newcat_default_uploadable']; + + if (isset($parent)) { - $query.= " SET uppercats = CONCAT('".$parent_uppercats."',',',id)"; + $insert{'id_uppercat'} = $parent{'id'}; + // 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']) + { + $insert{'visible'} = 'false'; + } + else + { + $insert{'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']) + { + $insert{'status'} = 'private'; + } + else + { + $insert{'status'} = $conf['newcat_default_status']; + } } else { - $query.= ' SET uppercats = id'; + $insert{'visible'} = $conf['newcat_default_visible']; + $insert{'status'} = $conf['newcat_default_status']; } - if (!empty($parent_global_rank)) + + $inserts = array($insert); + + // we have then to add the virtual category + $dbfields = array('site_id','name','id_uppercat','rank','commentable', + 'uploadable','visible','status'); + mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts); + + // And last we update the uppercats + $query = ' +SELECT MAX(id) + FROM '.CATEGORIES_TABLE.' +;'; + $my_id = array_pop(mysql_fetch_array(pwg_query($query))); + + $query = ' +UPDATE '.CATEGORIES_TABLE; + if (isset($parent)) { - $query.= " , global_rank = CONCAT('".$parent_global_rank."','.',rank)"; + $query.= " + SET uppercats = CONCAT('".$parent['uppercats']."',',',id) + , global_rank = CONCAT('".$parent['global_rank']."','.',rank)"; } else { - $query.= ' , uppercats = id'; + $query.= ' + SET uppercats = id + , global_rank = id'; } $query.= ' WHERE id = '.$my_id.' @@ -142,23 +172,22 @@ $result = pwg_query($query); while ($row = mysql_fetch_assoc($result)) { $categories[$row['rank']] = $row; + $categories[$row['rank']]['nb_subcats'] = 0; } // +-----------------------------------------------------------------------+ // | Navigation path | // +-----------------------------------------------------------------------+ if (isset($_GET['parent_id'])) { - $separator = ' '; $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list'; $navigation = ''; $navigation.= $lang['home']; $navigation.= ''; - $navigation.= $separator; + $navigation.= $conf['level_separator']; $current_category = get_cat_info($_GET['parent_id']); $navigation.= get_cat_display_name($current_category['name'], - $separator, $base_url.'&parent_id=', false); } @@ -337,7 +366,25 @@ if (count($infos) != 0) // +-----------------------------------------------------------------------+ // | Categories display | // +-----------------------------------------------------------------------+ -while (list($id,$category) = each($categories)) +$ranks = array(); +foreach ($categories as $category) +{ + $ranks[$category['id']] = $category['rank']; +} + +$query = ' +SELECT id_uppercat, COUNT(*) AS nb_subcats + FROM '. CATEGORIES_TABLE.' + WHERE id_uppercat IN ('.implode(',', array_keys($ranks)).') + GROUP BY id_uppercat +;'; +$result = pwg_query($query); +while ($row = mysql_fetch_array($result)) +{ + $categories[$ranks[$row['id_uppercat']]]['nb_subcats'] = $row['nb_subcats']; +} + +foreach ($categories as $category) { $images_folder = PHPWG_ROOT_PATH.'template/'; $images_folder.= $user['template'].'/admin/images'; @@ -356,17 +403,7 @@ while (list($id,$category) = each($categories)) } else { - // (Gweltas) May be should we have to introduce a computed field in the - // table to avoid this query -> (z0rglub) no because the number of - // sub-categories depends on permissions - $query = ' -SELECT COUNT(id) AS nb_sub_cats - FROM '. CATEGORIES_TABLE.' - WHERE id_uppercat = '.$category['id'].' -;'; - $row = mysql_fetch_array(pwg_query($query)); - - if ($row['nb_sub_cats'] > 0) + if ($category['nb_subcats'] > 0) { $image_src = $images_folder.'/icon_subfolder.gif'; } diff --git a/admin/cat_modify.php b/admin/cat_modify.php index c230fcf94..26bd0de50 100644 --- a/admin/cat_modify.php +++ b/admin/cat_modify.php @@ -103,11 +103,10 @@ foreach (array('comment','dir','site_id') as $nullable) // Navigation path $url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&parent_id='; $navigation = ''; -$navigation.= $lang['home'].' '; +$navigation.= $lang['home'].''.$conf['level_separator']; $navigation.= get_cat_display_name_cache( $category['uppercats'], - ' ', $url); $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='.$_GET['cat_id']; diff --git a/admin/group_perm.php b/admin/group_perm.php index 9725eafab..c60ed7420 100644 --- a/admin/group_perm.php +++ b/admin/group_perm.php @@ -104,8 +104,7 @@ while ( $row = mysql_fetch_array( $result ) ) } // category name $cat_infos = get_cat_info( $row['id'] ); - $name = get_cat_display_name( $cat_infos['name'],' > ', - 'font-weight:bold;' ); + $name = get_cat_display_name($cat_infos['name']); $vtp->setVar( $sub, 'category.name', $name ); // any subcat forbidden for this group ? if ( $is_group_allowed == 2 ) diff --git a/admin/include/functions.php b/admin/include/functions.php index 467a498f6..1191f1f6f 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -788,7 +788,7 @@ function is_user_allowed( $category_id, $restrictions ) function get_category_directories( $basedir ) { $sub_dirs = array(); - + if ( $opendir = opendir( $basedir ) ) { while ( $file = readdir( $opendir ) ) diff --git a/admin/infos_images.php b/admin/infos_images.php index 9c055a830..ef02c91b7 100644 --- a/admin/infos_images.php +++ b/admin/infos_images.php @@ -248,9 +248,7 @@ if (isset($page['cat'])) // Navigation path $current_category = get_cat_info($_GET['cat_id']); $url = PHPWG_ROOT_PATH.'admin.php?page=infos_images&cat_id='; - $category_path = get_cat_display_name($current_category['name'], - '->', - $url); + $category_path = get_cat_display_name($current_category['name'], $url); $form_action = PHPWG_ROOT_PATH.'admin.php'; $form_action.= '?page=infos_images&cat_id='.$_GET['cat_id']; diff --git a/admin/picture_modify.php b/admin/picture_modify.php index 647fdede4..7f3677f97 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -162,10 +162,10 @@ $url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id']; $url_img .= '&cat='.$row['storage_category_id']; $date = isset($_POST['date_creation']) && empty($errors) ?$_POST['date_creation']:date_convert_back(@$row['date_creation']); - + +$url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='; $storage_category = get_cat_display_name_cache($row['uppercats'], - ' → ', - '', + $url, false); //----------------------------------------------------- template initialization $template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl')); diff --git a/admin/remote_site.php b/admin/remote_site.php index 6f0279f21..66d6d6a58 100644 --- a/admin/remote_site.php +++ b/admin/remote_site.php @@ -176,7 +176,7 @@ function update_remote_site($listing_file, $site_id) */ function insert_remote_category($xml_content, $site_id, $id_uppercat, $level) { - global $counts, $removes; + global $counts, $removes, $conf; $uppercats = ''; // 0. retrieving informations on the category to display @@ -184,15 +184,18 @@ function insert_remote_category($xml_content, $site_id, $id_uppercat, $level) if (is_numeric($id_uppercat)) { $query = ' -SELECT name,uppercats,dir +SELECT id,name,uppercats,dir,status,visible 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']); - $uppercats = $row['uppercats']; - $name = $row['name']; - insert_remote_element($xml_content, $id_uppercat); } @@ -224,6 +227,39 @@ SELECT name,uppercats,dir // 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 ($xml_dirs as $xml_dir) { // 5. Is the category already existing ? we create a subcat if not @@ -239,9 +275,13 @@ SELECT name,uppercats,dir $insert{'name'} = $name; $insert{'site_id'} = $site_id; $insert{'uppercats'} = 'undef'; - if (is_numeric($id_uppercat)) + $insert{'commentable'} = $conf['newcat_default_commentable']; + $insert{'uploadable'} = 'false'; + $insert{'status'} = $create_values{'status'}; + $insert{'visible'} = $create_values{'visible'}; + if (isset($parent)) { - $insert{'id_uppercat'} = $id_uppercat; + $insert{'id_uppercat'} = $parent['id']; } array_push($inserts, $insert); } @@ -251,31 +291,25 @@ SELECT name,uppercats,dir if (count($inserts) > 0) { // inserts all found categories - $dbfields = array('dir','name','site_id','uppercats','id_uppercat'); + $dbfields = array('dir','name','site_id','uppercats','id_uppercat', + 'commentable','uploadable','status','visible'); 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 = ".$id_uppercat; } else { - $query.= '= '.$id_uppercat; + $query.= ' + SET uppercats = id + WHERE id_uppercat IS NULL'; } $query.= ' ;'; 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 = '