forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filters: MDL-7336 settings page for setting the local enabled/disable…
…d state
- Loading branch information
tjhunt
committed
Apr 13, 2009
1 parent
a042675
commit 0f74bb0
Showing
9 changed files
with
253 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
<?php // $Id$ | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
// // | ||
// NOTICE OF COPYRIGHT // | ||
// // | ||
// Moodle - Modular Object-Oriented Dynamic Learning Environment // | ||
// http://moodle.org // | ||
// // | ||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com // | ||
// // | ||
// This program is free software; you can redistribute it and/or modify // | ||
// it under the terms of the GNU General Public License as published by // | ||
// the Free Software Foundation; either version 2 of the License, or // | ||
// (at your option) any later version. // | ||
// // | ||
// This program is distributed in the hope that it will be useful, // | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of // | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | ||
// GNU General Public License for more details: // | ||
// // | ||
// http://www.gnu.org/copyleft/gpl.html // | ||
// // | ||
/////////////////////////////////////////////////////////////////////////// | ||
|
||
/** | ||
* Lets users configure which filters are active in a sub-context. | ||
* | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License | ||
* @package moodlecore | ||
*//** */ | ||
|
||
require_once(dirname(__FILE__) . '/../config.php'); | ||
require_once($CFG->libdir . '/adminlib.php'); | ||
|
||
$contextid = required_param('contextid',PARAM_INT); | ||
|
||
if (!$context = get_context_instance_by_id($contextid)) { | ||
print_error('wrongcontextid', 'error'); | ||
} | ||
|
||
// This is a policy decision, rather than something that would be impossible to implement. | ||
if (!in_array($context->contextlevel, array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE))) { | ||
print_error('cannotcustomisefiltersblockuser', 'error'); | ||
} | ||
|
||
$isfrontpage = $context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID; | ||
$contextname = print_context_name($context); | ||
|
||
if ($context->contextlevel == CONTEXT_COURSECAT) { | ||
$course = clone($SITE); | ||
} else if ($context->contextlevel == CONTEXT_COURSE) { | ||
$course = $DB->get_record('course', array('id' => $context->instanceid)); | ||
} else { | ||
// Must be module context. | ||
$course = $DB->get_record_sql('SELECT c.* FROM {course} c JOIN {context} ctx ON c.id = ctx.instanceid WHERE ctx.id = ?', | ||
array(get_parent_contextid($context))); | ||
} | ||
if (!$course) { | ||
print_error('invalidcourse', 'error'); | ||
} | ||
|
||
/// Check login and permissions. | ||
require_login($course); | ||
require_capability('moodle/filter:manage', $context); | ||
|
||
/// Get the list of available filters. | ||
$availablefilters = filter_get_available_in_context($context); | ||
if (!$isfrontpage && empty($availablefilters)) { | ||
print_error('nofiltersenabled', 'error'); | ||
} | ||
|
||
/// Process any form submission. | ||
if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) { | ||
foreach ($availablefilters as $filter => $filterinfo) { | ||
$newstate = optional_param(str_replace('/', '_', $filter), false, PARAM_INT); | ||
if ($newstate !== false && $newstate != $filterinfo->localstate) { | ||
filter_set_local_state($filter, $context->id, $newstate); | ||
} | ||
} | ||
redirect($CFG->wwwroot . '/filter/manage.php?contextid=' . $context->id, get_string('changessaved'), 1); | ||
} | ||
|
||
/// These are needed early because of tabs.php | ||
$assignableroles = get_assignable_roles($context, ROLENAME_BOTH); | ||
$overridableroles = get_overridable_roles($context, ROLENAME_BOTH); | ||
|
||
/// Work out an appropriate page title. | ||
$title = get_string('filtersettingsfor', 'filters', $contextname); | ||
$straction = get_string('filters', 'admin'); // Used by tabs.php | ||
|
||
/// Print the header and tabs | ||
if ($context->contextlevel == CONTEXT_COURSE and $context->instanceid == SITEID) { | ||
admin_externalpage_setup('frontpagefilters'); | ||
admin_externalpage_print_header(); | ||
} else { | ||
$currenttab = 'filters'; | ||
include_once($CFG->dirroot . '/' . $CFG->admin . '/roles/tabs.php'); | ||
} | ||
|
||
/// Print heading. | ||
print_heading_with_help($title, 'localfiltersettings'); | ||
|
||
if (empty($availablefilters)) { | ||
echo '<p class="centerpara">' . get_string('nofiltersenabled', 'filters') . "</p>\n"; | ||
} else { | ||
$settingscol = false; | ||
foreach ($availablefilters as $filter => $notused) { | ||
$hassettings = filter_has_local_settings($filter); | ||
$availablefilters[$filter]->hassettings = $hassettings; | ||
$settingscol = $settingscol || $hassettings; | ||
} | ||
|
||
$strsettings = get_string('settings'); | ||
$stroff = get_string('off', 'filters'); | ||
$stron = get_string('on', 'filters'); | ||
$strdefaultoff = get_string('defaultx', 'filters', $stroff); | ||
$strdefaulton = get_string('defaultx', 'filters', $stron); | ||
$activechoices = array( | ||
TEXTFILTER_INHERIT => '', | ||
TEXTFILTER_OFF => $stroff, | ||
TEXTFILTER_ON => $stron, | ||
); | ||
|
||
echo '<form action="' . $CFG->wwwroot . '/filter/manage.php?contextid=' . $context->id . '" method="post">'; | ||
echo "\n<div>\n"; | ||
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />'; | ||
|
||
$table = new stdClass; | ||
$table->head = array(get_string('filter'), get_string('isactive', 'filters')); | ||
$table->align = array('left', 'left'); | ||
if ($settingscol) { | ||
$table->head[] = $strsettings; | ||
$table->align = 'left'; | ||
} | ||
$table->width = ' '; | ||
$table->data = array(); | ||
|
||
// iterate through filters adding to display table | ||
foreach ($availablefilters as $filter => $filterinfo) { | ||
$row = array(); | ||
|
||
// Filter name. | ||
$row[] = filter_get_name($filter); | ||
|
||
// Default/on/off choice. | ||
if ($filterinfo->inheritedstate == TEXTFILTER_ON) { | ||
$activechoices[TEXTFILTER_INHERIT] = $strdefaulton; | ||
} else { | ||
$activechoices[TEXTFILTER_INHERIT] = $strdefaultoff; | ||
} | ||
$row[] = choose_from_menu($activechoices, str_replace('/', '_', $filter), | ||
$filterinfo->localstate, '', '', '', true); | ||
|
||
// Settings link, if required | ||
if ($settingscol) { | ||
$settings = ''; | ||
if ($filterinfo->hassettings) { | ||
$settings = '<a href="' . $CFG->wwwroot . '/filter/settings.php?contextid=' . | ||
$context->id . '&filter=' . $filter . '">' . $strsettings . '</a>'; | ||
} | ||
$row[] = $settings; | ||
} | ||
|
||
$table->data[] = $row; | ||
} | ||
|
||
print_table($table); | ||
echo '<div class="buttons">' . "\n"; | ||
echo '<input type="submit" name="savechanges" value="' . get_string('savechanges') . '" />'; | ||
echo "\n</div>\n"; | ||
echo "</div>\n"; | ||
echo "</form>\n"; | ||
|
||
} | ||
|
||
/// Appropriate back link. | ||
if (!$isfrontpage && ($url = get_context_url($context))) { | ||
echo '<div class="backlink"><a href="' . $url . '">' . | ||
get_string('backto', '', $contextname) . '</a></div>'; | ||
} | ||
|
||
print_footer($course); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<h1>Filter settings</h1> | ||
|
||
<p>This page lets you turn filters on or off in a particular part of the site. | ||
This page only gives you access to those filters that the Administrator has | ||
enabled.</p> | ||
|
||
<p>Some filters may also let you set local settings, in which case there will be | ||
a 'Settings' link next to their name.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters