/** * Common code for sending confirmation and cancellation notices * * @param string $postsubject Subject of the email * @param string $posttext Plain text contents of the email * @param string $posttextmgrheading Header to prepend to $posttext in manager email * @param string $notificationtype The type of notification to send * @see {{MDL_F2F_INVITE}} * @param class $facetoface record from the facetoface table * @param class $session record from the facetoface_sessions table * @param integer $userid ID of the recipient of the email * @returns string Error message (or empty string if successful) */ function facetoface_send_notice($postsubject, $posttext, $posttextmgrheading, $notificationtype, $facetoface, $session, $userid) { global $CFG, $DB; $user = $DB->get_record('user', array('id' => $userid)); if (!$user) { return 'error:invaliduserid'; } if (empty($postsubject) || empty($posttext)) { return ''; } // If no notice type is defined (TEXT or ICAL). if (!($notificationtype & MDL_F2F_BOTH)) { // If none, make sure they at least get a text email. $notificationtype |= MDL_F2F_TEXT; } // If we are cancelling, check if ical cancellations are disabled. if ($notificationtype & MDL_F2F_CANCEL && get_config(null, 'facetoface_disableicalcancel')) { $notificationtype |= MDL_F2F_TEXT; // Add a text notification. $notificationtype &= ~MDL_F2F_ICAL; // Remove the iCalendar notification. } // If we are sending an ical attachment, set file name. if ($notificationtype & MDL_F2F_ICAL) { if ($notificationtype & MDL_F2F_INVITE) { $attachmentfilename = 'invite.ics'; } else { if ($notificationtype & MDL_F2F_CANCEL) { $attachmentfilename = 'cancel.ics'; } } } // Do iCal attachement stuff. $icalattachments = array(); if ($notificationtype & MDL_F2F_ICAL) { if (get_config(null, 'facetoface_oneemailperday')) { // Keep track of all sessiondates. $sessiondates = $session->sessiondates; foreach ($sessiondates as $sessiondate) { $session->sessiondates = array($sessiondate); // One day at a time. $filename = facetoface_get_ical_attachment($notificationtype, $facetoface, $session, $user); $subject = facetoface_email_substitutions($postsubject, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); $body = facetoface_email_substitutions($posttext, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); $htmlbody = ''; // TODO. $icalattachments[] = array('filename' => $filename, 'subject' => $subject, 'body' => $body, 'htmlbody' => $htmlbody); } // Restore session dates. $session->sessiondates = $sessiondates; } else { $filename = facetoface_get_ical_attachment($notificationtype, $facetoface, $session, $user); $subject = facetoface_email_substitutions($postsubject, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); $body = facetoface_email_substitutions($posttext, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); $htmlbody = ''; // FIXME. $icalattachments[] = array('filename' => $filename, 'subject' => $subject, 'body' => $body, 'htmlbody' => $htmlbody); } } // Fill-in the email placeholders. $postsubject = facetoface_email_substitutions($postsubject, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); $posttext = facetoface_email_substitutions($posttext, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); $posttextmgrheading = facetoface_email_substitutions($posttextmgrheading, $facetoface->name, $facetoface->reminderperiod, $user, $session, $session->id); $posthtml = ''; // FIXME. if ($fromaddress = get_config(null, 'facetoface_fromaddress')) { $from = new stdClass(); $from->maildisplay = true; $from->email = $fromaddress; } else { $from = null; } $usercheck = $DB->get_record('user', array('id' => $userid)); // Send email with iCal attachment. if ($notificationtype & MDL_F2F_ICAL) { foreach ($icalattachments as $attachment) { if (!email_to_user($user, $from, $attachment['subject'], $attachment['body'], $attachment['htmlbody'], $attachment['filename'], $attachmentfilename)) { return 'error:cannotsendconfirmationuser'; } unlink($CFG->dataroot . '/' . $attachment['filename']); } } // Send plain text email. if ($notificationtype & MDL_F2F_TEXT) { if (!email_to_user($user, $from, $postsubject, $posttext, $posthtml)) { return 'error:cannotsendconfirmationuser'; } } // Manager notification. $manageremail = facetoface_get_manageremail($userid); if (!empty($posttextmgrheading) and !empty($manageremail) and $session->datetimeknown) { $managertext = $posttextmgrheading . $posttext; $manager = $user; $manager->email = $manageremail; // Leave out the ical attachments in the managers notification. if (!email_to_user($manager, $from, $postsubject, $managertext, $posthtml)) { return 'error:cannotsendconfirmationmanager'; } } // Third-party notification. if (!empty($facetoface->thirdparty) && ($session->datetimeknown || !empty($facetoface->thirdpartywaitlist))) { $thirdparty = $user; $recipients = explode(',', $facetoface->thirdparty); foreach ($recipients as $recipient) { $thirdparty->email = trim($recipient); // Leave out the ical attachments in the 3rd parties notification. if (!email_to_user($thirdparty, $from, $postsubject, $posttext, $posthtml)) { return 'error:cannotsendconfirmationthirdparty'; } } } return ''; }
echo facetoface_print_session($session, $viewattendees); if ($signedup) { if (!($session->datetimeknown && facetoface_has_session_started($session, $timenow))) { // Cancellation link. $cancellationurl = new moodle_url('cancelsignup.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions)); echo html_writer::link($cancellationurl, get_string('cancelbooking', 'facetoface'), array('title' => get_string('cancelbooking', 'facetoface'))); echo ' – '; } // See attendees link. if ($viewattendees) { $attendeesurl = new moodle_url('attendees.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions)); echo html_writer::link($attendeesurl, get_string('seeattendees', 'facetoface'), array('title' => get_string('seeattendees', 'facetoface'))); } echo html_writer::empty_tag('br') . html_writer::link($returnurl, get_string('goback', 'facetoface'), array('title' => get_string('goback', 'facetoface'))); } else { if (facetoface_manager_needed($facetoface) && !facetoface_get_manageremail($USER->id)) { // Don't allow signup to proceed if a manager is required. // Check to see if the user has a managers email set. echo html_writer::tag('p', html_writer::tag('strong', get_string('error:manageremailaddressmissing', 'facetoface'))); echo html_writer::empty_tag('br') . html_writer::link($returnurl, get_string('goback', 'facetoface'), array('title' => get_string('goback', 'facetoface'))); } else { if (!has_capability('mod/facetoface:signup', $context)) { echo html_writer::tag('p', html_writer::tag('strong', get_string('error:nopermissiontosignup', 'facetoface'))); echo html_writer::empty_tag('br') . html_writer::link($returnurl, get_string('goback', 'facetoface'), array('title' => get_string('goback', 'facetoface'))); } else { // Signup form. $mform->display(); } } } echo $OUTPUT->box_end();