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