Jump to content

Need help with PHP problem


dejansoftware

Recommended Posts

Newsletter works OK except Training schedule, Interviews schedule and Exams schedule which are showing day in future when they will be published.The problem is because the my newsletter will send this training, Interviews or Exams one the day when the schedule is on (evening of this day, about 11 PM), but I would like if they can be sent at least one day before that term, otherwise, they are useless and they are just provoke our customers, so I copy a part of newsletter code and excluded this 3 category ID.Here are couple more clarifications:If I publish article/s from different categories, newsletter.php will check for new articles and all of them will be putted to the newsletter and automatically sent on the same day.For example:18th october is term for exam. Newsletter will be sent on 18th october on the same day (later at night). So most of the customers will read it first thing in the morning (that's 19th), instead of at least 17th october.So the problem is just with scheduled articles for future publishing (Training schedule, Interviews schedule and Exams schedule).This Newsletter works fine with other news, the problem is just for articles schedules for future publishing, so if you can look at this code and help me to find the solution.Look for the kategorija in and kategorija not in (kategorija = category)Thanks

<?phpfunction auto_newsletter(){global $webpath, $path, $prefix, $admin_mail, $title, $lang;		$lang = "latn";$query = sprintf("SELECT datum FROM %s_logs WHERE sistem ='newsletter' LIMIT 1;", $prefix);$sql = mysql_query($query) or die(mysql_error());$data = mysql_fetch_array($sql, MYSQL_ASSOC);$sql = NULL;		$time = 24;$Datum = mktime(date("H")-$time, date("i"), date("s"), date("m") , date("d"), date("Y"));$Datum = strtotime(date('Y-m-d H:i:s', $Datum));//		$data["datum"] = "2008-03-07 08:00:00 ";$datum = strtotime(date('Y-m-d H:i:s', strtotime($data["datum"])));		$datum2 = date('Y-m-d H:i:s', mktime(date("H", strtotime($data["datum"]))+$time, date("i", strtotime($data["datum"])), date("s", strtotime($data["datum"])), date("m", strtotime($data["datum"])) , date("d", strtotime($data["datum"])), date("Y", strtotime($data["datum"]))));if ($Datum > $datum) {// Ovaj blok koristim za promjenu viewa odredjenih vijesti// $prije = date('Y-m-d H:i:s', mktime(0, 0, 0, date("m")-3, date("d"), date("Y")));// $query = sprintf("UPDATE %s_vijesti SET prikaz=0 WHERE objavljen < %s AND kategorija=2; ", $prefix, quote_smart($prije));//  mysql_query($query) or die(zabrane("error", "Problem u skrivanju konkursa prije $prije"));// kraj bloka$query = sprintf("UPDATE %s_logs SET datum=%s WHERE sistem ='newsletter' LIMIT 1;", $prefix, quote_smart($datum2));$sql = mysql_query($query);// u ovom slucaju spamovanje naroda je ok, tako da treba sad skupiti vijesti za slanje$query = sprintf("SELECT * FROM %s_vijesti WHERE lang='$lang' AND objavljen BETWEEN %s AND %s AND kategorija not in (10,11,12,16,17,18,19,20,21) ORDER BY objavljen DESC; ", $prefix, quote_smart($data["datum"]), quote_smart($datum2));			$data = NULL;$sql = mysql_query($query);			if (mysql_num_rows($sql) <> 0) {			// postoji li razlog za slanje newsletterawhile ($data = mysql_fetch_array($sql, MYSQL_ASSOC)) {$kat = $data["kategorija"];if (file_exists($path."/docs/news/".$filename."-mala.jpg")) {$html .= "<img src='".$webpath."/docs/news/".$filename."-mala.jpg' alt='' title='' align='left' hspace='10' vspace='10' />";}				$page = modul_page('news_categorised', $data["kategorija"]);$html .="<p><strong><a href='$webpath/$lang/?page=$page&kat=$kat&vijest=".$data["id"]."'>".$data["naslov"]."</a></strong>";$text =  "<p>".strip_tags($data["text"])."<hr />";$duzina = 400;while(substr($text, $duzina, 1)<>" " AND strlen($text)>$duzina){ $duzina++; }$html .= substr($text, 0, $duzina);}$html = "<h1>".convert("newsletter").": ".date('d.m.Y.', $datum)."</h1>".$html;			$query = sprintf("SELECT mail FROM %s_korisnici WHERE alerts>0 AND nivo>0; ", $prefix);$sql = mysql_query($query) or die(mysql_error());			if (mysql_num_rows($sql) <> 0) {require("$path/data/class.phpmailer.php");				$html = sprintf(convert("notification_header"), $webpath, $webpath, $webpath, $title, $title).$html.convert("notification_footer");				while ($data = mysql_fetch_array($sql, MYSQL_ASSOC)) {					$mejl = new PHPMailer();$mejl->From     = $admin_mail;$mejl->FromName = $title;$mejl->Host     = "mail.vladars.net";$mejl->Mailer   = "smtp";$mejl->Subject  = convert("newsletter").": ".date('d.m.Y.', $datum);					$mejl->Body    = $html;$mejl->AltBody = $title."\n________________________________\n".strip_tags($html);$mejl->AddAddress($data["mail"]);//	$mejl->AddBCC("robot@grave-design.com");//	echo $data["mail"], " ";if(!$mejl->Send()) zabrane("mailer", $data["mail"]);$mejl->ClearAddresses();$mejl->ClearAttachments();				}			}}}// najava 1$sql = NULL;$time = 48;$Datum = mktime(date("H")-$time, date("i"), date("s"), date("m") , date("d"), date("Y"));$datumOd = mktime(date("H")-$time, date("i"), date("s"), date("m") , date("d"), date("Y"));$Datum = strtotime(date('Y-m-d H:i:s', $Datum));//		$data["datum"] = "2008-03-07 08:00:00 ";$datum = strtotime(date('Y-m-d H:i:s', strtotime($data["datum"])));		//$datum2 = date('Y-m-d H:i:s', mktime(date("H", strtotime($data["datum"]))+$time, date("i", strtotime($data["datum"])), date("s", strtotime($data["datum"])), date("m", strtotime($data["datum"])) , date("d", strtotime($data["datum"])), date("Y", strtotime($data["datum"]))));$datum2 = date('Y-m-d H:i:s', mktime(date("H", strtotime($data["datum"])), date("i", strtotime($data["datum"])), date("s", strtotime($data["datum"])), date("m", strtotime($data["datum"])) , date("d", strtotime($data["datum"])), date("Y", strtotime($data["datum"]))));if ($Datum > $datum) {// Ovaj blok koristim za promjenu viewa odredjenih vijesti// $prije = date('Y-m-d H:i:s', mktime(0, 0, 0, date("m")-3, date("d"), date("Y")));// $query = sprintf("UPDATE %s_vijesti SET prikaz=0 WHERE objavljen < %s AND kategorija=2; ", $prefix, quote_smart($prije));//  mysql_query($query) or die(zabrane("error", "Problem u skrivanju konkursa prije $prije"));// kraj bloka$query = sprintf("UPDATE %s_logs SET datum=%s WHERE sistem ='newsletter' LIMIT 1;", $prefix, quote_smart($datum2));$sql = mysql_query($query);// u ovom slucaju spamovanje naroda je ok, tako da treba sad skupiti vijesti za slanje$query = sprintf("SELECT * FROM %s_vijesti WHERE lang='$lang' AND objavljen BETWEEN %s AND %s AND kategorija  in (10,11,12,16,17,18,19,20,21) ORDER BY objavljen DESC; ", $prefix, quote_smart($data["datum"]), quote_smart($datum2));			$data = NULL;$sql = mysql_query($query);			if (mysql_num_rows($sql) <> 0) {			// postoji li razlog za slanje newsletterawhile ($data = mysql_fetch_array($sql, MYSQL_ASSOC)) {$kat = $data["kategorija"];if (file_exists($path."/docs/news/".$filename."-mala.jpg")) {$html .= "<img src='".$webpath."/docs/news/".$filename."-mala.jpg' alt='' title='' align='left' hspace='10' vspace='10' />";}				$page = modul_page('news_categorised', $data["kategorija"]);$html .="<p><strong><a href='$webpath/$lang/?page=$page&kat=$kat&vijest=".$data["id"]."'>".$data["naslov"]."</a></strong>";$text =  "<p>".strip_tags($data["text"])."<hr />";$duzina = 400;while(substr($text, $duzina, 1)<>" " AND strlen($text)>$duzina){ $duzina++; }$html .= substr($text, 0, $duzina);}$html = "<h1>".convert("newsletter").": ".date('d.m.Y.', $datum)."</h1>".$html;			$query = sprintf("SELECT mail FROM %s_korisnici WHERE alerts>0 AND nivo>0; ", $prefix);$sql = mysql_query($query) or die(mysql_error());			if (mysql_num_rows($sql) <> 0) {require("$path/data/class.phpmailer.php");				$html = sprintf(convert("notification_header"), $webpath, $webpath, $webpath, $title, $title).$html.convert("notification_footer");				while ($data = mysql_fetch_array($sql, MYSQL_ASSOC)) {					$mejl = new PHPMailer();$mejl->From     = $admin_mail;$mejl->FromName = $title;$mejl->Host     = "mail.vladars.net";$mejl->Mailer   = "smtp";$mejl->Subject  = convert("newsletter").": ".date('d.m.Y.', $datum);					$mejl->Body    = $html;$mejl->AltBody = $title."\n________________________________\n".strip_tags($html);$mejl->AddAddress($data["mail"]);//	$mejl->AddBCC("robot@grave-design.com");//	echo $data["mail"], " ";if(!$mejl->Send()) zabrane("mailer", $data["mail"]);$mejl->ClearAddresses();$mejl->ClearAttachments();				}			}}}// end of the announcement}?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...