PageRenderTime 26ms CodeModel.GetById 46ms RepoModel.GetById 1ms app.codeStats 0ms

/offercheck.php

https://github.com/deviltry/qmigo
PHP | 530 lines | 297 code | 115 blank | 118 comment | 49 complexity | 974c98a7b4474adc3c7b88067959a785 MD5 | raw file
  1. <?
  2. # Make sure we display errors to the browser
  3. error_reporting(E_ALL ^ E_NOTICE);
  4. ini_set('display_errors', 1);
  5. #########################################################
  6. # Initialize a new session or obtain old one if possible
  7. #########################################################
  8. require "info_session.php";
  9. session_name($mySessionName);
  10. session_start();
  11. $pageTitle = "QMIGO: Bar Check";
  12. # Get our DB info
  13. require "info.php";
  14. # Get our site info
  15. require "offersiteinfo.php";
  16. # Make sure we display errors to the browser
  17. error_reporting(E_ALL ^ E_NOTICE);
  18. ini_set('display_errors', 1);
  19. // check to see if this is a member redeeming or a guest
  20. if ($_GET['id'])
  21. {
  22. /////////////// MEMBER VERIFICATION //////
  23. #########################################################
  24. # Check that we have MEMBER ID or GUEST ID
  25. #########################################################
  26. $member_id = $_GET["id"]; // POSTED MEMBER ID
  27. $offer_id = $_GET["o"]; // POSTED OFFER ID IN THE BROWSER
  28. if (empty($member_id))
  29. {
  30. //echo "HOLLA - error check";
  31. header("Location: member404.php"); //steer them to an ERROR PAGE
  32. exit;
  33. }
  34. #########################################################
  35. # Connect to the database.
  36. #########################################################
  37. $connection = mysql_connect($mySqlHostname, $mySqlUsername, $mySqlPassword);
  38. if (!$connection)
  39. die("Error " . mysql_errno() . " : " . mysql_error());
  40. # Select the DB
  41. $db_selected = mysql_select_db($mySqlDatabase, $connection);
  42. if (!$db_selected)
  43. die("Error " . mysql_errno() . " : " . mysql_error());
  44. #########################################################################
  45. # Check if MEMBER ID AND OFFER ID are available and related to each other
  46. #########################################################################
  47. $member_name = "";
  48. $SqlStatement = "SELECT * FROM qmigo_status WHERE member_id = $member_id AND offer_id = $offer_id";
  49. //echo $SqlStatement;
  50. $result = mysql_query($SqlStatement,$connection);
  51. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  52. if (mysql_num_rows($result) == 0) // if SQL returns 0 results on the search...
  53. { # There is no member with this ID
  54. mysql_close($connection);
  55. header("Location: member404.php"); // change for member specific
  56. exit;
  57. }
  58. #########################################################
  59. # Check if MEMBER ID exists
  60. #########################################################
  61. $member_name = "";
  62. $SqlStatement = "SELECT firstname, lastname FROM qmigo_members WHERE id=$member_id ";
  63. $result = mysql_query($SqlStatement,$connection);
  64. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  65. if ($row = mysql_fetch_array($result,MYSQL_NUM))
  66. { $member_name = "$row[0] $row[1]";
  67. }
  68. else
  69. { # There is no member with this ID
  70. mysql_close($connection);
  71. header("Location: member404.php"); // change for member specific
  72. exit;
  73. }
  74. #########################################################
  75. # Check if OFFER is current + has not expired
  76. #########################################################
  77. $time = time(); //server time
  78. $timeUnix = strtotime($time); // server time in Unix Time
  79. $offer_name = "";
  80. $SqlStatement = "SELECT * FROM qmigo_offers WHERE id=$offer_id ";
  81. $result = mysql_query($SqlStatement,$connection);
  82. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  83. if ($row = mysql_fetch_array($result,MYSQL_ASSOC))
  84. {
  85. $offer_name = $row['offer']; // offer name row
  86. $offer_expire = $row['offer_expire']; //offer expire time
  87. $expiredTimeUnix = strtotime($offer_expire);
  88. if ($expiredTimeUnix >= $time)
  89. {
  90. $expired = FALSE ; // False = TIME LEFT / Still Valid
  91. echo "YO"; }
  92. else {
  93. $expired = TRUE;
  94. echo "NOT SO BRO";
  95. echo "time:" . $time;
  96. echo "expiredTimeUnix: " . $expiredTimeUnix;
  97. echo "OFFER EXPIRE: " . $offer_expire;
  98. }
  99. }
  100. ###########################################################################
  101. # Check if OFFER HAS BEEN REDEEMED ALREADY - MAKE SURE TO PREVENT CHEATING.
  102. ########################################################################
  103. //$redeemed = ""; //???
  104. // CHECKS TO MAKE SURE OFFER IS ACTIVE AND NOT REDEEMED
  105. $SqlStatement = "SELECT QR_status from qmigo_status WHERE member_id = ". $member_id ." AND offer_id = " . $offer_id ;
  106. $result = mysql_query($SqlStatement,$connection);
  107. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  108. if ($row = mysql_fetch_assoc($result))
  109. { $redeemed = $row["QR_status"]; // Row for QR_status value
  110. $QR_redemption = $row["QR_redemption"]; // Row for QR_redemption timestamp
  111. if ($redeemed == 1) {
  112. $redeemed = TRUE ; // QR_status = 1, OFFER HAS ALREADY BEEN REDEEMED
  113. $QR_redemption = TRUE ;
  114. }
  115. else if ($redeemed == 0) {
  116. $redeemed = FALSE; // QR_status = 0, OFFER IS STILL ACTIVE/valid.
  117. $QR_redemption = FALSE;
  118. //DO SOMETHING IN THE HTML BELOW
  119. }
  120. }
  121. #########################################################
  122. # Use SELECT to show VENDOR INFO + OFFER INFO
  123. #########################################################
  124. # $SqlStatement = "SELECT offer, unix_timestamp(offer_expire) as offer_expire FROM socialdrinkster_offers ORDER BY offer_expire desc LIMIT 1";
  125. // VENDOR X OFFER ONE - TO - MANY
  126. $SqlStatement = "Select o.id, o.offer, unix_timestamp(o.offer_expire) AS offer_expire, v.venue, v.venue_streetaddress, v.venue_city, v.venue_state, v.venue_zipcode,
  127. v.venue_phone FROM qmigo_offers o, qmigo_vendors v WHERE v.id = o.vendor_id AND o.id = $offer_id LIMIT 1";
  128. // PICK SPECIFIC OFFER AND SPICK SPECIFIC VENDOR FROM THAT OFFER
  129. # Run the LATEST VENDOR INFO + OFFER INFO query on the database through the connection
  130. $result = mysql_query($SqlStatement,$connection);
  131. if (!$result)
  132. die("Error " . mysql_errno() . " : " . mysql_error());
  133. ########################################################
  134. # Get our site info -> menu bar
  135. require "offersiteinfo.php";
  136. #########################################################
  137. # Write the Mobile-Friendly header
  138. #########################################################
  139. include "mobileheader.php";
  140. $qmigo_url = "http://www.qmigo.com/offercheck.php?id=". $member_id . "&o=" . $offer_id;
  141. if ($expired) {
  142. $msg = "<h1>Offer already expired.</h1>";
  143. $qrcode = "http://cyn.ical.us/media/blogs/mymedia/prophet_lol_cat.jpg";
  144. // OFFER HAS EXPIRED
  145. $SqlStatement = "UPDATE qmigo_status SET QR_status = 2 WHERE member_id = ". $member_id ." AND offer_id = " . $offer_id ;
  146. # 0 = active, 1 = redeemed, 2 = expired
  147. }
  148. else if ($redeemed) {
  149. $msg = "No dice. You've already redeemed your offer for a free <b>" . $offer_name . "</b><br />";
  150. $qrcode = "images/nodice.gif ";
  151. }
  152. else {
  153. $msg = "<h1>Redeemed!</h1><br />";
  154. $qrcode = "http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=" . urlencode($qmigo_url);
  155. $SqlStatement = "UPDATE qmigo_status SET QR_status = 1 AND current_timestamp WHERE member_id = ". $member_id ." AND offer_id = " . $offer_id ;
  156. # 0 = active, 1 = redeemed, 2 = expired
  157. }
  158. $setexpire= mysql_query($SqlStatement,$connection); // run the sql
  159. if (!$setexpire)
  160. die("Error " . mysql_errno() . " : " . mysql_error());
  161. ?>
  162. <div id="wrapper">
  163. <img src="<?PHP echo $qrcode ?>" id="qrid" /><br />
  164. <!-- <span class="highlight"> -->
  165. <h1><?PHP echo $msg ?> </h1>
  166. <h2>You are: <?PHP echo $member_name ?></span></h2> <br />
  167. <?
  168. //echo $SqlStatement ;
  169. echo "Enjoy Your " .$offer_name . "<br />";
  170. $fmt = "%m/%d/%Y %I:%M %p";
  171. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) // {}'s used like '', ""s to recognize as VARIABLE.
  172. {
  173. $t = strftime($fmt,$row['offer_expire']);
  174. $offer_id = $row['id'];
  175. echo <<<END
  176. <br />
  177. {$row['venue']} <br />
  178. {$row['venue_streetaddress']}, {$row['venue_city']},{$row['venue_state']},{$row['venue_zipcode']} <br />
  179. <a class="call" href="tel:1{$row['venue_phone']}"> {$row['venue_phone']} </a><br />
  180. Ends @ <b> $t </b> <br />
  181. END;
  182. }
  183. }
  184. else if ($_GET['gid'])
  185. {
  186. // CRAIG
  187. ///////////// GUEST CHECK ///////////////////////////////
  188. #########################################################
  189. # Check that we have GUEST ID
  190. #########################################################
  191. $guest_id = $_GET["gid"]; // POSTED GUEST ID
  192. $offer_id = $_GET["o"]; // POSTED OFFER ID IN THE BROWSER
  193. if (empty($guest_id))
  194. {
  195. echo "HOLLA - error check";
  196. //header("Location: member404.php"); //steer them to an ERROR page...
  197. //exit;
  198. }
  199. #########################################################
  200. # Connect to the database.
  201. #########################################################
  202. $connection = mysql_connect($mySqlHostname, $mySqlUsername, $mySqlPassword);
  203. if (!$connection)
  204. die("Error " . mysql_errno() . " : " . mysql_error());
  205. # Select the DB
  206. $db_selected = mysql_select_db($mySqlDatabase, $connection);
  207. if (!$db_selected)
  208. die("Error " . mysql_errno() . " : " . mysql_error());
  209. #########################################################################
  210. # Check if GUEST ID AND OFFER ID are available and related to each other
  211. #########################################################################
  212. $guest_name = "";
  213. $SqlStatement = "SELECT * FROM qmigo_guests WHERE id = $guest_id AND offer_id = $offer_id";
  214. //echo $SqlStatement;
  215. $result = mysql_query($SqlStatement,$connection);
  216. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  217. if (mysql_num_rows($result) == 0) // if SQL returns 0 results on the search...
  218. {
  219. echo "ERROR CHECK: WHAT IS GOING ON?";
  220. # There is no guest member with this ID
  221. //mysql_close($connection);
  222. //header("Location: member404.php"); //
  223. //exit;
  224. }
  225. #########################################################
  226. # Check if GUEST ID exists
  227. #########################################################
  228. $guest_name = "";
  229. $SqlStatement = "SELECT firstname, lastname FROM qmigo_guests WHERE id=$guest_id ";
  230. $result = mysql_query($SqlStatement,$connection);
  231. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  232. if ($row = mysql_fetch_array($result,MYSQL_NUM))
  233. { $guest_name = "$row[0] $row[1]";
  234. }
  235. /*
  236. else
  237. { # There is no member with this ID
  238. mysql_close($connection);
  239. header("Location: member404.php"); // change for member specific
  240. exit;
  241. }
  242. */
  243. #########################################################
  244. # Check if OFFER is current + has not expired
  245. #########################################################
  246. $time = time(); //server time
  247. $timeUnix = strtotime($time); // server time in Unix Time
  248. $offer_name = "";
  249. $SqlStatement = "SELECT * FROM qmigo_offers WHERE id=$offer_id ";
  250. $result = mysql_query($SqlStatement,$connection);
  251. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  252. if ($row = mysql_fetch_array($result,MYSQL_ASSOC))
  253. {
  254. $offer_name = $row['offer']; // offer name row
  255. $offer_expire = $row['offer_expire']; //offer expire time
  256. $expiredTimeUnix = strtotime($offer_expire);
  257. if ($expiredTimeUnix >= $time)
  258. {
  259. $expired = FALSE ; // False = TIME LEFT / Still Valid
  260. echo "YO"; }
  261. else {
  262. $expired = TRUE;
  263. echo "NOT SO BRO";
  264. echo "time:" . $time;
  265. echo "expiredTimeUnix: " . $expiredTimeUnix;
  266. echo "OFFER EXPIRE: " . $offer_expire;
  267. }
  268. }
  269. else
  270. {
  271. /*
  272. { # There is no member with this ID
  273. mysql_close($connection);
  274. header("Location: member404.php"); // change for member specific
  275. exit;
  276. if (empty($member_id)) || if (empty($guest_id))
  277. { header("Location: member404.php"); //steer them to an ERROR page...design one
  278. exit;
  279. }
  280. */
  281. echo "TOO BAD!";
  282. ###########################################################################
  283. # Check if OFFER HAS BEEN REDEEMED ALREADY - MAKE SURE TO PREVENT CHEATING.
  284. ########################################################################
  285. //$redeemed = ""; //???
  286. // CHECKS TO MAKE SURE OFFER IS ACTIVE AND NOT REDEEMED
  287. $SqlStatement = "SELECT QR_status from qmigo_guests WHERE id = ". $guest_id ." AND offer_id = " . $offer_id ;
  288. $result = mysql_query($SqlStatement,$connection);
  289. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  290. if ($row = mysql_fetch_assoc($result))
  291. { $redeemed = $row["QR_status"]; // Row for QR_status value
  292. $QR_redemption = $row["QR_redemption"]; // Row for QR_redemption timestamp
  293. if ($redeemed == 1) {
  294. $redeemed = TRUE ; // QR_status = 1, OFFER HAS ALREADY BEEN REDEEMED
  295. $QR_redemption = TRUE ;
  296. }
  297. else if ($redeemed == 0) {
  298. $redeemed = FALSE; // QR_status = 0, OFFER IS STILL ACTIVE/valid.
  299. $QR_redemption = FALSE;
  300. //DO SOMETHING IN THE HTML BELOW
  301. }
  302. }
  303. #########################################################
  304. # Use SELECT to show VENDOR INFO + OFFER INFO
  305. #########################################################
  306. # $SqlStatement = "SELECT offer, unix_timestamp(offer_expire) as offer_expire FROM socialdrinkster_offers ORDER BY offer_expire desc LIMIT 1";
  307. // VENDOR X OFFER ONE - TO - MANY
  308. $SqlStatement = "Select o.id, o.offer, unix_timestamp(o.offer_expire) AS offer_expire, v.venue, v.venue_streetaddress, v.venue_city, v.venue_state, v.venue_zipcode,
  309. v.venue_phone FROM qmigo_offers o, qmigo_vendors v WHERE v.id = o.vendor_id AND o.id = $offer_id LIMIT 1";
  310. // PICK SPECIFIC OFFER AND SPICK SPECIFIC VENDOR FROM THAT OFFER
  311. # Run the LATEST VENDOR INFO + OFFER INFO query on the database through the connection
  312. $result = mysql_query($SqlStatement,$connection);
  313. if (!$result)
  314. die("Error " . mysql_errno() . " : " . mysql_error());
  315. ########################################################
  316. # Get our site info -> menu bar
  317. require "offersiteinfo.php";
  318. #########################################################
  319. # Write the Mobile-Friendly header
  320. #########################################################
  321. include "mobileheader.php";
  322. $qmigo_url = "http://www.qmigo.com/offercheck.php?gid=". $guest_id . "&o=" . $offer_id;
  323. if ($expired) {
  324. $msg = "<h1>Offer already expired.</h1>";
  325. $qrcode = "http://cyn.ical.us/media/blogs/mymedia/prophet_lol_cat.jpg";
  326. // OFFER HAS EXPIRED
  327. $SqlStatement = "UPDATE qmigo_guests SET QR_status = 2 WHERE id = ". $guest_id ." AND offer_id = " . $offer_id ;
  328. # 0 = active, 1 = redeemed, 2 = expired
  329. }
  330. else if ($redeemed) {
  331. $msg = "No dice. You've already redeemed your offer for a free <b>" . $offer_name . "</b><br />";
  332. $qrcode = "images/nodice.gif ";
  333. }
  334. else {
  335. $msg = "<h1>Redeemed!</h1><br />";
  336. $qrcode = "http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=" . urlencode($qmigo_url);
  337. $SqlStatement = "UPDATE qmigo_guests SET QR_status = 1 AND current_timestamp WHERE id = ". $guest_id ." AND offer_id = " . $offer_id ;
  338. # 0 = active, 1 = redeemed, 2 = expired
  339. }
  340. $setexpire= mysql_query($SqlStatement,$connection); // run the sql
  341. if (!$setexpire)
  342. die("Error " . mysql_errno() . " : " . mysql_error());
  343. ?>
  344. <div id="wrapper">
  345. <img src="<?PHP echo $qrcode ?>" id="qrid" /><br />
  346. <!-- <span class="highlight"> -->
  347. <h1><?PHP echo $msg ?> </h1>
  348. <h2>You are: <?PHP echo $guest_name ?></span></h2> <br />
  349. <?
  350. //echo $SqlStatement ;
  351. echo "Enjoy Your " .$offer_name . "<br />";
  352. $fmt = "%m/%d/%Y %I:%M %p";
  353. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) // {}'s used like '', ""s to recognize as VARIABLE.
  354. {
  355. $t = strftime($fmt,$row['offer_expire']);
  356. $offer_id = $row['id'];
  357. echo <<<END
  358. <br />
  359. {$row['venue']} <br />
  360. {$row['venue_streetaddress']}, {$row['venue_city']},{$row['venue_state']},{$row['venue_zipcode']} <br />
  361. <a class="call" href="tel:1{$row['venue_phone']}"> {$row['venue_phone']} </a><br />
  362. Ends @ <b> $t </b> <br />
  363. END;
  364. }
  365. }
  366. }
  367. else
  368. {
  369. echo "Sorry your guest info does not exist!";
  370. // error! no guest id!
  371. }
  372. ?>
  373. <script language="JavaScript">
  374. // formatting for this javascript applet - TargetDate = "04/15/2010 11:10 PM";
  375. TargetDate = "<?PHP echo $t ?>";
  376. BackColor = "white";
  377. ForeColor = "red";
  378. CountActive = true;
  379. CountStepper = -1;
  380. LeadingZero = true;
  381. //DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
  382. DisplayFormat = "%%H%%H: %%M%%M: %%S%%S";
  383. FinishMessage = "Offer Time is Expired!";
  384. </script>
  385. <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
  386. <br />
  387. Cheers, <br />
  388. QMIGO
  389. </div>
  390. <?
  391. #########################################################
  392. # Write end HTML here
  393. #########################################################
  394. include "mobilefooter.php";
  395. ?>