[21] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[345] | 23 | |
---|
[580] | 24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
[394] | 25 | { |
---|
[580] | 26 | die('Hacking attempt!'); |
---|
[394] | 27 | } |
---|
[798] | 28 | |
---|
[1072] | 29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 30 | |
---|
[580] | 31 | // +-----------------------------------------------------------------------+ |
---|
[1072] | 32 | // | Check Access and exit when user status is not ok | |
---|
| 33 | // +-----------------------------------------------------------------------+ |
---|
| 34 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 35 | |
---|
[5933] | 36 | trigger_action('loc_begin_cat_list'); |
---|
| 37 | |
---|
[5195] | 38 | if (!empty($_POST) or isset($_GET['delete'])) |
---|
| 39 | { |
---|
| 40 | check_pwg_token(); |
---|
| 41 | } |
---|
| 42 | |
---|
[1072] | 43 | // +-----------------------------------------------------------------------+ |
---|
[798] | 44 | // | functions | |
---|
| 45 | // +-----------------------------------------------------------------------+ |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * save the rank depending on given categories order |
---|
| 49 | * |
---|
| 50 | * The list of ordered categories id is supposed to be in the same parent |
---|
| 51 | * category |
---|
| 52 | * |
---|
| 53 | * @param array categories |
---|
| 54 | * @return void |
---|
| 55 | */ |
---|
| 56 | function save_categories_order($categories) |
---|
| 57 | { |
---|
[6698] | 58 | $current_rank_for_id_uppercat = array(); |
---|
[798] | 59 | $current_rank = 0; |
---|
[6698] | 60 | |
---|
[798] | 61 | $datas = array(); |
---|
[6698] | 62 | foreach ($categories as $category) |
---|
[798] | 63 | { |
---|
[6698] | 64 | if (is_array($category)) |
---|
| 65 | { |
---|
| 66 | $id = $category['id']; |
---|
| 67 | $id_uppercat = $category['id_uppercat']; |
---|
| 68 | |
---|
| 69 | if (!isset($current_rank_for_id_uppercat[$id_uppercat])) |
---|
| 70 | { |
---|
| 71 | $current_rank_for_id_uppercat[$id_uppercat] = 0; |
---|
| 72 | } |
---|
| 73 | $current_rank = ++$current_rank_for_id_uppercat[$id_uppercat]; |
---|
| 74 | } |
---|
| 75 | else |
---|
| 76 | { |
---|
| 77 | $id = $category; |
---|
| 78 | $current_rank++; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | array_push($datas, array('id' => $id, 'rank' => $current_rank)); |
---|
[798] | 82 | } |
---|
| 83 | $fields = array('primary' => array('id'), 'update' => array('rank')); |
---|
| 84 | mass_updates(CATEGORIES_TABLE, $fields, $datas); |
---|
| 85 | |
---|
[2306] | 86 | update_global_rank(); |
---|
[798] | 87 | } |
---|
| 88 | |
---|
| 89 | // +-----------------------------------------------------------------------+ |
---|
[580] | 90 | // | initialization | |
---|
| 91 | // +-----------------------------------------------------------------------+ |
---|
[834] | 92 | |
---|
[5195] | 93 | check_input_parameter('parent_id', $_GET, false, PATTERN_ID); |
---|
| 94 | |
---|
[580] | 95 | $categories = array(); |
---|
[834] | 96 | |
---|
[2306] | 97 | $base_url = get_root_url().'admin.php?page=cat_list'; |
---|
| 98 | $navigation = '<a href="'.$base_url.'">'; |
---|
[5021] | 99 | $navigation.= l10n('Home'); |
---|
[834] | 100 | $navigation.= '</a>'; |
---|
| 101 | |
---|
[580] | 102 | // +-----------------------------------------------------------------------+ |
---|
| 103 | // | virtual categories management | |
---|
| 104 | // +-----------------------------------------------------------------------+ |
---|
[8131] | 105 | // request to delete a virtual category |
---|
[8126] | 106 | if (isset($_GET['delete']) and is_numeric($_GET['delete'])) |
---|
[68] | 107 | { |
---|
[659] | 108 | delete_categories(array($_GET['delete'])); |
---|
[8168] | 109 | $_SESSION['page_infos'] = array(l10n('Virtual album deleted')); |
---|
[659] | 110 | update_global_rank(); |
---|
[8168] | 111 | |
---|
| 112 | $redirect_url = get_root_url().'admin.php?page=cat_list'; |
---|
| 113 | if (isset($_GET['parent_id'])) |
---|
| 114 | { |
---|
| 115 | $redirect_url.= '&parent_id='.$_GET['parent_id']; |
---|
| 116 | } |
---|
| 117 | redirect($redirect_url); |
---|
[394] | 118 | } |
---|
[602] | 119 | // request to add a virtual category |
---|
[798] | 120 | else if (isset($_POST['submitAdd'])) |
---|
[394] | 121 | { |
---|
[1064] | 122 | $output_create = create_virtual_category( |
---|
| 123 | $_POST['virtual_name'], |
---|
| 124 | @$_GET['parent_id'] |
---|
| 125 | ); |
---|
| 126 | |
---|
| 127 | if (isset($output_create['error'])) |
---|
[580] | 128 | { |
---|
[1064] | 129 | array_push($page['errors'], $output_create['error']); |
---|
[580] | 130 | } |
---|
[1064] | 131 | else |
---|
[68] | 132 | { |
---|
[1064] | 133 | array_push($page['infos'], $output_create['info']); |
---|
[68] | 134 | } |
---|
| 135 | } |
---|
[1066] | 136 | // save manual category ordering |
---|
[798] | 137 | else if (isset($_POST['submitOrder'])) |
---|
| 138 | { |
---|
[6698] | 139 | if ('manual' == $_POST['order_type']) |
---|
| 140 | { |
---|
| 141 | asort($_POST['catOrd'], SORT_NUMERIC); |
---|
| 142 | save_categories_order(array_keys($_POST['catOrd'])); |
---|
[1066] | 143 | |
---|
[6698] | 144 | array_push( |
---|
| 145 | $page['infos'], |
---|
[6969] | 146 | l10n('Album manual order was saved') |
---|
[6698] | 147 | ); |
---|
| 148 | } |
---|
| 149 | else |
---|
| 150 | { |
---|
| 151 | $query = ' |
---|
| 152 | SELECT id |
---|
[1066] | 153 | FROM '.CATEGORIES_TABLE.' |
---|
| 154 | WHERE id_uppercat '. |
---|
| 155 | (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).' |
---|
| 156 | ;'; |
---|
[6698] | 157 | $category_ids = array_from_query($query, 'id'); |
---|
[1066] | 158 | |
---|
[6698] | 159 | if (isset($_POST['recursive'])) |
---|
| 160 | { |
---|
| 161 | $category_ids = get_subcat_ids($category_ids); |
---|
| 162 | } |
---|
[1066] | 163 | |
---|
[6698] | 164 | $categories = array(); |
---|
| 165 | $names = array(); |
---|
| 166 | $id_uppercats = array(); |
---|
| 167 | |
---|
| 168 | $query = ' |
---|
| 169 | SELECT id, name, id_uppercat |
---|
[5079] | 170 | FROM '.CATEGORIES_TABLE.' |
---|
[6698] | 171 | WHERE id IN ('.implode(',', $category_ids).') |
---|
[5079] | 172 | ;'; |
---|
[6698] | 173 | $result = pwg_query($query); |
---|
| 174 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 175 | { |
---|
| 176 | array_push( |
---|
| 177 | $categories, |
---|
| 178 | array( |
---|
| 179 | 'id' => $row['id'], |
---|
| 180 | 'id_uppercat' => $row['id_uppercat'], |
---|
| 181 | ) |
---|
| 182 | ); |
---|
| 183 | array_push( |
---|
| 184 | $names, |
---|
| 185 | $row['name'] |
---|
| 186 | ); |
---|
| 187 | } |
---|
[1066] | 188 | |
---|
[6698] | 189 | array_multisort( |
---|
| 190 | $names, |
---|
| 191 | SORT_REGULAR, |
---|
| 192 | 'asc' == $_POST['ascdesc'] ? SORT_ASC : SORT_DESC, |
---|
| 193 | $categories |
---|
| 194 | ); |
---|
| 195 | save_categories_order($categories); |
---|
[5079] | 196 | |
---|
[6698] | 197 | array_push( |
---|
| 198 | $page['infos'], |
---|
[6993] | 199 | l10n('Albums automatically sorted') |
---|
[6698] | 200 | ); |
---|
| 201 | } |
---|
[5079] | 202 | } |
---|
| 203 | |
---|
[580] | 204 | // +-----------------------------------------------------------------------+ |
---|
| 205 | // | Navigation path | |
---|
| 206 | // +-----------------------------------------------------------------------+ |
---|
[834] | 207 | |
---|
[394] | 208 | if (isset($_GET['parent_id'])) |
---|
| 209 | { |
---|
[642] | 210 | $navigation.= $conf['level_separator']; |
---|
[580] | 211 | |
---|
[1861] | 212 | $navigation.= get_cat_display_name_from_id( |
---|
| 213 | $_GET['parent_id'], |
---|
[1064] | 214 | $base_url.'&parent_id=', |
---|
| 215 | false |
---|
| 216 | ); |
---|
[394] | 217 | } |
---|
[580] | 218 | // +-----------------------------------------------------------------------+ |
---|
| 219 | // | template initialization | |
---|
| 220 | // +-----------------------------------------------------------------------+ |
---|
[2530] | 221 | $template->set_filename('categories', 'cat_list.tpl'); |
---|
[394] | 222 | |
---|
[635] | 223 | $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list'; |
---|
| 224 | if (isset($_GET['parent_id'])) |
---|
| 225 | { |
---|
| 226 | $form_action.= '&parent_id='.$_GET['parent_id']; |
---|
| 227 | } |
---|
| 228 | |
---|
[2223] | 229 | $template->assign(array( |
---|
[394] | 230 | 'CATEGORIES_NAV'=>$navigation, |
---|
[1004] | 231 | 'F_ACTION'=>$form_action, |
---|
[5195] | 232 | 'PWG_TOKEN' => get_pwg_token(), |
---|
[580] | 233 | )); |
---|
[1131] | 234 | |
---|
[580] | 235 | // +-----------------------------------------------------------------------+ |
---|
| 236 | // | Categories display | |
---|
| 237 | // +-----------------------------------------------------------------------+ |
---|
[647] | 238 | |
---|
[798] | 239 | $categories = array(); |
---|
| 240 | |
---|
| 241 | $query = ' |
---|
[2324] | 242 | SELECT id, name, permalink, dir, rank, status |
---|
[798] | 243 | FROM '.CATEGORIES_TABLE; |
---|
| 244 | if (!isset($_GET['parent_id'])) |
---|
| 245 | { |
---|
| 246 | $query.= ' |
---|
| 247 | WHERE id_uppercat IS NULL'; |
---|
| 248 | } |
---|
| 249 | else |
---|
| 250 | { |
---|
| 251 | $query.= ' |
---|
| 252 | WHERE id_uppercat = '.$_GET['parent_id']; |
---|
| 253 | } |
---|
| 254 | $query.= ' |
---|
| 255 | ORDER BY rank ASC |
---|
| 256 | ;'; |
---|
[2324] | 257 | $categories = hash_from_query($query, 'id'); |
---|
[798] | 258 | |
---|
[2324] | 259 | // get the categories containing images directly |
---|
| 260 | $categories_with_images = array(); |
---|
| 261 | if ( count($categories) ) |
---|
[580] | 262 | { |
---|
[647] | 263 | $query = ' |
---|
[2324] | 264 | SELECT DISTINCT category_id |
---|
| 265 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 266 | WHERE category_id IN ('.implode(',', array_keys($categories)).')'; |
---|
| 267 | $categories_with_images = array_flip( array_from_query($query, 'category_id') ); |
---|
[642] | 268 | } |
---|
| 269 | |
---|
[2223] | 270 | $template->assign('categories', array()); |
---|
[2324] | 271 | $base_url = get_root_url().'admin.php?page='; |
---|
[642] | 272 | foreach ($categories as $category) |
---|
| 273 | { |
---|
[580] | 274 | $cat_list_url = $base_url.'cat_list'; |
---|
[1131] | 275 | |
---|
[580] | 276 | $self_url = $cat_list_url; |
---|
[394] | 277 | if (isset($_GET['parent_id'])) |
---|
[580] | 278 | { |
---|
| 279 | $self_url.= '&parent_id='.$_GET['parent_id']; |
---|
| 280 | } |
---|
[394] | 281 | |
---|
[2223] | 282 | $tpl_cat = |
---|
[580] | 283 | array( |
---|
[2433] | 284 | 'NAME' => |
---|
| 285 | trigger_event( |
---|
| 286 | 'render_category_name', |
---|
| 287 | $category['name'], |
---|
| 288 | 'admin_cat_list' |
---|
| 289 | ), |
---|
[1082] | 290 | 'ID' => $category['id'], |
---|
| 291 | 'RANK' => $category['rank']*10, |
---|
[798] | 292 | |
---|
[1082] | 293 | 'U_JUMPTO' => make_index_url( |
---|
| 294 | array( |
---|
[1861] | 295 | 'category' => $category |
---|
[1082] | 296 | ) |
---|
| 297 | ), |
---|
[1131] | 298 | |
---|
| 299 | 'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'], |
---|
[1082] | 300 | 'U_EDIT' => $base_url.'cat_modify&cat_id='.$category['id'], |
---|
[2306] | 301 | |
---|
[2223] | 302 | 'IS_VIRTUAL' => empty($category['dir']) |
---|
[798] | 303 | ); |
---|
[1131] | 304 | |
---|
[798] | 305 | if (empty($category['dir'])) |
---|
[21] | 306 | { |
---|
[2223] | 307 | $tpl_cat['U_DELETE'] = $self_url.'&delete='.$category['id']; |
---|
[5195] | 308 | $tpl_cat['U_DELETE'].= '&pwg_token='.get_pwg_token(); |
---|
[21] | 309 | } |
---|
[11040] | 310 | else |
---|
| 311 | { |
---|
| 312 | if ($conf['enable_synchronization']) |
---|
| 313 | { |
---|
| 314 | $tpl_cat['U_SYNC'] = $base_url.'site_update&site=1&cat_id='.$category['id']; |
---|
| 315 | } |
---|
| 316 | } |
---|
[1131] | 317 | |
---|
[2324] | 318 | if ( array_key_exists($category['id'], $categories_with_images) ) |
---|
[580] | 319 | { |
---|
[2223] | 320 | $tpl_cat['U_MANAGE_ELEMENTS']= |
---|
[8417] | 321 | $base_url.'batch_manager&cat='.$category['id']; |
---|
[21] | 322 | } |
---|
[798] | 323 | |
---|
| 324 | if ('private' == $category['status']) |
---|
[394] | 325 | { |
---|
[2223] | 326 | $tpl_cat['U_MANAGE_PERMISSIONS']= |
---|
| 327 | $base_url.'cat_perm&cat='.$category['id']; |
---|
[394] | 328 | } |
---|
[2223] | 329 | $template->append('categories', $tpl_cat); |
---|
[21] | 330 | } |
---|
[5933] | 331 | |
---|
| 332 | trigger_action('loc_end_cat_list'); |
---|
| 333 | |
---|
[580] | 334 | // +-----------------------------------------------------------------------+ |
---|
| 335 | // | sending html code | |
---|
| 336 | // +-----------------------------------------------------------------------+ |
---|
[394] | 337 | $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); |
---|
[362] | 338 | ?> |
---|