-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.php
57 lines (50 loc) · 1.79 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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();