Exemple #1
0
function local_course_notification_cron()
{
    global $DB;
    $runtime = time();
    echo "Running course notification cron at " . date('D M Y h:m:s', $runtime) . "\n";
    // Generate automatic reports.
    // Training reaching lifetime/expired.
    if ($checkcourses = $DB->get_records_sql('SELECT * from {local_course_notification} where expiryduration!=0')) {
        // We have some courses which we need to check against.
        foreach ($checkcourses as $checkcourse) {
            $course = $DB->get_record('course', array('id' => $checkcourse->courseid));
            if (!$course->visible) {
                // Don not send course notification for inactive course
                continue;
            }
            $expiredtext = "";
            $expiringtext = "";
            $latetext = "";
            echo "Get completion information for course: {$checkcourse->courseid} of company: {$checkcourse->companyid} \n";
            $sql = 'SELECT cc.* FROM {course_completions} cc' . ' JOIN {company_users} cu ON cu.userid = cc.userid ' . 'WHERE cc.course=:courseid AND cu.companyid = :companyid';
            $company = $DB->get_record('company', array('id' => $checkcourse->companyid, 'suspended' => 0));
            if (!$company) {
                echo "Either Company not exist or suspended";
                continue;
            }
            if ($coursecompletions = $DB->get_records_sql($sql, array('courseid' => $checkcourse->courseid, 'companyid' => $checkcourse->companyid))) {
                print_object($coursecompletions);
                // Get the course information.
                foreach ($coursecompletions as $completion) {
                    if (!empty($completion->timeenrolled) && empty($completion->timecompleted)) {
                        $user = $DB->get_record('user', array('id' => $completion->userid));
                        // Send course overdue email to user
                        /* echo "current time:-" . $runtime;
                           echo "<br>Timeenrol:-" . $completion->timeenrolled;
                           echo "<br>expiryduration:-" . $checkcourse->expiryduration;
                           echo "<br>warnexpire:-" . $checkcourse->warnexpire;
                           echo "warncourseoverdue:-" . $checkcourse->warncourseoverdue; */
                        if ($checkcourse->warncourseoverdue && $completion->timeenrolled + $checkcourse->expiryduration < $runtime && $runtime <= $completion->timeenrolled + $checkcourse->expiryduration + $checkcourse->warncourseoverdue) {
                            echo "<br>Sending course overdue email to {$user->email} \n";
                            EmailTemplate::send('expire', array('course' => $course, 'user' => $user));
                            /*$expiredtext .= $user->firstname . ' ' . $user->lastname . ', ' . $user->email . ' - ' .
                              date('D M Y', $completion->timecompleted) . "\n";*/
                        } else {
                            if ($checkcourse->warnexpire && $completion->timeenrolled + $checkcourse->expiryduration <= $checkcourse->warnexpire + $runtime && $completion->timeenrolled + $checkcourse->expiryduration > $runtime) {
                                echo "<br>Sending expiry warning email to {$user->email} \n";
                                EmailTemplate::send('expiry_warn_user', array('course' => $course, 'user' => $user));
                                /*$expiringtext .= $user->firstname . ' ' . $user->lastname . ', ' . $user->email . ' - ' .
                                  date('D M Y', $completion->timecompleted) . "\n";*/
                            }
                        }
                    }
                }
            }
        }
    }
}
 public function confirm()
 {
     global $DB, $CFG;
     if ($basketid = get_basket_id()) {
         // Send invoice email to the user.
         $basket = get_basket();
         $basket->itemized = get_invoice_html($basketid, 0, 0);
         // Notify shop admin.
         if (isset($CFG->commerce_admin_email)) {
             if (!($shopadmin = $DB->get_record('user', array('email' => $CFG->commerce_admin_email)))) {
                 $shopadmin = new stdClass();
                 $shopadmin->email = $CFG->commerce_admin_email;
                 if (empty($CFG->commerce_admin_firstname)) {
                     $shopadmin->firstname = "Shop";
                 } else {
                     $shopadmin->firstname = $CFG->commerce_admin_firstname;
                 }
                 if (empty($CFG->commerce_admin_lastname)) {
                     $shopadmin->lastname = "Admin";
                 } else {
                     $shopadmin->lastname = $CFG->commerce_admin_lastname;
                 }
                 $shopadmin->id = -999;
             }
         } else {
             $shopadmin = new stdClass();
             $shopadmin->email = $CFG->support_email;
             if (empty($CFG->commerce_admin_firstname)) {
                 $shopadmin->firstname = "Shop";
             } else {
                 $shopadmin->firstname = $CFG->commerce_admin_firstname;
             }
             if (empty($CFG->commerce_admin_lastname)) {
                 $shopadmin->lastname = "Admin";
             } else {
                 $shopadmin->lastname = $CFG->commerce_admin_lastname;
             }
             $shopadmin->id = -999;
         }
         if ($user = $DB->get_record('user', array('id' => $basket->userid))) {
             EmailTemplate::send('invoice_ordercomplete', array('user' => $user, 'invoice' => $basket, 'sender' => $shopadmin));
             // Notify shop admin.
             if (isset($CFG->commerce_admin_email)) {
                 EmailTemplate::send('invoice_ordercomplete_admin', array('user' => $shopadmin, 'invoice' => $basket, 'sender' => $shopadmin));
             }
             // Set status of invoice to unpaid.
             $DB->set_field('invoice', 'status', INVOICESTATUS_UNPAID, array('id' => $basketid));
             return '';
         }
     }
     return '<p class="error">' . get_string('pp_invoice_basketnolongeravailable', 'block_iomad_commerce') . '</p>';
 }
Exemple #3
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));
}
Exemple #4
0
 public static function store_temporary_password($user, $sendemail, $temppassword)
 {
     global $CFG, $USER;
     set_user_preference('iomad_temporary', self::rc4encrypt($temppassword), $user);
     unset_user_preference('create_password', $user);
     if ($sendemail) {
         $user->newpassword = $temppassword;
         if (!empty($CFG->iomad_email_senderisreal)) {
             EmailTemplate::send('user_create', array('user' => $user, 'sender' => $USER));
         } else {
             EmailTemplate::send('user_create', array('user' => $user, 'headers' => serialize(array("To:" . $user->email . ", " . $USER->email))));
         }
     } else {
         unset_user_preference('iomad_send_password', $user);
     }
 }
 } else {
     //$usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, $usercontext, 'user_profile', $usernew->id);
     $DB->update_record('user', $usernew);
     // Pass a true $userold here.
     if (!$authplugin->user_update($user, $userform->get_data())) {
         // Auth update failed, rollback for moodle.
         $DB->update_record('user', $user);
         print_error('cannotupdateuseronexauth', '', '', $user->auth);
     }
     // Set new password if specified.
     if (!empty($usernew->newpassword)) {
         if ($authplugin->can_change_password()) {
             if (!$authplugin->user_update_password($usernew, $usernew->newpassword)) {
                 print_error('cannotupdatepasswordonextauth', '', '', $usernew->auth);
             } else {
                 EmailTemplate::send('password_update', array('user' => $usernew));
             }
         }
     }
     // Code added by sumit 31/01/2016
     $userid = $usernew->id;
     if (!empty($usernew->managertype)) {
         $systemcontext = context_system::instance();
         $companycourseeditorrole = $DB->get_record('role', array('shortname' => 'companycourseeditor'));
         $companycoursenoneditorrole = $DB->get_record('role', array('shortname' => 'companycoursenoneditor'));
         if ($usernew->managertype == 2) {
             //$departmentmanagerrole = $DB->get_record('role', array('shortname' => 'companydepartmentmanager'));
             $companyinstructorrole = $DB->get_record('role', array('shortname' => 'instructor'));
             $companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
             //role_unassign_all(array('roleid' => $departmentmanagerrole->id, 'userid' => $userid, 'contextid' => $systemcontext->id), false, false);
             role_unassign_all(array('roleid' => $companyinstructorrole->id, 'userid' => $userid, 'contextid' => $systemcontext->id), false, false);
 public function process()
 {
     global $DB, $CFG;
     $this->create_user_selectors();
     // Process incoming enrolments.
     if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstoassign = $this->potentialusers->get_selected_users();
         if (!empty($userstoassign)) {
             foreach ($userstoassign as $adduser) {
                 $allow = true;
                 // GWL : Check the userid is valid.
                 if (!company::check_valid_user($this->selectedcompany, $adduser->id, $this->departmentid)) {
                     print_error('invaliduserdepartment', 'block_iomad_company_management');
                 }
                 if ($allow) {
                     company_user::enrol($adduser, array($this->course->id), $this->selectedcompany);
                     EmailTemplate::send('user_added_to_course', array('course' => $this->course, 'user' => $adduser));
                 }
             }
             $this->potentialusers->invalidate_selected_users();
             $this->currentusers->invalidate_selected_users();
         }
     }
     // Process incoming unenrolments.
     if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstounassign = $this->currentusers->get_selected_users();
         if (!empty($userstounassign)) {
             foreach ($userstounassign as $removeuser) {
                 // GWL : Check the userid is valid.
                 if (!company::check_valid_user($this->selectedcompany, $removeuser->id, $this->departmentid)) {
                     print_error('invaliduserdepartment', 'block_iomad_company_management');
                 }
                 company_user::unenrol($removeuser, array($this->course->id), $this->selectedcompany);
             }
             $this->potentialusers->invalidate_selected_users();
             $this->currentusers->invalidate_selected_users();
         }
     }
 }
Exemple #7
0
                             }
                         }
                         add_to_log($event->course, 'trainingevent', 'Department manager approved', 'view.php?id=' . $event->id, $event->name . ' User -' . $user->firstname . ' ' . $user->lastname . ' (id=' . $user->id . ') by ' . $USER->firstname . ' ' . $USER->lastname . ' (id=' . $USER->id . ')', $cmidinfo->id, $USER->id);
                     }
                 } else {
                     $userbooking->tm_ok = 0;
                     $userbooking->manager_ok = 1;
                     $DB->update_record('block_iomad_approve_access', $userbooking);
                     $course = $DB->get_record('course', array('id' => $event->course));
                     $location->time = date('jS \\of F Y \\a\\t h:i', $event->startdatetime);
                     $user = $DB->get_record('user', array('id' => $userid));
                     // Get the list of managers we need to send an email to.
                     $mymanagers = $company->get_my_managers($USER->id, 1);
                     foreach ($mymanagers as $mymanager) {
                         if ($manageruser = $DB->get_record('user', array('id' => $mymanager->userid))) {
                             EmailTemplate::send('course_classroom_approval', array('course' => $course, 'user' => $manageruser, 'approveuser' => $user, 'classroom' => $location, 'event' => $event));
                         }
                     }
                     add_to_log($event->course, 'trainingevent', 'Department manager approved', 'view.php?id=' . $event->id, $event->name . ' User -' . $user->firstname . ' ' . $user->lastname . ' (id=' . $user->id . ') by ' . $USER->firstname . ' ' . $USER->lastname . ' (id=' . $USER->id . ')', $cmidinfo->id, $USER->id);
                 }
             }
         }
     }
 }
 if ($action == 'grade' && !empty($userid)) {
     // Grade the user.
     $gradegrade->userid = $userid;
     $gradegrade->rawgrade = $usergrade;
     $gradegrade->finalgrade = $usergrade;
     $gradegrade->usermodified = $USER->id;
     $gradegrade->timemodified = time();
Exemple #8
0
function emails_report_cron()
{
    global $DB;
    $runtime = time();
    echo "Running email report cron at " . date('D M Y h:m:s', $runtime) . "\n";
    // Generate automatic reports.
    // Training reaching lifetime/expired.
    if ($checkcourses = $DB->get_records_sql('SELECT * from {iomad_courses} where validlength!=0')) {
        // We have some courses which we need to check against.
        foreach ($checkcourses as $checkcourse) {
            $expiredtext = "";
            $expiringtext = "";
            $latetext = "";
            echo "Get completion information for {$checkcourse->courseid} \n";
            if ($coursecompletions = $DB->get_records('course_completions', array('course' => $checkcourse->courseid))) {
                // Get the course information.
                $course = $DB->get_record('course', array('id' => $checkcourse->courseid));
                // We have completion information.
                foreach ($coursecompletions as $completion) {
                    if (!empty($completion->timecompleted)) {
                        // Got a completed time.
                        if ($completion->timecompleted + $checkcourse->validlength * 86400 > $runtime) {
                            // Got someone overdue.
                            $user = $DB->get_record('user', array('id' => $completion->userid));
                            echo "Sending overdue email to {$user->email} \n";
                            EmailTemplate::send('expire', array('course' => $course, 'user' => $user));
                            $expiredtext .= $user->firstname . ' ' . $user->lastname . ', ' . $user->email . ' - ' . date('D M Y', $completion->timecompleted) . "\n";
                        } else {
                            if ($completion->timecompleted + $checkcourse->validlength * 86400 + $checkcourse->warnexpire * 86400 > $runtime) {
                                // We got someone approaching expiry.
                                $user = $DB->get_record('user', array('id' => $completion->userid));
                                echo "Sending exiry email to {$user->email} \n";
                                EmailTemplate::send('expiry_warn_user', array('course' => $course, 'user' => $user));
                                $expiringtext .= $user->firstname . ' ' . $user->lastname . ', ' . $user->email . ' - ' . date('D M Y', $completion->timecompleted) . "\n";
                            }
                        }
                    } else {
                        if (!empty($completion->timeenrolled)) {
                            if ($completion->timeenrolled + $checkcourse->warncompletion * 86400 > $runtime) {
                                // Go someone not completed in time.
                                $user = $DB->get_record('user', array('id' => $completion->userid));
                                echo "Sending completion warning email to {$user->email} \n";
                                EmailTemplate::send('completion_warn_user', array('course' => $course, 'user' => $user));
                                $latetext .= $user->firstname . ' ' . $user->lastname . ', ' . $user->email . ' - ' . date('D M Y', $completion->timeenrolled) . "\n";
                            }
                        }
                    }
                }
                // Get the list of company managers.
                $companymanagers = $DB->get_records_sql("SELECT cm.userid FROM {companymanager} cm,\n                                                         {companycourse} cc\n                                                         WHERE cc.courseid = {$checkcourse->courseid}\n                                                         AND cc.companyid = cm.companyid");
                $managers = array();
                $coursecontext = context_course::instance($course->id);
                foreach ($companymanagers as $companymanager) {
                    $user = $DB->get_record('user', array('id' => $companymanager->userid));
                    if (has_capability('moodle/course:view', $coursecontext, $user)) {
                        $managers[] = $user;
                    }
                }
                // Check if there are any managers on this course.
                foreach ($managers as $manager) {
                    if (!empty($expiredtext)) {
                        // Send the summary email.
                        $course->reporttext = $expiredtext;
                        EmailTemplate::send('expire_manager', array('course' => $course, 'user' => $manager));
                    }
                    if (!empty($expiringtext)) {
                        // Send the summary email.
                        $course->reporttext = $expiringtext;
                        EmailTemplate::send('expiry_warn_manager', array('course' => $course, 'user' => $manager));
                    }
                    if (!empty($latetext)) {
                        // Send the summary email.
                        $course->reporttext = $latetext;
                        EmailTemplate::send('completion_warn_manager', array('course' => $course, 'user' => $manager));
                    }
                }
            }
        }
    }
}
 public function process()
 {
     global $DB, $CFG;
     $this->create_course_selectors();
     // Process incoming enrolments.
     if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
         $coursestoassign = $this->potentialcourses->get_selected_courses();
         if (!empty($coursestoassign)) {
             foreach ($coursestoassign as $addcourse) {
                 $allow = true;
                 if ($allow) {
                     company_user::enrol($this->user, array($addcourse->id));
                     EmailTemplate::send('user_added_to_course', array('course' => $addcourse, 'user' => $this->user));
                 }
             }
             $this->potentialcourses->invalidate_selected_courses();
             $this->currentcourses->invalidate_selected_courses();
         }
     }
     // Process incoming unenrolments.
     if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
         $coursestounassign = $this->currentcourses->get_selected_courses();
         if (!empty($coursestounassign)) {
             foreach ($coursestounassign as $removecourse) {
                 company_user::unenrol($this->user, array($removecourse->id));
             }
             $this->potentialcourses->invalidate_selected_courses();
             $this->currentcourses->invalidate_selected_courses();
         }
     }
 }
 public function process()
 {
     global $DB, $CFG;
     $this->create_course_selectors();
     // Process incoming enrolments.
     if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
         $coursestoassign = $this->potentialcourses->get_selected_courses();
         if (!empty($coursestoassign)) {
             if ($licenserecord = (array) $DB->get_record('companylicense', array('id' => $this->licenseid))) {
                 if ($licenserecord['used'] + count($coursestoassign) > $licenserecord['allocation']) {
                     echo "<div class='mform'><span class='error'>" . get_string('triedtoallocatetoomanylicenses', 'block_iomad_company_admin') . "</span></div>";
                 } else {
                     foreach ($coursestoassign as $addcourse) {
                         $DB->insert_record('companylicense_users', array('userid' => $this->userid, 'licenseid' => $licenserecord['id'], 'licensecourseid' => $addcourse->id));
                         // Create an email event.
                         $license = new stdclass();
                         $license->length = $licenserecord['validlength'];
                         $license->valid = date('d M Y', $licenserecord['expirydate']);
                         EmailTemplate::send('license_allocated', array('course' => $addcourse, 'user' => $this->user, 'license' => $license));
                         $licenserecord['used']++;
                         $DB->update_record('companylicense', $licenserecord);
                     }
                 }
             }
             $this->potentialcourses->invalidate_selected_courses();
             $this->currentcourses->invalidate_selected_courses();
         }
     }
     // Process incoming unenrolments.
     if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
         $coursestounassign = $this->currentcourses->get_selected_courses();
         if (!empty($coursestounassign)) {
             foreach ($coursestounassign as $removecourse) {
                 if ($userlicenserecord = $DB->get_record('companylicense_users', array('userid' => $this->userid, 'licensecourseid' => $removecourse->id, 'isusing' => 0))) {
                     $licenserecord = (array) $DB->get_record('companylicense', array('id' => $userlicenserecord->licenseid));
                     $DB->delete_records('companylicense_users', array('id' => $userlicenserecord->id));
                     $licenserecord['used']--;
                     $DB->update_record('companylicense', $licenserecord);
                 }
             }
             $this->potentialcourses->invalidate_selected_courses();
             $this->currentcourses->invalidate_selected_courses();
         }
     }
 }
 public function process()
 {
     global $DB, $CFG;
     $this->create_user_selectors();
     // Get the courses to send to if emails are configured.
     $courses = company::get_courses_by_license($this->license->id);
     // Process incoming allocations.
     if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstoassign = $this->potentialusers->get_selected_users();
         $numberoflicenses = $this->license->allocation;
         $count = $this->license->used;
         $licenserecord = (array) $this->license;
         if (!empty($userstoassign)) {
             foreach ($userstoassign as $adduser) {
                 if ($count >= $numberoflicenses) {
                     // Set the used amount.
                     $licenserecord['used'] = $count;
                     $DB->update_record('companylicense', $licenserecord);
                     redirect(new moodle_url("/blocks/iomad_company_admin/company_license_users_form.php", array('licenseid' => $this->licenseid, 'error' => 1)));
                 }
                 $allow = true;
                 // GWL : Check the userid is valid.
                 if (!company::check_valid_user($this->selectedcompany, $adduser->id, $this->departmentid)) {
                     print_error('invaliduserdepartment', 'block_iomad_company_management');
                 }
                 if ($allow) {
                     $count++;
                     $DB->insert_record('companylicense_users', array('userid' => $adduser->id, 'licenseid' => $this->licenseid));
                 }
                 // Create an email event.
                 foreach ($courses as $course) {
                     $license = new stdclass();
                     $license->length = $licenserecord['validlength'];
                     $license->valid = date('d M Y', $licenserecord['expirydate']);
                     EmailTemplate::send('license_allocated', array('course' => $course, 'user' => $adduser, 'license' => $license));
                 }
             }
             // Set the used amount for the license.
             $licenserecord['used'] = $count;
             $DB->update_record('companylicense', $licenserecord);
             $this->potentialusers->invalidate_selected_users();
             $this->currentusers->invalidate_selected_users();
         }
     }
     // Process incoming unallocations.
     if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstounassign = $this->currentusers->get_selected_users();
         $count = $this->license->used;
         $licenserecord = (array) $this->license;
         if (!empty($userstounassign)) {
             foreach ($userstounassign as $removeuser) {
                 // GWL : Check the userid is valid.
                 if (!company::check_valid_user($this->selectedcompany, $removeuser->id, $this->departmentid)) {
                     print_error('invaliduserdepartment', 'block_iomad_company_management');
                 }
                 if ($licensedata = $DB->get_record('companylicense_users', array('userid' => $removeuser->id, 'licenseid' => $this->licenseid))) {
                     if (!$licensedata->isusing) {
                         $DB->delete_records('companylicense_users', array('id' => $licensedata->id));
                         $count--;
                     }
                 }
                 // Create an email event.
                 foreach ($courses as $course) {
                     EmailTemplate::send('license_removed', array('course' => $course, 'user' => $removeuser));
                 }
             }
             // Update the number of allocated records..
             if ($count < 0) {
                 // Cant have less than 0 licenses.
                 $count = 0;
             }
             $licenserecord['used'] = $count;
             $DB->update_record('companylicense', $licenserecord);
             $this->potentialusers->invalidate_selected_users();
             $this->currentusers->invalidate_selected_users();
         }
     }
 }