Function EmailExpiryMessages


14/10/04
 

Function EmailExpiryMessages

This is going to be based on snippets from version 1.7 as well as the ExpiryData.xml parsing code that I wrote the day before yesterday. I'm going to use array_pop function again, as I did within the AppendExpiryDataToFile function.

Version 1 of the expiry checker was supposed to email the webmaster if pages had exceeded their expiry dates by a month. I'm not going to bother with that for now. Instead, I'll provide a URL so that anyone can check the contents of the ExpiryDataLastWeek.xml file at any time.

Here goes (1st attempt)...
 
function EmailExpiryMessages($FileName) {

  // open and lock the expiry data file
  $theFile_fp = fopen($FileName, "r+");
  $lock = flock($theFile_fp, 2);

  // continue when lock is obtained
  if ($lock) {

    $db = readDatabase($FileName);

    // Pop each ExpiredPage object and send the email
    while ($poppedExpiredPage = (array_pop($db))):

      $pageURL = $poppedExpiredPage->url;
      $pageOwner = $poppedExpiredPage->owner;
      $pageExpiryDate = $poppedExpiredPage->expired;
      $pageMessage = $poppedExpiredPage->message;

// Prepare the email
$mail_message = "This is to remind you that this web page...
\n  $pageURL
\n...expired on $pageExpiryDate. Here is the reminder message (if any):
\n*** $pageMessage ***
\nYou will receive a reminder each day that this page is hit. 
Please update the page as necessary, and remember to specify a new 
expiry date."; 

      // Now send the email
      mail($pageOwner, "Expiry Checker: $pageURL", $mail_message);

    endwhile;

  }  // unlock and close reminders file
  $lock = flock($theFile_fp, 3);
  fclose($theFile_fp);

}
 

 
 

<<contents ^top^