my module is showing bug .. not sure why ..

  1. /*
  2.  
  3.  
  4.  
  5.     * warning: array_fill() [function.array-fill]: Number of elements must be positive in /c/projects/click_to_call/trunk/control_interface/includes/database.inc on line 235.
  6.     * warning: implode() [function.implode]: Bad arguments. in /c/projects/click_to_call/trunk/control_interface/includes/database.inc on line 235.
  7.     * warning: array_keys() [function.array-keys]: The first argument should be an array in /c/projects/click_to_call/trunk/control_interface/modules/user/user.module on line 500.
  8.     * 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 /c/projects/click_to_call/trunk/control_interface/modules/user/user.module on line 500.
  9.  
  10.  
  11.  
  12. */
  13.  
  14.  
  15. <?php # vim: set filetype=php expandtab tabstop=2 shiftwidth=2 autoindent smartindent:
  16.  
  17. /* TODO: add user billing address. User card information or other things may be .. */
  18. /* TODO: may be a block showing billing information and last transaction .. */
  19.  
  20. function user_balance_perm() {
  21.   return array("has balance");
  22. }
  23.  
  24. function user_balance_help($path, $arg) {
  25.   switch($path) {
  26.     case "user/%user/balance" :
  27.     return "User Balance and billing details.";
  28.   }
  29. }
  30.  
  31. function user_balance_menu() {
  32.   return array(
  33.     "user/%user/balance" => array(
  34.       "title" => "Balance Information"
  35.       ,"description" => "Billing information as well as billing log view"
  36.       ,"page callback" => "drupal_get_form"
  37.       ,"page arguments" => array("user_balance_details", 1)
  38.       ,"access callback" => "user_balance_has_balance"
  39.       ,"access arguments" => array(1)
  40.       ,"file" => "user_balance.pages.inc"
  41.       ,"type" => MENU_LOCAL_ITEM
  42.     )
  43.   );
  44. }
  45.  
  46. function user_balance_has_balance($account) {
  47.   global $user;
  48.   if($account->uid == 1) {
  49.     return FALSE; /* forbid the admin user.. */
  50.   }
  51.   if(!user_access("has balance", $account)) {
  52.     return FALSE;
  53.   }
  54.   if($account->uid == $user->uid || user_access("administer users", $user)) {
  55.     return TRUE;
  56.   }
  57.   return FALSE;
  58. }
  59.  
  60. function user_balance_user($op, &$edit, &$account, $category = NULL) {
  61.   if(!user_access("has balance", $account)) {
  62.     return;
  63.   }
  64.   if($op == "categories") {
  65.     return array(
  66.       array(
  67.         "name" => "balance"
  68.         ,"title" => t("Balance Information")
  69.         ,"weight" => 7
  70.         //,'access callback' => 'user_balance_has_balance'
  71.         //,'access arguments' => array (
  72.         //  1
  73.         //)
  74.       )
  75.     );
  76.   }
  77.   if($op == "view") {
  78.     /* TODO: show last transaction .. */
  79.     $account->content["balance"] = array(
  80.       '#type' => 'user_profile_category'
  81.       ,'#title' => "Balance Information"
  82.       ,'current balance' => array(
  83.         '#type' => 'user_profile_item'
  84.         ,'#title' => "Current Balance"
  85.         ,'#value' => theme("balance", $account->amount, variable_get("balance default currency", 0))
  86.       )
  87.     );
  88.     return;
  89.   }
  90.   if($op == "load") {
  91.     $account->amount = db_result(db_query("SELECT amount FROM {user_balance} AS ub JOIN {balance} AS b ON (ub.bid = b.bid) WHERE ub.uid = %d", $account->uid)); /* see if we have balance entry .. */
  92.     return;
  93.   }
  94.   $add_balance_entry = FALSE;
  95.   if($op == "insert") {
  96.     $add_balance_entry = TRUE;
  97.   }
  98.   if($op == "update") {
  99.     $bid = db_result(db_query("SELECT bid FROM {user_balance} WHERE uid = %d", $account->uid)); /* see if we have balance entry .. */
  100.     if(!$bid) {
  101.       $add_balance_entry = TRUE;
  102.     }
  103.   }
  104.   if($add_balance_entry) {
  105.     /* when user is inserted we add balance information to his/her account .. */
  106.     db_query("INSERT INTO {balance} SET amount = 0, module = 'user_balance'");
  107.     $bid = db_last_insert_id("balance", "bid");
  108.     db_query("INSERT INTO {user_balance} SET bid = %d AND uid = %d", $bid, $account->uid);
  109.   }
  110. }