<?php
/*
* ConPortal - Pomona College ITS scheduling appplication
* Copyright (C) 2005-2008 Pomona College & Bucknell University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//This function sends an e-mail to usercons with information about a temp drop
function email_cons_temp_drop($shiftPid,$userPid,$message)
{
$name = getNameForUser($userPid);
$shiftData = getShiftDetailsHumanReadable($shiftPid);
$subject = 'Temp Drop - ' . $shiftData['day_of_week'] . ', ' . $shiftData['start_date'] .
' - ' . $shiftData['start_time'] . '-' . $shiftData['end_time'];
if ($userPid != $_SESSION['pid']) {
$altName = getNameForUser($_SESSION['pid']);
$body = "Shift posted by $altName on behalf of $name\n\n";
} else {
$body = "Shift posted by $name\n\n";
}
//$body .= $message."\n";
$body .= $subject . "\n\n" . $message . "\n\n" . EMAIL_FOOTER;
if(USER_CONTROLS_DROPTAKE_EMAIL == FALSE)
send_email($body,$subject,USERCONS);
else{
$users = getUsersForEmail("drop_emails");
foreach($users as $user)
send_email($body,$subject,$user["email"]);
}
$text = $subject . " dropped by " . $name;
addChangelogRecord($text, TRUE, $shiftPid);
}
//This function sends an e-mail to usercons with information about a temp take
function email_cons_temp_take($shiftPid,$userPid,$message)
{
$name = getNameForUser($userPid);
$shiftData = getShiftDetailsHumanReadable($shiftPid);
$subject = 'Temp Take - ' . $shiftData['day_of_week'] . ', ' . $shiftData['start_date'] .
' - ' . $shiftData['start_time'] . '-' . $shiftData['end_time'];
$shiftData['position'];
if ($userPid != $_SESSION['pid']) {
$altName = getNameForUser($_SESSION['pid']);
$body = "Shift taken by $altName on behalf of $name\n\n";
} else {
$body = "Shift taken by $name\n\n";
}
//$body .= $message."\n";
$body .= $subject . "\n\n" . $message . "\n\n" . EMAIL_FOOTER;
if(USER_CONTROLS_DROPTAKE_EMAIL == FALSE)
send_email($body,$subject,USERCONS);
else{
$users = getUsersForEmail("take_emails");
foreach($users as $user)
send_email($body,$subject,$user["email"]);
}
removeChangelogRecordByShiftPid($shiftPid);
}
//This function sends an e-mail to usercons with information about a perm drop
function email_cons_perm_drop($shiftPid,$userPid,$message)
{
$name = getNameForUser($userPid);
$shiftData = getShiftDetailsHumanReadable($shiftPid);
$subject = 'Perm Drop - ' . $shiftData['day_of_week'] . ', ' . $shiftData['start_date'] . '-' .
$shiftData['end_date'] . ' - ' . $shiftData['start_time'] . '-' . $shiftData['end_time'];
if ($userPid != $_SESSION['pid']) {
$altName = getNameForUser($_SESSION['pid']);
$body = "Shift posted by $altName on behalf of $name\n\n";
} else {
$body = "Shift posted by $name\n\n";
}
//$body .= $message."\n";
$body .= $subject . "\n\n" . $message . "\n\n" . EMAIL_FOOTER;
if(USER_CONTROLS_DROPTAKE_EMAIL == FALSE)
send_email($body,$subject,USERCONS);
else{
$users = getUsersForEmail("drop_emails");
foreach($users as $user)
send_email($body,$subject,$user["email"]);
}
$text = $subject . " dropped by " . $name;
addChangelogRecord($text, FALSE, $shiftPid);
}
//This function sends an e-mail to usercons with information about a perm take
function email_cons_perm_take($shiftPid,$userPid,$message)
{
$name = getNameForUser($userPid);
$shiftData = getShiftDetailsHumanReadable($shiftPid);
$subject = 'Perm Take - ' . $shiftData['day_of_week'] . ', ' . $shiftData['start_date'] . '-' .
$shiftData['end_date'] . ' - ' . $shiftData['start_time'] . '-' . $shiftData['end_time'];
if ($userPid != $_SESSION['pid']) {
$altName = getNameForUser($_SESSION['pid']);
$body = "Shift taken by $altName on behalf of $name\n\n";
} else {
$body = "Shift taken by $name\n\n";
}
//$body .= $message."\n";
$body .= $subject . "\n\n" . $message . "\n\n" . EMAIL_FOOTER;
if(USER_CONTROLS_DROPTAKE_EMAIL == FALSE)
send_email($body,$subject,USERCONS);
else{
$users = getUsersForEmail("drop_emails");
foreach($users as $user)
send_email($body,$subject,$user["email"]);
}
removeChangelogRecordByShiftPid($shiftPid);
}
/*
* Email an appointment assignee about a status change
*/
function emailAssignee ($appt_pid)
{
$appt = getAppointmentDetails($appt_pid);
$status = $appt['status'];
if ($status == "Cancelled" or $status == "Scheduled")
{
// Look up assignee
$timestamp = $appt['start_time'];
$shift = getShiftDetails(getShiftForTimeAndPosition($timestamp, $appt['position']));
if (isset($shift['owner']) and $shift['owner'] != 0)
{
// Send email to assignee
$userinfo = getUserDetails($shift['owner']);
$to = $userinfo['username'] . EMAIL_DOMAIN;
$subject = "Appointment " . $status;
$body = "";
if ($status == "Scheduled")
{
$body = "An appointment has been scheduled for you on " . timestamp_to_prettydate($timestamp) .
" at " . date("g:ia", $timestamp) . ".\n\n" .
"Ticket number: {$appt['ticket_number']}\n" .
"Description: {$appt['description']}\n" .
"Scheduled by: " . getNameForUser($appt['author']);
}
else
{
$body = "Your appointment on " . timestamp_to_prettydate($timestamp) . " at " .
date("g:ia", $timestamp) . " has been cancelled.";
}
send_email($body, $subject, $to);
}
elseif ($status == "Scheduled")
{
// Send the email to supers
$subject = "Appointment Scheduled for Unstaffed Shift";
$body = "An appointment has been scheduled on " . timestamp_to_prettydate($timestamp) .
" at " . date("g:ia", $timestamp) . ".\n\n" .
"Ticket number: {$appt['ticket_number']}\n" .
"Description: {$appt['description']}\n" .
"Scheduled by: " . getNameForUser($appt['author']);
send_email($body, $subject, SUPERS);
}
}
}
//This function sends an e-mail with the given subject and body to the
//specified list. It appends a note saying it was automatically sent by
//conportal and apends a URL to access the site.
function send_email($body,$subject,$to)
{
/* This is the original code to do this, but relying on PHP's built in mail() doesn't work in our envirionment. Retaining for reference purposes.
$body .= "\n\nThis message was automatically generated by the ITS ".
"Consultant Portal. You can visit it by going to ".BASE_URL.".";
mail($to,$subject,$body,"From: " . SUPERS); */
//We're implementing sending the mail with the PEAR Mail() feature to send through our
//authenticated SMTP server
include_once('Mail.php');
$headers['From'] = 'hide@address.com';
$headers['Reply-To'] = SUPERS;
$headers['To'] = $to;
$headers['Subject'] = $subject;
$params["host"] = 'smtpauth.bucknell.edu';
$params["port"] = '587';
$params["auth"] = true;
/*$params["host"] = 'smtp.bucknell.edu';
$params["port"] = '25';
$params["auth"] = false;*/
$params["username"] = 'techdesk';
$params["password"] = EMAIL_PASSWORD;
$params["localhost"] = 'linuxremote3.eg.bucknell.edu';
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('smtp', $params);
//The MOMENT OF TROOTH!!!!111
//Incidentally, that $to argument seems redundant; it's also included in the headers.
//Don't ask me, I just work here.
$mail_object->send($to, $headers, $body);
}
?>