BioTorrents.de’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.

points.php 3.7KB

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