diff --git a/admin/registration/index.php b/admin/registration/index.php index 8af727a026e78..d95149b9f3519 100644 --- a/admin/registration/index.php +++ b/admin/registration/index.php @@ -37,4 +37,4 @@ echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main'); echo $renderer->registrationselector(); -echo $OUTPUT->footer(); \ No newline at end of file +echo $OUTPUT->footer(); diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 7f09dbd3bd600..4026ffe6a69dd 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -35,6 +35,7 @@ } } + // calendar $temp = new admin_settingpage('calendar', get_string('calendarsettings','admin')); $temp->add(new admin_setting_special_adminseesall()); @@ -123,9 +124,10 @@ $temp->add(new admin_setting_configcheckbox('doctonewwindow', get_string('doctonewwindow', 'admin'), get_string('configdoctonewwindow', 'admin'), 0)); $ADMIN->add('appearance', $temp); - $temp = new admin_settingpage('mymoodle', get_string('mymoodle', 'admin')); - $temp->add(new admin_setting_configcheckbox('mymoodleredirect', get_string('mymoodleredirect', 'admin'), get_string('configmymoodleredirect', 'admin'), 0)); - $temp->add(new admin_setting_configtext('mycoursesperpage', get_string('mycoursesperpage', 'admin'), get_string('configmycoursesperpage', 'admin'), 21, PARAM_INT)); + $temp = new admin_externalpage('mypage', get_string('mypage', 'admin'), $CFG->wwwroot . '/my/indexsys.php'); + $ADMIN->add('appearance', $temp); + + $temp = new admin_externalpage('profilepage', get_string('myprofile', 'admin'), $CFG->wwwroot . '/user/profilesys.php'); $ADMIN->add('appearance', $temp); // coursemanager is the person responsible for course - usually manages enrolments, receives notification, etc. diff --git a/blocks/course_overview/block_course_overview.php b/blocks/course_overview/block_course_overview.php new file mode 100644 index 0000000000000..4c494178d1cfa --- /dev/null +++ b/blocks/course_overview/block_course_overview.php @@ -0,0 +1,128 @@ +. + +/** + * Course overview block + * + * Currently, just a copy-and-paste from the old My Moodle. + * + * @package blocks + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once($CFG->dirroot.'/lib/weblib.php'); +require_once($CFG->dirroot . '/lib/formslib.php'); + +class block_course_overview extends block_base { + /** + * block initializations + */ + public function init() { + $this->title = get_string('pluginname', 'block_course_overview'); + $this->version = 2010021100; + } + + /** + * block contents + * + * @return object + */ + public function get_content() { + global $USER; + if($this->content !== NULL) { + return $this->content; + } + + $this->content = new stdClass(); + $this->content->text = ''; + $this->content->footer = ''; + + $content = array(); + + // limits the number of courses showing up + $courses_limit = 21; + // FIXME: this should be a block setting, rather than a global setting + if (isset($CFG->mycoursesperpage)) { + $courses_limit = $CFG->mycoursesperpage; + } + + $morecourses = false; + if ($courses_limit > 0) { + $courses_limit = $courses_limit + 1; + } + + $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit); + $site = get_site(); + $course = $site; //just in case we need the old global $course hack + + if (($courses_limit > 0) && (count($courses) >= $courses_limit)) { + //remove the 'marker' course that we retrieve just to see if we have more than $courses_limit + array_pop($courses); + $morecourses = true; + } + + + if (array_key_exists($site->id,$courses)) { + unset($courses[$site->id]); + } + + foreach ($courses as $c) { + if (isset($USER->lastcourseaccess[$c->id])) { + $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id]; + } else { + $courses[$c->id]->lastaccess = 0; + } + } + + if (empty($courses)) { + $content[] = get_string('nocourses','my'); + } else { + ob_start(); + print_overview($courses); + $content[] = ob_get_contents(); + ob_end_clean(); + } + + // if more than 20 courses + if ($morecourses) { + $content[] = '
...'; + } + + $this->content->text = implode($content); + + return $this->content; + } + + /** + * allow the block to have a configuration page + * + * @return boolean + */ + public function has_config() { + return false; + } + + /** + * locations where block can be displayed + * + * @return array + */ + public function applicable_formats() { + return array('my-index'=>true); + } +} +?> diff --git a/blocks/course_overview/lang/en/block_course_overview.php b/blocks/course_overview/lang/en/block_course_overview.php new file mode 100644 index 0000000000000..c103d8e2543c5 --- /dev/null +++ b/blocks/course_overview/lang/en/block_course_overview.php @@ -0,0 +1,2 @@ +context); + global $USER; + + if (has_capability('moodle/block:edit', $this->context)) { + return true; + } + + // The blocks in My Moodle are a special case. We want them to inherit from the user context. + if (!empty($USER->id) + && $this->instance->parentcontextid == $this->page->context->id // Block belongs to this page + && $this->page->context->contextlevel == CONTEXT_USER // Page belongs to a user + && $this->page->context->instanceid == $USER->id) { // Page belongs to this user + return has_capability('moodle/my:manageblocks', $this->page->context); + } + + return false; } /** @@ -676,7 +690,20 @@ function user_can_edit() { * @return boolean */ function user_can_addto($page) { - return has_capability('moodle/block:edit', $page->context); + global $USER; + + if (has_capability('moodle/block:edit', $page->context)) { + return true; + } + + // The blocks in My Moodle are a special case and use a different capability. + if (!empty($USER->id) + && $page->context->contextlevel == CONTEXT_USER // Page belongs to a user + && $page->context->instanceid == $USER->id) { // Page belongs to this user + return has_capability('moodle/my:manageblocks', $page->context); + } + + return false; } function get_extra_capabilities() { diff --git a/blocks/myprofile/block_myprofile.php b/blocks/myprofile/block_myprofile.php new file mode 100644 index 0000000000000..60cf51ce68311 --- /dev/null +++ b/blocks/myprofile/block_myprofile.php @@ -0,0 +1,306 @@ +. + +/** + * Displays the user's profile information. + * + * @package blocks + * @copyright 2010 Remote-Learner.net + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Displays the user's profile information. + * + * @copyright 2010 Remote-Learner.net + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class block_myprofile extends block_base { + /** + * block initializations + */ + public function init() { + $this->title = get_string('pluginname', 'block_myprofile'); + $this->version = 2009123100; + } + + /** + * 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 .= '
'; + $this->content->text = $OUTPUT->user_picture($user, array('courseid'=>$course->id, 'size'=>'100', 'class'=>'profilepicture')); // The new class makes CSS easier + $this->content->text .= '
'; + } + + $this->content->text .= '
'.fullname($user).'
'; + + if(!isset($this->config->display_country) || $this->config->display_country == 1) { + $countries = get_string_manager()->get_list_of_countries(); + $this->content->text .= '
'; + $this->content->text .= get_string('country') . ': ' . $countries[$user->country]; + $this->content->text .= '
'; + } + + if(!isset($this->config->display_city) || $this->config->display_city == 1) { + $this->content->text .= '
'; + $this->content->text .= get_string('city') . ': ' . $user->city; + $this->content->text .= '
'; + } + + if(!isset($this->config->display_email) || $this->config->display_email == 1) { + $this->content->text .= ''; + } + + if(!empty($this->config->display_icq) && !empty($user->icq)) { + $this->content->text .= '
'; + $this->content->text .= 'ICQ: ' . $user->icq; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_skype) && !empty($user->skype)) { + $this->content->text .= '
'; + $this->content->text .= 'Skype: ' . $user->skype; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_yahoo) && !empty($user->yahoo)) { + $this->content->text .= '
'; + $this->content->text .= 'Yahoo: ' . $user->yahoo; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_aim) && !empty($user->aim)) { + $this->content->text .= '
'; + $this->content->text .= 'AIM: ' . $user->aim; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_msn) && !empty($user->msn)) { + $this->content->text .= '
'; + $this->content->text .= 'MSN: ' . $user->msn; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_phone1) && !empty($user->phone1)) { + $this->content->text .= '
'; + $this->content->text .= get_string('phone').': ' . $user->phone1; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_phone2) && !empty($user->phone2)) { + $this->content->text .= '
'; + $this->content->text .= get_string('phone').': ' . $user->phone2; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_institution) && !empty($user->institution)) { + $this->content->text .= '
'; + $this->content->text .= $user->institution; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_address) && !empty($user->address)) { + $this->content->text .= '
'; + $this->content->text .= $user->address; + $this->content->text .= '
'; + } + + if(!empty($this->config->display_firstaccess) && !empty($user->firstaccess)) { + $this->content->text .= '
'; + $this->content->text .= get_string('firstaccess').': ' . userdate($user->firstaccess); + $this->content->text .= '
'; + } + + if(!empty($this->config->display_lastaccess) && !empty($user->lastaccess)) { + $this->content->text .= '
'; + $this->content->text .= get_string('lastaccess').': ' . userdate($user->lastaccess); + $this->content->text .= '
'; + } + + if(!empty($this->config->display_currentlogin) && !empty($user->currentlogin)) { + $this->content->text .= '
'; + $this->content->text .= get_string('login').': ' . userdate($user->currentlogin); + $this->content->text .= '
'; + } + + if(!empty($this->config->display_lastip) && !empty($user->lastip)) { + $this->content->text .= '
'; + $this->content->text .= 'IP: ' . $user->lastip; + $this->content->text .= '
'; + } + + $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 .= '
'; + $this->content->text .= ''.get_string('editmyprofile').''; + $this->content->text .= '
'; + } + + + return $this->content; + } + + /** + * allow the block to have a configuration page + * + * @return boolean + */ + public function has_config() { + return false; + } + + /** + * allow more than one instance of the block on a page + * + * @return boolean + */ + public function instance_allow_multiple() { + //allow more than one instance on a page + return false; + } + + /** + * allow instances to have their own configuration + * + * @return boolean + */ + function instance_allow_config() { + //allow instances to have their own configuration + return false; + } + + /** + * instance specialisations (must have instance allow config true) + * + */ + public function specialization() { + } + + /** + * displays instance configuration form + * + * @return boolean + */ + function instance_config_print() { + if (!$this->instance_allow_config()) { + return false; + } + + global $CFG; + + $form = new block_myprofile.phpConfigForm(null, array($this->config)); + $form->display(); + + return true; + } + + /** + * locations where block can be displayed + * + * @return array + */ + public function applicable_formats() { + return array('all'=>true); + } + + /** + * post install configurations + * + */ + public function after_install() { + } + + /** + * post delete configurations + * + */ + public function before_delete() { + } + +} +?> diff --git a/blocks/myprofile/edit_form.php b/blocks/myprofile/edit_form.php new file mode 100644 index 0000000000000..4605853bf0358 --- /dev/null +++ b/blocks/myprofile/edit_form.php @@ -0,0 +1,157 @@ +. + +/** + * Form for editing profile block settings + * + * @package blocks + * @copyright 2010 Remote-Learner.net + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class block_myprofile_edit_form extends block_edit_form { + protected function specific_definition($mform) { + global $CFG; + $mform->addElement('header', 'configheader', get_string('myprofile_settings', 'block_myprofile')); + + $mform->addElement('selectyesno', 'config_display_picture', get_string('display_picture', 'block_myprofile')); + if (isset($this->block->config->display_picture)) { + $mform->setDefault('config_display_picture', $this->block->config->display_picture); + } else { + $mform->setDefault('config_display_picture', '1'); + } + + $mform->addElement('selectyesno', 'config_display_country', get_string('display_country', 'block_myprofile')); + if (isset($this->block->config->display_country)) { + $mform->setDefault('config_display_country', $this->block->config->display_country); + } else { + $mform->setDefault('config_display_country', '1'); + } + + $mform->addElement('selectyesno', 'config_display_city', get_string('display_city', 'block_myprofile')); + if (isset($this->block->config->display_city)) { + $mform->setDefault('config_display_city', $this->block->config->display_city); + } else { + $mform->setDefault('config_display_city', '1'); + } + + $mform->addElement('selectyesno', 'config_display_email', get_string('display_email', 'block_myprofile')); + if (isset($this->block->config->display_email)) { + $mform->setDefault('config_display_email', $this->block->config->display_email); + } else { + $mform->setDefault('config_display_email', '1'); + } + + $mform->addElement('selectyesno', 'config_display_un', get_string('display_un', 'block_myprofile')); + if (isset($this->block->config->display_un)) { + $mform->setDefault('config_display_un', $this->block->config->display_un); + } else { + $mform->setDefault('config_display_un', '0'); + } + + $mform->addElement('selectyesno', 'config_display_icq', get_string('display_icq', 'block_myprofile')); + if (isset($this->block->config->display_icq)) { + $mform->setDefault('config_display_icq', $this->block->config->display_icq); + } else { + $mform->setDefault('config_display_icq', '0'); + } + + $mform->addElement('selectyesno', 'config_display_skype', get_string('display_skype', 'block_myprofile')); + if (isset($this->block->config->display_skype)) { + $mform->setDefault('config_display_skype', $this->block->config->display_skype); + } else { + $mform->setDefault('config_display_skype', '0'); + } + + $mform->addElement('selectyesno', 'config_display_yahoo', get_string('display_yahoo', 'block_myprofile')); + if (isset($this->block->config->display_yahoo)) { + $mform->setDefault('config_display_yahoo', $this->block->config->display_yahoo); + } else { + $mform->setDefault('config_display_yahoo', '0'); + } + + $mform->addElement('selectyesno', 'config_display_aim', get_string('display_aim', 'block_myprofile')); + if (isset($this->block->config->display_aim)) { + $mform->setDefault('config_display_aim', $this->block->config->display_aim); + } else { + $mform->setDefault('config_display_aim', '0'); + } + + $mform->addElement('selectyesno', 'config_display_msn', get_string('display_msn', 'block_myprofile')); + if (isset($this->block->config->display_msn)) { + $mform->setDefault('config_display_msn', $this->block->config->display_msn); + } else { + $mform->setDefault('config_display_msn', '0'); + } + + $mform->addElement('selectyesno', 'config_display_phone1', get_string('display_phone1', 'block_myprofile')); + if (isset($this->block->config->display_phone1)) { + $mform->setDefault('config_display_phone1', $this->block->config->display_phone1); + } else { + $mform->setDefault('config_display_phone1', '0'); + } + + $mform->addElement('selectyesno', 'config_display_phone2', get_string('display_phone2', 'block_myprofile')); + if (isset($this->block->config->display_phone2)) { + $mform->setDefault('config_display_phone2', $this->block->config->display_phone2); + } else { + $mform->setDefault('config_display_phone2', '0'); + } + + $mform->addElement('selectyesno', 'config_display_institution', get_string('display_institution', 'block_myprofile')); + if (isset($this->block->config->display_institution)) { + $mform->setDefault('config_display_institution', $this->block->config->display_institution); + } else { + $mform->setDefault('config_display_institution', '0'); + } + + $mform->addElement('selectyesno', 'config_display_address', get_string('display_address', 'block_myprofile')); + if (isset($this->block->config->display_address)) { + $mform->setDefault('config_display_address', $this->block->config->display_address); + } else { + $mform->setDefault('config_display_address', '0'); + } + + $mform->addElement('selectyesno', 'config_display_firstaccess', get_string('display_firstaccess', 'block_myprofile')); + if (isset($this->block->config->display_firstaccess)) { + $mform->setDefault('config_display_firstaccess', $this->block->config->display_firstaccess); + } else { + $mform->setDefault('config_display_firstaccess', '0'); + } + + $mform->addElement('selectyesno', 'config_display_lastaccess', get_string('display_lastaccess', 'block_myprofile')); + if (isset($this->block->config->display_lastaccess)) { + $mform->setDefault('config_display_lastaccess', $this->block->config->display_lastaccess); + } else { + $mform->setDefault('config_display_lastaccess', '0'); + } + + $mform->addElement('selectyesno', 'config_display_currentlogin', get_string('display_currentlogin', 'block_myprofile')); + if (isset($this->block->config->display_currentlogin)) { + $mform->setDefault('config_display_currentlogin', $this->block->config->display_currentlogin); + } else { + $mform->setDefault('config_display_currentlogin', '0'); + } + + $mform->addElement('selectyesno', 'config_display_lastip', get_string('display_lastip', 'block_myprofile')); + if (isset($this->block->config->display_lastip)) { + $mform->setDefault('config_display_lastip', $this->block->config->display_lastip); + } else { + $mform->setDefault('config_display_lastip', '0'); + } + } +} \ No newline at end of file diff --git a/blocks/myprofile/lang/en/block_myprofile.php b/blocks/myprofile/lang/en/block_myprofile.php new file mode 100644 index 0000000000000..09c256d93621e --- /dev/null +++ b/blocks/myprofile/lang/en/block_myprofile.php @@ -0,0 +1,23 @@ + diff --git a/blocks/myprofile/styles.css b/blocks/myprofile/styles.css new file mode 100644 index 0000000000000..c64c1dcc21216 --- /dev/null +++ b/blocks/myprofile/styles.css @@ -0,0 +1,4 @@ +.block_myprofile img.profilepicture { height:100px; width:100px;} +.block_myprofile .myprofileitem.fullname {font-size:1.5em; font-style: bold;} +.block_myprofile .myprofileitem.edit {text-align: right;} + diff --git a/lang/en/admin.php b/lang/en/admin.php index 59622fa74b8a1..a4c6519aebef1 100755 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -254,6 +254,7 @@ $string['configminpasswordupper'] = 'Passwords must have at least these many upper case letters.'; $string['configmycoursesperpage'] = 'Maximum number of courses to display in any list of a user\'s own courses'; $string['configmymoodleredirect'] = 'This setting forces redirects to /my on login for non-admins and replaces the top level site navigation with /my'; +$string['configmypagelocked'] = 'This setting prevents the default page from being edited by any non-admins'; $string['confignavshowallcourses'] = 'Setting this ensures that all courses a user is registered in are shown on the navigation at all times. By default once a user browses to a course only that course is shown on the navigation.'; $string['confignavshowcategories'] = 'Show course categories in the navigation bar and navigation blocks'; $string['confignodefaultuserrolelists'] = 'This setting prevents all users from being returned from the database from deprecated calls of get_course_user, etc., for the site course if the default role provides that access. Check this, if you suffer a performance hit.'; @@ -668,8 +669,12 @@ $string['multilangupgradenotice'] = 'Your site is probably using old multilang syntax, multilang upgrade is recommended.'; $string['mustenablestats'] = 'Stats have not yet been enabled on this site.'; $string['mycoursesperpage'] = 'Number of courses'; +$string['mydashboard'] = 'System default dashboard'; $string['mymoodle'] = 'My Moodle'; $string['mymoodleredirect'] = 'Force users to use My Moodle'; +$string['mypage'] = 'Default My Moodle page'; +$string['myprofile'] = 'Default Profile page'; +$string['mypagelocked'] = 'Lock default page'; $string['mysql416bypassed'] = 'However, if your site is using iso-8859-1 (latin) languages ONLY, you may continue using your currently installed MySQL 4.1.12 (or higher).'; $string['mysql416required'] = 'MySQL 4.1.16 is the minimum version required for Moodle 1.6 in order to guarantee that all data can be converted to UTF-8 in the future.'; $string['navigationupgrade'] = 'This upgrade introduces two new navigation blocks that will replace these blocks: Administration, Courses, Activities and Participants. If you had set any special permissions on those blocks you should check to make sure everything is behaving as you want it.'; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 142034d6664be..90f531a141235 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -324,6 +324,7 @@ $string['coursenotaccessible'] = 'This course does not allow public access'; $string['courseoverview'] = 'Course overview'; $string['courseoverviewgraph'] = 'Course overview graph'; +$string['courseprofiles'] = 'Course profiles'; $string['coursereasonforrejecting'] = 'Your reasons for rejecting this request'; $string['coursereasonforrejectingemail'] = 'This will be emailed to the requester'; $string['coursereject'] = 'Reject a course request'; @@ -1365,6 +1366,7 @@ $string['publicdirectory0'] = 'Please do not publish this site'; $string['publicdirectory1'] = 'Publish the site name only'; $string['publicdirectory2'] = 'Publish the site name with a link'; +$string['publicprofile'] = 'Public profile'; $string['publicsitefileswarning'] = 'Note: files placed here can be accessed by anyone'; $string['publicsitefileswarning2'] = 'Note: Files placed here can be accessed by anyone who knows (or can guess) the URL. For security reasons, it is recommended that any backup files are deleted immediately after restoring them.'; $string['publicsitefileswarning3'] = 'Note: Files placed here can be accessed by anyone who knows (or can guess) the URL.
For security reasons, backup files should be saved in the secure backupdata folder only.'; @@ -1716,8 +1718,8 @@ $string['up'] = 'Up'; $string['update'] = 'Update'; $string['updated'] = 'Updated {$a}'; -$string['updatemymoodleoff'] = 'Normal mode'; -$string['updatemymoodleon'] = 'Edit this page'; +$string['updatemymoodleoff'] = 'Stop customising this page'; +$string['updatemymoodleon'] = 'Customise this page'; $string['updatemyprofile'] = 'Update profile'; $string['updatesevery'] = 'Updates every {$a} seconds'; $string['updatethis'] = 'Update this {$a}'; diff --git a/lang/en/my.php b/lang/en/my.php index 2f7549743dbc2..e43b13a3fe866 100644 --- a/lang/en/my.php +++ b/lang/en/my.php @@ -1,30 +1,14 @@ -. -/** - * Strings for component 'my', language 'en', branch 'MOODLE_20_STABLE' - * - * @package my - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['mymoodle'] = 'Overview of my courses'; +$string['mymoodle'] = 'My Moodle'; $string['nocourses'] = 'No course information to show.'; -$string['noguest'] = 'The \'Course Overview\' page is not available to guest users'; +$string['noguest'] = 'The \'My Moodle\' page is not available to guest users'; $string['pinblocks'] = 'Configure pinned blocks for my moodle'; -$string['pinblocksexplan'] = 'Any block settings you configure here will be visible (and non-editable) for any user of moodle on their \'my moodle\' overview page.'; +$string['pinblocksexplan'] = 'Any block settings you configure here will be visible (and non-editable) for any user of moodle on their \'My Moodle\' overview page.'; +$string['defaultpage'] = 'Default My Moodle page'; +$string['defaultprofilepage'] = 'Default profile page'; +$string['addpage'] = 'Add page'; +$string['delpage'] = 'Delete page'; +$string['managepages'] = 'Manage pages'; diff --git a/lib/accesslib.php b/lib/accesslib.php index 4e797246b1614..28600abef2790 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3710,9 +3710,10 @@ function get_context_url($context) { switch ($context->contextlevel) { case CONTEXT_USER: - $url = new moodle_url('/user/view.php', array('id'=>$context->instanceid)); - if ($COURSE->id != SITEID) { - $url->param('courseid', $COURSE->id); + if ($COURSE->id == SITEID) { + $url = new moodle_url('/user/profile.php', array('id'=>$context->instanceid)); + } else { + $url = new moodle_url('/user/view.php', array('id'=>$context->instanceid, 'courseid'=>$COURSE->id)); } return $url;; diff --git a/lib/adminlib.php b/lib/adminlib.php index 4793b6b155745..29c5f079dbef8 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -5854,6 +5854,7 @@ function print_plugin_tables() { 'community', 'completionstatus', 'course_list', + 'course_overview', 'course_summary', 'glossary_random', 'html', @@ -5862,6 +5863,7 @@ function print_plugin_tables() { 'mentees', 'messages', 'mnet_hosts', + 'myprofile', 'navigation', 'news_items', 'online_users', @@ -6895,7 +6897,7 @@ public function output_html($data, $query='') { $iprestriction = $token->iprestriction; } - $userprofilurl = new moodle_url('/user/view.php?id='.$token->userid); + $userprofilurl = new moodle_url('/user/profile.php?id='.$token->userid); $useratag = html_writer::start_tag('a', array('href' => $userprofilurl)); $useratag .= $token->firstname." ".$token->lastname; $useratag .= html_writer::end_tag('a'); diff --git a/lib/blocklib.php b/lib/blocklib.php index 3dd3950549461..da697c11a035b 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -1772,8 +1772,18 @@ function blocks_add_default_course_blocks($course) { * Add the default system-context blocks. E.g. the admin tree. */ function blocks_add_default_system_blocks() { + global $DB; + $page = new moodle_page(); $page->set_context(get_context_instance(CONTEXT_SYSTEM)); $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('navigation', 'settings')), '*', null, true); $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_bookmarks')), 'admin-*', null, null, 2); + + if ($defaultmypage = $DB->get_record('my_pages', array('userid'=>null, 'name'=>'__default', 'private'=>1))) { + $subpagepattern = $defaultmypage->id; + } else { + $subpagepattern = null; + } + + $page->blocks->add_blocks(array(BLOCK_POS_RIGHT => array('myprofile', 'private_files', 'online_users'), 'content' => array('course_overview')), 'my-index', $subpagepattern, false); } diff --git a/lib/db/access.php b/lib/db/access.php index 0197a5e751635..6da12870aec7a 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -493,6 +493,51 @@ ) ), + // can the user manage the system default profile page? + 'moodle/user:managesyspages' => array( + + 'riskbitmap' => RISK_SPAM | RISK_PERSONAL | RISK_CONFIG, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'manager' => CAP_ALLOW + ) + ), + + // can the user manage another user's profile page? + 'moodle/user:manageblocks' => array( + + 'riskbitmap' => RISK_SPAM | RISK_PERSONAL, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_USER + ), + + // can the user manage their own profile page? + 'moodle/user:manageownblocks' => array( + + 'riskbitmap' => RISK_SPAM | RISK_PERSONAL, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'user' => CAP_ALLOW, + ) + ), + + // can the user manage the system default dashboard page? + 'moodle/my:configsyspages' => array( + + 'riskbitmap' => RISK_SPAM | RISK_PERSONAL | RISK_CONFIG, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'legacy' => array( + 'manager' => CAP_ALLOW + ) + ), + 'moodle/role:assign' => array( 'riskbitmask' => RISK_SPAM | RISK_PERSONAL | RISK_XSS, diff --git a/lib/db/install.php b/lib/db/install.php index 848193119eb1c..e7eba9a2459c9 100644 --- a/lib/db/install.php +++ b/lib/db/install.php @@ -262,4 +262,18 @@ function xmldb_main_install() { // Install licenses require_once($CFG->libdir . '/licenselib.php'); license_manager::install_licenses(); + + /// Add two lines of data into this new table + $mypage = new object(); + $mypage->userid = NULL; + $mypage->name = '__default'; + $mypage->private = 0; + $mypage->sortorder = 0; + if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>0))) { + $DB->insert_record('my_pages', $mypage); + } + $mypage->private = 1; + if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>1))) { + $DB->insert_record('my_pages', $mypage); + } } diff --git a/lib/db/install.xml b/lib/db/install.xml index ab13cb0669983..c5baf62657eb4 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -587,7 +587,7 @@ - +
@@ -604,7 +604,22 @@
- +
+ + + + + + + + + + + + + +
+ @@ -2596,4 +2611,4 @@
-
\ No newline at end of file + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index f83ffcfe41fda..b15cdc9339c44 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3928,6 +3928,49 @@ function xmldb_main_upgrade($oldversion) { } + if ($result && $oldversion < 2010050400) { // my_pages for My Moodle and Public Profile pages + + /// Define table my_pages to be created + $table = new xmldb_table('my_pages'); + + /// Adding fields to table my_pages + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, 0); + $table->add_field('name', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null); + $table->add_field('private', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); + $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + + + /// Adding keys to table my_pages + $table->add_key('id', XMLDB_KEY_PRIMARY, array('id')); + + /// Adding indexes to table my_pages + $table->add_index('useridprivate', XMLDB_INDEX_NOTUNIQUE, array('userid', 'private')); + + /// Conditionally launch create table for my_pages + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Add two lines of data into this new table + $mypage = new object(); + $mypage->userid = NULL; + $mypage->name = '__default'; + $mypage->private = 0; + $mypage->sortorder = 0; + if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>0))) { + $result = $result && $DB->insert_record('my_pages', $mypage); + } + $mypage->private = 1; + if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>1))) { + $result = $result && $DB->insert_record('my_pages', $mypage); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2010050400); + } + + return $result; } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 39fcc5f651523..d3f2d5d64e773 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5066,7 +5066,11 @@ function email_welcome_message_to_user($course, $user=NULL) { } else { $a = new object(); $a->coursename = $course->fullname; - $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id"; + if ($course->id == SITEID) { + $a->profileurl = "$CFG->wwwroot/user/profile.php?id=$user->id"; + } else { + $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id"; + } $message = get_string("welcometocoursetext", "", $a); } diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 18cb423f50324..d438812c70bcc 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1251,7 +1251,11 @@ protected function load_for_user($user=null) { // If the user is the current user or has permission to view the details of the requested // user than add a view profile link. if ($iscurrentuser || has_capability('moodle/user:viewdetails', $coursecontext) || has_capability('moodle/user:viewdetails', $usercontext)) { - $usernode->add(get_string('viewprofile'), new moodle_url('/user/view.php',$baseargs)); + if ($issitecourse) { + $usernode->add(get_string('viewprofile'), new moodle_url('/user/profile.php',$baseargs)); + } else { + $usernode->add(get_string('viewprofile'), new moodle_url('/user/view.php',$baseargs)); + } } // Add nodes for forum posts and discussions if the user can view either or both @@ -1263,7 +1267,7 @@ protected function load_for_user($user=null) { $forumtab->add(get_string('posts', 'forum'), new moodle_url('/mod/forum/user.php', $baseargs)); } if ($canviewdiscussions) { - $forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php', array_merge($baseargs, array('mode'=>'discussions')))); + $forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php', array_merge($baseargs, array('mode'=>'discussions', 'course'=>$course->id)))); } } @@ -1290,60 +1294,63 @@ protected function load_for_user($user=null) { } // Add a reports tab and then add reports the the user has permission to see. - $reporttab = $usernode->add(get_string('activityreports')); $anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext); $viewreports = ($anyreport || ($course->showreports && $iscurrentuser)); - $reportargs = array('user'=>$user->id); - if (!empty($course->id)) { - $reportargs['id'] = $course->id; - } else { - $reportargs['id'] = SITEID; - } - if ($viewreports || has_capability('coursereport/outline:view', $coursecontext)) { - $reporttab->add(get_string('outlinereport'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'outline')))); - $reporttab->add(get_string('completereport'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'complete')))); - } + if ($viewreports) { + $reporttab = $usernode->add(get_string('activityreports')); + $reportargs = array('user'=>$user->id); + if (!empty($course->id)) { + $reportargs['id'] = $course->id; + } else { + $reportargs['id'] = SITEID; + } + if ($viewreports || has_capability('coursereport/outline:view', $coursecontext)) { + $reporttab->add(get_string('outlinereport'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'outline')))); + $reporttab->add(get_string('completereport'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'complete')))); + } - if ($viewreports || has_capability('coursereport/log:viewtoday', $coursecontext)) { - $reporttab->add(get_string('todaylogs'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'todaylogs')))); - } + if ($viewreports || has_capability('coursereport/log:viewtoday', $coursecontext)) { + $reporttab->add(get_string('todaylogs'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'todaylogs')))); + } - if ($viewreports || has_capability('coursereport/log:view', $coursecontext)) { - $reporttab->add(get_string('alllogs'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'alllogs')))); - } + if ($viewreports || has_capability('coursereport/log:view', $coursecontext)) { + $reporttab->add(get_string('alllogs'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'alllogs')))); + } - if (!empty($CFG->enablestats)) { - if ($viewreports || has_capability('coursereport/stats:view', $coursecontext)) { - $reporttab->add(get_string('stats'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'stats')))); + if (!empty($CFG->enablestats)) { + if ($viewreports || has_capability('coursereport/stats:view', $coursecontext)) { + $reporttab->add(get_string('stats'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'stats')))); + } } - } - $gradeaccess = false; - if (has_capability('moodle/grade:viewall', $coursecontext)) { - //ok - can view all course grades - $gradeaccess = true; - } else if ($course->showgrades) { - if ($iscurrentuser && has_capability('moodle/grade:view', $coursecontext)) { - //ok - can view own grades - $gradeaccess = true; - } else if (has_capability('moodle/grade:viewall', $usercontext)) { - // ok - can view grades of this user - parent most probably - $gradeaccess = true; - } else if ($anyreport) { - // ok - can view grades of this user - parent most probably + $gradeaccess = false; + if (has_capability('moodle/grade:viewall', $coursecontext)) { + //ok - can view all course grades $gradeaccess = true; + } else if ($course->showgrades) { + if ($iscurrentuser && has_capability('moodle/grade:view', $coursecontext)) { + //ok - can view own grades + $gradeaccess = true; + } else if (has_capability('moodle/grade:viewall', $usercontext)) { + // ok - can view grades of this user - parent most probably + $gradeaccess = true; + } else if ($anyreport) { + // ok - 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_merge($reportargs, array('mode'=>'grade')))); } - } - if ($gradeaccess) { - $reporttab->add(get_string('grade'), new moodle_url('/course/user.php', array_merge($reportargs, array('mode'=>'grade')))); - } - // Check the number of nodes in the report node... if there are none remove - // the node - if (count($reporttab->children)===0) { - $usernode->remove_child($reporttab); + // Check the number of nodes in the report node... if there are none remove + // the node + if (count($reporttab->children)===0) { + $usernode->remove_child($reporttab); + } } + // If the user is the current user add the repositories for the current user if ($iscurrentuser) { require_once($CFG->dirroot . '/repository/lib.php'); @@ -1355,6 +1362,23 @@ protected function load_for_user($user=null) { return true; } + private function add_my_pages($node, $subpages, $baseurl, $defaultname, $baseargs = array()) { + global $CFG; + + foreach($subpages as $page) { + $name = $page->name; + $params = $baseargs; + if ($page->name == '__default') { + $name = $defaultname; + } else { + $params['pageid'] = $page->id; + } + $url = new moodle_url($baseurl, $params); + + $node->add($name, $url, null, null, null, null, false); + } + } + /** * This method simply checks to see if a given module can extend the navigation. * @@ -2686,7 +2710,11 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr $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 - $profileurl = new moodle_url('/user/view.php', array('id'=>$user->id, 'course'=>$course->id)); + if ($course->id == SITEID) { + $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; @@ -2779,11 +2807,18 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr } // Messaging + // TODO this is adding itself to the messaging settings for other people based on one's own setting if (has_capability('moodle/user:editownmessageprofile', $systemcontext)) { $url = new moodle_url('/message/edit.php', array('id'=>$user->id, 'course'=>$course->id)); $usersetting->add(get_string('editmymessage', 'message'), $url, self::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; } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 131b959c6804f..144fa67b81392 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -407,7 +407,8 @@ public function login_info() { $context = get_context_instance(CONTEXT_COURSE, $course->id); $fullname = fullname($USER, true); - $username = "wwwroot/user/view.php?id=$USER->id&course=$course->id\">$fullname"; + // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page) + $username = "wwwroot/user/profile.php?id=$USER->id\">$fullname"; if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) { $username .= " from wwwroot}\">{$idprovider->name}"; } @@ -1675,7 +1676,11 @@ protected function render_user_picture(user_picture $userpicture) { $courseid = $userpicture->courseid; } - $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid)); + if ($courseid == SITEID) { + $url = new moodle_url('/user/profile.php', array('id' => $user->id)); + } else { + $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid)); + } $attributes = array('href'=>$url); diff --git a/lib/tablelib.php b/lib/tablelib.php index 9ceab875eb122..491f2cf4832e0 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -757,10 +757,15 @@ function format_row($row){ */ function col_fullname($row){ global $COURSE, $CFG; - if (!$this->download){ - return ''.fullname($row).''; + if (!$this->download){ + if ($COURSE->id == SITEID) { + return ''. + fullname($row).''; + } else { + return ''.fullname($row).''; + } } else { return fullname($row); } diff --git a/mod/forum/user.php b/mod/forum/user.php index a6b1d081b7531..daa016bb7c481 100644 --- a/mod/forum/user.php +++ b/mod/forum/user.php @@ -94,11 +94,7 @@ $PAGE->set_title("$course->shortname: $fullname: $strmode"); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); - -$currenttab = $mode; -$showroles = 1; -require($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page - +echo $OUTPUT->heading($fullname); switch ($mode) { case 'posts' : diff --git a/my/index.php b/my/index.php index f1254624df78c..bd135c2a1b460 100644 --- a/my/index.php +++ b/my/index.php @@ -1,98 +1,142 @@ dirroot.'/course/lib.php'); - - require_login(); - - $strmymoodle = get_string('mymoodle','my'); - - if (isguestuser()) { - $PAGE->set_title($strmymoodle); - echo $OUTPUT->header(); - echo $OUTPUT->confirm(get_string('noguest', 'my') . '

' . get_string('liketologin'), get_login_url(), $CFG->wwwroot); - echo $OUTPUT->footer(); - die; - } - - $edit = optional_param('edit', -1, PARAM_BOOL); - $blockaction = optional_param('blockaction', '', PARAM_ALPHA); - - $PAGE->set_context(get_context_instance(CONTEXT_USER, $USER->id)); - $PAGE->set_url('/my/index.php'); - $PAGE->set_pagelayout('mydashboard'); +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * My Moodle -- a user's personal dashboard + * + * - each user can currently have their own page (cloned from system and then customised) + * - only the user can see their own dashboard + * - users can add any blocks they want + * - the administrators can define a default site dashboard for users who have + * not created their own dashboard + * + * This script implements the user's view of the dashboard, and allows editing + * of the dashboard. + * + * @package moodlecore + * @subpackage my + * @copyright 2010 Remote-Learner.net + * @author Hubert Chathi + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(__FILE__) . '/../config.php'); +require_once($CFG->dirroot . '/my/lib.php'); + +redirect_if_major_upgrade_required(); + +// TODO Add sesskey check to edit +$edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off + +require_login(); + +$strmymoodle = get_string('myhome'); + +if (isguestuser()) { // Force them to see system default, no editing allowed + $userid = NULL; + $USER->editing = $edit = 0; // Just in case + $context = get_context_instance(CONTEXT_SYSTEM); + $PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); // unlikely :) + $header = "$SITE->shortname: $strmymoodle (GUEST)"; + +} else { // We are trying to view or edit our own My Moodle page + $userid = $USER->id; // Owner of the page + $context = get_context_instance(CONTEXT_USER, $USER->id); $PAGE->set_blocks_editing_capability('moodle/my:manageblocks'); - - if (($edit != -1) and $PAGE->user_allowed_editing()) { - $USER->editing = $edit; + $header = "$SITE->shortname: $strmymoodle"; +} + +// Get the My Moodle page info. Should always return something unless the database is broken. +if (!$currentpage = my_get_page($userid, MY_PAGE_PRIVATE)) { + print_error('mymoodlesetup'); +} + +if (!$currentpage->userid) { + $context = get_context_instance(CONTEXT_SYSTEM); // So we even see non-sticky blocks +} + +// Start setting up the page +$params = array(); +$PAGE->set_context($context); +$PAGE->set_url('/my/index.php', $params); +$PAGE->set_pagelayout('mydashboard'); +$PAGE->set_pagetype('my-index'); +$PAGE->blocks->add_region('content'); +$PAGE->set_subpage($currentpage->id); +$PAGE->set_title($header); +$PAGE->set_heading($header); + +// Toggle the editing state and switches +if ($PAGE->user_allowed_editing()) { + if ($edit !== null) { // Editing state was specified + $USER->editing = $edit; // Change editing state + if (!$currentpage->userid && $edit) { + // If we are viewing a system page as ordinary user, and the user turns + // editing on, copy the system pages as new user pages, and get the + // new page record + if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PRIVATE)) { + print_error('mymoodlesetup'); + } + $context = get_context_instance(CONTEXT_USER, $USER->id); + $PAGE->set_context($context); + $PAGE->set_subpage($currentpage->id); + } + } else { // Editing state is in session + if ($currentpage->userid) { // It's a page we can edit, so load from session + if (!empty($USER->editing)) { + $edit = 1; + } else { + $edit = 0; + } + } else { // It's a system page and they are not allowed to edit system pages + $USER->editing = $edit = 0; // Disable editing completely, just to be safe + } } - if (!empty($USER->editing)) { - $string = get_string('updatemymoodleoff'); - $edit = '0'; + // Add button for editing page + $params = array('edit' => !$edit); + + if (!$currentpage->userid) { + // viewing a system page -- let the user customise it + $editstring = get_string('updatemymoodleon'); + $params['edit'] = 1; + } else if (empty($edit)) { + $editstring = get_string('updatemymoodleon'); } else { - $string = get_string('updatemymoodleon'); - $edit = '1'; + $editstring = get_string('updatemymoodleoff'); } - $url = new moodle_url("$CFG->wwwroot/my/index.php", array('edit' => $edit)); - $button = $OUTPUT->single_button($url, $string); - - $header = $SITE->shortname . ': ' . $strmymoodle; - - $PAGE->set_title($strmymoodle); - $PAGE->set_heading($header); + $url = new moodle_url("$CFG->wwwroot/my/index.php", $params); + $button = $OUTPUT->single_button($url, $editstring); $PAGE->set_button($button); - echo $OUTPUT->header(); - -/// The main overview in the middle of the page - - // limits the number of courses showing up - $courses_limit = 21; - if (isset($CFG->mycoursesperpage)) { - $courses_limit = $CFG->mycoursesperpage; - } - - $morecourses = false; - if ($courses_limit > 0) { - $courses_limit = $courses_limit + 1; - } - - $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit); - $site = get_site(); - $course = $site; //just in case we need the old global $course hack - - if (($courses_limit > 0) && (count($courses) >= $courses_limit)) { - //remove the 'marker' course that we retrieve just to see if we have more than $courses_limit - array_pop($courses); - $morecourses = true; - } +} else { + $USER->editing = $edit = 0; +} - if (array_key_exists($site->id,$courses)) { - unset($courses[$site->id]); - } +// HACK WARNING! This loads up all this page's blocks in the system context +if ($currentpage->userid == 0) { + $CFG->blockmanagerclass = 'my_syspage_block_manager'; +} - foreach ($courses as $c) { - if (isset($USER->lastcourseaccess[$c->id])) { - $courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id]; - } else { - $courses[$c->id]->lastaccess = 0; - } - } - if (empty($courses)) { - echo $OUTPUT->box(get_string('nocourses','my')); - } else { - print_overview($courses); - } - - // if more than 20 courses - if ($morecourses) { - echo '
...'; - } +echo $OUTPUT->header(); - echo $OUTPUT->footer(); +echo $OUTPUT->blocks_for_region('content'); +echo $OUTPUT->footer(); diff --git a/my/indexsys.php b/my/indexsys.php new file mode 100644 index 0000000000000..70577d70d28d8 --- /dev/null +++ b/my/indexsys.php @@ -0,0 +1,111 @@ +. + +/** + * My Moodle -- a user's personal dashboard + * + * - each user can currently have their own page (cloned from system and then customised) + * - only the user can see their own dashboard + * - users can add any blocks they want + * - the administrators can define a default site dashboard for users who have + * not created their own dashboard + * + * This script implements the user's view of the dashboard, and allows editing + * of the dashboard. + * + * @package moodlecore + * @subpackage my + * @copyright 2010 Remote-Learner.net + * @author Hubert Chathi + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(__FILE__) . '/../config.php'); +require_once($CFG->dirroot . '/my/lib.php'); +require_once($CFG->libdir.'/adminlib.php'); + +$edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off + +require_login(); + +$strmymoodle = get_string('myhome'); + +$context = get_context_instance(CONTEXT_SYSTEM); +require_capability('moodle/my:configsyspages', $context); +$PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); +$header = "$SITE->shortname: $strmymoodle (DEFAULT)"; + +// Start setting up the page +$params = array(); +$PAGE->set_url('/my/indexsys.php', $params); +$PAGE->set_pagelayout('mydashboard'); +$PAGE->set_pagetype('my-index'); +$PAGE->set_context($context); +$PAGE->set_title($header); +$PAGE->set_heading($header); +$PAGE->blocks->add_region('content'); + +// TODO: Make the page be selected properly in the Settings block + +// Get the My Moodle page info. Should always return something unless the database is broken. +if (!$currentpage = my_get_page(0, MY_PAGE_PRIVATE)) { + print_error('mymoodlesetup'); +} +$PAGE->set_subpage($currentpage->id); + + +// Toggle the editing state and switches +if ($PAGE->user_allowed_editing()) { + if ($edit !== null) { // Editing state was specified + $USER->editing = $edit; // Change editing state + } else { // Editing state is in session + if (!empty($USER->editing)) { + $edit = 1; + } else { + $edit = 0; + } + } + + // Add button for editing page + $params['edit'] = !$edit; + + if (empty($edit)) { + $editstring = get_string('updatemymoodleon'); + } else { + $editstring = get_string('updatemymoodleoff'); + } + + $url = new moodle_url("$CFG->wwwroot/my/indexsys.php", $params); + $button = $OUTPUT->single_button($url, $editstring); + $PAGE->set_button($button); + +} else { + $USER->editing = $edit = 0; +} + +// HACK WARNING! This loads up all this page's blocks in the system context +if ($currentpage->userid == 0) { + $CFG->blockmanagerclass = 'my_syspage_block_manager'; +} + + +echo $OUTPUT->header(); + +echo $OUTPUT->blocks_for_region('content'); + +echo $OUTPUT->footer(); diff --git a/my/lib.php b/my/lib.php new file mode 100644 index 0000000000000..46183a60a2b11 --- /dev/null +++ b/my/lib.php @@ -0,0 +1,120 @@ +. + +/** + * My Moodle -- a user's personal dashboard + * + * This file contains common functions for the dashboard and profile pages. + * + * @package moodlecore + * @subpackage my + * @copyright 2010 Remote-Learner.net + * @author Hubert Chathi + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define('MY_PAGE_PUBLIC', 0); +define('MY_PAGE_PRIVATE', 1); + +require_once("$CFG->libdir/blocklib.php"); + +/* + * For a given user, this returns the $page information for their My Moodle page + * + */ +function my_get_page($userid, $private=MY_PAGE_PRIVATE) { + global $DB, $CFG; + + if (empty($CFG->forcedefaultmymoodle)) { // We ignore custom My Moodle pages if admin has forced them + // Does the user have their own page defined? If so, return it. + if ($customised = $DB->get_record('my_pages', array('userid' => $userid, 'private' => $private))) { + return $customised; + } + } + + // Otherwise return the system default page + return $DB->get_record('my_pages', array('userid' => null, 'name' => '__default', 'private' => $private)); +} + + +/* + * This copies a system default page to the current user + * + */ +function my_copy_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') { + global $DB; + + if ($customised = $DB->record_exists('my_pages', array('userid' => $userid, 'private' => $private))) { + return $customised; // We're done! + } + + // Get the system default page + if (!$systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => $private))) { + return false; // error + } + + // Clone the basic system page record + $page = clone($systempage); + unset($page->id); + $page->userid = $userid; + if (!$page->id = $DB->insert_record('my_pages', $page)) { + return false; + } + + // Clone ALL the associated blocks as well + $systemcontext = get_context_instance(CONTEXT_SYSTEM); + $usercontext = get_context_instance(CONTEXT_USER, $userid); + + $blockinstances = $DB->get_records('block_instances', array('parentcontextid' => $systemcontext->id, + 'pagetypepattern' => $pagetype, + 'subpagepattern' => $systempage->id)); + foreach ($blockinstances as $instance) { + unset($instance->id); + $instance->parentcontextid = $usercontext->id; + $instance->subpagepattern = $page->id; + if ($instance->id = $DB->insert_record('block_instances', $instance)) { + $blockcontext = get_context_instance(CONTEXT_BLOCK, $instance->id); // Just creates the context record + } + } + + // FIXME: block position overrides should be merged in with block instance + //$blockpositions = $DB->get_records('block_positions', array('subpage' => $page->name)); + //foreach($blockpositions as $positions) { + // $positions->subpage = $page->name; + // $DB->insert_record('block_positions', $tc); + //} + + return $page; +} + +class my_syspage_block_manager extends block_manager { + // HACK WARNING! + // TODO: figure out a better way to do this + /** + * Load blocks using the system context, rather than the user's context. + * + * This is needed because the My Moodle pages set the page context to the + * user's context for access control, etc. But the blocks for the system + * pages are stored in the system context. + */ + public function load_blocks($includeinvisible = null) { + $origcontext = $this->page->context; + $this->page->context = get_context_instance(CONTEXT_SYSTEM); + parent::load_blocks($includeinvisible); + $this->page->context = $origcontext; + } +} diff --git a/notes/edit.php b/notes/edit.php index d2c3f73410d2f..77d6dfc3f72de 100644 --- a/notes/edit.php +++ b/notes/edit.php @@ -29,8 +29,8 @@ $url->param('courseid', $courseid); $url->param('userid', $userid); - if ($publishstate !== NOTES_STATE_PUBLIC) { - $url->param('publishstate', $publishstate); + if ($state !== NOTES_STATE_PUBLIC) { + $url->param('publishstate', $state); } } diff --git a/notes/index.php b/notes/index.php index 2cbb691558837..7f78fb5cd24e2 100644 --- a/notes/index.php +++ b/notes/index.php @@ -89,11 +89,11 @@ $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); -echo $OUTPUT->heading(fullname($user)); - -$showroles = 1; -$currenttab = 'notes'; -require($CFG->dirroot .'/user/tabs.php'); +if ($userid) { + echo $OUTPUT->heading(fullname($user).': '.$strnotes); +} else { + echo $OUTPUT->heading($course->shortname.': '.$strnotes); +} $strsitenotes = get_string('sitenotes', 'notes'); $strcoursenotes = get_string('coursenotes', 'notes'); diff --git a/user/edit.php b/user/edit.php index 37588cf77eb57..0d700116877d1 100644 --- a/user/edit.php +++ b/user/edit.php @@ -252,11 +252,6 @@ echo $OUTPUT->header(); -/// Print tabs at the top -$showroles = 1; -$currenttab = 'editprofile'; -require('tabs.php'); - if ($email_changed) { echo $email_changed_html; } else { diff --git a/user/editadvanced.php b/user/editadvanced.php index afd99a2156db4..d8de0669e4aea 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -259,10 +259,7 @@ $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); - /// Print tabs at the top - $showroles = 1; - $currenttab = 'editprofile'; - require('tabs.php'); + echo $OUTPUT->heading($userfullname); } /// Finally display THE form diff --git a/user/index.php b/user/index.php index cb2e439e23608..d8984ee5c8b27 100644 --- a/user/index.php +++ b/user/index.php @@ -140,6 +140,8 @@ $PAGE->navbar->add(get_string('participants')); $PAGE->set_title("$course->shortname: ".get_string('participants')); $PAGE->set_heading($course->fullname); + $PAGE->set_pagetype('course-view-' . $course->format); + $PAGE->set_other_editing_capability('moodle/course:manageactivities'); echo $OUTPUT->header(); @@ -150,6 +152,7 @@ exit; } + // Should use this variable so that we don't break stuff every time a variable is added or changed. $baseurl = new moodle_url('/user/index.php', array( 'contextid' => $context->id, @@ -169,11 +172,8 @@ $filtertype = 'group'; $filterselect = $currentgroup; } - $currenttab = 'participants'; - $user = $USER; - $userindexpage = true; - require_once($CFG->dirroot .'/user/tabs.php'); + /// Get the hidden field list if (has_capability('moodle/course:viewhiddenuserfields', $context)) { diff --git a/user/profile.php b/user/profile.php new file mode 100644 index 0000000000000..98c2e6fe91f81 --- /dev/null +++ b/user/profile.php @@ -0,0 +1,372 @@ +. + +/** + * Public Profile -- a user's public profile page + * + * - each user can currently have their own page (cloned from system and then customised) + * - users can add any blocks they want + * - the administrators can define a default site public profile for users who have + * not created their own public profile + * + * This script implements the user's view of the public profile, and allows editing + * of the public profile. + * + * @package moodlecore + * @subpackage my + * @copyright 2010 Remote-Learner.net + * @author Hubert Chathi + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(__FILE__) . '/../config.php'); +require_once($CFG->dirroot . '/my/lib.php'); +require_once($CFG->dirroot . '/user/profile/lib.php'); + +$userid = optional_param('id', 0, PARAM_INT); +$edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off + +if (!empty($CFG->forceloginforprofiles)) { + require_login(); + if (isguestuser()) { + redirect(get_login_url()); + } +} else if (!empty($CFG->forcelogin)) { + require_login(); +} + +$userid = $userid ? $userid : $USER->id; // Owner of the page +$user = $DB->get_record('user', array('id' => $userid)); +$currentuser = ($user->id == $USER->id); +$context = $usercontext = get_context_instance(CONTEXT_USER, $userid, MUST_EXIST); + +if (!$currentuser && + !empty($CFG->forceloginforprofiles) && + !has_capability('moodle/user:viewdetails', $context) && + !has_coursemanager_role($userid)) { + // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366) + $struser = get_string('user'); + $PAGE->set_title("$SITE->shortname: $struser"); + $PAGE->set_heading("$SITE->shortname: $struser"); + $PAGE->set_url('/user/profile.php', array('id'=>$userid)); + $PAGE->navbar->add($struser); + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('usernotavailable', 'error')); + echo $OUTPUT->footer(); + exit; +} + +// Get the profile page. Should always return something unless the database is broken. +if (!$currentpage = my_get_page($userid, MY_PAGE_PUBLIC)) { + print_error('mymoodlesetup'); +} + +if (!$currentpage->userid) { + $context = get_context_instance(CONTEXT_SYSTEM); // A trick so that we even see non-sticky blocks +} + +$PAGE->set_context($context); +$PAGE->set_pagelayout('mydashboard'); +$PAGE->set_pagetype('user-profile'); + +// Set up block editing capabilities +if (isguestuser()) { // Guests can never edit their profile + $USER->editing = $edit = 0; // Just in case + $PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); // unlikely :) +} else { + if ($currentuser) { + $PAGE->set_blocks_editing_capability('moodle/user:manageownblocks'); + } else { + $PAGE->set_blocks_editing_capability('moodle/user:manageblocks'); + } +} + + + +// Start setting up the page +$strpublicprofile = get_string('publicprofile'); + +$params = array('id'=>$userid); +$PAGE->set_url('/user/profile.php', $params); +$PAGE->blocks->add_region('content'); +$PAGE->set_subpage($currentpage->id); +$PAGE->set_title("$SITE->shortname: $strpublicprofile"); +$PAGE->set_heading("$SITE->shortname: $strpublicprofile"); +$PAGE->navigation->extend_for_user($user); + + +// Toggle the editing state and switches +if ($PAGE->user_allowed_editing()) { + if ($edit !== null) { // Editing state was specified + $USER->editing = $edit; // Change editing state + if (!$currentpage->userid && $edit) { + // If we are viewing a system page as ordinary user, and the user turns + // editing on, copy the system pages as new user pages, and get the + // new page record + if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PUBLIC, 'user-profile')) { + print_error('mymoodlesetup'); + } + $PAGE->set_context($usercontext); + $PAGE->set_subpage($currentpage->id); + } + } else { // Editing state is in session + if ($currentpage->userid) { // It's a page we can edit, so load from session + if (!empty($USER->editing)) { + $edit = 1; + } else { + $edit = 0; + } + } else { // It's a system page and they are not allowed to edit system pages + $USER->editing = $edit = 0; // Disable editing completely, just to be safe + } + } + + // Add button for editing page + $params = array('edit' => !$edit); + + if (!$currentpage->userid) { + // viewing a system page -- let the user customise it + $editstring = get_string('updatemymoodleon'); + $params['edit'] = 1; + } else if (empty($edit)) { + $editstring = get_string('updatemymoodleon'); + } else { + $editstring = get_string('updatemymoodleoff'); + } + + $url = new moodle_url("$CFG->wwwroot/user/profile.php", $params); + $button = $OUTPUT->single_button($url, $editstring); + $PAGE->set_button($button); + +} else { + $USER->editing = $edit = 0; +} + +// HACK WARNING! This loads up all this page's blocks in the system context +if ($currentpage->userid == 0) { + $CFG->blockmanagerclass = 'my_syspage_block_manager'; +} + +// TODO WORK OUT WHERE THE NAV BAR IS! +echo $OUTPUT->header(); + + +// Print the standard content of this page, the basic profile info + +echo $OUTPUT->heading(fullname($user)); + +if (is_mnet_remote_user($user)) { + $sql = " + SELECT DISTINCT h.id, h.name, h.wwwroot, + a.name as application, a.display_name + FROM {mnet_host} h, {mnet_application} a + WHERE h.id = ? AND h.applicationid = a.id + ORDER BY a.display_name, h.name"; + + $remotehost = $DB->get_record_sql($sql, array($user->mnethostid)); + + echo '

'.get_string('remoteappuser', $remotehost->application)."
\n"; + if ($currentuser) { + if ($remotehost->application =='moodle') { + echo "Remote {$remotehost->display_name}: wwwroot}/user/edit.php\">{$remotehost->name} ".get_string('editremoteprofile')."

\n"; + } else { + echo "Remote {$remotehost->display_name}: wwwroot}/\">{$remotehost->name} ".get_string('gotoyourserver')."

\n"; + } + } else { + echo "Remote {$remotehost->display_name}: wwwroot}/\">{$remotehost->name}

\n"; + } +} + +echo '
'; +echo $OUTPUT->user_picture($user, array('size'=>100)); +echo '
'; + +echo '
'; +// Print the description + +if ($user->description && !isset($hiddenfields['description'])) { + if (!empty($CFG->profilesforenrolledusersonly) && !$currentuser && !$DB->record_exists('role_assignments', array('userid'=>$user->id))) { + echo get_string('profilenotshown', 'moodle'); + } else { + $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user_profile', $user->id); + echo format_text($user->description, $user->descriptionformat); + } +} +echo '
'; + +// Print all the little details in a list + +echo ''; + +if (! isset($hiddenfields['country']) && $user->country) { + print_row(get_string('country') . ':', get_string($user->country, 'countries')); +} + +if (! isset($hiddenfields['city']) && $user->city) { + print_row(get_string('city') . ':', $user->city); +} + +if (has_capability('moodle/user:viewhiddendetails', $context)) { + if ($user->address) { + print_row(get_string("address").":", "$user->address"); + } + if ($user->phone1) { + print_row(get_string("phone").":", "$user->phone1"); + } + if ($user->phone2) { + print_row(get_string("phone2").":", "$user->phone2"); + } +} + +if ($user->maildisplay == 1 + or ($user->maildisplay == 2 && !isguestuser()) + or has_capability('moodle/course:useremail', $context)) { + + $emailswitch = ''; + + if ($currentuser or has_capability('moodle/course:useremail', $context)) { /// Can use the enable/disable email stuff + if (!empty($enable) and confirm_sesskey()) { /// Recieved a parameter to enable the email address + $DB->set_field('user', 'emailstop', 0, array('id'=>$user->id)); + $user->emailstop = 0; + } + if (!empty($disable) and confirm_sesskey()) { /// Recieved a parameter to disable the email address + $DB->set_field('user', 'emailstop', 1, array('id'=>$user->id)); + $user->emailstop = 1; + } + } + + if (has_capability('moodle/course:useremail', $context)) { /// Can use the enable/disable email stuff + if ($user->emailstop) { + $switchparam = 'enable'; + $switchtitle = get_string('emaildisable'); + $switchclick = get_string('emailenableclick'); + $switchpix = 't/emailno'; + } else { + $switchparam = 'disable'; + $switchtitle = get_string('emailenable'); + $switchclick = get_string('emaildisableclick'); + $switchpix = 't/email'; + } + $emailswitch = " id&$switchparam=1&sesskey=".sesskey()."\">". + "pix_url("$switchpix") . "\" alt=\"$switchclick\" />"; + + } else if ($currentuser) { /// Can only re-enable an email this way + if ($user->emailstop) { // Include link that tells how to re-enable their email + $switchparam = 'enable'; + $switchtitle = get_string('emaildisable'); + $switchclick = get_string('emailenableclick'); + + $emailswitch = " (id&enable=1&sesskey=".sesskey()."\">$switchtitle)"; + } + } + + print_row(get_string("email").":", obfuscate_mailto($user->email, '', $user->emailstop)."$emailswitch"); +} + +if ($user->url && !isset($hiddenfields['webpage'])) { + $url = $user->url; + if (strpos($user->url, '://') === false) { + $url = 'http://'. $url; + } + print_row(get_string("webpage") .":", ''.s($user->url).''); +} + +if ($user->icq && !isset($hiddenfields['icqnumber'])) { + print_row(get_string('icqnumber').':',"icq)."\">".s($user->icq)." icq)."&img=5\" alt=\"\" />"); +} + +if ($user->skype && !isset($hiddenfields['skypeid'])) { + print_row(get_string('skypeid').':',''.s($user->skype). + ' '.get_string('status').''); +} +if ($user->yahoo && !isset($hiddenfields['yahooid'])) { + print_row(get_string('yahooid').':', ''.s($user->yahoo)." yahoo)."&m=g&t=0\" alt=\"\">"); +} +if ($user->aim && !isset($hiddenfields['aimid'])) { + print_row(get_string('aimid').':', ''.s($user->aim).''); +} +if ($user->msn && !isset($hiddenfields['msnid'])) { + print_row(get_string('msnid').':', s($user->msn)); +} + +/// Print the Custom User Fields +profile_display_fields($user->id); + + +if (!isset($hiddenfields['mycourses'])) { + if ($mycourses = get_my_courses($user->id, 'visible DESC,sortorder ASC', null, false, 21)) { + $shown=0; + $courselisting = ''; + foreach ($mycourses as $mycourse) { + if ($mycourse->category) { + $class = ''; + if ($mycourse->visible == 0) { + // get_my_courses will filter courses $USER cannot see + // if we get one with visible 0 it just means it's hidden + // ... but not from $USER + $class = 'class="dimmed"'; + } + $courselisting .= "wwwroot}/user/view.php?id={$user->id}&course={$mycourse->id}\" $class >" . format_string($mycourse->fullname) . ", "; + } + $shown++; + if($shown==20) { + $courselisting.= "..."; + break; + } + } + print_row(get_string('courseprofiles').':', rtrim($courselisting,', ')); + } +} +if (!isset($hiddenfields['firstaccess'])) { + if ($user->firstaccess) { + $datestring = userdate($user->firstaccess)."  (".format_time(time() - $user->firstaccess).")"; + } else { + $datestring = get_string("never"); + } + print_row(get_string("firstaccess").":", $datestring); +} +if (!isset($hiddenfields['lastaccess'])) { + if ($user->lastaccess) { + $datestring = userdate($user->lastaccess)."  (".format_time(time() - $user->lastaccess).")"; + } else { + $datestring = get_string("never"); + } + print_row(get_string("lastaccess").":", $datestring); +} + +/// Printing tagged interests +if (!empty($CFG->usetags)) { + if ($interests = tag_get_tags_csv('user', $user->id) ) { + print_row(get_string('interests') .": ", $interests); + } +} + +echo "
"; + + +echo $OUTPUT->blocks_for_region('content'); + +echo $OUTPUT->footer(); + + +function print_row($left, $right) { + echo "\n$left$right\n"; +} diff --git a/user/profilesys.php b/user/profilesys.php new file mode 100644 index 0000000000000..f551f0d7a5782 --- /dev/null +++ b/user/profilesys.php @@ -0,0 +1,108 @@ +. + +/** + * System Public Profile. + * + * This script allows the site administrator to edit the default site + * profile. + * + * @package moodlecore + * @subpackage my + * @copyright 2010 Remote-Learner.net + * @author Hubert Chathi + * @author Olav Jordan + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(dirname(__FILE__) . '/../config.php'); +require_once($CFG->dirroot . '/my/lib.php'); +require_once($CFG->libdir.'/adminlib.php'); + +$edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off + +require_login(); + +$strpublicprofile = get_string('publicprofile'); + +$context = get_context_instance(CONTEXT_SYSTEM); +require_capability('moodle/my:configsyspages', $context); +$PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); +$header = "$SITE->shortname: $strpublicprofile (DEFAULT)"; + +// Start setting up the page +$params = array(); +$PAGE->set_url('/user/profilesys.php', $params); +$PAGE->set_pagelayout('mydashboard'); +$PAGE->set_pagetype('user-profile'); +$PAGE->set_context($context); +$PAGE->set_title($header); +$PAGE->set_heading($header); +$PAGE->blocks->add_region('content'); + +// TODO: Make the page be selected properly in the Settings block + +// Get the Public Profile page info. Should always return something unless the database is broken. +if (!$currentpage = my_get_page(0, MY_PAGE_PUBLIC)) { + print_error('publicprofilesetup'); +} +$PAGE->set_subpage($currentpage->id); + + +// Toggle the editing state and switches +if ($PAGE->user_allowed_editing()) { + if ($edit !== null) { // Editing state was specified + $USER->editing = $edit; // Change editing state + } else { // Editing state is in session + if (!empty($USER->editing)) { + $edit = 1; + } else { + $edit = 0; + } + } + + // Add button for editing page + $params['edit'] = !$edit; + + if (empty($edit)) { + $editstring = get_string('updatemymoodleon'); + } else { + $editstring = get_string('updatemymoodleoff'); + } + + $url = new moodle_url("$CFG->wwwroot/my/profilesys.php", $params); + $button = $OUTPUT->single_button($url, $editstring); + $PAGE->set_button($button); + +} else { + $USER->editing = $edit = 0; +} + +// HACK WARNING! This loads up all this page's blocks in the system context +if ($currentpage->userid == 0) { + $CFG->blockmanagerclass = 'my_syspage_block_manager'; +} + + +echo $OUTPUT->header(); + +echo $OUTPUT->blocks_for_region('content'); + +print_object($currentpage); +print_object($context); + +echo $OUTPUT->footer(); diff --git a/user/view.php b/user/view.php index 782e85c3da9ba..337d07990c8ea 100644 --- a/user/view.php +++ b/user/view.php @@ -32,22 +32,25 @@ $enable = optional_param('enable', 0, PARAM_BOOL); // enable email $disable = optional_param('disable', 0, PARAM_BOOL); // disable email -if (empty($id)) { // See your own profile by default +if (empty($id)) { // See your own profile by default require_login(); $id = $USER->id; } -$url = new moodle_url('/user/view.php', array('id'=>$id)); -if ($courseid != SITEID) { - $url->param('course', $courseid); +if ($courseid == SITEID) { // Since Moodle 2.0 all site-level profiles are shown by profile.php + redirect($CFG->wwwroot.'/user/profile.php?id='.$id); // Immediate redirect } + +$url = new moodle_url('/user/view.php', array('id'=>$id,'course'=>$courseid)); $PAGE->set_url($url); $user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST); $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); +$currentuser = ($user->id == $USER->id); $systemcontext = get_context_instance(CONTEXT_SYSTEM); -$usercontext = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST); +$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); +$usercontext = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST); // Require login first if (isguestuser($user)) { @@ -55,31 +58,13 @@ print_error('invaliduserid'); } -$currentuser = ($user->id == $USER->id); - -if ($course->id == SITEID) { - $isfrontpage = true; - // do not use frontpage course context because there is no frontpage profile, instead it is the site profile - $coursecontext = $systemcontext; -} else { - $isfrontpage = false; - $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); -} - -$PAGE->set_context($usercontext); +$PAGE->set_context($coursecontext); +$PAGE->set_pagetype('course-view-' . $course->format); +$PAGE->set_other_editing_capability('moodle/course:manageactivities'); $isparent = false; -if ($isfrontpage) { - if (!empty($CFG->forceloginforprofiles)) { - require_login(); - if (isguestuser()) { - redirect(get_login_url()); - } - } else if (!empty($CFG->forcelogin)) { - require_login(); - } -} else if (!$currentuser +if (!$currentuser and $DB->record_exists('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id)) and has_capability('moodle/user:viewdetails', $usercontext)) { // TODO: very ugly hack - do not force "parents" to enrol into course their child is enrolled in, @@ -104,7 +89,7 @@ /// Now test the actual capabilities and enrolment in course if ($currentuser) { // me - if (!$isfrontpage and !is_enrolled($coursecontext) and !is_viewing($coursecontext)) { // Need to have full access to a course to see the rest of own info + if (!is_enrolled($coursecontext) and !is_viewing($coursecontext)) { // Need to have full access to a course to see the rest of own info echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('notenrolled', '', $fullname)); if (!empty($_SERVER['HTTP_REFERER'])) { @@ -119,43 +104,30 @@ $PAGE->set_title("$strpersonalprofile: "); $PAGE->set_heading("$strpersonalprofile: "); - if ($isfrontpage) { - // Reduce possibility of "browsing" userbase at site level - if (!empty($CFG->forceloginforprofiles) and !has_capability('moodle/user:viewdetails', $usercontext) and !has_coursemanager_role($user->id)) { - // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366) - $PAGE->navbar->add($struser); - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('usernotavailable', 'error')); - echo $OUTPUT->footer(); - exit; - } + // check course level capabilities + if (!has_capability('moodle/user:viewdetails', $coursecontext) && // normal enrolled user or mnager + !has_capability('moodle/user:viewdetails', $usercontext)) { // usually parent + print_error('cannotviewprofile'); + } - } else { - // check course level capabilities - if (!has_capability('moodle/user:viewdetails', $coursecontext) && // normal enrolled user or mnager - !has_capability('moodle/user:viewdetails', $usercontext)) { // usually parent - print_error('cannotviewprofile'); + if (!is_enrolled($coursecontext, $user->id)) { + // TODO: the only potential problem is that managers and inspectors might post in forum, but the link + // to profile would not work - maybe a new capability - moodle/user:freely_acessile_profile_for_anybody + // or test for course:inspect capability + if (has_capability('moodle/role:assign', $coursecontext)) { + $PAGE->navbar->add($fullname); + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('notenrolled', '', $fullname)); + } else { + echo $OUTPUT->header(); + $PAGE->navbar->add($struser); + echo $OUTPUT->heading(get_string('notenrolledprofile')); } - - if (!is_enrolled($coursecontext, $user->id)) { - // TODO: the only potential problem is that managers and inspectors might post in forum, but the link - // to profile would not work - maybe a new capability - moodle/user:freely_acessile_profile_for_anybody - // or test for course:inspect capability - if (has_capability('moodle/role:assign', $coursecontext)) { - $PAGE->navbar->add($fullname); - echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('notenrolled', '', $fullname)); - } else { - echo $OUTPUT->header(); - $PAGE->navbar->add($struser); - echo $OUTPUT->heading(get_string('notenrolledprofile')); - } - if (!empty($_SERVER['HTTP_REFERER'])) { - echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']); - } - echo $OUTPUT->footer(); - exit; + if (!empty($_SERVER['HTTP_REFERER'])) { + echo $OUTPUT->continue_button($_SERVER['HTTP_REFERER']); } + echo $OUTPUT->footer(); + exit; } // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group @@ -181,6 +153,7 @@ $PAGE->set_heading($course->fullname); $PAGE->set_pagelayout('standard'); echo $OUTPUT->header(); +echo $OUTPUT->heading(fullname($user)); if ($user->deleted) { echo $OUTPUT->heading(get_string('userdeleted')); @@ -194,11 +167,9 @@ add_to_log($course->id, "user", "view", "view.php?id=$user->id&course=$course->id", "$user->id"); -if (!$isfrontpage) { - $user->lastaccess = false; - if ($lastaccess = $DB->get_record('user_lastaccess', array('userid'=>$user->id, 'courseid'=>$course->id))) { - $user->lastaccess = $lastaccess->timeaccess; - } +$user->lastaccess = false; +if ($lastaccess = $DB->get_record('user_lastaccess', array('userid'=>$user->id, 'courseid'=>$course->id))) { + $user->lastaccess = $lastaccess->timeaccess; } @@ -209,18 +180,6 @@ $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); } -/// Print tabs at top -/// This same call is made in: -/// /user/view.php -/// /user/edit.php -/// /course/user.php - -$currenttab = 'profile'; -$showroles = 1; -if (!$user->deleted) { - include('tabs.php'); -} - if (is_mnet_remote_user($user)) { $sql = " SELECT DISTINCT h.id, h.name, h.wwwroot, @@ -243,30 +202,33 @@ } } -echo ''; -echo ''; -echo '
'; -echo $OUTPUT->user_picture($user, array('courseid'=>$course->id, 'size'=>100)); -echo ''; +echo ''; -// Print the description +echo '
'; +echo $OUTPUT->user_picture($user, array('size'=>100)); +echo '
'; +// Print the description +echo '
'; if ($user->description && !isset($hiddenfields['description'])) { - if (!$isfrontpage && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid'=>$id))) { + if (!empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid'=>$id))) { echo get_string('profilenotshown', 'moodle').'
'; } else { $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $usercontext->id, 'user_profile', $id); echo format_text($user->description, $user->descriptionformat)."
"; } } +echo '
'; + // Print all the little details in a list -echo ''; +echo '
'; if (! isset($hiddenfields['country']) && $user->country) { - $countries = get_string_manager()->get_list_of_countries(); - print_row(get_string('country') . ':', $countries[$user->country]); + print_row(get_string('country') . ':', get_string($user->country, 'countries')); } if (! isset($hiddenfields['city']) && $user->city) { @@ -286,7 +248,7 @@ } if ($user->maildisplay == 1 - or ($user->maildisplay == 2 and !$isfrontpage and !isguestuser()) + or ($user->maildisplay == 2 && !isguestuser()) or has_capability('moodle/course:useremail', $coursecontext)) { $emailswitch = ''; @@ -337,7 +299,7 @@ if (strpos($user->url, '://') === false) { $url = 'http://'. $url; } - print_row(get_string("webpage") .":", ''.s($user->url).''); + print_row(get_string('webpage') .':', ''.s($user->url).''); } if ($user->icq && !isset($hiddenfields['icqnumber'])) { @@ -390,7 +352,7 @@ break; } } - print_row(get_string('courses').':', rtrim($courselisting,', ')); + print_row(get_string('courseprofiles').':', rtrim($courselisting,', ')); } } if (!isset($hiddenfields['firstaccess'])) { @@ -439,8 +401,6 @@ echo "
"; -echo "
"; - $userauth = get_auth_plugin($user->auth); $passwordchangeurl = false; @@ -454,107 +414,10 @@ } } -// Print other functions -echo '
'; - -if ($passwordchangeurl) { - $params = array('id'=>$course->id); - - if (session_is_loggedinas()) { - $passwordchangeurl = ''; // do not use actual change password url - might contain sensitive data - } else { - $parts = explode('?', $passwordchangeurl); - $passwordchangeurl = reset($parts); - $after = next($parts); - preg_match_all('/([^&=]+)=([^&=]+)/', $after, $matches); - if (count($matches)) { - foreach($matches[0] as $key=>$match) { - $params[$matches[1][$key]] = $matches[2][$key]; - } - } - } - echo "
"; - echo "
"; - foreach($params as $key=>$value) { - echo ''; - } - if (session_is_loggedinas()) { - // changing of password when "Logged in as" is not allowed - echo ""; - } else { - echo ""; - } - echo "
"; - echo "
"; -} - -if (!$isfrontpage && empty($course->metacourse)) { // Mostly only useful at course level - - if ($currentuser) { - if (is_enrolled($coursecontext, NULL, 'moodle/role:unassignself')) { - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; - } - } else { - if (is_enrolled($coursecontext, $user->id, 'moodle/role:assign')) { // I can unassign roles - // add some button to unenroll user - } - } -} - -if (!$user->deleted and !$currentuser && !session_is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) && !is_siteadmin($user->id)) { - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
'; -} - -if (!$user->deleted and !empty($CFG->messaging) and !isguestuser() and has_capability('moodle/site:sendmessage', $systemcontext)) { - if (isloggedin() and $currentuser) { - if ($countmessages = $DB->count_records('message', array('useridto'=>$user->id))) { - $messagebuttonname = get_string("messages", "message")."($countmessages)"; - } else { - $messagebuttonname = get_string("messages", "message"); - } - echo "
"; - echo "
"; - echo ""; - echo "
"; - echo "
"; - } else { - echo "
id'\" action=\"../message/discussion.php\" method=\"get\">"; - echo "
"; - echo "id\" />"; - echo "id', 'message_$user->id', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\" />"; - echo "
"; - echo "
"; - } -} - -// Authorize.net: User Payments -// TODO: replace this hack with proper callback into all plugins -if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize')) { - echo "
"; - echo "
"; - echo "id\" />"; - echo "id\" />"; - echo ""; - echo "
"; - echo "
"; -} -echo "
\n"; +// Buttons gone! TODO: Make sure there's a good way to message someone from the profile pages if ($CFG->debugdisplay && debugging('', DEBUG_DEVELOPER) && $currentuser) { // Show user object - echo '
'; + echo '


'; echo $OUTPUT->heading('DEBUG MODE: User session variables'); print_object($USER); } diff --git a/version.php b/version.php index 891d51ec70c40..747637f3b5966 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2010050300; // YYYYMMDD = date of the last version bump + $version = 2010050400; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20100504)'; // Human-friendly version name