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

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.