[21] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3046] | 5 | // | Copyright(C) 2008-2009 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 | |
---|
[4505] | 36 | if (!empty($_POST) or isset($_GET['delete'])) |
---|
| 37 | { |
---|
| 38 | check_pwg_token(); |
---|
| 39 | } |
---|
| 40 | |
---|
[1072] | 41 | // +-----------------------------------------------------------------------+ |
---|
[798] | 42 | // | functions | |
---|
| 43 | // +-----------------------------------------------------------------------+ |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * save the rank depending on given categories order |
---|
| 47 | * |
---|
| 48 | * The list of ordered categories id is supposed to be in the same parent |
---|
| 49 | * category |
---|
| 50 | * |
---|
| 51 | * @param array categories |
---|
| 52 | * @return void |
---|
| 53 | */ |
---|
| 54 | function save_categories_order($categories) |
---|
| 55 | { |
---|
| 56 | $current_rank = 0; |
---|
| 57 | $datas = array(); |
---|
| 58 | foreach ($categories as $id) |
---|
| 59 | { |
---|
| 60 | array_push($datas, array('id' => $id, 'rank' => ++$current_rank)); |
---|
| 61 | } |
---|
| 62 | $fields = array('primary' => array('id'), 'update' => array('rank')); |
---|
| 63 | mass_updates(CATEGORIES_TABLE, $fields, $datas); |
---|
| 64 | |
---|
[2306] | 65 | update_global_rank(); |
---|
[798] | 66 | } |
---|
| 67 | |
---|
| 68 | // +-----------------------------------------------------------------------+ |
---|
[580] | 69 | // | initialization | |
---|
| 70 | // +-----------------------------------------------------------------------+ |
---|
[834] | 71 | |
---|
[4495] | 72 | check_input_parameter('parent_id', @$_GET['parent_id'], false, PATTERN_ID); |
---|
| 73 | |
---|
[580] | 74 | $categories = array(); |
---|
[834] | 75 | |
---|
[2306] | 76 | $base_url = get_root_url().'admin.php?page=cat_list'; |
---|
| 77 | $navigation = '<a href="'.$base_url.'">'; |
---|
[2201] | 78 | $navigation.= l10n('home'); |
---|
[834] | 79 | $navigation.= '</a>'; |
---|
| 80 | |
---|
[580] | 81 | // +-----------------------------------------------------------------------+ |
---|
| 82 | // | virtual categories management | |
---|
| 83 | // +-----------------------------------------------------------------------+ |
---|
[1106] | 84 | // request to delete a virtual category / not for an adviser |
---|
| 85 | if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser()) |
---|
[68] | 86 | { |
---|
[659] | 87 | delete_categories(array($_GET['delete'])); |
---|
[2201] | 88 | array_push($page['infos'], l10n('cat_virtual_deleted')); |
---|
[659] | 89 | update_global_rank(); |
---|
[394] | 90 | } |
---|
[602] | 91 | // request to add a virtual category |
---|
[798] | 92 | else if (isset($_POST['submitAdd'])) |
---|
[394] | 93 | { |
---|
[1064] | 94 | $output_create = create_virtual_category( |
---|
| 95 | $_POST['virtual_name'], |
---|
| 96 | @$_GET['parent_id'] |
---|
| 97 | ); |
---|
| 98 | |
---|
| 99 | if (isset($output_create['error'])) |
---|
[580] | 100 | { |
---|
[1064] | 101 | array_push($page['errors'], $output_create['error']); |
---|
[580] | 102 | } |
---|
[1064] | 103 | else |
---|
[68] | 104 | { |
---|
[1064] | 105 | array_push($page['infos'], $output_create['info']); |
---|
[68] | 106 | } |
---|
| 107 | } |
---|
[1066] | 108 | // save manual category ordering |
---|
[798] | 109 | else if (isset($_POST['submitOrder'])) |
---|
| 110 | { |
---|
| 111 | asort($_POST['catOrd'], SORT_NUMERIC); |
---|
| 112 | save_categories_order(array_keys($_POST['catOrd'])); |
---|
[1066] | 113 | |
---|
| 114 | array_push( |
---|
| 115 | $page['infos'], |
---|
| 116 | l10n('Categories manual order was saved') |
---|
| 117 | ); |
---|
[798] | 118 | } |
---|
[1066] | 119 | // sort categories alpha-numerically |
---|
| 120 | else if (isset($_POST['submitOrderAlphaNum'])) |
---|
| 121 | { |
---|
| 122 | $query = ' |
---|
| 123 | SELECT id, name |
---|
| 124 | FROM '.CATEGORIES_TABLE.' |
---|
| 125 | WHERE id_uppercat '. |
---|
| 126 | (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).' |
---|
| 127 | ;'; |
---|
| 128 | $result = pwg_query($query); |
---|
| 129 | while ($row = mysql_fetch_assoc($result)) |
---|
| 130 | { |
---|
[1225] | 131 | $categories[ $row['id'] ] = strtolower($row['name']); |
---|
[1066] | 132 | } |
---|
| 133 | |
---|
| 134 | asort($categories, SORT_REGULAR); |
---|
| 135 | save_categories_order(array_keys($categories)); |
---|
| 136 | |
---|
| 137 | array_push( |
---|
| 138 | $page['infos'], |
---|
| 139 | l10n('Categories ordered alphanumerically') |
---|
| 140 | ); |
---|
| 141 | } |
---|
| 142 | |
---|
[580] | 143 | // +-----------------------------------------------------------------------+ |
---|
| 144 | // | Navigation path | |
---|
| 145 | // +-----------------------------------------------------------------------+ |
---|
[834] | 146 | |
---|
[394] | 147 | if (isset($_GET['parent_id'])) |
---|
| 148 | { |
---|
[642] | 149 | $navigation.= $conf['level_separator']; |
---|
[580] | 150 | |
---|
[1861] | 151 | $navigation.= get_cat_display_name_from_id( |
---|
| 152 | $_GET['parent_id'], |
---|
[1064] | 153 | $base_url.'&parent_id=', |
---|
| 154 | false |
---|
| 155 | ); |
---|
[394] | 156 | } |
---|
[580] | 157 | // +-----------------------------------------------------------------------+ |
---|
| 158 | // | template initialization | |
---|
| 159 | // +-----------------------------------------------------------------------+ |
---|
[2530] | 160 | $template->set_filename('categories', 'cat_list.tpl'); |
---|
[394] | 161 | |
---|
[635] | 162 | $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list'; |
---|
| 163 | if (isset($_GET['parent_id'])) |
---|
| 164 | { |
---|
| 165 | $form_action.= '&parent_id='.$_GET['parent_id']; |
---|
| 166 | } |
---|
| 167 | |
---|
[2223] | 168 | $template->assign(array( |
---|
[394] | 169 | 'CATEGORIES_NAV'=>$navigation, |
---|
[1004] | 170 | 'F_ACTION'=>$form_action, |
---|
[4505] | 171 | 'PWG_TOKEN' => get_pwg_token(), |
---|
[580] | 172 | )); |
---|
[1131] | 173 | |
---|
[580] | 174 | // +-----------------------------------------------------------------------+ |
---|
| 175 | // | Categories display | |
---|
| 176 | // +-----------------------------------------------------------------------+ |
---|
[647] | 177 | |
---|
[798] | 178 | $categories = array(); |
---|
| 179 | |
---|
| 180 | $query = ' |
---|
[2324] | 181 | SELECT id, name, permalink, dir, rank, status |
---|
[798] | 182 | FROM '.CATEGORIES_TABLE; |
---|
| 183 | if (!isset($_GET['parent_id'])) |
---|
| 184 | { |
---|
| 185 | $query.= ' |
---|
| 186 | WHERE id_uppercat IS NULL'; |
---|
| 187 | } |
---|
| 188 | else |
---|
| 189 | { |
---|
| 190 | $query.= ' |
---|
| 191 | WHERE id_uppercat = '.$_GET['parent_id']; |
---|
| 192 | } |
---|
| 193 | $query.= ' |
---|
| 194 | ORDER BY rank ASC |
---|
| 195 | ;'; |
---|
[2324] | 196 | $categories = hash_from_query($query, 'id'); |
---|
[798] | 197 | |
---|
[2324] | 198 | // get the categories containing images directly |
---|
| 199 | $categories_with_images = array(); |
---|
| 200 | if ( count($categories) ) |
---|
[580] | 201 | { |
---|
[647] | 202 | $query = ' |
---|
[2324] | 203 | SELECT DISTINCT category_id |
---|
| 204 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 205 | WHERE category_id IN ('.implode(',', array_keys($categories)).')'; |
---|
| 206 | $categories_with_images = array_flip( array_from_query($query, 'category_id') ); |
---|
[642] | 207 | } |
---|
| 208 | |
---|
[2223] | 209 | $template->assign('categories', array()); |
---|
[2324] | 210 | $base_url = get_root_url().'admin.php?page='; |
---|
[642] | 211 | foreach ($categories as $category) |
---|
| 212 | { |
---|
[580] | 213 | $cat_list_url = $base_url.'cat_list'; |
---|
[1131] | 214 | |
---|
[580] | 215 | $self_url = $cat_list_url; |
---|
[394] | 216 | if (isset($_GET['parent_id'])) |
---|
[580] | 217 | { |
---|
| 218 | $self_url.= '&parent_id='.$_GET['parent_id']; |
---|
| 219 | } |
---|
[394] | 220 | |
---|
[2223] | 221 | $tpl_cat = |
---|
[580] | 222 | array( |
---|
[2433] | 223 | 'NAME' => |
---|
| 224 | trigger_event( |
---|
| 225 | 'render_category_name', |
---|
| 226 | $category['name'], |
---|
| 227 | 'admin_cat_list' |
---|
| 228 | ), |
---|
[1082] | 229 | 'ID' => $category['id'], |
---|
| 230 | 'RANK' => $category['rank']*10, |
---|
[798] | 231 | |
---|
[1082] | 232 | 'U_JUMPTO' => make_index_url( |
---|
| 233 | array( |
---|
[1861] | 234 | 'category' => $category |
---|
[1082] | 235 | ) |
---|
| 236 | ), |
---|
[1131] | 237 | |
---|
| 238 | 'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'], |
---|
[1082] | 239 | 'U_EDIT' => $base_url.'cat_modify&cat_id='.$category['id'], |
---|
[2306] | 240 | |
---|
[2223] | 241 | 'IS_VIRTUAL' => empty($category['dir']) |
---|
[798] | 242 | ); |
---|
[1131] | 243 | |
---|
[798] | 244 | if (empty($category['dir'])) |
---|
[21] | 245 | { |
---|
[2223] | 246 | $tpl_cat['U_DELETE'] = $self_url.'&delete='.$category['id']; |
---|
[4505] | 247 | $tpl_cat['U_DELETE'].= '&pwg_token='.get_pwg_token(); |
---|
[21] | 248 | } |
---|
[1131] | 249 | |
---|
[2324] | 250 | if ( array_key_exists($category['id'], $categories_with_images) ) |
---|
[580] | 251 | { |
---|
[2223] | 252 | $tpl_cat['U_MANAGE_ELEMENTS']= |
---|
| 253 | $base_url.'element_set&cat='.$category['id']; |
---|
[21] | 254 | } |
---|
[798] | 255 | |
---|
| 256 | if ('private' == $category['status']) |
---|
[394] | 257 | { |
---|
[2223] | 258 | $tpl_cat['U_MANAGE_PERMISSIONS']= |
---|
| 259 | $base_url.'cat_perm&cat='.$category['id']; |
---|
[394] | 260 | } |
---|
[2223] | 261 | $template->append('categories', $tpl_cat); |
---|
[21] | 262 | } |
---|
[580] | 263 | // +-----------------------------------------------------------------------+ |
---|
| 264 | // | sending html code | |
---|
| 265 | // +-----------------------------------------------------------------------+ |
---|
[394] | 266 | $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); |
---|
[362] | 267 | ?> |
---|