Guest User

Ajax Bank

a guest
Nov 9th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. <?php
  2. $_GET['print'] = array_key_exists('print', $_GET) ? $_GET['print'] : null;
  3.  
  4. if(!$_GET['print']) {
  5. require('globals.php');
  6. echo "<h3><u>Bank</u></h3>";
  7. } else {
  8. require_once('globals_nonauth.php');
  9. $bankprice = 50000;
  10. $file = basename(__FILE__);
  11. $_POST['amount'] = array_key_exists('amount', $_POST) && ctype_digit(str_replace(',', '', $_POST['amount'])) ? str_replace(',', '', $_POST['amount']) : null;
  12. if(isset($_GET['get_bank'])) {
  13. echo (isset($_GET['simple']) ? $ir['bankmoney'] : money_formatter($ir['bankmoney']));
  14. exit;
  15. }
  16. if(isset($_GET['get_hand'])) {
  17. echo (isset($_GET['simple']) ? $ir['money'] : money_formatter($ir['money']));
  18. exit;
  19. }
  20. if($ir['bankmoney'] > 0) {
  21. new_account();
  22. if(!$_GET['print']) {
  23. $h->endpage();
  24. }
  25. exit;
  26. }
  27. if(!isset($_GET['a'])) {
  28. $_GET['a'] = null;
  29. }
  30. switch($_GET['a']) {
  31. case 'deposit':
  32. deposit();
  33. break;
  34.  
  35. case 'withdraw':
  36. withdraw();
  37. break;
  38.  
  39. default:
  40. index();
  41. break;
  42. }
  43. }
  44. function new_account() {
  45. global $db, $ir, $userid, $notl;
  46. if(!$_GET['print']) {
  47. ?>
  48. <script type = "text/javascript">
  49. function openAccount() {
  50. var c = confirm("Are you sure you want to open an account for <?php echo money_formatter($bankprice); ?>?");
  51. if (c) {
  52. $('#main_text').html('Opening you an account...<br/>');
  53. $('#main_text').append('Checking if you have the correct funds...<br/>');
  54. if(<?php echo $ir['money']; ?> < <?php echo $bankprice; ?>) {
  55. $('#main_text').append('<span style = "color:red;">You do not have enough money to open a bank, you need <?php echo money_formatter($bankprice - $ir['money']); ?>...</span><br/>');
  56. } else {
  57. $.POST('<?php echo $file; ?>?open=true&print=1', function(data) {
  58. if(data == 'not_enough_money') {
  59. $('#main_text').append('<span style = "color:red;">Not enough money...</span><br/>');
  60. } else if (data == 'opened') {
  61. $('#main_text').append('<span style = "green;">You have successfully opened your bank account.</span><br/><br/>&gt; <a href = "javascript:void(0);" onlick = "showBank();">View Account</a>');
  62. }
  63.  
  64. });
  65.  
  66. }
  67. }
  68. }
  69. function showBank() {
  70. global $db, $ir, $userid, $notl;
  71. $.GET('<?php echo $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'] < $bankprice) {
  80. exit('not_enough_money');
  81. } else {
  82. $db->query("UPDATE `users` SET `money` = `money` - $bankprice, `bankmoney` = 0 WHERE `userid` = {$ir['userid']}");
  83. exit('opened');
  84. }
  85. } else {
  86. echo "<spand id = 'main_text'>You currently do not have a bank account with us, would you like to open an account for only <i>" . money_formatter($bankprice) . "</i>?<br/><br/>
  87. <a href = 'javascript:void(0);' onclick = 'openAccount();'>&gt;Open an account</a></span>";
  88. }
  89. }
  90. function index() {
  91. global $db, $ir, $userid, $notl;
  92. ?>
  93. <script type = "text/javascript">
  94. function makeTrans(type) {
  95. if(type != 'withdraw' && != 'desposit') {
  96. alert('Script error!');
  97. } else {
  98. var data = $('[name = '+type+']');
  99. $.POST('<?php echo $file; ?>?print=true&a=' + type, { 'amount' : data.val() }, function(data) {
  100. $('#' + type + '_callback').html(data);
  101. $.POST('<?php echo $file; ?>?print=true&get_bank=true', function(data) {
  102. $('#bank_money').html(data); });
  103. $.POST('<?php echo $file; ?>?a=deposit&print=true&get_bank=true&simple=true', function(data) {
  104. $('[name=withdraw]').val(data); });
  105. $.POST('<?php echo $file; ?>?a=withdraw&print=true&get_bank=true&simple=true', function(data) {
  106. $('[name=deposit]').val(data); });
  107. });
  108. }
  109. }
  110. </script>
  111. <?php
  112. echo "You currently have in your back account <i><span id = 'bank_money'>" . money_formatter($ir['bankmoney']) . "</span></i> in your bank account.<br/>";
  113. echo $ir['donatordays'] ? 'You are earning 5% interest this week.<br/><br/>' : '<br/><br/>';
  114. }
  115.  
  116.  
  117.  
  118.  
  119. if(!$_GET['print']) {
  120. $h->endpage();
  121. }
Add Comment
Please, Sign In to add comment