예제 #1
0
 /**
  *
  * @return mixed
  */
 public function logout() {
     set_user_preference($this->setting, '');
     set_user_preference($this->setting.'_nsid', '');
     $this->token = '';
     $this->nsid  = '';
     return $this->print_login();
 }
예제 #2
0
 public function __create($bookmarkurl, $title, $tokenval)
 {
     global $CFG, $DB;
     $response = new CliniqueServiceResponce();
     $token_val = array('token' => $tokenval);
     $userId = array_values($DB->get_records_sql('SELECT userid FROM {external_tokens} et WHERE et.token=?', $token_val));
     if ($userId) {
         $user_id = array('id' => $userId[0]->userid);
         //if(confirm_sesskey()){
         $user = array_values($DB->get_records_sql('SELECT * FROM {user} u WHERE u.id=?', $user_id));
         Favorites::__fav_user_login($user['0']);
         if (get_user_preferences('user_bookmarks')) {
             $bookmarks = explode(',', get_user_preferences('user_bookmarks'));
             if (in_array($bookmarkurl . ";" . $title, $bookmarks)) {
                 $response->response(true, 'You have already bookmarked');
                 die;
             }
         } else {
             $bookmarks = array();
         }
         //adds the bookmark at end of array
         $bookmarks[] = $bookmarkurl . ";" . $title;
         $bookmarks = implode(',', $bookmarks);
         //adds to preferences table
         set_user_preference('user_bookmarks', $bookmarks);
         global $CFG;
         //header("Location: " . $CFG->wwwroot . "/");
         //print "Added Favourite Successfully";
         $response->response(false, 'Added Favourite Successfully');
         die;
     } else {
         $response->response(false, 'Invalid user');
         die;
     }
 }
예제 #3
0
/**
 * Checks to see if user has visited blogpages before, if not, install 2
 * default blocks (blog_menu and blog_tags).
 */
function blog_check_and_install_blocks()
{
    global $USER, $DB;
    if (isloggedin() && !isguest()) {
        // if this user has not visited this page before
        if (!get_user_preferences('blogpagesize')) {
            // find the correct ids for blog_menu and blog_from blocks
            $menublock = $DB->get_record('block', array('name' => 'blog_menu'));
            $tagsblock = $DB->get_record('block', array('name' => 'blog_tags'));
            // add those 2 into block_instance page
            // Commmented out since the block changes broke it. Hopefully nico will fix it ;-)
            //                // add blog_menu block
            //                $newblock = new object();
            //                $newblock->blockid  = $menublock->id;
            //                $newblock->pageid   = $USER->id;
            //                $newblock->pagetype = 'blog-view';
            //                $newblock->position = 'r';
            //                $newblock->weight   = 0;
            //                $newblock->visible  = 1;
            //                $DB->insert_record('block_instances', $newblock);
            //
            //                // add blog_tags menu
            //                $newblock -> blockid = $tagsblock->id;
            //                $newblock -> weight  = 1;
            //                $DB->insert_record('block_instances', $newblock);
            // finally we set the page size pref
            set_user_preference('blogpagesize', 10);
        }
    }
}
예제 #4
0
 public function update_user_preferences()
 {
     parent::update_user_preferences();
     set_user_preference('quiz_report_responses_qtext', $this->showqtext);
     set_user_preference('quiz_report_responses_resp', $this->showresponses);
     set_user_preference('quiz_report_responses_right', $this->showright);
 }
 /**
  * Test are_notification_preferences_configured
  */
 public function test_are_notification_preferences_configured()
 {
     $this->resetAfterTest(true);
     $user1 = self::getDataGenerator()->create_user();
     $user2 = self::getDataGenerator()->create_user();
     $user3 = self::getDataGenerator()->create_user();
     self::setUser($user1);
     set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user1);
     set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'airnotifier', $user1);
     set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user2);
     set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user3);
     $params = array($user1->id, $user2->id, $user3->id);
     $preferences = message_airnotifier_external::are_notification_preferences_configured($params);
     $expected = array(array('userid' => $user1->id, 'configured' => 1));
     $this->assertEquals(1, count($preferences['users']));
     $this->assertEquals($expected, $preferences['users']);
     $this->assertEquals(2, count($preferences['warnings']));
     // Now, remove one user.
     delete_user($user2);
     $preferences = message_airnotifier_external::are_notification_preferences_configured($params);
     $this->assertEquals(1, count($preferences['users']));
     $this->assertEquals($expected, $preferences['users']);
     $this->assertEquals(2, count($preferences['warnings']));
     // Now, remove one user1 preference (the user still has one prefernce for airnotifier).
     unset_user_preference('message_provider_moodle_instantmessage_loggedin', $user1);
     $preferences = message_airnotifier_external::are_notification_preferences_configured($params);
     $this->assertEquals($expected, $preferences['users']);
     // Delete the last user1 preference.
     unset_user_preference('message_provider_moodle_instantmessage_loggedoff', $user1);
     $preferences = message_airnotifier_external::are_notification_preferences_configured($params);
     $expected = array(array('userid' => $user1->id, 'configured' => 0));
     $this->assertEquals($expected, $preferences['users']);
 }
예제 #6
0
파일: lib.php 프로젝트: nadavkav/MoodleTAO
/**
 * Checks to see if user has visited blogpages before, if not, install 2
 * default blocks (blog_menu and blog_tags).
 */
function blog_check_and_install_blocks()
{
    global $USER;
    if (isloggedin() && !isguest()) {
        // if this user has not visited this page before
        if (!get_user_preferences('blogpagesize')) {
            // find the correct ids for blog_menu and blog_from blocks
            $menublock = get_record('block', 'name', 'blog_menu');
            $tagsblock = get_record('block', 'name', 'blog_tags');
            // add those 2 into block_instance page
            // add blog_menu block
            $newblock = new object();
            $newblock->blockid = $menublock->id;
            $newblock->pageid = $USER->id;
            $newblock->pagetype = 'blog-view';
            $newblock->position = 'r';
            $newblock->weight = 0;
            $newblock->visible = 1;
            insert_record('block_instance', $newblock);
            // add blog_tags menu
            $newblock->blockid = $tagsblock->id;
            $newblock->weight = 1;
            insert_record('block_instance', $newblock);
            // finally we set the page size pref
            set_user_preference('blogpagesize', 10);
        }
    }
}
예제 #7
0
 public function update_user_preferences()
 {
     parent::update_user_preferences();
     if (quiz_has_grades($this->quiz)) {
         set_user_preference('quiz_overview_slotmarks', $this->slotmarks);
     }
 }
예제 #8
0
function keats_check_fontswitch()
{
    $changefont = optional_param('keatsfont', null, PARAM_ALPHA);
    if (in_array($changefont, array('fontSmall', 'fontBig'))) {
        return set_user_preference('theme_keats_chosen_font', $changefont);
    }
    return false;
}
예제 #9
0
 /**
  * Updates the user's password.
  *
  * Called when the user password is updated.
  *
  * @param  object  $user        User table object
  * @param  string  $newpassword Plaintext password
  * @return boolean result
  */
 function user_update_password($user, $newpassword)
 {
     $user = get_complete_user_data('id', $user->id);
     set_user_preference('auth_manual_passwordupdatetime', time(), $user->id);
     // This will also update the stored hash to the latest algorithm
     // if the existing hash is using an out-of-date algorithm (or the
     // legacy md5 algorithm).
     return update_internal_user_password($user, $newpassword);
 }
예제 #10
0
파일: editlib.php 프로젝트: JP-Git/moodle
function useredit_update_user_preference($usernew) {
    $ua = (array)$usernew;
    foreach($ua as $key=>$value) {
        if (strpos($key, 'preference_') === 0) {
            $name = substr($key, strlen('preference_'));
            set_user_preference($name, $value, $usernew->id);
        }
    }
}
예제 #11
0
파일: locallib.php 프로젝트: evltuma/moodle
/**
 * Sets user course sorting preference in course_overview block
 *
 * @param array $sortorder list of course ids
 */
function block_course_overview_update_myorder($sortorder)
{
    $value = implode(',', $sortorder);
    if (core_text::strlen($value) > 1333) {
        // The value won't fit into the user preference. Remove courses in the end of the list (mostly likely user won't even notice).
        $value = preg_replace('/,[\\d]*$/', '', core_text::substr($value, 0, 1334));
    }
    set_user_preference('course_overview_course_sortorder', $value);
}
예제 #12
0
파일: lib.php 프로젝트: evltuma/moodle
 /**
  * Returns maximum height for images
  *
  * Takes the maximum height for images eithre from search form or from
  * user preferences, updates user preferences if needed
  *
  * @return int
  */
 public function get_maxheight()
 {
     $param = optional_param('wikimedia_maxheight', 0, PARAM_INT);
     $pref = get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH);
     if ($param > 0 && $param != $pref) {
         $pref = $param;
         set_user_preference('repository_wikimedia_maxheight', $pref);
     }
     return $pref;
 }
예제 #13
0
파일: lib.php 프로젝트: njorth/marginalia
 public static function get_userid()
 {
     global $USER;
     // Get the users whose annotations are to be shown
     $annotationuser = get_user_preferences(AN_USER_PREF, null);
     if (null == $annotationuser) {
         $annotationuser = isguest() ? null : $USER->username;
         set_user_preference(AN_USER_PREF, $annotationuser);
     }
     return $annotationuser;
 }
 /**
  * Checks if username is set
  * 
  * @return boolean
  */
 public function check_login()
 {
     $username = get_user_preferences(self::USERNAME, '');
     if (empty($username)) {
         $username = optional_param('bitbucket_username', '', PARAM_ALPHANUM);
     }
     if ($username) {
         set_user_preference(self::USERNAME, $username);
         $this->client = new bitbucket($username);
         return true;
     }
     return false;
 }
예제 #15
0
 /**
  * Test load_users method.
  */
 public function test_load_users()
 {
     global $DB;
     $this->setAdminUser();
     $this->resetAfterTest(true);
     $roleteacher = $DB->get_record('role', array('shortname' => 'teacher'), '*', MUST_EXIST);
     // Create a course, users and groups.
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     $group = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
     $teacher = $this->getDataGenerator()->create_user();
     $user1 = $this->getDataGenerator()->create_user();
     $user2 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $roleteacher->id);
     $this->getDataGenerator()->enrol_user($user1->id, $course->id);
     $this->getDataGenerator()->enrol_user($user2->id, $course->id);
     $this->getDataGenerator()->create_group_member(array('groupid' => $group->id, 'userid' => $teacher->id));
     $this->getDataGenerator()->create_group_member(array('groupid' => $group->id, 'userid' => $user1->id));
     $this->getDataGenerator()->create_group_member(array('groupid' => $group->id, 'userid' => $user2->id));
     // Perform a regrade before creating the report.
     grade_regrade_final_grades($course->id);
     $screentest = new gradereport_singleview_screen_testable($course->id, 0, $group->id);
     $groupusers = $screentest->test_load_users();
     $this->assertCount(2, $groupusers);
     // Now, let's suspend the enrolment of a user. Should return only one user.
     $this->getDataGenerator()->enrol_user($user2->id, $course->id, $roleteacher->id, 'manual', 0, 0, ENROL_USER_SUSPENDED);
     $users = $screentest->test_load_users();
     $this->assertCount(1, $users);
     // Change the viewsuspendedusers capabilities and set the user preference to display suspended users.
     assign_capability('moodle/course:viewsuspendedusers', CAP_ALLOW, $roleteacher->id, $coursecontext, true);
     set_user_preference('grade_report_showonlyactiveenrol', false, $teacher);
     accesslib_clear_all_caches_for_unit_testing();
     $this->setUser($teacher);
     $screentest = new gradereport_singleview_screen_testable($course->id, 0, $group->id);
     $users = $screentest->test_load_users();
     $this->assertCount(2, $users);
     // Change the capability again, now the user can't see the suspended enrolments.
     assign_capability('moodle/course:viewsuspendedusers', CAP_PROHIBIT, $roleteacher->id, $coursecontext, true);
     set_user_preference('grade_report_showonlyactiveenrol', false, $teacher);
     accesslib_clear_all_caches_for_unit_testing();
     $users = $screentest->test_load_users();
     $this->assertCount(1, $users);
     // Now, activate the user enrolment again. We shall get 2 users now.
     $this->getDataGenerator()->enrol_user($user2->id, $course->id, $roleteacher->id, 'manual', 0, 0, ENROL_USER_ACTIVE);
     $users = $screentest->test_load_users();
     $this->assertCount(2, $users);
 }
예제 #16
0
파일: auth.php 프로젝트: JP-Git/moodle
 /**
  * Returns true if the username and password work and false if they are
  * wrong or don't exist. (Non-mnet accounts only!)
  *
  * @param string $username The username
  * @param string $password The password
  * @return bool Authentication success or failure.
  */
 function user_login($username, $password)
 {
     global $CFG, $DB, $USER;
     if (!($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id)))) {
         return false;
     }
     if (!validate_internal_user_password($user, $password)) {
         return false;
     }
     if ($password === 'changeme') {
         // force the change - this is deprecated and it makes sense only for manual auth,
         // because most other plugins can not change password easily or
         // passwords are always specified by users
         set_user_preference('auth_forcepasswordchange', true, $user->id);
     }
     return true;
 }
예제 #17
0
 public function __remove($bookmarkurl, $title, $tokenval)
 {
     global $CFG, $DB;
     $bookmarkurl = htmlspecialchars_decode($bookmarkurl);
     $title = htmlspecialchars_decode($title);
     $response = new CliniqueServiceResponce();
     $token_val = array('token' => $tokenval);
     // Get user token
     /**
      * @get user id from external_tokens table
      *
      */
     $userId = array_values($DB->get_records_sql('SELECT userid FROM {external_tokens} et WHERE et.token=?', $token_val));
     if ($userId) {
         $user_id = array('id' => $userId[0]->userid);
         //if(confirm_sesskey()){
         $user = array_values($DB->get_records_sql('SELECT * FROM {user} u WHERE u.id=?', $user_id));
         Favorites::__fav_user_login($user['0']);
         $bookmarks = explode(',', get_user_preferences('user_bookmarks'));
         $bookmarkremoved = false;
         foreach ($bookmarks as $bookmark) {
             // check the bookmarkurl and title given values to delete from preference
             $tempBookmark = explode(';', $bookmark);
             if ($tempBookmark[0] == $bookmarkurl && $tempBookmark[1] == $title) {
                 $keyToRemove = array_search($bookmark, $bookmarks);
                 unset($bookmarks[$keyToRemove]);
                 $bookmarkremoved = true;
             }
         }
         if ($bookmarkremoved == false) {
             $response->response(true, 'The bookmark you requested does not exist');
             die;
         }
         $bookmarks = implode(',', $bookmarks);
         set_user_preference('user_bookmarks', $bookmarks);
         global $CFG;
         //header("Location: " . $CFG->wwwroot . $bookmarkurl);
         $response->response(false, 'Removed Favorite Successfully');
         die;
     } else {
         $response->response(true, 'Invalid user');
         die;
     }
 }
예제 #18
0
 /**
  * Tests the installation of event handlers from file
  */
 public function test_get_preferred_editor()
 {
     // Fake a user agent.
     $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.21     5 Safari/534.10';
     $enabled = editors_get_enabled();
     // Array assignment is always a clone.
     $editors = $enabled;
     $first = array_shift($enabled);
     // Get the default editor which should be the first in the list.
     set_user_preference('htmleditor', '');
     $preferred = editors_get_preferred_editor();
     $this->assertEquals($first, $preferred);
     foreach ($editors as $key => $editor) {
         // User has set a preference for a specific editor.
         set_user_preference('htmleditor', $key);
         $preferred = editors_get_preferred_editor();
         $this->assertEquals($editor, $preferred);
     }
 }
예제 #19
0
/**
 * @param int $oldversion the version we are upgrading from
 * @return bool result
 */
function xmldb_auth_manual_upgrade($oldversion)
{
    global $CFG, $DB, $OUTPUT;
    if ($oldversion < 2011022700) {
        // force creation of missing passwords
        $createpassword = hash_internal_user_password('');
        $rs = $DB->get_recordset('user', array('password' => $createpassword, 'auth' => 'manual'));
        foreach ($rs as $user) {
            if (validate_email($user->email)) {
                $DB->set_field('user', 'password', 'to be created', array('id' => $user->id));
                unset_user_preference('auth_forcepasswordchange', $user);
                set_user_preference('create_password', 1, $user);
            }
        }
        $rs->close();
        upgrade_plugin_savepoint(true, 2011022700, 'auth', 'manual');
    }
    return true;
}
 public function __sendPassword($email)
 {
     global $CFG, $DB;
     $systemcontext = context_system::instance();
     $response = new CliniqueServiceResponce();
     if (!empty($email) || !$email) {
         $select = $DB->sql_like('email', ':email', false, true, false, '|') . " AND mnethostid = :mnethostid AND deleted=0 AND suspended=0";
         $params = array('email' => $DB->sql_like_escape($email, '|'), 'mnethostid' => $CFG->mnet_localhost_id);
         $user = $DB->get_record_select('user', $select, $params, '*', IGNORE_MULTIPLE);
         if ($user and ($user->auth === 'nologin' or !is_enabled_auth($user->auth))) {
             // bad luck - user is not able to login, do not let them reset password
             $user = false;
             $response->response(true, 'fp_nologin');
             die;
         }
         if (!empty($user)) {
             if (is_mnet_remote_user($user)) {
                 add_to_log(-1, 'custom_webservice', 'mnet_user', null, 'Forgot password - mnet user trying to access.', 0, $user->id);
                 $response->response(true, 'cp_mnet_user');
                 die;
             }
             if (isguestuser($user)) {
                 add_to_log(-1, 'custom_webservice', 'guest_user', null, 'Forgot password - guest user credential supplied.', 0, $user->id);
                 $response->response(true, 'fp_guest');
                 die;
             }
             // make sure user is allowed to change password
             require_capability('moodle/user:changeownpassword', $systemcontext, $user->id);
             if (!ForgotPassword::__app_reset_password_and_mail($user)) {
                 add_to_log(-1, 'custom_webservice', 'trigger_mail', null, 'Forgot password - email triggering failure.', 0, $user->id);
                 $response->response(true, 'fp_email_failure');
             } else {
                 set_user_preference('auth_forcepasswordchange', true, $user->id);
                 $response->response(true, 'fp_email_success');
             }
         } else {
             $response->response(false, 'fp_no_record');
         }
     } else {
         add_to_log(-1, 'custom_webservice', 'input_parameters', null, 'Forgot password - input parameters missing.', 0, $user->id);
     }
 }
예제 #21
0
 /**
  * Manage calendar syncing.
  */
 public function mode_onenote()
 {
     global $OUTPUT;
     $mform = new \local_o365\form\onenote('?action=onenote');
     if ($mform->is_cancelled()) {
         redirect(new \moodle_url('/local/o365/ucp.php'));
     } else {
         if ($fromform = $mform->get_data()) {
             $disableo365onenote = !empty($fromform->disableo365onenote) ? 1 : 0;
             set_user_preference('local_o365_disableo365onenote', $disableo365onenote);
             redirect(new \moodle_url('/local/o365/ucp.php'));
         } else {
             $defaultdata = ['disableo365onenote' => get_user_preferences('local_o365_disableo365onenote', 0)];
             $mform->set_data($defaultdata);
             echo $OUTPUT->header();
             $mform->display();
             echo $OUTPUT->footer();
         }
     }
 }
 /**
  * Block initialization
  */
 public function init()
 {
     $this->title = get_string('pluginname', 'block_course_overview_lite');
     // Transition old user hidden course preferences.
     if (is_null(get_user_preferences('block_course_overview_lite_courses_hidden')) && !is_null($userpref = get_user_preferences('eclass_course_overview_courses_hidden'))) {
         $hiddencourses = unserialize($userpref);
         block_course_overview_lite_update_courses_hidden($hiddencourses);
     } else {
         if (is_null(get_user_preferences('block_course_overview_lite_courses_hidden')) && !is_null($userpref = get_user_preferences('course_overview_lite_courses_hidden'))) {
             block_course_overview_lite_update_courses_hidden(unserialize($userpref));
         }
     }
     // Transition old user course order preference.
     if (is_null(get_user_preferences('block_course_overview_lite_course_order')) && !is_null($userpref = get_user_preferences('course_overview_lite_course_order'))) {
         set_user_preference('block_course_overview_lite_course_order', json_encode(unserialize($userpref)));
     }
     // Transition old user course order preference.
     if (is_null(get_user_preferences('block_course_overview_lite_number_of_courses')) && !is_null($userpref = get_user_preferences('course_overview_lite_number_of_courses'))) {
         set_user_preference('block_course_overview_lite_number_of_courses', $userpref);
     }
 }
 /**
  * Do the job.
  * Throw exceptions on errors (the job will be retried).
  */
 public function execute()
 {
     global $DB;
     // Generate new password emails for users - ppl expect these generated asap.
     if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
         mtrace('Creating passwords for new users...');
         $usernamefields = get_all_user_name_fields(true, 'u');
         $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.auth, u.deleted,\n                                                     u.suspended, u.emailstop, u.mnethostid, u.mailformat,\n                                                     {$usernamefields}, u.username, u.lang,\n                                                     p.id as prefid\n                                                FROM {user} u\n                                                JOIN {user_preferences} p ON u.id=p.userid\n                                               WHERE p.name='create_password' AND p.value='1' AND\n                                                     u.email !='' AND u.suspended = 0 AND\n                                                     u.auth != 'nologin' AND u.deleted = 0");
         // Note: we can not send emails to suspended accounts.
         foreach ($newusers as $newuser) {
             // Use a low cost factor when generating bcrypt hash otherwise
             // hashing would be slow when emailing lots of users. Hashes
             // will be automatically updated to a higher cost factor the first
             // time the user logs in.
             if (setnew_password_and_mail($newuser, true)) {
                 unset_user_preference('create_password', $newuser);
                 set_user_preference('auth_forcepasswordchange', 1, $newuser);
             } else {
                 trigger_error("Could not create and mail new user password!");
             }
         }
         $newusers->close();
     }
 }
예제 #24
0
파일: report.php 프로젝트: hatone/moodle
 public function display($quiz, $cm, $course)
 {
     global $CFG, $COURSE, $DB, $OUTPUT;
     $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
     $download = optional_param('download', '', PARAM_ALPHA);
     list($currentgroup, $students, $groupstudents, $allowed) = $this->load_relevant_students($cm);
     $pageoptions = array();
     $pageoptions['id'] = $cm->id;
     $pageoptions['mode'] = 'overview';
     $reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions);
     $qmsubselect = quiz_report_qm_filter_select($quiz);
     $mform = new mod_quiz_report_overview_settings($reporturl, array('qmsubselect' => $qmsubselect, 'quiz' => $quiz, 'currentgroup' => $currentgroup, 'context' => $this->context));
     if ($fromform = $mform->get_data()) {
         $regradeall = false;
         $regradealldry = false;
         $regradealldrydo = false;
         $attemptsmode = $fromform->attemptsmode;
         if ($qmsubselect) {
             $qmfilter = $fromform->qmfilter;
         } else {
             $qmfilter = 0;
         }
         $regradefilter = !empty($fromform->regradefilter);
         set_user_preference('quiz_report_overview_detailedmarks', $fromform->detailedmarks);
         set_user_preference('quiz_report_pagesize', $fromform->pagesize);
         $detailedmarks = $fromform->detailedmarks;
         $pagesize = $fromform->pagesize;
     } else {
         $regradeall = optional_param('regradeall', 0, PARAM_BOOL);
         $regradealldry = optional_param('regradealldry', 0, PARAM_BOOL);
         $regradealldrydo = optional_param('regradealldrydo', 0, PARAM_BOOL);
         $attemptsmode = optional_param('attemptsmode', null, PARAM_INT);
         if ($qmsubselect) {
             $qmfilter = optional_param('qmfilter', 0, PARAM_INT);
         } else {
             $qmfilter = 0;
         }
         $regradefilter = optional_param('regradefilter', 0, PARAM_INT);
         $detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1);
         $pagesize = get_user_preferences('quiz_report_pagesize', 0);
     }
     $this->validate_common_options($attemptsmode, $pagesize, $course, $currentgroup);
     $displayoptions = array();
     $displayoptions['attemptsmode'] = $attemptsmode;
     $displayoptions['qmfilter'] = $qmfilter;
     $displayoptions['regradefilter'] = $regradefilter;
     $mform->set_data($displayoptions + array('detailedmarks' => $detailedmarks, 'pagesize' => $pagesize));
     if (!$this->should_show_grades($quiz)) {
         $detailedmarks = 0;
     }
     // We only want to show the checkbox to delete attempts
     // if the user has permissions and if the report mode is showing attempts.
     $candelete = has_capability('mod/quiz:deleteattempts', $this->context) && $attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO;
     if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
         // This option is only available to users who can access all groups in
         // groups mode, so setting allowed to empty (which means all quiz attempts
         // are accessible, is not a security porblem.
         $allowed = array();
     }
     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
     $courseshortname = format_string($course->shortname, true, array('context' => $coursecontext));
     $displaycoursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     $displaycourseshortname = format_string($COURSE->shortname, true, array('context' => $displaycoursecontext));
     // Load the required questions.
     $questions = quiz_report_get_significant_questions($quiz);
     $table = new quiz_report_overview_table($quiz, $this->context, $qmsubselect, $groupstudents, $students, $detailedmarks, $questions, $candelete, $reporturl, $displayoptions);
     $filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'), $courseshortname, $quiz->name);
     $table->is_downloading($download, $filename, $displaycourseshortname . ' ' . format_string($quiz->name, true));
     if ($table->is_downloading()) {
         raise_memory_limit(MEMORY_EXTRA);
     }
     // Process actions.
     if (empty($currentgroup) || $groupstudents) {
         if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
             if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
                 require_capability('mod/quiz:deleteattempts', $this->context);
                 $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
                 redirect($reporturl->out(false, $displayoptions));
             }
         } else {
             if (optional_param('regrade', 0, PARAM_BOOL) && confirm_sesskey()) {
                 if ($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
                     require_capability('mod/quiz:regrade', $this->context);
                     $this->regrade_attempts($quiz, false, $groupstudents, $attemptids);
                     redirect($reporturl->out(false, $displayoptions));
                 }
             }
         }
     }
     if ($regradeall && confirm_sesskey()) {
         require_capability('mod/quiz:regrade', $this->context);
         $this->regrade_attempts($quiz, false, $groupstudents);
         redirect($reporturl->out(false, $displayoptions), '', 5);
     } else {
         if ($regradealldry && confirm_sesskey()) {
             require_capability('mod/quiz:regrade', $this->context);
             $this->regrade_attempts($quiz, true, $groupstudents);
             redirect($reporturl->out(false, $displayoptions), '', 5);
         } else {
             if ($regradealldrydo && confirm_sesskey()) {
                 require_capability('mod/quiz:regrade', $this->context);
                 $this->regrade_attempts_needing_it($quiz, $groupstudents);
                 redirect($reporturl->out(false, $displayoptions), '', 5);
             }
         }
     }
     // Start output.
     if (!$table->is_downloading()) {
         // Only print headers if not asked to download data
         $this->print_header_and_tabs($cm, $course, $quiz, 'overview');
     }
     if ($groupmode = groups_get_activity_groupmode($cm)) {
         // Groups are being used
         if (!$table->is_downloading()) {
             groups_print_activity_menu($cm, $reporturl->out(true, $displayoptions));
         }
     }
     // Print information on the number of existing attempts
     if (!$table->is_downloading()) {
         //do not print notices when downloading
         if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
             echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
         }
     }
     $hasquestions = quiz_questions_in_quiz($quiz->questions);
     if (!$table->is_downloading()) {
         if (!$hasquestions) {
             echo quiz_no_questions_message($quiz, $cm, $this->context);
         } else {
             if (!$students) {
                 echo $OUTPUT->notification(get_string('nostudentsyet'));
             } else {
                 if ($currentgroup && !$groupstudents) {
                     echo $OUTPUT->notification(get_string('nostudentsingroup'));
                 }
             }
         }
         // Print display options
         $mform->display();
     }
     $hasstudents = $students && (!$currentgroup || $groupstudents);
     if ($hasquestions && ($hasstudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) {
         // Construct the SQL
         $fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid, ';
         if ($qmsubselect) {
             $fields .= "(CASE " . "   WHEN {$qmsubselect} THEN 1" . "   ELSE 0 " . "END) AS gradedattempt, ";
         }
         list($fields, $from, $where, $params) = $this->base_sql($quiz, $qmsubselect, $qmfilter, $attemptsmode, $allowed);
         $table->set_count_sql("SELECT COUNT(1) FROM {$from} WHERE {$where}", $params);
         // Test to see if there are any regraded attempts to be listed.
         $fields .= ", COALESCE((\n                                SELECT MAX(qqr.regraded)\n                                  FROM {quiz_overview_regrades} qqr\n                                 WHERE qqr.questionusageid = quiza.uniqueid\n                          ), -1) AS regraded";
         if ($regradefilter) {
             $where .= " AND COALESCE((\n                                    SELECT MAX(qqr.regraded)\n                                      FROM {quiz_overview_regrades} qqr\n                                     WHERE qqr.questionusageid = quiza.uniqueid\n                                ), -1) <> -1";
         }
         $table->set_sql($fields, $from, $where, $params);
         if (!$table->is_downloading()) {
             // Regrade buttons
             if (has_capability('mod/quiz:regrade', $this->context)) {
                 $regradesneeded = $this->count_question_attempts_needing_regrade($quiz, $groupstudents);
                 if ($currentgroup) {
                     $a = new stdClass();
                     $a->groupname = groups_get_group_name($currentgroup);
                     $a->coursestudents = get_string('participants');
                     $a->countregradeneeded = $regradesneeded;
                     $regradealldrydolabel = get_string('regradealldrydogroup', 'quiz_overview', $a);
                     $regradealldrylabel = get_string('regradealldrygroup', 'quiz_overview', $a);
                     $regradealllabel = get_string('regradeallgroup', 'quiz_overview', $a);
                 } else {
                     $regradealldrydolabel = get_string('regradealldrydo', 'quiz_overview', $regradesneeded);
                     $regradealldrylabel = get_string('regradealldry', 'quiz_overview');
                     $regradealllabel = get_string('regradeall', 'quiz_overview');
                 }
                 $displayurl = new moodle_url($reporturl, $displayoptions + array('sesskey' => sesskey()));
                 echo '<div class="mdl-align">';
                 echo '<form action="' . $displayurl->out_omit_querystring() . '">';
                 echo '<div>';
                 echo html_writer::input_hidden_params($displayurl);
                 echo '<input type="submit" name="regradeall" value="' . $regradealllabel . '"/>';
                 echo '<input type="submit" name="regradealldry" value="' . $regradealldrylabel . '"/>';
                 if ($regradesneeded) {
                     echo '<input type="submit" name="regradealldrydo" value="' . $regradealldrydolabel . '"/>';
                 }
                 echo '</div>';
                 echo '</form>';
                 echo '</div>';
             }
             // Print information on the grading method
             if ($strattempthighlight = quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)) {
                 echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
             }
         }
         // Define table columns
         $columns = array();
         $headers = array();
         if (!$table->is_downloading() && $candelete) {
             $columns[] = 'checkbox';
             $headers[] = null;
         }
         $this->add_user_columns($table, $columns, $headers);
         $this->add_time_columns($columns, $headers);
         if ($detailedmarks) {
             foreach ($questions as $slot => $question) {
                 // Ignore questions of zero length
                 $columns[] = 'qsgrade' . $slot;
                 $header = get_string('qbrief', 'quiz', $question->number);
                 if (!$table->is_downloading()) {
                     $header .= '<br />';
                 } else {
                     $header .= ' ';
                 }
                 $header .= '/' . quiz_rescale_grade($question->maxmark, $quiz, 'question');
                 $headers[] = $header;
             }
         }
         if (!$table->is_downloading() && has_capability('mod/quiz:regrade', $this->context) && $this->has_regraded_questions($from, $where, $params)) {
             $columns[] = 'regraded';
             $headers[] = get_string('regrade', 'quiz_overview');
         }
         $this->add_grade_columns($quiz, $columns, $headers);
         $this->set_up_table_columns($table, $columns, $headers, $reporturl, $displayoptions, false);
         $table->set_attribute('class', 'generaltable generalbox grades');
         $table->out($pagesize, true);
     }
     if (!$table->is_downloading() && $this->should_show_grades($quiz)) {
         if ($currentgroup && $groupstudents) {
             list($usql, $params) = $DB->get_in_or_equal($groupstudents);
             $params[] = $quiz->id;
             if ($DB->record_exists_select('quiz_grades', "userid {$usql} AND quiz = ?", $params)) {
                 $imageurl = new moodle_url('/mod/quiz/report/overview/overviewgraph.php', array('id' => $quiz->id, 'groupid' => $currentgroup));
                 $graphname = get_string('overviewreportgraphgroup', 'quiz_overview', groups_get_group_name($currentgroup));
                 echo $OUTPUT->heading($graphname);
                 echo html_writer::tag('div', html_writer::empty_tag('img', array('src' => $imageurl, 'alt' => $graphname)), array('class' => 'graph'));
             }
         }
         if ($DB->record_exists('quiz_grades', array('quiz' => $quiz->id))) {
             $graphname = get_string('overviewreportgraph', 'quiz_overview');
             $imageurl = new moodle_url('/mod/quiz/report/overview/overviewgraph.php', array('id' => $quiz->id));
             echo $OUTPUT->heading($graphname);
             echo html_writer::tag('div', html_writer::empty_tag('img', array('src' => $imageurl, 'alt' => $graphname)), array('class' => 'graph'));
         }
     }
     return true;
 }
예제 #25
0
$forum->intro = trim($forum->intro);
switch ($forum->type) {
    case 'single':
        if (!($discussion = get_record("forum_discussions", "forum", $forum->id))) {
            if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
                notify("Warning! There is more than one discussion in this forum - using the most recent");
                $discussion = array_pop($discussions);
            } else {
                error("Could not find the discussion in this forum");
            }
        }
        if (!($post = forum_get_post_full($discussion->firstpost))) {
            error("Could not find the first post in this forum");
        }
        if ($mode) {
            set_user_preference("forum_displaymode", $mode);
        }
        $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
        $canrate = has_capability('mod/forum:rate', $context);
        forum_print_discussion($course, $forum, $discussion, $post, $displaymode, NULL, $canrate);
        break;
    case 'eachuser':
        if (!empty($forum->intro)) {
            print_box(format_text($forum->intro), 'generalbox', 'intro');
        }
        echo '<p align="center">';
        if (forum_user_can_post_discussion($forum)) {
            print_string("allowsdiscussions", "forum");
        } else {
            echo '&nbsp;';
        }
예제 #26
0
파일: lib.php 프로젝트: krysnuvadga/moodle
 /**
  * Logout from dropbox
  * @return array
  */
 public function logout()
 {
     set_user_preference($this->setting . '_access_key', '');
     set_user_preference($this->setting . '_access_secret', '');
     $this->access_key = '';
     $this->access_secret = '';
     return $this->print_login();
 }
예제 #27
0
 /**
  * Get an annotations preference value;  if the preference doesn't exist, create it
  * so that the Javascript client will have permission to set it later (to prevent
  * client creation of random preferences, only existing preferences can be set)
  */
 public function get_pref($name, $default)
 {
     $value = get_user_preferences($name, null);
     if (null == $value) {
         $value = $default;
         set_user_preference($name, $default);
     }
     return $value;
 }
예제 #28
0
/**
 * Lockout user and send notification email.
 *
 * @param stdClass $user
 */
function login_lock_account($user)
{
    global $CFG;
    if ($user->mnethostid != $CFG->mnet_localhost_id) {
        return;
    }
    if (isguestuser($user)) {
        return;
    }
    if (get_user_preferences('login_lockout_ignored', 0, $user)) {
        // This user can not be locked out.
        return;
    }
    $alreadylockedout = get_user_preferences('login_lockout', 0, $user);
    set_user_preference('login_lockout', time(), $user);
    if ($alreadylockedout == 0) {
        $secret = random_string(15);
        set_user_preference('login_lockout_secret', $secret, $user);
        $oldforcelang = force_current_language($user->lang);
        $site = get_site();
        $supportuser = core_user::get_support_user();
        $data = new stdClass();
        $data->firstname = $user->firstname;
        $data->lastname = $user->lastname;
        $data->username = $user->username;
        $data->sitename = format_string($site->fullname);
        $data->link = $CFG->wwwroot . '/login/unlock_account.php?u=' . $user->id . '&s=' . $secret;
        $data->admin = generate_email_signoff();
        $message = get_string('lockoutemailbody', 'admin', $data);
        $subject = get_string('lockoutemailsubject', 'admin', format_string($site->fullname));
        if ($message) {
            // Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
            email_to_user($user, $supportuser, $subject, $message);
        }
        force_current_language($oldforcelang);
    }
}
예제 #29
0
$quiz_reordertool = optional_param('reordertool', -1, PARAM_BOOL);
$quiz_qbanktool = optional_param('qbanktool', -1, PARAM_BOOL);
$scrollpos = optional_param('scrollpos', '', PARAM_INT);
list($thispageurl, $contexts, $cmid, $cm, $quiz, $pagevars) = question_edit_setup('editq', '/mod/quiz/edit.php', true);
$quiz->questions = quiz_clean_layout($quiz->questions);
$defaultcategoryobj = question_make_default_categories($contexts->all());
$defaultcategory = $defaultcategoryobj->id . ',' . $defaultcategoryobj->contextid;
if ($quiz_qbanktool > -1) {
    $thispageurl->param('qbanktool', $quiz_qbanktool);
    set_user_preference('quiz_qbanktool_open', $quiz_qbanktool);
} else {
    $quiz_qbanktool = get_user_preferences('quiz_qbanktool_open', 0);
}
if ($quiz_reordertool > -1) {
    $thispageurl->param('reordertool', $quiz_reordertool);
    set_user_preference('quiz_reordertab', $quiz_reordertool);
} else {
    $quiz_reordertool = get_user_preferences('quiz_reordertab', 0);
}
$canaddrandom = $contexts->have_cap('moodle/question:useall');
$canaddquestion = (bool) $contexts->having_add_and_use();
$quizhasattempts = quiz_has_attempts($quiz->id);
$PAGE->set_url($thispageurl);
// Get the course object and related bits.
$course = $DB->get_record('course', array('id' => $quiz->course));
if (!$course) {
    print_error('invalidcourseid', 'error');
}
$questionbank = new quiz_question_bank_view($contexts, $thispageurl, $course, $cm, $quiz);
$questionbank->set_quiz_has_attempts($quizhasattempts);
// Log this visit.
예제 #30
0
파일: view.php 프로젝트: hatone/moodle
}
$SESSION->dataprefs[$data->id]['search'] = $search;
// Make it sticky
$sort = optional_param('sort', $SESSION->dataprefs[$data->id]['sort'], PARAM_INT);
$SESSION->dataprefs[$data->id]['sort'] = $sort;
// Make it sticky
$order = optional_param('order', $SESSION->dataprefs[$data->id]['order'], PARAM_ALPHA) == 'ASC' ? 'ASC' : 'DESC';
$SESSION->dataprefs[$data->id]['order'] = $order;
// Make it sticky
$oldperpage = get_user_preferences('data_perpage_' . $data->id, 10);
$perpage = optional_param('perpage', $oldperpage, PARAM_INT);
if ($perpage < 2) {
    $perpage = 2;
}
if ($perpage != $oldperpage) {
    set_user_preference('data_perpage_' . $data->id, $perpage);
}
add_to_log($course->id, 'data', 'view', "view.php?id={$cm->id}", $data->id, $cm->id);
$urlparams = array('d' => $data->id);
if ($record) {
    $urlparams['rid'] = $record->id;
}
if ($page) {
    $urlparams['page'] = $page;
}
if ($mode) {
    $urlparams['mode'] = $mode;
}
if ($filter) {
    $urlparams['filter'] = $filter;
}