Commit 84c8ede0 authored by skodak's avatar skodak
Browse files

MDL-8343 reorganize frontpage settings in admintree - admin tree now allows to...

MDL-8343 reorganize frontpage settings in admintree - admin tree now allows to specify context together with required capability for each entry
MDL-8352 Fully separate CONTEXT_COURSE, SITEID from COURSE_SYSTEM - first part of cleanup related to frontpage
parent 018caef0
......@@ -114,6 +114,13 @@
$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';
......@@ -192,7 +199,11 @@
}
}
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
......@@ -269,7 +280,7 @@
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);
......
......@@ -135,6 +135,14 @@
$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';
......@@ -199,6 +207,10 @@
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);
}
?>
......@@ -27,11 +27,13 @@ if ($currenttab != 'update') {
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:
......
......@@ -15,32 +15,6 @@ $ADMIN->add('themes', $temp);
$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());
......
<?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.'&amp;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
......@@ -125,8 +125,6 @@ $temp->add(new admin_setting_configtext('proxyhost', get_string('proxyhost', 'ad
$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"));
......
......@@ -25,6 +25,7 @@ $ADMIN->add('modules', new admin_externalpage('managefilters', get_string('manag
$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')));
......
......@@ -64,7 +64,7 @@ class block_admin extends block_list {
/// 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="" />';
......@@ -94,13 +94,13 @@ class block_admin extends block_list {
/// 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.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
}
......
......@@ -309,12 +309,7 @@ class block_base {
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;
}
......
......@@ -9,6 +9,7 @@
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);
......@@ -33,26 +34,26 @@
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");
......@@ -107,18 +108,26 @@
$fullnav = str_replace('->', '&raquo;', "$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",
......
......@@ -49,7 +49,7 @@
}
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');
}
......@@ -216,10 +216,10 @@
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);
......@@ -264,7 +264,7 @@
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)) {
......@@ -272,7 +272,7 @@
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 />';
}
......
......@@ -278,7 +278,11 @@ $string['forceloginforprofiles'] = 'Force users to login for profiles';
$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';
......
......@@ -512,7 +512,7 @@ function create_admin_user() {
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);
}
......@@ -1113,6 +1113,11 @@ class admin_externalpage extends part_of_admin_tree {
*/
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.
*/
......@@ -1126,7 +1131,7 @@ class admin_externalpage extends part_of_admin_tree {
* @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;
......@@ -1136,6 +1141,7 @@ class admin_externalpage extends part_of_admin_tree {
$this->req_capability = array($req_capability);
}
$this->hidden = $hidden;
$this->context = $context;
}
/**
......@@ -1180,7 +1186,7 @@ class admin_externalpage extends part_of_admin_tree {
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;
......@@ -1227,6 +1233,11 @@ class admin_settingpage extends part_of_admin_tree {
*/
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.
*/
......@@ -1253,7 +1264,7 @@ class admin_settingpage extends part_of_admin_tree {
}
// 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;
......@@ -1264,6 +1275,7 @@ class admin_settingpage extends part_of_admin_tree {
$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
......@@ -1283,7 +1295,7 @@ class admin_settingpage extends part_of_admin_tree {
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;
......
......@@ -295,7 +295,7 @@ class page_base {
// 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'));
}
}
......@@ -347,7 +347,7 @@ class page_course extends page_base {
// 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));
......@@ -355,7 +355,7 @@ class page_course extends page_base {
// 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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment