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.  
  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.   $items[] = 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.   return $items;
  45. }
  46.  
  47. function user_balance_has_balance($account) {
  48.   global $user;
  49.   if($account->uid == 1) {
  50.     return FALSE; /* forbid the admin user.. */
  51.   }
  52.   if(!user_access("has balance", $account)) {
  53.     return FALSE;
  54.   }
  55.   if($account->uid == $user->uid || user_access("administer users", $user)) {
  56.     return TRUE;
  57.   }
  58.   return FALSE;
  59. }
  60.  
  61. function user_balance_user($op, &$edit, &$account, $category = NULL) {
  62.   if(!user_access("has balance", $account)) {
  63.     return;
  64.   }
  65.   if($op == "categories") {
  66.     return array(
  67.       array(
  68.         "name" => "balance"
  69.         ,"title" => t("Balance Information")
  70.         ,"weight" => 7
  71.         //,'access callback' => 'user_balance_has_balance'
  72.         //,'access arguments' => array (
  73.         //  1
  74.         //)
  75.       )
  76.     );
  77.   }
  78.   if($op == "view") {
  79.     /* TODO: show last transaction .. */
  80.     $account->content["balance"] = array(
  81.       '#type' => 'user_profile_category'
  82.       ,'#title' => "Balance Information"
  83.       ,'current balance' => array(
  84.         '#type' => 'user_profile_item'
  85.         ,'#title' => "Current Balance"
  86.         ,'#value' => theme("balance", $account->amount, variable_get("balance default currency", 0))
  87.       )
  88.     );
  89.     return;
  90.   }
  91.   if($op == "load") {
  92.     $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 .. */
  93.     return;
  94.   }
  95.   $add_balance_entry = FALSE;
  96.   if($op == "insert") {
  97.     $add_balance_entry = TRUE;
  98.   }
  99.   if($op == "update") {
  100.     $bid = db_result(db_query("SELECT bid FROM {user_balance} WHERE uid = %d", $account->uid)); /* see if we have balance entry .. */
  101.     if(!$bid) {
  102.       $add_balance_entry = TRUE;
  103.     }
  104.   }
  105.   if($add_balance_entry) {
  106.     /* when user is inserted we add balance information to his/her account .. */
  107.     db_query("INSERT INTO {balance} SET amount = 0, module = 'user_balance'");
  108.     $bid = db_last_insert_id("balance", "bid");
  109.     db_query("INSERT INTO {user_balance} SET bid = %d AND uid = %d", $bid, $account->uid);
  110.   }
  111. }