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