diff options
-rw-r--r-- | admin.php | 14 | ||||
-rw-r--r-- | admin/cat_options.php | 270 | ||||
-rw-r--r-- | admin/include/functions.php | 21 | ||||
-rw-r--r-- | admin/include/functions_metadata.php | 2 | ||||
-rw-r--r-- | admin/update.php | 55 | ||||
-rw-r--r-- | category.php | 26 | ||||
-rw-r--r-- | include/functions_category.inc.php | 197 | ||||
-rw-r--r-- | include/functions_html.inc.php | 86 | ||||
-rw-r--r-- | install/dbscheme.txt | 1 | ||||
-rw-r--r-- | install/phpwebgallery_structure.sql | 1 | ||||
-rw-r--r-- | language/en_UK.iso-8859-1/admin.lang.php | 24 | ||||
-rw-r--r-- | search.php | 22 | ||||
-rw-r--r-- | template/default/admin.tpl | 4 | ||||
-rw-r--r-- | template/default/admin/cat_options.tpl | 83 | ||||
-rw-r--r-- | template/default/admin/user_perm.tpl | 10 | ||||
-rw-r--r-- | template/default/category.tpl | 2 |
16 files changed, 346 insertions, 472 deletions
@@ -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 '<pre>'; // print_r($_POST); // print '</pre>'; -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 */ @@ -71,6 +72,35 @@ UPDATE '.CATEGORIES_TABLE.' ;'; 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); + } } function insert_local_category($id_uppercat) @@ -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 = ' + <ul class="menu">'; + + foreach ($categories as $category) + { + $level = substr_count($category['global_rank'], '.'); + if ($level > $ref_level) + { + $menu.= ' + <ul class="menu">'; + } + else if ($level < $ref_level) + { + $menu.= ' + </ul>'; + } + $ref_level = $level; + + $menu.= ' <li>'; - $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']); + $url = add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']); - $class = ''; - if (isset($page['cat']) - and is_numeric($page['cat']) - and $category['id'] == $page['cat']) - { - $class = 'menuCategorySelected'; - } - else - { - $class = 'menuCategoryNotSelected'; - } - - $name = $category['name']; - if (empty($name)) - { - $name = str_replace('_', ' ', $category['dir']); - } + $class = ''; + if (isset($page['cat']) + and is_numeric($page['cat']) + and $category['id'] == $page['cat']) + { + $class = 'menuCategorySelected'; + } + else + { + $class = 'menuCategoryNotSelected'; + } - $menu.= ' + $menu.= ' <a href="'.$url.'" title="'.$lang['hint_category'].'" class="'.$class.'"> - '.$name.' + '.$category['name'].' </a>'; - if ($category['nb_images'] > 0) - { - $menu.= ' + if ($category['nb_images'] > 0) + { + $menu.= ' <span class="menuInfoCat" title="'.$category['nb_images'].' '.$lang['images_available'].'"> ['.$category['nb_images'].'] </span> '.get_icon($category['date_last']); + } + + $menu.= '</li>'; } - // recursive call - if ($category['expanded'] and count($category['subcats']) > 0) - { - $menu.= ' - <ul class="menu">'; - foreach ($category['subcats'] as $subcat) - { - $menu.= get_html_menu_category($subcat); - } - $menu.= ' + $menu.= ' </ul>'; - } - - $menu.= '</li>'; - + return $menu; } diff --git a/install/dbscheme.txt b/install/dbscheme.txt index 654ccbc28..9aae6234c 100644 --- a/install/dbscheme.txt +++ b/install/dbscheme.txt @@ -31,6 +31,7 @@ column:uploadable table:categories type:enum('true','false') column:representative_picture_id table:categories type:mediumint nullable:Y length:8 signed:N column:uppercats table:categories type:varchar nullable:N length:255 binary:N column:commentable table:categories type:enum('true','false') nullable:N +column:global_rank table:categories type:varchar nullable:Y length:255 binary:N column:id table:comments type:int nullable:N length:11 signed:N column:image_id table:comments type:mediumint nullable:N length:8 signed:N column:date table:comments type:datetime nullable:N diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql index d24d7d023..f3f6cf863 100644 --- a/install/phpwebgallery_structure.sql +++ b/install/phpwebgallery_structure.sql @@ -25,6 +25,7 @@ CREATE TABLE phpwebgallery_categories ( representative_picture_id mediumint(8) unsigned default NULL, uppercats varchar(255) NOT NULL default '', commentable enum('true','false') NOT NULL default 'true', + global_rank varchar(255) default NULL, PRIMARY KEY (id), KEY categories_i2 (id_uppercat) ) TYPE=MyISAM; diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php index e57ec8d02..9e1242647 100644 --- a/language/en_UK.iso-8859-1/admin.lang.php +++ b/language/en_UK.iso-8859-1/admin.lang.php @@ -326,18 +326,22 @@ $lang['cat_list_virtual_category_added'] = 'virtual category added'; $lang['cat_list_virtual_category_deleted'] = 'virtual category deleted'; $lang['cat_options_menu'] = 'Options'; -$lang['cat_options_menu_upload'] = 'upload'; -$lang['cat_options_menu_visible'] = 'lock'; -$lang['cat_options_menu_comments'] = 'comments'; -$lang['cat_options_menu_status'] = 'access'; -$lang['cat_options_upload_true'] = 'authorize upload'; -$lang['cat_options_upload_false'] = 'forbid upload'; +$lang['cat_options_upload_menu'] = 'Upload'; +$lang['cat_options_upload_title'] = 'upload authorization settings for categories'; +$lang['cat_options_visible_menu'] = 'Lock'; +$lang['cat_options_visible_title'] = 'temporary lock categories'; +$lang['cat_options_comments_menu'] = 'Comments'; +$lang['cat_options_comments_title'] = 'authorize comments for categories'; +$lang['cat_options_status_menu'] = 'Access'; +$lang['cat_options_status_title'] = 'make your category private or public'; +$lang['cat_options_upload_true'] = 'upload authorized'; +$lang['cat_options_upload_false'] = 'upload forbidden'; $lang['cat_options_upload_info'] = '(multi)select categories to make them uploadable or not. Upload is not applicable to virtual categories and to categories from a remote site.'; -$lang['cat_options_comments_true'] = 'authorize comments'; -$lang['cat_options_comments_false'] = 'forbid comments'; +$lang['cat_options_comments_true'] = 'comments authorized'; +$lang['cat_options_comments_false'] = 'comments forbidden'; $lang['cat_options_comments_info'] = '(multi)select categories to make them commentable or not. By inheritance, an element is commentable if it belongs at least to one commentable category.'; -$lang['cat_options_visible_true'] = 'unlock'; -$lang['cat_options_visible_false'] = 'lock temporary'; +$lang['cat_options_visible_true'] = 'unlocked'; +$lang['cat_options_visible_false'] = 'locked'; $lang['cat_options_visible_info'] = '(multi)select categories to lock or unlock them. If you lock category, all its child categories becomes locked. It you unlock a category, all its parent categories becomes unlocked'; $lang['cat_options_status_true'] = 'public'; $lang['cat_options_status_false'] = 'private'; diff --git a/search.php b/search.php index 5fb9c9b25..e38255308 100644 --- a/search.php +++ b/search.php @@ -338,22 +338,22 @@ foreach ($datefields as $datefield) display_3dates($datefield); } //------------------------------------------------------------- categories form -// this is a trick : normally, get_user_plain_structure is used to create -// the categories structure for menu (in category.php) display, but here, we -// want all categories to be shown... -$user['expand'] = true; -$structure = create_user_structure(''); - +$query = ' +SELECT name,id,date_last,nb_images,global_rank,uppercats + FROM '.CATEGORIES_TABLE; + if ($user['forbidden_categories'] != '') + { + $query.= ' + WHERE id NOT IN ('.$user['forbidden_categories'].')'; + } +$query.= ' +;'; $selecteds = array(); if (isset($_POST['submit'])) { $selecteds = $_POST['cat']; } -display_select_categories($structure, - ' ', - $selecteds, - 'category_option', - array()); +display_select_cat_wrapper($query, $selecteds, 'category_option', false); $categories_selected = ''; if (isset($_POST['categories-check'])) diff --git a/template/default/admin.tpl b/template/default/admin.tpl index e971f0f95..d21761883 100644 --- a/template/default/admin.tpl +++ b/template/default/admin.tpl @@ -38,7 +38,9 @@ <ul class="menu"> <li><a class="adminMenu" href="{U_CATEGORIES}">{L_MANAGE}</a></li> <li><a class="adminMenu" href="{U_UPLOAD}">{L_UPLOAD}</a></li> - <li><a class="adminMenu" href="{U_CAT_OPTIONS}">{L_CAT_OPTIONS}</a></li> + <li><a class="adminMenu" href="{U_COMMENTS}">{L_COMMENTS}</a></li> + <li><a class="adminMenu" href="{U_VISIBLE}">{L_VISIBLE}</a></li> + <li><a class="adminMenu" href="{U_STATUS}">{L_STATUS}</a></li> </ul> </div> <div class="titreMenu">{L_IMAGES}</div> diff --git a/template/default/admin/cat_options.tpl b/template/default/admin/cat_options.tpl index 148f72e0b..1a5f442ba 100644 --- a/template/default/admin/cat_options.tpl +++ b/template/default/admin/cat_options.tpl @@ -1,60 +1,43 @@ -<p class="confMenu"> - <a class="{UPLOAD_CLASS}" href="{U_UPLOAD}">{L_CAT_OPTIONS_MENU_UPLOAD}</a> - <a class="{COMMENTS_CLASS}" href="{U_COMMENTS}">{L_CAT_OPTIONS_MENU_COMMENTS}</a> - <a class="{VISIBLE_CLASS}" href="{U_VISIBLE}">{L_CAT_OPTIONS_MENU_VISIBLE}</a> - <a class="{STATUS_CLASS}" href="{U_STATUS}">{L_CAT_OPTIONS_MENU_STATUS}</a> -</p> +<table width="100%" align="center"> + <tr class="admin"> + <th colspan="2">{L_TITLE}</th> + </tr> +</table> <form action="{F_ACTION}" method="post"> - <select style="width:500px" multiple="multiple" name="cat[]" size="20"> - <!-- BEGIN category_option --> - <option class="{category_option.CLASS}" {category_option.SELECTED} value="{category_option.VALUE}">{category_option.OPTION}</option> - <!-- END category_option --> + <table> + <tr> + <td style="text-align:center;">{L_CAT_OPTIONS_TRUE}</td> + <td></td> + <td style="text-align:center;">{L_CAT_OPTIONS_FALSE}</td> + </tr> + <tr> + <td> + <select style="width:300px" multiple="multiple" name="cat_true[]" size="20"> + <!-- BEGIN category_option_true --> + <option class="{category_option_true.CLASS}" {category_option_true.SELECTED} value="{category_option_true.VALUE}">{category_option_true.OPTION}</option> + <!-- END category_option_true --> </select> + </td> + <td valign="middle"> + <input type="submit" value="→" name="falsify" style="font-size:15px;" class="bouton" /> + <br /> + <input type="submit" value="←" name="trueify" style="font-size:15px;" class="bouton" /> + </td> + <td> + <select style="width:300px" multiple="multiple" name="cat_false[]" size="20"> + <!-- BEGIN category_option_false --> + <option class="{category_option_false.CLASS}" {category_option_false.SELECTED} value="{category_option_false.VALUE}">{category_option_false.OPTION}</option> + <!-- END category_option_false --> + </select> + </td> + </tr> + </table> - <!-- BEGIN upload --> - <p>{L_CAT_OPTIONS_UPLOAD_INFO}</p> - <p> - <input type="radio" name="option" value="true"/> <span class="optionTrue">{L_CAT_OPTIONS_UPLOAD_TRUE}</span> - </p> - <p> - <input type="radio" name="option" value="false"/> <span class="optionFalse">{L_CAT_OPTIONS_UPLOAD_FALSE}</span> - </p> - <!-- END upload --> - - <!-- BEGIN comments --> - <p>{L_CAT_OPTIONS_COMMENTS_INFO}</p> - <p> - <input type="radio" name="option" value="true"/> <span class="optionTrue">{L_CAT_OPTIONS_COMMENTS_TRUE}</span> - </p> - <p> - <input type="radio" name="option" value="false"/> <span class="optionFalse">{L_CAT_OPTIONS_COMMENTS_FALSE}</span> - </p> - <!-- END comments --> - - <!-- BEGIN visible --> - <p>{L_CAT_OPTIONS_VISIBLE_INFO}</p> - <p> - <input type="radio" name="option" value="true"/> <span class="optionTrue">{L_CAT_OPTIONS_VISIBLE_TRUE}</span> - </p> - <p> - <input type="radio" name="option" value="false"/> <span class="optionFalse">{L_CAT_OPTIONS_VISIBLE_FALSE}</span> - </p> - <!-- END visible --> - - <!-- BEGIN status --> - <p>{L_CAT_OPTIONS_STATUS_INFO}</p> - <p> - <input type="radio" name="option" value="true"/> <span class="optionTrue">{L_CAT_OPTIONS_STATUS_TRUE}</span> - </p> - <p> - <input type="radio" name="option" value="false"/> <span class="optionFalse">{L_CAT_OPTIONS_STATUS_FALSE}</span> - </p> - <!-- END status --> + <p>{L_CAT_OPTIONS_INFO}</p> <p style="text-align:center;"> - <input type="submit" value="{L_SUBMIT}" name="submit" class="bouton" /> <input type="reset" name="reset" value="{L_RESET}" class="bouton" /> </p> diff --git a/template/default/admin/user_perm.tpl b/template/default/admin/user_perm.tpl index c55c85446..f6fa3ba2a 100644 --- a/template/default/admin/user_perm.tpl +++ b/template/default/admin/user_perm.tpl @@ -12,15 +12,17 @@ <form action="{F_AUTH_ACTION}" method="POST"> <ul class="menu"> <!-- BEGIN category --> - <li> <a href="{permission.category.CAT_URL}">{permission.category.CAT_NAME}</a> + <li> + <input type="radio" name="{permission.category.CAT_ID}" value="0" {permission.category.AUTH_YES}/>{L_AUTHORIZED} + <input type="radio" name="{permission.category.CAT_ID}" value="1" {permission.category.AUTH_NO}/>{L_FORBIDDEN} + : + <a href="{permission.category.CAT_URL}">{permission.category.CAT_NAME}</a> <!-- BEGIN parent_forbidden --> {L_PARENT_FORBIDDEN} - <!-- END parent_forbidden --> - <input type="radio" name="{permission.category.CAT_ID}" value="0" {permission.category.AUTH_YES}/>{L_AUTHORIZED} - <input type="radio" name="{permission.category.CAT_ID}" value="1" {permission.category.AUTH_NO}/>{L_FORBIDDEN} </li> <!-- END category --> </ul> <input type="submit" name="submit" class="bouton" value="{L_SUBMIT}"/> </form> -<!-- END permission -->
\ No newline at end of file +<!-- END permission --> diff --git a/template/default/category.tpl b/template/default/category.tpl index 9f554ad83..681d30102 100644 --- a/template/default/category.tpl +++ b/template/default/category.tpl @@ -7,9 +7,7 @@ <a href="{U_HOME}">{L_CATEGORIES}</a> </div> <div class="menu"> - <ul class="menu"> {MENU_CATEGORIES_CONTENT} - </ul> <div class="totalImages">[ {NB_PICTURE} {L_TOTAL} ]</div> </div> <div class="titreMenu">{L_SPECIAL_CATEGORIES}</div> |