Guest User

shoplist.php

a guest
May 3rd, 2015
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.58 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * User Shops v1.00
  5.  * This module is a free
  6.  * addon for mccodes v2
  7. */
  8.  
  9. require(__DIR__.'/globals.php');
  10.  
  11. $getshops = $db->query("SELECT `id`,`name`,`desc`,`pic`,`status`,`owner` FROM `usershops` ORDER BY `cdate` DESC");
  12. if(!$db->num_rows($getshops))
  13.     echo "There are no player shops.";
  14. else
  15. {
  16.     if(isset($_GET['enter']))
  17.     {
  18.         $_GET['enter'] = isset($_GET['enter']) && ctype_digit($_GET['enter']) ? abs(intval($_GET['enter'])) : 0;
  19.         if(empty($_GET['enter']))
  20.             echo "Invalid.";
  21.         else
  22.         {
  23.             $usershop = $db->query("SELECT `id`,`name`,`status`,`owner` FROM `usershops` WHERE `id` = {$_GET['enter']}");
  24.             if(!$db->num_rows($usershop))
  25.                 echo "That's not a real shop.";
  26.             else
  27.             {
  28.                 $us = $db->fetch_row($usershop);
  29.                 if($us['status'] == 1)
  30.                 {
  31.                     echo "This users shop is closed for business right now come back when they are open.";
  32.                     $h->endpage();
  33.                     exit;
  34.                 }
  35.                 $useritems = $db->query("SELECT * FROM `user_shopitems` WHERE `sID` = {$us['id']}");
  36.                 if(!$db->num_rows($useritems))
  37.                     echo "This user has nothing in there store.";
  38.                 else
  39.                 {
  40.                     echo "<h3>Viewing Stock of {$us['name']}</h3>";
  41.                         while($ui = $db->fetch_row($useritems))
  42.                         {
  43.                             echo "
  44.                             <table width='75%' class='table' style='text-align:center'>
  45.                                 <tr>";
  46.                                     if($ui['stype'] == 'item')
  47.                                     {   echo "
  48.                                         <th>Item</th>
  49.                                         <th>Qty</th>
  50.                                         <th>Total Price</th>
  51.                                         <th>Action</th>";
  52.                                     }
  53.                                     else
  54.                                     {   echo "
  55.                                         <th>Qty</th>
  56.                                         <th>Total Price</th>
  57.                                         <th>Action</th>";
  58.                                     } echo "
  59.                                 </tr>";
  60.                                 if($ui['stype'] == 'item')
  61.                                     $selling = $db->fetch_single(
  62.                                         $db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$ui['selling']}"));
  63.                                 echo "
  64.                                 <tr>";
  65.                                     if($ui['stype'] == 'item')
  66.                                     {   echo "
  67.                                         <td>{$selling}</td>
  68.                                         <td>".number_format($ui['sqty'])."</td>
  69.                                         <td>".money_formatter($ui['tprice'])."</td>
  70.                                         <td><a href='shoplist.php?buy={$ui['id']}'>[Buy {$selling}</a></td><br />";
  71.                                     }
  72.                                     else
  73.                                     {   echo "
  74.                                         <td>".number_format($ui['sqty'])." {$ui['stype']}</td>
  75.                                         <td>".money_formatter($ui['tprice'])."</td>
  76.                                         <td><a href='shoplist.php?buy={$ui['id']}'>[Buy]</a></td><br />";
  77.                                     }   echo "
  78.                                    
  79.                                 </tr>";
  80.                         }
  81.                             echo "</table>";
  82.                 }  
  83.             }  
  84.         }
  85.     }
  86.     else if(isset($_GET['buy']))
  87.     {
  88.         $_GET['buy'] = isset($_GET['buy']) && ctype_digit($_GET['buy']) ? abs(intval($_GET['buy'])) : 0;
  89.         if(empty($_GET['buy']))
  90.             echo "Invalid.";
  91.         else
  92.         {
  93.             $itm_check = $db->query("SELECT * FROM `user_shopitems` WHERE `id` = {$_GET['buy']}");
  94.             if(!$db->num_rows($itm_check))
  95.                 echo "Invalid Item.";
  96.             else
  97.             {
  98.                 $itm_ret = $db->fetch_row($itm_check);
  99.                 $select = $db->query("SELECT `owner` FROM `usershops` WHERE `id` = {$itm_ret['sID']}");
  100.                 $owner = $db->fetch_row($select);
  101.                 $cost = $itm_ret['tprice'];
  102.                 if($ir['money'] < $cost)
  103.                     echo "You don't have enough money you need ".money_formatter($cost - $ir['money'])." more";
  104.                 else
  105.                 {
  106.                     if($itm_ret['stype'] == 'item')
  107.                     {
  108.                         $itmname = $db->fetch_single($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$itm_ret['selling']}"));
  109.                         item_add($itm_ret['selling'], $ir['userid'], $itm_ret['sqty']);
  110.                         $db->query("UPDATE `users` SET `money` = `money` - {$cost} WHERE `userid` = {$ir['userid']}");
  111.                         $db->query("UPDATE `users` SET `money` = `money` + {$cost} WHERE `userid` = {$owner['owner']}");
  112.                         echo "You purchased ".number_format($itm_ret['sqty'])." of {$itmname} for ".money_formatter($itm_ret['tprice']);
  113.                         $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$itm_ret['id']}");
  114.                     }
  115.                     else if($itm_ret['stype'] == 'crystals')
  116.                     {
  117.                         $db->query("UPDATE `users` SET `money` = `money` - {$cost} WHERE `userid` = {$ir['userid']}");
  118.                         $db->query("UPDATE `users` SET `money` = `money` + {$cost} WHERE `userid` = {$owner['owner']}");
  119.                         $db->query("UPDATE `users` SET `crystals` = `crystals` + {$itm_ret['sqty']} WHERE `userid` = {$ir['userid']}");
  120.                         echo "You purchased ".number_format($itm_ret['sqty'])." Crystal's for ".money_formatter($itm_ret['tprice']);
  121.                         $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$itm_ret['id']}");
  122.                     }
  123.                     else
  124.                     {
  125.                         $db->query("UPDATE `users` SET `money` = `money` - {$cost} WHERE `userid` = {$ir['userid']}");
  126.                         $db->query("UPDATE `users` SET `money` = `money` + {$cost} WHERE `userid` = {$owner['owner']}");
  127.                         $db->query("UPDATE `users` SET `donatordays` = `donatordays` + {$itm_ret['sqty']} WHERE `userid` = {$ir['userid']}");
  128.                         echo "You purchased ".number_format($itm_ret['sqty'])." Donator Days for ".money_formatter($itm_ret['tprice']);
  129.                         $db->query("DELETE FROM `user_shopitems` WHERE `id` = {$itm_ret['id']}");
  130.                     }
  131.                 }
  132.             }
  133.         }
  134.     }
  135.     else
  136.     {
  137.         echo "
  138.         <table width='75%' class='table' style='text-align:center'>
  139.             <tr>
  140.                 <th>Pic</th>
  141.                 <th>Shop Name</th>
  142.                 <th>Status</th>
  143.                 <th>Action</th>
  144.             </tr>";
  145.             while($shop = $db->fetch_row($getshops))
  146.             {
  147.                 if($shop['status'] == 1)
  148.                     $status = "<span style='color:red'>Closed</span>";
  149.                 else
  150.                     $status = "<span style='color:green'>Open</span>";
  151.                 echo "
  152.                 <tr>
  153.                     <td><img src='{$shop['pic']}' width='200px' height='70px' /></td>
  154.                     <td>{$shop['name']}</td>
  155.                     <td>{$status}</td>
  156.                     <td><a href='shoplist.php?enter={$shop['id']}'>[Enter Shop]</a></td>
  157.                 </tr>";
  158.             }
  159.         echo "</table>";
  160.     }
  161. }
  162. $h->endpage();
Advertisement
Add Comment
Please, Sign In to add comment