$vars = array('SITE' => $SITE->shortname, 'SITE_URL' => $CFG->wwwroot, 'COURSE_SHORT' => $COURSE->shortname, 'COURSE' => $COURSE->fullname, 'COURSE_URL' => $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id, 'MODULE' => $scheduler->name, 'USER' => fullname($student), 'DATE' => userdate($slot->starttime, get_string('strftimedate')), 'TIME' => userdate($slot->starttime, get_string('strftimetime')), 'DURATION' => $slot->duration); $notification = compile_mail_template('applied', $vars); $notificationHtml = compile_mail_template('applied_html', $vars); email_to_user($teacher, $student, get_string('newappointment', 'scheduler', $SITE->shortname), $notification, $notificationHtml); } } } // *********************************** Disengage alone from the slot ******************************/ if ($action == 'disengage') { $appointments = get_records_select('scheduler_appointment', "studentid = {$USER->id} AND attended = 0"); if ($appointments) { foreach ($appointments as $appointment) { $oldslot = get_record('scheduler_slots', 'id', $appointment->slotid); scheduler_delete_appointment($appointment->id, $oldslot, $scheduler); // notify teacher if ($scheduler->allownotifications) { $student = get_record('user', 'id', $USER->id); $teacher = get_record('user', 'id', $oldslot->teacherid); include_once $CFG->dirroot . '/mod/scheduler/mailtemplatelib.php'; $vars = array('SITE' => $SITE->shortname, 'SITE_URL' => $CFG->wwwroot, 'COURSE_SHORT' => $COURSE->shortname, 'COURSE' => $COURSE->fullname, 'COURSE_URL' => $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id, 'MODULE' => $scheduler->name, 'USER' => fullname($student), 'DATE' => userdate($oldslot->starttime, get_string('strftimedate')), 'TIME' => userdate($oldslot->starttime, get_string('strftimetime')), 'DURATION' => $oldslot->duration); $notification = compile_mail_template('cancelled', $vars); $notificationHtml = compile_mail_template('cancelled_html', $vars); email_to_user($teacher, $student, get_string('cancelledbystudent', 'scheduler', $SITE->shortname), $notification, $notificationHtml); } } // delete calendar events for that slot scheduler_delete_calendar_events($oldslot); // renew all calendar events as some appointments may be left for other students scheduler_add_update_calendar_events($oldslot, $course); } }
/** * sends required notifications by the watchers when first submit * @uses $COURSE * @param int $issueid * @param object $tracker */ function tracker_notifyccs_comment($issueid, $comment, $tracker = null) { global $COURSE, $SITE, $CFG, $USER; $issue = get_record('tracker_issue', 'id', $issueid); if (empty($tracker)) { // database access optimization in case we have a tracker from somewhere else $tracker = get_record('tracker', 'id', $issue->trackerid); } $issueccs = get_records('tracker_issuecc', 'issueid', $issue->id); if (!empty($issueccs)) { $vars = array('COURSE_SHORT' => $COURSE->shortname, 'COURSENAME' => format_string($COURSE->fullname), 'TRACKERNAME' => format_string($tracker->name), 'ISSUE' => $tracker->ticketprefix . $issue->id, 'SUMMARY' => $issue->summary, 'COMMENT' => format_string(stripslashes($comment)), 'ISSUEURL' => $CFG->wwwroot . "/mod/tracker/view.php?a={$tracker->id}&view=view&page=viewanissue&issueid={$issue->id}"); include_once $CFG->dirroot . '/mod/tracker/mailtemplatelib.php'; foreach ($issueccs as $cc) { $ccuser = get_record('user', 'id', $cc->userid); if ($cc->events & ON_COMMENT) { $vars['CONTRIBUTOR'] = fullname($USER); $vars['UNCCURL'] = $CFG->wwwroot . "/mod/tracker/view.php?a={$tracker->id}&view=profile&page=mywatches&ccid={$cc->userid}&what=unregister"; $vars['ALLUNCCURL'] = $CFG->wwwroot . "/mod/tracker/view.php?a={$tracker->id}&view=profile&page=mywatches&userid={$cc->userid}&what=unregisterall"; $notification = compile_mail_template('addcomment', $vars, 'tracker', $ccuser->lang); $notification_html = compile_mail_template('addcomment_html', $vars, 'tracker', $ccuser->lang); if ($CFG->debugsmtp) { echo "Sending Comment Notification to " . fullname($ccuser) . '<br/>' . $notification_html; } email_to_user($ccuser, $USER, get_string('submission', 'tracker', $SITE->shortname . ':' . format_string($tracker->name)), $notification, $notification_html); } } } }
/** * sends required notifications by the watchers when state changes * @uses COURSE * @param int $issueid * @param object $tracker */ function tracker_notifyccs_changestate($issueid, $tracker = null) { global $COURSE, $SITE, $CFG, $USER; $issue = get_record('tracker_issue', 'id', $issueid); if (empty($tracker)) { // database access optimization in case we have a tracker from somewhere else $tracker = get_record('tracker', 'id', $issue->trackerid); } $issueccs = get_records('tracker_issuecc', 'issueid', $issueid); if (!empty($issueccs)) { $vars = array('COURSE_SHORT' => $COURSE->shortname, 'COURSENAME' => format_string($COURSE->fullname), 'TRACKERNAME' => format_string($tracker->name), 'ISSUE' => $tracker->ticketprefix . $issueid, 'SUMMARY' => format_string($issue->summary), 'BY' => fullname($USER), 'ISSUEURL' => $CFG->wwwroot . "/mod/tracker/view.php?a={$tracker->id}&view=view&page=viewanissue&issueid={$issueid}"); include_once "{$CFG->dirroot}/mod/tracker/mailtemplatelib.php"; foreach ($issueccs as $cc) { $ccuser = get_record('user', 'id', $cc->userid); $vars['UNCCURL'] = $CFG->wwwroot . "/mod/tracker/view.php?a={$tracker->id}&view=profile&page=mywatches&ccid={$cc->userid}&what=unregister"; $vars['ALLUNCCURL'] = $CFG->wwwroot . "/mod/tracker/view.php?a={$tracker->id}&view=profile&page=mywatches&userid={$cc->userid}&what=unregisterall"; echo "status : {$issue->status} "; switch ($issue->status) { case OPEN: if ($cc->events & EVENT_OPEN) { $vars['EVENT'] = get_string('open', 'tracker'); $notification = compile_mail_template('statechanged', $vars); $notification_html = compile_mail_template('statechanged_html', $vars); } break; case RESOLVING: if ($cc->events & EVENT_RESOLVING) { $vars['EVENT'] = get_string('resolving', 'tracker'); $notification = compile_mail_template('statechanged', $vars); $notification_html = compile_mail_template('statechanged_html', $vars); } break; case WAITING: if ($cc->events & EVENT_WAITING) { $vars['EVENT'] = get_string('waiting', 'tracker'); $notification = compile_mail_template('statechanged', $vars); $notification_html = compile_mail_template('statechanged_html', $vars); } break; case RESOLVED: if ($cc->events & EVENT_RESOLVED) { $vars['EVENT'] = get_string('resolved', 'tracker'); $notification = compile_mail_template('statechanged', $vars); $notification_html = compile_mail_template('statechanged_html', $vars); } break; case ABANDONNED: if ($cc->events & EVENT_ABANDONNED) { $vars['EVENT'] = get_string('abandonned', 'tracker'); $notification = compile_mail_template('statechanged', $vars); $notification_html = compile_mail_template('statechanged_html', $vars); } break; case TRANSFERED: if ($cc->events & EVENT_TRANSFERED) { $vars['EVENT'] = get_string('transfered', 'tracker'); $notification = compile_mail_template('statechanged', $vars); $notification_html = compile_mail_template('statechanged_html', $vars); } break; default: } if ($CFG->debugsmtp) { echo "Sending State Change Mail Notification to " . fullname($ccuser) . '<br/>' . $notification_html; } email_to_user($ccuser, $USER, get_string('trackereventchanged', 'tracker', $SITE->shortname . ':' . format_string($tracker->name)), $notification, $notification_html); } } }
/** * Will delete calendar events for a given scheduler slot, and not complain if the record does not exist. * The only argument this function requires is the complete database record of a scheduler slot. * @param object $slot the slot instance * @uses $CFG * @uses $USER * @uses $COURSE * @return boolean true if success, false otherwise */ function scheduler_delete_calendar_events($slot) { global $CFG, $SITE, $COURSE; $scheduler = get_record('scheduler', 'id', $slot->schedulerid); if (!$scheduler) { return false; } $teacherEventType = "SSsup:{$slot->id}:{$scheduler->course}"; $studentEventType = "SSstu:{$slot->id}:{$scheduler->course}"; $teacherDeletionSuccess = delete_records('event', 'eventtype', $teacherEventType); $studentDeletionSuccess = delete_records('event', 'eventtype', $studentEventType); // we must fetch back all students identities as they may have been deleted $oldstudents = get_records('scheduler_appointment', 'slotid', $slot->id, '', 'studentid, studentid'); if ($scheduler->allownotifications && $oldstudents) { foreach (array_keys($oldstudents) as $oldstudent) { $student = get_record('user', 'id', $oldstudent); $teacher = get_record('user', 'id', $slot->teacherid); include_once $CFG->dirroot . '/mod/scheduler/mailtemplatelib.php'; $vars = array('SITE' => $SITE->shortname, 'SITE_URL' => $CFG->wwwroot, 'COURSE_SHORT' => $COURSE->shortname, 'COURSE' => $COURSE->fullname, 'COURSE_URL' => $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id, 'MODULE' => $scheduler->name, 'USER' => fullname($student), 'DATE' => userdate($slot->starttime, get_string('strftimedate')), 'TIME' => userdate($slot->starttime, get_string('strftimetime')), 'DURATION' => $slot->duration); $notification = compile_mail_template('cancelled', $vars); $notificationHtml = compile_mail_template('cancelled_html', $vars); email_to_user($teacher, $student, get_string('schedulecancelled', 'scheduler', $SITE->shortname), $notification, $notificationHtml); } } return $teacherDeletionSuccess && $studentDeletionSuccess; //this return may not be meaningful if the delete records functions do not return anything meaningful. }