111 lines
3.3 KiB
PHP
111 lines
3.3 KiB
PHP
<?php
|
|
$BASEDIR = str_replace("/event-email.php","",$SCRIPT_FILENAME);
|
|
include "$BASEDIR/db.php";
|
|
include "include/table.php";
|
|
|
|
$email_header = new Table("email_header");
|
|
|
|
|
|
|
|
//
|
|
// Get set of schools to process
|
|
//
|
|
$query = "select * from schools " .
|
|
"where status = 'Active' " .
|
|
"and email_system = 'Y' " .
|
|
"and other_modules = 'Y' " .
|
|
"order by school_name";
|
|
$schools = db_query($query);
|
|
|
|
$today = date("Y-m-d",time());
|
|
$end_date = date("Y-m-01",time() + 60 * 60 * 24 * 118);
|
|
|
|
while ($school = db_fetch_array($schools)) {
|
|
$school_name = $school['school_name'];
|
|
$school_num = $school['record_num'];
|
|
$pac_name = $school['pac_name'];
|
|
|
|
// Determine how many events there are in the calendar for this school
|
|
$query = "select * from event_calendar " .
|
|
"where school_num = $school_num " .
|
|
"and ((start_date >= '$today' and start_date < '$end_date') " .
|
|
"or (end_date >= '$today' and end_date < '$end_date')) " .
|
|
"order by start_date,end_date";
|
|
$events = db_query($query);
|
|
$num_events = db_num_rows($events);
|
|
|
|
if ($num_events == 0) continue;
|
|
|
|
|
|
//
|
|
// Process the events
|
|
//
|
|
$message = "<center>\n" .
|
|
" <table width='95%' cellpadding='2' cellspacing='0' class='content-table'>\n" .
|
|
" <tr>\n" .
|
|
" <td align='left' class='heading'>Upcoming Events from $pac_name Event Calendar</td>\n" .
|
|
" </tr>\n";
|
|
|
|
$count = 0;
|
|
while ($event = db_fetch_array($events)) {
|
|
extract($event);
|
|
|
|
$class = 'data-even';
|
|
if ($count %2 ) $class = 'data-odd';
|
|
$count++;
|
|
|
|
if (strlen($location) > 0) $location = " -- @ $location";
|
|
|
|
$message .= " <tr class='success'>\n" .
|
|
" <td align='left' valign='top'><b>$title</b></td>\n" .
|
|
" </tr>\n" .
|
|
" <tr class='$class'>\n" .
|
|
" <td align='left' valign='top'>$date_and_time $location<br><br></td>\n" .
|
|
" </tr>\n";
|
|
}
|
|
|
|
$message .= " </table>\n" .
|
|
"</center>\n";
|
|
|
|
|
|
//
|
|
// Determine how many matching records there are
|
|
//
|
|
$where_clause = "where email is not null and email != '' and school_num = $base_school_num and receive_emails = 'Y' ";
|
|
// $where_clause .= "and userid = 'mfester' ";
|
|
$query = "select count(*) from users " . $where_clause;
|
|
$matching_records = db_getVal($query);
|
|
|
|
|
|
//
|
|
// Create email header
|
|
//
|
|
$category = "Parent Events Broadcast";
|
|
$description = "Broadcast to Parents";
|
|
$reply_address = $school['reply_email'];
|
|
$reply_description = $school['reply_description'] . " Events";
|
|
$email_message_id = 0;
|
|
$subject = "$pac_name Event Calendar";
|
|
$message_text = db_getVal("select content from formatted_content where school_num = $school_num and content_type = 'Events'");
|
|
$message_text .= $message;
|
|
$email_template = "EmailTemplate.html";
|
|
$posted = date("Y-m-d H:i:s",time());
|
|
$send_after = date("Y-m-d H:i:s",time());
|
|
$status = "open";
|
|
$user_num = 0;
|
|
$processed_records = 0;
|
|
$sent_successfully = 0;
|
|
$skipped = 0;
|
|
$errors = 0;
|
|
$email_field_name = "email";
|
|
$primary_table = "users";
|
|
$query = "select * from users " . $where_clause .
|
|
"order by email,record_num";
|
|
|
|
// Create and insert the header record
|
|
$insert = $email_header->BuildInsert();
|
|
db_query($insert);
|
|
}
|
|
|
|
?>
|