[21] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 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 | // +-----------------------------------------------------------------------+ |
---|
[21] | 23 | |
---|
[632] | 24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
[403] | 25 | { |
---|
[632] | 26 | die('Hacking attempt!'); |
---|
[403] | 27 | } |
---|
[1072] | 28 | |
---|
[1895] | 29 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[1072] | 30 | |
---|
[12954] | 31 | |
---|
| 32 | // get_complete_dir returns the concatenation of get_site_url and |
---|
| 33 | // get_local_dir |
---|
| 34 | // Example : "pets > rex > 1_year_old" is on the the same site as the |
---|
| 35 | // Piwigo files and this category has 22 for identifier |
---|
| 36 | // get_complete_dir(22) returns "./galleries/pets/rex/1_year_old/" |
---|
| 37 | function get_complete_dir( $category_id ) |
---|
| 38 | { |
---|
| 39 | return get_site_url($category_id).get_local_dir($category_id); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | // get_local_dir returns an array with complete path without the site url |
---|
| 43 | // Example : "pets > rex > 1_year_old" is on the the same site as the |
---|
| 44 | // Piwigo files and this category has 22 for identifier |
---|
| 45 | // get_local_dir(22) returns "pets/rex/1_year_old/" |
---|
| 46 | function get_local_dir( $category_id ) |
---|
| 47 | { |
---|
| 48 | global $page; |
---|
| 49 | |
---|
| 50 | $uppercats = ''; |
---|
| 51 | $local_dir = ''; |
---|
| 52 | |
---|
| 53 | if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) ) |
---|
| 54 | { |
---|
| 55 | $uppercats = $page['plain_structure'][$category_id]['uppercats']; |
---|
| 56 | } |
---|
| 57 | else |
---|
| 58 | { |
---|
| 59 | $query = 'SELECT uppercats'; |
---|
| 60 | $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id; |
---|
| 61 | $query.= ';'; |
---|
| 62 | $row = pwg_db_fetch_assoc( pwg_query( $query ) ); |
---|
| 63 | $uppercats = $row['uppercats']; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | $upper_array = explode( ',', $uppercats ); |
---|
| 67 | |
---|
| 68 | $database_dirs = array(); |
---|
| 69 | $query = 'SELECT id,dir'; |
---|
| 70 | $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')'; |
---|
| 71 | $query.= ';'; |
---|
| 72 | $result = pwg_query( $query ); |
---|
| 73 | while( $row = pwg_db_fetch_assoc( $result ) ) |
---|
| 74 | { |
---|
| 75 | $database_dirs[$row['id']] = $row['dir']; |
---|
| 76 | } |
---|
| 77 | foreach ($upper_array as $id) |
---|
| 78 | { |
---|
| 79 | $local_dir.= $database_dirs[$id].'/'; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | return $local_dir; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | // retrieving the site url : "http://domain.com/gallery/" or |
---|
| 86 | // simply "./galleries/" |
---|
| 87 | function get_site_url($category_id) |
---|
| 88 | { |
---|
| 89 | global $page; |
---|
| 90 | |
---|
| 91 | $query = ' |
---|
| 92 | SELECT galleries_url |
---|
| 93 | FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c |
---|
| 94 | WHERE s.id = c.site_id |
---|
| 95 | AND c.id = '.$category_id.' |
---|
| 96 | ;'; |
---|
| 97 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 98 | return $row['galleries_url']; |
---|
| 99 | } |
---|
| 100 | |
---|
[1072] | 101 | // +-----------------------------------------------------------------------+ |
---|
| 102 | // | Check Access and exit when user status is not ok | |
---|
| 103 | // +-----------------------------------------------------------------------+ |
---|
| 104 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 105 | |
---|
[28587] | 106 | trigger_notify('loc_begin_cat_modify'); |
---|
[5933] | 107 | |
---|
[21] | 108 | //---------------------------------------------------------------- verification |
---|
[403] | 109 | if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) ) |
---|
[21] | 110 | { |
---|
[2490] | 111 | trigger_error( 'missing cat_id param', E_USER_ERROR); |
---|
[21] | 112 | } |
---|
[403] | 113 | |
---|
[21] | 114 | //--------------------------------------------------------- form criteria check |
---|
[825] | 115 | if (isset($_POST['submit'])) |
---|
[21] | 116 | { |
---|
[25019] | 117 | $data = array( |
---|
| 118 | 'id' => $_GET['cat_id'], |
---|
| 119 | 'name' => @$_POST['name'], |
---|
| 120 | 'comment' => |
---|
| 121 | $conf['allow_html_descriptions'] ? |
---|
| 122 | @$_POST['comment'] : strip_tags(@$_POST['comment']), |
---|
| 123 | ); |
---|
[12887] | 124 | |
---|
| 125 | if ($conf['activate_comments']) |
---|
| 126 | { |
---|
| 127 | $data['commentable'] = isset($_POST['commentable'])?$_POST['commentable']:'false'; |
---|
| 128 | } |
---|
[25019] | 129 | |
---|
| 130 | single_update( |
---|
[825] | 131 | CATEGORIES_TABLE, |
---|
[25019] | 132 | $data, |
---|
| 133 | array('id' => $data['id']) |
---|
[825] | 134 | ); |
---|
[29949] | 135 | if (isset($_POST['apply_commentable_on_sub'])) |
---|
[29265] | 136 | { |
---|
| 137 | $subcats = get_subcat_ids(array('id' => $data['id'])); |
---|
| 138 | $query = ' |
---|
| 139 | UPDATE '.CATEGORIES_TABLE.' |
---|
| 140 | SET commentable = \''.$data['commentable'].'\' |
---|
| 141 | WHERE id IN ('.implode(',', $subcats).') |
---|
| 142 | ;'; |
---|
| 143 | pwg_query($query); |
---|
| 144 | } |
---|
[1131] | 145 | |
---|
[2490] | 146 | // retrieve cat infos before continuing (following updates are expensive) |
---|
| 147 | $cat_info = get_cat_info($_GET['cat_id']); |
---|
[345] | 148 | |
---|
[29229] | 149 | if ($_POST['visible']=='true_sub') |
---|
[1500] | 150 | { |
---|
[29229] | 151 | set_cat_visible(array($_GET['cat_id']), true, true); |
---|
| 152 | } |
---|
| 153 | elseif ($cat_info['visible'] != get_boolean( $_POST['visible'] ) ) |
---|
| 154 | { |
---|
[2490] | 155 | set_cat_visible(array($_GET['cat_id']), $_POST['visible']); |
---|
[1500] | 156 | } |
---|
[2490] | 157 | |
---|
[12576] | 158 | // in case the use moves his album to the gallery root, we force |
---|
| 159 | // $_POST['parent'] from 0 to null to be compared with |
---|
| 160 | // $cat_info['id_uppercat'] |
---|
| 161 | if (empty($_POST['parent'])) |
---|
[1500] | 162 | { |
---|
[12576] | 163 | $_POST['parent'] = null; |
---|
| 164 | } |
---|
[12591] | 165 | |
---|
| 166 | // only move virtual albums |
---|
| 167 | if (empty($cat_info['dir']) and $cat_info['id_uppercat'] != $_POST['parent']) |
---|
[12576] | 168 | { |
---|
[2490] | 169 | move_categories( array($_GET['cat_id']), $_POST['parent'] ); |
---|
[1500] | 170 | } |
---|
| 171 | |
---|
[14506] | 172 | $_SESSION['page_infos'][] = l10n('Album updated successfully'); |
---|
| 173 | $redirect = true; |
---|
[21] | 174 | } |
---|
[2490] | 175 | elseif (isset($_POST['set_random_representant'])) |
---|
[633] | 176 | { |
---|
| 177 | set_random_representant(array($_GET['cat_id'])); |
---|
[14506] | 178 | $redirect = true; |
---|
[633] | 179 | } |
---|
[2490] | 180 | elseif (isset($_POST['delete_representant'])) |
---|
[809] | 181 | { |
---|
| 182 | $query = ' |
---|
| 183 | UPDATE '.CATEGORIES_TABLE.' |
---|
| 184 | SET representative_picture_id = NULL |
---|
| 185 | WHERE id = '.$_GET['cat_id'].' |
---|
| 186 | ;'; |
---|
| 187 | pwg_query($query); |
---|
[14506] | 188 | $redirect = true; |
---|
[809] | 189 | } |
---|
[1131] | 190 | |
---|
[14506] | 191 | if (isset($redirect)) |
---|
| 192 | { |
---|
| 193 | redirect($admin_album_base_url.'-properties'); |
---|
| 194 | } |
---|
| 195 | |
---|
[530] | 196 | // nullable fields |
---|
[809] | 197 | foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable) |
---|
[530] | 198 | { |
---|
| 199 | if (!isset($category[$nullable])) |
---|
| 200 | { |
---|
| 201 | $category[$nullable] = ''; |
---|
| 202 | } |
---|
| 203 | } |
---|
[345] | 204 | |
---|
[809] | 205 | $category['is_virtual'] = empty($category['dir']) ? true : false; |
---|
| 206 | |
---|
[2324] | 207 | $query = 'SELECT DISTINCT category_id |
---|
| 208 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 209 | WHERE category_id = '.$_GET['cat_id'].' |
---|
| 210 | LIMIT 1'; |
---|
| 211 | $result = pwg_query($query); |
---|
[4325] | 212 | $category['has_images'] = pwg_db_num_rows($result)>0 ? true : false; |
---|
[2223] | 213 | |
---|
[403] | 214 | // Navigation path |
---|
[834] | 215 | $navigation = get_cat_display_name_cache( |
---|
[635] | 216 | $category['uppercats'], |
---|
[13013] | 217 | get_root_url().'admin.php?page=album-' |
---|
[834] | 218 | ); |
---|
[345] | 219 | |
---|
[13013] | 220 | $form_action = $admin_album_base_url.'-properties'; |
---|
[403] | 221 | |
---|
| 222 | //----------------------------------------------------- template initialization |
---|
[13013] | 223 | $template->set_filename( 'album_properties', 'cat_modify.tpl'); |
---|
[809] | 224 | |
---|
[2286] | 225 | $base_url = get_root_url().'admin.php?page='; |
---|
[809] | 226 | $cat_list_url = $base_url.'cat_list'; |
---|
[1131] | 227 | |
---|
[809] | 228 | $self_url = $cat_list_url; |
---|
| 229 | if (!empty($category['id_uppercat'])) |
---|
| 230 | { |
---|
| 231 | $self_url.= '&parent_id='.$category['id_uppercat']; |
---|
| 232 | } |
---|
| 233 | |
---|
[2223] | 234 | $template->assign( |
---|
[1131] | 235 | array( |
---|
[1082] | 236 | 'CATEGORIES_NAV' => $navigation, |
---|
[2777] | 237 | 'CAT_ID' => $category['id'], |
---|
[2223] | 238 | 'CAT_NAME' => @htmlspecialchars($category['name']), |
---|
| 239 | 'CAT_COMMENT' => @htmlspecialchars($category['comment']), |
---|
[4385] | 240 | 'CAT_VISIBLE' => boolean_to_string($category['visible']), |
---|
[2223] | 241 | |
---|
[1082] | 242 | 'U_JUMPTO' => make_index_url( |
---|
| 243 | array( |
---|
[1861] | 244 | 'category' => $category |
---|
[1082] | 245 | ) |
---|
| 246 | ), |
---|
[1131] | 247 | |
---|
[25593] | 248 | 'U_ADD_PHOTOS_ALBUM' => $base_url.'photos_add&album='.$category['id'], |
---|
[1082] | 249 | 'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'], |
---|
[5920] | 250 | 'U_HELP' => get_root_url().'admin/popuphelp.php?page=cat_modify', |
---|
[1131] | 251 | |
---|
[1082] | 252 | 'F_ACTION' => $form_action, |
---|
| 253 | ) |
---|
| 254 | ); |
---|
[12887] | 255 | |
---|
| 256 | if ($conf['activate_comments']) |
---|
| 257 | { |
---|
| 258 | $template->assign('CAT_COMMENTABLE', boolean_to_string($category['commentable'])); |
---|
| 259 | } |
---|
[633] | 260 | |
---|
[6988] | 261 | // manage album elements link |
---|
[2324] | 262 | if ($category['has_images']) |
---|
[633] | 263 | { |
---|
[2517] | 264 | $template->assign( |
---|
| 265 | 'U_MANAGE_ELEMENTS', |
---|
[24834] | 266 | $base_url.'batch_manager&filter=album-'.$category['id'] |
---|
[2223] | 267 | ); |
---|
[13013] | 268 | |
---|
| 269 | $query = ' |
---|
| 270 | SELECT |
---|
| 271 | COUNT(image_id), |
---|
| 272 | MIN(DATE(date_available)), |
---|
| 273 | MAX(DATE(date_available)) |
---|
| 274 | FROM '.IMAGES_TABLE.' |
---|
| 275 | JOIN '.IMAGE_CATEGORY_TABLE.' ON image_id = id |
---|
| 276 | WHERE category_id = '.$category['id'].' |
---|
| 277 | ;'; |
---|
| 278 | list($image_count, $min_date, $max_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
| 279 | |
---|
| 280 | if ($min_date == $max_date) |
---|
| 281 | { |
---|
[25005] | 282 | $intro = l10n( |
---|
| 283 | 'This album contains %d photos, added on %s.', |
---|
[13013] | 284 | $image_count, |
---|
| 285 | format_date($min_date) |
---|
| 286 | ); |
---|
| 287 | } |
---|
| 288 | else |
---|
| 289 | { |
---|
[25005] | 290 | $intro = l10n( |
---|
| 291 | 'This album contains %d photos, added between %s and %s.', |
---|
[13013] | 292 | $image_count, |
---|
| 293 | format_date($min_date), |
---|
| 294 | format_date($max_date) |
---|
| 295 | ); |
---|
| 296 | } |
---|
[2223] | 297 | } |
---|
[13013] | 298 | else |
---|
| 299 | { |
---|
| 300 | $intro = l10n('This album contains no photo.'); |
---|
| 301 | } |
---|
[2223] | 302 | |
---|
[25005] | 303 | $intro.= '<br>'.l10n('Numeric identifier : %d', $category['id']); |
---|
[14990] | 304 | |
---|
[28533] | 305 | $template->assign(array( |
---|
| 306 | 'INTRO' => $intro, |
---|
| 307 | 'U_MANAGE_RANKS' => $base_url.'element_set_ranks&cat_id='.$category['id'], |
---|
| 308 | 'CACHE_KEYS' => get_admin_client_cache_keys(array('categories')), |
---|
| 309 | )); |
---|
[13013] | 310 | |
---|
[2223] | 311 | if ($category['is_virtual']) |
---|
| 312 | { |
---|
| 313 | $template->assign( |
---|
[809] | 314 | array( |
---|
[5335] | 315 | 'U_DELETE' => $self_url.'&delete='.$category['id'].'&pwg_token='.get_pwg_token(), |
---|
[809] | 316 | ) |
---|
| 317 | ); |
---|
| 318 | } |
---|
[2223] | 319 | else |
---|
[1500] | 320 | { |
---|
[2223] | 321 | $category['cat_full_dir'] = get_complete_dir($_GET['cat_id']); |
---|
| 322 | $template->assign( |
---|
| 323 | array( |
---|
[13013] | 324 | 'CAT_FULL_DIR' => preg_replace('/\/$/', '', $category['cat_full_dir']) |
---|
[2223] | 325 | ) |
---|
| 326 | ); |
---|
[11041] | 327 | |
---|
| 328 | if ($conf['enable_synchronization']) |
---|
| 329 | { |
---|
| 330 | $template->assign( |
---|
| 331 | 'U_SYNC', |
---|
| 332 | $base_url.'site_update&site=1&cat_id='.$category['id'] |
---|
| 333 | ); |
---|
| 334 | } |
---|
| 335 | |
---|
[1500] | 336 | } |
---|
| 337 | |
---|
[809] | 338 | // representant management |
---|
[2324] | 339 | if ($category['has_images'] |
---|
[809] | 340 | or !empty($category['representative_picture_id'])) |
---|
| 341 | { |
---|
[2223] | 342 | $tpl_representant = array(); |
---|
[809] | 343 | |
---|
| 344 | // picture to display : the identified representant or the generic random |
---|
| 345 | // representant ? |
---|
| 346 | if (!empty($category['representative_picture_id'])) |
---|
| 347 | { |
---|
| 348 | $query = ' |
---|
[12796] | 349 | SELECT id,representative_ext,path |
---|
[633] | 350 | FROM '.IMAGES_TABLE.' |
---|
| 351 | WHERE id = '.$category['representative_picture_id'].' |
---|
| 352 | ;'; |
---|
[4325] | 353 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[12796] | 354 | $src = DerivativeImage::thumb_url($row); |
---|
[13077] | 355 | $url = get_root_url().'admin.php?page=photo-'.$category['representative_picture_id']; |
---|
[1131] | 356 | |
---|
[2223] | 357 | $tpl_representant['picture'] = |
---|
[809] | 358 | array( |
---|
| 359 | 'SRC' => $src, |
---|
| 360 | 'URL' => $url |
---|
| 361 | ); |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | // can the admin choose to set a new random representant ? |
---|
[2324] | 365 | $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false; |
---|
[809] | 366 | |
---|
| 367 | // can the admin delete the current representant ? |
---|
| 368 | if ( |
---|
[2324] | 369 | ($category['has_images'] |
---|
[809] | 370 | and $conf['allow_random_representative']) |
---|
| 371 | or |
---|
[2324] | 372 | (!$category['has_images'] |
---|
[809] | 373 | and !empty($category['representative_picture_id']))) |
---|
| 374 | { |
---|
[2223] | 375 | $tpl_representant['ALLOW_DELETE'] = true; |
---|
[809] | 376 | } |
---|
[2223] | 377 | $template->assign('representant', $tpl_representant); |
---|
[633] | 378 | } |
---|
| 379 | |
---|
[2223] | 380 | if ($category['is_virtual']) |
---|
[68] | 381 | { |
---|
[28533] | 382 | $template->assign('parent_category', empty($category['id_uppercat']) ? array() : array($category['id_uppercat'])); |
---|
[809] | 383 | } |
---|
| 384 | |
---|
[28587] | 385 | trigger_notify('loc_end_cat_modify'); |
---|
[5933] | 386 | |
---|
[21] | 387 | //----------------------------------------------------------- sending html code |
---|
[13013] | 388 | $template->assign_var_from_handle('ADMIN_CONTENT', 'album_properties'); |
---|
[7024] | 389 | ?> |
---|