Пример #1
0
 /**
  * This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
     // Course context
     $systemcontext = get_system_context();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = get_context_instance(CONTEXT_USER, $user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = get_context_instance(CONTEXT_USER, $user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canviewusercourse && !$canviewuser || !can_access_course($course, $user->id)) {
                 return false;
             }
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS) {
                 // If groups are in use, make sure we can see that group
                 return false;
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     if ($gstitle != 'usercurrentsettings') {
         $key .= $userid;
     }
     // Add a user setting branch
     $usersetting = $this->add(get_string($gstitle, 'moodle', $fullname), null, self::TYPE_CONTAINER, null, $key);
     $usersetting->id = 'usersettings';
     if ($this->page->context->contextlevel == CONTEXT_USER && $this->page->context->instanceid == $user->id) {
         // Automatically start by making it active
         $usersetting->make_active();
     }
     // Check if the user has been deleted
     if ($user->deleted) {
         if (!has_capability('moodle/user:update', $coursecontext)) {
             // We can't edit the user so just show the user deleted message
             $usersetting->add(get_string('userdeleted'), null, self::TYPE_SETTING);
         } else {
             // We can edit the user so show the user deleted message and link it to the profile
             if ($course->id == $SITE->id) {
                 $profileurl = new moodle_url('/user/profile.php', array('id' => $user->id));
             } else {
                 $profileurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
             }
             $usersetting->add(get_string('userdeleted'), $profileurl, self::TYPE_SETTING);
         }
         return true;
     }
     $userauthplugin = false;
     if (!empty($user->auth)) {
         $userauthplugin = get_auth_plugin($user->auth);
     }
     // Add the profile edit link
     if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if (($currentuser || is_siteadmin($USER) || !is_siteadmin($user)) && has_capability('moodle/user:update', $systemcontext)) {
             $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $course->id));
             $usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
         } else {
             if (has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user) || $currentuser && has_capability('moodle/user:editownprofile', $systemcontext)) {
                 if ($userauthplugin && $userauthplugin->can_edit_profile()) {
                     $url = $userauthplugin->edit_profile_url();
                     if (empty($url)) {
                         $url = new moodle_url('/user/edit.php', array('id' => $user->id, 'course' => $course->id));
                     }
                     $usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
                 }
             }
         }
     }
     // Change password link
     if ($userauthplugin && $currentuser && !session_is_loggedinas() && !isguestuser() && has_capability('moodle/user:changeownpassword', $systemcontext) && $userauthplugin->can_change_password()) {
         $passwordchangeurl = $userauthplugin->change_password_url();
         if (empty($passwordchangeurl)) {
             $passwordchangeurl = new moodle_url('/login/change_password.php', array('id' => $course->id));
         }
         $usersetting->add(get_string("changepassword"), $passwordchangeurl, self::TYPE_SETTING);
     }
     // View the roles settings
     if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $usercontext)) {
         $roles = $usersetting->add(get_string('roles'), null, self::TYPE_SETTING);
         $url = new moodle_url('/admin/roles/usersroles.php', array('userid' => $user->id, 'courseid' => $course->id));
         $roles->add(get_string('thisusersroles', 'role'), $url, self::TYPE_SETTING);
         $assignableroles = get_assignable_roles($usercontext, ROLENAME_BOTH);
         if (!empty($assignableroles)) {
             $url = new moodle_url('/admin/roles/assign.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
             $roles->add(get_string('assignrolesrelativetothisuser', 'role'), $url, self::TYPE_SETTING);
         }
         if (has_capability('moodle/role:review', $usercontext) || count(get_overridable_roles($usercontext, ROLENAME_BOTH)) > 0) {
             $url = new moodle_url('/admin/roles/permissions.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
             $roles->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING);
         }
         $url = new moodle_url('/admin/roles/check.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
         $roles->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING);
     }
     // Portfolio
     if ($currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext)) {
         require_once $CFG->libdir . '/portfoliolib.php';
         if (portfolio_instances(true, false)) {
             $portfolio = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING);
             $url = new moodle_url('/user/portfolio.php', array('courseid' => $course->id));
             $portfolio->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING);
             $url = new moodle_url('/user/portfoliologs.php', array('courseid' => $course->id));
             $portfolio->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING);
         }
     }
     $enablemanagetokens = false;
     if (!empty($CFG->enablerssfeeds)) {
         $enablemanagetokens = true;
     } else {
         if (!is_siteadmin($USER->id) && !empty($CFG->enablewebservices) && has_capability('moodle/webservice:createtoken', get_system_context())) {
             $enablemanagetokens = true;
         }
     }
     // Security keys
     if ($currentuser && $enablemanagetokens) {
         $url = new moodle_url('/user/managetoken.php', array('sesskey' => sesskey()));
         $usersetting->add(get_string('securitykeys', 'webservice'), $url, self::TYPE_SETTING);
     }
     // Repository
     if (!$currentuser && $usercontext->contextlevel == CONTEXT_USER) {
         if (!$this->cache->cached('contexthasrepos' . $usercontext->id)) {
             require_once $CFG->dirroot . '/repository/lib.php';
             $editabletypes = repository::get_editable_types($usercontext);
             $haseditabletypes = !empty($editabletypes);
             unset($editabletypes);
             $this->cache->set('contexthasrepos' . $usercontext->id, $haseditabletypes);
         } else {
             $haseditabletypes = $this->cache->{'contexthasrepos' . $usercontext->id};
         }
         if ($haseditabletypes) {
             $url = new moodle_url('/repository/manage_instances.php', array('contextid' => $usercontext->id));
             $usersetting->add(get_string('repositories', 'repository'), $url, self::TYPE_SETTING);
         }
     }
     // Messaging
     if ($currentuser && has_capability('moodle/user:editownmessageprofile', $systemcontext) || !isguestuser($user) && has_capability('moodle/user:editmessageprofile', $usercontext) && !is_primary_admin($user->id)) {
         $url = new moodle_url('/message/edit.php', array('id' => $user->id));
         $usersetting->add(get_string('editmymessage', 'message'), $url, self::TYPE_SETTING);
     }
     // Blogs
     if ($currentuser && !empty($CFG->bloglevel)) {
         $blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs');
         $blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING);
         if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', get_context_instance(CONTEXT_SYSTEM))) {
             $blog->add(get_string('externalblogs', 'blog'), new moodle_url('/blog/external_blogs.php'), navigation_node::TYPE_SETTING);
             $blog->add(get_string('addnewexternalblog', 'blog'), new moodle_url('/blog/external_blog_edit.php'), navigation_node::TYPE_SETTING);
         }
     }
     // Login as ...
     if (!$user->deleted and !$currentuser && !session_is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) && !is_siteadmin($user->id)) {
         $url = new moodle_url('/course/loginas.php', array('id' => $course->id, 'user' => $user->id, 'sesskey' => sesskey()));
         $usersetting->add(get_string('loginas'), $url, self::TYPE_SETTING);
     }
     return $usersetting;
 }
Пример #2
0
         // Actually suspend the user.
         company_user::suspend($user->id);
     }
 } else {
     if ($unsuspend and confirm_sesskey()) {
         // Unsuspends a selected user, after confirmation.
         if (!iomad::has_capability('block/iomad_company_admin:editusers', $systemcontext)) {
             print_error('nopermissions', 'error', '', 'suspend a user');
         }
         if (!($user = $DB->get_record('user', array('id' => $unsuspend)))) {
             print_error('nousers', 'error');
         }
         if (!company::check_canedit_user($companyid, $user->id)) {
             print_error('invaliduserid');
         }
         if (is_primary_admin($user->id)) {
             print_error('nopermissions', 'error', '', 'delete the primary admin user');
         }
         if ($confirm != md5($unsuspend)) {
             $fullname = fullname($user, true);
             echo $OUTPUT->heading(get_string('unsuspenduser', 'block_iomad_company_admin') . " " . $fullname);
             $optionsyes = array('unsuspend' => $unsuspend, 'confirm' => md5($unsuspend), 'sesskey' => sesskey());
             echo $OUTPUT->confirm(get_string('unsuspendcheckfull', 'block_iomad_company_admin', "'{$fullname}'"), new moodle_url('editusers.php', $optionsyes), 'editusers.php');
             echo $OUTPUT->footer();
             die;
         } else {
             // Actually unsuspend the user.
             company_user::unsuspend($user->id);
         }
     } else {
         if ($acl and confirm_sesskey()) {
Пример #3
0
 /**
  * This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = context_course::instance($course->id);
     // Course context
     $systemcontext = context_system::instance();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = context_user::instance($user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = context_user::instance($user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $userisenrolled = is_enrolled($coursecontext, $user->id, '', true);
             if (!$canviewusercourse && !$canviewuser || !$userisenrolled) {
                 return false;
             }
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS && !$canviewuser) {
                 // If groups are in use, make sure we can see that group (MDL-45874). That does not apply to parents.
                 if ($courseid == $this->page->course->id) {
                     $mygroups = get_fast_modinfo($this->page->course)->groups;
                 } else {
                     $mygroups = groups_get_user_groups($courseid);
                 }
                 $usergroups = groups_get_user_groups($courseid, $userid);
                 if (!array_intersect_key($mygroups[0], $usergroups[0])) {
                     return false;
                 }
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     $prefurl = new moodle_url('/user/preferences.php');
     if ($gstitle != 'usercurrentsettings') {
         $key .= $userid;
         $prefurl->param('userid', $userid);
     }
     // Add a user setting branch.
     if ($gstitle == 'usercurrentsettings') {
         $dashboard = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_CONTAINER, null, 'dashboard');
         // This should be set to false as we don't want to show this to the user. It's only for generating the correct
         // breadcrumb.
         $dashboard->display = false;
         if (get_home_page() == HOMEPAGE_MY) {
             $dashboard->mainnavonly = true;
         }
         $iscurrentuser = $user->id == $USER->id;
         $baseargs = array('id' => $user->id);
         if ($course->id != $SITE->id && !$iscurrentuser) {
             $baseargs['course'] = $course->id;
             $issitecourse = false;
         } else {
             // Load all categories and get the context for the system.
             $issitecourse = true;
         }
         // Add the user profile to the dashboard.
         $profilenode = $dashboard->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile');
         if (!empty($CFG->navadduserpostslinks)) {
             // Add nodes for forum posts and discussions if the user can view either or both
             // There are no capability checks here as the content of the page is based
             // purely on the forums the current user has access too.
             $forumtab = $profilenode->add(get_string('forumposts', 'forum'));
             $forumtab->add(get_string('posts', 'forum'), new moodle_url('/mod/forum/user.php', $baseargs), null, 'myposts');
             $forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php', array_merge($baseargs, array('mode' => 'discussions'))), null, 'mydiscussions');
         }
         // Add blog nodes.
         if (!empty($CFG->enableblogs)) {
             if (!$this->cache->cached('userblogoptions' . $user->id)) {
                 require_once $CFG->dirroot . '/blog/lib.php';
                 // Get all options for the user.
                 $options = blog_get_options_for_user($user);
                 $this->cache->set('userblogoptions' . $user->id, $options);
             } else {
                 $options = $this->cache->{'userblogoptions' . $user->id};
             }
             if (count($options) > 0) {
                 $blogs = $profilenode->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER);
                 foreach ($options as $type => $option) {
                     if ($type == "rss") {
                         $blogs->add($option['string'], $option['link'], self::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
                     } else {
                         $blogs->add($option['string'], $option['link'], self::TYPE_SETTING, null, 'blog' . $type);
                     }
                 }
             }
         }
         // Add the messages link.
         // It is context based so can appear in the user's profile and in course participants information.
         if (!empty($CFG->messaging)) {
             $messageargs = array('user1' => $USER->id);
             if ($USER->id != $user->id) {
                 $messageargs['user2'] = $user->id;
             }
             if ($course->id != $SITE->id) {
                 $messageargs['viewing'] = MESSAGE_VIEW_COURSE . $course->id;
             }
             $url = new moodle_url('/message/index.php', $messageargs);
             $dashboard->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
         }
         // Add the "My private files" link.
         // This link doesn't have a unique display for course context so only display it under the user's profile.
         if ($issitecourse && $iscurrentuser && has_capability('moodle/user:manageownfiles', $usercontext)) {
             $url = new moodle_url('/user/files.php');
             $dashboard->add(get_string('privatefiles'), $url, self::TYPE_SETTING);
         }
         // Add a node to view the users notes if permitted.
         if (!empty($CFG->enablenotes) && has_any_capability(array('moodle/notes:manage', 'moodle/notes:view'), $coursecontext)) {
             $url = new moodle_url('/notes/index.php', array('user' => $user->id));
             if ($coursecontext->instanceid != SITEID) {
                 $url->param('course', $coursecontext->instanceid);
             }
             $profilenode->add(get_string('notes', 'notes'), $url);
         }
         // Show the grades node.
         if ($issitecourse && $iscurrentuser || has_capability('moodle/user:viewdetails', $usercontext)) {
             require_once $CFG->dirroot . '/user/lib.php';
             // Set the grades node to link to the "Grades" page.
             if ($course->id == SITEID) {
                 $url = user_mygrades_url($user->id, $course->id);
             } else {
                 // Otherwise we are in a course and should redirect to the user grade report (Activity report version).
                 $url = new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $user->id));
             }
             $dashboard->add(get_string('grades', 'grades'), $url, self::TYPE_SETTING, null, 'mygrades');
         }
         // Let plugins hook into user navigation.
         $pluginsfunction = get_plugins_with_function('extend_navigation_user', 'lib.php');
         foreach ($pluginsfunction as $plugintype => $plugins) {
             if ($plugintype != 'report') {
                 foreach ($plugins as $pluginfunction) {
                     $pluginfunction($profilenode, $user, $usercontext, $course, $coursecontext);
                 }
             }
         }
         $usersetting = navigation_node::create(get_string('preferences', 'moodle'), $prefurl, self::TYPE_CONTAINER, null, $key);
         $dashboard->add_node($usersetting);
     } else {
         $usersetting = $this->add(get_string('preferences', 'moodle'), $prefurl, self::TYPE_CONTAINER, null, $key);
         $usersetting->display = false;
     }
     $usersetting->id = 'usersettings';
     // Check if the user has been deleted.
     if ($user->deleted) {
         if (!has_capability('moodle/user:update', $coursecontext)) {
             // We can't edit the user so just show the user deleted message.
             $usersetting->add(get_string('userdeleted'), null, self::TYPE_SETTING);
         } else {
             // We can edit the user so show the user deleted message and link it to the profile.
             if ($course->id == $SITE->id) {
                 $profileurl = new moodle_url('/user/profile.php', array('id' => $user->id));
             } else {
                 $profileurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
             }
             $usersetting->add(get_string('userdeleted'), $profileurl, self::TYPE_SETTING);
         }
         return true;
     }
     $userauthplugin = false;
     if (!empty($user->auth)) {
         $userauthplugin = get_auth_plugin($user->auth);
     }
     $useraccount = $usersetting->add(get_string('useraccount'), null, self::TYPE_CONTAINER, null, 'useraccount');
     // Add the profile edit link.
     if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if (($currentuser || is_siteadmin($USER) || !is_siteadmin($user)) && has_capability('moodle/user:update', $systemcontext)) {
             $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $course->id));
             $useraccount->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
         } else {
             if (has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user) || $currentuser && has_capability('moodle/user:editownprofile', $systemcontext)) {
                 if ($userauthplugin && $userauthplugin->can_edit_profile()) {
                     $url = $userauthplugin->edit_profile_url();
                     if (empty($url)) {
                         $url = new moodle_url('/user/edit.php', array('id' => $user->id, 'course' => $course->id));
                     }
                     $useraccount->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
                 }
             }
         }
     }
     // Change password link.
     if ($userauthplugin && $currentuser && !\core\session\manager::is_loggedinas() && !isguestuser() && has_capability('moodle/user:changeownpassword', $systemcontext) && $userauthplugin->can_change_password()) {
         $passwordchangeurl = $userauthplugin->change_password_url();
         if (empty($passwordchangeurl)) {
             $passwordchangeurl = new moodle_url('/login/change_password.php', array('id' => $course->id));
         }
         $useraccount->add(get_string("changepassword"), $passwordchangeurl, self::TYPE_SETTING, null, 'changepassword');
     }
     if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) || has_capability('moodle/user:editprofile', $usercontext)) {
             $url = new moodle_url('/user/language.php', array('id' => $user->id, 'course' => $course->id));
             $useraccount->add(get_string('preferredlanguage'), $url, self::TYPE_SETTING, null, 'preferredlanguage');
         }
     }
     $pluginmanager = core_plugin_manager::instance();
     $enabled = $pluginmanager->get_enabled_plugins('mod');
     if (isset($enabled['forum']) && isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) || has_capability('moodle/user:editprofile', $usercontext)) {
             $url = new moodle_url('/user/forum.php', array('id' => $user->id, 'course' => $course->id));
             $useraccount->add(get_string('forumpreferences'), $url, self::TYPE_SETTING);
         }
     }
     $editors = editors_get_enabled();
     if (count($editors) > 1) {
         if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
             if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) || has_capability('moodle/user:editprofile', $usercontext)) {
                 $url = new moodle_url('/user/editor.php', array('id' => $user->id, 'course' => $course->id));
                 $useraccount->add(get_string('editorpreferences'), $url, self::TYPE_SETTING);
             }
         }
     }
     // Add "Course preferences" link.
     if (isloggedin() && !isguestuser($user)) {
         if ($currentuser && has_capability('moodle/user:editownprofile', $systemcontext) || has_capability('moodle/user:editprofile', $usercontext)) {
             $url = new moodle_url('/user/course.php', array('id' => $user->id, 'course' => $course->id));
             $useraccount->add(get_string('coursepreferences'), $url, self::TYPE_SETTING, null, 'coursepreferences');
         }
     }
     // View the roles settings.
     if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $usercontext)) {
         $roles = $usersetting->add(get_string('roles'), null, self::TYPE_SETTING);
         $url = new moodle_url('/admin/roles/usersroles.php', array('userid' => $user->id, 'courseid' => $course->id));
         $roles->add(get_string('thisusersroles', 'role'), $url, self::TYPE_SETTING);
         $assignableroles = get_assignable_roles($usercontext, ROLENAME_BOTH);
         if (!empty($assignableroles)) {
             $url = new moodle_url('/admin/roles/assign.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
             $roles->add(get_string('assignrolesrelativetothisuser', 'role'), $url, self::TYPE_SETTING);
         }
         if (has_capability('moodle/role:review', $usercontext) || count(get_overridable_roles($usercontext, ROLENAME_BOTH)) > 0) {
             $url = new moodle_url('/admin/roles/permissions.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
             $roles->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING);
         }
         $url = new moodle_url('/admin/roles/check.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
         $roles->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING);
     }
     // Repositories.
     if (!$this->cache->cached('contexthasrepos' . $usercontext->id)) {
         require_once $CFG->dirroot . '/repository/lib.php';
         $editabletypes = repository::get_editable_types($usercontext);
         $haseditabletypes = !empty($editabletypes);
         unset($editabletypes);
         $this->cache->set('contexthasrepos' . $usercontext->id, $haseditabletypes);
     } else {
         $haseditabletypes = $this->cache->{'contexthasrepos' . $usercontext->id};
     }
     if ($haseditabletypes) {
         $repositories = $usersetting->add(get_string('repositories', 'repository'), null, self::TYPE_SETTING);
         $repositories->add(get_string('manageinstances', 'repository'), new moodle_url('/repository/manage_instances.php', array('contextid' => $usercontext->id)));
     }
     // Portfolio.
     if ($currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext)) {
         require_once $CFG->libdir . '/portfoliolib.php';
         if (portfolio_has_visible_instances()) {
             $portfolio = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING);
             $url = new moodle_url('/user/portfolio.php', array('courseid' => $course->id));
             $portfolio->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING);
             $url = new moodle_url('/user/portfoliologs.php', array('courseid' => $course->id));
             $portfolio->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING);
         }
     }
     $enablemanagetokens = false;
     if (!empty($CFG->enablerssfeeds)) {
         $enablemanagetokens = true;
     } else {
         if (!is_siteadmin($USER->id) && !empty($CFG->enablewebservices) && has_capability('moodle/webservice:createtoken', context_system::instance())) {
             $enablemanagetokens = true;
         }
     }
     // Security keys.
     if ($currentuser && $enablemanagetokens) {
         $url = new moodle_url('/user/managetoken.php', array('sesskey' => sesskey()));
         $useraccount->add(get_string('securitykeys', 'webservice'), $url, self::TYPE_SETTING);
     }
     // Messaging.
     if ($currentuser && has_capability('moodle/user:editownmessageprofile', $systemcontext) || !isguestuser($user) && has_capability('moodle/user:editmessageprofile', $usercontext) && !is_primary_admin($user->id)) {
         $url = new moodle_url('/message/edit.php', array('id' => $user->id));
         $useraccount->add(get_string('messaging', 'message'), $url, self::TYPE_SETTING);
     }
     // Blogs.
     if ($currentuser && !empty($CFG->enableblogs)) {
         $blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs');
         if (has_capability('moodle/blog:view', $systemcontext)) {
             $blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING);
         }
         if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', $systemcontext)) {
             $blog->add(get_string('externalblogs', 'blog'), new moodle_url('/blog/external_blogs.php'), navigation_node::TYPE_SETTING);
             $blog->add(get_string('addnewexternalblog', 'blog'), new moodle_url('/blog/external_blog_edit.php'), navigation_node::TYPE_SETTING);
         }
         // Remove the blog node if empty.
         $blog->trim_if_empty();
     }
     // Badges.
     if ($currentuser && !empty($CFG->enablebadges)) {
         $badges = $usersetting->add(get_string('badges'), null, navigation_node::TYPE_CONTAINER, null, 'badges');
         if (has_capability('moodle/badges:manageownbadges', $usercontext)) {
             $url = new moodle_url('/badges/mybadges.php');
             $badges->add(get_string('managebadges', 'badges'), $url, self::TYPE_SETTING);
         }
         $badges->add(get_string('preferences', 'badges'), new moodle_url('/badges/preferences.php'), navigation_node::TYPE_SETTING);
         if (!empty($CFG->badges_allowexternalbackpack)) {
             $badges->add(get_string('backpackdetails', 'badges'), new moodle_url('/badges/mybackpack.php'), navigation_node::TYPE_SETTING);
         }
     }
     // Let plugins hook into user settings navigation.
     $pluginsfunction = get_plugins_with_function('extend_navigation_user_settings', 'lib.php');
     foreach ($pluginsfunction as $plugintype => $plugins) {
         foreach ($plugins as $pluginfunction) {
             $pluginfunction($usersetting, $user, $usercontext, $course, $coursecontext);
         }
     }
     return $usersetting;
 }
 function can_do_delete()
 {
     global $USER;
     // make sure we don't delete the admin user, or ourselves
     $userid = cm_get_moodleuserid($this->required_param('id', PARAM_INT));
     return !is_primary_admin($userid) && $userid != $USER->id && $this->_has_capability('block/curr_admin:user:delete');
 }
Пример #5
0
         if (isguestuser() or !isloggedin()) {
             // guests and not logged in can not edit own profile
         } else {
             if ($USER->id == $user->id) {
                 if (has_capability('moodle/user:update', $systemcontext)) {
                     $edittype = 'advanced';
                 } else {
                     if (has_capability('moodle/user:editownprofile', $systemcontext)) {
                         $edittype = 'normal';
                     }
                 }
             } else {
                 if (has_capability('moodle/user:update', $systemcontext) and !is_primary_admin($user->id)) {
                     $edittype = 'advanced';
                 } else {
                     if (has_capability('moodle/user:editprofile', $personalcontext) and !is_primary_admin($user->id)) {
                         //teachers, parents, etc.
                         $edittype = 'normal';
                     }
                 }
             }
         }
     }
 }
 if ($edittype == 'advanced') {
     $toprow[] = new tabobject('editprofile', $wwwroot . '/user/editadvanced.php?id=' . $user->id . '&course=' . $course->id, get_string('editmyprofile'));
 } else {
     if ($edittype == 'normal') {
         $toprow[] = new tabobject('editprofile', $wwwroot . '/user/edit.php?id=' . $user->id . '&course=' . $course->id, get_string('editmyprofile'));
     }
 }
Пример #6
0
    $user->id = -1;
    $user->auth = 'manual';
    $user->confirmed = 1;
    $user->deleted = 0;
} else {
    // editing existing user
    require_capability('moodle/user:update', $systemcontext);
    if (!($user = $DB->get_record('user', array('id' => $id)))) {
        print_error('invaliduserid');
    }
}
// remote users cannot be edited
if ($user->id != -1 and is_mnet_remote_user($user)) {
    redirect($CFG->wwwroot . "/user/view.php?id={$id}&course={$course->id}");
}
if ($user->id != $USER->id and is_primary_admin($user->id)) {
    // Can't edit primary admin
    print_error('adminprimarynoedit');
}
if (isguestuser($user->id)) {
    // the real guest user can not be edited
    print_error('guestnoeditprofileother');
}
if ($user->deleted) {
    print_header();
    print_heading(get_string('userdeleted'));
    print_footer($course);
    die;
}
//load user preferences
useredit_load_preferences($user);
Пример #7
0
 public function delete()
 {
     global $CFG;
     $result = false;
     $muser = cm_get_moodleuserid($this->id);
     if (empty($muser) || !is_primary_admin($muser)) {
         $level = context_level_base::get_custom_context_level('user', 'block_curr_admin');
         $result = attendance::delete_for_user($this->id);
         $result = $result && curriculumstudent::delete_for_user($this->id);
         $result = $result && instructor::delete_for_user($this->id);
         $result = $result && student::delete_for_user($this->id);
         $result = $result && student_grade::delete_for_user($this->id);
         $result = $result && usertrack::delete_for_user($this->id);
         $result = $result && usercluster::delete_for_user($this->id);
         $result = $result && clusterassignment::delete_for_user($this->id);
         $result = $result && waitlist::delete_for_user($this->id);
         $result = $result && delete_context($level, $this->id);
         // Delete Moodle user.
         if ($muser = get_record('user', 'idnumber', $this->idnumber, 'mnethostid', $CFG->mnet_localhost_id, 'deleted', 0)) {
             $result = $result && delete_user($muser);
         }
         $result = $result && parent::delete();
     }
     return $result;
 }
Пример #8
0
 public function delete()
 {
     global $CFG;
     $muser = $this->get_moodleuser();
     if (empty($muser) || !is_primary_admin($muser->id)) {
         // delete associated data
         require_once elis::lib('data/data_filter.class.php');
         $filter = new field_filter('userid', $this->id);
         curriculumstudent::delete_records($filter, $this->_db);
         student::delete_records($filter, $this->_db);
         student_grade::delete_records($filter, $this->_db);
         waitlist::delete_records($filter, $this->_db);
         instructor::delete_records($filter, $this->_db);
         usertrack::delete_records($filter, $this->_db);
         clusterassignment::delete_records($filter, $this->_db);
         //delete association to Moodle user, if applicable
         require_once elispm::lib('data/usermoodle.class.php');
         $filter = new field_filter('cuserid', $this->id);
         usermoodle::delete_records($filter, $this->_db);
         // Delete Moodle user.
         if (!empty($muser)) {
             delete_user($muser);
         }
         parent::delete();
         $context = \local_elisprogram\context\user::instance($this->id);
         $context->delete();
     }
 }
Пример #9
0
 /**
  * This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = context_course::instance($course->id);
     // Course context
     $systemcontext = context_system::instance();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = context_user::instance($user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = context_user::instance($user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $userisenrolled = is_enrolled($coursecontext, $user->id);
             if (!$canviewusercourse && !$canviewuser || !$userisenrolled) {
                 return false;
             }
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS && !$canviewuser) {
                 // If groups are in use, make sure we can see that group (MDL-45874). That does not apply to parents.
                 if ($courseid == $this->page->course->id) {
                     $mygroups = get_fast_modinfo($this->page->course)->groups;
                 } else {
                     $mygroups = groups_get_user_groups($courseid);
                 }
                 $usergroups = groups_get_user_groups($courseid, $userid);
                 if (!array_intersect_key($mygroups[0], $usergroups[0])) {
                     return false;
                 }
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     if ($gstitle != 'usercurrentsettings') {
         $key .= $userid;
     }
     // Add a user setting branch
     $usersetting = $this->add(get_string($gstitle, 'moodle', $fullname), null, self::TYPE_CONTAINER, null, $key);
     $usersetting->id = 'usersettings';
     if ($this->page->context->contextlevel == CONTEXT_USER && $this->page->context->instanceid == $user->id) {
         // Automatically start by making it active
         $usersetting->make_active();
     }
     // Check if the user has been deleted
     if ($user->deleted) {
         if (!has_capability('moodle/user:update', $coursecontext)) {
             // We can't edit the user so just show the user deleted message
             $usersetting->add(get_string('userdeleted'), null, self::TYPE_SETTING);
         } else {
             // We can edit the user so show the user deleted message and link it to the profile
             if ($course->id == $SITE->id) {
                 $profileurl = new moodle_url('/user/profile.php', array('id' => $user->id));
             } else {
                 $profileurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
             }
             $usersetting->add(get_string('userdeleted'), $profileurl, self::TYPE_SETTING);
         }
         return true;
     }
     $userauthplugin = false;
     if (!empty($user->auth)) {
         $userauthplugin = get_auth_plugin($user->auth);
     }
     // Add the profile edit link
     if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if (($currentuser || is_siteadmin($USER) || !is_siteadmin($user)) && has_capability('moodle/user:update', $systemcontext)) {
             $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $course->id));
             $usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
         } else {
             if (has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user) || $currentuser && has_capability('moodle/user:editownprofile', $systemcontext)) {
                 if ($userauthplugin && $userauthplugin->can_edit_profile()) {
                     $url = $userauthplugin->edit_profile_url();
                     if (empty($url)) {
                         $url = new moodle_url('/user/edit.php', array('id' => $user->id, 'course' => $course->id));
                     }
                     $usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
                 }
             }
         }
     }
     // Change password link
     if ($userauthplugin && $currentuser && !\core\session\manager::is_loggedinas() && !isguestuser() && has_capability('moodle/user:changeownpassword', $systemcontext) && $userauthplugin->can_change_password()) {
         $passwordchangeurl = $userauthplugin->change_password_url();
         if (empty($passwordchangeurl)) {
             $passwordchangeurl = new moodle_url('/login/change_password.php', array('id' => $course->id));
         }
         $usersetting->add(get_string("changepassword"), $passwordchangeurl, self::TYPE_SETTING, null, 'changepassword');
     }
     // View the roles settings
     if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $usercontext)) {
         $roles = $usersetting->add(get_string('roles'), null, self::TYPE_SETTING);
         $url = new moodle_url('/admin/roles/usersroles.php', array('userid' => $user->id, 'courseid' => $course->id));
         $roles->add(get_string('thisusersroles', 'role'), $url, self::TYPE_SETTING);
         $assignableroles = get_assignable_roles($usercontext, ROLENAME_BOTH);
         if (!empty($assignableroles)) {
             $url = new moodle_url('/admin/roles/assign.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
             $roles->add(get_string('assignrolesrelativetothisuser', 'role'), $url, self::TYPE_SETTING);
         }
         if (has_capability('moodle/role:review', $usercontext) || count(get_overridable_roles($usercontext, ROLENAME_BOTH)) > 0) {
             $url = new moodle_url('/admin/roles/permissions.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
             $roles->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING);
         }
         $url = new moodle_url('/admin/roles/check.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
         $roles->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING);
     }
     // Portfolio
     if ($currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext)) {
         require_once $CFG->libdir . '/portfoliolib.php';
         if (portfolio_has_visible_instances()) {
             $portfolio = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING);
             $url = new moodle_url('/user/portfolio.php', array('courseid' => $course->id));
             $portfolio->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING);
             $url = new moodle_url('/user/portfoliologs.php', array('courseid' => $course->id));
             $portfolio->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING);
         }
     }
     $enablemanagetokens = false;
     if (!empty($CFG->enablerssfeeds)) {
         $enablemanagetokens = true;
     } else {
         if (!is_siteadmin($USER->id) && !empty($CFG->enablewebservices) && has_capability('moodle/webservice:createtoken', context_system::instance())) {
             $enablemanagetokens = true;
         }
     }
     // Security keys
     if ($currentuser && $enablemanagetokens) {
         $url = new moodle_url('/user/managetoken.php', array('sesskey' => sesskey()));
         $usersetting->add(get_string('securitykeys', 'webservice'), $url, self::TYPE_SETTING);
     }
     // Messaging
     if ($currentuser && has_capability('moodle/user:editownmessageprofile', $systemcontext) || !isguestuser($user) && has_capability('moodle/user:editmessageprofile', $usercontext) && !is_primary_admin($user->id)) {
         $url = new moodle_url('/message/edit.php', array('id' => $user->id));
         $usersetting->add(get_string('messaging', 'message'), $url, self::TYPE_SETTING);
     }
     // Blogs
     if ($currentuser && !empty($CFG->enableblogs)) {
         $blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs');
         $blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING);
         if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', context_system::instance())) {
             $blog->add(get_string('externalblogs', 'blog'), new moodle_url('/blog/external_blogs.php'), navigation_node::TYPE_SETTING);
             $blog->add(get_string('addnewexternalblog', 'blog'), new moodle_url('/blog/external_blog_edit.php'), navigation_node::TYPE_SETTING);
         }
     }
     // Badges.
     if ($currentuser && !empty($CFG->enablebadges)) {
         $badges = $usersetting->add(get_string('badges'), null, navigation_node::TYPE_CONTAINER, null, 'badges');
         $badges->add(get_string('preferences'), new moodle_url('/badges/preferences.php'), navigation_node::TYPE_SETTING);
         if (!empty($CFG->badges_allowexternalbackpack)) {
             $badges->add(get_string('backpackdetails', 'badges'), new moodle_url('/badges/mybackpack.php'), navigation_node::TYPE_SETTING);
         }
     }
     // Add reports node.
     $reporttab = $usersetting->add(get_string('activityreports'));
     $reports = get_plugin_list_with_function('report', 'extend_navigation_user', 'lib.php');
     foreach ($reports as $reportfunction) {
         $reportfunction($reporttab, $user, $course);
     }
     $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext);
     if ($anyreport || $course->showreports && $currentuser) {
         // Add grade hardcoded grade report if necessary.
         $gradeaccess = false;
         if (has_capability('moodle/grade:viewall', $coursecontext)) {
             // Can view all course grades.
             $gradeaccess = true;
         } else {
             if ($course->showgrades) {
                 if ($currentuser && has_capability('moodle/grade:view', $coursecontext)) {
                     // Can view own grades.
                     $gradeaccess = true;
                 } else {
                     if (has_capability('moodle/grade:viewall', $usercontext)) {
                         // Can view grades of this user - parent most probably.
                         $gradeaccess = true;
                     } else {
                         if ($anyreport) {
                             // Can view grades of this user - parent most probably.
                             $gradeaccess = true;
                         }
                     }
                 }
             }
         }
         if ($gradeaccess) {
             $reporttab->add(get_string('grade'), new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $usercontext->instanceid)));
         }
     }
     // Check the number of nodes in the report node... if there are none remove the node
     $reporttab->trim_if_empty();
     // Login as ...
     if (!$user->deleted and !$currentuser && !\core\session\manager::is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) && !is_siteadmin($user->id)) {
         $url = new moodle_url('/course/loginas.php', array('id' => $course->id, 'user' => $user->id, 'sesskey' => sesskey()));
         $usersetting->add(get_string('loginas'), $url, self::TYPE_SETTING);
     }
     // Let admin tools hook into user settings navigation.
     $tools = get_plugin_list_with_function('tool', 'extend_navigation_user_settings', 'lib.php');
     foreach ($tools as $toolfunction) {
         $toolfunction($usersetting, $user, $usercontext, $course, $coursecontext);
     }
     return $usersetting;
 }
 /**
  * Prints a section full of activity modules
  */
 function print_section_fn($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%", $hidecompletion = false, $resubmission = false)
 {
     global $CFG, $USER, $DB, $PAGE, $OUTPUT;
     static $initialised;
     static $groupbuttons;
     static $groupbuttonslink;
     static $isediting;
     static $ismoving;
     static $strmovehere;
     static $strmovefull;
     static $strunreadpostsone;
     static $groupings;
     static $modulenames;
     // oncampus
     $selected_week = $section->__get('section');
     if (!($oc_chapter = $this->get_chapter_for_lection($selected_week))) {
         echo $selected_week . "Fehler beim Laden des Kapitels";
         return;
     }
     if (!has_capability('moodle/course:update', $this->context) and $oc_chapter['enabled'] == 'false') {
         echo '<div class="inactive-chapter">' . $oc_chapter['name'] . ' - Dieses Kapitel ist noch nicht freigegeben!</div>';
         return;
     }
     if (!has_capability('moodle/course:update', $this->context) and $oc_chapter['enabled'] == 'hidden') {
         echo '<div class="inactive-chapter">' . $oc_chapter['name'] . ' - Du besitzt nicht die Rechte um dieses Kapitel zu sehen!</div>';
         return;
     }
     // oncampus ende
     if (!isset($initialised)) {
         $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
         $groupbuttonslink = !$course->groupmodeforce;
         $isediting = $PAGE->user_is_editing();
         $ismoving = $isediting && ismoving($course->id);
         if ($ismoving) {
             $strmovehere = get_string("movehere");
             $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
         }
         $modulenames = array();
         $initialised = true;
     }
     $modinfo = get_fast_modinfo($course);
     $completioninfo = new completion_info($course);
     //Accessibility: replace table with list <ul>, but don't output empty list.
     if (!empty($section->sequence)) {
         // Fix bug #5027, don't want style=\"width:$width\".
         echo "<ul class=\"section img-text\">\n";
         $sectionmods = explode(",", $section->sequence);
         foreach ($sectionmods as $modnumber) {
             if (empty($mods[$modnumber])) {
                 continue;
             }
             /**
              * @var cm_info
              */
             $mod = $mods[$modnumber];
             if ($ismoving and $mod->id == $USER->activitycopy) {
                 // do not display moving mod
                 continue;
             }
             if (isset($modinfo->cms[$modnumber])) {
                 // We can continue (because it will not be displayed at all)
                 // if:
                 // 1) The activity is not visible to users
                 // and
                 // 2a) The 'showavailability' option is not set (if that is set,
                 //     we need to display the activity so we can show
                 //     availability info)
                 // or
                 // 2b) The 'availableinfo' is empty, i.e. the activity was
                 //     hidden in a way that leaves no info, such as using the
                 //     eye icon.
                 if (!$modinfo->cms[$modnumber]->uservisible && (empty($modinfo->cms[$modnumber]->showavailability) || empty($modinfo->cms[$modnumber]->availableinfo))) {
                     // visibility shortcut
                     continue;
                 }
             } else {
                 if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) {
                     // module not installed
                     continue;
                 }
                 if (!coursemodule_visible_for_user($mod) && empty($mod->showavailability)) {
                     // full visibility check
                     continue;
                 }
             }
             if (!isset($modulenames[$mod->modname])) {
                 $modulenames[$mod->modname] = get_string('modulename', $mod->modname);
             }
             $modulename = $modulenames[$mod->modname];
             // In some cases the activity is visible to user, but it is
             // dimmed. This is done if viewhiddenactivities is true and if:
             // 1. the activity is not visible, or
             // 2. the activity has dates set which do not include current, or
             // 3. the activity has any other conditions set (regardless of whether
             //    current user meets them)
             $canviewhidden = has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id));
             $accessiblebutdim = false;
             if ($canviewhidden) {
                 $accessiblebutdim = !$mod->visible;
                 if (!empty($CFG->enableavailability)) {
                     $accessiblebutdim = $accessiblebutdim || $mod->availablefrom > time() || $mod->availableuntil && $mod->availableuntil < time() || count($mod->conditionsgrade) > 0 || count($mod->conditionscompletion) > 0;
                 }
             }
             $liclasses = array();
             $liclasses[] = 'activity';
             $liclasses[] = $mod->modname;
             $liclasses[] = 'modtype_' . $mod->modname;
             $extraclasses = $mod->get_extra_classes();
             if ($extraclasses) {
                 $liclasses = array_merge($liclasses, explode(' ', $extraclasses));
             }
             echo html_writer::start_tag('li', array('class' => join(' ', $liclasses), 'id' => 'module-' . $modnumber));
             if ($ismoving) {
                 echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a><br />
                  ';
             }
             $classes = array('mod-indent');
             if (!empty($mod->indent)) {
                 $classes[] = 'mod-indent-' . $mod->indent;
                 if ($mod->indent > 15) {
                     $classes[] = 'mod-indent-huge';
                 }
             }
             echo html_writer::start_tag('div', array('class' => join(' ', $classes)));
             // Get data about this course-module
             list($content, $instancename) = array($modinfo->cms[$modnumber]->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)), $modinfo->cms[$modnumber]->get_formatted_name());
             //=get_print_section_cm_text($modinfo->cms[$modnumber], $course);
             //Accessibility: for files get description via icon, this is very ugly hack!
             $altname = '';
             $altname = $mod->modfullname;
             if (!empty($customicon)) {
                 $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
                 if ($archetype == MOD_ARCHETYPE_RESOURCE) {
                     $mimetype = mimeinfo_from_icon('type', $customicon);
                     $altname = get_mimetype_description($mimetype);
                 }
             }
             // Avoid unnecessary duplication: if e.g. a forum name already
             // includes the word forum (or Forum, etc) then it is unhelpful
             // to include that in the accessible description that is added.
             if (false !== strpos(textlib::strtolower($instancename), textlib::strtolower($altname))) {
                 $altname = '';
             }
             // File type after name, for alphabetic lists (screen reader).
             if ($altname) {
                 $altname = get_accesshide(' ' . $altname);
             }
             // We may be displaying this just in order to show information
             // about visibility, without the actual link
             $contentpart = '';
             if ($mod->uservisible) {
                 // Nope - in this case the link is fully working for user
                 $linkclasses = '';
                 $textclasses = '';
                 if ($accessiblebutdim) {
                     $linkclasses .= ' dimmed';
                     $textclasses .= ' dimmed_text';
                     $accesstext = '<span class="accesshide">' . get_string('hiddenfromstudents') . ': </span>';
                 } else {
                     $accesstext = '';
                 }
                 if ($linkclasses) {
                     $linkcss = 'class="' . trim($linkclasses) . '" ';
                 } else {
                     $linkcss = '';
                 }
                 if ($textclasses) {
                     $textcss = 'class="' . trim($textclasses) . '" ';
                 } else {
                     $textcss = '';
                 }
                 // Get on-click attribute value if specified
                 $onclick = $mod->get_on_click();
                 if ($onclick) {
                     $onclick = ' onclick="' . $onclick . '"';
                 }
                 if ($url = $mod->get_url()) {
                     // Display link itself
                     echo '<a ' . $linkcss . $mod->extra . $onclick . ' href="' . $url . '"><img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> ' . $accesstext . '<span class="instancename">' . $instancename . $altname . '</span></a>';
                     // If specified, display extra content after link
                     if ($content) {
                         $contentpart = '<div class="contentafterlink' . trim($textclasses) . '">' . $content . '</div>';
                     }
                 } else {
                     // No link, so display only content
                     $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>';
                 }
                 if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                     if (!isset($groupings)) {
                         $groupings = groups_get_all_groupings($course->id);
                     }
                     echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                 }
             } else {
                 $textclasses = $extraclasses;
                 $textclasses .= ' dimmed_text';
                 if ($textclasses) {
                     $textcss = 'class="' . trim($textclasses) . '" ';
                 } else {
                     $textcss = '';
                 }
                 $accesstext = '<span class="accesshide">' . get_string('notavailableyet', 'condition') . ': </span>';
                 if ($url = $mod->get_url()) {
                     // Display greyed-out text of link
                     echo '<div ' . $textcss . $mod->extra . ' >' . '<img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> <span>' . $instancename . $altname . '</span></div>';
                     // Do not display content after link when it is greyed out like this.
                 } else {
                     // No link, so display only content (also greyed)
                     $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>';
                 }
             }
             // Module can put text after the link (e.g. forum unread)
             echo $mod->get_after_link();
             // If there is content but NO link (eg label), then display the
             // content here (BEFORE any icons). In this case cons must be
             // displayed after the content so that it makes more sense visually
             // and for accessibility reasons, e.g. if you have a one-line label
             // it should work similarly (at least in terms of ordering) to an
             // activity.
             if (empty($url)) {
                 echo $contentpart;
             }
             if ($isediting) {
                 if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) {
                     if (!($mod->groupmodelink = $groupbuttonslink)) {
                         $mod->groupmode = $course->groupmode;
                     }
                 } else {
                     $mod->groupmode = false;
                 }
                 echo '&nbsp;&nbsp;';
                 //echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
                 if (!$mod instanceof cm_info) {
                     $modinfo = get_fast_modinfo($mod->course);
                     $mod = $modinfo->get_cm($mod->id);
                 }
                 $actions = course_get_cm_edit_actions($mod, $mod->indent, $section->section);
                 $courserenderer = $PAGE->get_renderer('core', 'course');
                 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
                 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
                 // the course page HTML will allow this to be removed.
                 echo ' ' . $courserenderer->course_section_cm_edit_actions($actions);
                 echo $mod->get_after_edit_icons();
             }
             // Completion
             require_once 'modulelib.php';
             $completion = $hidecompletion ? COMPLETION_TRACKING_NONE : $completioninfo->is_enabled($mod);
             if ($completion != COMPLETION_TRACKING_NONE && isloggedin() && !isguestuser() && $mod->uservisible) {
                 $completiondata = $completioninfo->get_data($mod, true);
                 $completionicon = '';
                 if ($isediting) {
                     switch ($completion) {
                         case COMPLETION_TRACKING_MANUAL:
                             $completionicon = 'manual-enabled';
                             break;
                         case COMPLETION_TRACKING_AUTOMATIC:
                             $completionicon = 'auto-enabled';
                             break;
                         default:
                             // wtf
                     }
                 } else {
                     if (is_siteadmin() || !has_capability('mod/assignment:submit', get_context_instance(CONTEXT_COURSE, $course->id))) {
                         switch ($completion) {
                             case COMPLETION_TRACKING_MANUAL:
                                 $completionicon = 'manual-enabled';
                                 break;
                             case COMPLETION_TRACKING_AUTOMATIC:
                                 $completionicon = 'auto-enabled';
                                 break;
                             default:
                                 // wtf
                         }
                     } else {
                         if ($completion == COMPLETION_TRACKING_MANUAL) {
                             switch ($completiondata->completionstate) {
                                 case COMPLETION_INCOMPLETE:
                                     $completionicon = 'manual-n';
                                     break;
                                 case COMPLETION_COMPLETE:
                                     $completionicon = 'manual-y';
                                     break;
                             }
                         } else {
                             // Automatic
                             if (($mod->modname == 'assignment' || $mod->modname == 'assign') && isset($mod->completiongradeitemnumber)) {
                                 $act_compl = is_saved_or_submitted($mod, $USER->id, $resubmission);
                                 if ($act_compl == 'submitted') {
                                     // $completiondata->completionstate = COMPLETION_WAITFORGRADE_FN;
                                 } else {
                                     if ($act_compl == 'waitinggrade') {
                                         $completiondata->completionstate = COMPLETION_WAITFORGRADE_FN;
                                     } else {
                                         if ($act_compl == 'saved') {
                                             $completiondata->completionstate = COMPLETION_SAVED_FN;
                                         }
                                     }
                                 }
                             }
                             switch ($completiondata->completionstate) {
                                 case COMPLETION_INCOMPLETE:
                                     $completionicon = 'auto-n';
                                     break;
                                 case COMPLETION_COMPLETE:
                                     $completionicon = 'auto-y';
                                     break;
                                 case COMPLETION_COMPLETE_PASS:
                                     $completionicon = 'auto-pass';
                                     break;
                                 case COMPLETION_COMPLETE_FAIL:
                                     $completionicon = 'auto-fail';
                                     break;
                                 case COMPLETION_WAITFORGRADE_FN:
                                     $completionicon = 'submitted';
                                     break;
                                 case COMPLETION_SAVED_FN:
                                     $completionicon = 'saved';
                                     break;
                             }
                         }
                     }
                 }
                 if ($completionicon) {
                     $imgsrc = '' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/completion-' . $completionicon . '.gif';
                     $imgalt = s(get_string('completion-alt-' . $completionicon, 'format_octabs'));
                     if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting && has_capability('mod/assignment:submit', get_context_instance(CONTEXT_COURSE, $course->id)) && !is_primary_admin($USER->id)) {
                         $imgtitle = s(get_string('completion-title-' . $completionicon, 'format_octabs'));
                         $newstate = $completiondata->completionstate == COMPLETION_COMPLETE ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE;
                         // In manual mode the icon is a toggle form...
                         // If this completion state is used by the
                         // conditional activities system, we need to turn
                         // off the JS.i
                         /* oncampus 
                         			if (!empty($CFG->enableavailability) &&
                                                         condition_info::completion_value_used_as_condition($course, $mod)) {
                                                     $extraclass = ' preventjs';
                                                 } else {
                                                     $extraclass = '';
                                                 }
                                                 echo "
                                                         <form class='togglecompletion$extraclass' method='post' action='" . $CFG->wwwroot . "/course/togglecompletion.php'><div>
                                                         <input type='hidden' name='id' value='{$mod->id}' />
                                                         <input type='hidden' name='sesskey' value='" . sesskey() . "' />
                                                         <input type='hidden' name='completionstate' value='$newstate' />
                                                         <input type='image' src='$imgsrc' alt='$imgalt' title='$imgtitle' />
                                                         </div></form>"; 
                         			*/
                     } else {
                         // In auto mode, or when editing, the icon is just an image
                         /* echo "<span class='autocompletion'>";
                            echo "<img src='$imgsrc' alt='$imgalt' title='$imgalt' /></span>"; */
                     }
                 }
             }
             // If there is content AND a link, then display the content here
             // (AFTER any icons). Otherwise it was displayed before
             if (!empty($url)) {
                 echo $contentpart;
             }
             // Show availability information (for someone who isn't allowed to
             // see the activity itself, or for staff)
             if (!$mod->uservisible) {
                 echo '<div class="availabilityinfo">' . $mod->availableinfo . '</div>';
             } else {
                 if ($canviewhidden && !empty($CFG->enableavailability)) {
                     $ci = new condition_info($mod);
                     $fullinfo = $ci->get_full_information();
                     if ($fullinfo) {
                         echo '<div class="availabilityinfo">' . get_string($mod->showavailability ? 'userrestriction_visible' : 'userrestriction_hidden', 'condition', $fullinfo) . '</div>';
                     }
                 }
             }
             echo html_writer::end_tag('div');
             echo html_writer::end_tag('li') . "\n";
         }
     } elseif ($ismoving) {
         echo "<ul class=\"section\">\n";
     }
     if ($ismoving) {
         echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a></li>
          ';
     }
     if (!empty($section->sequence) || $ismoving) {
         echo "</ul><!--class='section'-->\n\n";
     }
 }
Пример #11
0
 /**
  * block contents
  *
  * @return object
  */
 public function get_content()
 {
     global $CFG, $USER, $DB, $OUTPUT, $PAGE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (!isloggedin()) {
         return '';
         // Never useful unless you are logged in
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     $course = $this->page->course;
     if ($PAGE->context->contextlevel == CONTEXT_USER) {
         $user = $DB->get_record('user', array('id' => $PAGE->context->instanceid));
     } else {
         $user = $USER;
     }
     if ($course->id == SITEID) {
         $coursecontext = get_context_instance(CONTEXT_SYSTEM);
     } else {
         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
         // Course context
         // Make sure they can view the course
         if (!is_viewing($coursecontext)) {
             return '';
         }
     }
     // TODO: clean up the following even more
     if (!isset($this->config->display_picture) || $this->config->display_picture == 1) {
         $this->content->text .= '<div class="myprofileitem picture">';
         $this->content->text .= $OUTPUT->user_picture($user, array('courseid' => $course->id, 'size' => '100', 'class' => 'profilepicture'));
         // The new class makes CSS easier
         $this->content->text .= '</div>';
     }
     $this->content->text .= '<div class="myprofileitem fullname">' . fullname($user) . '</div>';
     if (!isset($this->config->display_country) || $this->config->display_country == 1) {
         $countries = get_string_manager()->get_list_of_countries();
         if (isset($countries[$user->country])) {
             $this->content->text .= '<div class="myprofileitem country">';
             $this->content->text .= get_string('country') . ': ' . $countries[$user->country];
             $this->content->text .= '</div>';
         }
     }
     if (!isset($this->config->display_city) || $this->config->display_city == 1) {
         $this->content->text .= '<div class="myprofileitem city">';
         $this->content->text .= get_string('city') . ': ' . $user->city;
         $this->content->text .= '</div>';
     }
     if (!isset($this->config->display_email) || $this->config->display_email == 1) {
         $this->content->text .= '<div class="myprofileitem email">';
         $this->content->text .= obfuscate_mailto($user->email, '');
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_icq) && !empty($user->icq)) {
         $this->content->text .= '<div class="myprofileitem icq">';
         $this->content->text .= 'ICQ: ' . $user->icq;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_skype) && !empty($user->skype)) {
         $this->content->text .= '<div class="myprofileitem skype">';
         $this->content->text .= 'Skype: ' . $user->skype;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_yahoo) && !empty($user->yahoo)) {
         $this->content->text .= '<div class="myprofileitem yahoo">';
         $this->content->text .= 'Yahoo: ' . $user->yahoo;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_aim) && !empty($user->aim)) {
         $this->content->text .= '<div class="myprofileitem aim">';
         $this->content->text .= 'AIM: ' . $user->aim;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_msn) && !empty($user->msn)) {
         $this->content->text .= '<div class="myprofileitem msn">';
         $this->content->text .= 'MSN: ' . $user->msn;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_phone1) && !empty($user->phone1)) {
         $this->content->text .= '<div class="myprofileitem phone1">';
         $this->content->text .= get_string('phone') . ': ' . $user->phone1;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_phone2) && !empty($user->phone2)) {
         $this->content->text .= '<div class="myprofileitem phone2">';
         $this->content->text .= get_string('phone') . ': ' . $user->phone2;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_institution) && !empty($user->institution)) {
         $this->content->text .= '<div class="myprofileitem institution">';
         $this->content->text .= $user->institution;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_address) && !empty($user->address)) {
         $this->content->text .= '<div class="myprofileitem address">';
         $this->content->text .= $user->address;
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_firstaccess) && !empty($user->firstaccess)) {
         $this->content->text .= '<div class="myprofileitem firstaccess">';
         $this->content->text .= get_string('firstaccess') . ': ' . userdate($user->firstaccess);
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_lastaccess) && !empty($user->lastaccess)) {
         $this->content->text .= '<div class="myprofileitem lastaccess">';
         $this->content->text .= get_string('lastaccess') . ': ' . userdate($user->lastaccess);
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_currentlogin) && !empty($user->currentlogin)) {
         $this->content->text .= '<div class="myprofileitem currentlogin">';
         $this->content->text .= get_string('login') . ': ' . userdate($user->currentlogin);
         $this->content->text .= '</div>';
     }
     if (!empty($this->config->display_lastip) && !empty($user->lastip)) {
         $this->content->text .= '<div class="myprofileitem lastip">';
         $this->content->text .= 'IP: ' . $user->lastip;
         $this->content->text .= '</div>';
     }
     $editscript = NULL;
     if (isguestuser($user)) {
         // guest account can not be edited
     } else {
         if (is_mnet_remote_user($user)) {
             // cannot edit remote users
         } else {
             if (isguestuser() or !isloggedin()) {
                 // guests and not logged in can not edit own profile
             } else {
                 if ($USER->id == $user->id) {
                     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
                     if (has_capability('moodle/user:update', $systemcontext)) {
                         $editscript = '/user/editadvanced.php';
                     } else {
                         if (has_capability('moodle/user:editownprofile', $systemcontext)) {
                             $editscript = '/user/edit.php';
                         }
                     }
                 } else {
                     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
                     $personalcontext = get_context_instance(CONTEXT_USER, $user->id);
                     if (has_capability('moodle/user:update', $systemcontext) and !is_primary_admin($user->id)) {
                         $editscript = '/user/editadvanced.php';
                     } else {
                         if (has_capability('moodle/user:editprofile', $personalcontext) and !is_primary_admin($user->id)) {
                             //teachers, parents, etc.
                             $editscript = '/user/edit.php';
                         }
                     }
                 }
             }
         }
     }
     if ($editscript) {
         $this->content->text .= '<div class="myprofileitem edit">';
         $this->content->text .= '<a href="' . $CFG->wwwroot . $editscript . '?id=' . $user->id . '&amp;course=' . $course->id . '">' . get_string('editmyprofile') . '</a>';
         $this->content->text .= '</div>';
     }
     return $this->content;
 }
Пример #12
0
 function can_do_delete()
 {
     global $USER;
     // make sure we don't delete the admin user, or ourselves
     $cuser = new user($this->required_param('id', PARAM_INT));
     $muser = $cuser->get_moodleuser();
     if (!isset($muser->id)) {
         //no corresponding Moodle user, so just check the capability
         return $this->_has_capability('local/elisprogram:user_delete');
     }
     return !is_primary_admin($muser->id) && $muser->id != $USER->id && $this->_has_capability('local/elisprogram:user_delete');
 }