Topic: Notify when ads are expiring
Hi all, I know some of you are wanting to notify your job posters when their ads are about to expire (if you are offering a premium service of some sort) so I thought I'd share this simple mod with all of you.
On /_includes folder, on class.Maintenance.php, comment out the block
// deactivate jobs older than 30 days
/**
public function DeactivateJobs()
{
global $db;
$sql = 'UPDATE jobs SET is_active = 0 WHERE DATEDIFF(NOW(), created_on) > 30 AND is_active = 1';
$db->Execute($sql);
}
**/
then add below it:
// deactivate jobs older than 30 days + notification
public function DeactivateJobs()
{
$postMan = new Postman();
global $db;
$notifmin = 27; //the day when you want notification to be sent prior to the ad expiring
$notifmax = 30; //the day the ad actually expires
$dayscount = $notifmax - $notifmin;
$sql = 'SELECT * FROM jobs WHERE DATEDIFF(NOW(), created_on) >= .' $notifmin '. AND is_active = 1';
$row = $db->Execute($sql);
foreach ( $row as $rows )
{
$ademail = trim(strtolower($rows['poster_email']))
$adname = trim($rows['title']);
$adcomp = trim($rows['company']);
$adurl = BASE_URL . "job/" . $rows['id'] . "/";
$sqlu = "UPDATE jobs SET is_active = 0 WHERE DATEDIFF(NOW(), created_on) > ". $notifmax ." AND is_active = 1 AND id = " . $rows['id']) ;
$db->Execute($sqlu);
$postMan->MailExpiringAd($ademail, $adname, $adcomp, $adurl, $dayscount);
}
}
on /_includes, on class.Postman.php
add:
// mail client when ad is expiring
public function MailExpiringAd($email, $name, $comp, $url, $days)
{
$msg = EMAIL_HEADER . "\n\nWe'd like to inform you that your ad <". $name .">: \n\n". $url ."\n\nunder the Company <". $comp ."> is expiring in ". $days ." days.";
$msg .= "\n\nThank you for using our service!";
$msg .= "\n\n---\n" . EMAIL_FOOTER ;
$subject = "Your ad in " . SITE_NAME . " is expiring in ". $days ." days.";
if (mail($email, $subject, $msg, "From: " . SITE_NAME . " <" . NOTIFY_EMAIL .">"))
{
return true;
}
else
{
return false;
}
}
on cron_maintenance.php
add:
require_once '_includes/class.Postman.php';
and make sure that this line exists
// deactivate jobs older than 30 days + notification
$janitor->DeactivateJobs();
and lastly, you must set-up a cron job to run the cron_maintenance.php file or else the script wont work ![]()
as usual, for other questions, you can email me at myredjumpsuit [at] gmail [dot] com