01-08-2023, 12:18 PM
The main idea is to make unified functions that could be usable in all fees events and therefore managed from one place in the code (not messed around in different ways in different script files).
open /includes/functions_fees.php:
find
insert after
head down to the final curly brace. and bore that last Insert after last "}"
Insert the following code:
Now you can use for fees events just couple of lines: (this means you use this code anywhere you need to register or update fees, you do not need to do anything with this right now.
And then you need to edit sell.php, otherwise it raises an error:
Find The code:
and replace it with
open /admin/fees.php and replace the $fees arrays
Replace all instances of
with
Find
and replace with:
find
and replace with
open /includes/functions_fees.php:
find
Code:
class fees
{
var $ASCII_RANGE;
insert after
Code:
public $types = array( //0 = single value, 1 = staged fees
'signup_fee' => 0,
'buyer_fee' => 1,
'setup' => 1,
'hpfeat_fee' => 0,
'bolditem_fee' => 0,
'hlitem_fee' => 0,
'rp_fee' => 0,
'picture_fee' => 0,
'relist_fee' => 0,
'buyout_fee' => 0,
'endauc_fee' => 1,
'bid_fee' => 0
);
head down to the final curly brace. and bore that last Insert after last "}"
Insert the following code:
Code:
function edit_user_balance($user_id, $amount) //edits user balance and returns the restult of balance after editing
{
global $system, $DBPrefix;
$addquery = ' ' . $amount;
$query = "SELECT suspended, balance FROM " . $DBPrefix . "users WHERE id = " . $user_id;
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
$data = mysql_fetch_assoc($res);
if ($amount <> 0 )
{
if ($system->SETTINGS['fee_disable_acc'] == 'y')
{
// reable user account if it was disabled
if ($data['suspended'] == 7 && ($data['balance'] + $amount) >= - $system->SETTINGS['fee_max_debt'])
{
$addquery = $addquery . ' , suspended = 0 ';
} elseif ($data['suspended'] == 0 && ($data['balance'] + $amount) < - $system->SETTINGS['fee_max_debt'])
{
$addquery = $addquery . ' , suspended = 7 ';
}
}
$query = "UPDATE " . $DBPrefix . "users SET balance = balance +" . $addquery . " WHERE id = " . $user_id;
$system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
}
return ($data['balance'] + $amount);
}
function get_fee_def($fee_type, $fee_base = NULL)
{
global $system, $DBPrefix;
if($this->types[$fee_type] == 0)
{
$query = "SELECT value FROM " . $DBPrefix . "fees WHERE type = '" . $fee_type . "'";
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
$value = mysql_result($res, 0);
}
elseif($this->types[$fee_type] == 1)
{
$query = "SELECT value FROM " . $DBPrefix . "fees WHERE type = '" . $fee_type . "' and fee_from <= " . $fee_base . " and fee_to >= " . $fee_base;
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
$value = mysql_result($res, 0);
}
return $value;
}
function register_fee($user_id, $fee_type, $auct_id = 0, $fee_base = NULL, $currency = NULL)
//finds the fee amount
//registers fee
//returns left balance
{
global $system, $DBPrefix;
if ($system->SETTINGS['fees'] == 'y')
{
$f_amount = $this->get_fee_def($fee_type, $fee_base);
// Disable next tree lines till future development, that uses these table values, otherwise this table/data will just take a space.
// $query = "INSERT INTO " . $DBPrefix . "userfees VALUES
// (NULL, '" . $auct_id . "', '" . $user_id . "', '" . $f_amount . "', 0, '" . $fee_type . "')";
// $system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
$f_amount = $this->edit_user_balance($user_id, - $f_amount);
return $f_amount;
} else {
return 0;
}
}
Now you can use for fees events just couple of lines: (this means you use this code anywhere you need to register or update fees, you do not need to do anything with this right now.
Code:
$fees = new fees();
$fees->register_fee($user->user_data['id'], "setup", $auction_id, $minimum_bid);
Quote:If you want to play with userfees table (you enabled lines after comment line in register_fee function) then you need to add field in table webid_userfees:
fee_type: varchar(15), not null
And then you need to edit sell.php, otherwise it raises an error:
Find The code:
Code:
if ($system->SETTINGS['fees'] == 'y')
{
$feeupdate = false;
if ($_SESSION['SELL_action'] == 'edit')
{
$query = "SELECT id FROM " . $DBPrefix . "userfees WHERE auc_id = " . $auction_id;
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
if (mysql_num_rows($res) == 1)
{
$feeupdate = true;
$query = "UPDATE " . $DBPrefix . "userfees SET amt = amt + " . $fee . " WHERE auc_id = " . $auction_id;
$system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
}
}
if (!$feeupdate)
{
$query = "INSERT INTO " . $DBPrefix . "userfees VALUES (NULL, " . $auction_id . ", " . $user->user_data['id'] . ", " . $fee . ", 0)";
$system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
}
if ($system->SETTINGS['fee_type'] == 2 && $fee > 0)
{
$query = "UPDATE " . $DBPrefix . "auctions SET suspended = 9 WHERE id = " . $auction_id;
$system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
$addcounter = false;
}
else
{
$query = "UPDATE " . $DBPrefix . "users SET balance = balance - " . $fee . " WHERE id = " . $user->user_data['id'];
$system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
}
}
and replace it with
Code:
$fees = new fees();
$fees->register_fee($user->user_data['id'], "setup", $auction_id, $minimum_bid);
open /admin/fees.php and replace the $fees arrays
Replace all instances of
Code:
$fees[$_GET['type']]
with
Code:
$fees->types[$_GET['type']]
Find
Code:
$query = "SELECT value FROM " . $DBPrefix . "fees WHERE type = '" . $_GET['type'] . "'";
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
$value = mysql_result($res, 0);
and replace with:
Code:
$value = $fees->get_fee_def($_GET['type']);
find
Code:
'VALUE' => $row['value']
and replace with
Code:
'VALUE' => $system->print_money_nosymbol($row['value'])