From: skodak Date: Mon, 29 Jan 2007 21:29:27 +0000 (+0000) Subject: MDL-8343 reorganize frontpage settings in admintree - admin tree now allows to specif... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=84c8ede022abe5d80b8b101f2a257acdce0801d7;p=moodle.git 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 --- diff --git a/admin/roles/assign.php b/admin/roles/assign.php index 70b0716c4e..4d2c103c75 100755 --- a/admin/roles/assign.php +++ b/admin/roles/assign.php @@ -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); diff --git a/admin/roles/override.php b/admin/roles/override.php index da7cd5a803..a52124f691 100755 --- a/admin/roles/override.php +++ b/admin/roles/override.php @@ -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); + } ?> diff --git a/admin/roles/tabs.php b/admin/roles/tabs.php index 7c721310d5..a69baa0101 100755 --- a/admin/roles/tabs.php +++ b/admin/roles/tabs.php @@ -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", - "wwwroot/course/view.php?id=$course->id\">$course->shortname -> $straction"); + if ($context->instanceid != SITEID) { + $streditcoursesettings = get_string("editcoursesettings"); + + $course = get_record('course', 'id', $context->instanceid); + print_header($streditcoursesettings, "$course->fullname", + "wwwroot/course/view.php?id=$course->id\">$course->shortname -> $straction"); + } break; case CONTEXT_GROUP: diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 26c746793c..3e9d484d6c 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -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()); diff --git a/admin/settings/frontpage.php b/admin/settings/frontpage.php new file mode 100644 index 0000000000..db77184861 --- /dev/null +++ b/admin/settings/frontpage.php @@ -0,0 +1,38 @@ +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 diff --git a/admin/settings/server.php b/admin/settings/server.php index 8993484f3a..30e1b701c3 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -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")); diff --git a/admin/settings/top.php b/admin/settings/top.php index e638989bf4..e538b68c31 100644 --- a/admin/settings/top.php +++ b/admin/settings/top.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'))); diff --git a/blocks/admin/block_admin.php b/blocks/admin/block_admin.php index 23f31d93df..ebc31816eb 100644 --- a/blocks/admin/block_admin.php +++ b/blocks/admin/block_admin.php @@ -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[]=''.get_string('assignroles', 'role').''; $this->content->icons[]=''; @@ -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[]=''.get_string('backup').''; $this->content->icons[]=''; } /// Restore to this course - if (has_capability('moodle/site:restore', $context)) { + if (has_capability('moodle/site:restore', $context) && ($course->id!==SITEID)) { $this->content->items[]=''.get_string('restore').''; $this->content->icons[]=''; } diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index 38e4287fa0..27cda71f1e 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -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; } diff --git a/files/index.php b/files/index.php index 87b83c1b38..1c6e43d1f1 100644 --- a/files/index.php +++ b/files/index.php @@ -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 ''; - 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('->', '»', "$course->shortname -> $fullnav"); echo ''; - 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", - "admin/index.php\">".get_string("administration"). - " -> $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", diff --git a/index.php b/index.php index 95a48f7c79..3696cb2a17 100644 --- a/index.php +++ b/index.php @@ -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 ''; // uh-changes start if (!empty($THEME->roundcorners)) { @@ -272,7 +272,7 @@ echo '
'; } // 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 '
'.update_course_icon($SITE->id).'
'; echo '
'; } diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index 5d89d63f38..99a74365eb 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -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'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 0f22ea1d87..30255f5de0 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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; diff --git a/lib/pagelib.php b/lib/pagelib.php index 7924d199e5..69cdccfe2e 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -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; }