SMF Shop
SMFShop => SMFShop Announcements => Topic started by: Daniel15 on February 10, 2006, 08:43:23 pm
-
Hi,
Unfortunately, some people don't have access to cron jobs, and therefore ask me if there's a way to add the interest without using cron jobs.
First, create a file somewhere on your website. Give it a random name, maybe something like dointerest2342351.php. This is so members of your site don't know the name of the file, and therefore can't add the interest themselves. Put the following text in the file:
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.net/ |
\**********************************************/
//File: dointerest.php
// The file to add interest to member's bank
//VERSION: 1.31 (Build 7)
//DATE: 10th December 2005
include("/home/[username]/public_html/forum/SSI.php");
$interest_rate = $modSettings['shopInterest'] / 100;
db_query("UPDATE {$db_prefix}members
SET moneyBank = moneyBank + (moneyBank*{$interest_rate})", __FILE__, __LINE__);
echo "Interest added at ".date("d/m/Y h:i:s A");
?>
Replace '/home/[username]/public_html/forum/' with the absolute URL of the forum. This can be found by going to SMF Admin Panel --> Edit Server Settings --> SMF Directory. It will look something like '/home/username/public_html/forum'.
Next, we use a utility that calls this script every day. There are several web-based cron tools, but most are in other languages. You can get a Windows program that will call the script every day, or, if you want to, you could just run the script yourself :)
Once you've set that up, your interest should now be working!
UPDATE: You may try to call the script via the Windows Task Scheduler. Please see this post (http://www.www.daniel15.com/forum/index.php?topic=95.msg349#msg349) for more details
-
I found a place that will let you set up a free web based cron job www.cronjobs.org/index.php (http://www.cronjobs.org/index.php)
The only info you need to change are...
Name.....just make something up
URL http......ie www.yoursite.com/forum/your_bankinterest.php
Expire after........change to 999 because setting to 000 will give an error
HOUR.....set to 0am or whatever time you want
Hope this helps someone :)
-
I found a place that will let you set up a free web based cron job www.cronjobs.org/index.php (http://www.cronjobs.org/index.php)
The only info you need to change are...
Name.....just make something up
URL http......ie www.yoursite.com/forum/your_bankinterest.php
Expire after........change to 999 because setting to 000 will give an error
HOUR.....set to 0am or whatever time you want
Hope this helps someone :)
I am still waiting for a validation email from that site :'( :'( :'(
Next, we use a utility that calls this script every day. There are several web-based cron tools, but most are in other languages. You can get a Windows program that will call the script every day, or, if you want to, you could just run the script yourself Smiley
UPDATE: You may try to call the script via the Windows Task Scheduler. Please see this post for more details
How to do this & i did follow the link .... and the link for the windows task scheduler is dead :crazy2: :crazy2: :crazy2:
-
and the link for the windows task scheduler is dead
Bah, my find-and-replace made the link incorrect!
Try this link instead: http://www.daniel15.com/forum/index.php?topic=95.msg349#msg349
-
Nvm daniel. Manage to get it working by doing cron job in the cpanel O0 O0 O0
-
Ehm, sorry
but how to call the script myself?
-
*bump* ?
-
I was wondering... All you have to do is visit http://url/forum/interest.php (or whatever I named it) to activiate it, right? Well I went to it and it was a blank page. Is this normal?
-
Completely normal. :)
-
Well, you should get a page saying 'Interest added at ' followed by the date... However, if you don't, it should be fine (as long as the interest is actually added)
For the 'do_interest.php' file, it won't work if you call it from your browser...
-
Hello,
there is a misstake in the script by Daniel15, i have correct them...
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.com/ |
\**********************************************/
//File: dointerest.php
// The file to add interest to member's bank
//VERSION: 1.31 (Build 7)
//DATE: 10th December 2005
include("/home/[username]/public_html/forum/SSI.php");
$interest_rate = $modSettings['shopInterest'] / 100;
db_query("UPDATE {$db_prefix}members
SET moneyBank = moneyBank + (moneyBank*{$interest_rate})", __FILE__, __LINE__);
echo "Interest added at ".date("d/m/Y h:i:s A");
?>
The last "}" must be deleted, i assume he forgot this while editing original dointere4st.php
Now everything should working if you call the script from browser
-
Thanks prisoner, I've correct my (stupid) mistake :P
-
Wow. I just happened to read this and find that it actually doesn't avoid cron jobs. A cron job just calls a script daily. If you can't do that, what can you do? Well, why not simply run interest whenever someone visits the shop... it takes a few database querys, but nothing fancy. Note that this only works if your members are active. Someone needs to log-on to trigger it. You could be fancy, and have it find the number of days in between failed interest days, but that would be tricky with leap years. I wanna keep this simple
Ok. Open shop.php, find
$context['page_title'] = $txt['shop'];
$context['linktree'][] = array(
'url' => "$scripturl?action=shop",
'name' => $txt['shop'],
);
Below this is where we will code. The first thing to do is to check if it is a new day or not. The best way to do this is to create a column in the Settings database table, which records the last time someone collected interest. So insert a row into that table with variable = 'InterestDate' and value = 0.
now add this code
$date = date('z') //find the current date. Z is the day of the year it is.
$olddate = $modSettings['InterestDate'] //last date you got interest
if ($date != $olddate) // if they are equal, do nothing. If they are not equal, time to collect interest.
{
$interest_rate = $modSettings['shopInterest'] / 100;
db_query("UPDATE {$db_prefix}members
SET moneyBank = moneyBank + (moneyBank*{$interest_rate})", __FILE__, __LINE__); // This gives interst copied from daniels script, so it should work.
$result = db_query("UPDATE {$db_prefix}settings
SET value = {$date}
WHERE variable = 'InterestDate'", __FILE__, __LINE__); //update the last time interest was collected
}
And that it. I havn't tested it(its 11:30 PM right now), but it should work. If not, just give me the error you get and I will try to fix it.
-
Nice suggestion Basil Beard :)
Wow. I just happened to read this and find that it actually doesn't avoid cron jobs. A cron job just calls a script daily. If you can't do that, what can you do?
Well, I meant, if you don't have access to cron jobs on your server ;)
-
Is the new shop version 2.3 suppose to calculate bank interest on its own? I noticed its not and i have to force the bank int everyday. Also noticed it only likes whole number like 1 or 2, and wont take 0.02
Let me know if im doing it wrong or if you have a suggestion. Greatly appreciate.
John
-
Am i the only one having trouble? :(
-
Is the new shop version 2.3 suppose to calculate bank interest on its own?
Yes, that's what the dointerest.php file does (unless you mean something else?)
Also noticed it only likes whole number like 1 or 2, and wont take 0.02
That's fixed in the development version of SMFShop, and will be fixed in the next release. I posted a fix on how to achieve this (search this forum for it)
-
But a cron job has to be established to run the dointrest right? And if so, whats the path i run on the cron job? Im asking because i thought this would be done automatically (calculate interest)
Starting my scavenger hunt on the other fix.
thanks.
-
Im searching for the bank interest change question i had above. I get the same results when i do different searches on the forum. If someone could point me to the thread that talks about it regards i would appreciate it.
My host dont have cron job. im trying to use cronjobs.org but it doesn't run it.
-
This doesnt work for me, I get a white screen then nothing happens when I run the script in IE. Am I supposed to run it some other way?
Got it to work on another PC! :)
-
instead of calling dointerest.php from inside Sources/Shop
I used this file and setup the absolute path to SSI.php and placed it inside Sources/shop and saved it as interest.php and made a cron using interest.php and it seems to work. Could there be an issue with dointerest.php that comes with the package? I am using 3.0 by the way
-
I've been fighting with interest for 2 weeks now. For some reason no matter what I did I couldn't get the cron job to work from CPanel. Anyhow... I just found this thread, made my cronjob at http://www.onlinecronjobs.com (free) and tada! Instant interest!
I had to share since the site allows you to test your cron jobs so you don't have to wait 24 hours to check if it works. Thought you all would be interested.
Now I'm gonna see if I can set it that way with the Lottery job too. Will let you know if that works. :smitten:
-
got it working!!!
great!