Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/my/index.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00038 require_once(dirname(__FILE__) . '/../config.php');
00039 require_once($CFG->dirroot . '/my/lib.php');
00040 
00041 redirect_if_major_upgrade_required();
00042 
00043 // TODO Add sesskey check to edit
00044 $edit   = optional_param('edit', null, PARAM_BOOL);    // Turn editing on and off
00045 
00046 require_login();
00047 
00048 $strmymoodle = get_string('myhome');
00049 
00050 if (isguestuser()) {  // Force them to see system default, no editing allowed
00051     $userid = NULL; 
00052     $USER->editing = $edit = 0;  // Just in case
00053     $context = get_context_instance(CONTEXT_SYSTEM);
00054     $PAGE->set_blocks_editing_capability('moodle/my:configsyspages');  // unlikely :)
00055     $header = "$SITE->shortname: $strmymoodle (GUEST)";
00056 
00057 } else {        // We are trying to view or edit our own My Moodle page
00058     $userid = $USER->id;  // Owner of the page
00059     $context = get_context_instance(CONTEXT_USER, $USER->id);
00060     $PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
00061     $header = "$SITE->shortname: $strmymoodle";
00062 }
00063 
00064 // Get the My Moodle page info.  Should always return something unless the database is broken.
00065 if (!$currentpage = my_get_page($userid, MY_PAGE_PRIVATE)) {
00066     print_error('mymoodlesetup');
00067 }
00068 
00069 if (!$currentpage->userid) {
00070     $context = get_context_instance(CONTEXT_SYSTEM);  // So we even see non-sticky blocks
00071 }
00072 
00073 // Start setting up the page
00074 $params = array();
00075 $PAGE->set_context($context);
00076 $PAGE->set_url('/my/index.php', $params);
00077 $PAGE->set_pagelayout('mydashboard');
00078 $PAGE->set_pagetype('my-index');
00079 $PAGE->blocks->add_region('content');
00080 $PAGE->set_subpage($currentpage->id);
00081 $PAGE->set_title($header);
00082 $PAGE->set_heading($header);
00083 
00084 if (get_home_page() != HOMEPAGE_MY) {
00085     if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
00086         set_user_preference('user_home_page_preference', HOMEPAGE_MY);
00087     } else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) {
00088         $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/my/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
00089     }
00090 }
00091 
00092 // Toggle the editing state and switches
00093 if ($PAGE->user_allowed_editing()) {
00094     if ($edit !== null) {             // Editing state was specified
00095         $USER->editing = $edit;       // Change editing state
00096         if (!$currentpage->userid && $edit) {
00097             // If we are viewing a system page as ordinary user, and the user turns
00098             // editing on, copy the system pages as new user pages, and get the
00099             // new page record
00100             if (!$currentpage = my_copy_page($USER->id, MY_PAGE_PRIVATE)) {
00101                 print_error('mymoodlesetup');
00102             }
00103             $context = get_context_instance(CONTEXT_USER, $USER->id);
00104             $PAGE->set_context($context);
00105             $PAGE->set_subpage($currentpage->id);
00106         }
00107     } else {                          // Editing state is in session
00108         if ($currentpage->userid) {   // It's a page we can edit, so load from session
00109             if (!empty($USER->editing)) {
00110                 $edit = 1;
00111             } else {
00112                 $edit = 0;
00113             }
00114         } else {                      // It's a system page and they are not allowed to edit system pages
00115             $USER->editing = $edit = 0;          // Disable editing completely, just to be safe
00116         }
00117     }
00118 
00119     // Add button for editing page
00120     $params = array('edit' => !$edit);
00121 
00122     if (!$currentpage->userid) {
00123         // viewing a system page -- let the user customise it
00124         $editstring = get_string('updatemymoodleon');
00125         $params['edit'] = 1;
00126     } else if (empty($edit)) {
00127         $editstring = get_string('updatemymoodleon');
00128     } else {
00129         $editstring = get_string('updatemymoodleoff');
00130     }
00131 
00132     $url = new moodle_url("$CFG->wwwroot/my/index.php", $params);
00133     $button = $OUTPUT->single_button($url, $editstring);
00134     $PAGE->set_button($button);
00135 
00136 } else {
00137     $USER->editing = $edit = 0;
00138 }
00139 
00140 // HACK WARNING!  This loads up all this page's blocks in the system context
00141 if ($currentpage->userid == 0) {
00142     $CFG->blockmanagerclass = 'my_syspage_block_manager';
00143 }
00144 
00145 
00146 echo $OUTPUT->header();
00147 
00148 echo $OUTPUT->blocks_for_region('content');
00149 
00150 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations