Changeset 2084 for trunk/include/functions_user.inc.php
- Timestamp:
- Sep 11, 2007, 4:24:51 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_user.inc.php
r2055 r2084 258 258 calculate_permissions($userdata['id'], $userdata['status']); 259 259 260 /* now we build the list of forbidden images (this list does not contain 261 images that are not in at least an authorized category)*/ 262 $query = ' 263 SELECT DISTINCT(id) 264 FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id 265 WHERE category_id NOT IN ('.$userdata['forbidden_categories'].') 266 AND level>'.$userdata['level']; 267 $forbidden_ids = array_from_query($query, 'id'); 268 269 if ( empty($forbidden_ids) ) 270 { 271 array_push( $forbidden_ids, 0 ); 272 } 273 $userdata['image_access_type'] = 'NOT IN'; //TODO maybe later 274 $userdata['image_access_list'] = implode(',',$forbidden_ids); 275 260 276 update_user_cache_categories($userdata); 261 277 … … 270 286 FROM '.IMAGE_CATEGORY_TABLE.' 271 287 WHERE category_id NOT IN ('.$userdata['forbidden_categories'].') 288 AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].') 272 289 ;'; 273 290 list($userdata['nb_total_images']) = mysql_fetch_array(pwg_query($query)); … … 282 299 $query = ' 283 300 INSERT INTO '.USER_CACHE_TABLE.' 284 (user_id, need_update, forbidden_categories, nb_total_images) 301 (user_id, need_update, forbidden_categories, nb_total_images, 302 image_access_type, image_access_list) 285 303 VALUES 286 304 ('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\',\'' 287 .$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].') 305 .$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"' 306 .$userdata['image_access_type'].'","'.$userdata['image_access_list'].'") 288 307 ;'; 289 308 pwg_query($query); … … 528 547 529 548 $query = 'SELECT c.id cat_id, global_rank'; 530 if ( !isset($filter_days) ) 531 { 532 $query .= ', 533 date_last cat_date_last, 534 nb_images cat_nb_images 535 FROM '.CATEGORIES_TABLE.' as c'; 536 } 537 else 538 { 539 // Count by date_available to avoid count null 540 $query .= ', 541 MAX(date_available) cat_date_last, 542 COUNT(date_available) cat_nb_images 543 FROM '.CATEGORIES_TABLE.' as c 544 LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id 545 LEFT JOIN '.IMAGES_TABLE.' AS i 546 ON ic.image_id = i.id AND 547 i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)'; 548 $group_by = 'c.id'; 549 } 549 // Count by date_available to avoid count null 550 $query .= ', 551 MAX(date_available) cat_date_last, COUNT(date_available) cat_nb_images 552 FROM '.CATEGORIES_TABLE.' as c 553 LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON ic.category_id = c.id 554 LEFT JOIN '.IMAGES_TABLE.' AS i 555 ON ic.image_id = i.id 556 AND i.level<='.$userdata['level']; 557 558 if ( isset($filter_days) ) 559 { 560 $query .= ' AND i.date_available > SUBDATE(CURRENT_DATE,INTERVAL '.$filter_days.' DAY)'; 561 } 562 $group_by = 'c.id'; 550 563 551 564 if ( !empty($userdata['forbidden_categories']) ) … … 720 733 { 721 734 global $page, $conf; 722 735 723 736 if (!isset($page['cache_default_user'])) 724 737 { … … 728 741 $result = pwg_query($query); 729 742 $page['cache_default_user'] = mysql_fetch_assoc($result); 730 743 731 744 if ($page['cache_default_user'] !== false) 732 745 { … … 840 853 foreach ($user_ids as $user_id) 841 854 { 855 $level= isset($default_user['level']) ? $default_user['level'] : 0; 842 856 if ($user_id == $conf['webmaster_id']) 843 857 { 844 858 $status = 'webmaster'; 845 } 846 else if (($user_id == $conf['guest_id']) or 859 $level = max( $conf['available_permission_levels'] ); 860 } 861 else if (($user_id == $conf['guest_id']) or 847 862 ($user_id == $conf['default_user_id'])) 848 863 { … … 859 874 'user_id' => $user_id, 860 875 'status' => $status, 861 'registration_date' => $dbnow 876 'registration_date' => $dbnow, 877 'level' => $level 862 878 )); 863 879 864 880 array_push($inserts, $insert); 865 881 } 866 882 867 883 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); … … 902 918 * availability of the file 903 919 * 904 * in descending order of preference: 920 * in descending order of preference: 905 921 * param language, user language, default language 906 922 * PhpWebGallery default language. … … 1291 1307 } 1292 1308 case 'visible_images': 1293 {1294 1309 if (!empty($filter['visible_images'])) 1295 1310 { … … 1297 1312 $field_name.' IN ('.$filter['visible_images'].')'; 1298 1313 } 1314 // note there is no break - visible include forbidden 1315 case 'forbidden_images': 1316 if ( 1317 !empty($user['image_access_list']) 1318 or $user['image_access_type']!='NOT IN' 1319 ) 1320 { 1321 $table_prefix=null; 1322 if ($field_name=='id') 1323 { 1324 $table_prefix = ''; 1325 } 1326 elseif ($field_name=='i.id') 1327 { 1328 $table_prefix = 'i.'; 1329 } 1330 if ( isset($table_prefix) ) 1331 { 1332 $sql_list[]=$table_prefix.'level<='.$user['level']; 1333 } 1334 else 1335 { 1336 $sql_list[]=$field_name.' '.$user['image_access_type'] 1337 .' ('.$user['image_access_list'].')'; 1338 } 1339 } 1299 1340 break; 1300 }1301 1341 default: 1302 1342 {
Note: See TracChangeset
for help on using the changeset viewer.