PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/offer.php

https://github.com/deviltry/qmigo
PHP | 279 lines | 165 code | 55 blank | 59 comment | 24 complexity | e3113d82cebb41647dc7e2a70669a200 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. //session_save_path(); // see if dreamhost can do something...
  9. require "info_session.php";
  10. session_name($mySessionName);
  11. session_start();
  12. $pageTitle = "QMIGO: Your Offer";
  13. # Get our DB info
  14. require "info.php";
  15. # Get our site info
  16. require "offersiteinfo.php";
  17. # Make sure we display errors to the browser
  18. error_reporting(E_ALL ^ E_NOTICE);
  19. ini_set('display_errors', 1);
  20. ## TIME VARIABLES ##
  21. $time = time(); //server time
  22. $timeUnix = strtotime($time); // server time in Unix Time
  23. #########################################################
  24. # Check that we have MEMBER 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. { header("Location: member404.php"); //steer them to an ERROR page...design one
  30. exit;
  31. }
  32. #########################################################
  33. # Connect to the database.
  34. #########################################################
  35. $connection = mysql_connect($mySqlHostname, $mySqlUsername, $mySqlPassword);
  36. if (!$connection)
  37. die("Error " . mysql_errno() . " : " . mysql_error());
  38. # Select the DB
  39. $db_selected = mysql_select_db($mySqlDatabase, $connection);
  40. if (!$db_selected)
  41. die("Error " . mysql_errno() . " : " . mysql_error());
  42. #########################################################################
  43. # Check if MEMBER ID AND OFFER ID are available and related to each other
  44. #########################################################################
  45. $member_name = "";
  46. $SqlStatement = "SELECT * FROM qmigo_status WHERE member_id = $member_id AND offer_id = $offer_id";
  47. //echo $SqlStatement;
  48. $result = mysql_query($SqlStatement,$connection);
  49. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  50. if (mysql_num_rows($result) == 0)
  51. { # There is no member with this ID
  52. mysql_close($connection);
  53. header("Location: member404.php"); // change for member specific
  54. exit;
  55. }
  56. #########################################################
  57. # Check if MEMBER ID exists
  58. #########################################################
  59. //Have to figure out how to simultaneously check for WHERE id=$member_id AND id=$offer_id | id=X&o=XX
  60. $member_name = "";
  61. $SqlStatement = "SELECT firstname, lastname FROM qmigo_members WHERE id=$member_id ";
  62. $result = mysql_query($SqlStatement,$connection);
  63. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  64. if ($row = mysql_fetch_array($result,MYSQL_NUM))
  65. { $member_name = "$row[0] ";
  66. }
  67. else
  68. { # There is no member with this ID
  69. mysql_close($connection);
  70. header("Location: member404.php"); // change for member specific
  71. exit;
  72. }
  73. #########################################################
  74. # Check if OFFER HAS NOT EXPIRED - IF SO, DISPLAY LOLCAT
  75. #########################################################
  76. $offer_name = "";
  77. $SqlStatement = "SELECT * FROM qmigo_offers WHERE id=$offer_id ";
  78. $result = mysql_query($SqlStatement,$connection);
  79. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  80. if ($row = mysql_fetch_array($result,MYSQL_ASSOC))
  81. { $offer_name = $row['offer']; // offer name row
  82. $offer_expire = $row['offer_expire']; //offer expire row
  83. $expiredTimeUnix = strtotime($offer_expire);
  84. /*
  85. $time = time(); //server time
  86. $timeUnix = strtotime($time); // server time in Unix Time
  87. */
  88. if ($expiredTimeUnix >= $time)
  89. {
  90. $expired = FALSE ; // False = TIME LEFT / Still Valid
  91. echo "YO" . "<br />";
  92. echo $expiredTimeUnix;
  93. }
  94. else
  95. {
  96. $expired = TRUE; // True = Time Expired
  97. echo "NOT SO BRO";
  98. echo "time:" . $time;
  99. echo "expiredTimeUnix: " . $expiredTimeUnix;
  100. echo "OFFER EXPIRE: " . $offer_expire;
  101. }
  102. // print out other stuff
  103. }
  104. else
  105. { # There is no member with this ID
  106. mysql_close($connection);
  107. header("Location: member404.php"); // change for member specific
  108. exit;
  109. }
  110. #########################################################
  111. # Check if OFFER HAS BEEN REDEEMED ALREADY - MAKE SURE TO PREVENT CHEATING.
  112. #########################################################
  113. //$redeemed = ""; //???
  114. // CHECKS TO MAKE SURE OFFER IS ACTIVE AND NOT REDEEMED
  115. $SqlStatement = "SELECT QR_status from qmigo_status WHERE member_id = ". $member_id ." AND offer_id = " . $offer_id ;
  116. $result = mysql_query($SqlStatement,$connection);
  117. if (!$result) die("Error " . mysql_errno() . " : " . mysql_error());
  118. if ($row = mysql_fetch_assoc($result))
  119. { $redeemed = $row["QR_status"]; // Row for QR_status value
  120. if ($redeemed == 1) {
  121. $redeemed = TRUE ; // QR_status = 1, OFFER HAS ALREADY BEEN REDEEMED
  122. }
  123. else if ($redeemed == 0) {
  124. $redeemed = FALSE; // QR_status = 0, OFFER IS STILL ACTIVE/valid.
  125. //DO SOMETHING IN THE HTML BELOW
  126. }
  127. }
  128. #########################################################
  129. # Use SELECT to show VENDOR INFO + OFFER INFO
  130. #########################################################
  131. # $SqlStatement = "SELECT offer, unix_timestamp(offer_expire) as offer_expire FROM socialdrinkster_offers ORDER BY offer_expire desc LIMIT 1";
  132. // VENDOR X OFFER ONE - TO - MANY
  133. $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,
  134. v.venue_phone FROM qmigo_offers o, qmigo_vendors v WHERE v.id = o.vendor_id AND o.id = $offer_id LIMIT 1";
  135. // PICK SPECIFIC OFFER AND SPICK SPECIFIC VENDOR FROM THAT OFFER
  136. # Run the LATEST VENDOR INFO + OFFER INFO query on the database through the connection
  137. $result = mysql_query($SqlStatement,$connection);
  138. if (!$result)
  139. die("Error " . mysql_errno() . " : " . mysql_error());
  140. ########################################################
  141. # Get our site info -> menu bar
  142. require "offersiteinfo.php";
  143. # Write the Mobile-Friendly header
  144. include "qrheader.php";
  145. $qmigo_url = "http://www.qmigo.com/qmigo-offercheck.php?id=". $member_id . "&o=" . $offer_id;
  146. if ($expired == TRUE) {
  147. // $qrcode = "http://cyn.ical.us/media/blogs/mymedia/prophet_lol_cat.jpg";
  148. // OFFER HAS EXPIRED
  149. $msg = "<h1>Offer already expired.</h1>";
  150. // $SqlStatement = "UPDATE qmigo_status SET QR_status = 2 WHERE member_id = ". $member_id ." AND offer_id = " . $offer_id ;
  151. # 0 = active, 1 = redeemed, 2 = expired
  152. }
  153. else if ($redeemed) {
  154. // $qrcode = "images/socialdrinkster-nodice.gif";
  155. $msg = "No dice. You've already redeemed your offer.";
  156. }
  157. else {
  158. $qrcode = "http://chart.apis.google.com/chart?cht=qr&chs=400x400&chl=" . urlencode($qmigo_url);
  159. // $SqlStatement = "UPDATE socialdrinkster_status SET QR_status = 1 WHERE member_id = ". $member_id ." AND offer_id = " . $offer_id ;
  160. # 0 = active, 1 = redeemed, 2 = expired
  161. $msg = "Redeem offer, " . $member_name ;
  162. }
  163. /*
  164. }
  165. */
  166. $setexpire= mysql_query($SqlStatement,$connection);
  167. if (!$setexpire)
  168. die("Error " . mysql_errno() . " : " . mysql_error());
  169. ?>
  170. <!-- QR CODE PLACED HERE -->
  171. <!-- <img src="<?PHP echo $qrcode ?>" id="qrid" /> -->
  172. <h1><?PHP echo $msg ?> </h1>
  173. <?PHP //echo $member_name ?>
  174. <?
  175. //echo $SqlStatement ;
  176. // NOT RUNNING THE PROPER VENDOR ID WITH OFFER.
  177. $fmt = "%m/%d/%Y %I:%M %p";
  178. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) // {}'s used like '', ""s to recognize as VARIABLE.
  179. {
  180. $t = strftime($fmt,$row['offer_expire']);
  181. $offer_id = $row['id'];
  182. echo <<<END
  183. <br />
  184. <b> $offer_name </b> @ {$row['venue']} <br />
  185. Ends @ <b> $t </b> <br />
  186. {$row['venue_streetaddress']}, {$row['venue_city']},{$row['venue_state']},{$row['venue_zipcode']} <br />
  187. <a class="call" href="tel:1{$row['venue_phone']}"> {$row['venue_phone']} </a><br />
  188. END;
  189. }
  190. ?>
  191. <script language="JavaScript">
  192. // formatting for this javascript applet - TargetDate = "04/15/2010 11:10 PM";
  193. TargetDate = "<?PHP echo $t ?>";
  194. BackColor = "white";
  195. ForeColor = "red";
  196. CountActive = true;
  197. CountStepper = -1;
  198. LeadingZero = true;
  199. //DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
  200. DisplayFormat = "%%H%%H: %%M%%M: %%S%%S";
  201. FinishMessage = "Offer Time is Expired!";
  202. </script>
  203. <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>
  204. <br />
  205. Cheers, <br />
  206. QMIGO
  207. <?
  208. #########################################################
  209. # Write end HTML here
  210. #########################################################
  211. include "mobilefooter.php";
  212. ?>