Guest User

Untitled

a guest
Oct 18th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.35 KB | None | 0 0
  1. <?php
  2.  
  3. $subject="Ofertele zilei MegaPont";
  4. $from = 'Newsletter MegaPont<admin@megapont.ro>';
  5.  
  6. // To send HTML mail, the Content-type header must be set
  7. $headers = 'MIME-Version: 1.0' . "\r\n";
  8. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  9.  
  10. /* Select the City Details*/
  11. $resultSet = mysql_query("select * from coupons_cities where status='A'");
  12. if(mysql_num_rows($resultSet) >0)
  13. {
  14. while($row=mysql_fetch_array($resultSet))
  15. {
  16. if($row['cityid']!='')
  17. {
  18. $cityid = $row['cityid'];
  19.  
  20. //select the deal
  21. $query = "select *,TIMEDIFF(coupons_coupons.coupon_enddate,now())as timeleft,( SELECT count( p.coupon_purchaseid ) FROM coupons_purchase p WHERE p.couponid = coupons_coupons.coupon_id and p.Coupon_amount_Status='T' ) AS pcounts from coupons_coupons left join coupons_shops on coupons_coupons.coupon_shop = coupons_shops.shopid left join coupons_cities on coupons_shops.shop_city = coupons_cities.cityid left join coupons_country on coupons_shops.shop_country = coupons_country.countryid where ";
  22.  
  23.  
  24. //add the city condition
  25. if($cityid)
  26. {
  27. $current_startdate = date("Y-m-d").' 00:00:00';
  28. $current_enddate = date("Y-m-d").' 23:59:59';
  29.  
  30. $query .= "coupon_city = '$cityid' AND coupon_enddate between '$current_startdate' and '$current_enddate' and ";
  31. $query .= "coupon_status = 'A' AND coupon_enddate > now() order by rand() limit 0,1 ";
  32. $result = mysql_query($query);
  33. $deal_type = $admin_language['main_today'];
  34.  
  35. if(mysql_num_rows($result)==0)
  36. {
  37.  
  38. $query = '';
  39. $query = "select *,TIMEDIFF(coupons_coupons.coupon_enddate,now())as timeleft,( SELECT count( p.coupon_purchaseid ) FROM coupons_purchase p WHERE p.couponid = coupons_coupons.coupon_id and p.Coupon_amount_Status='T' ) AS pcounts from coupons_coupons left join coupons_shops on coupons_coupons.coupon_shop = coupons_shops.shopid left join coupons_cities on coupons_shops.shop_city = coupons_cities.cityid left join coupons_country on coupons_shops.shop_country = coupons_country.countryid where ";
  40. $query .= "coupon_city = '$cityid' AND coupon_status = 'A' AND coupon_enddate > now() order by rand() limit 0,1 ";
  41. $result = mysql_query($query);
  42. $deal_type = $admin_language['main_hot'];
  43.  
  44. }
  45.  
  46. }
  47. else
  48. {
  49.  
  50. $query .= "coupon_status = 'A' AND coupon_enddate > now() order by rand() limit 0,1 ";
  51. $result = mysql_query($query);
  52. $deal_type = $admin_language['main_hot'];
  53.  
  54. }
  55.  
  56.  
  57. /* Deals content display here */
  58. if(mysql_num_rows($result) >0)
  59. {
  60.  
  61. while($row = mysql_fetch_array($result))
  62. {
  63. if($row["timeleft"] > "00:00:00")
  64. {
  65.  
  66. //discount value
  67. $discount = ($row["coupon_realvalue"] * ($row["coupon_offer"]/100));
  68. $current_amount = $row["coupon_realvalue"] - $discount; //current rate of deal
  69. $contact_url = DOCROOT.'contactus.html';
  70. $deal_url = DOCROOT.'deals/'.friendlyURL(html_entity_decode($row["coupon_name"], ENT_QUOTES)).'_'.$row['coupon_id'].'.html';
  71. $cityname = html_entity_decode($row["cityname"], ENT_QUOTES);
  72.  
  73. if(file_exists($row["coupon_image"]))
  74. {
  75. $img_url = DOCROOT.$row["coupon_image"];
  76. }
  77. else
  78. {
  79. $img_url = DOCROOT.'themes/'. CURRENT_THEME.'/images/no_image.jpg';
  80. }
  81.  
  82. /* GET THE EMAIL TEMPLATE FROM THE FILE AND REPLACE THE VALUES */
  83. $str = implode("",file('email/newsletter.html'));
  84.  
  85. $str = str_replace("SITEURL",$docroot,$str);
  86. $str = str_replace("CITYNAME",$cityname,$str);
  87. $str = str_replace("DATE",date("l, F j, Y"),$str);
  88. $str = str_replace("FACEBOOK_FOLLOW",FACEBOOK_FOLLOW,$str);
  89. $str = str_replace("TWITTER_FOLLOW",TWITTER_FOLLOW,$str);
  90. $str = str_replace("CURRENT_THEME",CURRENT_THEME,$str);
  91. $str = str_replace("COUPONNAME",ucfirst(html_entity_decode($row["coupon_name"], ENT_QUOTES)),$str);
  92. $str = str_replace("COUPONIMAGESRC",$img_url,$str);
  93. $str = str_replace("CURRENTAMOUNT",round($current_amount).CURRENCY,$str);
  94. $str = str_replace("COUPONREALVALUE",$row["coupon_realvalue"].CURRENCY,$str);
  95. $str = str_replace("COUPONOFFER",$row["coupon_offer"].'%',$str);
  96. $str = str_replace("DISCOUNT",$discount .CURRENCY,$str);
  97. $str = str_replace("SHOPADDRESS",html_entity_decode($row["shop_address"], ENT_QUOTES),$str);
  98. $str = str_replace("CITYNAME",$cityname,$str);
  99. $str = str_replace("COUNTRYNAME",html_entity_decode($row["countryname"], ENT_QUOTES),$str);
  100. $str = str_replace("COUPONDESCRIPTION",nl2br(html_entity_decode($row["coupon_description"], ENT_QUOTES)),$str);
  101. $str = str_replace("CONTACTURL",$contact_url,$str);
  102. $str = str_replace("DEALURL",$deal_url,$str);
  103.  
  104. $str = str_replace("SITENAME",SITE_NAME,$str);
  105.  
  106. //get the purchased coupon's count
  107. $purchased_count = $row["pcounts"];
  108.  
  109. $deal_url = DOCROOT.'deals/'.friendlyURL(html_entity_decode($row["coupon_name"], ENT_QUOTES)).'_'.$row['coupon_id'].'.html';
  110.  
  111.  
  112. }
  113.  
  114.  
  115. /* Select the Email to that purticular city Details*/
  116. //echo "select * from newsletter_subscribers where city_id='$cityid' and status='A'";
  117. $resultSet_Email = mysql_query("select * from newsletter_subscribers where city_id='$cityid' and status='A'");
  118. if(mysql_num_rows($resultSet_Email) >0)
  119. {
  120.  
  121. while($row_Email = mysql_fetch_array($resultSet_Email))
  122. {
  123. if($row_Email['email']!='')
  124. {
  125. $email_list .= $row_Email['email'].',';
  126.  
  127. }
  128.  
  129. }
  130.  
  131. }
  132.  
  133. $to1 = $email_list;
  134. $to = substr($to1,0,strlen($to1)-1);
  135.  
  136.  
  137. // Additional headers
  138. $headers .= 'From: '.$from.'' . "\r\n";
  139. $headers .= 'Bcc: '.$to.'' . "\r\n";
  140.  
  141. $message = $str;
  142.  
  143. $SMTP_USERNAME = SMTP_USERNAME;
  144. $SMTP_PASSWORD = SMTP_PASSWORD;
  145. $SMTP_HOST = SMTP_HOST;
  146. $SMTP_STATUS = SMTP_STATUS;
  147.  
  148. if($SMTP_STATUS==1)
  149. {
  150. include($_SERVER['DOCUMENT_ROOT']."/modules/SMTP/smtp.php"); //mail send thru smtp
  151. }
  152. else
  153. {
  154. mail($from,$subject,$message,$headers);
  155. }
  156.  
  157. $redirect_url = $_SERVER['HTTP_REFERER'];
  158. set_response_mes(1, $admin_language['mailsend']);
  159. url_redirect($redirect_url);
  160.  
  161. /* Ends Select the Email to that purticular city Details*/
  162. }
  163. }
  164. /* End Deals content display here */
  165.  
  166.  
  167. }
  168. }
  169. }
  170.  
  171.  
  172.  
  173.  
  174. ?>
Add Comment
Please, Sign In to add comment