function print_entry($course) { global $CFG, $USER; $strloginto = get_string("loginto", "", $course->shortname); $strcourses = get_string("courses"); $teacher = get_teacher($course->id); if ((double) $course->cost < 0) { $cost = (double) $CFG->enrol_cost; } else { $cost = (double) $course->cost; } if (abs($cost) < 0.01) { // no cost, default to base class entry to course $manual = enrolment_factory::factory('manual'); $manual->print_entry($course); } else { $navlinks = array(); $navlinks[] = array('name' => $strcourses, 'link' => "{$CFG->wwwroot}/course", 'type' => 'misc'); $navlinks[] = array('name' => $strloginto, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header($strloginto, $course->fullname, $navigation); print_course($course, "80%"); if ($course->password) { // Presenting two options print_heading(get_string('costorkey', 'enrol_paypal'), 'center'); } print_simple_box_start("center"); if ($USER->username == 'guest') { // force login only for guest user, not real users with guest role if (empty($CFG->loginhttps)) { $wwwroot = $CFG->wwwroot; } else { // This actually is not so secure ;-), 'cause we're // in unencrypted connection... $wwwroot = str_replace("http://", "https://", $CFG->wwwroot); } echo '<div align="center"><p>' . get_string('paymentrequired') . '</p>'; echo '<p><b>' . get_string('cost') . ": {$CFG->enrol_currency} {$cost}" . '</b></p>'; echo '<p><a href="' . $wwwroot . '/login/">' . get_string('loginsite') . '</a></p>'; echo '</div>'; } else { //Sanitise some fields before building the PayPal form $coursefullname = $course->fullname; $courseshortname = $course->shortname; $userfullname = fullname($USER); $userfirstname = $USER->firstname; $userlastname = $USER->lastname; $useraddress = $USER->address; $usercity = $USER->city; include $CFG->dirroot . '/enrol/paypal/enrol.html'; } print_simple_box_end(); if ($course->password) { // Second option $password = ''; include $CFG->dirroot . '/enrol/manual/enrol.html'; } print_footer(); } }
function workshop_cron() { // Function to be run periodically according to the moodle cron global $CFG, $USER; // if there any ungraded assessments run the grading routine if ($workshops = get_records("workshop")) { foreach ($workshops as $workshop) { // automatically grade assessments if workshop has examples and/or peer assessments if ($workshop->gradingstrategy and ($workshop->ntassessments or $workshop->nsassessments)) { workshop_grade_assessments($workshop); } } } $timenow = time(); // Find all workshop notifications that have yet to be mailed out, and mails them $cutofftime = $timenow - $CFG->maxeditingtime; // look for new assessments if ($assessments = workshop_get_unmailed_assessments($cutofftime)) { foreach ($assessments as $assessment) { echo "Processing workshop assessment {$assessment->id}\n"; // only process the entry once if (!set_field("workshop_assessments", "mailed", "1", "id", "{$assessment->id}")) { echo "Could not update the mailed field for id {$assessment->id}\n"; } if (!($submission = get_record("workshop_submissions", "id", "{$assessment->submissionid}"))) { echo "Could not find submission {$assessment->submissionid}\n"; continue; } if (!($workshop = get_record("workshop", "id", $submission->workshopid))) { echo "Could not find workshop id {$submission->workshopid}\n"; continue; } if (!($course = get_record("course", "id", $workshop->course))) { error("Could not find course id {$workshop->course}"); continue; } if (!($cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id))) { error("Course Module ID was incorrect"); continue; } if (!($submissionowner = get_record("user", "id", "{$submission->userid}"))) { echo "Could not find user {$submission->userid}\n"; continue; } if (!($assessmentowner = get_record("user", "id", "{$assessment->userid}"))) { echo "Could not find user {$assessment->userid}\n"; continue; } if (!workshop_is_student($workshop, $submissionowner->id) and !workshop_is_teacher($workshop, $submissionowner->id)) { continue; // Not an active participant } if (!workshop_is_student($workshop, $assessmentowner->id) and !workshop_is_teacher($workshop, $assessmentowner->id)) { continue; // Not an active participant } // don't sent self assessment if ($submissionowner->id == $assessmentowner->id) { continue; } $strworkshops = get_string("modulenameplural", "workshop"); $strworkshop = get_string("modulename", "workshop"); // it's an assessment, tell the submission owner $USER->lang = $submissionowner->lang; $sendto = $submissionowner; // "Your assignment \"$submission->title\" has been assessed by" if (workshop_is_student($workshop, $assessmentowner->id)) { $msg = get_string("mail1", "workshop", $submission->title) . " a {$course->student}.\n"; } else { $msg = get_string("mail1", "workshop", $submission->title) . " " . fullname($assessmentowner) . "\n"; } // "The comments and grade can be seen in the workshop assignment '$workshop->name' // I have taken the following line out because the info is repeated below. // $msg .= get_string("mail2", "workshop", $workshop->name)."\n\n"; $postsubject = "{$course->shortname}: {$strworkshops}: " . format_string($workshop->name, true); $posttext = "{$course->shortname} -> {$strworkshops} -> " . format_string($workshop->name, true) . "\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= $msg; // "The comments and grade can be seen in ..." $posttext .= get_string("mail2", "workshop", format_string($workshop->name, true) . ", {$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}") . "\n"; $posttext .= "---------------------------------------------------------------------\n"; if ($sendto->mailformat == 1) { // HTML $posthtml = "<p><font face=\"sans-serif\">" . "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/workshop/index.php?id={$course->id}\">{$strworkshops}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}\">" . format_string($workshop->name, true) . "</a></font></p>"; $posthtml .= "<hr><font face=\"sans-serif\">"; $posthtml .= "<p>{$msg}</p>"; $posthtml .= "<p>" . get_string("mail2", "workshop", " <a href=\"{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}\">" . format_string($workshop->name, true) . "</a>") . "</p></font><hr>"; } else { $posthtml = ""; } if (!($teacher = get_teacher($course->id))) { echo "Error: can not find teacher for course {$course->id}!\n"; } if (!email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { echo "Error: workshop cron: Could not send out mail for id {$submission->id} to\n user {$sendto->id} ({$sendto->email})\n"; } } } // look for new assessments of resubmissions if ($assessments = workshop_get_unmailed_resubmissions($cutofftime)) { $timenow = time(); foreach ($assessments as $assessment) { echo "Processing workshop assessment {$assessment->id}\n"; // only process the entry once if (!set_field("workshop_assessments", "mailed", "1", "id", "{$assessment->id}")) { echo "Could not update the mailed field for id {$assessment->id}\n"; } if (!($submission = get_record("workshop_submissions", "id", "{$assessment->submissionid}"))) { echo "Could not find submission {$assessment->submissionid}\n"; continue; } if (!($workshop = get_record("workshop", "id", $submission->workshopid))) { echo "Could not find workshop id {$submission->workshopid}\n"; continue; } if (!($course = get_record("course", "id", $workshop->course))) { error("Could not find course id {$workshop->course}"); continue; } if (!($cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id))) { error("Course Module ID was incorrect"); continue; } if (!($submissionowner = get_record("user", "id", "{$submission->userid}"))) { echo "Could not find user {$submission->userid}\n"; continue; } if (!($assessmentowner = get_record("user", "id", "{$assessment->userid}"))) { echo "Could not find user {$assessment->userid}\n"; continue; } if (!workshop_is_student($workshop, $submissionowner->id) and !workshop_is_teacher($workshop, $submissionowner->id)) { continue; // Not an active participant } if (!workshop_is_student($workshop, $assessmentowner->id) and !workshop_is_teacher($workshop, $assessmentowner->id)) { continue; // Not an active participant } $strworkshops = get_string("modulenameplural", "workshop"); $strworkshop = get_string("modulename", "workshop"); // it's a resubission assessment, tell the assessment owner to (re)assess $USER->lang = $assessmentowner->lang; $sendto = $assessmentowner; // "The assignment \"$submission->title\" is a revised piece of work. " $msg = get_string("mail8", "workshop", $submission->title) . "\n"; // "Please assess it in the workshop assignment '$workshop->name' // $msg .= get_string("mail9", "workshop", $workshop->name)."\n\n"; $postsubject = "{$course->shortname}: {$strworkshops}: " . format_string($workshop->name, true); $posttext = "{$course->shortname} -> {$strworkshops} -> " . format_string($workshop->name, true) . "\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= $msg; // "Please assess it in ..." $posttext .= get_string("mail9", "workshop", format_string($workshop->name, true) . ", {$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}") . "\n"; $posttext .= "---------------------------------------------------------------------\n"; if ($sendto->mailformat == 1) { // HTML $posthtml = "<p><font face=\"sans-serif\">" . "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/workshop/index.php?id={$course->id}\">{$strworkshops}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}\">" . format_string($workshop->name, true) . "</a></font></p>"; $posthtml .= "<hr><font face=\"sans-serif\">"; $posthtml .= "<p>{$msg}</p>"; $posthtml .= "<p>" . get_string("mail9", "workshop", " <a href=\"{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}\">" . format_string($workshop->name, true) . "</a>") . '</p></font><hr>'; } else { $posthtml = ""; } if (!($teacher = get_teacher($course->id))) { echo "Error: can not find teacher for course {$course->id}!\n"; } if (!email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { echo "Error: workshop cron: Could not send out mail for id {$submission->id} to\n user {$sendto->id} ({$sendto->email})\n"; } } } // look for new comments if ($comments = workshop_get_unmailed_comments($cutofftime)) { $timenow = time(); foreach ($comments as $comment) { echo "Processing workshop comment {$comment->id}\n"; // only process the entry once if (!set_field("workshop_comments", "mailed", "1", "id", "{$comment->id}")) { echo "Could not update the mailed field for comment id {$comment->id}\n"; } if (!($assessment = get_record("workshop_assessments", "id", "{$comment->assessmentid}"))) { echo "Could not find assessment {$comment->assessmentid}\n"; continue; } if (!($submission = get_record("workshop_submissions", "id", "{$assessment->submissionid}"))) { echo "Could not find submission {$assessment->submissionid}\n"; continue; } if (!($workshop = get_record("workshop", "id", $submission->workshopid))) { echo "Could not find workshop id {$submission->workshopid}\n"; continue; } if (!($course = get_record("course", "id", $workshop->course))) { error("Could not find course id {$workshop->course}"); continue; } if (!($cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id))) { error("Course Module ID was incorrect"); continue; } if (!($submissionowner = get_record("user", "id", "{$submission->userid}"))) { echo "Could not find user {$submission->userid}\n"; continue; } if (!($assessmentowner = get_record("user", "id", "{$assessment->userid}"))) { echo "Could not find user {$assessment->userid}\n"; continue; } if (!workshop_is_student($workshop, $submissionowner->id) and !workshop_is_teacher($workshop, $submissionowner->id)) { continue; // Not an active participant } if (!workshop_is_student($workshop, $assessmentowner->id) and !workshop_is_teacher($workshop, $assessmentowner->id)) { continue; // Not an active participant } $strworkshops = get_string("modulenameplural", "workshop"); $strworkshop = get_string("modulename", "workshop"); // see if the submission owner needs to be told if ($comment->userid != $submission->userid) { $USER->lang = $submissionowner->lang; $sendto = $submissionowner; // "A comment has been added to the assignment \"$submission->title\" by if (workshop_is_student($workshop, $assessmentowner->id)) { $msg = get_string("mail4", "workshop", $submission->title) . " a {$course->student}.\n"; } else { $msg = get_string("mail4", "workshop", $submission->title) . " " . fullname($assessmentowner) . "\n"; } // "The new comment can be seen in the workshop assignment '$workshop->name' // $msg .= get_string("mail5", "workshop", $workshop->name)."\n\n"; $postsubject = "{$course->shortname}: {$strworkshops}: " . format_string($workshop->name, true); $posttext = "{$course->shortname} -> {$strworkshops} -> " . format_string($workshop->name, true) . "\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= $msg; // "The new comment can be seen in ..." $posttext .= get_string("mail5", "workshop", format_string($workshop->name, true) . ", {$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}") . "\n"; $posttext .= "---------------------------------------------------------------------\n"; if ($sendto->mailformat == 1) { // HTML $posthtml = "<p><font face=\"sans-serif\">" . "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/workshop/index.php?id={$course->id}\">{$strworkshops}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}\">" . format_string($workshop->name, true) . "</a></font></p>"; $posthtml .= "<hr><font face=\"sans-serif\">"; $posthtml .= "<p>{$msg}</p>"; $posthtml .= "<p>" . get_string("mail5", "workshop", " <a href=\"{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}\">" . format_string($workshop->name, true) . "</a>") . "</p></font><hr>"; } else { $posthtml = ""; } if (!($teacher = get_teacher($course->id))) { echo "Error: can not find teacher for course {$course->id}!\n"; } if (!email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { echo "Error: workshop cron: Could not send out mail for id {$submission->id} to user\n {$sendto->id} ({$sendto->email})\n"; } } // see if the assessor needs to to told if ($comment->userid != $assessment->userid) { $USER->lang = $assessmentowner->lang; $sendto = $assessmentowner; // "A comment has been added to the assignment \"$submission->title\" by if (workshop_is_student($workshop, $submissionowner->id)) { $msg = get_string("mail4", "workshop", $submission->title) . " a {$course->student}.\n"; } else { $msg = get_string("mail4", "workshop", $submission->title) . " " . fullname($submissionowner) . "\n"; } // "The new comment can be seen in the workshop assignment '$workshop->name' // $msg .= get_string("mail5", "workshop", $workshop->name)."\n\n"; $postsubject = "{$course->shortname}: {$strworkshops}: " . format_string($workshop->name, true); $posttext = "{$course->shortname} -> {$strworkshops} -> " . format_string($workshop->name, true) . "\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= $msg; // "The new comment can be seen in ..." $posttext .= get_string("mail5", "workshop", format_string($workshop->name, true) . ", {$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}") . "\n"; $posttext .= "---------------------------------------------------------------------\n"; if ($sendto->mailformat == 1) { // HTML $posthtml = "<p><font face=\"sans-serif\">" . "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/workshop/index.php?id={$course->id}\">{$strworkshops}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}\">" . format_string($workshop->name, true) . "</a></font></p>"; $posthtml .= "<hr><font face=\"sans-serif\">"; $posthtml .= "<p>{$msg}</p>"; $posthtml .= "<p>" . get_string("mail5", "workshop", " <a href=\"{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}\">" . format_string($workshop->name, true) . "</a>") . "</p></font><hr>"; } else { $posthtml = ""; } if (!($teacher = get_teacher($course->id))) { echo "Error: can not find teacher for course {$course->id}!\n"; } if (!email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { echo "Error: workshop cron: Could not send out mail for id {$submission->id} to user\n {$sendto->id} ({$sendto->email})\n"; } if (!set_field("workshop_comments", "mailed", "1", "id", "{$comment->id}")) { echo "Could not update the mailed field for comment id {$comment->id}\n"; } } } } return true; }
function email_welcome_message_to_user($course, $user = NULL) { global $CFG, $USER; if (isset($CFG->sendcoursewelcomemessage) and !$CFG->sendcoursewelcomemessage) { return; } if (empty($user)) { if (!isloggedin()) { return false; } $user = $USER; } if (!empty($course->welcomemessage)) { $message = $course->welcomemessage; } else { $a = new Object(); $a->coursename = $course->fullname; $a->profileurl = "{$CFG->wwwroot}/user/view.php?id={$user->id}&course={$course->id}"; $message = get_string("welcometocoursetext", "", $a); } /// If you don't want a welcome message sent, then make the message string blank. if (!empty($message)) { $subject = get_string('welcometocourse', '', format_string($course->fullname)); if (!($teacher = get_teacher($course->id))) { $teacher = get_admin(); } email_to_user($user, $teacher, $subject, $message); } }
} if ($data->payment_gross < $cost) { $cost = format_float($cost, 2); email_paypal_error_to_admin("Amount paid is not enough ({$data->payment_gross} < {$cost}))", $data); die; } // ALL CLEAR ! if (!insert_record("enrol_paypal", addslashes_object($data))) { // Insert a transaction record email_paypal_error_to_admin("Error while trying to insert valid transaction", $data); } if (!enrol_into_course($course, $user, 'paypal')) { email_paypal_error_to_admin("Error while trying to enrol " . fullname($user) . " in '{$course->fullname}'", $data); die; } else { $teacher = get_teacher($course->id); if (!empty($CFG->enrol_mailstudents)) { $a->coursename = $course->fullname; $a->profileurl = "{$CFG->wwwroot}/user/view.php?id={$user->id}"; email_to_user($user, $teacher, get_string("enrolmentnew", '', $course->shortname), get_string('welcometocoursetext', '', $a)); } if (!empty($CFG->enrol_mailteachers)) { $a->course = $course->fullname; $a->user = fullname($user); email_to_user($teacher, $user, get_string("enrolmentnew", '', $course->shortname), get_string('enrolmentnewuser', '', $a)); } if (!empty($CFG->enrol_mailadmins)) { $a->course = $course->fullname; $a->user = fullname($user); $admins = get_admins(); foreach ($admins as $admin) {
function email_welcome_message_to_user($course, $user = NULL) { global $CFG, $USER; if (empty($user)) { if (!isloggedin()) { return false; } $user = $USER; } if (!empty($course->welcomemessage)) { $subject = get_string('welcometocourse', '', format_string($course->fullname)); $a->coursename = $course->fullname; $a->profileurl = "{$CFG->wwwroot}/user/view.php?id={$USER->id}&course={$course->id}"; //$message = get_string("welcometocoursetext", "", $a); $message = $course->welcomemessage; if (!($teacher = get_teacher($course->id))) { $teacher = get_admin(); } email_to_user($user, $teacher, $subject, $message); } }
/** * Presents registration forms. * * @param object $course Course info * @access public */ function print_entry($course) { global $CFG, $USER, $form; $zerocost = zero_cost($course); if ($zerocost) { $manual = enrolment_factory::factory('manual'); if (!empty($this->errormsg)) { $manual->errormsg = $this->errormsg; } $manual->print_entry($course); return; } prevent_double_paid($course); httpsrequired(); if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 443) { // MDL-9836 if (empty($CFG->loginhttps)) { error(get_string('httpsrequired', 'enrol_authorize')); } else { $wwwsroot = str_replace('http:', 'https:', $CFG->wwwroot); redirect("{$wwwsroot}/course/enrol.php?id={$course->id}"); exit; } } $strcourses = get_string('courses'); $strloginto = get_string('loginto', '', $course->shortname); $navlinks = array(); $navlinks[] = array('name' => $strcourses, 'link' => "{$CFG->wwwroot}/course/", 'type' => 'misc'); $navlinks[] = array('name' => $strloginto, 'link' => null, 'type' => 'misc'); $navigation = build_navigation($navlinks); print_header($strloginto, $course->fullname, $navigation); print_course($course, '80%'); if ($course->password) { print_heading(get_string('choosemethod', 'enrol_authorize'), 'center'); } print_simple_box_start('center', '80%'); if ($USER->username == 'guest') { // only real guest user, not for users with guest role $curcost = get_course_cost($course); echo '<div align="center">'; echo '<p>' . get_string('paymentrequired') . '</p>'; echo '<p><b>' . get_string('cost') . ": {$curcost['currency']} {$curcost['cost']}" . '</b></p>'; echo '<p><a href="' . $CFG->httpswwwroot . '/login/">' . get_string('loginsite') . '</a></p>'; echo '</div>'; } else { require_once $CFG->dirroot . '/enrol/authorize/enrol_form.php'; $frmenrol = new enrol_authorize_form('enrol.php', compact('course')); if ($frmenrol->get_data()) { $authorizeerror = ''; switch ($form->paymentmethod) { case AN_METHOD_CC: $authorizeerror = $this->cc_submit($form, $course); break; case AN_METHOD_ECHECK: $authorizeerror = $this->echeck_submit($form, $course); break; } if (!empty($authorizeerror)) { error($authorizeerror); } } $frmenrol->display(); } print_simple_box_end(); if ($course->password) { $password = ''; $teacher = get_teacher($course->id); include $CFG->dirroot . '/enrol/manual/enrol.html'; } print_footer(); }
/** * This function is run by admin/cron.php every time * * The cron function can perform regular checks for the current * enrollment plugin. For example it can check a foreign database, * all look for a file to pull data in from * */ function cron() { global $CFG; // Notify users about enrolments that are going to expire soon! if (empty($CFG->lastexpirynotify)) { $CFG->lastexpirynotify = 0; } if ($CFG->lastexpirynotify < date('Ymd') && ($courses = get_records_select('course', 'enrolperiod > 0 AND expirynotify > 0 AND expirythreshold > 0'))) { $admin = get_admin(); $strexpirynotify = get_string('expirynotify'); foreach ($courses as $course) { $a = new object(); $a->coursename = $course->shortname . '/' . $course->fullname; $a->threshold = $course->expirythreshold / 86400; $a->extendurl = $CFG->wwwroot . '/user/index.php?id=' . $course->id; $a->current = array(); $a->past = array(); $a->current = $a->past = array(); $expiry = time() + $course->expirythreshold; /// Get all the role assignments for this course that have expired. if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) { continue; } if ($oldenrolments = get_records_sql(' SELECT u.* FROM ' . $CFG->prefix . 'role_assignments ra, ' . $CFG->prefix . 'user u WHERE ra.contextid = ' . $context->id . ' AND ra.timeend > 0 AND ra.timeend <= ' . $expiry . ' AND ra.userid = u.id ')) { if (!($teacher = get_teacher($course->id))) { $teacher = get_admin(); } $a->teacherstr = fullname($teacher, true); $strexpirynotifystudentsemail = get_string('expirynotifystudentsemail', '', $a); foreach ($oldenrolments as $user) { /// Email all users about to expire $a->studentstr = fullname($user, true); if ($user->timeend < $expiry - 86400) { $a->past[] = fullname($user) . " <{$user->email}>"; } else { $a->current[] = fullname($user) . " <{$user->email}>"; if ($course->notifystudents) { // Send this guy notice email_to_user($user, $teacher, $SITE->fullname . ' ' . $strexpirynotify, $strexpirynotifystudentsemail); } } } $a->current = implode("\n", $a->current); $a->past = implode("\n", $a->past); $strexpirynotifyemail = get_string('expirynotifyemail', '', $a); if ($a->current || $a->past) { if ($teachers = get_users_by_capability($context, 'moodle/course:update', 'u.*,ra.hidden', 'r.sortorder ASC', '', '', '', '', false)) { foreach ($teachers as $teacher) { email_to_user($teacher, $admin, $a->coursename . ' ' . $strexpirynotify, $strexpirynotifyemail); } } } } set_config('lastexpirynotify', date('Ymd')); } } }
function certificate_email_students($USER) { global $course, $certificate, $CFG; $certrecord = certificate_get_issue($course, $USER); if ($certrecord->sent > 0) { return; } $teacher = get_teacher($course->id); $strawarded = get_string('awarded', 'certificate'); $stremailstudenttext = get_string('emailstudenttext', 'certificate'); $info->username = fullname($user); $info->certificate = format_string($certificate->name, true); $info->course = format_string($course->fullname, true); $from = fullname($teacher); $subject = $info->course . ': ' . $info->certificate; $message = get_string('emailstudenttext', 'certificate', $info) . "\n"; // Make the HTML version more XHTML happy (&) $messagehtml = text_to_html(get_string('emailstudenttext', 'certificate', $info)); $user->mailformat = 0; // Always send HTML version as well $attachment = $course->id . '/moddata/certificate/' . $certificate->id . '/' . $USER->id . '/certificate.pdf'; $attachname = "certificate.pdf"; set_field("certificate_issues", "sent", "1", "certificateid", $certificate->id, "userid", $USER->id); return email_to_user($USER, $from, $subject, $message, $messagehtml, $attachment, $attachname); }
function exercise_cron() { // Function to be run periodically according to the moodle cron // Finds all exercise notifications that have yet to be mailed out, and mails them global $CFG, $USER; $cutofftime = time() - $CFG->maxeditingtime; // look for new assessments if ($assessments = exercise_get_unmailed_assessments($cutofftime)) { $timenow = time(); foreach ($assessments as $assessment) { echo "Processing exercise assessment {$assessment->id}\n"; // switch on mailed if (!set_field("exercise_assessments", "mailed", "1", "id", "{$assessment->id}")) { echo "Could not update the mailed field for id {$assessment->id}\n"; } if (!($submission = get_record("exercise_submissions", "id", "{$assessment->submissionid}"))) { echo "Could not find submission {$assessment->submissionid}\n"; continue; } if (!($exercise = get_record("exercise", "id", $submission->exerciseid))) { echo "Could not find exercise record for id {$submission->exerciseid}\n"; continue; } if (!($course = get_record("course", "id", "{$exercise->course}"))) { echo "Could not find course {$exercise->course}\n"; continue; } if (!($cm = get_coursemodule_from_instance("exercise", $exercise->id, $course->id))) { error("Course Module ID was incorrect"); continue; } if (!($submissionowner = get_record("user", "id", "{$submission->userid}"))) { echo "Could not find user {$submission->userid}\n"; continue; } if (!($assessmentowner = get_record("user", "id", "{$assessment->userid}"))) { echo "Could not find user {$assessment->userid}\n"; continue; } if (!isstudent($course->id, $submissionowner->id) and !isteacher($course->id, $submissionowner->id)) { continue; // Not an active participant } if (!isstudent($course->id, $assessmentowner->id) and !isteacher($course->id, $assessmentowner->id)) { continue; // Not an active participant } // if the submission belongs to a teacher it's a student assessment. No need to email anything. if (isteacher($course->id, $submissionowner->id)) { continue; } $strexercises = get_string("modulenameplural", "exercise"); $strexercise = get_string("modulename", "exercise"); // it's an assessment, tell the submission owner $USER->lang = $submissionowner->lang; $sendto = $submissionowner; // "Your assignment \"$submission->title\" has been assessed by" $msg = get_string("mail1", "exercise", $submission->title) . ' ' . fullname($assessmentowner) . ".\n"; // "The comments and grade can be seen in the exercise assignment '$exercise->name' $msg .= get_string("mail2", "exercise", format_string($exercise->name, true)) . "\n\n"; $postsubject = "{$course->shortname}: {$strexercises}: " . format_string($exercise->name, true); $posttext = "{$course->shortname} -> {$strexercises} -> " . format_string($exercise->name, true) . "\n"; $posttext .= "---------------------------------------------------------------------\n"; $posttext .= $msg; // "You can see it in your exercise assignment" $posttext .= get_string("mail3", "exercise") . ":\n"; $posttext .= " {$CFG->wwwroot}/mod/exercise/view.php?id={$cm->id}\n"; $posttext .= "---------------------------------------------------------------------\n"; if ($sendto->mailformat == 1) { // HTML $posthtml = "<p><font face=\"sans-serif\">" . "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/exercise/index.php?id={$course->id}\">{$strexercises}</a> ->" . "<a href=\"{$CFG->wwwroot}/mod/exercise/view.php?id={$cm->id}\">" . format_string($exercise->name, true) . "</a></font></p>"; $posthtml .= "<hr /><font face=\"sans-serif\">"; $posthtml .= "<p>{$msg}</p>"; $posthtml .= "<p>" . get_string("mail3", "exercise") . " <a href=\"{$CFG->wwwroot}/mod/exercise/view.php?id={$cm->id}\">" . format_string($exercise->name, true) . "</a>.</p></font><hr />"; } else { $posthtml = ""; } if (!($teacher = get_teacher($course->id))) { echo "Error: can not find teacher for course {$course->id}!\n"; } if (!email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) { echo "Error: exercise cron: Could not send out mail for id {$submission->id} to user {$sendto->id} ({$sendto->email})\n"; } } } return true; }
function certificate_email_students($user, $course, $certificate, $certrecord) { if ($certrecord->mailed > 0) { return; } $teacher = get_teacher($course->id); $info->username = fullname($user); $info->certificate = format_string($certificate->name, true); $info->course = format_string($course->fullname, true); $from = fullname($teacher); $subject = $info->course . ': ' . $info->certificate; $message = get_string('emailstudenttext', 'certificate', $info) . "\n"; // Make the HTML version more XHTML happy (&) $messagehtml = text_to_html(get_string('emailstudenttext', 'certificate', $info)); $user->mailformat = 0; // Always send HTML version as well $filesafe = clean_filename($certificate->name . '.pdf'); $attachment = $course->id . '/moddata/certificate/' . $certificate->id . '/' . $user->id . '/' . $filesafe; $attachname = $filesafe; set_field('certificate_issues', 'mailed', '1', 'certificateid', $certificate->id, 'userid', $user->id); return email_to_user($user, $from, $subject, $message, $messagehtml, $attachment, $attachname); }
$wheresql = empty($wheresql) ? " WHERE addtime> " . $settr : $wheresql . " AND addtime> " . $settr; $oederbysql = " order BY addtime DESC "; } if (!empty($_GET['refre'])) { $settr = strtotime("-" . intval($_GET['refre']) . " day"); $wheresql = empty($wheresql) ? " WHERE refreshtime> " . $settr : $wheresql . " AND refreshtime> " . $settr; $oederbysql = " order BY refreshtime DESC "; } } $total_sql = "SELECT COUNT(*) AS num FROM " . table('train_teachers') . $wheresql; $total_val = $db->get_total($total_sql); $page = new page(array('total' => $total_val, 'perpage' => $perpage, 'getarray' => $_GET)); $currenpage = $page->nowindex; $offset = ($currenpage - 1) * $perpage; $getsql = "SELECT * FROM " . table('train_teachers') . $wheresql . $oederbysql; $teacher = get_teacher($offset, $perpage, $getsql); $smarty->assign('pageheader', "讲师管理"); $smarty->assign('teacher', $teacher); $smarty->assign('total', $total); $smarty->assign('page', $page->show(3)); $smarty->assign('total_val', $total_val); get_token(); $smarty->display('train/admin_train_teacher.htm'); } elseif ($act == 'teacher_perform') { check_token(); $yid = !empty($_REQUEST['y_id']) ? $_REQUEST['y_id'] : adminmsg("你没有选择讲师!", 1); if (!empty($_POST['delete'])) { check_permissions($_SESSION['admin_purview'], "tea_del"); if ($_POST['delete_teacher'] == 'yes') { !del_train_idteacher($yid) ? adminmsg("删除讲师失败!", 0) : ""; }
exit; } else { add_teacher($last_name, $first_name, $display_name); } } $teacherList = get_teacher_list(); include 'teacher_list.php'; break; case 'show_modify_teacher': $teacher_id = filter_input(INPUT_GET, 'teacher_id'); $teacher = get_teacher($teacher_id); $error_msg = ''; $first_name = $teacher['first_name']; $last_name = $teacher['last_name']; $display_name = $teacher['display_name']; $teachers = get_teacher($teacher_id); include 'teacher_modify.php'; exit; break; case 'modify_teacher': $error_msg = ''; $choice = filter_input(INPUT_POST, 'choice'); $first_name = filter_input(INPUT_POST, 'first_name'); $last_name = filter_input(INPUT_POST, 'last_name'); $display_name = filter_input(INPUT_POST, 'display_name'); $teacher_id = filter_input(INPUT_POST, 'teacher_id'); if ($choice == 'Modify') { if (empty($first_name)) { $error_msg .= "First Number is required.<BR>"; } if (empty($last_name)) {
?> <tr> <td> <a href="javascript:jump('../course.php?courseid=<?php $course_id = $row[0]; echo $course_id; ?> ')"><?php $course_id = $row[0]; echo get_coursename($course_id); ?> </a> </td> <td> <?php echo get_teacher($row[0]); ?> </td> </tr> <?php } ?> </table> <?php } } ?>