MDL-8352 Fully separate CONTEXT_COURSE, SITEID from COURSE_SYSTEM - first part of cleanup related to frontpage
$adminroot = admin_get_root();
admin_externalpage_setup('assignroles', $adminroot);
admin_externalpage_print_header($adminroot);
+ } else if ($context->contextlevel==CONTEXT_COURSE and $context->instanceid == SITEID) {
+ $adminroot = admin_get_root();
+ admin_externalpage_setup('frontpageroles', $adminroot);
+ admin_externalpage_print_header($adminroot);
+ $currenttab = '';
+ $tabsmode = 'assign';
+ include_once('tabs.php');
} else {
$currenttab = '';
$tabsmode = 'assign';
}
}
- print_heading_with_help(get_string('assignroles', 'role'), 'assignroles');
+ if ($context->contextlevel==CONTEXT_COURSE and $context->instanceid == SITEID) {
+ print_heading_with_help(get_string('frontpageroles', 'admin'), 'assignroles');
+ } else {
+ print_heading_with_help(get_string('assignroles', 'role'), 'assignroles');
+ }
if ($roleid) { /// prints a form to swap roles
print_table($table);
}
- if ($context->contextlevel == CONTEXT_SYSTEM) {
+ if ($context->contextlevel == CONTEXT_SYSTEM or ($context->contextlevel==CONTEXT_COURSE and $context->instanceid == SITEID)) {
admin_externalpage_print_footer($adminroot);
} else {
print_footer($course);
$showroles = 1;
$currenttab = 'override';
include_once($CFG->dirroot.'/user/tabs.php');
+ } else if ($context->contextlevel==CONTEXT_COURSE and $context->instanceid == SITEID) {
+ require_once($CFG->libdir.'/adminlib.php');
+ $adminroot = admin_get_root();
+ admin_externalpage_setup('frontpageroles', $adminroot);
+ admin_externalpage_print_header($adminroot);
+ $currenttab = '';
+ $tabsmode = 'override';
+ include_once('tabs.php');
} else {
$currenttab = '';
$tabsmode = 'override';
print_table($table);
}
- print_footer($course);
+ if ($context->contextlevel == CONTEXT_SYSTEM or ($context->contextlevel==CONTEXT_COURSE and $context->instanceid == SITEID)) {
+ admin_externalpage_print_footer($adminroot);
+ } else {
+ print_footer($course);
+ }
?>
break;
case CONTEXT_COURSE:
- $streditcoursesettings = get_string("editcoursesettings");
-
- $course = get_record('course', 'id', $context->instanceid);
- print_header($streditcoursesettings, "$course->fullname",
- "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> $straction");
+ if ($context->instanceid != SITEID) {
+ $streditcoursesettings = get_string("editcoursesettings");
+
+ $course = get_record('course', 'id', $context->instanceid);
+ print_header($streditcoursesettings, "$course->fullname",
+ "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> $straction");
+ }
break;
case CONTEXT_GROUP:
$ADMIN->add('themes', new admin_externalpage('themeselector', get_string('themeselector','admin'), $CFG->wwwroot . '/theme/index.php'));
-// "frontpage" settingpage
-$temp = new admin_settingpage('frontpage', get_string('frontpage','admin'));
-$temp->add(new admin_setting_sitesettext('fullname', get_string('fullsitename'), '', ''));
-$temp->add(new admin_setting_sitesettext('shortname', get_string('shortsitename'), '', ''));
-$temp->add(new admin_setting_special_frontpagedesc());
-$temp->add(new admin_setting_courselist_frontpage(false)); // non-loggedin version of the setting (that's what the parameter is for :) )
-$temp->add(new admin_setting_courselist_frontpage(true)); // loggedin version of the setting
-$temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'),
- get_string('sitesectionhelp','admin'), 1));
-$temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'),
- '', 3,
- array('0' => '0',
- '1' => '1',
- '2' => '2',
- '3' => '3',
- '4' => '4',
- '5' => '5',
- '6' => '6',
- '7' => '7',
- '8' => '8',
- '9' => '9',
- '10' => '10')));
-$temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
-$temp->add(new admin_setting_configcheckbox('allowvisiblecoursesinhiddencategories', get_string('allowvisiblecoursesinhiddencategories', 'admin'), get_string('configvisiblecourses', 'admin'), 0));
-$ADMIN->add('appearance', $temp);
-
// calendar
$temp = new admin_settingpage('calendar', get_string('calendarsettings','admin'));
$temp->add(new admin_setting_special_adminseesall());
--- /dev/null
+<?php // $Id$
+
+// This file defines everything related to frontpage
+
+$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
+
+// "frontpage" settingpage
+$temp = new admin_settingpage('frontpagesettings', get_string('frontpagesettings','admin'), 'moodle/course:update', false, $frontpagecontext);
+$temp->add(new admin_setting_sitesettext('fullname', get_string('fullsitename'), '', ''));
+$temp->add(new admin_setting_sitesettext('shortname', get_string('shortsitename'), '', ''));
+$temp->add(new admin_setting_special_frontpagedesc());
+$temp->add(new admin_setting_courselist_frontpage(false)); // non-loggedin version of the setting (that's what the parameter is for :) )
+$temp->add(new admin_setting_courselist_frontpage(true)); // loggedin version of the setting
+$temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'), get_string('sitesectionhelp','admin'), 1));
+$temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'), '', 3,
+ array('0' => '0',
+ '1' => '1',
+ '2' => '2',
+ '3' => '3',
+ '4' => '4',
+ '5' => '5',
+ '6' => '6',
+ '7' => '7',
+ '8' => '8',
+ '9' => '9',
+ '10' => '10')));
+$temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
+$temp->add(new admin_setting_configcheckbox('allowvisiblecoursesinhiddencategories', get_string('allowvisiblecoursesinhiddencategories', 'admin'), get_string('configvisiblecourses', 'admin'), 0));
+$ADMIN->add('frontpage', $temp);
+
+$ADMIN->add('frontpage', new admin_externalpage('frontpageroles', get_string('frontpageroles', 'admin'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=" . $frontpagecontext->id, 'moodle/role:assign', false, $frontpagecontext));
+
+$ADMIN->add('frontpage', new admin_externalpage('frontpagebackup', get_string('frontpagebackup', 'admin'), $CFG->wwwroot.'/backup/backup.php?id='.SITEID, 'moodle/site:backup', false, $frontpagecontext));
+
+$ADMIN->add('frontpage', new admin_externalpage('frontpagerestore', get_string('frontpagerestore', 'admin'), $CFG->wwwroot.'/files/index.php?id='.SITEID.'&wdir=/backupdata', 'moodle/site:restore', false, $frontpagecontext));
+
+$ADMIN->add('frontpage', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID, 'moodle/course:managefiles', false, $frontpagecontext));
+?>
\ No newline at end of file
$temp->add(new admin_setting_configtext('proxyport', get_string('proxyport', 'admin'), get_string('configproxyport', 'admin'), 0, PARAM_INT));
$ADMIN->add('server', $temp);
-$ADMIN->add('server', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID));
-
$ADMIN->add('server', new admin_externalpage('maintenancemode', get_string('sitemaintenancemode', 'admin'), "$CFG->wwwroot/$CFG->admin/maintenance.php"));
$ADMIN->add('root', new admin_category('security', get_string('security','admin')));
$ADMIN->add('root', new admin_category('appearance', get_string('appearance','admin')));
+$ADMIN->add('root', new admin_category('frontpage', get_string('frontpage','admin')));
$ADMIN->add('root', new admin_category('server', get_string('server','admin')));
$ADMIN->add('root', new admin_category('mnet', get_string('net','mnet')));
/// Assign roles to the course
- if (has_capability('moodle/role:assign', $context)) {
+ if (has_capability('moodle/role:assign', $context) && ($course->id!==SITEID)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">'.get_string('assignroles', 'role').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/roles.gif" class="icon" alt="" />';
/// Backup this course
- if (has_capability('moodle/site:backup', $context)) {
+ if (has_capability('moodle/site:backup', $context)&& ($course->id!==SITEID)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->instance->pageid.'">'.get_string('backup').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/backup.gif" class="icon" alt="" />';
}
/// Restore to this course
- if (has_capability('moodle/site:restore', $context)) {
+ if (has_capability('moodle/site:restore', $context) && ($course->id!==SITEID)) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&wdir=/backupdata">'.get_string('restore').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
}
switch ($this->instance->pagetype) {
case 'course-view':
- if ($this->instance->pageid == SITEID) {
- $context = get_context_instance(CONTEXT_SYSTEM, $this->instance->pageid);
- } else {
- $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
- }
-
+ $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
if (!has_capability('moodle/site:manageblocks', $context)) {
return null;
}
require('../config.php');
require($CFG->libdir.'/filelib.php');
+ require($CFG->libdir.'/adminlib.php');
$id = required_param('id', PARAM_INT);
$file = optional_param('file', '', PARAM_PATH);
error("That's an invalid course id");
}
- require_login($course->id);
+ require_login($course);
require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id));
function html_footer() {
- global $course, $choose;
+ global $course, $choose, $adminroot;
echo '</td></tr></table>';
- print_footer($course);
+ if ($course->id == SITEID) {
+ admin_externalpage_print_footer($adminroot);
+ } else {
+ print_footer($course);
+ }
}
function html_header($course, $wdir, $formfield=""){
global $CFG, $ME, $choose;
- if (! $site = get_site()) {
- error("Invalid site!");
- }
-
- if ($course->id == $site->id) {
+ if ($course->id == SITEID) {
$strfiles = get_string("sitefiles");
} else {
$strfiles = get_string("files");
$fullnav = str_replace('->', '»', "$course->shortname -> $fullnav");
echo '<div id="nav-bar">'.$fullnav.'</div>';
- if ($course->id == $site->id) {
+ if ($course->id == SITEID and $wdir != "/backupdata") {
print_heading(get_string("publicsitefileswarning"), "center", 2);
}
} else {
- if ($course->id == $site->id) {
- print_header("$course->shortname: $strfiles", "$course->fullname",
- "<a href=\"../$CFG->admin/index.php\">".get_string("administration").
- "</a> -> $fullnav", $formfield);
+ if ($course->id == SITEID) {
- print_heading(get_string("publicsitefileswarning"), "center", 2);
+ if ($wdir == "/backupdata") {
+ $adminroot = admin_get_root();
+ admin_externalpage_setup('frontpagerestore', $adminroot);
+ admin_externalpage_print_header($adminroot);
+ } else {
+ $adminroot = admin_get_root();
+ admin_externalpage_setup('sitefiles', $adminroot);
+ admin_externalpage_print_header($adminroot);
+
+ print_heading(get_string("publicsitefileswarning"), "center", 2);
+
+ }
} else {
print_header("$course->shortname: $strfiles", "$course->fullname",
}
if ($CFG->rolesactive) { // if already using roles system
- if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+ if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
if (moodle_needs_upgrading()) {
redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
}
case FRONTPAGECOURSELIST:
- if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) and !isguest() and empty($CFG->disablemycourses)) {
+ if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
print_heading_block(get_string('mycourses'));
print_my_moodle();
- } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
+ } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
// admin should not see list of courses when there are too many of them
print_heading_block(get_string('availablecourses'));
print_courses(0, '100%', true);
case 'right':
// uh-changes end
// The right column
- if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+ if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, SITEID))) {
echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
// uh-changes start
if (!empty($THEME->roundcorners)) {
echo '<div class="i1"><div class="i2"><div class="i3">';
}
// uh-changes end
- if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
+ if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, SITEID))) {
echo '<div style="text-align:center">'.update_course_icon($SITE->id).'</div>';
echo '<br />';
}
$string['forcetimezone'] = 'Force default timezone';
$string['framename'] = 'Frame name';
$string['frontpage'] = 'Front Page';
+$string['frontpagebackup'] = 'Front Page backup';
$string['frontpageloggedin'] = 'Front page items when logged in';
+$string['frontpagerestore'] = 'Front Page restore';
+$string['frontpageroles'] = 'Front Page roles';
+$string['frontpagesettings'] = 'Front Page settings';
$string['fullnamedisplay'] = 'Full Name Format';
$string['gdversion'] = 'GD version';
$string['generalsettings'] = 'General settings';
if (!$adminroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW)) {
error('No admin role could be found');
}
- $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+ $sitecontext = get_context_instance(CONTEXT_SYSTEM);
foreach ($adminroles as $adminrole) {
role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
}
*/
var $req_capability;
+ /**
+ * @var object The context in which capability/permission should be checked, default is site context.
+ */
+ var $context;
+
/**
* @var bool hidden in admin tree block.
*/
* @param string $url The external URL that we should link to when someone requests this external page.
* @param mixed $req_capability The role capability/permission a user must have to access this external page. Defaults to 'moodle/site:config'.
*/
- function admin_externalpage($name, $visiblename, $url, $req_capability = 'moodle/site:config', $hidden=false) {
+ function admin_externalpage($name, $visiblename, $url, $req_capability = 'moodle/site:config', $hidden=false, $context=false) {
$this->name = $name;
$this->visiblename = $visiblename;
$this->url = $url;
$this->req_capability = array($req_capability);
}
$this->hidden = $hidden;
+ $this->context = $context;
}
/**
if (!get_site()) {
return true; // no access check before site is fully set up
}
- $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+ $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
foreach($this->req_capability as $cap) {
if (has_capability($cap, $context)) {
return true;
*/
var $req_capability;
+ /**
+ * @var object The context in which capability/permission should be checked, default is site context.
+ */
+ var $context;
+
/**
* @var bool hidden in admin tree block.
*/
}
// see admin_externalpage
- function admin_settingpage($name, $visiblename, $req_capability = 'moodle/site:config', $hidden=false) {
+ function admin_settingpage($name, $visiblename, $req_capability = 'moodle/site:config', $hidden=false, $context=false) {
global $CFG;
$this->settings = new stdClass();
$this->name = $name;
$this->req_capability = array($req_capability);
}
$this->hidden = false;
+ $this->context = $context;
}
// not the same as add for admin_category. adds an admin_setting to this admin_settingpage. settings appear (on the settingpage) in the order in which they're added
if (!get_site()) {
return true; // no access check before site is fully set up
}
- $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+ $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
foreach($this->req_capability as $cap) {
if (has_capability($cap, $context)) {
return true;
// is this page always editable, regardless of anything else?
function edit_always() {
- return (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS'));
+ return (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM)) && defined('ADMIN_STICKYBLOCKS'));
}
}
// This is also about editting of blocks BUT mainly activities in course page layout, see
// update_course_icon() - it must use the same capability
function user_allowed_editing() {
- if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
+ if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM)) && defined('ADMIN_STICKYBLOCKS')) {
return true;
}
return has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $this->id));
// Is the user actually editing this course page or "sticky page" right now?
function user_is_editing() {
- if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
+ if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM)) && defined('ADMIN_STICKYBLOCKS')) {
//always in edit mode on sticky page
return true;
}