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');
- $user_shop = $db->query("SELECT * FROM `usershops` WHERE `owner` = {$ir['userid']}");
- if(!$db->num_rows($user_shop))
- {
- $shop_cost = 250000;
- if($ir['userid'] == 1)
- $shop_cost = 1;
- if(isset($_POST['create']))
- {
- if (!isset($_POST['verf']) || !verify_csrf_code('us_buyshop',stripslashes($_POST['verf'])))
- csrf_error('buyshop');
- if($ir['money'] < $shop_cost)
- {
- echo "You don't have enough money. You need ".money_formatter($shop_cost - $ir['money'])." more.";
- $h->endpage();
- exit;
- }
- $sn = isset($_POST['sname']) && preg_match("/^[a-z0-9_]+([\\s]{1}[a-z0-9_]|[a-z0-9_])+$/i",$_POST['sname'])
- ? $db->escape(strip_tags(stripslashes($_POST['sname']))) : '';
- $sdesc = isset($_POST['sdesc']) ? $db->escape(strip_tags(stripslashes($_POST['sdesc']))) : '';
- $status = isset($_POST['status']) && ctype_digit($_POST['status']) ? abs(intval($_POST['status'])) : 0;
- $pic = isset($_POST['spic']) && is_string($_POST['spic']) ? stripslashes($_POST['spic']) : '';
- if(!empty($pic))
- {
- if(strlen($pic) < 8 || !(substr($pic, 0, 7) == 'http://' || substr($pic, 0, 8 == 'https://')))
- {
- echo "Invalid Image.<br />> <a href='myshop.php'>Go Back</a>";
- $h->endpage();
- exit;
- }
- $sz = get_filesize_remote($pic);
- if($sz <= 0 || $sz >= 1048576)
- {
- echo "Invalid new pic entered.<br />> <a href='myshop.php'>Back</a>";
- $h->endpage();
- exit;
- }
- $image = (@getimagesize($pic));
- if(!is_array($image))
- {
- echo "Invalid Image.<br />> <a href='myshop.php'>Go Back</a>";
- $h->endpage();
- exit;
- }
- }
- if(empty($sn) || empty($sdesc) || empty($status))
- {
- echo "You have missed a required feild.<br />> <a href='myshop.php'>Go Back</a>";
- $h->endpage();
- exit;
- }
- else
- {
- $db->query("UPDATE `users` SET `money` = `money` - {$shop_cost} WHERE `userid` = {$ir['userid']}");
- $db->query("INSERT INTO `usershops` (`name`,`desc`,`pic`,`status`,`owner`,`cdate`) "."
- VALUES('{$sn}','{$sdesc}','{$pic}','{$status}',{$ir['userid']},".time().")");
- echo "You have paid ".money_formatter($shop_cost)." to buy a shop.";
- }
- }
- else
- {
- $code = request_csrf_code('us_buyshop');
- echo "<h3>Create Shop</h3>
- <i>If you wish to create a shop it will cost you ".money_formatter($shop_cost)."</i><br /><br />
- <form method='post'>
- Shop Name: <input type='text' name='sname' /><br /><br />
- Shop Desc: <input type='text' name='sdesc' /><br /><br />
- Shop Pic: <input type='text' name='spic' /><br /><br />
- Shop Closed: <input type='radio' name='status' value='1' checked='checked' />Yes <input type='radio' name='status' value='2' />No<br /><br />
- <input type='hidden' name='verf' value='{$code}' />
- <input type='submit' name='create' value='Create Shop' />
- </form>";
- }
- }
- else
- {
- $us = $db->fetch_row($user_shop);
- if(isset($_POST['addtoshop']))
- {
- $wts = isset($_POST['wts']) && in_array($_POST['wts'], array('item','donatordays','crystals'),true) ? $_POST['wts'] : 'item';
- $itmid = isset($_POST['itmid']) && ctype_digit($_POST['itmid']) ? abs(intval($_POST['itmid'])) : 0;
- $qty = isset($_POST['qty']) && ctype_digit($_POST['qty']) ? abs(intval($_POST['qty'])) : 0;
- $tcost = isset($_POST['tcost']) && ctype_digit($_POST['tcost']) ? abs(intval($_POST['tcost'])) : 0;
- if($_POST['wts'] == 'item')
- {
- if(empty($itmid) || empty($wts) || empty($qty) || empty($tcost))
- {
- echo "Invalid.";
- $h->endpage();
- exit;
- }
- else
- {
- $q = $db->query("SELECT `inv_qty`,`inv_itemid`,`inv_id`,`itmname` FROM `inventory` AS `iv`
- INNER JOIN `items` AS `i` ON `iv`.`inv_itemid` = `i`.`itmid` = {$_POST['itmid']} AND `inv_userid` = $userid");
- if($db->num_rows($q) == 0)
- {
- $db->free_result($q);
- echo "Invalid Item ID. or you don't have any of those.";
- }
- else
- {
- $r = $db->fetch_row($q);
- $db->free_result($q);
- if($r['inv_qty'] < $_POST['qty'])
- {
- echo 'You do not have enough of this item.';
- $h->endpage();
- exit;
- }
- $checkq = sprintf(
- 'SELECT `id`,`sID` FROM `user_shopitems` WHERE `selling` = %u AND `tprice` = %u AND `sID` = %u',
- $r['inv_itemid'], $tcost, $us['id']
- );
- $checkq = $db->query($checkq);
- if($db->num_rows($checkq) > 0)
- {
- $cqty = $db->fetch_row($checkq);
- $query = sprintf('UPDATE `user_shopitems` SET `sqty` = `sqty` + %u WHERE `sID` = %u
- AND `id` = %u', $qty,$cqty['sID'],$cqty['id']);
- $db->query($query);
- }
- else
- $db->query("INSERT INTO `user_shopitems` VALUES (NULL,'{$wts}','{$r['inv_itemid']}',{$qty},{$tcost},{$us['id']})");
- $db->free_result($checkq);
- item_remove($userid, $r['inv_itemid'], $qty);
- echo "Item added to shop.";
- }
- }
- }
- else if($_POST['wts'] == 'crystals')
- {
- if(!empty($itmid))
- echo "Item id slot must be empty when no item selected..";
- else if(empty($wts) || empty($qty) || empty($tcost))
- echo "Invalid missed required feild..";
- else
- {
- if($ir['crystals'] < $_POST['qty'])
- {
- echo 'You do not have enough crystals you need '.number_format($_POST['qty'] - $ir['crystals']).' more.';
- $h->endpage();
- exit;
- }
- $checkq = sprintf(
- 'SELECT `id`,`sID` FROM `user_shopitems` WHERE `tprice` = %u AND `sID` = %u',$tcost, $us['id']
- );
- $checkq = $db->query($checkq);
- if($db->num_rows($checkq) > 0)
- {
- $cqty = $db->fetch_row($checkq);
- $query = sprintf('UPDATE `user_shopitems` SET `sqty` = `sqty` + %u WHERE `sID` = %u
- AND `id` = %u', $qty,$cqty['sID'],$cqty['id']);
- $db->query($query);
- }
- else
- $db->query("INSERT INTO `user_shopitems` (`stype`,`sqty`,`tprice`,`sID`) "." VALUES ('{$wts}',{$qty},{$tcost},{$us['id']})");
- $db->free_result($checkq);
- $query = sprintf(
- 'UPDATE `users` SET `crystals` = `crystals` - %u WHERE `userid` = %u', $qty,$ir['userid']
- );
- $query = $db->query($query);
- $qty = number_format($qty);
- echo "[{$qty}] Crystals added to shop.";
- }
- }
- else
- {
- if(!empty($itmid))
- echo "Item id slot must be empty when no item selected..";
- else if(empty($wts) || empty($qty) || empty($tcost))
- echo "Invalid missed required feild..";
- else
- {
- if($ir['donatordays'] < $_POST['qty'])
- {
- echo 'You do not have enough donator days you need '.number_format($_POST['qty'] - $ir['donatordays']).' more.';
- $h->endpage();
- exit;
- }
- $checkq = sprintf(
- 'SELECT `id`,`stype`,`tprice` FROM `user_shopitems`
- WHERE `stype` = "%s" AND `tprice` = %u AND `sID` = %u',$_POST['wts'], $tcost, $us['id']
- );
- $checkq = $db->query($checkq);
- if($db->num_rows($checkq) > 0)
- {
- $cqty = $db->fetch_row($checkq);
- $query = sprintf('UPDATE `user_shopitems` SET `sqty` = `sqty` + %u WHERE `sID` = %u
- AND `id` = %u', $qty,$cqty['sID'],$cqty['id']);
- $db->query($query);
- }
- else
- $db->query("INSERT INTO `user_shopitems` (`stype`,`sqty`,`tprice`,`sID`) "." VALUES ('{$wts}',{$qty},{$tcost},{$us['id']})");
- $db->free_result($checkq);
- $query = sprintf(
- 'UPDATE `users` SET `donatordays` = `donatordays` - %u WHERE `userid` = %u', $qty,$ir['userid']
- );
- $query = $db->query($query);
- $qty = number_format($qty);
- echo "[{$qty}] Donator Days added to shop.";
- }
- }
- }
- else
- {
- if(isset($_GET['remove']))
- {
- $_GET['remove'] = isset($_GET['remove']) && ctype_digit($_GET['remove']) ? abs(intval($_GET['remove'])) : 0;
- if(empty($_GET['remove']))
- {
- echo "Invalid Format..";
- $h->endpage();
- exit;
- }
- $check = $db->query("SELECT `owner` FROM `usershops` WHERE `owner` = {$ir['userid']}");
- if(!$db->num_rows($check))
- echo "You don't have a shop..";
- else
- {
- $check_item = $db->query("SELECT * FROM `user_shopitems` WHERE `id` = {$_GET['remove']} AND `sID` = {$us['id']}");
- if(!$db->num_rows($check_item))
- echo "You don't have this item in your shop..";
- else
- {
- $itm = $db->fetch_row($check_item);
- if($itm['stype'] == 'item')
- {
- $itmname = $db->fetch_single($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$itm['selling']}"));
- item_add($itm['selling'],$us['owner'],$itm['sqty']);
- $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$_GET['remove']} AND `sID` = {$us['id']}");
- echo "You have removed the [x ".number_format($itm['sqty'])."] of {$itmname} from the shop.";
- }
- else if($itm['stype'] == 'crystals')
- {
- $db->query("UPDATE `users` SET `crystals` = `crystals` + {$itm['sqty']} WHERE `userid` = {$ir['userid']}");
- $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$_GET['remove']} AND `sID` = {$us['id']}");
- echo "You have removed the [x ".number_format($itm['sqty'])."] Crystals from the shop.";
- }
- else
- {
- $db->query("UPDATE `users` SET `donatordays` = `donatordays` + {$itm['sqty']} WHERE `userid` = {$ir['userid']}");
- $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$_GET['remove']} AND `sID` = {$us['id']}");
- echo "You have removed the [x ".number_format($itm['sqty'])."] Donator Days from the shop.";
- }
- }
- }
- }
- echo "<h3>Your Shop</h3>";
- $user_items = $db->query("SELECT * FROM `user_shopitems` WHERE `sID` = {$us['id']}");
- if(!$db->num_rows($user_items))
- echo "You don't have any items.<br /><br />";
- echo "
- <table width='90%' class='table' style='text-align:center;'>
- <tr>
- <th>Item</th>
- <th>Qty</th>
- <th>Total Cost</th>
- <th>Action</th>
- </tr>";
- while($si = $db->fetch_row($user_items))
- {
- if($si['stype'] == 'item')
- {
- $itm = $db->fetch_row($db->query("SELECT `itmid`,`itmname` FROM `items` WHERE `itmid` = {$si['selling']}"));
- $si['stype'] = $itm['itmname'];
- }
- else if($si['stype'] == 'crystals')
- $si['stype'] = "".number_format($si['sqty'])." Crystals";
- else
- $si['stype'] = "".number_format($si['sqty'])." Donator Days";
- echo "
- <tr>
- <td>{$si['stype']}</td>
- <td>".number_format($si['sqty'])."</td>
- <td>".money_formatter($si['tprice'])."</td>
- <td><a href='myshop.php?remove={$si['id']}'>[Remove]</td>
- </tr>";
- }
- echo "</table><br /><hr>
- <h3>Add to shop</h3>
- <script>
- $(document).ready(function () {
- $('#state').change(function() {
- // foo is the id of the other select box
- if ($(this).val() != 'item') {
- $('#foo').hide();
- } else {
- $('#foo').show();
- }
- });
- });
- </script>
- <form method='post'>
- What you selling:
- <select id='state' name='wts' type='dropdown'>
- <option value='item' selected>Item</option>
- <option value='donatordays'>Donator Days</option>
- <option value='crystals'>Crystals</option>
- </select><br />
- <div id='foo'><br />Item Id: <input type='text' name='itmid' value='0' /></div><br />
- Qty: <input type='text' name='qty' value='1' /><br /><br />
- Total Cost: <input type='text' name='tcost' value='0' /><br /><br />
- <input type='submit' name='addtoshop' value='Add To your Shop' />
- </form>";
- }
- }
- $h->endpage();
Advertisement
Add Comment
Please, Sign In to add comment