Beispiel #1
0
function test()
{
    echo "<hr /><b>Fake user object</b>";
    $user = (object) array('firstname' => 'User', 'lastname' => 'Test', 'email' => '*****@*****.**', 'username' => 'testuser', 'newpassword' => 'somenewpassword');
    $sender = (object) array('firstname' => 'Test', 'Lastname' => 'User');
    echo EmailTemplate::send('user_create', array('user' => $user, 'course' => 2, 'sender' => $sender));
    echo EmailTemplate::send('user_added_to_course', array('course' => 2), array(array('user' => 3), array('user' => 56), array('user' => $user)));
    echo "<hr /><b>Email template from database</b>";
    echo EmailTemplate::send('user_added_to_course', array('user' => 3, 'course' => 2));
    echo "<hr /><b>Email to current user about current course</b>";
    echo EmailTemplate::send('user_added_to_course');
    echo "<hr/><b>Email all users in a department</b>";
    echo EmailTemplate::send_to_all_users_in_department(3, 'user_added_to_course', array('course' => 2));
}
// Set the url.
$linkurl = new moodle_url('/local/email/template_edit_form.php');
// Build the nav bar.
company_admin_fix_breadcrumb($PAGE, $linktext, $linkurl);
$blockpage = new blockpage($PAGE, $OUTPUT, 'email', 'local', 'send_emails');
$blockpage->setup();
require_login(null, false);
// Adds to $PAGE, creates $OUTPUT.
// Get the form data.
// Set up the form.
$mform = new template_send_form($PAGE->url, $context, $companyid, $templateid, $templaterecord);
$mform->set_data($templaterecord);
if ($mform->is_cancelled()) {
    redirect($templatelist);
} else {
    if ($data = $mform->get_data()) {
        $data->userid = $USER->id;
        foreach ($data->selectedcourses as $course) {
            $depts = company::get_departments_by_course($course->id);
            $sql = "SELECT\n                    cr.*,\n                    ccr.startdatetime,\n                    ccr.enddatetime,\n                    ccr.intro as summary\n                FROM {courseclassroom} ccr\n                    INNER JOIN {classroom} cr ON ccr.classroomid = cr.id\n                WHERE ccr.course = :course\n                ORDER BY ccr.startdatetime > " . time() . ", ccr.startdatetime";
            $classroom = $DB->get_record_sql($sql, array('course' => $course->id), 0, 1);
            foreach ($depts as $departmentid) {
                EmailTemplate::send_to_all_users_in_department($departmentid, $templaterecord->name, array('course' => $course->id, 'classroom' => $classroom));
            }
        }
        redirect($templatelist);
    }
}
$blockpage->display_header();
$mform->display();
echo $OUTPUT->footer();
Beispiel #3
0
 $PAGE->set_heading($SITE->fullname);
 // Are we sending out emails?
 if (!empty($publish)) {
     if (has_capability('block/iomad_company_admin:edit_all_departments', context_system::instance())) {
         $userhierarchylevel = $parentlevel->id;
     } else {
         $userlevel = company::get_userlevel($USER);
         $userhierarchylevel = $userlevel->id;
     }
     $departmentid = $userhierarchylevel;
     echo $OUTPUT->header();
     echo "<h2>" . get_string('sendingemails', 'trainingevent') . "</h2>";
     $course = $DB->get_record('course', array('id' => $event->course));
     $course->url = new moodle_url('course/view.php', array('id' => $course->id));
     $location->time = date('jS \\of F Y \\a\\t h:i', $event->startdatetime);
     EmailTemplate::send_to_all_users_in_department($departmentid, 'advertise_classroom_based_course', array('course' => $course, 'classroom' => $location, 'event' => $event));
     redirect("{$CFG->wwwroot}/mod/trainingevent/view.php?id={$id}", get_string('emailssent', 'trainingevent'));
     die;
 }
 // Get the current number booked on it.
 $numattending = $DB->count_records('trainingevent_users', array('trainingeventid' => $event->id));
 $eventtable = "<h2>{$event->name}</h2>";
 if (!empty($messagestring)) {
     $eventtable .= "<p>{$messagestring}</p>";
 }
 $eventtable .= "<table><tr>";
 if (has_capability('mod/trainingevent:invite', $context)) {
     $eventtable .= "<td>" . $OUTPUT->single_button("{$CFG->wwwroot}/mod/trainingevent/view.php?id={$id}&publish=1", get_string('publish', 'trainingevent')) . "</td>";
 }
 if (has_capability('mod/trainingevent:viewattendees', $context)) {
     $eventtable .= "<td>" . $OUTPUT->single_button("{$CFG->wwwroot}/mod/trainingevent/view.php?id={$id}&view=1", get_string('viewattendees', 'trainingevent')) . "</td>";