Guest User

Untitled

a guest
Jul 15th, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.39 KB | None | 0 0
  1. <?php
  2.  
  3. require_once(__DIR__.'/globals.php');
  4.  
  5. $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : '';
  6. switch($_GET['action'])
  7. {
  8.     case 'travel': travel(); break;
  9.     default: travel_agency(); break;
  10. }
  11.  
  12. function travel_agency()
  13. {
  14.     global $db,$ir,$h,$set;
  15.     echo "
  16.     <div style='text-align:center;'>
  17.         <img src='images/ta.png' width='200px' height='200px' />
  18.         <h3>Travel Agency</h3>
  19.         <p>Welcome to the {$set['game_name']} travel agency how can we help you today?</p>
  20.         <a href='monorail.php?action=travel'><button>Travel</button></a>
  21.         <a href='monorail.php?insurance'><button>Travel Insurcance?</button></a><br /><br />";
  22.         if(isset($_GET['buy']))
  23.         {
  24.             if($ir['insured'] >= 10)
  25.                 echo "You are insured already you can only renew it once its 10 days or less.";
  26.             else if($ir['credits'] < 5)
  27.                 echo "Sorry you don't have enough credits you need ".(5 - $ir['credits'])." more.";
  28.             else
  29.             {
  30.                 $ir['credits'] -= 5;
  31.                 $ir['insured'] += 30;
  32.                 $db->query("UPDATE `users` SET `credits` = {$ir['credits']},`insured` = {$ir['insured']} WHERE `userid` = {$ir['userid']}");
  33.                 echo "You have purchased insurance for 5 credits this will last for 30 days.";
  34.             }
  35.         }
  36.         else if(isset($_GET['insurance']))
  37.         {
  38.             echo "<hr width='50%' align='center'>
  39.             <h4 style='color:red'>Insurance Support Team</h4>
  40.             <span style='text-align:center;'>
  41.                 Hello {$ir['username']} Traveling can be dangerous you never know what might happen.
  42.                 If you take insurance out with us we will make sure you are well looked after.<br /><br />
  43.            
  44.                 <h3>Package Includes</h3>
  45.                 &bullet; 20 Free Hospital Heals which you can sign yourself out of hospital.<br />
  46.                 &bullet; 50% of your travel cost returned if hurt in acident using our service.<br />
  47.                 &bullet; As a member you can heal a friend for 50% of cost.<br />
  48.             </span>
  49.             <a href='monorail.php?buy'><button>Pay 5 Credits for insurance</button></a>
  50.             <a href='monorail.php'><button>Who needs insurance</button></a>";
  51.         }
  52.     echo "</div>";
  53. $h->endpage();
  54. }
  55.  
  56. function travel()
  57. {
  58.     global $db,$ir,$h;
  59.     $ttype = array(
  60.         'Car',
  61.         'Boat',
  62.         'Bus',
  63.         'Plane'
  64.     );
  65.     if(isset($_POST['travel']))
  66.     {
  67.         $_POST['ttype'] = isset($_POST['ttype']) && ctype_alpha($_POST['ttype']) && in_array($_POST['ttype'], $ttype) ? $_POST['ttype'] : '';
  68.         if(empty($_POST['ttype']))
  69.             echo "Invalid Format.";
  70.         else
  71.         {
  72.             $locations = $db->query("SELECT `ID`,`ttype`,`traveltime`,`travelcost`,`location` FROM `locations`
  73.                 WHERE `ttype` = '{$_POST['ttype']}' AND `levelreq` <= {$ir['level']} AND `cityid` != {$ir['location']}");
  74.             if(!$db->num_rows($locations))
  75.             {
  76.                 $db->free_result($locations);
  77.                 echo "There is no locations for this type of transport..";
  78.             }
  79.             else
  80.             {
  81.                 echo "
  82.                 <table width='75%'>
  83.                     <tr>
  84.                         <th>Name</th>
  85.                         <th>Cost</th>
  86.                         <th>Travel Time</th>
  87.                         <th>Action</th>
  88.                     </tr>";
  89.                     while($tr = $db->fetch_row($locations))
  90.                     {
  91.                         if($tr['ttype'] == 'Car')
  92.                         {
  93.                             $tr['traveltime'] += $tr['traveltime'] / 100 * 60;
  94.                             $tr['travelcost'] -= $tr['travelcost'] / 100 * 50;
  95.                         }
  96.                         else if($tr['ttype'] == 'Boat')
  97.                         {
  98.                             $tr['traveltime'] += $tr['traveltime'] / 100 * 40;
  99.                             $tr['travelcost'] -= $tr['travelcost'] / 100 * 35;
  100.                         }
  101.                         else if($tr['ttype'] == 'Bus')
  102.                         {
  103.                             $tr['traveltime'] += $tr['traveltime'] / 100 * 75;
  104.                             $tr['travelcost'] -= $tr['travelcost'] / 100 * 45;
  105.                         }
  106.                         else if($tr['ttype'] == 'Plane')
  107.                         {
  108.                             $tr['traveltime'] -= $tr['traveltime'] / 100 * 15;
  109.                             $tr['travelcost'] += $tr['travelcost'] / 100 * 75;
  110.                         }
  111.                         echo "
  112.                         <tr>
  113.                             <td>{$tr['location']}</td>
  114.                             <td>".money_formatter($tr['travelcost'])."</td>
  115.                             <td>".money_formatter($tr['traveltime'], '')." minutes</td>
  116.                             <td><a href='monorail.php?action=travel&begin={$tr['ID']}'>Travel</a></td>
  117.                         </tr>";
  118.                     }
  119.                 echo "</table>";
  120.             }
  121.         }
  122.     }
  123.     else if(isset($_GET['begin']))
  124.     {
  125.         $_GET['begin'] = isset($_GET['begin']) && ctype_digit($_GET['begin']) ? abs(intval($_GET['begin'])) : 0;
  126.         if(empty($_GET['begin']))
  127.             echo "Invalid.";
  128.         else
  129.         {
  130.             $check = $db->query("SELECT * FROM `locations` WHERE `ID` = {$_GET['begin']}");
  131.             if(!$db->num_rows($check))
  132.             {
  133.                 $db->free_result($check);
  134.                 echo "That's not a real location.";
  135.             }
  136.             else
  137.             {
  138.                 $loc = $db->fetch_row($check);
  139.                 if($ir['location'] == $loc['cityid'])
  140.                     echo "You are already at this location.";
  141.                 else if($loc['ttype'] == 'Car')
  142.                 {
  143.                     $loc['traveltime'] += $loc['traveltime'] / 100 * 60;
  144.                     $loc['travelcost'] -= $loc['travelcost'] / 100 * 50;
  145.                 }
  146.                 else if($loc['ttype'] == 'Boat')
  147.                 {
  148.                     $loc['traveltime'] += $loc['traveltime'] / 100 * 40;
  149.                     $loc['travelcost'] -= $loc['travelcost'] / 100 * 35;
  150.                 }
  151.                 else if($loc['ttype'] == 'Bus')
  152.                 {
  153.                     $loc['traveltime'] += $loc['traveltime'] / 100 * 75;
  154.                     $loc['travelcost'] -= $loc['travelcost'] / 100 * 45;
  155.                 }
  156.                 else if($loc['ttype'] == 'Plane')
  157.                 {
  158.                     $loc['traveltime'] -= $loc['traveltime'] / 100 * 15;
  159.                     $loc['travelcost'] += $loc['travelcost'] / 100 * 75;
  160.                 }
  161.                 if($ir['traveling'])
  162.                     echo "Sorry but you are already traveling this page is blocked.";
  163.                 else if($ir['money'] < $loc['travelcost'])
  164.                     echo "You don't have enough money you need ".money_formatter($loc['travelcost'] - $ir['money'])." more.";
  165.                 else
  166.                 {
  167.                     # insert the data into a traveling table and make the users travel to int 1 update it when traveling
  168.                     $db->query("UPDATE `users` SET `money` = `money` - {$loc['travelcost']},`traveling` = 1 WHERE `userid` = {$ir['userid']}");
  169.                     $db->query("INSERT INTO `traveling` (`userid`,`time`,`location`,`ttype`)
  170.                         VALUES({$ir['userid']},{$loc['traveltime']},{$loc['cityid']},'{$loc['ttype']}')");
  171.                     echo "You have begin traveling to {$loc['location']} it will take {$loc['traveltime']} minutes.";
  172.                 }
  173.             }
  174.         }
  175.     }
  176.     else
  177.     {
  178.         echo "<h4>Travel Choices</h4>
  179.         <p>Pick a transport type diffrent methods cost diffrent prices and diffent travel times.</p>
  180.         <form method='post'>
  181.             Transport Type:
  182.             <select name='ttype' type='dropdown'>";
  183.                 foreach($ttype as $opt)
  184.                     printf("<option value='%1\$s'>%1\$s</option>", $opt); echo "
  185.             </select>
  186.             <input type='submit' name='travel' value='Show Locations' />
  187.         </form>";
  188.     }
  189. $h->endpage();
  190. }
Advertisement
Add Comment
Please, Sign In to add comment