Hey due to request i recoded the cmarket to set your needs what it dose it when you add crystals you choose 1 5 10 days after they days are up it returnes the crystals and deletes from market also i have added a way they can only add 3 crystal sales at a time
Replace cmarket.php
with this
<?php
include "globals.php";
print "<h3>Crystal Market</h3>";
switch($_GET['action'])
{
case "buy":
crystal_buy();
break;
case "remove":
crystal_remove();
break;
case "add":
crystal_add();
break;
default:
cmarket_index();
break;
}
function cmarket_index()
{
global $db,$ir,$c,$userid,$h;
print "<a href='cmarket.php?action=add'>> Add A Listing</a><br /><br />
Viewing all listings...
<table width=75% cellspacing=1 class='table'> <tr style='background:gray'> <th>Adder</th> <th>Qty</th> <th>Price each</th> <th>Days Left</th> <th>Price total</th> <th>Links</th> </tr>";
$q=$db->query("SELECT cm.*, u.* FROM crystalmarket cm LEFT JOIN users u ON u.userid=cm.cmADDER ORDER BY cmPRICE/cmQTY ASC");
while($r=$db->fetch_row($q))
{
if($r['cmADDER'] == $userid) { $link = "<a href='cmarket.php?action=remove&ID={$r['cmID']}'>Remove</a>"; } else { $link = "<a href='cmarket.php?action=buy&ID={$r['cmID']}'>Buy</a>"; }
$each= (int) $r['cmPRICE'] / $r['cmQTY'];
print "\n<tr> <td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]</td> <td>{$r['cmQTY']}</td> <td> \$" . number_format($each)."</td> <td>{$r['cmDAYS']} Days.</td> <td>\$".number_format($r['cmPRICE'])."</td> <td>[$link]</td> </tr>";
}
print "</table>";
}
function crystal_remove()
{
global $db,$ir,$c,$userid,$h;
$q=$db->query("SELECT * FROM crystalmarket WHERE cmID={$_GET['ID']} AND cmADDER=$userid");
if(!$db->num_rows($q))
{
print "Error, either these crystals do not exist, or you are not the owner.<br />
<a href='cmarket.php'>> Back</a>";
$h->endpage();
exit;
}
$r=$db->fetch_row($q);
$db->query("UPDATE users SET crystals=crystals+{$r['cmQTY']} where userid=$userid");
$db->query("DELETE FROM crystalmarket WHERE cmID={$_GET['ID']}");
print "Crystals removed from market!<br />
<a href='cmarket.php'>> Back</a>";
}
}
function crystal_buy()
{
global $db,$ir,$c,$userid,$h;
$q=$db->query("SELECT * FROM crystalmarket cm WHERE cmID={$_GET['ID']}");
if(!$db->num_rows($q))
{
print "Error, either these crystals do not exist, or they have already been bought.<br />
<a href='cmarket.php'>> Back</a>";
$h->endpage();
exit;
}
$r=$db->fetch_row($q);
if($r['cmPRICE'] > $ir['money'])
{
print "Error, you do not have the funds to buy these crystals.<br />
<a href='cmarket.php'>> Back</a>";
$h->endpage();
exit;
}
$db->query("UPDATE users SET crystals=crystals+{$r['cmQTY']} where userid=$userid");
$db->query("DELETE FROM crystalmarket WHERE cmID={$_GET['ID']}");
$db->query("UPDATE users SET money=money-{$r['cmPRICE']} where userid=$userid");
$db->query("UPDATE users SET money=money+{$r['cmPRICE']} where userid={$r['cmADDER']}");
event_add($r['cmADDER'],"<a href='viewuser.php?u=$userid'>{$ir['username']}</a> bought your {$r['cmQTY']} crystals from the market for \$".number_format($r['cmPRICE']).".",$c);
print "You bought the {$r['cmQTY']} crystals from the market for \$".number_format($r['cmPRICE']).".";
}
function crystal_add()
{
global $db,$ir,$c,$userid,$h;
$_POST['amnt'] = abs((int) $_POST['amnt']);
$_POST['price'] = abs((int) $_POST['price']);
if($_POST['amnt'])
{
if($_POST['amnt'] > $ir['crystals'])
{
die ("You are trying to add more crystals to the market than you have.");
}
$b=$db->query("SELECT * FROM crystalmarket WHERE cmADDER=$userid");
if ($db->num_rows($b) > 2)
{
die("<center>You Are Only Allowed 3 Crystal Sales At A Time<br><a href='cmarket.php?action=add'> Back</a>");
}
$tp=$_POST['amnt']*$_POST['price'];
$db->query("INSERT INTO crystalmarket VALUES('',{$_POST['amnt']},$userid,$tp,{$_POST['days']})");
$db->query("UPDATE users SET crystals=crystals-{$_POST['amnt']} WHERE userid=$userid");
print "Crystals added to market!<br />
<a href='cmarket.php'>> Back</a>";
}
else
{
print "<b>Adding a listing...</b><br /><br />
You have <b>{$ir['crystals']}</b> crystal(s) that you can add to the market.<form action='cmarket.php?action=add' method='post'><table width=50% border=2><tr>
<td>Crystals:</td> <td><input type='text' name='amnt' value='{$ir['crystals']}' /></td></tr><tr>
<td>Price Each:</td> <td><input type='text' name='price' value='200' /></td></tr><tr>
<td>Days:</td> <td><select type='dropdown' name='days' value='{$ir['cmDAYS']}' />><br />
<option value='1'>1
<option value='5'>5
<option value='10'>10</select>
</tr>
<td colspan=2 align=center><input type='submit' value='Add To Market' /></tr></table></form>";
}
}
$h->endpage();
?>
add the to your
cron_hour.php
$db->query("UPDATE crystalmarket SET cmDAYS = cmDAYS - 1 WHERE cmDAYS > 0");
if($r['cmDAYS'] == 0)
{
$q=$db->query("SELECT cm.*, u.* FROM crystalmarket cm LEFT JOIN users u ON u.userid=cm.cmADDER ORDER BY cmPRICE/cmQTY ASC");
while($r=$db->fetch_row($q))
{
$q=$db->query("SELECT * FROM crystalmarket WHERE cmID={$r['cmID']} AND cmADDER={$r['userid']}");
$r=$db->fetch_row($q);
$db->query("UPDATE users SET crystals=crystals+{$r['cmQTY']} WHERE userid={$r['cmADDER']}");
$db->query("DELETE FROM crystalmarket WHERE cmID={$r['cmID']}");
}
}
add this to your DB
SQL
ALTER TABLE `crystalmarket` ADD `cmDAYS` INT( 11 ) NOT NULL DEFAULT '1';
Add Your Done.
any bugs message me but has been tested
adding the itemmarket 1 soon