/** * Sends an email notification to the user * This function sends an email notifiying the user * of creation/modification/deletion of a reservation * @param string $type type of modification made to the reservation * @param array $repeat_dates array of dates reserved on * @param array $users_to_inform array of emails to CC about the reservation mod * @global $conf */ function send_email($type, $repeat_dates = null, $users_to_inform = null) { global $conf; // Dont bother if nobody wants email if (!$this->user->wants_email($type) && !$conf['app']['emailAdmin']) { return; } // Email addresses $adminemail = $this->sched['adminemail']; $techEmail = $conf['app']['techEmail']; $url = CmnFns::getScriptURL(); // Format date $start_date = Time::formatReservationDate($this->start_date, $this->start); $end_date = Time::formatReservationDate($this->end_date, $this->end); $start = Time::formatTime($this->get_start()); $end = Time::formatTime($this->get_end()); $defs = array(translate('Reservation #'), translate('Start Date'), translate('End Date'), translate('Resource'), translate('Start Time'), translate('End Time'), translate('Location'), translate('Contact')); switch ($type) { case 'e_add': $mod = 'created'; break; case 'e_mod': $mod = 'modified'; break; case 'e_del': $mod = 'deleted'; break; case 'e_app': $mod = 'approved'; break; } $to = $this->user->get_email(); // Who to mail to $subject = translate("Reservation {$mod} for", array($start_date)); $uname = $this->user->get_fname(); $location = $this->resource->properties['location']; $phone = $this->resource->properties['rphone']; $name = $this->resource->properties['name']; $location = !empty($location) ? $location : translate('N/A'); $phone = !empty($phone) ? $phone : translate('N/A'); if ($mod == 'approved') { $text = translate_email('reservation_activity_7', $uname, $this->id, $start_date, $start, $end_date, $end, $name, $location, translate($mod)); } else { $text = translate_email('reservation_activity_1', $uname, translate($mod), $this->id, $start_date, $start, $end_date, $end, $name, $location, translate($mod)); } if ($this->is_repeat && count($repeat_dates) > 1) { // Start at index = 1 because at index 0 is the parent date $text .= translate_email('reservation_activity_2'); for ($d = 1; $d < count($repeat_dates); $d++) { $text .= Time::formatDate($repeat_dates[$d]) . "\r\n<br/>"; } $text .= "\r\n<br/>"; } if ($type != 'e_add' && $this->is_repeat) { $text .= translate_email('reservation_activity_3', translate($mod)); } if (!empty($this->summary)) { $text .= stripslashes(translate_email('reservation_activity_4', $this->summary)); } $phone = "202-994-9870"; $text .= translate_email('reservation_activity_5', $adminemail, $phone, $conf['app']['title'], $url, $url); if (!empty($techEmail)) { $text .= translate_email('reservation_activity_6', $techEmail, $techEmail); } if ($this->user->wants_html()) { $msg = <<<EOT <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" \t\t"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> \t<!-- \tbody { \t\tfont-size: 11px; \tfont-family: Verdana, Arial, Helvetica, sans-serif; \t\tbackground-color: #F0F0F0; \t} \ta { \t\tcolor: #104E8B; \t\ttext-decoration: none; \t} \ta:hover { \t\tcolor: #474747; \t\ttext-decoration: underline; \t} \ttable tr.header td { \t\tpadding-top: 2px; \t\tpadding-botton: 2px; \t\tbackground-color: #CCCCCC; \t\tcolor: #000000; \t\tfont-weight: bold; \t\tfont-size: 10px; \t\tpadding-left: 10px; \t\tpadding-right: 10px; \t\tborder-bottom: solid 1px #000000; \t} \ttable tr.values td { \t\tborder-bottom: solid 1px #000000; \t\tpadding-left: 10px; \t\tpadding-right: 10px; \t\tfont-size: 10px; \t} \t--> \t</style> </head> <body> {$text} <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr class="header"> <td>{$defs[0]}</td> <td>{$defs[1]}</td> <td>{$defs[2]}</td> <td>{$defs[3]}</td> <td>{$defs[4]}</td> <td>{$defs[5]}</td> <td>{$defs[6]}</td> \t<td>{$defs[7]}</td> </tr> <tr class="values"> <td>{$this->id}</td> <td>{$start_date}</td> \t<td>{$end_date}</td> <td>{$name}</td> <td>{$start}</td> <td>{$end}</td> <td>{$location}</td> <td>{$phone}</td> </tr> </table> </body> </html> EOT; } else { $text = strip_tags($text); // Strip out HTML tags $msg = $text; $fields = array(array($defs[0], $this->id, strlen($this->id) < strlen($defs[0]) ? strlen($defs[0]) : strlen($this->id)), array($defs[1], $start_date, strlen($start_date) < strlen($defs[1]) ? strlen($defs[1]) : strlen($start_date)), array($defs[2], $end_date, strlen($end_date) < strlen($defs[2]) ? strlen($defs[2]) : strlen($end_date)), array($defs[3], $name, strlen($name) < strlen($defs[3]) ? strlen($defs[3]) : strlen($name)), array($defs[4], $start, strlen($start) < strlen($defs[4]) ? strlen($defs[4]) : strlen($start)), array($defs[5], $end, strlen($end) < strlen($defs[5]) ? strlen($defs[5]) : strlen($end)), array($defs[6], $location, strlen($location) < strlen($defs[6]) ? strlen($defs[6]) : strlen($location)), array($defs[7], $phone, strlen($phone) < strlen($defs[7]) ? strlen($defs[7]) : strlen($phone))); $total_width = 0; foreach ($fields as $a) { // Create total width by adding all width fields plus the '| ' that occurs before every cell and ' ' after $total_width += 2 + $a[2] + 1; } $total_width++; // Final '|' $divider = '+' . str_repeat('-', $total_width - 2) . '+'; // Row dividers $msg .= $divider . "\n"; $msg .= '| ' . translate("Reservation {$mod}") . str_repeat(' ', $total_width - strlen(translate("Reservation {$mod}")) - 4) . " |\n"; $msg .= $divider . "\n"; foreach ($fields as $a) { // Repeat printing all title fields, plus enough spaces for padding $msg .= "| {$a['0']}" . str_repeat(' ', $a[2] - strlen($a[0]) + 1); } $msg .= "|\n"; // Close the row $msg .= $divider . "\n"; foreach ($fields as $a) { // Repeat printing all field values, plus enough spaces for padding $msg .= "| {$a['1']}" . str_repeat(' ', $a[2] - strlen($a[1]) + 1); } $msg .= "|\n"; // Close the row $msg .= $divider . "\n"; } $send = false; // Send email using PHPMailer $mailer = new PHPMailer(); $mailer->ClearAllRecipients(); if ($this->user->wants_email($type)) { $send = true; $mailer->AddAddress($to, $uname); if ($conf['app']['emailAdmin']) { // Add the admin to the CC if they want it $mailer->AddBCC($adminemail, translate('Administrator')); } } else { if ($conf['app']['emailAdmin']) { $send = true; $mailer->AddAddress($adminemail, translate('Administrator')); } } if (!empty($users_to_inform)) { foreach ($users_to_inform as $idx => $email) { $mailer->AddCC($email); } } $mailer->From = $adminemail; $mailer->FromName = $conf['app']['title']; $mailer->Subject = $subject; $mailer->Body = $msg; $mailer->IsHTML($this->user->wants_html()); if ($send) { $mailer->Send(); } $headers = null; unset($headers, $msg, $fields); }
/** * Return the formatted and timezone adjusted date * @param int $ts time stamp for date to format * @return formatted date */ function get_display_date() { return Time::formatReservationDate($this->_date['todayTs'], $this->startDay, null, 'schedule_daily'); }
/** * This function prints a table of all upcoming * reservations that the current user has been invited to but not yet responded to. * It also provides a way for them to accept/decline invitations * @param mixed $res array of reservation data * @param string $err last error message from database */ function showParticipatingTable($res, $err) { global $link; ?> <table width="100%" border="0" cellspacing="0" cellpadding="1" align="center"> <tr> <td class="tableBorder"> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td colspan="7" class="tableTitle"> <a href="javascript: void(0);" onclick="showHideCpanelTable('accepted');">› <?php echo translate('My Reservation Participation'); ?> </a> </td> <td class="tableTitle"> <div align="right"> <?php $link->doLink('javascript: help(\'my_participation\');', '?', '', 'color: #FFFFFF;', translate('Help') . ' - ' . translate('My Reservation Participation')); ?> </div> </td> </tr> </table> <div id="accepted" style="display: <?php echo getShowHide('accepted'); ?> "> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr class="rowHeaders"> <td width="10%"><?php echo translate('Start Date'); ?> </td> <td width="10%"><?php echo translate('End Date'); ?> </td> <td width="23%"><?php echo translate('Resource'); ?> </td> <td width="10%"><?php echo translate('Start Time'); ?> </td> <td width="10%"><?php echo translate('End Time'); ?> </td> <td width="20%"><?php echo translate('Owner'); ?> </td> <td width="16%"><?php echo translate('End Participation'); ?> </td> </tr> <?php // Write message if they have no reservations if (!$res) { echo ' <tr class="cellColor"><td colspan="7" align="center">' . $err . '</td></tr>'; } // For each reservation, clean up the date/time and print it for ($i = 0; is_array($res) && $i < count($res); $i++) { $rs = $res[$i]; $class = 'cellColor' . $i % 2; echo " <tr class=\"{$class}\" align=\"center\">" . ' <td>' . $link->getLink("javascript: reserve('v','','','" . $rs['resid'] . "');", Time::formatReservationDate($rs['start_date'], $rs['starttime']), '', '', translate('View this reservation')) . '</td>' . ' <td>' . $link->getLink("javascript: reserve('v','','','" . $rs['resid'] . "');", Time::formatReservationDate($rs['end_date'], $rs['endtime']), '', '', translate('View this reservation')) . '</td>' . ' <td style="text-align:left;">' . $rs['name'] . '</td>' . ' <td>' . Time::formatTime($rs['starttime']) . '</td>' . ' <td>' . Time::formatTime($rs['endtime']) . '</td>' . ' <td style="text-align:left;">' . $rs['fname'] . ' ' . $rs['lname'] . '</td>' . ' <td>' . $link->getLink("manage_invites.php?id={$rs['resid']}&memberid={$rs['memberid']}&accept_code={$rs['accept_code']}&action=" . INVITE_DECLINE, translate('End Participation'), '', '', translate('End Participation')) . '</td>' . " </tr>\n"; } unset($res); ?> </table> </div> </td> </tr> </table> <?php }