Automatically generated installer lang files
[moodle.git] / my / index.php
CommitLineData
1d422980 1<?php
0d6b9d4f 2
03d9401e
MD
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * My Moodle -- a user's personal dashboard
20 *
21 * - each user can currently have their own page (cloned from system and then customised)
22 * - only the user can see their own dashboard
23 * - users can add any blocks they want
24 * - the administrators can define a default site dashboard for users who have
25 * not created their own dashboard
26 *
27 * This script implements the user's view of the dashboard, and allows editing
28 * of the dashboard.
29 *
30 * @package moodlecore
31 * @subpackage my
32 * @copyright 2010 Remote-Learner.net
33 * @author Hubert Chathi <hubert@remote-learner.net>
34 * @author Olav Jordan <olav.jordan@remote-learner.net>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37
38require_once(dirname(__FILE__) . '/../config.php');
39require_once($CFG->dirroot . '/my/lib.php');
40
41redirect_if_major_upgrade_required();
42
43// TODO Add sesskey check to edit
44$edit = optional_param('edit', null, PARAM_BOOL); // Turn editing on and off
45
46require_login();
47
48$strmymoodle = get_string('myhome');
49
50if (isguestuser()) { // Force them to see system default, no editing allowed
51 $userid = NULL;
52 $USER->editing = $edit = 0; // Just in case
53 $context = get_context_instance(CONTEXT_SYSTEM);
54 $PAGE->set_blocks_editing_capability('moodle/my:configsyspages'); // unlikely :)
55 $header = "$SITE->shortname: $strmymoodle (GUEST)";
56
57} else { // We are trying to view or edit our own My Moodle page
58 $userid = $USER->id; // Owner of the page
59 $context = get_context_instance(CONTEXT_USER, $USER->id);
cfcfb9f3 60 $PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
03d9401e
MD
61 $header = "$SITE->shortname: $strmymoodle";
62}
63
64// Get the My Moodle page info. Should always return something unless the database is broken.
65if (!$currentpage = my_get_page($userid, MY_PAGE_PRIVATE)) {
66 print_error('mymoodlesetup');
67}
68
69if (!$currentpage->userid) {
70 $context = get_context_instance(CONTEXT_SYSTEM); // So we even see non-sticky blocks
71}
72
73// Start setting up the page
74$params = array();
75$PAGE->set_context($context);
76$PAGE->set_url('/my/index.php', $params);
77$PAGE->set_pagelayout('mydashboard');
78$PAGE->set_pagetype('my-index');
79$PAGE->blocks->add_region('content');
80$PAGE->set_subpage($currentpage->id);
81$PAGE->set_title($header);
82$PAGE->set_heading($header);
83
e7f72fb5
IT
84if (!isguestuser()) { // Skip default home page for guests
85 if (get_home_page() != HOMEPAGE_MY) {
86 if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
87 set_user_preference('user_home_page_preference', HOMEPAGE_MY);
88 } else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) {
89 $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/my/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
90 }
4766a50c
SH
91 }
92}
93
03d9401e
MD
94// Toggle the editing state and switches
95if ($PAGE->user_allowed_editing()) {
96 if ($edit !== null) { // Editing state was specified
97 $USER->editing = $edit; // Change editing state
98 if (!$currentpage->userid && $edit) {
99 // If we are viewing a system page as ordinary user, and the user turns
100 // editing on, copy the system pages as new user pages, and get the
101 // new page record
102 if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PRIVATE)) {
103 print_error('mymoodlesetup');
104 }
105 $context = get_context_instance(CONTEXT_USER, $USER->id);
106 $PAGE->set_context($context);
107 $PAGE->set_subpage($currentpage->id);
108 }
109 } else { // Editing state is in session
110 if ($currentpage->userid) { // It's a page we can edit, so load from session
111 if (!empty($USER->editing)) {
112 $edit = 1;
113 } else {
114 $edit = 0;
115 }
116 } else { // It's a system page and they are not allowed to edit system pages
117 $USER->editing = $edit = 0; // Disable editing completely, just to be safe
118 }
0d6b9d4f 119 }
120
03d9401e
MD
121 // Add button for editing page
122 $params = array('edit' => !$edit);
123
124 if (!$currentpage->userid) {
125 // viewing a system page -- let the user customise it
126 $editstring = get_string('updatemymoodleon');
127 $params['edit'] = 1;
128 } else if (empty($edit)) {
129 $editstring = get_string('updatemymoodleon');
7527a2f0 130 } else {
03d9401e 131 $editstring = get_string('updatemymoodleoff');
7527a2f0 132 }
133
03d9401e
MD
134 $url = new moodle_url("$CFG->wwwroot/my/index.php", $params);
135 $button = $OUTPUT->single_button($url, $editstring);
609adb68 136 $PAGE->set_button($button);
e84a97b8 137
03d9401e
MD
138} else {
139 $USER->editing = $edit = 0;
140}
e84a97b8 141
03d9401e
MD
142// HACK WARNING! This loads up all this page's blocks in the system context
143if ($currentpage->userid == 0) {
144 $CFG->blockmanagerclass = 'my_syspage_block_manager';
145}
3131d5c6 146
d4a03c00 147
03d9401e 148echo $OUTPUT->header();
0d6b9d4f 149
03d9401e 150echo $OUTPUT->blocks_for_region('content');
0d6b9d4f 151
03d9401e 152echo $OUTPUT->footer();