Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Steev

Pages: [1]
1
General SMFShop Discussion / Re: Variable Restock Rates
« on: April 15, 2007, 10:38:36 am »
Yeah, I've been working on setting up the forum/mod.  The forum is working fine, but for some reason I can't seem to get any mods installed on the new forum (keep getting errors about the directory not being writable, when it doesn't time out)....but I didn't know about test_modification.php.  Thanks for that advice. :)

2
Yeah, I've been having issues with Cron on my server as well (playing with my stock)...I had to use /usr/local/bin/php for my php command.  I also had to change the include("../../SSI.php") line to have the full path to the SSI.php, as the include-path apparently treated the . directory as the /usr/local/bin, not as the directory of the php file I was running.

So I'd suggest the command be the following:
/usr/local/bin/php -q /home/mortgago/domains/[your domain]/public_html/Sources/shop/dointerest.php.


Mind, the part after the -q should be the actual path to your dointerest.php.  I'm assuming that the path above is correct, based on the errors you were showing.

Also, based on those, double check the dointerest.php file...that first error looks like you might be missing a '<' at the very first character of the file, somehow.


EDIT: Missed that daniel15 suggested the exact same thing...oops.  Sorry for the duplicate info.

3
General SMFShop Discussion / Re: Variable Restock Rates
« on: April 13, 2007, 08:55:57 am »
Good to hear.  Did you install it as a package, or did you do the modifications manually?   I haven't had a chance to try the package installer on it yet; I'm intending on creating a junk install of SMF with the shop tonight to try it out on, but I'm curious. :)

4
General SMFShop Discussion / Re: Forum Permissions
« on: April 13, 2007, 05:01:32 am »
Yeah, there should be an option in the 'modify' section of each board you set up.  Right now, it's just a checkbox--recieve points or not. 

Next version of SMFShop should allow you to choose a different number of points for each board.

5
General SMFShop Discussion / Variable Restock Rates
« on: April 12, 2007, 11:12:32 pm »
I have just uploaded Release Candidate 1 of my Variable Restock Rates mod for SMFShop to http://dev.dansoftaustralia.net/projects/varrestocks/.  I would appreciate any comments or suggestions you may have.

NOTE
While I have tested the code itself, and all appears to work, I have not yet tested the .xml files used to add the package automatically.  If you use these, make backups of affected files.

Affected Files
ShopAdmin.template.php
ShopAdmin.php
Shop.english.php
item_engine.php

New Files
dostock.php

readme.txt
This modification makes an additional method of restocking the SMFShop, allowing to automatically stock at a certain rate, up to a specified maximum value.  Each item in the shop can have it's own configured restock rate.

Changelog:
==================
Version 1.0 (RC1)
- Added the ability to reset stocking periods.
- Changed dostock.php so that it will reduce to max_stock even if stock_period hasn't arrived.
- Wrote an uninstall script that will remove database fields if run.

Version 0.1
- First version
- Added new database configuration to allow for automatic restocking.
- Added new file, dostock.php, which will do the automatic stocking.  Requires a cron job to run successfully.
- Altered administration files to show restock options.
- Altered item_engine.php to add restock variables.
- Added new elements to Shop.english.php.
- Default Values: 50 Max Stock, 50 Restock Rate, 1 Hour Intervals


6
Coding / Re: Several Modification Ideas
« on: April 11, 2007, 03:18:10 am »
New question, same topic, and again, a thanks in advance for the help.

In ShopAdmin.template.php, I have the following:
Code: [Select]
<table>
<tr>
<td align="right"><label for="itemname">', $txt['shop_name'], ':</label></td>
<td><input name="itemname" id="itemname" type="text" value="', $context['shop_edit']['name'], '" size="80"  style="width: 100%" /></td>
</tr><tr>
<td align="right" valign="top"><label for="itemdesc">', $txt['shop_description'], ':</label></td>
<td><textarea name="itemdesc" id="itemdesc" cols="40" rows="6" style="width: 100%">', $context['shop_edit']['desc'], '</textarea></td>
</tr><tr>
<td align="right"><label for="itemprice">', $txt['shop_price'], ':</label></td>
<td>', $modSettings['shopCurrencyPrefix'], '<input name="itemprice" id="itemprice" type="text" value="', $context['shop_edit']['price'], '" size="5" />', $modSettings['shopCurrencySuffix'], '</td>
</tr><tr>
<td align="right"><label for="itemstock">', $txt['shop_stock'], ':</label></td>
<td><input name="itemstock" id="itemstock" type="text" value="', $context['shop_edit']['stock'], '" size="5" /></td>
</tr>';
//BEGIN CODE ADDED FOR Variable Restock Rates
echo '<tr>
<td align="right"><label for="stock_period">', $txt['shop_stock_period'], ':</label></td>
<td><input name="stock_period" id="stock_period" type="text" value="', $context['shop_item']['stock_period'], '"size="5" /></td>
</tr><tr>
<td align="right"><label for="stock_add">', $txt['shop_stock_add'], ':</label></td>
<td><input name="stock_add" id="stock_add" type="text" value="', $context['shop_item']['stock_add'], '"size="5" /></td>
</tr><tr>
<td align="right"><label for="max_stock">', $txt['shop_max_stock'], ':</label></td>
<td><input name="max_stock" id="max_stock" type="text" value="', $context['shop_item']['max_stock'], '"size="5" /></td>
</tr>';
//END CODE ADDED FOR Variable Restock Rates
echo '<tr>
<td align="right"><label for="cat">', $txt['shop_category'], ':</label></td>
<td>
The form continues, but that gets all of my stuff in there.

In ShopAdmin.php, I have the following:\
Code: [Select]
// Update the item information
// QUERY UPDATED FOR Variable Restock Rates
db_query("
UPDATE {$db_prefix}shop_items
SET name = '{$_POST['itemname']}',
`desc` = '{$_POST['itemdesc']}',
price = {$_POST['itemprice']},
stock = {$_POST['itemstock']},
image = '{$_POST['icon']}',
delete_after_use = {$delete},
category = {$_POST['cat']},
stock_period = {$_POST['stock_period']},
stock_add = {$_POST['stock_add']},
max_stock = {$_POST['max_stock']},
{$additional}
WHERE id = {$_POST['id']}
LIMIT 1", __FILE__, __LINE__);

When I run it, it lets me get to the edit page, but the three new text fields are empty.  And when I click Edit, I get a MYSQL error at the end of that ShopAdmin.php block.

I know I have some $context stuff in the template; did I miss a location where I need to add this data?  I'm assuming that it's the $context being missing that's causing data to not make it over to the query, which is causing the query to fail.  Can anyone help?

Edit: Removed extra tabs.

EditX2: Fixed the issue.  It was two problems rolled into one.  I was using $context['shop_item'] instead of ['shop_edit'] in the template, and I had an extra comma in the query, since $additional begins with a comma if it's needed.

I've now got this installed on my site, and things are working swimmingly at the moment.  Thanks again.

7
Coding / Re: Several Modification Ideas
« on: April 10, 2007, 09:21:51 pm »
Fair enough.  I've been marking my changes too (6 years in software development almost force you to), but the diff in EditPadPro gives me a quick glance at the changes to make it even easier. :)

Thanks for the help, guys.

8
Coding / Re: Several Modification Ideas
« on: April 10, 2007, 12:57:57 pm »
I've made a project for the Variable Restock Rates, and will probably be making another one shortly for the Resellable items...but I have one question, since these are my first SMF mods...

Is there an easy way to make the .xml files for the install, or do I have to do the diffs and copy-paste everything manually?

9
Coding / Re: Several Modification Ideas
« on: April 08, 2007, 11:12:10 am »
Awesome.  I'll have to grab the dev version, then. :)  Out of curiosity, are the bonuses per board as well, or just the base points?  I have all the bonuses at 0, so it doesn't matter either way, but I'm curious.

I've grabbed the coding guidelines, but not until after I wrote that code.  I think I got most of it, though.

10
Coding / Re: Several Modification Ideas
« on: April 07, 2007, 05:33:03 am »
I was working on the variable restock rates today.  Here's what I've come up with so far.

First, the install, adding 4 columns to the shop_items table.
Code: [Select]
<?php
// Variable Restock SMFShop Mod installation script (Build 1)
// Some code taken from SMFShop install.php by Daniel15
//Build 1 (6 April 2007, 14:35, GMT -5)

if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
// Hmm... no SSI.php and no SMF?
elseif (!defined('SMF'))
die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');

$result db_query("SHOW COLUMNS FROM {$db_prefix}shop_items LIKE 'stock_period'"__FILE____LINE__);
if (
mysql_num_rows($result) == 0
ALTER TABLE {$db_prefix}shop_items ADD `stock_periodTINYINT(4UNSIGNED DEFAULT '1' NOT NULL", __FILE__, __LINE__);

$result = db_query("SHOW COLUMNS FROM {$db_prefix}shop_items LIKE 'stock_add'", __FILE__, __LINE__);
if (mysql_num_rows(
$result) == 0) 
ALTER TABLE 
{$db_prefix}shop_items ADD `stock_add` TINYINT(4) UNSIGNED DEFAULT '50' NOT NULL"__FILE____LINE__);

$result db_query("SHOW COLUMNS FROM {$db_prefix}shop_items LIKE 'max_stock'"__FILE____LINE__);
if (
mysql_num_rows($result) == 0
ALTER TABLE {$db_prefix}shop_items ADD `max_stockTINYINT(4UNSIGNED DEFAULT '50' NOT NULL", __FILE__, __LINE__);

$result = db_query("SHOW COLUMNS FROM {$db_prefix}shop_items LIKE 'last_stocked'", __FILE__, __LINE__);
if (mysql_num_rows(
$result) == 0) 
ALTER TABLE 
{$db_prefix}shop_items ADD `last_stocked` INT(10) UNSIGNED DEFAULT '0' NOT NULL"__FILE____LINE__);

?>

Then, a new file, which I've named dostock.php.
Code: [Select]
<?php
// Modification for:

/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
|         (c) 2005 DanSoft Australia           |
|      http://www.dansoftaustralia.com/        |
\**********************************************/

//File: dostock.php
//      The file to check stock levels and increase, if needed.
//Build 1 (6 April 2007, 14:35, GMT -5)

// A cron job should be set up to run this file every hour.
// This file checks the current shop stock levels, and increases them
// if the appropriate time has come.  Will also decrease to desired
// maximum levels.

if(!isset($_SERVER["HTTP_HOST"])) 
{

include("../../SSI.php");

$result db_query("
SELECT id, stock, stock_period, stock_add, max_stock, last_stocked
FROM 
{$db_prefix}shop_items" __FILE____LINE__);

// There should be multiple rows.
while ($row mysql_fetch_assoc($result))
{
$id $row['id']
$current_stock $row['stock'];
$stock_period $row['stock_period'];
$stock_add $row['stock_add'];
$max_stock $row['max_stock'];
$last_stocked $row['last_stocked'];

// Check if we need to restock the item.
$current_time time();
$period_seconds $stock_period 60 60// 60 seconds by 60 minutes by hours.
if ($current_time >= $last_stocked $period_seconds)
{
// We have passed our stock period.
// Check to see if our current stock is less than we're willing to keep around.
if ($current_stock $max_stock)
{
// It is, so add some.
$current_stock $current_stock $stock_add;
// if ($current_stock < $max_stock)
// if ($current_time >= $last_stocked + $period_seconds)
// Now make sure we're not over the most we want to hold.
$current_stock $current_stock $max_stock $max_stock $current_stock// Limit to max stock.

// Update the table with the new information.
$result2 db_query ("
UPDATE 
{$db_prefix}shop_items
SET stock = 
{$current_stock},
last_stocked=
{$current_time}
WHERE id=
$id__FILE____LINE__);

// Sanity check on table update?
// if (mysql_affected_rows ($result2) != 1) echo 'ERROR DETECTED<br>';
// This is set to be a cron, so no output needed.  Sanity check skipped.

mysql_free_result($result2);
// while ($row = mysql_fetch_assoc($result))

mysql_free_result($result);

// if(!isset($_SERVER["HTTP_HOST"])) 
?>


Obviously, this isn't yet complete--options for those four would need to be added to the admininstration section, and probably the item_engine as well.  But as I got that far, I realized there was one thing I didn't know.

$context seems to be used everywhere.  As you can see, I've used individual variables, as that's how I'm used to doing PHP.  How is $context supposed to be used?

11
Coding / Several Modification Ideas
« on: April 06, 2007, 08:52:35 am »
Some of these I've noticed are repeats from other threads, but not all of them, and since I had them handwritten as ideas, I'm including them all for completeness.

1) Points per post By Board
This would require in the "Modify Boards" section of the ACP change the "Count Shop Posts" into a "Points per Post".  It shouldn't be too hard of a change; the big change is altering the Boards table so that it has a MoneyPerPost smallint(5) field; but I'm probably missing something on that regard.

2) Sellable Items
Each item should have a sale price and an OnSale() function.  The function would probably only add the money to their inventory and remove the item.  Perhaps an option to allow sold items to return to the store inventory or not?

3) Items by Usergroup
I'd like to see a way to make an item limited to certain usergroups.  Buying, using, or both.  This one, though, I have absolutely no idea how to go about it, at the moment.

4) Variable Restock Rates
A couple more variables--TimeToRestock, MaxStock, EachStock.  A new field in the shop's inventory would have a LastRestocked time.  A cron job would probably be needed so that every hour it would check the last restocks against the time to restock, and if it's been at least TimeToRestock hours, it increases the shop's stock by EachStock, up to a maximum of MaxStock.  I've got a good idea of how to do this, but I see it being fairly complicated and will take some time to do.

5) Destruction Changes / Charged Items
Instead of just a static delete_on_use variable, there should be a OnCleanUp() function; a counter should be added to the inventory field as well for charged items.  The OnCleanUp() function would decide whether and how to remove the item; for instance, if the counter has reached 0, or a random chance is met.  I recently created an item with three options; on three of them, it would get deleted, and it would stay on the other three.  This would be optimal for items like that.

If anyone has already finished these, or has more ideas of how to implement them, I'd be appreciative.

Pages: [1]