Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1.  
  2. Skip to content
  3. This repository
  4.  
  5.     Pull requests
  6.     Issues
  7.     Gist
  8.  
  9.     @dean1012
  10.  
  11. 1
  12. 0
  13.  
  14.     0
  15.  
  16. dean1012/webgiveaway
  17. Code
  18. Issues 1
  19. Pull requests 0
  20. Wiki
  21. Pulse
  22. Graphs
  23. Settings
  24. webgiveaway/host.php
  25. 73c3345 on Sep 26, 2015
  26. @dean1012 dean1012 Optimization again...
  27. 1 contributor
  28. 77 lines (65 sloc) 1.74 KB
  29. <?php
  30. require_once 'inc/Database.php';
  31. require_once 'inc/SmartyT.php';
  32. require_once 'inc/User.php';
  33. require_once 'inc/SteamGame.php';
  34. session_start();
  35. // User must be logged in to see this page
  36. $user = User::getLoggedInUser();
  37. if (!$user) {
  38.   session_write_close();
  39.   header('Location: login.php');
  40.   exit();
  41. }
  42. $smarty = SmartyT::getSmarty();
  43. $smarty->assign('user', $user);
  44. if (file_exists('/var/tmp/.maintenance')) {
  45.   $smarty->display('maintenance.tpl');
  46.   exit();
  47. }
  48. $smarty->assign('errormsg', null);
  49. if (isset($_POST['appid'])) {
  50.   $appid = $_POST['appid'];
  51.   $duration = $_POST['duration'];
  52.   if (!is_numeric($appid)) {
  53.     die ('FATAL ERROR: $appid not an integer');
  54.   }
  55.   if (!is_numeric($duration)) {
  56.     die ('FATAL ERROR: $duration not an integer');
  57.   } else {
  58.     switch ($duration) {
  59.       case 2:
  60.       case 4:
  61.       case 8:
  62.       case 16:
  63.       case 24:
  64.       case 32:
  65.       case 40:
  66.       case 48:
  67.         break;
  68.       default:
  69.         $smarty->assign('errormsg', 'Something went wrong, try again?');
  70.         break;
  71.     }
  72.   }
  73.   try {
  74. echo "TRY1";
  75.     $game = new SteamGame($appid);
  76. echo "TRY2";
  77.     $date = new DateTime();
  78. echo "TRY3";
  79.     $date->add(new DateInterval("PT{$duration}H"));
  80. echo "TRY4"
  81.     $expiration = $date->getTimestamp();
  82. echo "TRY5"
  83.     $stmt = Database::getConnection()->prepare('INSERT INTO giveaways (appid, expiration, host) VALUES (:appid, :expiration, :host)');
  84. echo "TRY6"
  85.     $stmt->execute(array(
  86.         ':appid' => $appid,
  87.         ':expiration' => $expiration,
  88.         ':host' => $user->getId(),
  89.     ));
  90. echo "TRY7"
  91.     $giveawayid = Database::getConnection()->lastInsertId();
  92. echo "TRY8"
  93.     session_write_close();
  94. echo "TRY9"
  95.     header("Location: viewgiveaway.php?id=$giveawayid");
  96. echo "TRY10"
  97.     exit();
  98.   } catch (Exception $ex) {
  99. echo "EXCEPTION " . $ex->getMessage(); die();
  100.     $smarty->assign('errormsg', 'Something went wrong, try again?');
  101.   }
  102. }
  103. $smarty->display('host.tpl');
  104. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement