From f0fcd1eedc26c0d36b6b0556b9f53124ba9f889f Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 23 Nov 2004 22:31:24 +0000 Subject: - global categories' options : instead of N horizontal tabs on a single page, N options in the left menu (but the same backend) - categories.global_rank : new calculated field. It gives a global rank of the category among all others (updated during ordering) - category.php page : menu is generated faster thanks to categories.global_rank, recursivity becomes useless :-) - new function to display select box with a set of categories : display_select_cat_wrapper - cat_options : instead of using 1 multiselect for true/false items, using 1 multiselect for true, and another one for false. The form provides buttons with arrows to switch categories from one multiselect to another - deletion of obsolete function display_categories (working with the old template system) - deletion of obsolete functions get_user_plain_structure, create_user_structure, get_user_subcat_ids, update_structure, count_images : useless thanks to global_rank git-svn-id: http://piwigo.org/svn/trunk@614 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin.php | 14 +- admin/cat_options.php | 270 +++++++++++++++---------------- admin/include/functions.php | 21 --- admin/include/functions_metadata.php | 2 +- admin/update.php | 55 +++++-- category.php | 26 +-- include/functions_category.inc.php | 197 ++++++---------------- include/functions_html.inc.php | 86 +++++----- install/dbscheme.txt | 1 + install/phpwebgallery_structure.sql | 1 + language/en_UK.iso-8859-1/admin.lang.php | 24 +-- search.php | 22 +-- template/default/admin.tpl | 4 +- template/default/admin/cat_options.tpl | 83 ++++------ template/default/admin/user_perm.tpl | 10 +- template/default/category.tpl | 2 - 16 files changed, 346 insertions(+), 472 deletions(-) diff --git a/admin.php b/admin.php index a18da82ee..4822e048b 100644 --- a/admin.php +++ b/admin.php @@ -166,6 +166,7 @@ if ( mysql_num_rows( $result ) > 0 ) $link_start = PHPWG_ROOT_PATH.'admin.php?page='; $conf_link = $link_start.'configuration&section='; +$opt_link = $link_start.'cat_options&section='; //----------------------------------------------------- template initialization include(PHPWG_ROOT_PATH.'include/page_header.php'); $template->set_filenames( array('admin'=>'admin.tpl') ); @@ -189,7 +190,6 @@ $template->assign_vars(array( 'L_SITES'=>$lang['remote_sites'], 'L_CATEGORIES'=>$lang['categories'], 'L_MANAGE'=>$lang['manage'], - 'L_UPLOAD'=>$lang['upload'], 'L_IMAGES'=>$lang['pictures'], 'L_WAITING'=>$lang['waiting'].$nb_waiting, 'L_COMMENTS'=>$lang['comments'].$nb_comments, @@ -199,8 +199,11 @@ $template->assign_vars(array( 'L_GROUPS'=>$lang['groups'], 'L_AUTH'=>$lang['permissions'], 'L_UPDATE'=>$lang['update'], - 'L_CAT_OPTIONS'=>$lang['cat_options_menu'], - + 'L_UPLOAD'=>$lang['cat_options_upload_menu'], + 'L_COMMENTS'=>$lang['cat_options_comments_menu'], + 'L_VISIBLE'=>$lang['cat_options_visible_menu'], + 'L_STATUS'=>$lang['cat_options_status_menu'], + 'U_CONFIG_GENERAL'=>add_session_id($conf_link.'general' ), 'U_CONFIG_COMMENTS'=>add_session_id($conf_link.'comments' ), 'U_CONFIG_DISPLAY'=>add_session_id($conf_link.'default' ), @@ -212,7 +215,10 @@ $template->assign_vars(array( 'U_USERS'=>add_session_id($link_start.'user_search' ), 'U_GROUPS'=>add_session_id($link_start.'group_list' ), 'U_CATEGORIES'=>add_session_id($link_start.'cat_list' ), - 'U_UPLOAD'=>add_session_id($link_start.'admin_upload' ), + 'U_UPLOAD'=>add_session_id($opt_link.'upload'), + 'U_COMMENTS'=>add_session_id($opt_link.'comments'), + 'U_VISIBLE'=>add_session_id($opt_link.'visible'), + 'U_STATUS'=>add_session_id($opt_link.'status'), 'U_WAITING'=>add_session_id($link_start.'waiting' ), 'U_COMMENTS'=>add_session_id($link_start.'comments' ), 'U_CAT_UPDATE'=>add_session_id($link_start.'update'), diff --git a/admin/cat_options.php b/admin/cat_options.php index cb518f7db..b62422961 100644 --- a/admin/cat_options.php +++ b/admin/cat_options.php @@ -36,7 +36,7 @@ include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); // print '
';
 // print_r($_POST);
 // print '
'; -if (isset($_POST['submit']) and count($_POST['cat']) > 0) +if (isset($_POST['falsify']) and count($_POST['cat_true']) > 0) { switch ($_GET['section']) { @@ -44,8 +44,8 @@ if (isset($_POST['submit']) and count($_POST['cat']) > 0) { $query = ' UPDATE '.CATEGORIES_TABLE.' - SET uploadable = \''.$_POST['option'].'\' - WHERE id IN ('.implode(',', $_POST['cat']).') + SET uploadable = \'false\' + WHERE id IN ('.implode(',', $_POST['cat_true']).') ;'; pwg_query($query); break; @@ -54,8 +54,8 @@ UPDATE '.CATEGORIES_TABLE.' { $query = ' UPDATE '.CATEGORIES_TABLE.' - SET commentable = \''.$_POST['option'].'\' - WHERE id IN ('.implode(',', $_POST['cat']).') + SET commentable = \'false\' + WHERE id IN ('.implode(',', $_POST['cat_true']).') ;'; pwg_query($query); break; @@ -63,79 +63,101 @@ UPDATE '.CATEGORIES_TABLE.' case 'visible' : { // locking a category => all its child categories become locked - if ($_POST['option'] == 'false') - { - $subcats = get_subcat_ids($_POST['cat']); - $query = ' + $subcats = get_subcat_ids($_POST['cat_true']); + $query = ' UPDATE '.CATEGORIES_TABLE.' SET visible = \'false\' WHERE id IN ('.implode(',', $subcats).') ;'; - pwg_query($query); - } + pwg_query($query); + break; + } + case 'status' : + { + // make a category private => all its child categories become private + $subcats = get_subcat_ids($_POST['cat_true']); + $query = ' +UPDATE '.CATEGORIES_TABLE.' + SET status = \'private\' + WHERE id IN ('.implode(',', $subcats).') +;'; + pwg_query($query); + break; + } + } +} +else if (isset($_POST['trueify']) and count($_POST['cat_false']) > 0) +{ + switch ($_GET['section']) + { + case 'upload' : + { + $query = ' +UPDATE '.CATEGORIES_TABLE.' + SET uploadable = \'true\' + WHERE id IN ('.implode(',', $_POST['cat_false']).') +;'; + pwg_query($query); + break; + } + case 'comments' : + { + $query = ' +UPDATE '.CATEGORIES_TABLE.' + SET commentable = \'true\' + WHERE id IN ('.implode(',', $_POST['cat_false']).') +;'; + pwg_query($query); + break; + } + case 'visible' : + { // unlocking a category => all its parent categories become unlocked - if ($_POST['option'] == 'true') - { - $uppercats = array(); - $query = ' + $uppercats = array(); + $query = ' SELECT uppercats FROM '.CATEGORIES_TABLE.' - WHERE id IN ('.implode(',', $_POST['cat']).') + WHERE id IN ('.implode(',', $_POST['cat_false']).') ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - $uppercats = array_merge($uppercats, - explode(',', $row['uppercats'])); - } - $uppercats = array_unique($uppercats); - - $query = ' + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $uppercats = array_merge($uppercats, + explode(',', $row['uppercats'])); + } + $uppercats = array_unique($uppercats); + + $query = ' UPDATE '.CATEGORIES_TABLE.' SET visible = \'true\' WHERE id IN ('.implode(',', $uppercats).') ;'; - pwg_query($query); - } + pwg_query($query); break; } case 'status' : { - // make a category private => all its child categories become private - if ($_POST['option'] == 'false') - { - $subcats = get_subcat_ids($_POST['cat']); - $query = ' -UPDATE '.CATEGORIES_TABLE.' - SET status = \'private\' - WHERE id IN ('.implode(',', $subcats).') -;'; - pwg_query($query); - } // make public a category => all its parent categories become public - if ($_POST['option'] == 'true') - { - $uppercats = array(); - $query = ' + $uppercats = array(); + $query = ' SELECT uppercats FROM '.CATEGORIES_TABLE.' - WHERE id IN ('.implode(',', $_POST['cat']).') + WHERE id IN ('.implode(',', $_POST['cat_false']).') ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - $uppercats = array_merge($uppercats, - explode(',', $row['uppercats'])); - } - $uppercats = array_unique($uppercats); - - $query = ' + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $uppercats = array_merge($uppercats, + explode(',', $row['uppercats'])); + } + $uppercats = array_unique($uppercats); + + $query = ' UPDATE '.CATEGORIES_TABLE.' SET status = \'public\' WHERE id IN ('.implode(',', $uppercats).') ;'; - pwg_query($query); - } + pwg_query($query); break; } } @@ -159,22 +181,6 @@ $template->assign_vars( array( 'L_SUBMIT'=>$lang['submit'], 'L_RESET'=>$lang['reset'], - 'L_CAT_OPTIONS_MENU_UPLOAD'=>$lang['cat_options_menu_upload'], - 'L_CAT_OPTIONS_MENU_VISIBLE'=>$lang['cat_options_menu_visible'], - 'L_CAT_OPTIONS_MENU_COMMENTS'=>$lang['cat_options_menu_comments'], - 'L_CAT_OPTIONS_MENU_STATUS'=>$lang['cat_options_menu_status'], - 'L_CAT_OPTIONS_UPLOAD_INFO'=>$lang['cat_options_upload_info'], - 'L_CAT_OPTIONS_UPLOAD_TRUE'=>$lang['cat_options_upload_true'], - 'L_CAT_OPTIONS_UPLOAD_FALSE'=>$lang['cat_options_upload_false'], - 'L_CAT_OPTIONS_COMMENTS_INFO'=>$lang['cat_options_comments_info'], - 'L_CAT_OPTIONS_COMMENTS_TRUE'=>$lang['cat_options_comments_true'], - 'L_CAT_OPTIONS_COMMENTS_FALSE'=>$lang['cat_options_comments_false'], - 'L_CAT_OPTIONS_VISIBLE_INFO'=>$lang['cat_options_visible_info'], - 'L_CAT_OPTIONS_VISIBLE_TRUE'=>$lang['cat_options_visible_true'], - 'L_CAT_OPTIONS_VISIBLE_FALSE'=>$lang['cat_options_visible_false'], - 'L_CAT_OPTIONS_STATUS_INFO'=>$lang['cat_options_status_info'], - 'L_CAT_OPTIONS_STATUS_TRUE'=>$lang['cat_options_status_true'], - 'L_CAT_OPTIONS_STATUS_FALSE'=>$lang['cat_options_status_false'], 'U_UPLOAD'=>add_session_id($base_url.'upload'), 'U_VISIBLE'=>add_session_id($base_url.'visible'), @@ -205,127 +211,103 @@ switch ($page['section']) { case 'upload' : { - $query = ' -SELECT id + $query_true = ' +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' WHERE uploadable = \'true\' AND dir IS NOT NULL AND site_id = 1 ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($cats_true, $row['id']); - } - $query = ' -SELECT id + $query_false = ' +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' WHERE uploadable = \'false\' AND dir IS NOT NULL AND site_id = 1 ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($cats_false, $row['id']); - } - + $template->assign_vars( + array( + 'L_TITLE' => $lang['cat_options_upload_title'], + 'L_CAT_OPTIONS_TRUE' => $lang['cat_options_upload_true'], + 'L_CAT_OPTIONS_FALSE' => $lang['cat_options_upload_false'], + 'L_CAT_OPTIONS_INFO' => $lang['cat_options_upload_info'], + ) + ); $template->assign_block_vars('upload', array()); - break; } case 'comments' : { - $query = ' -SELECT id + $query_true = ' +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' WHERE commentable = \'true\' ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($cats_true, $row['id']); - } - $query = ' -SELECT id + $query_false = ' +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' WHERE commentable = \'false\' ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($cats_false, $row['id']); - } - + $template->assign_vars( + array( + 'L_TITLE' => $lang['cat_options_comments_title'], + 'L_CAT_OPTIONS_TRUE' => $lang['cat_options_comments_true'], + 'L_CAT_OPTIONS_FALSE' => $lang['cat_options_comments_false'], + 'L_CAT_OPTIONS_INFO' => $lang['cat_options_comments_info'], + ) + ); $template->assign_block_vars('comments', array()); - break; } case 'visible' : { - $query = ' -SELECT id + $query_true = ' +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' WHERE visible = \'true\' ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($cats_true, $row['id']); - } - $query = ' -SELECT id + $query_false = ' +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' WHERE visible = \'false\' ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($cats_false, $row['id']); - } - + $template->assign_vars( + array( + 'L_TITLE' => $lang['cat_options_visible_title'], + 'L_CAT_OPTIONS_TRUE' => $lang['cat_options_visible_true'], + 'L_CAT_OPTIONS_FALSE' => $lang['cat_options_visible_false'], + 'L_CAT_OPTIONS_INFO' => $lang['cat_options_visible_info'], + ) + ); $template->assign_block_vars('visible', array()); - break; } case 'status' : { - $query = ' -SELECT id + $query_true = ' +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' WHERE status = \'public\' ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($cats_true, $row['id']); - } - $query = ' -SELECT id + $query_false = ' +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' WHERE status = \'private\' ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($cats_false, $row['id']); - } - + $template->assign_vars( + array( + 'L_TITLE' => $lang['cat_options_status_title'], + 'L_CAT_OPTIONS_TRUE' => $lang['cat_options_status_true'], + 'L_CAT_OPTIONS_FALSE' => $lang['cat_options_status_false'], + 'L_CAT_OPTIONS_INFO' => $lang['cat_options_status_info'], + ) + ); $template->assign_block_vars('status', array()); - break; } } -$CSS_classes = array('optionTrue'=>$cats_true, - 'optionFalse'=>$cats_false); - -$user['expand'] = true; -$structure = create_user_structure(''); -display_select_categories($structure, - ' ', - array(), - 'category_option', - $CSS_classes); +display_select_cat_wrapper($query_true,array(),'category_option_true'); +display_select_cat_wrapper($query_false,array(),'category_option_false'); // +-----------------------------------------------------------------------+ // | sending html code | // +-----------------------------------------------------------------------+ diff --git a/admin/include/functions.php b/admin/include/functions.php index 2b28f6784..c78df307e 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -580,27 +580,6 @@ function get_keywords( $keywords_string ) return array_unique( $keywords ); } -function display_categories( $categories, $indent, - $selected = -1, $forbidden = -1 ) -{ - global $vtp,$sub; - - foreach ( $categories as $category ) { - if ( $category['id'] != $forbidden ) - { - $vtp->addSession( $sub, 'associate_cat' ); - $vtp->setVar( $sub, 'associate_cat.value', $category['id'] ); - $content = $indent.'- '.$category['name']; - $vtp->setVar( $sub, 'associate_cat.content', $content ); - if ( $category['id'] == $selected ) - $vtp->setVar( $sub, 'associate_cat.selected', ' selected="selected"' ); - $vtp->closeSession( $sub, 'associate_cat' ); - display_categories( $category['subcats'], $indent.str_repeat(' ',3), - $selected, $forbidden ); - } - } -} - /** * returns an array with the ids of the restricted categories for the user * diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php index 3872718fa..0e11d4d10 100644 --- a/admin/include/functions_metadata.php +++ b/admin/include/functions_metadata.php @@ -40,7 +40,7 @@ function get_sync_iptc_data($file) { if (in_array($pwg_key, $datefields)) { - if ( preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches)) + if (preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches)) { $iptc[$pwg_key] = $matches[1].'-'.$matches[2].'-'.$matches[3]; } diff --git a/admin/update.php b/admin/update.php index 10813349e..ac364e465 100644 --- a/admin/update.php +++ b/admin/update.php @@ -37,12 +37,13 @@ define('CURRENT_DATE', date('Y-m-d')); // +-----------------------------------------------------------------------+ /** - * order categories (update categories.rank database field) + * order categories (update categories.rank and global_rank database fields) * * the purpose of this function is to give a rank for all categories * (insides its sub-category), even the newer that have none at te * beginning. For this, ordering function selects all categories ordered by - * rank ASC then name ASC for each uppercat. + * rank ASC then name ASC for each uppercat. It also updates the global rank + * which is able to order any two categorie in the whole tree * * @returns void */ @@ -68,6 +69,35 @@ SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat UPDATE '.CATEGORIES_TABLE.' SET rank = '.++$current_rank.' WHERE id = '.$row['id'].' +;'; + pwg_query($query); + } + // global rank update + $query = ' +UPDATE '.CATEGORIES_TABLE.' + SET global_rank = rank + WHERE id_uppercat IS NULL +;'; + pwg_query($query); + + $query = ' +SELECT DISTINCT(id_uppercat) + FROM '.CATEGORIES_TABLE.' + WHERE id_uppercat IS NOT NULL +;'; + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + $query = ' +SELECT global_rank + FROM '.CATEGORIES_TABLE.' + WHERE id = '.$row['id_uppercat'].' +;'; + list($uppercat_global_rank) = mysql_fetch_array(pwg_query($query)); + $query = ' +UPDATE '.CATEGORIES_TABLE.' + SET global_rank = CONCAT(\''.$uppercat_global_rank.'\', \'.\', rank) + WHERE id_uppercat = '.$row['id_uppercat'].' ;'; pwg_query($query); } @@ -571,23 +601,14 @@ if (!isset($_POST['submit'])) $template->assign_block_vars('introduction', array()); $query = ' -SELECT id +SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.' - WHERE site_id != 1 + WHERE site_id = 1 ;'; - $result = pwg_query($query); - while ($row = mysql_fetch_array($result)) - { - array_push($user['restrictions'], $row['id']); - } - $user['forbidden_categories'] = implode(',', $user['restrictions']); - $user['expand'] = true; - $structure = create_user_structure(''); - display_select_categories($structure, - ' ', - array(), - 'introduction.category_option', - array()); + display_select_cat_wrapper($query, + array(), + 'introduction.category_option', + false); } // +-----------------------------------------------------------------------+ // | synchronize files | diff --git a/category.php b/category.php index 0fe1ad2a8..1d9c75fe4 100644 --- a/category.php +++ b/category.php @@ -39,11 +39,14 @@ if ( isset( $_GET['act'] ) redirect( $url ); } //-------------------------------------------------- access authorization check -if ( isset( $_GET['cat'] ) ) check_cat_id( $_GET['cat'] ); +if (isset($_GET['cat'])) +{ + check_cat_id($_GET['cat']); +} check_login_authorization(); -if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) +if (isset($page['cat']) and is_numeric($page['cat'])) { - check_restrictions( $page['cat'] ); + check_restrictions($page['cat']); } //-------------------------------------------------------------- initialization // detection of the start picture to display @@ -90,14 +93,6 @@ if ( $user['expand'] ) { $page['tab_expand'] = array(); } - -// creating the structure of the categories (useful for displaying the menu) -// creating the plain structure : array of all the available categories and -// their relative informations, see the definition of the function -// get_user_plain_structure for further details. -$page['plain_structure'] = get_user_plain_structure(); -$page['structure'] = create_user_structure( '' ); -$page['structure'] = update_structure( $page['structure'] ); //----------------------------------------------------- template initialization // // Start output of page @@ -106,7 +101,6 @@ $title = $page['title']; include(PHPWG_ROOT_PATH.'include/page_header.php'); $template->set_filenames( array('category'=>'category.tpl') ); - //-------------------------------------------------------------- category title if ( !isset( $page['title'] ) ) { @@ -120,18 +114,12 @@ if ( isset( $page['cat_nb_images'] ) and $page['cat_nb_images'] > 0 ) $icon_recent = get_icon(date('Y-m-d')); -$page['menu'] = ''; -foreach ($page['structure'] as $category) -{ - $page['menu'].= get_html_menu_category($category); -} - $template->assign_vars(array( 'NB_PICTURE' => count_user_total_images(), 'TITLE' => $template_title, 'USERNAME' => $user['username'], 'TOP_NUMBER'=>$conf['top_number'], - 'MENU_CATEGORIES_CONTENT'=>$page['menu'], + 'MENU_CATEGORIES_CONTENT'=>get_categories_menu(), 'L_CATEGORIES' => $lang['categories'], 'L_HINT_CATEGORY' => $lang['hint_category'], diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index d46ddc104..f8682433d 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -116,15 +116,14 @@ function check_cat_id( $cat ) } } -function get_user_plain_structure() +function get_categories_menu() { global $page,$user; - $infos = array('name','id','date_last','nb_images','dir','id_uppercat', - 'rank','site_id','uppercats'); + $infos = array(''); $query = ' -SELECT '.implode(',', $infos).' +SELECT name,id,date_last,nb_images,global_rank FROM '.CATEGORIES_TABLE.' WHERE 1 = 1'; // stupid but permit using AND after it ! if (!$user['expand']) @@ -143,125 +142,17 @@ SELECT '.implode(',', $infos).' AND id NOT IN ('.$user['forbidden_categories'].')'; } $query.= ' - ORDER BY id_uppercat ASC, rank ASC ;'; - $plain_structure = array(); $result = pwg_query($query); + $cats = array(); while ($row = mysql_fetch_array($result)) { - $category = array(); - foreach ($infos as $info) - { - if ($info == 'uc.date_last') - { - if (empty($row['date_last'])) - { - $category['date_last'] = 0; - } - else - { - list($year,$month,$day) = explode('-', $row['date_last']); - $category['date_last'] = mktime(0,0,0,$month,$day,$year); - } - } - else if (isset($row[$info])) - { - $category[$info] = $row[$info]; - } - else - { - $category[$info] = ''; - } - } - $plain_structure[$row['id']] = $category; - } - - return $plain_structure; -} - -function create_user_structure( $id_uppercat ) -{ - global $page; - - if ( !isset( $page['plain_structure'] ) ) - $page['plain_structure'] = get_user_plain_structure(); - - $structure = array(); - $ids = get_user_subcat_ids( $id_uppercat ); - foreach ( $ids as $id ) { - $category = $page['plain_structure'][$id]; - $category['subcats'] = create_user_structure( $id ); - array_push( $structure, $category ); - } - return $structure; -} - -function get_user_subcat_ids( $id_uppercat ) -{ - global $page; - - $ids = array(); - foreach ( $page['plain_structure'] as $id => $category ) { - if ( $category['id_uppercat'] == $id_uppercat ) array_push( $ids, $id ); - else if ( count( $ids ) > 0 ) return $ids; - } - return $ids; -} - -// update_structure updates or add informations about each node of the -// structure : -// -// 1. should the category be expanded in the menu ? -// If the category has to be expanded (ie its id is in the -// $page['tab_expand'] or all the categories must be expanded by default), -// $category['expanded'] is set to true. -// -// 2. associated expand string -// in the menu, there is a expand string (used in the URL) to tell which -// categories must be expanded in the menu if this category is chosen -function update_structure( $categories ) -{ - global $page, $user; - - $updated_categories = array(); - - foreach ( $categories as $category ) { - // update the "expanded" key - if ( $user['expand'] - or in_array( $category['id'], $page['tab_expand'] ) ) - { - $category['expanded'] = true; - } - else - { - $category['expanded'] = false; - } - // recursive call - $category['subcats'] = update_structure( $category['subcats'] ); - // adding the updated category - array_push( $updated_categories, $category ); + array_push($cats, $row); } + usort($cats, 'global_rank_compare'); - return $updated_categories; -} - -// count_images returns the number of pictures contained in the given -// category represented by an array, in this array, we have (among other -// things) : -// $category['nb_images'] -> number of pictures in this category -// $category['subcats'] -> array of sub-categories -// count_images goes to the deepest sub-category to find the total number of -// pictures contained in the given given category -function count_images( $categories ) -{ - return count_user_total_images(); - $total = 0; - foreach ( $categories as $category ) { - $total+= $category['nb_images']; - $total+= count_images( $category['subcats'] ); - } - return $total; + return get_html_menu_category($cats); } function count_user_total_images() @@ -829,47 +720,54 @@ SELECT COUNT(1) AS count } function display_select_categories($categories, - $indent, $selecteds, $blockname, - $CSS_classes) + $fullname = true) { - global $template,$user; + global $template; foreach ($categories as $category) { - if (!in_array($category['id'], $user['restrictions'])) + $selected = ''; + if (in_array($category['id'], $selecteds)) { - $selected = ''; - if (in_array($category['id'], $selecteds)) - { - $selected = ' selected="selected"'; - } - - $class = ''; - foreach (array_keys($CSS_classes) as $CSS_class) - { - if (in_array($category['id'], $CSS_classes[$CSS_class])) - { - $class = $CSS_class; - } - } + $selected = ' selected="selected"'; + } - $template->assign_block_vars( - $blockname, - array('SELECTED'=>$selected, - 'VALUE'=>$category['id'], - 'CLASS'=>$class, - 'OPTION'=>$indent.'- '.$category['name'] - )); - - display_select_categories($category['subcats'], - $indent.str_repeat(' ',3), - $selecteds, - $blockname, - $CSS_classes); + if ($fullname) + { + $option = get_cat_display_name_cache($category['uppercats'], + ' → ', + '', + false); + } + else + { + $option = str_repeat(' ', + (3 * substr_count($category['global_rank'], '.'))); + $option.= '- '.$category['name']; } + + $template->assign_block_vars( + $blockname, + array('SELECTED'=>$selected, + 'VALUE'=>$category['id'], + 'OPTION'=>$option + )); + } +} + +function display_select_cat_wrapper($query, $selecteds, $blockname, + $fullname = true) +{ + $result = pwg_query($query); + $categories = array(); + while ($row = mysql_fetch_array($result)) + { + array_push($categories, $row); } + usort($categories, 'global_rank_compare'); + display_select_categories($categories, $selecteds, $blockname, $fullname); } /** @@ -904,4 +802,9 @@ SELECT DISTINCT(id) } return $subcats; } + +function global_rank_compare($a, $b) +{ + return strnatcasecmp($a['global_rank'], $b['global_rank']); +} ?> diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index ccf6c7435..f1a8610db 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -211,7 +211,7 @@ function get_cat_display_name($cat_informations, * @return string */ function get_cat_display_name_cache($uppercats, - $separator, + $separator, $url = 'category.php?cat=', $replace_space = true) { @@ -271,72 +271,76 @@ SELECT id,name * * HTML code generated uses logical list tags ul and each category is an * item li. The paramter given is the category informations as an array, - * used keys are : id, name, dir, nb_images, date_last, subcats (sub-array) + * used keys are : id, name, nb_images, date_last * - * @param array category + * @param array categories * @return string */ -function get_html_menu_category($category) +function get_html_menu_category($categories) { global $page, $lang; + $ref_level = 0; $menu = ' +