GregFest Posted January 4, 2012 Share Posted January 4, 2012 when adding a item to the market you have 2 options 1 money 2 crystals. well players select money and then they post item. when you go to item market it only shows in crystals. and when u have a load of crystals to buy that item you cant, due to "Error, you do not have the funds to buy this item. ". if anyone can help it would be great full. Quote Link to comment Share on other sites More sharing options...
GregFest Posted January 4, 2012 Author Share Posted January 4, 2012 imadd.php <?php /* Engine: MC V2.5 (Redux) File: imadd.php Author: mccodes.com */ if ( !defined($_CONFIG['define_code']) ) { echo 'This file cannot be accessed directly.'; exit; } $_GET['ID'] = ( isset($_GET['ID'])&&is_numeric($_GET['ID']) )?abs(intval($_GET['ID'])):''; $_GET['price'] = ( isset($_GET['price'])&&is_numeric($_GET['price']) )?abs(intval($_GET['price'])):''; $_GET['QTY'] = ( isset($_GET['QTY'])&&is_numeric($_GET['QTY']) )?abs(intval($_GET['QTY'])):''; $_GET['currency'] = ( isset($_GET['currency']) && in_array($_GET['currency'], array('main','second')) )?$_GET['currency']:'main'; if ( $_GET['price'] && $_GET['QTY'] && $_GET['ID'] ) { $q=$db->query("SELECT iv.`inv_qty`, `inv_itemid`, `inv_id`, i.`itmname` FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid WHERE inv_id={$_GET['ID']} and inv_userid=$userid"); if($db->num_rows($q) == 0) { echo "Invalid Item ID"; } else { $r = $db->fetch_row($q); if ( $r['inv_qty'] < $_GET['QTY'] ) { echo 'You do not have enough of this item.'; $h->endpage(); exit; } $checkq = $db->query('SELECT `imID` FROM `itemmarket` WHERE `imITEM` = '.$r['inv_itemid'].' AND `imPRICE` = "'.$_GET['price'].'" AND `imADDER` = '.$userid.' AND `imCURRENCY` = "'.$_GET['currency'].'"'); if ( $db->num_rows($checkq) ) { $cqty = $db->fetch_row($checkq); $query = sprintf('UPDATE `itemmarket` SET imQTY = imQTY + %u WHERE imID = %u', $_GET['QTY'], $cqty['imID']); $db->query($query); } else { $db->query("INSERT INTO itemmarket VALUES ('','{$r['inv_itemid']}',$userid,{$_GET['price']}, '{$_GET['currency']}', '{$_GET['QTY']}')"); } item_remove($userid, $r['inv_itemid'], $_GET['QTY']); $db->query("INSERT INTO imarketaddlogs VALUES ( '', {$r['inv_itemid']}, {$_GET['price']}, {$r['inv_id']}, $userid, unix_timestamp(), '{$ir['username']} added {$r['itmname']} x{$_GET['QTY']} to the itemmarket for {$_GET['price']} {$_GET['currency']}')"); echo "Item added to market."; } } else { if ( empty($_GET['ID']) ) { echo 'A error occured, please go back and try again.'; die($h->endpage()); } $q = $db->query("SELECT `inv_id` FROM `inventory` WHERE `inv_id` = {$_GET['ID']} AND `inv_userid` = $userid"); if ( $db->num_rows($q) == 0 ) { echo 'Invalid Item ID'; } else { echo ' Adding an item to the item market... <form action="index.php" method="get"> '.gen_url('imadd','hidden').' <input type="hidden" name="ID" value="'.$_GET['ID'].'" /> <br> Quantity: <input type="text" name="QTY" value=""> <br> Price: <input type="text" name="price" value="0" /> <br> <select name="currency" type="dropdown"> <option value="main">'.$set['main_currency'].'</option> <option value="second">'.$set['second_currency'].'</option> </select> <br /> <input type="submit" value="Add" /> </form> '; } } $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
GregFest Posted January 4, 2012 Author Share Posted January 4, 2012 (edited) itemmarket.php <?php /* Engine: MC V2.5 (Redux) File: itemmarket.php Author: mccodes.com */ if ( !defined($_CONFIG['define_code']) ) { echo 'This file cannot be accessed directly.'; exit; } echo "<h3>Item Market</h3>"; switch($_GET['action']) { case "buy": item_buy(); break; case "gift1": item_gift1(); break; case "gift2": item_gift2(); break; case "remove": itemm_remove(); break; default: imarket_index(); break; } function imarket_index() { global $db,$ir,$c,$userid,$h,$set; echo ' <br /> <table width="100%" cellspacing="1" cellpadding="1" class="table" align="center"> <tr> <th width="25%">Adder</th> <th width="25%">Item</th> <th width="20%">Price Each</th> <th width="20%">Price Total</th> <th width="10%">Links</th> </tr> '; $q = $db->query("SELECT im.`imPRICE`,`imQTY`,`imCURRENCY`,`imADDER`,`imID`, i.`itmid`,`itmname`, u.`userid`,`username`, it.`itmtypename` FROM `itemmarket` im LEFT JOIN `items` i ON im.`imITEM` = i.`itmid` LEFT JOIN `users` u ON u.`userid` = im.`imADDER` LEFT JOIN `itemtypes` it ON i.`itmtype` = it.`itmtypeid` ORDER BY i.`itmtype`, i.`itmname`, u.`username` ASC"); $cblah = 1; $lt = ''; while ( $r = $db->fetch_row($q) ) { if ( $lt != $r['itmtypename'] ) { $lt = $r['itmtypename']; echo ' <tr> <th colspan="5" align="center">'.$lt.'</th> </tr> '; } $ctprice = ($r['imPRICE'] * $r['imQTY']); if($r['imCURRENCY'] == "main") { $price = money_formatter($r['imPRICE'], '$'); $tprice = money_formatter($ctprice, '$'); } else { $price = number_format($r['imPRICE'])." ".$set['second_currency']; $tprice = number_format($ctprice)." ".$set['second_currency']; } if($r['imADDER'] == $userid) { $link = "[<a href='".gen_url('itemmarket',true)."&action=remove&ID={$r['imID']}'>Remove</a>]"; } else { $link = "[<a href='".gen_url('itemmarket',true)."&action=buy&ID={$r['imID']}'>Buy</a>] [<a href='".gen_url('itemmarket',true)."&action=gift1&ID={$r['imID']}'>Gift</a>]"; } echo ' <tr> <td><a href="'.gen_url('viewuser',true).'&u='.$r['userid'].'">'.$r['username'].'</a> ['.$r['userid'].']</td> <td><a href="'.gen_url('iteminfo',true).'&ID='.$r['itmid'].'">'.$r['itmname'].'</a> '; if ($r['imQTY'] > 1) { echo ' x'.$r['imQTY']; } echo ' </td> <td>'.$price.'</td> <td>'.$tprice.'</td> <td>'.$link.' '; if($ir['user_level'] == '2') { echo ' <br> [<a href="?action=quantify&ID='.$r['imID'].'">Merge</a>] '; } echo ' </td> </tr> '; } echo ' </table> '; } function itemm_remove() { global $db,$ir,$userid,$h,$set; $_GET['ID'] = ( isset($_GET['ID'])&&is_numeric($_GET['ID']) )?abs(intval($_GET['ID'])):''; if ( empty($_GET['ID']) ) { echo 'Something went wrong.<br />> <a href="'.gen_url('itemmarket',true).'" alt="Go Back" title="Go Back">Go Back</a>'; die($h->endpage()); } $q = $db->query("SELECT im.`imITEM`, `imQTY`, `imADDER`, `imID`, i.`itmname` FROM `itemmarket` im LEFT JOIN `items` i ON im.`imITEM`=i.`itmid` WHERE im.`imID` = {$_GET['ID']} AND im.`imADDER` = $userid"); if(!$db->num_rows($q)) { echo "Error, either this item does not exist, or you are not the owner. <br /> <a href='".gen_url('itemmarket',true)."'>> Back</a> "; die($h->endpage()); } $r = $db->fetch_row($q); item_add($userid, $r['imITEM'], $r['imQTY']); $i = ($db->insert_id()) ? $db->insert_id() : 99999; $db->query("DELETE FROM `itemmarket` WHERE `imID`={$_GET['ID']}"); $db->query("INSERT INTO `imremovelogs` VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} removed {$r['itmname']} x {$r['imQTY']} from the item market.')"); echo ' Item removed from market! <br /> <a href="'.gen_url('itemmarket',true).'">> Back</a> '; } function item_buy() { global $db,$ir,$c,$userid,$h,$set; $_GET['ID'] = ( isset($_GET['ID'])&&is_numeric($_GET['ID']) )?abs(intval($_GET['ID'])):''; $_POST['QTY'] = ( isset($_POST['QTY'])&&is_numeric($_POST['QTY']) )?abs(intval($_POST['QTY'])):''; if ( $_GET['ID'] AND !$_POST['QTY'] ) { $q = $db->query("SELECT im.`imADDER`, `imCURRENCY`, `imPRICE`, `imQTY`, `imITEM`, `imID`, i.`itmname` FROM `itemmarket` im LEFT JOIN `items` i ON i.`itmid` = im.`imITEM` WHERE im.`imID`={$_GET['ID']}"); $r = $db->fetch_row($q); echo ' Enter how many <b>'.$r['itmname'].'</b> you want to buy. <br> There is <b>'.$r['imQTY'].'</b> available. <br> <form action="'.gen_url('itemmarket',true).'&action=buy&ID='.$_GET['ID'].'" method="post"> Quantity: <input type="text" name="QTY" value=""> <br> <input type="submit" value="Buy"> </form> '; } elseif ( !$_GET['ID'] ) { echo 'Invalid use of file.'; } else { $q = $db->query("SELECT im.`imADDER`, `imCURRENCY`, `imPRICE`, `imQTY`, `imITEM`, `imID`, i.`itmname` FROM `itemmarket` im LEFT JOIN `items` i ON i.`itmid` = im.`imITEM` WHERE im.`imID`={$_GET['ID']}"); if ( !$db->num_rows($q) ) { echo ' Error, either this item does not exist, or it has already been bought. <br /> > <a href="'.gen_url('itemmarket',true).'">Back</a> '; die($h->endpage()); } $r = $db->fetch_row($q); if($r['imADDER'] == $userid) { echo ' Error, you cannot buy you\'re own items.<br> > <a href="'.gen_url('itemmarket',true).'">Back</a> '; die($h->endpage()); } if($_GET['ID'] AND $_POST['QTY']) { $curr = $r['imCURRENCY']; $r['imPRICE'] = $r['imPRICE']*$_POST['QTY']; } if($r['imPRICE'] > $ir[$curr]) { echo ' Error, you do not have the funds to buy this item. <br /> > <a href="'.gen_url('itemmarket',true).'">Back</a> '; die($h->endpage()); } if($_POST['QTY'] > $r['imQTY']) { echo ' Error, you cannot buy more than <b>'.$r['imQTY'].' '.$r['itmname'].'(s)</b> <br> > <a href="'.gen_url('itemmarket',true).'&action=buy&ID='.$_GET['ID'].'">Back</a> '; die($h->endpage()); } item_add($userid, $r['imITEM'], $_POST['QTY']); $i = ($db->insert_id()) ? $db->insert_id() : 99999; if($_POST['QTY'] == $r['imQTY']) { $db->query("DELETE FROM `itemmarket` WHERE `imID` = {$_GET['ID']}"); } elseif ( $_POST['QTY'] < $r['imQTY'] ) { $db->query('UPDATE `itemmarket` SET `imQTY` = `imQTY` - '.$_POST['QTY'].' WHERE imID= '.$_GET['ID']); } $db->query("UPDATE `users` SET `$curr` = `$curr` - {$r['imPRICE']} WHERE `userid` = $userid"); $db->query("UPDATE `users` SET `$curr` = `$curr` + {$r['imPRICE']} WHERE `userid` = {$r['imADDER']}"); if($curr=="main") { event_add($r['imADDER'],"<a href='".gen_url('viewuser',true)."&u=$userid'>{$ir['username']}</a> bought your {$r['itmname']} item from the market for \$".number_format($r['imPRICE']).".",$c); $db->query("INSERT INTO `imbuylogs` VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought {$r['itmname']} x{$r['imQTY']} from the item market for \${$r['imPRICE']} from user ID {$r['imADDER']}')"); echo " You bought the {$r['itmname']} x{$_POST['QTY']} from the market for \$".number_format($r['imPRICE'])."."; } else { event_add($r['imADDER'],"<a href='".gen_url('viewuser',true)."&u=$userid'>{$ir['username']}</a> bought your {$r['itmname']} item from the market for ".number_format($r['imPRICE'])." ".$set['second_currency'].".",$c); $db->query("INSERT INTO `imbuylogs` VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought {$r['itmname']} x{$r['imQTY']} from the item market for {$r['imPRICE']} {$set['second_currency']} from user ID {$r['imADDER']}')"); echo " You bought the {$r['itmname']} x{$_POST['QTY']} from the market for ".number_format($r['imPRICE'])." ".$set['second_currency'].". "; } } } function item_gift1() { global $db,$ir,$c,$userid,$h,$set; $_GET['ID'] = ( isset($_GET['ID'])&&is_numeric($_GET['ID']) )?abs(intval($_GET['ID'])):''; if ( empty($_GET['ID']) ) { echo 'Something went wrong.<br />> <a href="'.gen_url('itemmarket',true).'" alt="Go Back" title="Go Back">Go Back</a>'; die($h->endpage()); } $q = $db->query("SELECT im.`imCURRENCY`, `imPRICE`, `imQTY`, i.`itmname` FROM `itemmarket` im LEFT JOIN `items` i ON i.`itmid` = im.`imITEM` WHERE im.`imID` = {$_GET['ID']}"); if ( !$db->num_rows($q) ) { echo " Error, either this item does not exist, or it has already been bought. <br /> > <a href='".gen_url('itemmarket',true)."'>Back</a> "; die($h->endpage()); } $r = $db->fetch_row($q); $curr = $r['imCURRENCY']; if ( $r['imPRICE'] > $ir[$curr] ) { echo ' Error, you do not have the funds to buy this item. <br /> > <a href="'.gen_url('itemmarket',true).'">Back</a> '; die($h->endpage()); } if ( $curr == "main" ) { echo " Buying the <b>{$r['itmname']}</b> for \$".number_format($r['imPRICE'])." each as a gift. <br /> There is <b>{$r['imQTY']}</b> available. <br /> <form action='".gen_url('itemmarket',true)."&action=gift2' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> User to give gift to: ".user_dropdown($c,'user')." <br /> Quantity: <input type='text' name='QTY' value=''> <br /> <input type='submit' value='Buy Item and Send Gift' /> </form> "; } else { echo " Buying the <b>{$r['itmname']}</b> for ".number_format($r['imPRICE'])." ".$set['second_currency']." each as a gift. <br /> There is <b>{$r['imQTY']}</b> available. <br /> <form action='".gen_url('itemmarket',true)."&action=gift2' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> User to give gift to: ".user_dropdown($c,'user')." <br /> Quantity: <input type='text' name='QTY' value=''> <br /> <input type='submit' value='Buy Item and Send Gift' /> </form> "; } } function item_gift2() { global $db,$ir,$c,$userid,$h,$set; $_POST['QTY'] = ( isset($_POST['QTY'])&&is_numeric($_POST['QTY']) )?abs(intval($_POST['QTY'])):''; $_POST['user'] = ( isset($_POST['user'])&&is_numeric($_POST['user']) )?abs(intval($_POST['user'])):''; $_POST['ID'] = ( isset($_POST['ID'])&&is_numeric($_POST['ID']) )?abs(intval($_POST['ID'])):''; if ( (empty($_POST['ID']) OR empty($_POST['user']) OR empty($_POST['QTY'])) ) { echo 'Something went wrong.<br />> <a href="'.gen_url('itemmarket',true).'" alt="Go Back" title="Go Back">Go Back</a>'; die($h->endpage()); } $query_user_exist = $db->query("SELECT `userid` FROM `users` WHERE `userid` = {$_POST['user']}"); if ( $db->num_rows($query_user_exist) == 0 ) { echo ' User doesn\'t exist. <br /> > <a href="'.gen_url('itemmarket',true).'">Back</a> '; die($h->endpage()); } $q = $db->query("SELECT im.`imADDER`, `imCURRENCY`, `imPRICE`, `imQTY`, `imITEM`, `imID`, i.`itmname` FROM `itemmarket` im LEFT JOIN `items` i ON i.`itmid` = im.`imITEM` WHERE im.`imID` = {$_POST['ID']}"); if ( !$db->num_rows($q) ) { echo ' Error, either this item does not exist, or it has already been bought. <br /> > <a href="'.gen_url('itemmarket',true).'">Back</a> '; die($h->endpage()); } $r = $db->fetch_row($q); if($r['imADDER'] == $userid) { echo ' Error, you cannot buy you\'re own items.<br> > <a href="'.gen_url('itemmarket',true).'">Back</a> '; die($h->endpage()); } $curr = $r['imCURRENCY']; $r['imPRICE'] = $r['imPRICE']*$_POST['QTY']; if($r['imPRICE'] > $ir[$curr]) { echo " Error, you do not have the funds to buy this item. <br /> > <a href='".gen_url('itemmarket',true)."'>Back</a> "; die($h->endpage()); } if($_POST['QTY'] > $r['imQTY']) { echo ' Error, you cannot buy more than <b>'.$r['imQTY'].' '.$r['itmname'].'(s)</b> <br> > <a href="'.gen_url('itemmarket',true).'&action=buy&ID='.$_POST['ID'].'">Back</a> '; die($h->endpage()); } item_add($_POST['user'], $r['imITEM'], $_POST['QTY']); $i = ($db->insert_id()) ? $db->insert_id() : 99999; if ( $_POST['QTY'] == $r['imQTY'] ) { $db->query("DELETE FROM `itemmarket` WHERE `imID` = {$_POST['ID']}"); } elseif ( $_POST['QTY'] < $r['imQTY'] ) { $db->query('UPDATE `itemmarket` SET `imQTY` = `imQTY` - '.$_POST['QTY'].' WHERE `imID` = '.$_POST['ID']); } $db->query("UPDATE `users` SET `$curr` = `$curr` - {$r['imPRICE']} WHERE `userid`= $userid"); $db->query("UPDATE `users` SET `$curr` = `$curr` + {$r['imPRICE']} where `userid` = {$r['imADDER']}"); if($curr=="main") { event_add($r['imADDER'],"<a href='".gen_url('viewuser',true)."&u=$userid'>{$ir['username']}</a> bought your {$r['itmname']} x{$_POST['QTY']} item(s) from the market for \$".number_format($r['imPRICE']).".",$c); event_add($_POST['user'], "<a href='".gen_url('viewuser',true)."&u=$userid'>{$ir['username']}</a> bought you {$r['itmname']} x{$_POST['QTY']} from the item market as a gift.",$c); $u = $db->query("SELECT `username` FROM `users` WHERE `userid` = {$_POST['user']}"); $uname = $db->fetch_single($u); $db->query("INSERT INTO `imbuylogs` VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought {$r['itmname']} x{$r['imQTY']} from the item market for \${$r['imPRICE']} from user ID {$r['imADDER']} as a gift for $uname [{$_POST['user']}]')"); echo " You bought the {$r['itmname']} from the market for \$".number_format($r['imPRICE'])." and sent the gift to $uname. "; } else { event_add($r['imADDER'],"<a href='".gen_url('viewuser',true)."&u=$userid'>{$ir['username']}</a> bought your {$r['itmname']} x{$_POST['QTY']} item(s) from the market for ".number_format($r['imPRICE'])." ".$set['second_currency'].".",$c); event_add($_POST['user'], "<a href='".gen_url('viewuser',true)."&u=$userid'>{$ir['username']}</a> bought you {$r['itmname']} x{$_POST['QTY']} from the item market as a gift.",$c); $u = $db->query("SELECT `username` FROM `users` WHERE `userid` = {$_POST['user']}"); $uname = $db->fetch_single($u); $db->query("INSERT INTO `imbuylogs` VALUES ('', {$r['imITEM']}, {$r['imADDER']}, $userid, {$r['imPRICE']}, {$r['imID']}, $i, unix_timestamp(), '{$ir['username']} bought {$r['itmname']} x{$r['imQTY']} from the item market for {$r['imPRICE']} ".$set['second_currency']." from user ID {$r['imADDER']} as a gift for $uname [{$_POST['user']}]')"); echo " You bought the {$r['itmname']} x{$_POST['QTY']} from the market for ".number_format($r['imPRICE'])." ".$set['second_currency']." and sent the gift to $uname. "; } } $h->endpage(); ?> Edited January 4, 2012 by GregFest Quote Link to comment Share on other sites More sharing options...
GregFest Posted January 4, 2012 Author Share Posted January 4, 2012 FIXED thanks SomeRandomBastard for those words Quote Link to comment Share on other sites More sharing options...
melduk Posted April 4, 2014 Share Posted April 4, 2014 Hey Greg How did you manage to fix this? Any help would be much appreciated! Thanks. Quote Link to comment Share on other sites More sharing options...
classified Posted August 30, 2015 Share Posted August 30, 2015 ive fixed this problem if anyone needs it let me know Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.