示例#1
0
文件: auth.php 项目: JP-Git/moodle
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object
  * @param boolean $notify print notice with link and terminate
  */
 function user_signup($user, $notify = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $user->password = hash_internal_user_password($user->password);
     $user->id = $DB->insert_record('user', $user);
     /// Save any custom profile field information
     profile_save_data($user);
     $user = $DB->get_record('user', array('id' => $user->id));
     events_trigger('user_created', $user);
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth_email');
     }
     if ($notify) {
         global $CFG, $PAGE, $OUTPUT;
         $emailconfirm = get_string('emailconfirm');
         $PAGE->navbar->add($emailconfirm);
         $PAGE->set_title($emailconfirm);
         $PAGE->set_heading($PAGE->course->fullname);
         echo $OUTPUT->header();
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#2
0
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object (with system magic quotes)
  * @param boolean $notify print notice with link and terminate
  */
 function user_signup($user, $notify = true)
 {
     global $CFG;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $user->password = hash_internal_user_password($user->password);
     if (!($user->id = insert_record('user', $user))) {
         print_error('auth_emailnoinsert', 'auth');
     }
     /// Save any custom profile field information
     profile_save_data($user);
     $user = get_record('user', 'id', $user->id);
     events_trigger('user_created', $user);
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth');
     }
     if ($notify) {
         global $CFG;
         $emailconfirm = get_string('emailconfirm');
         $navlinks = array();
         $navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
         $navigation = build_navigation($navlinks);
         print_header($emailconfirm, $emailconfirm, $navigation);
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#3
0
文件: lib.php 项目: jamesmcq/elis
function cluster_groups_changed($name)
{
    global $DB;
    $shortname = substr($name, strpos($name, 'local_elisprogram_') + strlen('local_elisprogram_'));
    // TBD: following didn't work?
    //$value = elis::$config->local_elisprogram->$shortname;
    $value = $DB->get_field('config_plugins', 'value', array('plugin' => 'local_elisprogram', 'name' => $shortname));
    //error_log("/local/elisprogram/lib/lib.php::cluster_groups_changed({$name}) {$shortname} = '{$value}'");
    if (!empty($value)) {
        $event = 'crlm_' . $shortname . '_enabled';
        error_log("Triggering event: {$event}");
        events_trigger($event, 0);
    }
}
示例#4
0
/**
 * Update a user with a user object (will compare against the ID)
 *
 * @param object $user the user to update
 */
function user_update_user($user)
{
    global $DB;
    // set the timecreate field to the current time
    if (!is_object($user)) {
        $user = (object) $user;
    }
    // unset password here, for updating later
    if (isset($user->password)) {
        $passwd = $user->password;
        unset($user->password);
    }
    $user->timemodified = time();
    $DB->update_record('user', $user);
    // trigger user_updated event on the full database user row
    $updateduser = $DB->get_record('user', array('id' => $user->id));
    events_trigger('user_updated', $updateduser);
    // if password was set, then update its hash
    if (isset($passwd)) {
        update_internal_user_password($updateduser, $passwd);
    }
}
示例#5
0
 function user_signup($user, $notify = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $password_clear = $user->password;
     $user->password = hash_internal_user_password($user->password);
     if (!($user->id = $DB->insert_record('user', $user))) {
         print_error('auth_emailnoinsert', 'auth');
     }
     /// Save any custom profile field information
     profile_save_data($user);
     $conditions = array('id' => $user->id);
     $user = $DB->get_record('user', $conditions);
     /* Create user in Joomla */
     $userinfo['username'] = $user->username;
     $userinfo['password'] = $password_clear;
     $userinfo['password2'] = $password_clear;
     $userinfo['name'] = $user->firstname . " " . $user->lastname;
     $userinfo['email'] = $user->email;
     $userinfo['block'] = 1;
     $this->call_method("createUser", $userinfo);
     events_trigger('user_created', $user);
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth');
     }
     if ($notify) {
         global $CFG;
         $emailconfirm = get_string('emailconfirm');
         $navlinks = array();
         $navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
         $navigation = build_navigation($navlinks);
         print_header($emailconfirm, $emailconfirm, $navigation);
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
示例#6
0
/**
 * Adds a specified user to a group
 * @param int $userid   The user id
 * @param int $groupid  The group id
 * @return boolean True if user added successfully or the user is already a 
 * member of the group, false otherwise. 
 */
function groups_add_member($groupid, $userid)
{
    if (!groups_group_exists($groupid)) {
        return false;
    }
    if (groups_is_member($groupid, $userid)) {
        return true;
    }
    $member = new object();
    $member->groupid = $groupid;
    $member->userid = $userid;
    $member->timeadded = time();
    if (!insert_record('groups_members', $member)) {
        return false;
    }
    //update group info
    set_field('groups', 'timemodified', $member->timeadded, 'id', $groupid);
    // MDL-9983
    $eventdata = new object();
    $eventdata->groupid = $groupid;
    $eventdata->userid = $userid;
    events_trigger('group_user_added', $eventdata);
    return true;
}
示例#7
0
        } else {
            $newlayout[] = 0;
        }
    }
    $attempt->layout = implode(',', $newlayout);
}
// Save the attempt in the database.
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$attempt->uniqueid = $quba->get_id();
$attempt->id = $DB->insert_record('quiz_attempts', $attempt);
// Log the new attempt.
if ($attempt->preview) {
    add_to_log($course->id, 'quiz', 'preview', 'view.php?id=' . $quizobj->get_cmid(), $quizobj->get_quizid(), $quizobj->get_cmid());
} else {
    add_to_log($course->id, 'quiz', 'attempt', 'review.php?attempt=' . $attempt->id, $quizobj->get_quizid(), $quizobj->get_cmid());
}
// Trigger event.
$eventdata = new stdClass();
$eventdata->component = 'mod_quiz';
$eventdata->attemptid = $attempt->id;
$eventdata->timestart = $attempt->timestart;
$eventdata->timestamp = $attempt->timestart;
$eventdata->userid = $attempt->userid;
$eventdata->quizid = $quizobj->get_quizid();
$eventdata->cmid = $quizobj->get_cmid();
$eventdata->courseid = $quizobj->get_courseid();
events_trigger('quiz_attempt_started', $eventdata);
$transaction->allow_commit();
// Redirect to the attempt page.
redirect($quizobj->attempt_url($attempt->id, $page));
示例#8
0
文件: lib.php 项目: numbas/moodle
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $CFG, $DB;
    $data->timemodified = time();
    $oldcourse = $DB->get_record('course', array('id' => $data->id), '*', MUST_EXIST);
    $context = get_context_instance(CONTEXT_COURSE, $oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
        context_moved($context, $newparent);
    }
    fix_course_sortorder();
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
    // Trigger events
    events_trigger('course_updated', $course);
}
 /**
  * Associates a cluster with a track.
  */
 static function associate($cluster, $track, $autounenrol = true, $autoenrol = true)
 {
     global $CURMAN;
     $db = $CURMAN->db;
     // make sure we don't double-associate
     if ($db->record_exists(CLSTTRKTABLE, 'clusterid', $cluster, 'trackid', $track)) {
         return;
     }
     $record = new clustertrack();
     $record->clusterid = $cluster;
     $record->trackid = $track;
     $record->autoenrol = $autoenrol;
     $record->autounenrol = $autounenrol;
     $record->data_insert_record();
     // Enrol all users in the cluster into track.
     $sql = 'SELECT uc.*
             FROM ' . $CURMAN->db->prefix_table(CLSTASSTABLE) . ' as uc
             JOIN ' . $CURMAN->db->prefix_table(USRTABLE) . ' as u
             ON uc.userid = u.id
             WHERE uc.clusterid = ' . $cluster . ' AND uc.autoenrol = 1
             ORDER BY u.lastname';
     $users = $db->get_records_sql($sql);
     //        $users = $db->get_records(CLSTUSERTABLE, 'clusterid', $cluster);
     if ($users && !empty($autoenrol)) {
         foreach ($users as $user) {
             usertrack::enrol($user->userid, $track);
         }
     }
     events_trigger('crlm_cluster_track_associated', $record);
 }
示例#10
0
 /**
  * Called after the mod has set itself up, to finish off any course module settings
  * (set instance id, add to correct section, set visibility, etc.) and send the response
  *
  * @param int $instanceid id returned by the mod when it was created
  */
 protected function finish_setup_course_module($instanceid)
 {
     global $DB, $USER;
     if (!$instanceid) {
         // Something has gone wrong - undo everything we can.
         delete_course_module($this->cm->id);
         throw new moodle_exception('errorcreatingactivity', 'moodle', '', $this->module->name);
     }
     $DB->set_field('course_modules', 'instance', $instanceid, array('id' => $this->cm->id));
     // Rebuild the course cache after update action
     rebuild_course_cache($this->course->id, true);
     $this->course->modinfo = null;
     // Otherwise we will just get the old version back again.
     $sectionid = course_add_cm_to_section($this->course, $this->cm->id, $this->section);
     set_coursemodule_visible($this->cm->id, true);
     // retrieve the final info about this module.
     $info = get_fast_modinfo($this->course);
     if (!isset($info->cms[$this->cm->id])) {
         // The course module has not been properly created in the course - undo everything.
         delete_course_module($this->cm->id);
         throw new moodle_exception('errorcreatingactivity', 'moodle', '', $this->module->name);
     }
     $mod = $info->cms[$this->cm->id];
     $mod->groupmodelink = $this->cm->groupmodelink;
     $mod->groupmode = $this->cm->groupmode;
     // Trigger mod_created event with information about this module.
     $eventdata = new stdClass();
     $eventdata->modulename = $mod->modname;
     $eventdata->name = $mod->name;
     $eventdata->cmid = $mod->id;
     $eventdata->courseid = $this->course->id;
     $eventdata->userid = $USER->id;
     events_trigger('mod_created', $eventdata);
     add_to_log($this->course->id, "course", "add mod", "../mod/{$mod->modname}/view.php?id={$mod->id}", "{$mod->modname} {$instanceid}");
     add_to_log($this->course->id, $mod->modname, "add", "view.php?id={$mod->id}", "{$instanceid}", $mod->id);
     $this->send_response($mod);
 }
示例#11
0
/**
 * Sends post content to plagiarism plugin
 * @param object $post Forum post object
 * @param object $cm Course-module
 * @param string $name
 * @return bool
*/
function forum_trigger_content_uploaded_event($post, $cm, $name) {
    $context = context_module::instance($cm->id);
    $fs = get_file_storage();
    $files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $post->id, "timemodified", false);
    $eventdata = new stdClass();
    $eventdata->modulename   = 'forum';
    $eventdata->name         = $name;
    $eventdata->cmid         = $cm->id;
    $eventdata->itemid       = $post->id;
    $eventdata->courseid     = $post->course;
    $eventdata->userid       = $post->userid;
    $eventdata->content      = $post->message;
    if ($files) {
        $eventdata->pathnamehashes = array_keys($files);
    }
    events_trigger('assessable_content_uploaded', $eventdata);

    return true;
}
示例#12
0
/**
 * Delete a course, including all related data from the database,
 * and any associated files from the moodledata folder.
 *
 * @param mixed $courseorid The id of the course or course object to delete.
 * @param bool $showfeedback Whether to display notifications of each action the function performs.
 * @return bool true if all the removals succeeded. false if there were any failures. If this
 *             method returns false, some of the removals will probably have succeeded, and others
 *             failed, but you have no way of knowing which.
 */
function delete_course($courseorid, $showfeedback = true)
{
    global $CFG;
    $result = true;
    if (is_object($courseorid)) {
        $courseid = $courseorid->id;
        $course = $courseorid;
    } else {
        $courseid = $courseorid;
        if (!($course = get_record('course', 'id', $courseid))) {
            return false;
        }
    }
    // frontpage course can not be deleted!!
    if ($courseid == SITEID) {
        return false;
    }
    if (!remove_course_contents($courseid, $showfeedback)) {
        if ($showfeedback) {
            notify("An error occurred while deleting some of the course contents.");
        }
        $result = false;
    }
    if (!delete_records("course", "id", $courseid)) {
        if ($showfeedback) {
            notify("An error occurred while deleting the main course record.");
        }
        $result = false;
    }
    /// Delete all roles and overiddes in the course context
    if (!delete_context(CONTEXT_COURSE, $courseid)) {
        if ($showfeedback) {
            notify("An error occurred while deleting the main course context.");
        }
        $result = false;
    }
    if (!fulldelete($CFG->dataroot . '/' . $courseid)) {
        if ($showfeedback) {
            notify("An error occurred while deleting the course files.");
        }
        $result = false;
    }
    if ($result) {
        //trigger events
        events_trigger('course_deleted', $course);
    }
    return $result;
}
 /**
  * tests events_trigger funtion() when instant handler fails
  */
 function test__events_trigger__failed_instant()
 {
     $this->assertEqual(1, events_trigger('test_instant', 'fail'), 'fail first event: %s');
     $this->assertEqual(1, events_trigger('test_instant', 'ok'), 'this one should fail too: %s');
     $this->assertEqual(0, events_cron('test_instant'), 'all events should stay in queue: %s');
     $this->assertEqual(2, events_pending_count('test_instant'), 'two events should in queue: %s');
     $this->assertEqual(0, sample_function_handler('status'), 'verify no event dispatched yet: %s');
     sample_function_handler('ignorefail');
     //ignore "fail" eventdata from now on
     $this->assertEqual(1, events_trigger('test_instant', 'ok'), 'this one should go to queue directly: %s');
     $this->assertEqual(3, events_pending_count('test_instant'), 'three events should in queue: %s');
     $this->assertEqual(0, sample_function_handler('status'), 'verify previous event was not dispatched: %s');
     $this->assertEqual(3, events_cron('test_instant'), 'all events should be dispatched: %s');
     $this->assertEqual(3, sample_function_handler('status'), 'verify three events were dispatched: %s');
     $this->assertEqual(0, events_pending_count('test_instant'), 'no events should in queue: %s');
     $this->assertEqual(0, events_trigger('test_instant', 'ok'), 'this event should be dispatched immediately: %s');
     $this->assertEqual(4, sample_function_handler('status'), 'verify event was dispatched: %s');
     $this->assertEqual(0, events_pending_count('test_instant'), 'no events should in queue: %s');
 }
示例#14
0
 /**
  * Test PM user method moodle_fullname
  */
 public function test_pmuser_moodle_fullname()
 {
     global $DB;
     // Create a Moodle user
     $src = new stdClass();
     $src->username = '******';
     $src->password = '******';
     $src->idnumber = '_____phpunit_test_';
     $src->firstname = 'John';
     $src->lastname = 'Doe';
     $src->email = '*****@*****.**';
     $src->country = 'CA';
     $src->confirmed = 1;
     $src->id = $DB->insert_record('user', $src);
     events_trigger('user_created', $src);
     // Get the PM user
     $retr = user::find(new field_filter('idnumber', $src->idnumber), array(), 0, 0);
     $this->assertTrue($retr->valid());
     $retr = $retr->current();
     $mdluser = $DB->get_record('user', array('id' => $src->id));
     $this->assertEquals(fullname($mdluser), $retr->moodle_fullname());
 }
示例#15
0
文件: lib.php 项目: nmicha/moodle
/**
 * Update a user with a user object (will compare against the ID)
 *
 * @param object $user the user to update
 */
function user_update_user($user)
{
    global $DB;
    // set the timecreate field to the current time
    if (!is_object($user)) {
        $user = (object) $user;
    }
    //check username
    if (isset($user->username)) {
        if ($user->username !== textlib::strtolower($user->username)) {
            throw new moodle_exception('usernamelowercase');
        } else {
            if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
                throw new moodle_exception('invalidusername');
            }
        }
    }
    // unset password here, for updating later
    if (isset($user->password)) {
        //check password toward the password policy
        if (!check_password_policy($user->password, $errmsg)) {
            throw new moodle_exception($errmsg);
        }
        $passwd = $user->password;
        unset($user->password);
    }
    $user->timemodified = time();
    $DB->update_record('user', $user);
    // trigger user_updated event on the full database user row
    $updateduser = $DB->get_record('user', array('id' => $user->id));
    // if password was set, then update its hash
    if (isset($passwd)) {
        $authplugin = get_auth_plugin($updateduser->auth);
        if ($authplugin->can_change_password()) {
            $authplugin->user_update_password($updateduser, $passwd);
        }
    }
    events_trigger('user_updated', $updateduser);
    add_to_log(SITEID, 'user', get_string('update'), '/view.php?id=' . $updateduser->id, fullname($updateduser));
}
示例#16
0
 /**
  * Update users
  *
  * @param array $users
  * @return null
  * @since Moodle 2.2
  */
 public static function update_users($users)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . "/user/lib.php";
     require_once $CFG->dirroot . "/user/profile/lib.php";
     //required for customfields related function
     // Ensure the current user is allowed to run this function
     $context = context_system::instance();
     require_capability('moodle/user:update', $context);
     self::validate_context($context);
     $params = self::validate_parameters(self::update_users_parameters(), array('users' => $users));
     $transaction = $DB->start_delegated_transaction();
     foreach ($params['users'] as $user) {
         if (empty($user['country'])) {
             //Allowing empty country leads to login issues. Let's not allow such updates
             continue;
         }
         user_update_user($user);
         //update user custom fields
         if (!empty($user['customfields'])) {
             foreach ($user['customfields'] as $customfield) {
                 $user["profile_field_" . $customfield['type']] = $customfield['value'];
                 //profile_save_data() saves profile file
                 //it's expecting a user with the correct id,
                 //and custom field to be named profile_field_"shortname"
             }
             profile_save_data((object) $user);
             events_trigger('user_updated', (object) $user);
         }
         //preferences
         if (!empty($user['preferences'])) {
             foreach ($user['preferences'] as $preference) {
                 set_user_preference($preference['type'], $preference['value'], $user['id']);
             }
         }
     }
     $transaction->allow_commit();
     return null;
 }
示例#17
0
 /**
  * Perform all necessary tasks to add an instructor assignment to the system.
  *
  * @return  boolean  true on success, otherwise false
  */
 public function add()
 {
     if ($this->duplicate_check() === false && $this->has_required_fields()) {
         $result = $this->data_insert_record();
         if ($result) {
             //trigger appropriate notification only on success
             events_trigger('crlm_instructor_assigned', $this);
         }
         return $result;
     } else {
         //invalid data
         return false;
     }
 }
示例#18
0
 /**
  * Deletes a category and moves all content (children, courses and questions) to the new parent
  *
  * Note that this function does not check capabilities, {@link coursecat::can_move_content_to()}
  * must be called prior
  *
  * @param int $newparentid
  * @param bool $showfeedback
  * @return bool
  */
 public function delete_move($newparentid, $showfeedback = false)
 {
     global $CFG, $DB, $OUTPUT;
     require_once $CFG->libdir . '/gradelib.php';
     require_once $CFG->libdir . '/questionlib.php';
     require_once $CFG->dirroot . '/cohort/lib.php';
     // get all objects and lists because later the caches will be reset so
     // we don't need to make extra queries
     $newparentcat = self::get($newparentid, MUST_EXIST, true);
     $catname = $this->get_formatted_name();
     $children = $this->get_children();
     $coursesids = $DB->get_fieldset_select('course', 'id', 'category = :category ORDER BY sortorder ASC', array('category' => $this->id));
     $context = context_coursecat::instance($this->id);
     if ($children) {
         foreach ($children as $childcat) {
             $childcat->change_parent_raw($newparentcat);
             // Log action.
             add_to_log(SITEID, "category", "move", "editcategory.php?id={$childcat->id}", $childcat->id);
         }
         fix_course_sortorder();
     }
     if ($coursesids) {
         if (!move_courses($coursesids, $newparentid)) {
             if ($showfeedback) {
                 echo $OUTPUT->notification("Error moving courses");
             }
             return false;
         }
         if ($showfeedback) {
             echo $OUTPUT->notification(get_string('coursesmovedout', '', $catname), 'notifysuccess');
         }
     }
     // move or delete cohorts in this context
     cohort_delete_category($this);
     // now delete anything that may depend on course category context
     grade_course_category_delete($this->id, $newparentid, $showfeedback);
     if (!question_delete_course_category($this, $newparentcat, $showfeedback)) {
         if ($showfeedback) {
             echo $OUTPUT->notification(get_string('errordeletingquestionsfromcategory', 'question', $catname), 'notifysuccess');
         }
         return false;
     }
     // finally delete the category and it's context
     $DB->delete_records('course_categories', array('id' => $this->id));
     $context->delete();
     add_to_log(SITEID, "category", "delete", "index.php", "{$this->name} (ID {$this->id})");
     events_trigger('course_category_deleted', $this);
     cache_helper::purge_by_event('changesincoursecat');
     if ($showfeedback) {
         echo $OUTPUT->notification(get_string('coursecategorydeleted', '', $catname), 'notifysuccess');
     }
     // If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
     if ($this->id == $CFG->defaultrequestcategory) {
         set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent' => 0)));
     }
     return true;
 }
示例#19
0
    $supportuser = new object();
    $supportuser->email = $CFG->supportemail ? $CFG->supportemail : $admin->email;
    $supportuser->firstname = $CFG->supportname ? $CFG->supportname : $admin->firstname;
    $supportuser->lastname = $CFG->supportname ? '' : $admin->lastname;
    $supportuser->maildisplay = true;
    /// Send the message and redirect
    $eventdata = new object();
    $eventdata->modulename = 'moodle';
    $eventdata->userfrom = $USER;
    $eventdata->userto = $supportuser;
    $eventdata->subject = 'Error: ' . $form->referer . ' -> ' . $form->requested;
    $eventdata->fullmessage = $form->text;
    $eventdata->fullmessageformat = FORMAT_PLAIN;
    $eventdata->fullmessagehtml = '';
    $eventdata->smallmessage = '';
    events_trigger('message_send', $eventdata);
    redirect($CFG->wwwroot . '/course/', 'Message sent, thanks', 3);
    exit;
}
$site = get_site();
$redirecturl = empty($_SERVER['REDIRECT_URL']) ? '' : $_SERVER['REDIRECT_URL'];
$httpreferer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
$requesturi = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
print_header($site->fullname . ':Error', $site->fullname . ': Error 404', 'Error 404 - File not Found', '');
print_simple_box('<p align="center">' . get_string('pagenotexist', 'error') . '<br />' . s($requesturi) . '</p>', 'center');
if (isloggedin()) {
    ?>
        <center>
        <p><?php 
示例#20
0
     $user->id = $DB->insert_record('user', $user);
     $upt->track('username', html_writer::link(new moodle_url('/user/profile.php', array('id' => $user->id)), s($user->username)), 'normal', false);
     // save custom profile fields data
     profile_save_data($user);
     if ($forcechangepassword) {
         set_user_preference('auth_forcepasswordchange', 1, $user);
     }
     if ($user->password === 'to be generated') {
         set_user_preference('create_password', 1, $user);
     }
     $upt->track('status', $struseradded);
     $upt->track('id', $user->id, 'normal', false);
     $usersnew++;
     // make sure user context exists
     get_context_instance(CONTEXT_USER, $user->id);
     events_trigger('user_created', $user);
     if ($bulk == UU_BULK_NEW or $bulk == UU_BULK_ALL) {
         if (!in_array($user->id, $SESSION->bulk_users)) {
             $SESSION->bulk_users[] = $user->id;
         }
     }
 }
 // add to cohort first, it might trigger enrolments indirectly - do NOT create cohorts here!
 foreach ($filecolumns as $column) {
     if (!preg_match('/^cohort\\d+$/', $column)) {
         continue;
     }
     if (!empty($user->{$column})) {
         $addcohort = $user->{$column};
         if (!isset($cohorts[$addcohort])) {
             if (is_number($addcohort)) {
示例#21
0
/**
 * Update the Moodle course with the contents from the SIS course
 * Note: $course includes id, fullname, shortname and startdate
 *
 * @author Andrew Zoltay
 * date    2011-06-02
 * @param update course object $course
 * @return true for success, false for failure
 */
function cace_update_course($course)
{
    $course->timemodified = time();
    if (cace_dbupdate_course($course)) {
        // Do some logging.
        add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
        // Trigger events.
        events_trigger('course_updated', $course);
        return true;
    } else {
        return false;
    }
}
示例#22
0
文件: rest.php 项目: nicusX/moodle
                    throw new moodle_exception("Ajax rest.php: This module is missing mod/{$cm->modname}/lib.php");
                }
                $deleteinstancefunction = $cm->modname . "_delete_instance";
                // Run the module's cleanup funtion.
                if (!$deleteinstancefunction($cm->instance)) {
                    throw new moodle_exception("Ajax rest.php: Could not delete the {$cm->modname} {$cm->name} (instance)");
                    die;
                }
                // remove all module files in case modules forget to do that
                $fs = get_file_storage();
                $fs->delete_area_files($modcontext->id);
                if (!delete_course_module($cm->id)) {
                    throw new moodle_exception("Ajax rest.php: Could not delete the {$cm->modname} {$cm->name} (coursemodule)");
                }
                // Remove the course_modules entry.
                if (!delete_mod_from_section($cm->id, $cm->section)) {
                    throw new moodle_exception("Ajax rest.php: Could not delete the {$cm->modname} {$cm->name} from section");
                }
                // Trigger a mod_deleted event with information about this module.
                $eventdata = new stdClass();
                $eventdata->modulename = $cm->modname;
                $eventdata->cmid = $cm->id;
                $eventdata->courseid = $course->id;
                $eventdata->userid = $USER->id;
                events_trigger('mod_deleted', $eventdata);
                rebuild_course_cache($course->id);
                add_to_log($courseid, "course", "delete mod", "view.php?id={$courseid}", "{$cm->modname} {$cm->instance}", $cm->id);
                break;
        }
        break;
}
示例#23
0
 /**
  * Alerts teachers by email of new or changed assignments that need grading
  *
  * First checks whether the option to email teachers is set for this assignment.
  * Sends an email to ALL teachers in the course (or in the group if using separate groups).
  * Uses the methods email_teachers_text() and email_teachers_html() to construct the content.
  *
  * @global object
  * @global object
  * @param $submission object The submission that has changed
  * @return void
  */
 function email_teachers($submission)
 {
     global $CFG, $DB;
     if (empty($this->assignment->emailteachers)) {
         // No need to do anything
         return;
     }
     $user = $DB->get_record('user', array('id' => $submission->userid));
     if ($teachers = $this->get_graders($user)) {
         $strassignments = get_string('modulenameplural', 'assignment');
         $strassignment = get_string('modulename', 'assignment');
         $strsubmitted = get_string('submitted', 'assignment');
         foreach ($teachers as $teacher) {
             $info = new object();
             $info->username = fullname($user, true);
             $info->assignment = format_string($this->assignment->name, true);
             $info->url = $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id;
             $postsubject = $strsubmitted . ': ' . $info->username . ' -> ' . $this->assignment->name;
             $posttext = $this->email_teachers_text($info);
             $posthtml = $teacher->mailformat == 1 ? $this->email_teachers_html($info) : '';
             $eventdata = new object();
             $eventdata->modulename = 'assignment';
             $eventdata->userfrom = $user;
             $eventdata->userto = $teacher;
             $eventdata->subject = $postsubject;
             $eventdata->fullmessage = $posttext;
             $eventdata->fullmessageformat = FORMAT_PLAIN;
             $eventdata->fullmessagehtml = $posthtml;
             $eventdata->smallmessage = '';
             if (events_trigger('message_send', $eventdata) > 0) {
             }
         }
     }
 }
示例#24
0
function link_to_gdoc($name, $link, $type = null, $modtype = 'url')
{
    global $COURSE, $DB, $CFG, $USER;
    require_once "{$CFG->dirroot}/mod/{$modtype}/lib.php";
    //add
    $fromform = new stdClass();
    $newform = new stdClass();
    $mform = new MoodleQuickForm(null, 'POST', 'nothing');
    $module = $DB->get_record("modules", array('name' => $modtype));
    $course = $COURSE;
    $cw = get_course_section(0, $course->id);
    $cm = null;
    // fields for mdl_url
    $fromform->course = $course->id;
    $fromform->name = $name;
    $fromform->introformat = 0;
    $fromform->introeditor = 0;
    $fromform->externalurl = $link;
    /*    if ($type !== 'dir') {
            $fromform->display          = 6;
            $fromform->displayoptions = 'a:2:{s:10:"popupwidth";i:1024;s:11:"popupheight";i:768;}';
        } else {
    */
    $fromform->display = 0;
    $fromform->popupwidth = 1024;
    $fromform->popupheight = 768;
    $fromform->popupwidth = null;
    $fromform->popupheight = null;
    $fromform->displayoptions = 'a:1:{s:10:"printintro";i:0;}';
    //    }
    // fields for mdl_course_module
    $fromform->module = $module->id;
    $fromform->instance = '';
    $fromform->section = 0;
    // The section number itself - relative!!! (section column in course_sections)
    $fromform->idnumber = null;
    $fromform->score = 0;
    $fromform->indent = 0;
    $fromform->visible = 1;
    $fromform->visibleold = 1;
    $fromform->groupmode = $course->groupmode;
    $fromform->groupingid = 0;
    $fromform->groupmembersonly = 0;
    $fromform->completion = 0;
    $fromform->completionview = 0;
    $fromform->completionexpected = 0;
    $fromform->availablefrom = 0;
    $fromform->availableuntil = 0;
    $fromform->showavailability = 0;
    $fromform->showdescription = 0;
    $fromform->conditiongradegroup = array();
    $fromform->conditionfieldgroup = array();
    // fields for mdl_course_sections
    $fromform->summaryformat = 0;
    $fromform->modulename = clean_param($module->name, PARAM_SAFEDIR);
    // For safety
    //	$fromform->add              = 'resource';
    //	$fromform->type             = $type == 'dir' ? 'collection' : 'file';
    //	$fromform->return           = 0; //must be false if this is an add, go back to course view on cancel
    //    $fromform->coursemodule 	= '';
    //	$fromform->popup			= 'resizable=1,scrollbars=1,directories=1,location=1,menubar=1,toolbar=1,status=1,width=1024,height=768';
    //	require_login($course->id); // needed to setup proper $COURSE
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    require_capability('moodle/course:manageactivities', $context);
    if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
        $fromform->groupmode = 0;
        // do not set groupmode
    }
    if (!course_allowed_module($course, $fromform->modulename)) {
        print_error('moduledisable', '', '', $fromform->modulename);
    }
    // first add course_module record because we need the context
    $newcm = new stdClass();
    $newcm->course = $course->id;
    $newcm->module = $fromform->module;
    $newcm->instance = 0;
    // not known yet, will be updated later (this is similar to restore code)
    $newcm->visible = $fromform->visible;
    $newcm->groupmode = $fromform->groupmode;
    $newcm->groupingid = $fromform->groupingid;
    $newcm->groupmembersonly = $fromform->groupmembersonly;
    $completion = new completion_info($course);
    if ($completion->is_enabled()) {
        $newcm->completion = $fromform->completion;
        $newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
        $newcm->completionview = $fromform->completionview;
        $newcm->completionexpected = $fromform->completionexpected;
    }
    if (!empty($CFG->enableavailability)) {
        $newcm->availablefrom = $fromform->availablefrom;
        $newcm->availableuntil = $fromform->availableuntil;
        $newcm->showavailability = $fromform->showavailability;
    }
    if (isset($fromform->showdescription)) {
        $newcm->showdescription = $fromform->showdescription;
    } else {
        $newcm->showdescription = 0;
    }
    if (!($fromform->coursemodule = add_course_module($newcm))) {
        print_error('cannotaddcoursemodule');
    }
    if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
        $draftid_editor = file_get_submitted_draft_itemid('introeditor');
        file_prepare_draft_area($draftid_editor, null, null, null, null);
        $fromform->introeditor = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftid_editor);
        // TODO: add better default
    }
    if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
        $introeditor = $fromform->introeditor;
        unset($fromform->introeditor);
        $fromform->intro = $introeditor['text'];
        $fromform->introformat = $introeditor['format'];
    }
    $addinstancefunction = $fromform->modulename . "_add_instance";
    $updateinstancefunction = $fromform->modulename . "_update_instance";
    $returnfromfunc = $addinstancefunction($fromform, $mform);
    //	$returnfromfunc = url_add_instance($fromform, $mform);
    if (!$returnfromfunc or !is_number($returnfromfunc)) {
        // undo everything we can
        $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
        delete_context(CONTEXT_MODULE, $fromform->coursemodule);
        $DB->delete_records('course_modules', array('id' => $fromform->coursemodule));
        if (!is_number($returnfromfunc)) {
            print_error('invalidfunction', '', course_get_url($course, $cw->section));
        } else {
            print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename);
        }
    }
    $fromform->instance = $returnfromfunc;
    $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id' => $fromform->coursemodule));
    // update embedded links and save files
    $modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
    if (!empty($introeditor)) {
        $fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 'mod_' . $fromform->modulename, 'intro', 0, array('subdirs' => true), $introeditor['text']);
        $DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id' => $fromform->instance));
    }
    // course_modules and course_sections each contain a reference
    // to each other, so we have to update one of them twice.
    $sectionid = add_mod_to_section($fromform);
    $DB->set_field('course_modules', 'section', $sectionid, array('id' => $fromform->coursemodule));
    // make sure visibility is set correctly (in particular in calendar)
    set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
    if (isset($fromform->cmidnumber)) {
        //label
        // set cm idnumber
        set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
    }
    // Set up conditions
    if ($CFG->enableavailability) {
        condition_info::update_cm_from_form((object) array('id' => $fromform->coursemodule), $fromform, false);
    }
    $eventname = 'mod_created';
    add_to_log($course->id, "course", "add mod", "../mod/{$fromform->modulename}/view.php?id={$fromform->coursemodule}", "{$fromform->modulename} {$fromform->instance}");
    add_to_log($course->id, $fromform->modulename, "add", "view.php?id={$fromform->coursemodule}", "{$fromform->instance}", $fromform->coursemodule);
    // Trigger mod_created/mod_updated event with information about this module.
    $eventdata = new stdClass();
    $eventdata->modulename = $fromform->modulename;
    $eventdata->name = $fromform->name;
    $eventdata->cmid = $fromform->coursemodule;
    $eventdata->courseid = $course->id;
    $eventdata->userid = $USER->id;
    events_trigger($eventname, $eventdata);
    rebuild_course_cache($course->id);
    return 1;
}
示例#25
0
    $certrequest->status = 'approved';
    $certrequest->changeuserid = $USER->id;
    $certrequest->timechanged = time();
    $certrequest->description = $description;
    if (!update_record('tao_user_certification_status', $certrequest)) {
        notify("Error updating certification status");
        print_footer(NULL, $course);
        die;
    }
    //now save event
    $eventdata = new object();
    $eventdata->userid = $certrequest->userid;
    $eventdata->course = $course->id;
    $eventdata->certification = $certrequest->certtype;
    $eventdata->certificationid = $certrequest->id;
    events_trigger('certification_updated', $eventdata);
    $mtuser = get_record('user', 'id', $certrequest->userid);
    $emailtext = get_string('certemailapprovetext', 'block_tao_certification_path') . "<br><br>" . $description;
    message_post_message($USER, $mtuser, addslashes($emailtext), FORMAT_HTML, 'direct');
    notify(get_string('certificationapproved', 'block_tao_certification_path'), 'notifysuccess');
} elseif ($action == 'declined') {
    $certrequest->status = 'declined';
    $certrequest->changeuserid = $USER->id;
    $certrequest->timechanged = time();
    $certrequest->description = $description;
    if (!update_record('tao_user_certification_status', $certrequest)) {
        notify("Error updating certification status");
        print_footer(NULL, $course);
        die;
    }
    $mtuser = get_record('user', 'id', $certrequest->userid);
示例#26
0
    /**
     * assignment submission is processed before grading
     *
     * @param $mform If validation failed when submitting this form - this is the moodleform - it can be null
     * @return bool Return false if the validation fails. This affects which page is displayed next.
     */
    private function process_submit_for_grading($mform) {
        global $USER, $CFG;

        // Need submit permission to submit an assignment
        require_capability('mod/assign:submit', $this->context);
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
        require_sesskey();

        $data = new stdClass();
        $adminconfig = $this->get_admin_config();
        $requiresubmissionstatement = (!empty($adminconfig->requiresubmissionstatement) ||
                                       $this->get_instance()->requiresubmissionstatement) &&
                                       !empty($adminconfig->submissionstatement);

        $submissionstatement = '';
        if (!empty($adminconfig->submissionstatement)) {
            $submissionstatement = $adminconfig->submissionstatement;
        }

        if ($mform == null) {
            $mform = new mod_assign_confirm_submission_form(null, array($requiresubmissionstatement,
                                                                    $submissionstatement,
                                                                    $this->get_course_module()->id,
                                                                    $data));
        }

        $data = $mform->get_data();
        if (!$mform->is_cancelled()) {
            if ($mform->get_data() == false) {
                return false;
            }
            if ($this->get_instance()->teamsubmission) {
                $submission = $this->get_group_submission($USER->id, 0, true);
            } else {
                $submission = $this->get_user_submission($USER->id, true);
            }

            if ($submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
                // Give each submission plugin a chance to process the submission
                $plugins = $this->get_submission_plugins();
                foreach ($plugins as $plugin) {
                    $plugin->submit_for_grading();
                }

                $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
                $this->update_submission($submission, $USER->id, true, $this->get_instance()->teamsubmission);
                $completion = new completion_info($this->get_course());
                if ($completion->is_enabled($this->get_course_module()) && $this->get_instance()->completionsubmit) {
                    $completion->update_state($this->get_course_module(), COMPLETION_COMPLETE, $USER->id);
                }

                if (isset($data->submissionstatement)) {
                    $this->add_to_log('submission statement accepted', get_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER)));
                }
                $this->add_to_log('submit for grading', $this->format_submission_for_log($submission));
                $this->notify_graders($submission);
                $this->notify_student_submission_receipt($submission);
                // Trigger assessable_content_done event to show completion
                $eventdata = new stdClass();
                $eventdata->modulename   = 'assign';
                $eventdata->cmid         = $this->get_course_module()->id;
                $eventdata->itemid       = $submission->id;
                $eventdata->courseid     = $this->get_course()->id;
                $eventdata->userid       = $USER->id;
                events_trigger('assessable_content_done', $eventdata);
            }
        }
        return true;
    }
示例#27
0
if ($id and $delete) {
    if (!$confirm) {
        print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group'));
        $optionsyes = array('id' => $id, 'delete' => 1, 'courseid' => $courseid, 'sesskey' => sesskey(), 'confirm' => 1);
        $optionsno = array('id' => $courseid);
        notice_yesno(get_string('deletegroupconfirm', 'group', $group->name), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
        print_footer();
        die;
    } else {
        if (confirm_sesskey()) {
            if (groups_delete_group($id)) {
                // MDL-9983
                $eventdata = new object();
                $eventdata->group = $id;
                $eventdata->course = $courseid;
                events_trigger('group_deleted', $eventdata);
                redirect('index.php?id=' . $course->id);
            } else {
                print_error('erroreditgroup', 'group', $returnurl);
            }
        }
    }
}
/// First create the form
$editform = new group_form();
$editform->set_data($group);
if ($editform->is_cancelled()) {
    redirect($returnurl);
} elseif ($data = $editform->get_data()) {
    if ($data->id) {
        if (!groups_update_group($data, $editform->_upload_manager)) {
示例#28
0
文件: category.php 项目: r007/PMoodle
/// Editing functions
if ($creatorediting) {
    /// Move a specified course to a new category
    if (!empty($deletecourses) and $data = data_submitted() and confirm_sesskey()) {
        // Some courses are being moved
        // user must have category update in both cats to perform this
        require_capability('moodle/category:update', $context);
        //require_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $moveto));
        $courses = array();
        foreach ($data as $key => $value) {
            if (preg_match('/^c\\d+$/', $key)) {
                $course = get_record("course", "id", substr($key, 1));
                if (!empty($course)) {
                    delete_course($course->id, false);
                    // MDL-9983
                    events_trigger('course_deleted', $course);
                }
            }
        }
        fix_course_sortorder();
        //update course count in catagories
    }
    if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) {
        // Some courses are being moved
        // user must have category update in both cats to perform this
        require_capability('moodle/category:update', $context);
        require_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $moveto));
        if (!($destcategory = get_record("course_categories", "id", $data->moveto))) {
            error("Error finding the category");
        }
        $courses = array();
示例#29
0
/**
 * Removes multiple role assignments, parameters may contain:
 *   'roleid', 'userid', 'contextid', 'component', 'enrolid'.
 *
 * @param array $params role assignment parameters
 * @param bool $subcontexts unassign in subcontexts too
 * @param bool $includemanual include manual role assignments too
 * @return void
 */
function role_unassign_all(array $params, $subcontexts = false, $includemanual = false)
{
    global $USER, $CFG, $DB;
    if (!$params) {
        throw new coding_exception('Missing parameters in role_unsassign_all() call');
    }
    $allowed = array('roleid', 'userid', 'contextid', 'component', 'itemid');
    foreach ($params as $key => $value) {
        if (!in_array($key, $allowed)) {
            throw new coding_exception('Unknown role_unsassign_all() parameter key', 'key:' . $key);
        }
    }
    if (isset($params['component']) and $params['component'] !== '' and strpos($params['component'], '_') === false) {
        throw new coding_exception('Invalid component paramter in role_unsassign_all() call', 'component:' . $params['component']);
    }
    if ($includemanual) {
        if (!isset($params['component']) or $params['component'] === '') {
            throw new coding_exception('include manual parameter requires component parameter in role_unsassign_all() call');
        }
    }
    if ($subcontexts) {
        if (empty($params['contextid'])) {
            throw new coding_exception('subcontexts paramtere requires component parameter in role_unsassign_all() call');
        }
    }
    $ras = $DB->get_records('role_assignments', $params);
    foreach ($ras as $ra) {
        $DB->delete_records('role_assignments', array('id' => $ra->id));
        if ($context = context::instance_by_id($ra->contextid, IGNORE_MISSING)) {
            // this is a bit expensive but necessary
            $context->mark_dirty();
            /// If the user is the current user, then do full reload of capabilities too.
            if (!empty($USER->id) && $USER->id == $ra->userid) {
                reload_all_capabilities();
            }
        }
        events_trigger('role_unassigned', $ra);
    }
    unset($ras);
    // process subcontexts
    if ($subcontexts and $context = context::instance_by_id($params['contextid'], IGNORE_MISSING)) {
        if ($params['contextid'] instanceof context) {
            $context = $params['contextid'];
        } else {
            $context = context::instance_by_id($params['contextid'], IGNORE_MISSING);
        }
        if ($context) {
            $contexts = $context->get_child_contexts();
            $mparams = $params;
            foreach ($contexts as $context) {
                $mparams['contextid'] = $context->id;
                $ras = $DB->get_records('role_assignments', $mparams);
                foreach ($ras as $ra) {
                    $DB->delete_records('role_assignments', array('id' => $ra->id));
                    // this is a bit expensive but necessary
                    $context->mark_dirty();
                    /// If the user is the current user, then do full reload of capabilities too.
                    if (!empty($USER->id) && $USER->id == $ra->userid) {
                        reload_all_capabilities();
                    }
                    events_trigger('role_unassigned', $ra);
                }
            }
        }
    }
    // do this once more for all manual role assignments
    if ($includemanual) {
        $params['component'] = '';
        role_unassign_all($params, $subcontexts, false);
    }
}
示例#30
0
} elseif ($preferences['newemailattemptsleft'] < 1) {
    cancel_email_update($user->id);
    $stroutofattempts = get_string('auth_outofnewemailupdateattempts', 'auth_email');
    echo $OUTPUT->box($stroutofattempts, 'center');
} elseif ($key == $preferences['newemailkey']) {
    $olduser = clone $user;
    cancel_email_update($user->id);
    $user->email = $preferences['newemail'];
    // Detect duplicate before saving
    if ($DB->get_record('user', array('email' => $user->email))) {
        $stremailnowexists = get_string('auth_emailnowexists', 'auth_email');
        echo $OUTPUT->box($stremailnowexists, 'center');
        echo $OUTPUT->continue_button("{$CFG->wwwroot}/user/view.php?id={$user->id}");
    } else {
        // update user email
        $DB->set_field('user', 'email', $user->email, array('id' => $user->id));
        $authplugin = get_auth_plugin($user->auth);
        $authplugin->user_update($olduser, $user);
        events_trigger('user_updated', $user);
        $a->email = $user->email;
        $stremailupdatesuccess = get_string('auth_emailupdatesuccess', 'auth_email', $a);
        echo $OUTPUT->box($stremailupdatesuccess, 'center');
        echo $OUTPUT->continue_button("{$CFG->wwwroot}/user/view.php?id={$user->id}");
    }
} else {
    $preferences['newemailattemptsleft']--;
    set_user_preference('newemailattemptsleft', $preferences['newemailattemptsleft'], $user->id);
    $strinvalidkey = get_string('auth_invalidnewemailkey', 'auth_email');
    echo $OUTPUT->box($strinvalidkey, 'center');
}
echo $OUTPUT->footer();