aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/functions_user.inc.php92
1 files changed, 51 insertions, 41 deletions
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index d7ef88992..fac372852 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -247,8 +247,7 @@ SELECT ';
}
$query.= '
FROM '.USERS_TABLE.'
- WHERE '.$conf['user_fields']['id'].' = \''.$user_id.'\'
-;';
+ WHERE '.$conf['user_fields']['id'].' = \''.$user_id.'\'';
$row = mysql_fetch_array(pwg_query($query));
@@ -258,8 +257,7 @@ SELECT ';
SELECT ui.*, uc.*
FROM '.USER_INFOS_TABLE.' AS ui LEFT JOIN '.USER_CACHE_TABLE.' AS uc
ON ui.user_id = uc.user_id
- WHERE ui.user_id = \''.$user_id.'\'
-;';
+ WHERE ui.user_id = \''.$user_id.'\'';
$result = pwg_query($query);
if (mysql_num_rows($result) > 0)
{
@@ -320,21 +318,64 @@ SELECT DISTINCT(id)
$userdata['image_access_type'] = 'NOT IN'; //TODO maybe later
$userdata['image_access_list'] = implode(',',$forbidden_ids);
- update_user_cache_categories($userdata);
$query = '
SELECT COUNT(DISTINCT(image_id)) as total
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id NOT IN ('.$userdata['forbidden_categories'].')
- AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')
-;';
+ AND image_id '.$userdata['image_access_type'].' ('.$userdata['image_access_list'].')';
list($userdata['nb_total_images']) = mysql_fetch_array(pwg_query($query));
+
+ // now we update user cache categories
+ $user_cache_cats = get_computed_categories($userdata, null);
+ if ( !is_admin($userdata['status']) )
+ { // for non admins we forbid categories with no image (feature 1053)
+ $forbidden_ids = array();
+ foreach ($user_cache_cats as $cat_id => $cat)
+ {
+ if ($cat['count_images']==0)
+ {
+ array_push($forbidden_ids, $cat_id);
+ unset( $user_cache_cats[$cat_id] );
+ }
+ }
+ if ( !empty($forbidden_ids) )
+ {
+ if ( empty($userdata['forbidden_categories']) )
+ {
+ $userdata['forbidden_categories'] = implode(',', $forbidden_ids);
+ }
+ else
+ {
+ $userdata['forbidden_categories'] .= ','.implode(',', $forbidden_ids);
+ }
+ }
+ }
+
+ // delete user cache
+ $query = '
+DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
+ WHERE user_id = '.$userdata['id'];
+ pwg_query($query);
+
+ include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+ mass_inserts
+ (
+ USER_CACHE_CATEGORIES_TABLE,
+ array
+ (
+ 'user_id', 'cat_id',
+ 'date_last', 'max_date_last', 'nb_images', 'count_images', 'count_categories'
+ ),
+ $user_cache_cats
+ );
+
+
// update user cache
$query = '
DELETE FROM '.USER_CACHE_TABLE.'
- WHERE user_id = '.$userdata['id'].'
-;';
+ WHERE user_id = '.$userdata['id'];
pwg_query($query);
$query = '
@@ -345,8 +386,7 @@ INSERT INTO '.USER_CACHE_TABLE.'
('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\','
.$userdata['cache_update_time'].',\''
.$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].',"'
- .$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")
-;';
+ .$userdata['image_access_type'].'","'.$userdata['image_access_list'].'")';
pwg_query($query);
}
}
@@ -643,36 +683,6 @@ FROM '.CATEGORIES_TABLE.' as c
}
/**
- * update data of user_cache_categories
- *
- * @param array userdata
- * @return null
- */
-function update_user_cache_categories($userdata)
-{
- // delete user cache
- $query = '
-DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
- WHERE user_id = '.$userdata['id'].'
-;';
- pwg_query($query);
-
- $cats = get_computed_categories($userdata, null);
-
- include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
- mass_inserts
- (
- USER_CACHE_CATEGORIES_TABLE,
- array
- (
- 'user_id', 'cat_id',
- 'date_last', 'max_date_last', 'nb_images', 'count_images', 'count_categories'
- ),
- $cats
- );
-}
-
-/**
* returns user identifier thanks to his name, false if not found
*
* @param string username