diff options
Diffstat (limited to 'admin/cat_list.php')
-rw-r--r-- | admin/cat_list.php | 111 |
1 files changed, 73 insertions, 38 deletions
diff --git a/admin/cat_list.php b/admin/cat_list.php index be359e5be..729fe845f 100644 --- a/admin/cat_list.php +++ b/admin/cat_list.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | Piwigo - a PHP based photo gallery | // +-----------------------------------------------------------------------+ -// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org | +// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | // +-----------------------------------------------------------------------+ @@ -78,7 +78,7 @@ function save_categories_order($categories) $current_rank++; } - array_push($datas, array('id' => $id, 'rank' => $current_rank)); + $datas[] = array('id' => $id, 'rank' => $current_rank); } $fields = array('primary' => array('id'), 'update' => array('rank')); mass_updates(CATEGORIES_TABLE, $fields, $datas); @@ -115,43 +115,42 @@ if (isset($_GET['delete']) and is_numeric($_GET['delete'])) delete_categories(array($_GET['delete'])); $_SESSION['page_infos'] = array(l10n('Virtual album deleted')); update_global_rank(); + invalidate_user_cache(); $redirect_url = get_root_url().'admin.php?page=cat_list'; if (isset($_GET['parent_id'])) { $redirect_url.= '&parent_id='.$_GET['parent_id']; - } + } redirect($redirect_url); } // request to add a virtual category -else if (isset($_POST['submitAdd'])) +elseif (isset($_POST['submitAdd'])) { $output_create = create_virtual_category( $_POST['virtual_name'], @$_GET['parent_id'] ); + invalidate_user_cache(); if (isset($output_create['error'])) { - array_push($page['errors'], $output_create['error']); + $page['errors'][] = $output_create['error']; } else { - array_push($page['infos'], $output_create['info']); + $page['infos'][] = $output_create['info']; } } // save manual category ordering -else if (isset($_POST['submitManualOrder'])) +elseif (isset($_POST['submitManualOrder'])) { asort($_POST['catOrd'], SORT_NUMERIC); save_categories_order(array_keys($_POST['catOrd'])); - array_push( - $page['infos'], - l10n('Album manual order was saved') - ); + $page['infos'][] = l10n('Album manual order was saved'); } -else if (isset($_POST['submitAutoOrder'])) +elseif (isset($_POST['submitAutoOrder'])) { $query = ' SELECT id @@ -178,17 +177,11 @@ SELECT id, name, id_uppercat $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { - array_push( - $categories, - array( - 'id' => $row['id'], - 'id_uppercat' => $row['id_uppercat'], - ) - ); - array_push( - $names, - $row['name'] + $categories[] = array( + 'id' => $row['id'], + 'id_uppercat' => $row['id_uppercat'], ); + $names[] = $row['name']; } array_multisort( @@ -199,10 +192,7 @@ SELECT id, name, id_uppercat ); save_categories_order($categories); - array_push( - $page['infos'], - l10n('Albums automatically sorted') - ); + $page['infos'][] = l10n('Albums automatically sorted'); } // +-----------------------------------------------------------------------+ @@ -215,8 +205,7 @@ if (isset($_GET['parent_id'])) $navigation.= get_cat_display_name_from_id( $_GET['parent_id'], - $base_url.'&parent_id=', - false + $base_url.'&parent_id=' ); } // +-----------------------------------------------------------------------+ @@ -262,17 +251,66 @@ $categories = hash_from_query($query, 'id'); // get the categories containing images directly $categories_with_images = array(); -if ( count($categories) ) +if (count($categories)) { $query = ' -SELECT DISTINCT category_id +SELECT + category_id, + COUNT(*) AS nb_photos FROM '.IMAGE_CATEGORY_TABLE.' - WHERE category_id IN ('.implode(',', array_keys($categories)).')'; - $categories_with_images = array_flip( array_from_query($query, 'category_id') ); + GROUP BY category_id +;'; + // WHERE category_id IN ('.implode(',', array_keys($categories)).') + + $nb_photos_in = query2array($query, 'category_id', 'nb_photos'); + + $query = ' +SELECT + id, + uppercats + FROM '.CATEGORIES_TABLE.' +;'; + $all_categories = query2array($query, 'id', 'uppercats'); + $subcats_of = array(); + + foreach (array_keys($categories) as $cat_id) + { + foreach ($all_categories as $id => $uppercats) + { + if (preg_match('/(^|,)'.$cat_id.',/', $uppercats)) + { + @$subcats_of[$cat_id][] = $id; + } + } + } + + $nb_sub_photos = array(); + foreach ($subcats_of as $cat_id => $subcat_ids) + { + $nb_photos = 0; + foreach ($subcat_ids as $id) + { + if (isset($nb_photos_in[$id])) + { + $nb_photos+= $nb_photos_in[$id]; + } + } + + $nb_sub_photos[$cat_id] = $nb_photos; + } } $template->assign('categories', array()); $base_url = get_root_url().'admin.php?page='; + +if (isset($_GET['parent_id'])) +{ + $template->assign( + 'PARENT_EDIT', + $base_url.'album-'.$_GET['parent_id'] + ); +} + foreach ($categories as $category) { $cat_list_url = $base_url.'cat_list'; @@ -291,6 +329,9 @@ foreach ($categories as $category) $category['name'], 'admin_cat_list' ), + 'NB_PHOTOS' => isset($nb_photos_in[$category['id']]) ? $nb_photos_in[$category['id']] : 0, + 'NB_SUB_PHOTOS' => isset($nb_sub_photos[$category['id']]) ? $nb_sub_photos[$category['id']] : 0, + 'NB_SUB_ALBUMS' => isset($subcats_of[$category['id']]) ? count($subcats_of[$category['id']]) : 0, 'ID' => $category['id'], 'RANK' => $category['rank']*10, @@ -319,12 +360,6 @@ foreach ($categories as $category) } } - if ( array_key_exists($category['id'], $categories_with_images) ) - { - $tpl_cat['U_MANAGE_ELEMENTS']= - $base_url.'batch_manager&cat='.$category['id']; - } - $template->append('categories', $tpl_cat); } |