Unsupported scripts and control panel web app for a hosting company
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.

billing.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?PHP
  2. require_once('lib/dashboard.php');
  3. require_once('lib/common.php');
  4. require_once('lib/database.php');
  5. require_once('lib/account.php');
  6. define('TITLE', 'Billing');
  7. addDashboardItem('Frequently asked questions', 'How do I pay outstanding bills?', 'support/008');
  8. function foo() {
  9. if (!isset($_POST['code']) || m($_POST['code']) != $_POST['code']) {
  10. return;
  11. }
  12. $sql = 'SELECT discount_id, discount_time, discount_money, discount_start, discount_end, discount_type, discount_message FROM discounts WHERE discount_code = \''.$_POST['code'].'\'';
  13. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  14. if (mysql_num_rows($res) == 0) {
  15. define('MESSAGE', 'That discount code does not exist.');
  16. l('Non-existant discount code used: '.$_POST['code']);
  17. return;
  18. }
  19. $row = mysql_fetch_array($res);
  20. if ($row['discount_start'] > time()) {
  21. define('MESSAGE', 'That discount is not yet valid.');
  22. l('Discount code used prematurely: '.$_POST['code']);
  23. return;
  24. }
  25. if ($row['discount_end'] < time()) {
  26. define('MESSAGE', 'That discount is no longer valid.');
  27. l('Discount code expired: '.$_POST['code']);
  28. return;
  29. }
  30. if ($row['discount_type'] != 'general') {
  31. define('MESSAGE', 'That discount is for new signups only.');
  32. l('Signup discount code used: '.$_POST['code']);
  33. return;
  34. }
  35. $sql2 = 'SELECT du_id FROM discountusers WHERE discount_id = '.$row['discount_id'].' AND user_id = '.UID;
  36. $res2 = mysql_query($sql2) or mf(__FILE__, __LINE__, $sql2);
  37. if (mysql_num_rows($res2) > 0) {
  38. define('MESSAGE', 'You have already claimed that discount.');
  39. l('Already used discount code: '.$_POST['code']);
  40. return;
  41. }
  42. $sql2 = 'SELECT bill_id, bill_due, bill_amount FROM billing WHERE user_id = '.UID.' AND bill_paid <> 2';
  43. $res2 = mysql_query($sql2) or mf(__FILE__, __LINE__, $sql2);
  44. $row2 = mysql_fetch_array($res2);
  45. $row2['bill_due'] += $row['discount_time'];
  46. $row2['bill_amount'] -= $row['discount_money'];
  47. $sql2 = 'UPDATE billing SET bill_due = '.$row2['bill_due'].', bill_amount = '.$row2['bill_amount'].', bill_paid = 0 WHERE bill_id = '.$row2['bill_id'];
  48. mysql_query($sql2) or mf(__FILE__, __LINE__, $sql2);
  49. $sql2 = 'INSERT INTO discountusers (discount_id, user_id) VALUES ('.$row['discount_id'].','.UID.')';
  50. mysql_query($sql2) or mf(__FILE__, __LINE__, $sql2);
  51. l('Discount code applied: '.$_POST['code']);
  52. if ($row['discount_time'] > 0 && $row['discount_money'] == 0) {
  53. define('MESSAGE', 'Your current billing period has been extended by '.round($row['discount_time']/2629728,2).' month(s). '.$row['discount_message']);
  54. } elseif ($row['discount_time'] == 0) {
  55. define('MESSAGE', 'Your next bill has been reduced by £'.($row['discount_money']/100).'. '.$row['discount_message']);
  56. } else {
  57. define('MESSAGE', 'Your current billing period has been extended by '.round($row['discount_time']/2629728,2).' month(s), and the next bill has been reduced bby £'.($row['discount_money']/100).'. '.$row['discount_message']);
  58. }
  59. }
  60. foo();
  61. require_once('lib/header.php');
  62. require_once('pages/billing.php');
  63. if (!defined('NODISCOUNT')) { require_once('pages/discount.php'); }
  64. require_once('lib/footer.php');
  65. ?>