Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * User Shops v1.00
- * This module is a free
- * addon for mccodes v2
- */
- require(__DIR__.'/globals.php');
- $getshops = $db->query("SELECT `id`,`name`,`desc`,`pic`,`status`,`owner` FROM `usershops` ORDER BY `cdate` DESC");
- if(!$db->num_rows($getshops))
- echo "There are no player shops.";
- else
- {
- if(isset($_GET['enter']))
- {
- $_GET['enter'] = isset($_GET['enter']) && ctype_digit($_GET['enter']) ? abs(intval($_GET['enter'])) : 0;
- if(empty($_GET['enter']))
- echo "Invalid.";
- else
- {
- $usershop = $db->query("SELECT `id`,`name`,`status`,`owner` FROM `usershops` WHERE `id` = {$_GET['enter']}");
- if(!$db->num_rows($usershop))
- echo "That's not a real shop.";
- else
- {
- $us = $db->fetch_row($usershop);
- if($us['status'] == 1)
- {
- echo "This users shop is closed for business right now come back when they are open.";
- $h->endpage();
- exit;
- }
- $useritems = $db->query("SELECT * FROM `user_shopitems` WHERE `sID` = {$us['id']}");
- if(!$db->num_rows($useritems))
- echo "This user has nothing in there store.";
- else
- {
- echo "<h3>Viewing Stock of {$us['name']}</h3>";
- while($ui = $db->fetch_row($useritems))
- {
- echo "
- <table width='75%' class='table' style='text-align:center'>
- <tr>";
- if($ui['stype'] == 'item')
- { echo "
- <th>Item</th>
- <th>Qty</th>
- <th>Total Price</th>
- <th>Action</th>";
- }
- else
- { echo "
- <th>Qty</th>
- <th>Total Price</th>
- <th>Action</th>";
- } echo "
- </tr>";
- if($ui['stype'] == 'item')
- $selling = $db->fetch_single(
- $db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$ui['selling']}"));
- echo "
- <tr>";
- if($ui['stype'] == 'item')
- { echo "
- <td>{$selling}</td>
- <td>".number_format($ui['sqty'])."</td>
- <td>".money_formatter($ui['tprice'])."</td>
- <td><a href='shoplist.php?buy={$ui['id']}'>[Buy {$selling}</a></td><br />";
- }
- else
- { echo "
- <td>".number_format($ui['sqty'])." {$ui['stype']}</td>
- <td>".money_formatter($ui['tprice'])."</td>
- <td><a href='shoplist.php?buy={$ui['id']}'>[Buy]</a></td><br />";
- } echo "
- </tr>";
- }
- echo "</table>";
- }
- }
- }
- }
- else if(isset($_GET['buy']))
- {
- $_GET['buy'] = isset($_GET['buy']) && ctype_digit($_GET['buy']) ? abs(intval($_GET['buy'])) : 0;
- if(empty($_GET['buy']))
- echo "Invalid.";
- else
- {
- $itm_check = $db->query("SELECT * FROM `user_shopitems` WHERE `id` = {$_GET['buy']}");
- if(!$db->num_rows($itm_check))
- echo "Invalid Item.";
- else
- {
- $itm_ret = $db->fetch_row($itm_check);
- $select = $db->query("SELECT `owner` FROM `usershops` WHERE `id` = {$itm_ret['sID']}");
- $owner = $db->fetch_row($select);
- $cost = $itm_ret['tprice'];
- if($ir['money'] < $cost)
- echo "You don't have enough money you need ".money_formatter($cost - $ir['money'])." more";
- else
- {
- if($itm_ret['stype'] == 'item')
- {
- $itmname = $db->fetch_single($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$itm_ret['selling']}"));
- item_add($itm_ret['selling'], $ir['userid'], $itm_ret['sqty']);
- $db->query("UPDATE `users` SET `money` = `money` - {$cost} WHERE `userid` = {$ir['userid']}");
- $db->query("UPDATE `users` SET `money` = `money` + {$cost} WHERE `userid` = {$owner['owner']}");
- echo "You purchased ".number_format($itm_ret['sqty'])." of {$itmname} for ".money_formatter($itm_ret['tprice']);
- $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$itm_ret['id']}");
- }
- else if($itm_ret['stype'] == 'crystals')
- {
- $db->query("UPDATE `users` SET `money` = `money` - {$cost} WHERE `userid` = {$ir['userid']}");
- $db->query("UPDATE `users` SET `money` = `money` + {$cost} WHERE `userid` = {$owner['owner']}");
- $db->query("UPDATE `users` SET `crystals` = `crystals` + {$itm_ret['sqty']} WHERE `userid` = {$ir['userid']}");
- echo "You purchased ".number_format($itm_ret['sqty'])." Crystal's for ".money_formatter($itm_ret['tprice']);
- $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$itm_ret['id']}");
- }
- else
- {
- $db->query("UPDATE `users` SET `money` = `money` - {$cost} WHERE `userid` = {$ir['userid']}");
- $db->query("UPDATE `users` SET `money` = `money` + {$cost} WHERE `userid` = {$owner['owner']}");
- $db->query("UPDATE `users` SET `donatordays` = `donatordays` + {$itm_ret['sqty']} WHERE `userid` = {$ir['userid']}");
- echo "You purchased ".number_format($itm_ret['sqty'])." Donator Days for ".money_formatter($itm_ret['tprice']);
- $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$itm_ret['id']}");
- }
- }
- }
- }
- }
- else
- {
- echo "
- <table width='75%' class='table' style='text-align:center'>
- <tr>
- <th>Pic</th>
- <th>Shop Name</th>
- <th>Status</th>
- <th>Action</th>
- </tr>";
- while($shop = $db->fetch_row($getshops))
- {
- if($shop['status'] == 1)
- $status = "<span style='color:red'>Closed</span>";
- else
- $status = "<span style='color:green'>Open</span>";
- echo "
- <tr>
- <td><img src='{$shop['pic']}' width='200px' height='70px' /></td>
- <td>{$shop['name']}</td>
- <td>{$status}</td>
- <td><a href='shoplist.php?enter={$shop['id']}'>[Enter Shop]</a></td>
- </tr>";
- }
- echo "</table>";
- }
- }
- $h->endpage();
Advertisement
Add Comment
Please, Sign In to add comment