Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nips.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?
  2. $Amount = (int) db_string($_POST['amount']);
  3. $To = (int) db_string($_POST['to']);
  4. $UserID = (int) $LoggedUser['ID'];
  5. $Adjust = isset($_POST['adjust'])?true:false;
  6. $Message = $_POST['message'];
  7. // 10% tax
  8. $Tax = 0.1;
  9. if ($LoggedUser['DisableNips']) {
  10. $Err = 'You are not allowed to send nips.';
  11. } else {
  12. if ($Adjust)
  13. $Amount = $Amount/(1-$Tax);
  14. $SentAmount = (int) ($Amount*(1-$Tax));
  15. $Amount = (int) $Amount;
  16. if ($UserID == $To) {
  17. $Err = 'If you sent nips to yourself it wouldn\'t even do anything. Stop that.';
  18. } elseif ($Amount < 0) {
  19. $Err = 'You can\'t a negative amount you shitter.';
  20. } elseif ($Amount < 100) {
  21. $Err = 'You must send at least 100 Nips.';
  22. } else {
  23. $DB->query("
  24. SELECT ui.DisableNips
  25. FROM users_main AS um
  26. JOIN users_info AS ui ON um.ID = ui.UserID
  27. WHERE ID = $To");
  28. if (!$DB->has_results()) {
  29. $Err = 'That user doesn\'t exist.';
  30. } else {
  31. list($Disabled) = $DB->next_record();
  32. if ($Disabled) {
  33. $Err = "This user is not allowed to receive nips.";
  34. } else {
  35. $DB->query("
  36. SELECT BonusPoints
  37. FROM users_main
  38. WHERE ID = $UserID");
  39. if ($DB->has_results()) {
  40. list($BP) = $DB->next_record();
  41. if ($BP < $Amount) {
  42. $Err = 'You don\'t have enough Nips.';
  43. } else {
  44. $DB->query("
  45. UPDATE users_main
  46. SET BonusPoints = BonusPoints - $Amount
  47. WHERE ID = $UserID");
  48. $DB->query("
  49. UPDATE users_main
  50. SET BonusPoints = BonusPoints + ".$SentAmount."
  51. WHERE ID = $To");
  52. $UserInfo = Users::user_info($UserID);
  53. $ToInfo = Users::user_info($To);
  54. $DB->query("
  55. UPDATE users_info
  56. SET AdminComment = CONCAT('".sqltime()." - Sent $Amount Nips (".$SentAmount." after tax) to [user]".$ToInfo['Username']."[/user]\n\n', AdminComment)
  57. WHERE UserID = $UserID");
  58. $DB->query("
  59. UPDATE users_info
  60. SET AdminComment = CONCAT('".sqltime()." - Received ".$SentAmount." Nips from [user]".$UserInfo['Username']."[/user]\n\n', AdminComment)
  61. WHERE UserID = $To");
  62. $PM = '[user]'.$UserInfo['Username'].'[/user] has sent you a gift of '.$SentAmount.' Nips!';
  63. if (!empty($Message)) {
  64. $PM .= "\n\n".'[quote='.$UserInfo['Username'].']'.$Message.'[/quote]';
  65. }
  66. Misc::send_pm($To, 0, 'You\'ve received a gift!', $PM);
  67. $Cache->delete_value('user_info_heavy_'.$UserID);
  68. $Cache->delete_value('user_stats_'.$UserID);
  69. $Cache->delete_value('user_info_heavy_'.$To);
  70. $Cache->delete_value('user_stats_'.$To);
  71. }
  72. } else {
  73. $Err = 'An unknown error occurred.';
  74. }
  75. }
  76. }
  77. }
  78. }
  79. View::show_header('Send Nips'); ?>
  80. <div class='thin'>
  81. <h2 id='general'>Send Nips</h2>
  82. <div class='box pad' style='padding: 10px 10px 10px 20p;'>
  83. <p><?=$Err?'Error: '.$Err:'Sent '.$Amount.' Nips ('.$SentAmount.' after tax) to '.$ToInfo['Username'].'.'?></p>
  84. <p><a href='/user.php?id=<?=$To?>'>Return</a></p>
  85. </div>
  86. </div>
  87. <? View::show_footer(); ?>