user module causes warning while calling user_access()

  1. function user_is_queue_member($account) {
  2.   global $user;
  3.   /*
  4.    * if I omit the following check it creates
  5.    * following error:
  6.    * ==========================================================
  7.    * warning: array_fill() [function.array-fill]: Number of elements must be positive in /data/projects/voip_support/trunk/control_interface/includes/database.inc on line 235.
  8.    * warning: implode() [function.implode]: Bad arguments. in /data/projects/voip_support/trunk/control_interface/includes/database.inc on line 235.
  9.    * warning: array_keys() [function.array-keys]: The first argument should be an array in /data/projects/voip_support/trunk/control_interface/modules/user/user.module on line 500.
  10.    * user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 query: SELECT p.perm FROM web_role r INNER JOIN web_permission p ON p.rid = r.rid WHERE r.rid IN () in /data/projects/voip_support/trunk/control_interface/modules/user/user.module on line 500.
  11.    * ==========================================================
  12.    * The probable reason is $account->role is not assigned when user_access() is called. Note that I called this in hook_user implementation which is called before all the node elements are loaded.
  13.    */
  14.   if(!is_array($account->roles)) {
  15.     return FALSE;
  16.   }
  17.   if($account->uid == 1) {
  18.     return FALSE; /* forbid the admin user.. */
  19.   }
  20.   if(!user_access("can be queue member", $account)) {
  21.     return FALSE;
  22.   }
  23.   if($account->uid == $user->uid || user_access("administer users", $user)) {
  24.     return TRUE;
  25.   }
  26.   return FALSE;
  27. }