Index: /extensions/community/add_photos.php
===================================================================
--- /extensions/community/add_photos.php	(revision 9582)
+++ /extensions/community/add_photos.php	(revision 9583)
@@ -270,27 +270,26 @@
 
 $create_subcategories = false;
-
-if ($user_permissions['create_whole_gallery'])
+if ($user_permissions['create_whole_gallery'] or count($user_permissions['create_categories']) > 0)
 {
   $create_subcategories = true;
 }
 
-if (count($user_permissions['create_categories']) > 0)
-{
-  $create_subcategories = true;
-  $category_ids = null;
-  
-  $query = '
+$create_categories = $user_permissions['create_categories'];
+if (count($user_permissions['create_categories']) == 0)
+{
+  $create_categories = array(-1);
+}
+
+$query = '
 SELECT id,name,uppercats,global_rank
   FROM '.CATEGORIES_TABLE.'
-  WHERE id IN ('.implode(',', $user_permissions['create_categories']).')
-;';
-
-  display_select_cat_wrapper(
-    $query,
-    $selected_category,
-    'category_parent_options'
-    );
-}
+  WHERE id IN ('.implode(',', $create_categories).')
+;';
+
+display_select_cat_wrapper(
+  $query,
+  $selected_category,
+  'category_parent_options'
+  );
 
 $template->assign(
Index: /extensions/community/admin_permissions.php
===================================================================
--- /extensions/community/admin_permissions.php	(revision 9582)
+++ /extensions/community/admin_permissions.php	(revision 9583)
@@ -157,5 +157,5 @@
   }
 
-  conf_update_param('community_update', time());
+  community_update_cache_key();
 }
 
@@ -175,5 +175,5 @@
   pwg_query($query);
 
-  conf_update_param('community_update', time());
+  community_update_cache_key();
 
   $_SESSION['page_infos'] = array(l10n('Permission removed'));
Index: /extensions/community/include/functions_community.inc.php
===================================================================
--- /extensions/community/include/functions_community.inc.php	(revision 9582)
+++ /extensions/community/include/functions_community.inc.php	(revision 9583)
@@ -26,15 +26,22 @@
   global $conf, $user;
 
-  if (!isset($conf['community_update']))
-  {
-    conf_update_param('community_update', time());
-  }
-  
-  if (isset($_SESSION['community_user_permissions']))
-  {
-    if ($_SESSION['community_update'] > $conf['community_update'])
-    {
-      return $_SESSION['community_user_permissions'];
-    }
+  $cache_key = community_get_cache_key();
+  if (!isset($cache_key))
+  {
+    $cache_key = community_update_cache_key();
+  }
+
+  // I (plg) don't understand why, but when you connect, you keep the
+  // permissions calculated for the "guest" : the session is "inheritated"
+  // from guest to the connected user, so I add a
+  // $_SESSION['community_user_id'] to force refresh if the permissions were
+  // not calculated for the right user
+  if (
+    isset($_SESSION['community_user_id'])
+    and $_SESSION['community_user_id'] == $user_id
+    and $_SESSION['community_cache_key'] == $cache_key
+    )
+  {
+    return $_SESSION['community_user_permissions'];
   }
 
@@ -199,5 +206,6 @@
 
   $_SESSION['community_user_permissions'] = $return;
-  $_SESSION['community_update'] = time();
+  $_SESSION['community_cache_key'] = $cache_key;
+  $_SESSION['community_user_id'] = $user_id;
 
   return $_SESSION['community_user_permissions'];
@@ -242,3 +250,23 @@
 }
 
+function community_update_cache_key()
+{
+  $cache_key = generate_key(20);
+  conf_update_param('community_cache_key', $cache_key);
+  return $cache_key;
+}
+
+function community_get_cache_key()
+{
+  global $conf;
+
+  if (isset($conf['community_cache_key']))
+  {
+    return $conf['community_cache_key'];
+  }
+  else
+  {
+    return null;
+  }
+}
 ?>
Index: /extensions/community/main.inc.php
===================================================================
--- /extensions/community/main.inc.php	(revision 9582)
+++ /extensions/community/main.inc.php	(revision 9583)
@@ -127,5 +127,5 @@
   // photos" link in the gallery menu
   $user_permissions = community_get_user_permissions($user['id']);
-  
+
   if (count($user_permissions['upload_categories']) == 0 and !$user_permissions ['create_whole_gallery'])
   {
@@ -213,3 +213,9 @@
   community_reject_user_pendings($user_id);
 }
+
+add_event_handler('invalidate_user_cache', 'community_refresh_cache_update_time');
+function community_refresh_cache_update_time()
+{
+  community_update_cache_key();
+}
 ?>
Index: /extensions/community/maintain.inc.php
===================================================================
--- /extensions/community/maintain.inc.php	(revision 9582)
+++ /extensions/community/maintain.inc.php	(revision 9583)
@@ -328,5 +328,6 @@
   mass_inserts($prefixeTable.'community_permissions', array_keys($insert), array($insert));
 
-  conf_update_param('community_update', time());
+  include_once(dirname(__FILE__).'/include/functions_community.inc.php');
+  community_update_cache_key();
 }
 ?>
