Changeset 11934 for extensions/Icy_Picture_Modify/icy_picture_modify.php
- Timestamp:
- Aug 12, 2011, 9:13:57 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Icy_Picture_Modify/icy_picture_modify.php
r11614 r11934 58 58 59 59 // Simplify redirect to administrator page if current user == admin 60 // FIXME: when a non-existent image_id is provided, the original code61 // FIXME: picture_modify doesn't work well. It should deny to modify62 // FIXME: such picture.63 60 if (is_admin()) 64 61 { … … 68 65 $url.= '&image_id='.$_GET['image_id']; 69 66 $url.= isset($_GET['cat_id']) ? '&cat_id='.$_GET['cat_id'] : ''; 67 // FIXME: What happens if a POST data were sent within admin uid? 70 68 redirect_http($url); 71 69 } … … 94 92 } 95 93 94 // <find writable categories> 95 96 // * Purpose: Find all categories that are reachable for the current user. 97 // * FIXME: This query will include all readable categories, those ones 98 // use can't write to them. 99 100 $my_categories = array(); 101 $my_permissions = null; 102 103 // <community support> 104 if (is_file(PHPWG_PLUGINS_PATH.'community/include/functions_community.inc.php')) 105 { 106 include_once(PHPWG_PLUGINS_PATH.'community/include/functions_community.inc.php'); 107 $user_permissions = community_get_user_permissions($user['id']); 108 $my_categories = $user_permissions['upload_categories']; 109 } 110 // </community support> 111 112 // FIXME: what happens if both of the following conditions are true 113 // FIXME: * true == $user_permissions['create_whole_gallery'] 114 // FIXME: * 0 < count($my_categories) 115 if (empty($user_permissions) or $user_permissions['create_whole_gallery']) 116 { 117 $query = ' 118 SELECT category_id 119 FROM '.IMAGE_CATEGORY_TABLE.' 120 ;'; 121 122 // list of categories to which the user can access 123 $my_categories = array_diff( 124 array_from_query($query, 'category_id'), 125 explode(',',calculate_permissions($user['id'], $user['status']))); 126 } 127 // </find writable categories> 96 128 97 129 // +-----------------------------------------------------------------------+ … … 128 160 ;'; 129 161 130 $authorizeds = array_diff( 131 array_from_query($query, 'category_id'), 132 explode(',', calculate_permissions($user['id'], $user['status'])) 133 ); 162 $authorizeds = array_intersect($my_categories, 163 array_from_query($query, 'category_id')); 134 164 135 165 foreach ($authorizeds as $category_id) … … 164 194 } 165 195 166 //--------------------------------------------------------- update informations 196 // +-----------------------------------------------------------------------+ 197 // | update informations | 198 // +-----------------------------------------------------------------------+ 167 199 168 200 // first, we verify whether there is a mistake on the given creation date … … 231 263 array_push($page['infos'], l10n('Photo informations updated')); 232 264 } 265 266 // +-----------------------------------------------------------------------+ 267 // | associate | 268 // +-----------------------------------------------------------------------+ 233 269 // associate the element to other categories than its storage category 270 // 234 271 if (isset($_POST['associate']) 235 272 and isset($_POST['cat_dissociated']) … … 239 276 associate_images_to_categories( 240 277 array($_GET['image_id']), 241 $_POST['cat_dissociated']278 array_intersect($_POST['cat_dissociated'], $my_categories) 242 279 ); 243 280 } 281 282 244 283 // dissociate the element from categories (but not from its storage category) 245 284 if (isset($_POST['dissociate']) … … 248 287 ) 249 288 { 289 $arr_dissociate = array_intersect($_POST['cat_associated'], $my_categories); 250 290 $query = ' 251 291 DELETE FROM '.IMAGE_CATEGORY_TABLE.' 252 292 WHERE image_id = '.$_GET['image_id'].' 253 AND category_id IN ('.implode(',', $ _POST['cat_associated']).')293 AND category_id IN ('.implode(',', $arr_dissociate).') 254 294 '; 255 295 pwg_query($query); 256 296 257 update_category($ _POST['cat_associated']);258 } 259 // elect the element to represent the given categories297 update_category($arr_dissociate); 298 } 299 // select the element to represent the given categories 260 300 if (isset($_POST['elect']) 261 301 and isset($_POST['cat_dismissed']) … … 264 304 { 265 305 $datas = array(); 266 foreach ($_POST['cat_dismissed'] as $category_id) 267 { 268 array_push($datas, 269 array('id' => $category_id, 270 'representative_picture_id' => $_GET['image_id'])); 271 } 272 $fields = array('primary' => array('id'), 273 'update' => array('representative_picture_id')); 274 mass_updates(CATEGORIES_TABLE, $fields, $datas); 306 $arr_dimissed = array_intersect($_POST['cat_dismissed'], $my_categories); 307 if (count($arr_dimissed) > 0) 308 { 309 foreach ($arr_dimissed as $category_id) 310 { 311 array_push($datas, 312 array('id' => $category_id, 313 'representative_picture_id' => $_GET['image_id'])); 314 } 315 $fields = array('primary' => array('id'), 316 'update' => array('representative_picture_id')); 317 mass_updates(CATEGORIES_TABLE, $fields, $datas); 318 } 275 319 } 276 320 // dismiss the element as representant of the given categories … … 280 324 ) 281 325 { 282 set_random_representant($_POST['cat_elected']); 326 $arr_dismiss = array_intersect($_POST['cat_elected'], $my_categories); 327 if (count($arr_dismiss) > 0) 328 { 329 set_random_representant($arr_dismiss); 330 } 283 331 } 284 332 … … 310 358 $row = pwg_db_fetch_assoc(pwg_query($query)); 311 359 360 // the physical storage directory contains the image 312 361 $storage_category_id = null; 313 362 if (!empty($row['storage_category_id'])) … … 463 512 ;'; 464 513 465 $authorizeds = array_diff( 466 array_from_query($query, 'category_id'), 467 explode( 468 ',', 469 calculate_permissions($user['id'], $user['status']) 470 ) 471 ); 472 514 // list of categories (OF THIS IMAGE) to which the user can access 515 $authorizeds = array_intersect($my_categories, 516 array_from_query($query, 'category_id')); 517 518 // if current category belongs to list of authorized categories 519 // we simply provide link to that category 473 520 if (isset($_GET['cat_id']) 474 521 and in_array($_GET['cat_id'], $authorizeds)) … … 482 529 ); 483 530 } 531 // otherwise we provide links to the *first* category in the list 484 532 else 485 533 { … … 493 541 ) 494 542 ); 543 // FIXME: why the first category is selected? 495 544 break; 496 545 } … … 507 556 FROM '.CATEGORIES_TABLE.' 508 557 INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id 509 WHERE image_id = '.$_GET['image_id']; 558 WHERE image_id = '.$_GET['image_id'] . ' 559 AND id IN ('. join(",", $my_categories).')'; 560 // if the image belongs to a physical storage, 561 // we simply ignore that storage album 510 562 if (isset($storage_category_id)) 511 563 { … … 531 583 FROM '.CATEGORIES_TABLE.' 532 584 WHERE id NOT IN ('.implode(',', $associateds).') 585 AND id IN ('. join(",", $my_categories).') 533 586 ;'; 534 587 display_select_cat_wrapper($query, array(), 'dissociated_options'); … … 539 592 FROM '.CATEGORIES_TABLE.' 540 593 WHERE representative_picture_id = '.$_GET['image_id'].' 594 AND id IN ('. join(",", $my_categories).') 541 595 ;'; 542 596 display_select_cat_wrapper($query, array(), 'elected_options'); … … 545 599 SELECT id,name,uppercats,global_rank 546 600 FROM '.CATEGORIES_TABLE.' 547 WHERE representative_picture_id != '.$_GET['image_id'].' 548 OR representative_picture_id IS NULL 601 WHERE id IN ('. join(",", $my_categories).') 602 AND (representative_picture_id != '.$_GET['image_id'].' 603 OR representative_picture_id IS NULL) 549 604 ;'; 550 605 display_select_cat_wrapper($query, array(), 'dismissed_options');
Note: See TracChangeset
for help on using the changeset viewer.