Guest User

jQuery Ajax Banking

a guest
Feb 6th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.95 KB | None | 0 0
  1. <?php
  2.  
  3. //-----------------------------------
  4. // Mod created by Dave Macaulay ([email protected])
  5. // For free use only with Mccodes V2
  6. // For use of mod this must remain intack!
  7. //------------------------------------
  8.  
  9. if(!isset($_GET['print'])) {
  10.     require('globals.php');
  11.     echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  12.    <h3><u>City Bank</u></h3><hr/>';
  13. } else {
  14.     require('globals_nonauth.php');
  15. }
  16. define('price', 5000);
  17. define('file', basename($_SERVER['SCRIPT_FILENAME']));
  18.  
  19. $_GET['amount'] = (isset($_GET['amount']) && is_numeric($_GET['amount'])) ? abs(intval($_GET['amount'])) : '';
  20. if(isset($_GET['get_bank'])) {
  21.     echo ($_GET['simple'] ? $ir['bankmoney'] : money_formatter($ir['bankmoney'] + 0));  
  22.     exit;
  23. }
  24. if(isset($_GET['get_hand'])) {
  25.     echo ($_GET['simple'] ? $ir['money'] : money_formatter($ir['money'] + 0));  
  26.     exit;
  27. }
  28. if($ir['bankmoney'] < 0) {
  29.     new_account();
  30.     if(!isset($_GET['print'])) {
  31.         $h->endpage();
  32.     }
  33.     exit;  
  34. }
  35. if (!isset($_GET['a']))
  36. {
  37.     $_GET['a'] = '';
  38. }
  39. switch($_GET['a'])
  40. {
  41.     case 'deposit': deposit(); break;
  42.     case 'withdraw': withdraw(); break;
  43.     default: index(); break;
  44. }
  45. function new_account() {
  46.     global $ir,$db,$c,$userid;
  47.     if(!isset($_GET['print'])) {
  48.         ?>
  49.         <script type="text/javascript">
  50.         function openAccount() {
  51.             var c = confirm("Are you sure you want to open a bank account for <?=money_formatter(price)?>?");
  52.             if(c) {
  53.                 $('#main_text').html('Opening account...
  54. ');
  55.                 $('#main_text').append('Checking you have the correct funds...
  56. ');
  57.                 if(<?=$ir['money']?> < <?=price?>) {
  58.                     $('#main_text').append('<span style="color: red;">Incorrect funds, You need another <?=money_formatter((price)-$ir['money'])?>...</span>');        
  59.                 } else {
  60.                     $.post('<?=file?>?open=true&print=1', function(data) {
  61.                       if(data == 'not_enough_money') {
  62.                         $('#main_text').append('Incorrect funds...');      
  63.                       } else if(data == 'opened') {
  64.                         $('#main_text').append('You have succesfully opened your brand new bank account!<a href="javascript:void(0);">&gt;View Account</a>');  
  65.                       }
  66.                     });
  67.                 }
  68.             }
  69.         }
  70.         function showBank() {
  71.             $.get('<?=file?>?print=1', function(data) {  
  72.                 $('#main_text').html(data);
  73.             });
  74.         }
  75.         </script>
  76.         <?php
  77.     }
  78.     if(isset($_GET['open'])) {
  79.         if($ir['money'] < price) {
  80.             echo 'Not enough money to open a bank.';
  81.             exit;
  82.         } else {
  83.             $db->query("UPDATE `users` SET `money` = `money` - " . price . ", `bankmoney` = 0 WHERE `userid` = " . $userid);
  84.             echo 'Bank account opened.';
  85.             exit;
  86.         }
  87.     } else {
  88.         echo '
  89.        <span id="main_text">
  90.        You currently don\'t have a bank account with us, would you like to open an account for only <i>' . money_formatter(price + 0). '</i>!<br/>
  91.     <a href="javascript:void(0);">&gt;Open an account!</a></span>';
  92.     }
  93. }
  94. function index() {
  95.     global $ir,$db,$c,$userid;
  96.     ?>
  97.     <script type="text/javascript">
  98.         function makeTrans(type) {
  99.             if(type != 'withdraw' && type != 'deposit') {
  100.                 alert("Script Error!");  
  101.             } else {
  102.                 var data = $('[name='+type+']');
  103.                 $.post('<?=file?>?print=true&a=' + type, { 'amount' : data.val() }, function(data) {
  104.                     $('#' + type + '_callback').html(data);
  105.                     $.post('<?=file?>?print=true&get_bank=true', function(data) { $('#bank_money').html(data); });
  106.                     $.post('<?=file?>?print=true&get_bank=true&sim  ple=true', function(data) { $('[name=withdraw]').val(data); });
  107.                     $.post('<?=file?>?print=true&get_hand=true&sim  ple=true', function(data) { $('[name=deposit]').val(data); });
  108.                 });
  109.             }
  110.         }
  111.     </script>
  112.     <?php
  113.     echo 'You currently have <i><span id="bank_money">' . money_formatter($ir['bankmoney'] + 0) . '</i> in your bank account. You are earning 2% interest on this daily.<br/>
  114.  
  115.  
  116.    <a href="javascript:void(0);" target="_blank">&gt;Withdraw</a><br/>
  117.    <div id="withdraw" style="background: #ffffd3;border: 1px #ffff99 solid;display: none;padding: 20px;width: 250px;margin: 5px;">
  118.        <form action="" method="post" onsubmit="makeTrans(\'withdraw\');return false;"><input type="text" name="withdraw" value="' . ($ir['bankmoney'] ? $ir['bankmoney'] : 0) . '" /> <input type="submit" value="Withdraw" /></form>
  119.        <div id="withdraw_callback">
  120.            Please select the amount you wish to withdraw then hit the withdraw button next to it.
  121.        </div>
  122.    </div>
  123.  
  124.    <a href="javascript:void(0);" target="_blank">&gt;Deposit</a><br/>
  125.    <div id="deposit" style="background: #ffffd3;border: 1px #ffff99 solid;display: none;padding: 20px;width: 250px;margin: 5px;">
  126.        <form action ="" method="post" onsubmit="makeTrans(\'deposit\'); return false;"><input type="text" name="deposit" value="' . ($ir['money'] ? $ir['money'] : 0) . '" /> <input type="submit" value="Deposit" /></form>
  127.        <div id="deposit_callback">
  128.           Please choose the amount of money you wish to store in your account.
  129.        </div>
  130.    </div>
  131.  
  132.    ';  
  133. }
  134. function deposit() {
  135.     global $db,$ir,$c,$userid;
  136.     if($_POST['amount'] > $ir['money']) {
  137.         echo '<span style="color:red;">You do not have that much money to deposit!</span>';
  138.     } else {
  139.         $fee = ceil($_POST['amount'] * 15 / 100);
  140.         $fee = ($fee > 3000 ? 3000 : $fee);
  141.         $gain = $_POST['amount'] - $fee;
  142.         $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` + ".$gain.", `money` = `money` - ".$_POST['amount']." WHERE `userid` = ".$userid);
  143.         echo 'You deposited ' . money_formatter($_POST['amount'] + 0) . ' into your account.
  144.  
  145.        The 15% fee of ' . money_formatter($fee + 0) . ' was taken depositing you a final amount of ' . money_formatter($gain + 0) . '.';
  146.     }
  147. }
  148. function withdraw() {
  149.     global $db,$ir,$c,$userid;
  150.     if(isset($_POST['amount']) && $_POST['money'] > $ir['bankmoney']) {
  151.         echo '<span style="color:red;">You dont have enough money saved to withdraw that much!</span>';
  152.     } else {
  153.         $db->query("UPDATE `users` SET `bankmoney` = `bankmoney` - " . $_POST['amount'] . ", `money` = `money` + " . $_POST['amount'] . " WHERE `userid` = ".$userid);
  154.         $ir['money'] += $_POST['amount'];
  155.         echo 'You withdrew ' . money_formatter($_POST['amount'] + 0) . ' into your hand from your account.<br/>
  156.        You know have ' . money_formatter($ir['money'] + 0) . ' in your hand.';
  157.     }
  158. }
  159. if(!isset($_GET['print'])) {
  160.     $h->endpage();
  161. }
  162. ?>
Add Comment
Please, Sign In to add comment