RedJumpsuit

jobberBase custom development and support

 

Code School

Send Notification When Ads are Expiring

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:

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->QueryArray($sql);
      print_r($row); // this will print the array of the ad that was deactivated
      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 /config.php add:

define('EMAIL_HEADER','Welcome to RedJumpsuit\'s Site!');
define('EMAIL_FOOTER','http://www.redjumpsuit.net');

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 (only partially true) it will still work but you have to access you cron_maintenance.php file from your browser.

the only real purpose of the cron job is to automate running scripts for you. the php way is to just actually run/access the php file. if your cron_maintenance.php is on your root folder, then you can just access it like http://yourjobberbase.site/cron_maintenance.php

would be good though to name your cron_maintenance.php file into something unique to you (like cron_maintenance_xxxxxx.php) where x represents values (like a code or pin) that only you would know, so that not just anybody could run your cron_maintenance.php file

3 Comments

Code School

  1. you just need to save a copy of the file and rename it. then specify the new cron file on your cron tab.

  2. How do I create a new cron_maintenance.php file? I would like to add the form of security you talked about. Great site though it’s really helpfull

Trackbacks

  1. Cron to Deactivate Older Jobs | RedJumpsuit (Not Automatic)

Leave a Response