Ok this one is really tricky. I have no way of packaging it however I'm willing to let anyone who want's to take a shot of including it into the Shop system to do so.
Requirements are of course that you use SMFShop (I originally designed it under 2.0 however it still works under 2.2) You will need to have a way to change the database as you will need to create a new column in the members table. You will also need to change the dointerest.php file a little bit.
Step 1. Create a new column in the smf_members (or what ever prefix you are using) table called 'bankInterest'. It should be an integer and the default should be 0 as this would not allow modification of the standard bank interest that is part of the SMFShop system.
Step 2. Place this script into the Sources/shop/items directory:
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.com/ |
\**********************************************/
//File: AddToInterest.php
// Item (takes additional fields when adding to Admin panel)
//VERSION: 1.0
//DATE: 13th February 2006
//AUTHOR: JRSofty Programming
class item_AddToInterest extends itemTemplate {
function getItemDetails() {
$this->name = "Add xxx to Interest Rate";
$this->desc = "Increase your Interest Rate by xxx";
$this->price = 100;
$this->require_input = false;
$this->can_use_item = true;
}
//this is the best bit of this item. When you add the item into the admin panel, you
//can set additional variables (up to 4). Make sure to call them info1, info2, info3
//and info4.
function getAddInput() {
return "Amount to change Interest Rate by: <input type='text' name='info1' value='1'>";
}
//the additional parameters (see 'getAddInput' above) are in the '$item_info array.
//make sure to make it global (like shown here) otherwise you won't be able to access
//it's contents. THE ARRAY IS 1-BASED (eg. 1 IS THE FIRST ITEM) NOT 0-BASED!
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info;
$result = db_query("UPDATE {$db_prefix}members
SET bankInterest = bankInterest + {$item_info[1]}
WHERE ID_MEMBER = {$ID_MEMBER}",
__FILE__, __LINE__);
return "Successfully added {$item_info[1]} to interest!";
//echo $item_info[1];
die("dead");
}
}
?>
Step 3: Here is the dointerest.php that I use so that the interest increase is picked up from the member's row in the table and added to the bank interest.
<?php
include ('../../SSI.php');
$request = db_query("SELECT `ID_MEMBER`, `bankInterest`
FROM {$db_prefix}members",__FILE__,__LINE__);
while(($row = mysql_fetch_array($request)) !== false){
$interest_rate = ($modSettings['shopInterest'] + $row['bankInterest']) / 100;
db_query("UPDATE {$db_prefix}members
SET moneyBank = moneyBank + (moneyBank*{$interest_rate}) WHERE `ID_MEMBER` = ".$row['ID_MEMBER'], __FILE__, __LINE__);
echo $row['ID_MEMBER'] . " Interest added at " . $interest_rate . " ".date("d/m/Y h:i:s A")."<br>";
}
?>
Known issues:
When you enter the Shop your updated or changed Interest rate does not display. It only displays what the SMFShop System Interest is set. Other than that it seems to work ok.
If anyone would like to package this please feel free (or if Daniel15 would like to include it in his next version that is also fine
) the only thing I ask is that my name remain in place in the code.