-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checking in old birthday-reminder script code.
- Loading branch information
William T Navarre
committed
Jan 16, 2016
1 parent
253b314
commit 71fc5a5
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
############################################################################### | ||
# $Id$ | ||
# Script to run daily tasks | ||
############################################################################### | ||
|
||
require_once dirname(__FILE__).'/common.php'; | ||
|
||
# Mails a list of today's birthdays to the chairman | ||
function getBirthdays() { | ||
global $mdb2; | ||
|
||
# Who is the current chairman? | ||
$sql = "SELECT display_name FROM staff WHERE position = 'Chairman' AND " . | ||
"active = 'yes'"; | ||
$res =& $mdb2->query($sql); | ||
if(PEAR::isError($res)) { | ||
error_log($res->getDebugInfo()); | ||
fatal("Could not get chairman's name: ".$res->getMessage()); | ||
} | ||
$chairman = $res->fetchOne(); | ||
$chairtok = explode(" ", $chairman); | ||
$res->free(); | ||
|
||
# Get today's Birthdays | ||
$sql = "SELECT display_name, YEAR(CURDATE()) - YEAR(birthday) AS age FROM " . | ||
"staff WHERE MONTH(CURDATE()) = MONTH(birthday) AND DAY(CURDATE()) = " . | ||
"DAY(birthday) AND active = 'yes' GROUP BY display_name ORDER BY " . | ||
"birthday ASC"; | ||
$res =& $mdb2->query($sql); | ||
if(PEAR::isError($res)) { | ||
error_log($res->getDebugInfo()); | ||
fatal("Could not get today's birthdays: ".$res->getMessage()); | ||
} | ||
$rows = $res->numRows; | ||
if ( $rows == 0 ) { | ||
$res->free(); | ||
return; | ||
} | ||
$res->bindColumn('display_name', $name); | ||
$res->bindColumn('age', $age); | ||
|
||
# Form mail message | ||
$message = "Hi $chairtok[0],\n\n"; | ||
while ($row = $res->fetchRow()) { | ||
$message .= " $name is $age today.\n"; | ||
} | ||
$message .= "\nPlease send them birthday wishes!\n\n"; | ||
$message .= "Sincerely,\n\nThe Masthead and Maillist Maintenance System\n"; | ||
|
||
# Mail the results | ||
mail("$chairman <[email protected]>", "Today's Birthday Reminders", | ||
$message, "From: 3M Birthday Reminder <[email protected]>"); | ||
} // end of getBirthdays() | ||
|
||
### Run Commands | ||
getBirthdays(); |