// extract and sanitize the auth key explicitly
$modules = get_list_of_plugins("auth");
if (in_array($config['auth'], $modules)) {
- $auth = $config['auth'];
+ $auth = $config['auth'];
} else {
notify("Error defining the authentication method");
}
if (preg_match('/^pluginconfig_(.+?)$/', $name, $matches)) {
$plugin = "auth/$auth";
$name = $matches[1];
- if (! set_config($name, $value, $plugin)) {
+ if (! set_config($name, $value, $plugin)) {
notify("Problem saving config $name as $value for plugin $plugin");
}
- } else { // normal handling for
+ } else { // normal handling for
if (! set_config($name, $value)) {
notify("Problem saving config $name as $value");
}
echo "<form target=\"{$CFG->framename}\" name=\"authmenu\" method=\"post\" action=\"auth.php\">";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" />";
print_string("chooseauthmethod","auth");
-
+
echo ' ';
choose_from_menu ($options, "auth", $auth, "","document.location='auth.php?sesskey=$USER->sesskey&auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
require_once("$CFG->dirroot/auth/$auth/config.html");
$CFG->pagepath = 'auth/' . $auth;
-
+
echo '<tr><td colspan="3">';
print_heading(get_string('auth_common_settings', 'auth'));
echo '<td/></tr>';
// Good enough for most auth plugins
// but some may want a custom one if they are offering
// other options
-// Note: pluginconfig_ fields have special handling.
+// Note: pluginconfig_ fields have special handling.
function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
echo '<tr><td colspan="3">';
'onlogin' => get_string('update_onlogin', 'auth'));
$updateextoptions = array('0' => get_string('update_never', 'auth'),
'1' => get_string('update_onupdate', 'auth'));
-
+
$pluginconfig = get_config("auth/$auth");
-
+
// helptext is on a field with rowspan
if (empty($helptext)) {
$helptext = ' ';
}
if(empty($pluginconfig->{"field_updatelocal_$field"})) {
$pluginconfig->{"field_updatelocal_$field"} = '';
- }
+ }
if (empty($pluginconfig->{"field_updateremote_$field"})) {
$pluginconfig->{"field_updateremote_$field"} = '';
}
//First of all we check that everything is correct
//Check for trailing slash and backslash in backup_sche_destination
- if (!empty($backup_sche_destination) and
+ if (!empty($backup_sche_destination) and
(substr($backup_sche_destination,-1) == "/" or substr($backup_sche_destination,-1) == "\\")) {
$error = true;
$sche_destination_error = get_string("pathslasherror");
if (isset($a_config[$tocheck])) {
$temp .= "1";
} else {
- $temp .= "0";
+ $temp .= "0";
}
unset($a_config[$tocheck]);
$i++;
foreach ($courses as $course) {
//We check if the course exists in backup_course
$backup_course = get_record("backup_courses","courseid",$course->id);
- //If it doesn't exist, create
+ //If it doesn't exist, create
if (!$backup_course) {
$temp_backup_course->courseid = $course->id;
$newid = insert_record("backup_courses",$temp_backup_course);
//Check for required functions...
if (!function_exists('utf8_encode')) {
notify("You need to add XML support to your PHP installation");
- }
+ }
include ("$CFG->dirroot/backup/config.html");
print_simple_box_end();
require_once($CFG->libdir.'/blocklib.php');
$blockid = required_param('block', PARAM_INT);
-
+
if(($blockrecord = blocks_get_record($blockid)) === false) {
error('This block does not exist');
}
$strconfiguration = get_string('configuration');
$strmanageblocks = get_string('manageblocks');
$strblockname = $block->get_title();
-
+
// $CFG->pagepath is used to generate the body and id attributes for the body tag
// of the page. It is also used to generate the link to the Moodle Docs for this view.
$CFG->pagepath = 'block/' . $block->name() . '/config';
-
+
admin_externalpage_print_header($adminroot);
print_heading(get_string('incompatibleblocks', 'admin'));
$table = new flexible_table('admin-blocks-incompatible');
-
+
$table->define_columns(array('block', 'delete'));
$table->define_headers(array($strname, $strdelete));
$table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php');
-
+
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'incompatible');
$table->set_attribute('class', 'generaltable generalbox');
-
+
$table->setup();
foreach ($incompatible as $block) {
}
closedir($dir);
}
-
+
?>
$enrol = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR);
$CFG->pagepath = 'enrol';
-
+
$adminroot = admin_get_root();
admin_externalpage_setup('enrolment', $adminroot);
if ($frm = data_submitted()) {
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
- }
+ }
if (empty($frm->enable)) {
$frm->enable = array();
}
require_once("../config.php");
require_once($CFG->libdir.'/adminlib.php');
-
+
$adminroot = admin_get_root();
admin_externalpage_setup('enrolment', $adminroot);
if ($frm = data_submitted()) {
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
- }
+ }
if ($enrolment->process_config($frm)) {
redirect("enrol.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
}
"document.location='enrol_config.php?enrol='+document.enrolmenu.enrol.options[document.enrolmenu.enrol.selectedIndex].value", "");
echo "</b></p></div>";
-
-/// Print current enrolment type description
+
+/// Print current enrolment type description
print_simple_box_start("center", "80%");
print_heading($options[$enrol]);
print_simple_box_end();
echo "<hr />";
-
+
$enrolment->config_form($frm);
echo "<center><p><input type=\"submit\" value=\"".get_string("savechanges")."\"></p></center>\n";
// $CFG->pagepath is used to generate the body and id attributes for the body tag
// of the page. It is also used to generate the link to the Moodle Docs for this view.
$CFG->pagepath = 'filter/' . $filtername . '/config';
-
+
// get translated strings for use on page
$txt = new Object;
$txt->managefilters = get_string( 'managefilters' );
//==============================
// Display logic
//==============================
-
+
$filtername = ucfirst($filtername);
admin_externalpage_print_header($adminroot);
print_heading( $filtername );
}
function exists() {
if (!$this->is_enabled()) {
- return true;
+ return true;
}
if ($this->status() < 1) {
return true;
function severity() {
if ($this->is_enabled() and $this->status() == 0) {
return SEVERITY_SIGNIFICANT;
- } else {
+ } else {
return SEVERITY_ANNOYANCE;
}
}
global $CFG;
$desc = 'Slasharguments are needed for relative linking in uploaded resources:<ul>';
if (!$this->is_enabled()) {
- $desc .= '<li>slasharguments are <strong>disabled</strong> in Moodle configuration</li>';
+ $desc .= '<li>slasharguments are <strong>disabled</strong> in Moodle configuration</li>';
} else {
- $desc .= '<li>slasharguments are enabled in Moodle configuration</li>';
+ $desc .= '<li>slasharguments are enabled in Moodle configuration</li>';
}
if ($this->status() == -1) {
$desc .= '<li>can not run automatic test, you can verify it <a href="'.$CFG->wwwroot.'/file.php/testslasharguments" target="_blank">here</a> manually</li>';
$solution .= 'Congratulations - everything seems OK now :-D';
}
if ($status < 1) {
- $solution .= '<p>IIS:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li><li>do NOT enable AllowPathInfoForScriptMappings !!!</li><li>slasharguments may not work when using ISAPI and PHP 4.3.10 and older</li></ul></p>';
- $solution .= '<p>Apache 1:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
- $solution .= '<p>Apache 2:<ul><li>you must add <code>AcceptPathInfo on</code> to php.ini or .htaccess</li><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
+ $solution .= '<p>IIS:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li><li>do NOT enable AllowPathInfoForScriptMappings !!!</li><li>slasharguments may not work when using ISAPI and PHP 4.3.10 and older</li></ul></p>';
+ $solution .= '<p>Apache 1:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
+ $solution .= '<p>Apache 2:<ul><li>you must add <code>AcceptPathInfo on</code> to php.ini or .htaccess</li><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
}
return $solution;
}
blocks_execute_action($page, blocks_get_by_page($page), 'add', (int)$admintree->id, false, false);
if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
blocks_execute_action($page, blocks_get_by_page($page), 'moveleft', $admintreeinstance, false, false);
- }
+ }
}
set_config('adminblocks_initialised', 1);
}
/// Check for any special upgrades that might need to be run
- if (!empty($CFG->upgrade)) {
+ if (!empty($CFG->upgrade)) {
print_simple_box(get_string("upgrade$CFG->upgrade", "admin",
"$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"), "center", '60%');
print_spacer(10,10);
}
/// Print slightly annoying registration button every six months ;-)
-/// You can set the "registered" variable to something far in the future
+/// You can set the "registered" variable to something far in the future
/// if you really want to prevent this. eg 9999999999
if (!isset($CFG->registered) || $CFG->registered < (time() - 3600*24*30*6)) {
$options = array();
$table->cellpadding = 5;
$table->cellspacing = 0;
$table->width = '40%';
-
+
$configdata = '<div class="adminlink"><a href="config.php">'.get_string('configvariables', 'admin').
'</a> - <span class="explanation">'.get_string('adminhelpconfigvariables').'</span></div>';
$configdata .= '<div class="adminlink"><a href="site.php">'.get_string('sitesettings').
'</a> - <span class="explanation">'.get_string('helpcalendarsettings', 'admin').'</span></div>';
$configdata .= '<div class="adminlink"><a href="maintenance.php">'.get_string('sitemaintenancemode', 'admin').
'</a> - <span class="explanation">'.get_string('helpsitemaintenance', 'admin').'</span></div>';
-
+
$table->data[] = array('<strong>'.get_string('configuration').'</strong>', $configdata);
-
+
$userdata = '<div class="adminlink"><a href="auth.php?sesskey='.$USER->sesskey.'">'.get_string("authentication").
'</a> - <span class="explanation">'.get_string('adminhelpauthentication').'</span></div>';
$userdata .= '<div class="adminlink"><a href="user.php">'.get_string('edituser').
$userdata .= '<div class="adminlink"><a href="roles/assign.php?contextid='.$context->id.'">'.
get_string('assignsiteroles').'</a> - <span class="explanation">'.get_string('adminhelpassignsiteroles').
'</span></div>';
-
+
$table->data[] = array('<strong>'.get_string('users').'</strong>', $userdata);
-
+
$coursedata = '<div class="adminlink"><a href="../course/index.php?edit=on&sesskey='.$USER->sesskey.'">'.get_string('managecourses').
'</a> - <span class="explanation">'.get_string('adminhelpcourses').'</span></div>';
$coursedata .= '<div class="adminlink"><a href="enrol.php?sesskey='.$USER->sesskey.'">'.get_string('enrolmentplugins').
'</a> - <span class="explanation">'.get_string('adminhelpenrolments').'</span></div>';
-
-
+
+
$table->data[] = array('<strong>'.get_string('courses').'</strong>', $coursedata);
-
+
$miscdata = '<div class="adminlink"><a href="../files/index.php?id='.$site->id.'">'.get_string('sitefiles').
'</a> - <span class="explanation">'.get_string('adminhelpsitefiles').'</span></div>';
$miscdata .= '<div class="adminlink"><a href="stickyblocks.php">'.get_string('stickyblocks','admin').
$miscdata .= '<div class="adminlink"><a href="xmldb/index.php">'.get_string('xmldbeditor').
'</a> - <span class="explanation">'.get_string('adminhelpxmldbeditor').'</span></div>';
}
-
+
$table->data[] = array('<strong>'.get_string('miscellaneous').'</strong>', $miscdata);
-
-/*
- /// Hooks for Matt Oquists contrib code for repositories and portfolio.
+
+/*
+ /// Hooks for Matt Oquists contrib code for repositories and portfolio.
/// The eventual official versions may not look like this
if (isset($CFG->portfolio) && file_exists("$CFG->dirroot/$CFG->portfolio")) {
$table->data[] = array("<strong><a href=\"../portfolio/\">".get_string('portfolio','portfolio').'</a></
strong>',
'<div class="explanation">'.get_string('adminhelpportfolio','portfolio').'</div>');
}
-
+
if (isset($CFG->repo) && file_exists("$CFG->dirroot/$CFG->repo")) {
$table->data[] = array("<strong><a href=\"../repository/?repoid=1&action=list\">".get_string('repository','
repository').'</a></strong>',
'<div class="explanation">'.get_string('adminhelprepository','repository').'</div>');
}
-*/
-
-
+*/
+
+
print_table($table);
-
+
}
//////////////////////////////////////////////////////////////////////////////////////////////////
echo '</div>';
}
-
+
if (optional_param('dbmigrate')) { // ??? Is this actually used?
print_simple_box_start('center','60%');
require_once($CFG->dirroot.'/admin/utfdbmigrate.php');
$strconfiguration = get_string("configuration");
$strmanagemodules = get_string("managemodules");
$strmodulename = get_string("modulename", $module);
-
+
// $CFG->pagepath is used to generate the body and id attributes for the body tag
// of the page. It is also used to generate the link to the Moodle Docs for this view.
$CFG->pagepath = 'mod/' . $module . '/config';
-
+
admin_externalpage_print_header($adminroot);
print_heading($strmodulename);
admin_externalpage_print_header($adminroot);
print_heading($stractivities);
-
+
$coursesaffected = false;
-
+
/// If data submitted, then process and store.
}
if (!empty($delete) and confirm_sesskey()) {
-
+
$strmodulename = get_string("modulename", "$delete");
if (!$confirm) {
- notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename),
- "modules.php?delete=$delete&confirm=1&sesskey=$USER->sesskey",
+ notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename),
+ "modules.php?delete=$delete&confirm=1&sesskey=$USER->sesskey",
"modules.php");
admin_externalpage_print_footer($adminroot);
exit;
notify("Error occurred while deleting all $strmodulename records in course_modules table");
}
- // Then delete all the logs
+ // Then delete all the logs
if (!delete_records("log", "module", $module->name)) {
notify("Error occurred while deleting all $strmodulename records in log table");
}
}
}
}
- }
+ }
// Delete the capabilities that were defined by this module
capabilities_cleanup('mod/'.$module->name);
-
+
// rebuild_course_cache(); // Because things have changed
$coursesaffected = true;
notice(get_string("moduledeletefiles", "", $a), "modules.php");
}
}
-
+
if ($coursesaffected) {
rebuild_course_cache(); // Because things have changed
}
-
+
/// Get and sort the existing modules
<?PHP // $Id$
// Allows the admin to manage questiontypes
// This page is adapted from modules.php
-
+
// This page is not yet in service, the whole plug-in architecture
// for question types is still under construction.
$strquestions = get_string("questions");
$strquestiontype = get_string("questiontype", 'quiz');
- print_header("$site->shortname: $strquestions", "$site->fullname",
+ print_header("$site->shortname: $strquestions", "$site->fullname",
"<a href=\"index.php\">$stradministration</a> -> ".
"<a href=\"configure.php\">$strconfiguration</a> -> $strquestions");
print_heading($strquestions);
-
+
/// If data submitted, then process and store.
}
if (!empty($delete) and confirm_sesskey()) {
-
+
$strqtypename = get_string("qtypename", "qtype_$delete");
if (!$confirm) {
- notice_yesno(get_string("qtypedeleteconfirm", "admin", $strqtypename),
- "questiontypes.php?delete=$delete&confirm=1&sesskey=$USER->sesskey",
+ notice_yesno(get_string("qtypedeleteconfirm", "admin", $strqtypename),
+ "questiontypes.php?delete=$delete&confirm=1&sesskey=$USER->sesskey",
"questiontypes.php");
print_footer();
exit;
}
}
}
- }
+ }
$a->qtype = $strqtypename;
$a->directory = "$CFG->dirroot/qtype/$delete";
$count = count_records('quiz_questions', 'qtype', $qtype->id);
$delete = $count ? '' : "<a href=\"questiontypes.php?delete=$qtype->name&sesskey=$USER->sesskey\">$strdelete</a>";
-
+
if ($qtype->visible) {
$visible = "<a href=\"questiontypes.php?hide=$qtype->name&sesskey=$USER->sesskey\" title=\"$strhide\">".
"<img src=\"$CFG->pixpath/i/hide.gif\" align=\"middle\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" /></a>";
$strcourseoverview = get_string('courseoverview');
$strnav = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/index.php">'.get_string('administration').'</a> -> <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/report.php">'.$strreports.'</a> -> '.$strcourseoverview;
-
+
$reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED);
$tableprefix = $CFG->prefix.'stats_';
$earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend LIMIT 1');
$earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend LIMIT 1');
$earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend LIMIT 1');
-
+
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
if (empty($earliestmonth)) $earliestmonth = time();
if (!empty($report) && !empty($time)) {
$param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
-
+
$sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table
." WHERE timeend >= ".$param->timeafter
." GROUP BY courseid "
.$param->extras
." ORDER BY ".$param->orderby
." LIMIT ".$numcourses;
-
+
$courses = get_records_sql($sql);
if (empty($courses)) {
}
echo '<center><img src="'.$CFG->wwwroot.'/'.$CFG->admin.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></center>';
-
+
$table = new object();
$table->align = array('left','center','center','center');
$table->head = array(get_string('course'),$param->line1);
if (!empty($param->line2)) {
- $table->head[] = $param->line2;
+ $table->head[] = $param->line2;
}
if (!empty($param->line3)) {
$table->head[] = $param->line3;
}
-
+
foreach ($courses as $c) {
$a = array();
$a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.get_field('course','shortname','id',$c->courseid).'</a>';
}
print_table($table);
}
-
+
admin_externalpage_print_footer($adminroot);
?>
require_login();
require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID));
-
+
stats_check_uptodate($course->id);
$param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
.$param->extras
." ORDER BY ".$param->orderby
." LIMIT ".$numcourses;
-
+
$courses = get_records_sql($sql);
-
+
if (empty($courses)) {
error(get_string('statsnodata'),$CFG->wwwroot.'/'.$CFG->admin.'/report/course/index.php');
}
-
+
$graph = new graph(750,400);
$graph->y_format['bar1'] = array('colour' => 'blue','bar' => 'fill','legend' => $param->{$param->graphline});
$graph->draw_stack();
-
+
?>
print_heading(get_string('chooselogs') .':');
- print_log_selector_form($course);
+ print_log_selector_form($course);
echo '<br />';
print_heading(get_string('chooselivelogs') .':');
// Options set when the class is created.
var $showpasses;
-
+
// Lang strings. Set in the constructor.
var $strrunonlyfolder;
var $strrunonlyfile;
-
+
var $strseparator;
-
+
/**
* Constructor.
- *
+ *
* @param bool $showpasses Whether this reporter should output anything for passes.
*/
function ExHtmlReporter($showpasses) {
global $CFG;
-
+
$this->HtmlReporter();
$this->showpasses = $showpasses;
-
+
$this->strrunonlyfolder = $this->get_string('runonlyfolder');
$this->strrunonlyfile = $this->get_string('runonlyfile');
$this->strseparator = ' <img src="' . $CFG->pixpath . '/a/r_breadcrumb.gif" class="resize" alt="" /> ';
*/
function _paintPassFail($passorfail, $message) {
global $FULLME, $CFG;
-
+
print_simple_box_start('', '100%', '', 5, $passorfail . ' generalbox');
$url = $this->_htmlEntities($this->_stripParameterFromUrl($FULLME, 'path'));
echo '<b class="', $passorfail, '">', $this->get_string($passorfail), '</b>: ';
print_simple_box_end();
flush();
}
-
+
/**
* Called when a notice needs to be output.
*/
echo $this->get_string('summary', $summarydata);
echo '</div>';
- echo '<div class="performanceinfo">',
+ echo '<div class="performanceinfo">',
$this->get_string('runat', date('<b>d-m-Y H:i T</b>')),
$this->get_string('version', SimpleTestOptions::getVersion()),
'</div>';
}
-
+
/**
* Strip a specified parameter from the query string of a URL, if present.
- * Adds a separator to the end of the URL, so that a new parameter
+ * Adds a separator to the end of the URL, so that a new parameter
* can easily be appended. For example (assuming $param = 'frog'):
- *
+ *
* http://example.com/index.php -> http://example.com/index.php?
* http://example.com/index.php?frog=1 -> http://example.com/index.php?
* http://example.com/index.php?toad=1 -> http://example.com/index.php?toad=1&
* http://example.com/index.php?frog=1&toad=1 -> http://example.com/index.php?toad=1&
- *
+ *
* @param string $url the URL to modify.
* @param string $param the parameter to strip from the URL, if present.
- *
+ *
* @return string The modified URL.
*/
function _stripParameterFromUrl($url, $param) {
if ($file != 'CVS' && !in_array($file_path, $this->ignorefolders)) {
$this->_recurseFolders($file_path);
}
- } elseif (preg_match('/simpletest(\/|\\\\)test.*\.php$/', $file_path) ||
+ } elseif (preg_match('/simpletest(\/|\\\\)test.*\.php$/', $file_path) ||
($this->thorough && preg_match('/simpletest(\/|\\\\)slowtest.*\.php$/', $file_path))) {
$s_count++;
if (!is_null($path)) {
// Create the group of tests.
$test =& new AutoGroupTest($showsearch, $thorough);
-
- // OU specific. We use the _nonproject folder for stuff we want to
+
+ // OU specific. We use the _nonproject folder for stuff we want to
// keep in CVS, but which is not really relevant. It does no harm
// to leave this here.
$test->addIgnoreFolder($CFG->dirroot . '/_nonproject');
-
+
// Make the reporter, which is what displays the results.
$reporter = new ExHtmlReporter($showpasses);
-
+
if ($showsearch) {
print_heading('Searching for test cases');
}
flush();
-
+
// Work out what to test.
if (substr($path, 0, 1) == '/') {
$path = substr($path, 1);
print_simple_box(get_string('pathdoesnotexist', $langfile, $path), '', '', '', '', 'errorbox');
$ok = false;
}
-
+
// If we have something to test, do it.
if ($ok) {
if ($path == $CFG->dirroot) {
}
require_capability('moodle/site:viewreport', get_context_instance(CONTEXT_COURSE, $course->id));
-
- add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id);
+
+ add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id);
stats_check_uptodate($course->id);
-
-
+
+
// $strreports = get_string("reports");
// $strstats = get_string('stats');
//
// <a href=\"{$CFG->wwwroot}/admin/report.php\">$strreports</a> ->
// $strstats";
-// print_header("$course->shortname: $strstats", "$course->fullname",
+// print_header("$course->shortname: $strstats", "$course->fullname",
// $crumb, '', '', true, ' ', $menu);
-
-
+
+
require_once($CFG->dirroot.'/course/report/stats/report.php');
-
+
admin_externalpage_print_footer($adminroot);
?>
<?php
/**
- * this page defines what roles can access (grant user that role and override that roles'
- * capabilities in different context. For example, we can say that Teachers can only grant
+ * this page defines what roles can access (grant user that role and override that roles'
+ * capabilities in different context. For example, we can say that Teachers can only grant
* student role or modify student role's capabilities. Note that you need both the right
* capability moodle/roles:assign or moodle/roles:manage and this database table roles_deny_grant
* to be able to grant roles. If a user has moodle/roles:manage at site level assignment
$site = get_site();
$stradministration = get_string('administration');
$strmanageroles = get_string('manageroles');
-
+
/// form processiong here
/// get all roles
-
+
$roles = get_records('role');
if ($grant = data_submitted()) {
-
+
foreach ($grant as $grole => $val) {
if ($grole == 'dummy') {
- continue;
+ continue;
}
-
+
$string = explode('_', $grole);
$temp[$string[1]][$string[2]] = 1; // if set, means can access
}
}
} else { //if set, means can access, attempt to remove it from db
delete_records('role_allow_assign', 'roleid', $srole->id, 'allowassign', $trole->id);
- }
+ }
}
}
}
$table->cellspacing = 0;
$table->width = '90%';
$table->align[] = 'right';
-
+
/// get all the roles identifier
foreach ($roles as $role) {
$rolesname[] = format_string($role->name);
$roleids[] = $role->id;
$table->align[] = 'center';
$table->wrap[] = 'nowrap';
- }
-
+ }
+
$table->head = array_merge(array(''), $rolesname);
-
+
foreach ($roles as $role) {
$beta = get_box_list($role->id, $roleids);
$table->data[] = array_merge(array(format_string($role->name)), $beta);
}
print_simple_box(get_string('configallowassign', 'admin'), 'center');
-
+
echo '<form action="allowassign.php" method="post">';
print_table($table);
echo '<div class="singlebutton"><input type="submit" value="'.get_string('savechanges').'"/></div>';
echo '<input type="hidden" name="dummy" value="1" />'; // this is needed otherwise we do not know a form has been submitted
echo '</form>';
-
+
admin_externalpage_print_footer($adminroot);
function get_box_list($roleid, $arraylist){
-
+
foreach ($arraylist as $targetid) {
if (get_record('role_allow_assign', 'roleid', $roleid, 'allowassign', $targetid)) {
$array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" checked="checked"/>';
} else {
- $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';
+ $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';
}
}
return $array;
<?php
/**
- * this page defines what roles can override (override roles in different context. For example,
+ * this page defines what roles can override (override roles in different context. For example,
* we can say that Admin can override teacher roles in a course
* To be able to override roles. If a user has moodle/roles:overrde at context level
* and be in the roles_allow_override table.
$site = get_site();
$stradministration = get_string('administration');
$strmanageroles = get_string('manageroles');
-
+
/// form processiong here
/// get all roles
-
+
$roles = get_records('role');
if ($grant = data_submitted()) {
-
+
foreach ($grant as $grole => $val) {
if ($grole == 'dummy') {
- continue;
+ continue;
}
-
+
$string = explode('_', $grole);
$temp[$string[1]][$string[2]] = 1; // if set, means can access
}
}
} else { //if set, means can access, attempt to remove it from db
delete_records('role_allow_override', 'roleid', $srole->id, 'allowoverride', $trole->id);
- }
+ }
}
}
}
/// displaying form here
admin_externalpage_print_header($adminroot);
-
+
$currenttab='allowoverride';
require_once('managetabs.php');
$table->cellspacing = 0;
$table->width = '90%';
$table->align[] = 'right';
-
+
/// get all the roles identifier
foreach ($roles as $role) {
$rolesname[] = format_string($role->name);
$roleids[] = $role->id;
$table->align[] = 'center';
$table->wrap[] = 'nowrap';
- }
-
+ }
+
$table->head = array_merge(array(''), $rolesname);
-
+
foreach ($roles as $role) {
$beta = get_box_list($role->id, $roleids);
$table->data[] = array_merge(array(format_string($role->name)), $beta);
}
print_simple_box(get_string('configallowoverride', 'admin'), 'center');
-
+
echo '<form action="allowoverride.php" method="post">';
print_table($table);
echo '<div class="singlebutton"><input type="submit" value="'.get_string('savechanges').'"/></div>';
// returns array
function get_box_list($roleid, $arraylist){
-
+
foreach ($arraylist as $targetid) {
if (get_record('role_allow_override', 'roleid', $roleid, 'allowoverride', $targetid)) {
$array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" checked="checked"/>';
} else {
- $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';
+ $array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';
}
}
return $array;
onFocus="document.studentform.add.disabled=true;
document.studentform.remove.disabled=false;
document.studentform.addselect.selectedIndex=-1;" />
- <?php
+ <?php
foreach ($contextusers as $contextuser) {
$fullname = fullname($contextuser, true);
echo "<option value=\"$contextuser->id\">".$fullname.", ".$contextuser->email."</option>\n";
}
?>
-
+
</select></td>
<td valign="top">
<br />
document.studentform.remove.disabled=true;
document.studentform.removeselect.selectedIndex=-1;">
<?php
-
+
if (!empty($searchusers)) {
echo "<optgroup label=\"$strsearchresults (" . count($searchusers) . ")\">\n";
foreach ($searchusers as $user) {
?>
</select>
<br />
- <input type="text" name="searchtext" size="30" value="<?php p($searchtext, true) ?>"
+ <input type="text" name="searchtext" size="30" value="<?php p($searchtext, true) ?>"
onFocus ="document.studentform.add.disabled=true;
document.studentform.remove.disabled=true;
document.studentform.removeselect.selectedIndex=-1;
$strshowall = get_string('showall');
$strparticipants = get_string('participants');
-
+
/// Make sure this user can assign that role
if ($roleid) {
if (!user_can_assign($context, $roleid)) {
error ('you can not override this role in this context');
- }
+ }
}
if ($userid) {
print_header("$fullname", "$fullname",
"<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
<a href=\"".$CFG->wwwroot."/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> ->".$straction,
- "", "", true, " ", navmenu($course));
-
- /// site header
+ "", "", true, " ", navmenu($course));
+
+ /// site header
} else {
print_header("$course->fullname: $fullname", "$course->fullname",
- "<a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
+ "<a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$courseid."\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
}
-
+
$showroles = 1;
$currenttab = 'assign';
include_once($CFG->dirroot.'/user/tabs.php');
$existinguserarray = array();
if (!$contextusers = get_role_users($roleid, $context)) {
- $contextusers = array();
+ $contextusers = array();
}
foreach ($contextusers as $contextuser) {
$existinguserarray[] = $contextuser->id;
}
-
+
$existinguserlist = implode(',', $existinguserarray);
unset($existinguserarray);
}
}
-
+
if ($roleid) {
/// prints a form to swap roles
echo '<form name="rolesform" action="assign.php" method="post">';
$table->head = array(get_string('roles', 'role'), get_string('users'));
$table->wrap = array('nowrap', 'nowrap');
$table->align = array('right', 'center');
-
+
foreach ($assignableroles as $roleid => $rolename) {
$countusers = 0;
if ($contextusers = get_role_users($roleid, $context)) {
}
$table->data[] = array('<a href="assign.php?contextid='.$context->id.'&roleid='.$roleid.$userparam.'">'.$rolename.'</a>', $countusers);
}
-
+
print_table($table);
}
<br />
<?php print_string('roledescription', 'role'); ?>:
<?php print_textarea($usehtmleditor, 10, 50, 50, 10, 'description', $role->description); ?>
-<p>
+<p>
<table>
<tr>
<td><?php print_string('capability','role') ?></td>
<td><?php print_string('risks','role') ?></td>
</tr>
-<?php
+<?php
// init these 2
$contextlevel = 0;
$component = '';
foreach ($capabilities as $capability) {
- // prints a breaker if component or name or context level
+ // prints a breaker if component or name or context level
if ($capability->component != $component or $capability->contextlevel != $contextlevel) {
echo ('<tr><td colspan="4"><strong>'.
- get_component_string($capability->component, $capability->contextlevel).'</strong></td></tr>');
+ get_component_string($capability->component, $capability->contextlevel).'</strong></td></tr>');
}
// these 2 are used to see to group same mod/core capabilities together
?></td>
</tr>
-<?php } ?>
-</table>
+<?php } ?>
+</table>
</p>
<br />
<input type="submit" value="<?php p($submitlabel); ?>" />
if ($roleid && $action!='delete') {
$role = get_record('role', 'id', $roleid);
- $editingstr = '-> '.get_string('editinga', '', $role->name);
+ $editingstr = '-> '.get_string('editinga', '', $role->name);
} else {
- $editingstr ='';
+ $editingstr ='';
}
admin_externalpage_print_header($adminroot);
switch ($action) {
case 'add':
- $newrole = create_role($name, $shortname, $description);
+ $newrole = create_role($name, $shortname, $description);
$ignore = array('roleid', 'sesskey', 'action', 'name', 'description', 'contextid');
$data = data_submitted();
foreach ($data as $capname => $value) {
- if (in_array($capname, $ignore)) {
+ if (in_array($capname, $ignore)) {
continue;
}
$data = data_submitted();
foreach ($data as $capname => $value) {
- if (in_array($capname, $ignore)) {
+ if (in_array($capname, $ignore)) {
continue;
}
$localoverride->permission = $value;
$localoverride->timemodified = time();
$localoverride->modifierid = $USER->id;
- update_record('role_capabilities', $localoverride);
+ update_record('role_capabilities', $localoverride);
}
} else { // insert a record
assign_capability($capname, $value, $roleid, $sitecontext->id);
$role->id = $roleid;
$role->name = $name;
- $role->description = $description;
+ $role->description = $description;
if (!update_record('role', $role)) {
error('Could not update role!');
break;
case 'delete':
- if ($confirm) { // deletes a role
+ if ($confirm) { // deletes a role
// check for depedencies XXX TODO
echo ('<input type="hidden" name="roleid" value="'.$roleid.'">');
echo ('<input type="hidden" name="sesskey" value="'.sesskey().'">');
echo ('<input type="hidden" name="confirm" value="1">');
- notice_yesno(get_string('deleterolesure', 'role'),
+ notice_yesno(get_string('deleterolesure', 'role'),
'manage.php?action=delete&roleid='.$roleid.'&sesskey='.sesskey().'&confirm=1', 'manage.php');
admin_externalpage_print_footer($adminroot);
exit;
}
- break;
+ break;
/// add possible positioning switch here
default:
- break;
+ break;
}
if ($roleid) {
$action='edit';
$role = get_record('role', 'id', $roleid);
- } else {
- $action='add';
+ } else {
+ $action='add';
$role->name='';
$role->shortname='';
$role->description='';
$table->cellspacing = 0;
$table->width = '90%';
- $table->head = array(get_string('roles', 'role'),
- get_string('description'),
+ $table->head = array(get_string('roles', 'role'),
+ get_string('description'),
get_string('delete'));
/*************************
$table->data[] = array('<a href="manage.php?roleid='.$role->id.'&sesskey='.sesskey().'">'.format_string($role->name).'</a>', format_text($role->description, FORMAT_HTML), '<a href="manage.php?action=delete&roleid='.$role->id.'&sesskey='.sesskey().'">'.$strdelete.'</a>');
- }
+ }
print_table($table);
$options = new object;
// this page deals with the 2 tabs for manage.php and grant.php
$toprow[] = new tabobject('manage', $CFG->wwwroot.'/admin/roles/manage.php', get_string('manageroles', 'role'));
-
+
$toprow[] = new tabobject('allowassign', $CFG->wwwroot.'/admin/roles/allowassign.php', get_string('allowassign', 'role'));
$toprow[] = new tabobject('allowoverride', $CFG->wwwroot.'/admin/roles/allowoverride.php', get_string('allowoverride', 'role'));
-
+
$tabs = array($toprow);
-
+
print_tabs($tabs, $currenttab);
?>
- <form action="override.php" method="post">
+ <form action="override.php" method="post">
<input type="hidden" name="contextid" value="<?php p($contextid) ?>">
<input type="hidden" name="roleid" value="<?php p($roleid) ?>">
<?php
<td><?php print_string('prohibit','role') ?></td>
<td><?php print_string('risks','role') ?></td>
</tr>
- <?php
-
+ <?php
+
// init these 2
$contextlevel = 0;
$component = '';
foreach ($capabilities as $capability) {
- // prints a breaker if component or name or context level
+ // prints a breaker if component or name or context level
if ($capability->component != $component or $capability->contextlevel != $contextlevel) {
- echo ('<tr><td colspan="5"><b>'.get_component_string($capability->component, $capability->contextlevel).'</b></td></tr>');
+ echo ('<tr><td colspan="5"><b>'.get_component_string($capability->component, $capability->contextlevel).'</b></td></tr>');
}
-
+
// these 2 are used to see to group same mod/core capabilities together
$contextlevel = $capability->contextlevel;
$component = $capability->component;
-
+
// check the capability override for this cap, this role in this context
if (isset($localoverrides[$capability->name])) {
$localpermission = $localoverrides[$capability->name]->permission;
} else {
$isallow = 0;
$isprevent = 0;
- $isprohibit = 0;
+ $isprohibit = 0;
}
$isdisabled = $isprohibit || islegacy($capability->name);
-
+
?>
-
+
<tr>
<td><?php echo get_capability_string($capability->name); ?></td>
<td align="center">
- <input type="radio" name="<?php echo $capability->name; ?>" value="0"
- <?php
- if ($localpermission == 0) {echo 'checked="checked"';}
+ <input type="radio" name="<?php echo $capability->name; ?>" value="0"
+ <?php
+ if ($localpermission == 0) {echo 'checked="checked"';}
if ($isdisabled) {echo 'disabled="disabled"';}?> />
</td>
<td align="center" <?php if ($isallow) {echo 'class="capcurrent"';} ?>>
<input type="radio" name="<?php echo $capability->name; ?>"
<?php echo ' value="'.CAP_ALLOW.'"';
- if ($localpermission == CAP_ALLOW) {echo ' checked="checked"';}
+ if ($localpermission == CAP_ALLOW) {echo ' checked="checked"';}
if ($isdisabled) {echo ' disabled="disabled"';}?> />
</td>
<td align="center" <?php if ($isprevent) {echo 'class="capcurrent"';} ?>>
- <input type="radio" name="<?php echo $capability->name; ?>"
+ <input type="radio" name="<?php echo $capability->name; ?>"
<?php echo ' value="'.CAP_PREVENT.'"';
- if ($localpermission == CAP_PREVENT) {echo ' checked="checked"';}
+ if ($localpermission == CAP_PREVENT) {echo ' checked="checked"';}
if ($isdisabled) {echo ' disabled="disabled"';}?> />
</td>
<td align="center" <?php if ($isprohibit) {echo 'class="capcurrent"';} ?>>
<input type="radio" name="<?php echo $capability->name; ?>"
<?php echo ' value="'.CAP_PROHIBIT.'"';
- if ($localpermission == CAP_PROHIBIT) {echo ' checked="checked"';}
+ if ($localpermission == CAP_PROHIBIT) {echo ' checked="checked"';}
if ($isdisabled) {echo ' disabled="disabled"';}?> />
</td>
<td><?php
}
?></td>
</tr>
-
- <?php } ?>
- </table>
+
+ <?php } ?>
+ </table>
<br />
<div align="center"><input type="submit" value="<?php print_string('savechanges') ?>" /></div>
</form>
<?php
-
+
require_once("../../config.php");
-
+
$contextid = required_param('contextid',PARAM_INT); // context id
$roleid = optional_param('roleid', 0, PARAM_INT); // required role id
$userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs
$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
-
+
if ($courseid) {
- $course = get_record('course', 'id', $courseid);
+ $course = get_record('course', 'id', $courseid);
} else {
$course = $SITE;
}
-
+
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
if ($contextid == $sitecontext->id) {
error ('can not override base role capabilities');
$context = get_record('context', 'id', $contextid);
$overridableroles = get_overridable_roles($context);
-
+
/// Make sure this user can override that role
if ($roleid) {
if (!user_can_override($context, $roleid)) {
error ('you can not override this role in this context');
- }
+ }
}
-
+
if ($userid) {
$user = get_record('user', 'id', $userid);
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
}
-
+
/// Print the header and tabs
if ($context->aggregatelevel == CONTEXT_USER) {
-
+
/// course header
if ($course->id != SITEID) {
print_header("$fullname", "$fullname",
"<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
<a href=\"".$CFG->wwwroot."/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname</a> -> $straction",
- "", "", true, " ", navmenu($course));
-
- /// site header
+ "", "", true, " ", navmenu($course));
+
+ /// site header
} else {
print_header("$course->fullname: $fullname", "$course->fullname",
- "<a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
+ "<a href=\"".$CFG->wwwroot."/user/view.php?id=".$userid."&course=".$course->id."\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
}
$showroles = 1;
$currenttab = 'override';
/// Process incoming role override
if ($data = data_submitted()) {
- $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
+ $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
'', 'capability, permission, id');
foreach ($data as $capname => $value) {
if ($capname == 'contextid' || $capname == 'roleid') { // ignore contextid and roleid
- continue;
+ continue;
}
-
+
if (isset($localoverrides[$capname])) { // Something exists, so update it
-
+
if ($value == CAP_INHERIT) { // inherit = delete
- delete_records('role_capabilities', 'roleid', $roleid, 'contextid', $contextid,
+ delete_records('role_capabilities', 'roleid', $roleid, 'contextid', $contextid,
'capability', $capname);
} else {
$localoverride = new object;
$localoverride->permission = $value;
$localoverride->timemodified = time();
$localoverride->modifierid = $USER->id;
-
+
if (!update_record('role_capabilities', $localoverride)) {
debugging('Could not update a capability!');
}
}
-
+
} else { // insert a record
-
+
if ($value != CAP_INHERIT) { // Ignore inherits
$override->capability = $capname;
$override->contextid = $contextid;
} else {
$parentcontext = $context; // site level in override??
}
-
+
$r_caps = role_context_capabilities($roleid, $parentcontext);
- $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
+ $localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
'', 'capability, permission, id');
-
+
// Get the capabilities overrideable in this context
if ($capabilities = fetch_context_capabilities($context)) {
print_simple_box_start("center");
} else { // Print overview table
$userparam = (!empty($userid)) ? '&userid='.$userid : '';
-
+
$table->tablealign = 'center';
$table->cellpadding = 5;
$table->cellspacing = 0;
$table->head = array(get_string('roles', 'role'), get_string('overrides', 'role'));
$table->wrap = array('nowrap', 'nowrap');
$table->align = array('right', 'center');
-
+
foreach ($overridableroles as $roleid => $rolename) {
$countusers = 0;
$overridecount = count_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id");
$table->data[] = array('<a href="override.php?contextid='.$context->id.'&roleid='.$roleid.$userparam.'">'.$rolename.'</a>', $overridecount);
}
-
+
print_table($table);
}
-
+
print_footer($course);
-
+
?>
$blockname = print_context_name($context);
$navigation = $blockname. ' -> '.$straction;
- switch ($blockinstance->pagetype) {
+ switch ($blockinstance->pagetype) {
case 'course-view':
if ($course = get_record('course', 'id', $blockinstance->pageid)) {
if ($course->id != SITEID) {
$toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.
$context->instanceid.'&return=true&sesskey='.sesskey(), get_string('update'));
- }
+ }
$toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.
- $context->id, get_string('roles'));
+ $context->id, get_string('roles'));
if (isset($tabsmode)) {
if (!isset($assignableroles)) {
- $assignableroles = get_assignable_roles($context);
+ $assignableroles = get_assignable_roles($context);
}
if (!isset($overridableroles)) {
- $overridableroles = get_overridable_roles($context);
+ $overridableroles = get_overridable_roles($context);
}
$inactive[] = 'roles';
if (!empty($assignableroles)) {
- $secondrow[] = new tabobject('assign',
- $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id,
- get_string('assignroles', 'role'),
- get_string('showallroles', 'role'),
- true);
+ $secondrow[] = new tabobject('assign',
+ $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id,
+ get_string('assignroles', 'role'),
+ get_string('showallroles', 'role'),
+ true);
}
- if (!empty($overridableroles)) {
- $secondrow[] = new tabobject('override',
+ if (!empty($overridableroles)) {
+ $secondrow[] = new tabobject('override',
$CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id,
- get_string('overrideroles', 'role'),
- get_string('showallroles', 'role'),
- true);
+ get_string('overrideroles', 'role'),
+ get_string('showallroles', 'role'),
+ true);
}
if ($tabsmode == 'override') {
- $currenttab = 'override';
+ $currenttab = 'override';
} elseif ($tabsmode == 'assign') {
- $currenttab = 'assign';
+ $currenttab = 'assign';
}
} else {
- $inactive[] = '';
+ $inactive[] = '';
}
if (!empty($secondrow)) {
if ($site = get_site()) {
require_login();
-}
+}
page_map_class(PAGE_ADMIN, 'page_admin');
$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
$return = optional_param('return','', PARAM_ALPHA);
-
+
if (!isset($USER->adminediting)) {
$USER->adminediting = false;
}
if (!empty($SITE->fullname)) {
$pageblocks = blocks_setup($PAGE);
- $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
+ $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
BLOCK_L_MAX_WIDTH);
- $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
+ $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
BLOCK_R_MAX_WIDTH);
-
+
// print header stuff
$PAGE->print_header();
$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'),
+$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,
+$temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'),
+ '', 3,
array('0' => '0',
'1' => '1',
'2' => '2',
$temp->add(new admin_setting_configcheckbox('messaging', get_string('messaging', 'admin'), get_string('configmessaging','admin'), 1));
$temp->add(new admin_setting_configcheckbox('allowobjectembed', get_string('allowobjectembed', 'admin'), get_string('configallowobjectembed', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('enabletrusttext', get_string('enabletrusttext', 'admin'), get_string('configenabletrusttext', 'admin'), 0));
-$temp->add(new admin_setting_configselect('maxeditingtime', get_string('maxeditingtime','admin'), get_string('configmaxeditingtime','admin'), 1800,
+$temp->add(new admin_setting_configselect('maxeditingtime', get_string('maxeditingtime','admin'), get_string('configmaxeditingtime','admin'), 1800,
array(60 => get_string('numminutes', '', 1),
300 => get_string('numminutes', '', 5),
900 => get_string('numminutes', '', 15),
1800 => get_string('numminutes', '', 30),
2700 => get_string('numminutes', '', 45),
3600 => get_string('numminutes', '', 60))));
-$temp->add(new admin_setting_configselect('fullnamedisplay', get_string('fullnamedisplay', 'admin'), get_string('configfullnamedisplay', 'admin'),
+$temp->add(new admin_setting_configselect('fullnamedisplay', get_string('fullnamedisplay', 'admin'), get_string('configfullnamedisplay', 'admin'),
'firstname lastname', array('language' => get_string('language'),
'firstname lastname' => get_string('firstname') . ' + ' . get_string('lastname'),
'lastname firstname' => get_string('lastname') . ' + ' . get_string('firstname'),
$temp->add(new admin_setting_configselect('restrictmodulesfor', get_string('restrictmodulesfor', 'admin'), get_string('configrestrictmodulesfor', 'admin'), 'none', array('none' => 'No courses',
'all' => 'All courses',
'requested' => 'Requested courses')));
-$temp->add(new admin_setting_configcheckbox('restrictbydefault', get_string('restrictbydefault', 'admin'), get_string('configrestrictbydefault', 'admin'), 0));
+$temp->add(new admin_setting_configcheckbox('restrictbydefault', get_string('restrictbydefault', 'admin'), get_string('configrestrictbydefault', 'admin'), 0));
if (!$options = get_records("modules")) {
$options = array();
}
// "systempaths" settingpage
$temp = new admin_settingpage('systempaths', get_string('systempaths','admin'));
-$temp->add(new admin_setting_configselect('gdversion', get_string('gdversion','admin'), get_string('configgdversion', 'admin'), check_gd_version(), array('0' => get_string('gdnot'),
- '1' => get_string('gd1'),
+$temp->add(new admin_setting_configselect('gdversion', get_string('gdversion','admin'), get_string('configgdversion', 'admin'), check_gd_version(), array('0' => get_string('gdnot'),
+ '1' => get_string('gd1'),
'2' => get_string('gd2'))));
$temp->add(new admin_setting_configtext('zip', get_string('pathtozip','admin'), get_string('configzip', 'admin'), '', PARAM_PATH));
$temp->add(new admin_setting_configtext('unzip', get_string('pathtounzip','admin'), get_string('configunzip', 'admin'), '', PARAM_PATH));
$temp->add(new admin_setting_configtext('noreplyaddress', get_string('noreplyaddress', 'admin'), get_string('confignoreplyaddress', 'admin'), 'noreply@' . $_SERVER['HTTP_HOST'], PARAM_NOTAGS));
$temp->add(new admin_setting_configtext('allowemailaddresses', get_string('allowemailaddresses', 'admin'), get_string('configallowemailaddresses', 'admin'), '', PARAM_NOTAGS));
$temp->add(new admin_setting_configtext('denyemailaddresses', get_string('denyemailaddresses', 'admin'), get_string('configdenyemailaddresses', 'admin'), '', PARAM_NOTAGS));
-$temp->add(new admin_setting_configselect('digestmailtime', get_string('digestmailtime', 'admin'), get_string('configdigestmailtime', 'admin'), 17, array('00' => '00',
- '01' => '01',
- '02' => '02',
- '03' => '03',
- '04' => '04',
- '05' => '05',
- '06' => '06',
- '07' => '07',
- '08' => '08',
- '09' => '09',
- '10' => '10',
- '11' => '11',
- '12' => '12',
- '13' => '13',
- '14' => '14',
- '15' => '15',
- '16' => '16',
- '17' => '17',
- '18' => '18',
- '19' => '19',
- '20' => '20',
- '21' => '21',
- '22' => '22',
+$temp->add(new admin_setting_configselect('digestmailtime', get_string('digestmailtime', 'admin'), get_string('configdigestmailtime', 'admin'), 17, array('00' => '00',
+ '01' => '01',
+ '02' => '02',
+ '03' => '03',
+ '04' => '04',
+ '05' => '05',
+ '06' => '06',
+ '07' => '07',
+ '08' => '08',
+ '09' => '09',
+ '10' => '10',
+ '11' => '11',
+ '12' => '12',
+ '13' => '13',
+ '14' => '14',
+ '15' => '15',
+ '16' => '16',
+ '17' => '17',
+ '18' => '18',
+ '19' => '19',
+ '20' => '20',
+ '21' => '21',
+ '22' => '22',
'23' => '23')));
if (!empty($CFG->unicodedb)) { // These options are only available if running under unicodedb
unset($options);
$temp = new admin_settingpage('debugging', get_string('debugging', 'admin'));
$temp->add(new admin_setting_special_debug());
$temp->add(new admin_setting_special_perfdebug());
-$ADMIN->add('server', $temp);
+$ADMIN->add('server', $temp);
// "stats" settingpage
60*60*8 => '8 '.get_string('hours') )));
$temp->add(new admin_setting_configtime('statsruntimestarthour', 'statsruntimestartminute', get_string('statsruntimestart', 'admin'), get_string('configstatsruntimestart', 'admin'), array('h' => 0, 'm' => 0)));
$temp->add(new admin_setting_configtext('statsuserthreshold', get_string('statsuserthreshold', 'admin'), get_string('configstatsuserthreshold', 'admin'), 0, PARAM_INT));
-$ADMIN->add('server', $temp);
+$ADMIN->add('server', $temp);
// "http" settingpage
$temp->add(new admin_Setting_configcheckbox('slasharguments', get_string('slasharguments', 'admin'), get_string('configslasharguments', 'admin'), 1));
$temp->add(new admin_setting_configtext('proxyhost', get_string('proxyhost', 'admin'), get_string('configproxyhost', 'admin'), '', PARAM_HOST));
$temp->add(new admin_setting_configtext('proxyport', get_string('proxyport', 'admin'), get_string('configproxyport', 'admin'), '', PARAM_INT));
-$ADMIN->add('server', $temp);
+$ADMIN->add('server', $temp);
$ADMIN->add('server', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID));
}
$assignableroles = get_assignable_roles($context);
-$temp->add(new admin_setting_configselect('notloggedinroleid', get_string('notloggedinroleid', 'admin'),
+$temp->add(new admin_setting_configselect('notloggedinroleid', get_string('notloggedinroleid', 'admin'),
get_string('confignotloggedinroleid', 'admin'), $guestrole->id, $assignableroles ));
-$temp->add(new admin_setting_configselect('defaultuserroleid', get_string('defaultuserroleid', 'admin'),
+$temp->add(new admin_setting_configselect('defaultuserroleid', get_string('defaultuserroleid', 'admin'),
get_string('configdefaultuserroleid', 'admin'), $guestrole->id, $assignableroles));
-$temp->add(new admin_setting_configselect('defaultcourseroleid', get_string('defaultcourseroleid', 'admin'),
+$temp->add(new admin_setting_configselect('defaultcourseroleid', get_string('defaultcourseroleid', 'admin'),
get_string('configdefaultcourseroleid', 'admin'), $studentrole->id, $assignableroles));
//$temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0));
//$temp->add(new admin_setting_configcheckbox('allusersaresitestudents', get_string('allusersaresitestudents', 'admin'), get_string('configallusersaresitestudents','admin'), 1));
-$temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('hiddenuserfields', 'admin'),
- get_string('confighiddenuserfields', 'admin'), array(),
+$temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('hiddenuserfields', 'admin'),
+ get_string('confighiddenuserfields', 'admin'), array(),
array('none' => get_string('none'),
'description' => get_string('description'),
'city' => get_string('city'),
<?php // $Id$
-// detects settings that were added during an upgrade, displays a screen for the admin to
+// detects settings that were added during an upgrade, displays a screen for the admin to
// modify them, and then processes modifications
require_once('../config.php');
// first we deal with the case where there are no new settings to be set
if ($newsettingshtml == '') {
- redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
+ redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
die;
}
/**
* Find settings that have not been initialized (e.g. during initial install or an upgrade).
- *
+ *
* Tests each setting's get_setting() method. If the result is NULL, we consider the setting
* to be uninitialized.
*
$return = array_merge($return, find_new_settings($node->children[$entry]));
}
return $return;
- }
+ }
- if (is_a($node, 'admin_settingpage')) {
+ if (is_a($node, 'admin_settingpage')) {
$return = array();
foreach ($node->settings as $setting) {
if ($setting->get_setting() === NULL) {
$return .= output_new_settings_by_page($node->children[$entry]);
}
return $return;
- }
+ }
- if (is_a($node, 'admin_settingpage')) {
+ if (is_a($node, 'admin_settingpage')) {
$newsettings = array();
foreach ($node->settings as $setting) {
if ($setting->get_setting() === NULL) {
$return = '<tr><td colspan="2"><strong>' . $node->visiblename . '</strong></td></tr>';
foreach ($newsettings as $newsetting) {
$return .= $newsetting->output_html();
- }
+ }
}
return $return;
}
2006-07-11 - Important notes
-I've just discovered this some seconds ago, in order
+I've just discovered this some seconds ago, in order
to test properly the XMLDB classes and editor:
1.- PHP 5 required for now. Will change this soon.
2006-07-11 - Initial commit
-This directory contains the XMLDB classes to be used
-under Moodle > 1.7 to store all the DB info in a
+This directory contains the XMLDB classes to be used
+under Moodle > 1.7 to store all the DB info in a
neutral form (classes dir). Also it contains one simple
interface to edit all those structures.
to http://your.server/moodle/admin/xmldb
The edition interface isn't completed yet (it laks 3 more forms
-to edit fields, keys and indexes) and there isn't any lang file
+to edit fields, keys and indexes) and there isn't any lang file
(although I hope everything is really clear).
The edition interface includes one reverse-engineering tool that
"generators" needed in order to use it to create Moodle DB structures
for each RDBMS flavour.
-Once the interface was finished (2-3 days from now) related documentation
-will be sent to http://docs.moodle.org/en/XML_database_schema in order
+Once the interface was finished (2-3 days from now) related documentation
+will be sent to http://docs.moodle.org/en/XML_database_schema in order
to comment/modify/approve the final XML format.
-All the code is, obviously GPL, with its copyrights and so on...
+All the code is, obviously GPL, with its copyrights and so on...
Ciao, Eloy Lafuente (stronk7) :-)
// //
///////////////////////////////////////////////////////////////////////////
-/// This is the main action class. It implements all the basic
+/// This is the main action class. It implements all the basic
/// functionalities to be shared by each action.
class XMLDBAction {
* Constructor to keep PHP5 happy
*/
function __construct() {
- $this->XMLDBAction();
+ $this->XMLDBAction();
}
- /**
- * Init method, every subclass will have its own,
+ /**
+ * Init method, every subclass will have its own,
* always calling the parent one
*/
function init() {
$this->errormsg = NULL;
$this->subaction = NULL;
}
-
+
/**
* returns the type of output of the file
*/
}
/**
- * getPostAtion method, returns the action to launch after executing
+ * getPostAtion method, returns the action to launch after executing
* another one
*/
function getPostAction() {
return $this->postaction;
}
- /**
+ /**
* getTitle method returns the title of the action (that is part
* of the $str array attribute
*/
/**
* main invoke method, it simply sets the postaction attribute
- * if possible
+ * if possible
*/
function invoke() {
global $SESSION;
-
+
/// If we are used any dir, save it in the lastused session object
/// Some actions can use it to perform positioning
if ($lastused = optional_param ('dir', NULL, PARAM_PATH)) {
$SESSION->lastused = stripslashes_safe($lastused);
}
-
+
$this->postaction = optional_param ('postaction', NULL, PARAM_ALPHAEXT);
/// Avoid being recursive
if ($this->title == $this->postaction) {
$result = false;
if (file_exists($actionpath) && is_readable($actionpath)) {
require_once($actionpath);
- if ($xmldb_action = new $action) {
+ if ($xmldb_action = new $action) {
$result = $xmldb_action->invoke();
if ($result) {
if ($xmldb_action->does_generate != ACTION_NONE &&
// //
///////////////////////////////////////////////////////////////////////////
-/// This class will
+/// This class will
class create_xml_file extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$xmlcomment = 'XMLDB file for Moodle ' . dirname($xmlpath);
$xmltable = strtolower(basename(dirname($xmlpath)));
-
+
/// Initial contents
$c = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
$c.= ' <XMLDB PATH="' . $xmlpath . '" VERSION="' . $xmlversion .'" COMMENT="' . $xmlcomment .'">' . "\n";
class delete_field extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Recalculate the hash
$structure->calculateHash(true);
-
+
/// If the hash has changed from the original one, change the version
/// and mark the structure as changed
$origstructure =& $dbdir->xml_file->getStructure();
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class delete_index extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Recalculate the hash
$structure->calculateHash(true);
-
+
/// If the hash has changed from the original one, change the version
/// and mark the structure as changed
$origstructure =& $dbdir->xml_file->getStructure();
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class delete_key extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Recalculate the hash
$structure->calculateHash(true);
-
+
/// If the hash has changed from the original one, change the version
/// and mark the structure as changed
$origstructure =& $dbdir->xml_file->getStructure();
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class delete_sentence extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Recalculate the hash
$structure->calculateHash(true);
-
+
/// If the hash has changed from the original one, change the version
/// and mark the structure as changed
$origstructure =& $dbdir->xml_file->getStructure();
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class delete_statement extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class delete_table extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class delete_xml_file extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class edit_field extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Register the needed events
- onload=function() {
+ onload=function() {
/// Adjust the form on load
transformForm();
class edit_field_save extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$length > 0 && $length <= 20)) {
$errors[] = $this->str['integerincorrectlength'];
}
- if (!(empty($default) || (is_numeric($default) &&
+ if (!(empty($default) || (is_numeric($default) &&
!empty($default) &&
intval($default)==floatval($default)))) {
$errors[] = $this->str['defaultincorrect'];
$length > 0 && $length <= 20)) {
$errors[] = $this->str['numberincorrectlength'];
}
- if (!(empty($decimals) || (is_numeric($decimals) &&
- !empty($decimals) &&
+ if (!(empty($decimals) || (is_numeric($decimals) &&
+ !empty($decimals) &&
intval($decimals)==floatval($decimals) &&
- $decimals >= 0 &&
+ $decimals >= 0 &&
$decimals < $length))) {
$errors[] = $this->str['numberincorrectdecimals'];
}
- if (!(empty($default) || (is_numeric($default) &&
+ if (!(empty($default) || (is_numeric($default) &&
!empty($default)))) {
$errors[] = $this->str['defaultincorrect'];
}
}
/// Float checks
if ($type == XMLDB_TYPE_FLOAT) {
- if (!(empty($length) || (is_numeric($length) &&
- !empty($length) &&
+ if (!(empty($length) || (is_numeric($length) &&
+ !empty($length) &&
intval($length)==floatval($length) &&
- $length > 0 &&
+ $length > 0 &&
$length <= 20))) {
$errors[] = $this->str['floatincorrectlength'];
}
- if (!(empty($decimals) || (is_numeric($decimals) &&
- !empty($decimals) &&
+ if (!(empty($decimals) || (is_numeric($decimals) &&
+ !empty($decimals) &&
intval($decimals)==floatval($decimals) &&
- $decimals >= 0 &&
+ $decimals >= 0 &&
$decimals < $length))) {
$errors[] = $this->str['floatincorrectdecimals'];
}
- if (!(empty($default) || (is_numeric($default) &&
+ if (!(empty($default) || (is_numeric($default) &&
!empty($default)))) {
$errors[] = $this->str['defaultincorrect'];
}
}
} else {
$enumerr = true;
- }
+ }
if ($enumerr) {
$errors[] = $this->str['enumvaluesincorrect'];
} else {
$tempfield->setDefault($default);
/// Prepare the output
$site = get_site();
- print_header("$site->shortname: XMLDB",
- "$site->fullname",
+ print_header("$site->shortname: XMLDB",
+ "$site->fullname",
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
notice ('<p>' .implode(', ', $errors) . '</p>
<p>' . $tempfield->readableInfo(),
$next->setChanged(true);
}
}
-
- /// Set comment
+
+ /// Set comment
$field->setComment($comment);
/// Set the rest of fields
$field->setEnum($enum);
$field->setEnumValues($enumvalues);
$field->setDefault($default);
-
+
/// If the hash has changed from the old one, change the version
/// and mark the structure as changed
$field->calculateHash(true);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
}
class edit_index extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class edit_index_save extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$tempindex->setFields($fieldsarr);
/// Prepare the output
$site = get_site();
- print_header("$site->shortname: XMLDB",
- "$site->fullname",
+ print_header("$site->shortname: XMLDB",
+ "$site->fullname",
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
notice ('<p>' .implode(', ', $errors) . '</p>
<p>' . $tempindex->readableInfo(),
$next->setChanged(true);
}
}
-
- /// Set comment
+
+ /// Set comment
$index->setComment($comment);
/// Set the rest of fields
$index->setUnique($unique);
$index->setFields($fieldsarr);
-
+
/// If the hash has changed from the old one, change the version
/// and mark the structure as changed
$index->calculateHash(true);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
}
class edit_key extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Register the needed events
- onload=function() {
+ onload=function() {
/// Adjust the form on load
transformForm();
class edit_key_save extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Check reftable is not empty
if (empty($reftable)) {
$errors[] = $this->str['noreftablespecified'];
- } else
+ } else
/// Check reffields are not empty
if (empty($reffieldsarr[0])) {
$errors[] = $this->str['noreffieldsspecified'];
- } else
+ } else
/// Check the number of fields is correct
if (count($fieldsarr) != count($reffieldsarr)) {
$errors[] = $this->str['wrongnumberofreffields'];
}
/// Prepare the output
$site = get_site();
- print_header("$site->shortname: XMLDB",
- "$site->fullname",
+ print_header("$site->shortname: XMLDB",
+ "$site->fullname",
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
notice ('<p>' .implode(', ', $errors) . '</p>
<p>' . $tempkey->readableInfo(),
$next->setChanged(true);
}
}
-
- /// Set comment
+
+ /// Set comment
$key->setComment($comment);
/// Set the rest of fields
$key->setRefTable($reftable);
$key->setRefFields($reffieldsarr);
}
-
+
/// If the hash has changed from the old one, change the version
/// and mark the structure as changed
$key->calculateHash(true);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
}
class edit_sentence extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$b .= ' <a href="index.php?action=edit_statement&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
$b .= '</p>';
$o .= $b;
-
+
$this->output = $o;
}
-
+
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class edit_sentence_save extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
if ($result && count($fields) != count($values)) {
$errors[] = $this->str['wrongnumberoffieldsorvalues'];
}
-
+
if (!empty($errors)) {
/// Prepare the output
$site = get_site();
- print_header("$site->shortname: XMLDB",
- "$site->fullname",
+ print_header("$site->shortname: XMLDB",
+ "$site->fullname",
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
notice ('<p>' .implode(', ', $errors) . '</p>
<p>' . s($sentence),
/// Continue if we aren't under errors
if (empty($errors)) {
$sentences[$sentenceparam] = $sentence;
-
+
/// If the sentence has changed from the old one, change the version
/// and mark the statement and structure as changed
if ($oldsentence != $sentence) {
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
}
class edit_statement extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
///$statement->deleteSentence('changeme');
/// Add the fields list
- $sentences =& $statement->getSentences();
+ $sentences =& $statement->getSentences();
if (!empty($sentences)) {
$o .= '<h3 class="main">' . $this->str['sentences'] . '</h3>';
$o .= '<table id="listfields" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
$b .= '<a href="index.php?action=delete_sentence&sentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
$b .= '</td>';
/// Print table row
- $o .= '<tr class="r' . $row . '"><td class="table cell">' . $p . $sentence . $b . '</tr>';
+ $o .= '<tr class="r' . $row . '"><td class="table cell">' . $p . $sentence . $b . '</tr>';
$row = ($row + 1) % 2;
}
$o .= '</table>';
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class edit_statement_save extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
}
- /// Set comment
+ /// Set comment
$statement->setComment($comment);
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class edit_table extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$table->deleteIndex('changeme');
/// Add the fields list
- $fields =& $table->getFields();
+ $fields =& $table->getFields();
if (!empty($fields)) {
$o .= '<h3 class="main">' . $this->str['fields'] . '</h3>';
$o .= '<table id="listfields" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
}
$b .= '</td><td class="button cell">';
/// The delete button (if we have more than one and it isn't used
- if (count($fields) > 1 &&
+ if (count($fields) > 1 &&
!$structure->getFieldUses($table->getName(), $field->getName())) {
$b .= '<a href="index.php?action=delete_field&field=' . $field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
} else {
/// The readable info
$r = '</td><td class="readableinfo cell">' . $field->readableInfo() . '</td>';
/// Print table row
- $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_field_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&field=' . $field->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $field->getName() . '</a>' . $b . $r . '</tr>';
+ $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_field_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&field=' . $field->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $field->getName() . '</a>' . $b . $r . '</tr>';
$row = ($row + 1) % 2;
}
$o .= '</table>';
}
/// Add the keys list
- $keys =& $table->getKeys();
+ $keys =& $table->getKeys();
if (!empty($keys)) {
$o .= '<h3 class="main">' . $this->str['keys'] . '</h3>';
$o .= '<table id="listkeys" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
/// The readable info
$r = '</td><td class="readableinfo cell">' . $key->readableInfo() . '</td>';
/// Print table row
- $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_key_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&key=' . $key->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $key->getName() . '</a>' . $b . $r .'</tr>';
+ $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_key_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&key=' . $key->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $key->getName() . '</a>' . $b . $r .'</tr>';
$row = ($row + 1) % 2;
}
$o .= '</table>';
}
/// Add the indexes list
- $indexes =& $table->getIndexes();
+ $indexes =& $table->getIndexes();
if (!empty($indexes)) {
$o .= '<h3 class="main">' . $this->str['indexes'] . '</h3>';
$o .= '<table id="listindexes" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
/// The readable info
$r = '</td><td class="readableinfo cell">' . $index->readableInfo() . '</td>';
/// Print table row
- $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&index=' . $index->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $index->getName() . '</a>' . $b . $r .'</tr>';
+ $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&index=' . $index->getName() . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $index->getName() . '</a>' . $b . $r .'</tr>';
$row = ($row + 1) % 2;
}
$o .= '</table>';
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class edit_table_save extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
}
- /// Set comment
+ /// Set comment
$table->setComment($comment);
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class edit_xml_file extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
sort($reserved_words);
$reserved_words = array_unique($reserved_words);
/// Add the tables list
- $tables =& $structure->getTables();
+ $tables =& $structure->getTables();
if ($tables) {
$o .= '<h3 class="main">' . $this->str['tables'] . '</h3>';
$o .= '<table id="listtables" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
}
$b .= '</td>';
/// Print table row
- $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $table->getName() . '</a>' . $b . '</tr>';
+ $o .= '<tr class="r' . $row . '"><td class="table cell"><a href="index.php?action=view_table_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&table=' . $table->getName() . '&select=edited" target="_blank">' . $table->getName() . '</a>' . $b . '</tr>';
$row = ($row + 1) % 2;
}
$o .= '</table>';
}
///Add the statements list
- $statements =& $structure->getStatements();
+ $statements =& $structure->getStatements();
if ($statements) {
$o .= '<h3 class="main">' . $this->str['statements'] . '</h3>';
$o .= '<table id="liststatements" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
$b .= '<a href="index.php?action=delete_statement&statement=' . $statement->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
$b .= '</td>';
/// Print statement row
- $o .= '<tr class="r' . $row . '"><td class="statement cell"><a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&statement=' . $statement->getName() . '&select=edited" target="_blank">' . $statement->getName() . '</a>' . $b . '</tr>';
+ $o .= '<tr class="r' . $row . '"><td class="statement cell"><a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&statement=' . $statement->getName() . '&select=edited" target="_blank">' . $statement->getName() . '</a>' . $b . '</tr>';
$row = ($row + 1) % 2;
}
$o .= '</table>';
class edit_xml_file_save extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// //
///////////////////////////////////////////////////////////////////////////
-/// This class will check all the db directories existing under the
+/// This class will check all the db directories existing under the
/// current Moodle installation, sending them to the SESSION->dbdirs array
class get_db_directories extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path); //Update status
}
}
-
+
/// Now, question types (question/type/xxx/db)
if ($plugins = get_list_of_plugins('question/type')) {
foreach ($plugins as $plugin) {
$XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path); //Update status
}
}
-
+
/// Now, backup/restore stuff (backup/db)
$dbdir = new stdClass;
$dbdir->path = $CFG->dirroot . '/backup/db';
$XMLDB->dbdirs[$dbdir->path]->path_exists = file_exists($dbdir->path); //Update status
}
}
-
+
/// Now, enrolment plugins (enrol/xxx/db)
if ($plugins = get_list_of_plugins('enrol', 'db')) {
foreach ($plugins as $plugin) {
}
/// Sort by key
ksort($XMLDB->dbdirs);
-
+
/// Return ok if arrived here
return true;
}
class load_xml_file extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class load_xml_files extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class main_view extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class move_updown_field extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Table has changed
$table->setChanged(true);
-
+
/// Reorder the fields
$table->orderFields($fields);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class move_updown_index extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Table has changed
$table->setChanged(true);
-
+
/// Reorder the indexes
$table->orderIndexes($indexes);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class move_updown_key extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Table has changed
$table->setChanged(true);
-
+
/// Reorder the keys
$table->orderKeys($keys);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class move_updown_statement extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Statement has changed
$statement->setChanged(true);
-
+
/// Reorder the structure
$structure->orderStatements($statements);
/// Send statements back to structure (the order above break refs)
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class move_updown_table extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Table has changed
$table->setChanged(true);
-
+
/// Reorder the structure
$structure->orderTables($tables);
/// Send tables back to structure (the order above break refs)
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class new_field extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class new_index extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$structure->setChanged(true);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class new_key extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$structure->setChanged(true);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class new_sentence extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$structure->setChanged(true);
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class new_statement extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$this->output = $o;
- /// If table, retrofit information and, if everything works,
+ /// If table, retrofit information and, if everything works,
/// go to the table edit action
} else {
/// Get some params (table is mandatory here)
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class new_table extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$structure->addTable($table);
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// //
///////////////////////////////////////////////////////////////////////////
-/// This class will ask and retrofit all the information from one
+/// This class will ask and retrofit all the information from one
/// mysql table present in the Moodle DB to one XMLDBTable structure
class new_table_from_mysql extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$this->output = $o;
- /// If table, retrofit information and, if everything works,
+ /// If table, retrofit information and, if everything works,
/// go to the table edit action
} else {
/// Get some params (table is mandatory here)
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class revert_changes extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class save_xml_file extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
- /// Get the edited dir
+ /// Get the edited dir
if (!empty($XMLDB->editeddirs)) {
if (isset($XMLDB->editeddirs[$dirpath])) {
$editeddir =& $XMLDB->editeddirs[$dirpath];
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
// //
///////////////////////////////////////////////////////////////////////////
-/// This class will
+/// This class will
class template extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class test extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class unload_xml_file extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class view_field_xml extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class view_index_xml extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class view_key_xml extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class view_reserved_words extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
}
}
$wronguses[] = $this->str['table'] . ' - ' . $table . ' (' . implode(', ',$list_of_db) . ')';
-
+
}
$dbfields = $db->MetaColumns($dbtable);
if ($dbfields) {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class view_statement_xml extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class view_structure_php extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$structure =& $editeddir->xml_file->getStructure();
}
/// ADD YOUR CODE HERE
-
+
$tables =& $structure->getTables();
$table = reset($tables);
$defaulttable = null;
$o = $b;
/// Calculate the popup of commands
- $commands = array('create_table',
+ $commands = array('create_table',
'drop_table',
'rename_table');
foreach ($commands as $command) {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
}
/**
- * This function will generate all the PHP code needed to
+ * This function will generate all the PHP code needed to
* create one table using XMLDB objects and functions
- *
+ *
* @param XMLDBStructure structure object containing all the info
* @param string table table code to be created
* @return string PHP code to be used to create the table
}
/**
- * This function will generate all the PHP code needed to
+ * This function will generate all the PHP code needed to
* drop one table using XMLDB objects and functions
- *
+ *
* @param XMLDBStructure structure object containing all the info
* @param string table table code to be dropped
* @return string PHP code to be used to drop the table
}
/**
- * This function will generate all the PHP code needed to
+ * This function will generate all the PHP code needed to
* rename one table using XMLDB objects and functions
- *
+ *
* @param XMLDBStructure structure object containing all the info
* @param string table table code to be renamed
* @return string PHP code to be used to rename the table
class view_structure_sql extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class view_structure_xml extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class view_table_php extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// ADD YOUR CODE HERE
$tableparam = required_param('table', PARAM_PATH);
-
+
$table =& $structure->getTable($tableparam);
$fields = $table->getFields();
$field = reset($fields);
$o .= '<h3 class="main">' . $this->str['table'] . ': ' . s($tableparam) . '</h3>';
/// Calculate the popup of commands
- $commands = array('add_field',
+ $commands = array('add_field',
'drop_field',
'rename_field');
foreach ($commands as $command) {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
}
/**
- * This function will generate all the PHP code needed to
+ * This function will generate all the PHP code needed to
* create one field using XMLDB objects and functions
- *
+ *
* @param XMLDBStructure structure object containing all the info
* @param string table table name
* @param string field field name to be created
}
/**
- * This function will generate all the PHP code needed to
+ * This function will generate all the PHP code needed to
* drop one field using XMLDB objects and functions
- *
+ *
* @param XMLDBStructure structure object containing all the info
* @param string table table name
* @param string field field name to be dropped
}
/**
- * This function will generate all the PHP code needed to
+ * This function will generate all the PHP code needed to
* rename one field using XMLDB objects and functions
- *
+ *
* @param XMLDBStructure structure object containing all the info
* @param string table table name
* @param string field field name to be renamed
/**
* This function disables some elements from the fields/keys/indexes drop down
*/
-function disablePopupHeads() {
- var popup = document.getElementById("menufieldkeyindex");
- var i = popup.length;
- while (i--) {
- option = popup[i];
- if (option.value == "fieldshead" || option.value == "keyshead" || option.value == "indexeshead") {
- popup[i].disabled = true;
- }
+function disablePopupHeads() {
+ var popup = document.getElementById("menufieldkeyindex");
+ var i = popup.length;
+ while (i--) {
+ option = popup[i];
+ if (option.value == "fieldshead" || option.value == "keyshead" || option.value == "indexeshead") {
+ popup[i].disabled = true;
+ }
}
}
class view_table_sql extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
$this->output = $o;
/// Launch postaction if exists (leave this here!)
- if ($this->getPostAction() && $result) {
+ if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
class view_table_xml extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
class view_xml extends XMLDBAction {
- /**
+ /**
* Init method, every subclass will have its own
*/
function init() {
/// Get the file parameter
$file = required_param('file', PARAM_PATH);
$file = $CFG->dirroot . stripslashes_safe($file);
- /// File must be under $CFG->wwwroot and
+ /// File must be under $CFG->wwwroot and
/// under one db directory (simple protection)
if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot &&
substr(dirname($file), -2, 2) == 'db') {
require_once('../../lib/xmldb/classes/XMLDBIndex.class.php');
require_once('../../lib/xmldb/classes/XMLDBStatement.class.php');
-/// Add Moodle config script (this is loaded AFTER all the rest
+/// Add Moodle config script (this is loaded AFTER all the rest
/// of classes because it starts the SESSION and classes to be
/// stored there MUST be declared before in order to avoid
/// getting "incomplete" objects
$stradministration = get_string('administration');
/// Body of the script, based on action, we delegate the work
- $action = optional_param ('action', 'main_view', PARAM_ALPHAEXT);
+ $action = optional_param ('action', 'main_view', PARAM_ALPHAEXT);
/// Get the action path and invoke it
$actionsroot = "$CFG->dirroot/$CFG->admin/xmldb/actions";
/// Based on getDoesGenerate()
switch ($xmldb_action->getDoesGenerate()) {
case ACTION_GENERATE_HTML:
- /// Define $CFG->javascript to use our custom javascripts.
+ /// Define $CFG->javascript to use our custom javascripts.
/// Save the original one to add it from ours. Global too! :-(
global $standard_javascript;
$standard_javascript = $CFG->javascript; // Save original javascript file
$CFG->javascript = $CFG->dirroot.'/admin/xmldb/javascript.php'; //Use our custom javascript code
/// Go with standard header
- print_header("$site->shortname: XMLDB",
- "$site->fullname",
+ print_header("$site->shortname: XMLDB",
+ "$site->fullname",
"<a href=\"../index.php\">$stradministration</a> -> <a href=\"index.php\">XMLDB</a>");
print_heading($xmldb_action->getTitle());
echo $xmldb_action->getOutput();
error ("Error: wrong action specified ($action)");
}
- if ($xmldb_action->getDoesGenerate() != ACTION_GENERATE_XML) {
+ if ($xmldb_action->getDoesGenerate() != ACTION_GENERATE_XML) {
if (debugging()) {
///print_object($XMLDB);
}
$block_rss_client_capabilities = array(
-
+
'block/rss_client:createprivatefeeds' => array(
-
+
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'admin' => CAP_ALLOW
)
),
-
+
'block/rss_client:createsharedfeeds' => array(
-
+
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'admin' => CAP_ALLOW
)
),
-
+
'block/rss_client:manageownfeeds' => array(
-
+
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'admin' => CAP_ALLOW
)
),
-
+
'block/rss_client:manageanyfeeds' => array(
-
+
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'admin' => CAP_ALLOW
)
)
-
+
);
?>
\ No newline at end of file
}
}
- if ($capabilities = get_records_select('role_capabilities',
+ if ($capabilities = get_records_select('role_capabilities',
"roleid = $guestrole->id AND contextid = $sitecontext->id")) {
foreach ($capabilities as $capability) {
- $USER->capabilities[$context->id][$capability->capability] = $capability->permission;
+ $USER->capabilities[$context->id][$capability->capability] = $capability->permission;
}
}
/**
* Load default not logged in role capabilities when user is not logged in
- * @return bool
+ * @return bool
*/
function load_notloggedin_role() {
global $CFG, $USER;
}
}
- if ($capabilities = get_records_select('role_capabilities',
+ if ($capabilities = get_records_select('role_capabilities',
"roleid = $CFG->notloggedinroleid AND contextid = $sitecontext->id")) {
foreach ($capabilities as $capability) {
- $USER->capabilities[$sitecontext->id][$capability->capability] = $capability->permission;
+ $USER->capabilities[$sitecontext->id][$capability->capability] = $capability->permission;
}
}
/**
* Load default not logged in role capabilities when user is not logged in
- * @return bool
+ * @return bool
*/
function load_defaultuser_role() {
global $CFG, $USER;
}
}
- if ($capabilities = get_records_select('role_capabilities',
+ if ($capabilities = get_records_select('role_capabilities',
"roleid = $CFG->defaultuserroleid AND contextid = $sitecontext->id")) {
foreach ($capabilities as $capability) {
if (!isset($USER->capabilities[$sitecontext->id][$capability->capability])) { // Don't overwrite
- $USER->capabilities[$sitecontext->id][$capability->capability] = $capability->permission;
+ $USER->capabilities[$sitecontext->id][$capability->capability] = $capability->permission;
}
}
- // SPECIAL EXCEPTION: If the default user role is actually a guest role, then
+ // SPECIAL EXCEPTION: If the default user role is actually a guest role, then
// remove some capabilities so this user doesn't get confused with a REAL guest
if (isset($USER->capabilities[$sitecontext->id]['moodle/legacy:guest']) and $USER->username != 'guest') {
- unset($USER->capabilities[$sitecontext->id]['moodle/legacy:guest']);
+ unset($USER->capabilities[$sitecontext->id]['moodle/legacy:guest']);
unset($USER->capabilities[$sitecontext->id]['moodle/course:view']); // No access to courses by default
}
}
* @return array of contextids
*/
function get_parent_cats($context, $type) {
-
+
$parents = array();
-
+
switch ($type) {
case CONTEXT_COURSECAT:
if (!$cat = get_record('course_categories','id',$context->instanceid)) {
$cat = get_record('course_categories','id',$cat->parent);
}
break;
-
+
case CONTEXT_COURSE:
if (!$course = get_record('course', 'id', $context->instanceid)) {
break;
$cat = get_record('course_categories','id',$cat->parent);
}
break;
-
+
default:
break;
}
* @param string $errorstring - an errorstring
* @param string $stringfile - which stringfile to get it from
*/
-function require_capability($capability, $context=NULL, $userid=NULL, $doanything=true,
+function require_capability($capability, $context=NULL, $userid=NULL, $doanything=true,
$errormessage="nopermissions", $stringfile='') {
global $USER;
require_login();
}
}
-
+
/// OK, if they still don't have the capability then print a nice error message
if (!has_capability($capability, $context, $userid, $doanything)) {
if (isset($capabilities[$sitecontext->id]['moodle/site:doanything'])) {
return (0 < $capabilities[$sitecontext->id]['moodle/site:doanything']);
}
-
+
switch ($context->aggregatelevel) {
-
+
case CONTEXT_COURSECAT:
// Check parent cats.
$parentcats = get_parent_cats($context, CONTEXT_COURSECAT);
$usercontexts = array();
if ($context) { // if context is specified
- $usercontexts = get_parent_contexts($context);
+ $usercontexts = get_parent_contexts($context);
} else { // else, we load everything
if ($userroles = get_records('role_assignments','userid',$userid)) {
foreach ($userroles as $userrole) {
if ($capability) {
$capsearch = " AND rc.capability = '$capability' ";
} else {
- $capsearch ="";
+ $capsearch ="";
}
/// Then we use 1 giant SQL to bring out all relevant capabilities.
$SQL = " SELECT rc.capability, c1.id, (c1.aggregatelevel * 100) AS aggrlevel,
SUM(rc.permission) AS sum
FROM
- {$CFG->prefix}role_assignments ra,
+ {$CFG->prefix}role_assignments ra,
{$CFG->prefix}role_capabilities rc,
{$CFG->prefix}context c1
WHERE
ra.roleid=rc.roleid AND
ra.userid=$userid AND
$searchcontexts1
- rc.contextid=$siteinstance->id
+ rc.contextid=$siteinstance->id
$capsearch
GROUP BY
rc.capability, (c1.aggregatelevel * 100), c1.id
{$CFG->prefix}context c2
WHERE
ra.contextid=c1.id AND
- ra.roleid=rc.roleid AND
- ra.userid=$userid AND
- rc.contextid=c2.id AND
+ ra.roleid=rc.roleid AND
+ ra.userid=$userid AND
+ rc.contextid=c2.id AND
$searchcontexts1
$searchcontexts2
rc.contextid != $siteinstance->id
$capsearch
-
+
GROUP BY
rc.capability, (c1.aggregatelevel * 100 + c2.aggregatelevel), c1.id
HAVING
while (!$rs->EOF) {
$array = $rs->fields;
$temprecord = new object;
-
+
foreach ($array as $key=>$val) {
if ($key == 'aggrlevel') {
$temprecord->aggregatelevel = $val;
$rs->MoveNext();
}
}
-
+
/* so up to this point we should have somethign like this
* $capabilities[1] ->aggregatelevel = 1000
->module = SITEID
->capability = do_anything
->id = 1 (id is the context id)
->sum = 0
-
+
* $capabilities[2] ->aggregatelevel = 1000
->module = SITEID
->capability = post_messages
->capability = view_course_activities
->id = 26
->sum = 0 (this is another course)
-
+
* $capabilities[5] ->aggregatelevel = 3050
->module = course
->capability = view_course_activities
$context = get_context_instance_by_id($capability->id);
if (!empty($otheruserid)) { // we are pulling out other user's capabilities, do not write to session
-
+
if (capability_prohibits($capability->capability, $context, $capability->sum, $usercap)) {
$usercap[$capability->id][$capability->capability] = -9000;
continue;
}
- $usercap[$capability->id][$capability->capability] = $capability->sum;
-
+ $usercap[$capability->id][$capability->capability] = $capability->sum;
+
} else {
if (capability_prohibits($capability->capability, $context, $capability->sum)) { // if any parent or parent's parent is set to prohibit
$USER->capabilities[$capability->id][$capability->capability] = -9000;
continue;
}
-
+
// if no parental prohibit set
// just write to session, i am not sure this is correct yet
// since 3050 shows up after 3000, and 3070 shows up after 3050,
$USER->capabilities[$capability->id][$capability->capability] = $capability->sum;
}
}
-
+
// now we don't care about the huge array anymore, we can dispose it.
unset($capabilities);
-
+
if (!empty($otheruserid)) {
- return $usercap; // return the array
+ return $usercap; // return the array
}
// see array in session to see what it looks like
/*
* Check all the login enrolment information for the given user object
- * by querying the enrolment plugins
+ * by querying the enrolment plugins
*/
function check_enrolment_plugins(&$user) {
global $CFG;
require_once($CFG->dirroot .'/enrol/enrol.class.php');
-
+
if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
$plugins = array($CFG->enrol);
}
// If this capability is set to prohibit.
return true;
}
-
+
if (isset($array)) {
- if (isset($array[$context->id][$capability])
+ if (isset($array[$context->id][$capability])
&& $array[$context->id][$capability] < -8000) {
return true;
- }
+ }
} else {
// Else if set in session.
- if (isset($USER->capabilities[$context->id][$capability])
+ if (isset($USER->capabilities[$context->id][$capability])
&& $USER->capabilities[$context->id][$capability] < -8000) {
return true;
}
}
switch ($context->aggregatelevel) {
-
+
case CONTEXT_SYSTEM:
// By now it's a definite an inherit.
return 0;
*/
function print_capabilities($modid=0) {
global $CFG;
-
+
$capabilities = array();
if ($modid) {
// Call the function that grabs the file and parse.
$cm = get_record('course_modules', 'id', $modid);
$module = get_record('modules', 'id', $cm->module);
-
+
} else {
// Print all capabilities.
foreach ($capabilities as $capability) {
function moodle_install_roles() {
global $CFG, $db;
-
+
// Create a system wide context for assignemnt.
$systemcontext = $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
// Create default/legacy roles and capabilities.
// (1 legacy capability per legacy role at system level).
- $adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin');
+ $adminrole = create_role(get_string('administrator'), 'admin', get_string('administratordescription'), 'moodle/legacy:admin');
if (!assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $systemcontext->id)) {
error('Could not assign moodle/site:doanything to the admin role');
}
- $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'moodle/legacy:coursecreator');
- $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'moodle/legacy:editingteacher');
- $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'moodle/legacy:teacher');
+ $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'moodle/legacy:coursecreator');
+ $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'moodle/legacy:editingteacher');
+ $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'moodle/legacy:teacher');
$studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'moodle/legacy:student');
$guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'moodle/legacy:guest');
// assign above new roles. If a user has both teacher and student role,
// only teacher role is assigned. The assignment should be system level.
$dbtables = $db->MetaTables('TABLES');
-
+
/**
* Upgrade the admins.
* Sort using id ASC, first one is primary admin.
*/
if (in_array($CFG->prefix.'user_admins', $dbtables)) {
- if ($useradmins = get_records_sql('SELECT * from '.$CFG->prefix.'user_admins ORDER BY ID ASC')) {
+ if ($useradmins = get_records_sql('SELECT * from '.$CFG->prefix.'user_admins ORDER BY ID ASC')) {
foreach ($useradmins as $admin) {
role_assign($adminrole, $admin->userid, 0, $systemcontext->id);
}
*/
if (in_array($CFG->prefix.'user_students', $dbtables)) {
if ($userstudents = get_records('user_students')) {
- foreach ($userstudents as $student) {
+ foreach ($userstudents as $student) {
// populate the user_lastaccess table
unset($access);
$access->timeaccess = $student->timeaccess;
}
/**
- * Insert the correct records for legacy roles
+ * Insert the correct records for legacy roles
*/
allow_assign($adminrole, $adminrole);
allow_assign($adminrole, $coursecreatorrole);
allow_assign($adminrole, $noneditteacherrole);
- allow_assign($adminrole, $editteacherrole);
+ allow_assign($adminrole, $editteacherrole);
allow_assign($adminrole, $studentrole);
allow_assign($adminrole, $guestrole);
-
+
allow_assign($coursecreatorrole, $noneditteacherrole);
allow_assign($coursecreatorrole, $editteacherrole);
- allow_assign($coursecreatorrole, $studentrole);
+ allow_assign($coursecreatorrole, $studentrole);
allow_assign($coursecreatorrole, $guestrole);
-
- allow_assign($editteacherrole, $noneditteacherrole);
- allow_assign($editteacherrole, $studentrole);
+
+ allow_assign($editteacherrole, $noneditteacherrole);
+ allow_assign($editteacherrole, $studentrole);
allow_assign($editteacherrole, $guestrole);
-
+
/// overrides
allow_override($adminrole, $adminrole);
allow_override($adminrole, $coursecreatorrole);
allow_override($adminrole, $noneditteacherrole);
- allow_override($adminrole, $editteacherrole);
+ allow_override($adminrole, $editteacherrole);
allow_override($adminrole, $studentrole);
- allow_override($adminrole, $guestrole);
+ allow_override($adminrole, $guestrole);
// Should we delete the tables after we are done? Not yet.
* @return boolean - success or failure.
*/
function assign_legacy_capabilities($capability, $legacyperms) {
-
+
foreach ($legacyperms as $type => $perm) {
-
+
$systemcontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
-
+
// The legacy capabilities are:
// 'moodle/legacy:guest'
// 'moodle/legacy:student'
// 'moodle/legacy:editingteacher'
// 'moodle/legacy:coursecreator'
// 'moodle/legacy:admin'
-
+
if ($roles = get_roles_with_capability('moodle/legacy:'.$type, CAP_ALLOW)) {
foreach ($roles as $role) {
// Assign a site level capability.
*/
function islegacy($capabilityname) {
if (strstr($capabilityname, 'legacy') === false) {
- return false;
+ return false;
} else {
- return true;
+ return true;
}
}
* @return id or false
*/
function create_role($name, $shortname, $description, $legacy='') {
-
+
// check for duplicate role name
-
+
if ($role = get_record('role','name', $name)) {
- error('there is already a role with this name!');
+ error('there is already a role with this name!');
}
-
+
if ($role = get_record('role','shortname', $shortname)) {
- error('there is already a role with this shortname!');
+ error('there is already a role with this shortname!');
}
$role->name = $name;
$role->shortname = $shortname;
$role->description = $description;
-
- $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
-
+
+ $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+
if ($id = insert_record('role', $role)) {
- if ($legacy) {
- assign_capability($legacy, CAP_ALLOW, $id, $context->id);
+ if ($legacy) {
+ assign_capability($legacy, CAP_ALLOW, $id, $context->id);
}
-
+
/// By default, users with role:manage at site level
/// should be able to assign users to this new role, and override this new role's capabilities
-
+
// find all admin roles
if ($adminroles = get_roles_with_capability('moodle/role:manage', CAP_ALLOW, $context)) {
// foreach admin role
foreach ($adminroles as $arole) {
// write allow_assign and allow_overrid
allow_assign($arole->id, $id);
- allow_override($arole->id, $id);
+ allow_override($arole->id, $id);
}
}
-
+
return $id;
} else {
- return false;
+ return false;
}
-
+
}
/**
* @param permission - int 1,-1 or -1000
*/
function assign_capability($capability, $permission, $roleid, $contextid, $overwrite=false) {
-
+
global $USER;
-
+
if (empty($permission) || $permission == 0) { // if permission is not set
- unassign_capability($capability, $roleid, $contextid);
+ unassign_capability($capability, $roleid, $contextid);
}
-
+
$existing = get_record('role_capabilities', 'contextid', $contextid, 'roleid', $roleid, 'capability', $capability);
if ($existing and !$overwrite) { // We want to keep whatever is there already
* @return boolean - success or failure
*/
function unassign_capability($capability, $roleid, $contextid=NULL) {
-
+
if (isset($contextid)) {
$status = delete_records('role_capabilities', 'capability', $capability,
'roleid', $roleid, 'contextid', $contextid);
function get_roles_with_capability($capability, $permission=NULL, $context='') {
global $CFG;
-
+
if ($context) {
if ($contexts = get_parent_contexts($context)) {
$listofcontexts = '('.implode(',', $contexts).')';
} else {
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
- $listofcontexts = '('.$sitecontext->id.')'; // must be site
- }
+ $listofcontexts = '('.$sitecontext->id.')'; // must be site
+ }
$contextstr = "AND (rc.contextid = '$context->id' OR rc.contextid IN $listofcontexts)";
} else {
$contextstr = '';
}
-
- $selectroles = "SELECT r.*
+
+ $selectroles = "SELECT r.*
FROM {$CFG->prefix}role r,
{$CFG->prefix}role_capabilities rc
WHERE rc.capability = '$capability'
notify('Either userid or groupid must be provided');
return false;
}
-
+
if ($userid && !record_exists('user', 'id', $userid)) {
notify('User does not exist!');
return false;
/// Make sure they have an entry in user_lastaccess for courses they can access
// role_add_lastaccess_entries($userid, $context);
}
-
+
/// now handle metacourse role assignments if in course context
if ($success and $context->aggregatelevel == CONTEXT_COURSE) {
if ($parents = get_records('course_meta', 'child_course', $context->instanceid)) {
function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0) {
global $USER, $CFG;
-
+
$success = true;
$args = array('roleid', 'userid', 'groupid', 'contextid');
return $success;
}
-/*
- * A convenience function to take care of the common case where you
+/*
+ * A convenience function to take care of the common case where you
* just want to enrol someone using the default role into a course
*
* @param object $course
if (role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol)) {
return false;
}
-
+
email_welcome_message_to_user($course, $user);
-
+
add_to_log($course->id, 'course', 'enrol', 'view.php?id='.$course->id, $user->id);
return true;
}
}
break;
-
+
case CONTEXT_COURSE: // For a whole course
if ($course = get_record('course', 'id', $context->instanceid)) {
$varprefix = 'moodle';
} else {
$compparts = explode('/', $component);
-
+
if ($compparts[0] == 'block') {
// Blocks are an exception. Blocks directory is 'blocks', and not
// 'block'. So we need to jump through hoops.
}
}
$capabilities = array();
-
+
if (file_exists($defpath)) {
require_once($defpath);
$capabilities = ${$varprefix.'_capabilities'};
*
* Note that the absence of the db/access.php capabilities definition file
* will cause any stored capabilities for the component to be removed from
- * the database.
+ * the database.
*
* @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
* @return boolean
*/
function update_capabilities($component='moodle') {
-
+
$storedcaps = array();
$filecaps = load_capability_def($component);
// Are there new capabilities in the file definition?
$newcaps = array();
-
+
foreach ($filecaps as $filecap => $def) {
- if (!$storedcaps ||
+ if (!$storedcaps ||
($storedcaps && in_array($filecap, $storedcaps) === false)) {
if (!array_key_exists('riskbitmask', $def)) {
$def['riskbitmask'] = 0; // no risk if not specified
$capability->contextlevel = $capdef['contextlevel'];
$capability->component = $component;
$capability->riskbitmask = $capdef['riskbitmask'];
-
+
if (!insert_record('capabilities', $capability, false, 'id')) {
return false;
}
-
+
global $db;
$db->debug= 999;
// Do we need to assign the new capabilities to roles that have the
// definition that we need to delete from the stored capabilities and
// role assignments?
capabilities_cleanup($component, $filecaps);
-
+
return true;
}
* @return int - number of deprecated capabilities that have been removed
*/
function capabilities_cleanup($component, $newcapdef=NULL) {
-
+
$removedcount = 0;
-
+
if ($cachedcaps = get_cached_capabilities($component)) {
foreach ($cachedcaps as $cachedcap) {
if (empty($newcapdef) ||
array_key_exists($cachedcap->name, $newcapdef) === false) {
-
+
// Remove from capabilities cache.
if (!delete_records('capabilities', 'name', $cachedcap->name)) {
error('Could not delete deprecated capability '.$cachedcap->name);
/**
- * Extracts the relevant capabilities given a contextid.
+ * Extracts the relevant capabilities given a contextid.
* All case based, example an instance of forum context.
* Will fetch all forum related capabilities, while course contexts
* Will fetch all capabilities
* `component` varchar(100) NOT NULL,
*/
function fetch_context_capabilities($context) {
-
+
global $CFG;
$sort = 'ORDER BY contextlevel,component,id'; // To group them sensibly for display
-
+
switch ($context->aggregatelevel) {
case CONTEXT_SYSTEM: // all
case CONTEXT_PERSONAL:
$SQL = "select * from {$CFG->prefix}capabilities where contextlevel = ".CONTEXT_PERSONAL;
break;
-
+
case CONTEXT_USER:
$SQL = "select * from {$CFG->prefix}capabilities where contextlevel = ".CONTEXT_USER;
break;
-
+
case CONTEXT_COURSECAT: // all
$SQL = "select * from {$CFG->prefix}capabilities";
break;
case CONTEXT_MODULE: // mod caps
$cm = get_record('course_modules', 'id', $context->instanceid);
$module = get_record('modules', 'id', $cm->module);
-
+
$SQL = "select * from {$CFG->prefix}capabilities where contextlevel = ".CONTEXT_MODULE."
and component = 'mod/$module->name'";
break;
case CONTEXT_BLOCK: // block caps
$cb = get_record('block_instance', 'id', $context->instanceid);
$block = get_record('block', 'id', $cb->blockid);
-
+
$SQL = "select * from {$CFG->prefix}capabilities where contextlevel = ".CONTEXT_BLOCK."
and component = 'block/$block->name'";
break;
}
// end of special sorting
return $records;
-
+
}
* @return array of capability records from the capabilities table.
*/
function fetch_context_independent_capabilities() {
-
+
$contextindependentcaps = array(
'moodle/site:accessallgroups'
);
$records = array();
-
+
foreach ($contextindependentcaps as $capname) {
$record = get_record('capabilities', 'name', $capname);
array_push($records, $record);
*/
function role_context_capabilities($roleid, $context, $cap='') {
global $CFG;
-
+
$contexts = get_parent_contexts($context);
$contexts[] = $context->id;
$contexts = '('.implode(',', $contexts).')';
-
+
if ($cap) {
$search = " AND rc.capability = '$cap' ";
} else {
- $search = '';
+ $search = '';
}
-
- $SQL = "SELECT rc.*
- FROM {$CFG->prefix}role_capabilities rc,
+
+ $SQL = "SELECT rc.*
+ FROM {$CFG->prefix}role_capabilities rc,
{$CFG->prefix}context c
WHERE rc.contextid in $contexts
AND rc.roleid = $roleid
AND rc.contextid = c.id $search
- ORDER BY c.aggregatelevel DESC,
- rc.capability DESC";
+ ORDER BY c.aggregatelevel DESC,
+ rc.capability DESC";
$capabilities = array();
-
+
if ($records = get_records_sql($SQL)) {
// We are traversing via reverse order.
foreach ($records as $record) {
// If not set yet (i.e. inherit or not set at all), or currently we have a prohibit
if (!isset($capabilities[$record->capability]) || $record->permission<-500) {
$capabilities[$record->capability] = $record->permission;
- }
+ }
}
}
return $capabilities;
}
/**
- * Recursive function which, given a context, find all parent context ids,
+ * Recursive function which, given a context, find all parent context ids,
* and return the array in reverse order, i.e. parent first, then grand
* parent, etc.
* @param object $context
return array($parent->id);
}
break;
-
+
case CONTEXT_USER:
if (!$parent = get_context_instance(CONTEXT_SYSTEM, SITEID)) {
return array();
return array($parent->id);
}
break;
-
+
case CONTEXT_COURSECAT: // Coursecat -> coursecat or site
if (!$coursecat = get_record('course_categories','id',$context->instanceid)) {
return array();
*/
function get_related_contexts_string($context) {
if ($parents = get_parent_contexts($context)) {
- return (' IN ('.$context->id.','.implode(',', $parents).')');
+ return (' IN ('.$context->id.','.implode(',', $parents).')');
} else {
return (' ='.$context->id);
}
* @param $capabilityname - e.g. mod/choice:readresponses
*/
function get_capability_string($capabilityname) {
-
+
// Typical capabilityname is mod/choice:readresponses
$names = split('/', $capabilityname);
$stringname = $names[1]; // choice:readresponses
- $components = split(':', $stringname);
+ $components = split(':', $stringname);
$componentname = $components[0]; // choice
switch ($names[0]) {
case 'mod':
$string = get_string($stringname, $componentname);
break;
-
+
case 'block':
$string = get_string($stringname, 'block_'.$componentname);
break;
case 'moodle':
$string = get_string($stringname, 'role');
break;
-
+
case 'enrol':
$string = get_string($stringname, 'enrol_'.$componentname);
- break;
-
+ break;
+
default:
$string = get_string($stringname);
- break;
-
+ break;
+
}
return $string;
}
default:
error ('This is an unknown context!');
return false;
-
+
}
return $string;
}
global $CFG;
$contextlist = get_related_contexts_string($context);
-
+
$sql = "SELECT DISTINCT r.id,
r.name,
r.shortname,
r.sortorder
FROM {$CFG->prefix}role_assignments ra,
- {$CFG->prefix}role r
- WHERE r.id = ra.roleid
+ {$CFG->prefix}role r
+ WHERE r.id = ra.roleid
AND ra.contextid $contextlist
ORDER BY r.sortorder ASC";
-
+
return get_records_sql($sql);
}
-/** this function is used to print roles column in user profile page.
+/** this function is used to print roles column in user profile page.
* @param int userid
* @param int contextid
* @return string
*/
function get_user_roles_in_context($userid, $contextid){
global $CFG;
-
+
$rolestring = '';
$SQL = 'select * from '.$CFG->prefix.'role_assignments ra, '.$CFG->prefix.'role r where ra.userid='.$userid.' and ra.contextid='.$contextid.' and ra.roleid = r.id';
if ($roles = get_records_sql($SQL)) {
foreach ($roles as $userrole) {
$rolestring .= '<a href="'.$CFG->wwwroot.'/user/index.php?contextid='.$userrole->contextid.'&roleid='.$userrole->roleid.'">'.$userrole->name.'</a>, ';
- }
-
+ }
+
}
return rtrim($rolestring, ', ');
}
// first check if user has override capability
// if not return false;
if (!has_capability('moodle/role:override', $context)) {
- return false;
+ return false;
}
// pull out all active roles of this user from this context(or above)
if ($userroles = get_user_roles($context)) {
}
}
}
-
+
return false;
-
+
}
/**
* @return boolean
*/
function user_can_assign($context, $targetroleid) {
-
+
// first check if user has override capability
// if not return false;
if (!has_capability('moodle/role:assign', $context)) {
- return false;
+ return false;
}
// pull out all active roles of this user from this context(or above)
if ($userroles = get_user_roles($context)) {
}
}
}
-
- return false;
+
+ return false;
}
/**
WHERE ra.userid = '.$userid.
' AND ra.roleid = r.id
AND ra.contextid = c.id
- AND '.$contexts.
+ AND '.$contexts.
' ORDER BY c.aggregatelevel DESC');
}
/**
- * Creates a record in the allow_override table
+ * Creates a record in the allow_override table
* @param int sroleid - source roleid
* @param int troleid - target roleid
* @return int - id or false
}
/**
- * Creates a record in the allow_assign table
+ * Creates a record in the allow_assign table
* @param int sroleid - source roleid
* @param int troleid - target roleid
* @return int - id or false
}
}
}
-
- return $options;
+
+ return $options;
}
/*
* Returns a role object that is the default role for new enrolments
* in a given course
*
- * @param object $course
+ * @param object $course
* @return object $role
*/
function get_default_course_role($course) {
* @param $fields - fields to be pulled
* @param $sort - the sort order
* @param $limitfrom - number of records to skip (offset)
- * @param $limitnum - number of records to fetch
+ * @param $limitnum - number of records to fetch
* @param $groups - single group or array of groups - group(s) user is in
* @param $exceptions - list of users to exclude
*/
-function get_users_by_capability($context, $capability, $fields='', $sort='',
+function get_users_by_capability($context, $capability, $fields='', $sort='',
$limitfrom='', $limitnum='', $groups='', $exceptions='') {
global $CFG;
-
+
/// Sorting out groups
if ($groups) {
$groupjoin = 'INNER JOIN '.$CFG->prefix.'groups_members gm ON gm.userid = ra.userid';
-
+
if (is_array($groups)) {
$groupsql = 'AND gm.groupid IN ('.implode(',', $groups).')';
} else {
- $groupsql = 'AND gm.groupid = '.$groups;
+ $groupsql = 'AND gm.groupid = '.$groups;
}
} else {
$groupjoin = '';
- $groupsql = '';
+ $groupsql = '';
}
-
+
/// Sorting out exceptions
$exceptionsql = $exceptions ? "AND u.id NOT IN ($exceptions)" : '';
$sort = 'ul.timeaccess';
}
- $sortby = $sort ? " ORDER BY $sort " : '';
-
+ $sortby = $sort ? " ORDER BY $sort " : '';
+
/// If context is a course, then construct sql for ul
if ($context->aggregatelevel == CONTEXT_COURSE) {
$courseid = $context->instanceid;
if ($caps[$capability] > 0) { // resolved capability > 0
$validroleids[] = $prole->id;
}
- }
+ }
$roleids = '('.implode(',', $validroleids).')';
/// Construct the main SQL
$select = " SELECT $fields";
- $from = " FROM {$CFG->prefix}user u
- INNER JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id
+ $from = " FROM {$CFG->prefix}user u
+ INNER JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id
LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul ON ul.userid = u.id
$groupjoin";
- $where = " WHERE ra.contextid ".get_related_contexts_string($context)."
- AND u.deleted = 0
- AND ra.roleid in $roleids
+ $where = " WHERE ra.contextid ".get_related_contexts_string($context)."
+ AND u.deleted = 0
+ AND ra.roleid in $roleids
$exceptionsql
$coursesql
$groupsql";
- return get_records_sql($select.$from.$where.$sortby, $limitfrom, $limitnum);
+ return get_records_sql($select.$from.$where.$sortby, $limit