$settings = ''; // By default, no configuration
if ($blockobject and $blockobject->has_config()) {
- if (file_exists($CFG->dirroot.'/blocks/'.$block->name.'/settings.php')) {
+ $blocksettings = admin_get_root()->locate('blocksetting' . $block->name);
+
+ if ($blocksettings instanceof admin_externalpage) {
+ $settings = '<a href="' . $blocksettings->url . '">' . get_string('settings') . '</a>';
+ } else if ($blocksettings instanceof admin_settingpage) {
$settings = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=blocksetting'.$block->name.'">'.$strsettings.'</a>';
} else {
$settings = '<a href="block.php?block='.$blockid.'">'.$strsettings.'</a>';
$discussion->name = $blogentry->subject;
$discussion->assessed = $forum->assessed;
$discussion->message = $blogentry->summary;
- $discussion->messageformat = $forum->introformat;
+ $discussion->messageformat = $blogentry->summaryformat;
$discussion->messagetrust = 0;
$discussion->attachments = 0;
$discussion->mailnow = false;
cli_heading(get_string('notice'));
echo get_string('maturitycorewarning', 'admin', $maturitylevel) . PHP_EOL;
echo get_string('morehelp') . ': ' . get_docs_url('admin/versions') . PHP_EOL;
- echo get_string('continue') . PHP_LOL;
+ echo get_string('continue') . PHP_EOL;
$prompt = get_string('cliyesnoprompt', 'admin');
$input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin')));
if ($input == get_string('clianswerno', 'admin')) {
// blog
$temp = new admin_settingpage('blog', get_string('blog','blog'));
$temp->add(new admin_setting_configcheckbox('useblogassociations', get_string('useblogassociations', 'blog'), get_string('configuseblogassociations','blog'), 1));
- $temp->add(new admin_setting_bloglevel('bloglevel', get_string('bloglevel', 'admin'), get_string('configbloglevel', 'admin'), 4, array(5 => get_string('worldblogs','blog'),
- 4 => get_string('siteblogs','blog'),
- 1 => get_string('personalblogs','blog'),
- 0 => get_string('disableblogs','blog'))));
+ $temp->add(new admin_setting_bloglevel('bloglevel', get_string('bloglevel', 'admin'), get_string('configbloglevel', 'admin'), 4, array(BLOG_GLOBAL_LEVEL => get_string('worldblogs','blog'),
+ BLOG_SITE_LEVEL => get_string('siteblogs','blog'),
+ BLOG_USER_LEVEL => get_string('personalblogs','blog'),
+ 0 => get_string('disableblogs','blog'))));
$temp->add(new admin_setting_configcheckbox('useexternalblogs', get_string('useexternalblogs', 'blog'), get_string('configuseexternalblogs','blog'), 1));
$temp->add(new admin_setting_configselect('externalblogcrontime', get_string('externalblogcrontime', 'blog'), get_string('configexternalblogcrontime', 'blog'), 86400,
array(43200 => get_string('numhours', '', 12),
// link to tag management interface
$ADMIN->add('appearance', new admin_externalpage('managetags', get_string('managetags', 'tag'), "$CFG->wwwroot/tag/manage.php"));
-
+
$temp = new admin_settingpage('additionalhtml', get_string('additionalhtml', 'admin'));
$temp->add(new admin_setting_heading('additionalhtml_heading', get_string('additionalhtml_heading', 'admin'), get_string('additionalhtml_desc', 'admin')));
$temp->add(new admin_setting_configtextarea('additionalhtmlhead', get_string('additionalhtmlhead', 'admin'), get_string('additionalhtmlhead_desc', 'admin'), '', PARAM_RAW));
}
$ADMIN->add('webservicesettings', $temp);
-
+// Question type settings
if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) {
// Question type settings.
$ADMIN->add('modules', new admin_category('qtypesettings', get_string('questiontypes', 'admin')));
}
}
}
+
+// Plagiarism plugin settings
if ($hassiteconfig && !empty($CFG->enableplagiarism)) {
$ADMIN->add('modules', new admin_category('plagiarism', get_string('plagiarism', 'plagiarism')));
$temp = new admin_settingpage('plagiarismsettings', get_string('plagiarismsettings', 'plagiarism'));
}
}
$ADMIN->add('reports', new admin_externalpage('comments', get_string('comments'), $CFG->wwwroot.'/comment/', 'moodle/site:viewreports'));
-/// Now add reports
+// Course reports settings
+if ($hassiteconfig) {
+ $pages = array();
+ foreach (get_plugin_list('coursereport') as $report => $path) {
+ $file = $CFG->dirroot . '/course/report/' . $report . '/settings.php';
+ if (file_exists($file)) {
+ $settings = new admin_settingpage('coursereport' . $report,
+ get_string('pluginname', 'coursereport_' . $report), 'moodle/site:config');
+ // settings.php may create a subcategory or unset the settings completely
+ include($file);
+ if ($settings) {
+ $pages[] = $settings;
+ }
+ }
+ }
+ if (!empty($pages)) {
+ $ADMIN->add('modules', new admin_category('coursereports', get_string('coursereports')));
+ foreach ($pages as $page) {
+ $ADMIN->add('coursereports', $page);
+ }
+ }
+}
+
+// Now add reports
foreach (get_plugin_list('report') as $plugin => $plugindir) {
$settings_path = "$plugindir/settings.php";
if (file_exists($settings_path)) {
// "performance" settingpage
$temp = new admin_settingpage('performance', get_string('performance', 'admin'));
+$temp->add(new admin_setting_configtext('numcoursesincombo', get_string('numcoursesincombo', 'admin'), get_string('numcoursesincombo_help', 'admin'), 500));
+
$temp->add(new admin_setting_configselect('extramemorylimit', get_string('extramemorylimit', 'admin'),
get_string('configextramemorylimit', 'admin'), '512M',
// if this option is set to 0, default 128M will be used
$optionalsubsystems->add(new admin_setting_configcheckbox('enablecompletion',
get_string('enablecompletion','completion'),
get_string('configenablecompletion','completion'), 0));
- $optionalsubsystems->add(new admin_setting_configcheckbox('enableavailability',
+ $optionalsubsystems->add($checkbox = new admin_setting_configcheckbox('enableavailability',
get_string('enableavailability','condition'),
get_string('configenableavailability','condition'), 0));
+ $checkbox->set_affects_modinfo(true);
$optionalsubsystems->add(new admin_setting_configcheckbox('enableplagiarism', get_string('enableplagiarism','plagiarism'), get_string('configenableplagiarism','plagiarism'), 0));
}
$mform->setDefault('maildigest', 0);
$mform->setAdvanced('maildigest');
- $choices = array(0 => get_string('autosubscribeyes'), 1 => get_string('autosubscribeno'));
+ $choices = array(1 => get_string('autosubscribeyes'), 0 => get_string('autosubscribeno'));
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
$mform->setDefault('autosubscribe', 1);
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
/**
* Blog Menu Block page.
*
- * @package moodlecore
- * @subpackage blog
+ * @package block
+ * @subpackage blog_menu
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-/**
- * Require the blog lib file, several useful functions in there
- */
-require_once($CFG->dirroot .'/blog/lib.php');
+defined('MOODLE_INTERNAL') || die();
/**
* The blog menu block class
}
function get_content() {
+ global $CFG;
- // Check if we've already generated content
- if (!empty($this->content)) {
+ // detect if blog enabled
+ if ($this->content !== NULL) {
return $this->content;
}
- // Prep the content
- $this->content = new stdClass;
-
- /**
- * Prepare the content for this block
- */
- $options = blog_get_all_options($this->page);
- if (count($options)==0) {
- // Don't display menu block if block is set at site level, and user is not logged in
+ if (empty($CFG->bloglevel)) {
+ $this->content = new stdClass();
$this->content->text = '';
if ($this->page->user_is_editing()) {
- // If editing is enabled show an informative message
$this->content->text = get_string('blogdisable', 'blog');
}
return $this->content;
+
+ } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
+ $this->content = new stdClass();
+ $this->content->text = '';
+ return $this->content;
+ }
+
+ // require necessary libs and get content
+ require_once($CFG->dirroot .'/blog/lib.php');
+
+ // Prep the content
+ $this->content = new stdClass();
+
+ $options = blog_get_all_options($this->page);
+ if (count($options) == 0) {
+ $this->content->text = '';
+ return $this->content;
}
// Iterate the option types
// Display the content as a list
$this->content->text = html_writer::alist($menulist, array('class'=>'list'));
- /**
- * Prepare the footer for this block
- */
+ // Prepare the footer for this block
if (has_capability('moodle/blog:search', get_context_instance(CONTEXT_SYSTEM))) {
// Full-text search field
$form = html_writer::tag('label', get_string('search', 'admin'), array('for'=>'blogsearchquery', 'class'=>'accesshide'));
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
/**
* Recent Blog Entries Block page.
*
- * @package moodlecore
- * @subpackage blog
+ * @package block
+ * @subpackage blog_recent
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-require_once($CFG->dirroot .'/blog/lib.php');
-require_once($CFG->dirroot .'/blog/locallib.php');
+defined('MOODLE_INTERNAL') || die();
/**
* This block simply outputs a list of links to recent blog entries, depending on
}
function get_content() {
- global $CFG, $USER, $PAGE, $DB, $OUTPUT;
-
- if (empty($this->config->recentbloginterval)) {
- $this->config->recentbloginterval = 8400;
- }
+ global $CFG;
- if (empty($this->config->numberofrecentblogentries)) {
- $this->config->numberofrecentblogentries = 4;
+ if ($this->content !== NULL) {
+ return $this->content;
}
- if (empty($CFG->bloglevel) || ($CFG->bloglevel < BLOG_GLOBAL_LEVEL && !(isloggedin() && !isguestuser()))) {
+ // verify blog is enabled
+ if (empty($CFG->bloglevel)) {
+ $this->content = new stdClass();
$this->content->text = '';
if ($this->page->user_is_editing()) {
$this->content->text = get_string('blogdisable', 'blog');
}
return $this->content;
+
+ } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
+ $this->content = new stdClass();
+ $this->content->text = '';
+ return $this->content;
+ }
+
+ require_once($CFG->dirroot .'/blog/lib.php');
+ require_once($CFG->dirroot .'/blog/locallib.php');
+
+ if (empty($this->config->recentbloginterval)) {
+ $this->config->recentbloginterval = 8400;
+ }
+
+ if (empty($this->config->numberofrecentblogentries)) {
+ $this->config->numberofrecentblogentries = 4;
}
$this->content = new stdClass();
<?php
-
-//TODO: fix these sloppy constant names or move them elsewhere!
-
-define('BLOGDEFAULTTIMEWITHIN', 90);
-define('BLOGDEFAULTNUMBEROFTAGS', 20);
-define('BLOGDEFAULTSORT', 'name');
-
-require_once($CFG->dirroot .'/blog/lib.php');
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Blog tags block.
+ *
+ * @package block
+ * @subpackage blog_tags
+ * @copyright 2006 Shane Elliott
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+define('BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN', 90);
+define('BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS', 20);
+define('BLOCK_BLOG_TAGS_DEFAULTSORT', 'name');
class block_blog_tags extends block_base {
function init() {
function get_content() {
global $CFG, $SITE, $USER, $DB, $OUTPUT;
- if (empty($CFG->usetags) || empty($CFG->bloglevel)) {
+ if ($this->content !== NULL) {
+ return $this->content;
+ }
+
+ // make sure blog and tags are actually enabled
+ if (empty($CFG->bloglevel)) {
+ $this->content = new stdClass();
+ $this->content->text = '';
+ if ($this->page->user_is_editing()) {
+ $this->content->text = get_string('blogdisable', 'blog');
+ }
+ return $this->content;
+
+ } else if (empty($CFG->usetags)) {
+ $this->content = new stdClass();
$this->content->text = '';
if ($this->page->user_is_editing()) {
$this->content->text = get_string('tagsaredisabled', 'tag');
}
return $this->content;
+
+ } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL and (!isloggedin() or isguestuser())) {
+ $this->content = new stdClass();
+ $this->content->text = '';
+ return $this->content;
}
+ // require the libs and do the work
+ require_once($CFG->dirroot .'/blog/lib.php');
+
if (empty($this->config->timewithin)) {
- $this->config->timewithin = BLOGDEFAULTTIMEWITHIN;
+ $this->config->timewithin = BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN;
}
if (empty($this->config->numberoftags)) {
- $this->config->numberoftags = BLOGDEFAULTNUMBEROFTAGS;
+ $this->config->numberoftags = BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS;
}
if (empty($this->config->sort)) {
- $this->config->sort = BLOGDEFAULTSORT;
- }
-
- if ($this->content !== NULL) {
- return $this->content;
+ $this->config->sort = BLOCK_BLOG_TAGS_DEFAULTSORT;
}
- $this->content = new stdClass;
+ $this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
/// Now we sort the tag display order
$CFG->tagsort = $this->config->sort;
- usort($etags, "blog_tags_sort");
+ usort($etags, "block_blog_tags_sort");
/// Finally we create the output
/// Accessibility: markup as a list.
}
}
-function blog_tags_sort($a, $b) {
+function block_blog_tags_sort($a, $b) {
global $CFG;
if (empty($CFG->tagsort)) {
if (is_numeric($a->$tagsort)) {
return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1;
} elseif (is_string($a->$tagsort)) {
- return strcmp($a->$tagsort, $b->$tagsort);
+ return strcmp($a->$tagsort, $b->$tagsort); //TODO: this is not compatible with UTF-8!!
} else {
return 0;
}
$numberoftags[$i] = $i;
}
$mform->addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags);
- $mform->setDefault('config_numberoftags', BLOGDEFAULTNUMBEROFTAGS);
+ $mform->setDefault('config_numberoftags', BLOCK_BLOG_TAGS_DEFAULTNUMBEROFTAGS);
$timewithin = array(
10 => get_string('numdays', '', 10),
365 => get_string('numdays', '', 365),
);
$mform->addElement('select', 'config_timewithin', get_string('timewithin', 'blog'), $timewithin);
- $mform->setDefault('config_timewithin', BLOGDEFAULTTIMEWITHIN);
+ $mform->setDefault('config_timewithin', BLOCK_BLOG_TAGS_DEFAULTTIMEWITHIN);
$sort = array(
'name' => get_string('tagtext', 'blog'),
'id' => get_string('tagdatelastused', 'blog'),
);
$mform->addElement('select', 'config_sort', get_string('tagsort', 'blog'), $sort);
- $mform->setDefault('config_sort', BLOGDEFAULTSORT);
+ $mform->setDefault('config_sort', BLOCK_BLOG_TAGS_DEFAULTSORT);
}
}
'courselimit' => $limit,
'expansionlimit' => $expansionlimit
);
+ $this->page->requires->string_for_js('viewallcourses', 'moodle');
$this->page->requires->yui_module(array('core_dock', 'moodle-block_navigation-navigation'), 'M.block_navigation.init_add_tree', array($arguments));
}
.block_navigation .block_tree li {margin:3px;list-style: none;padding:0;}
.block_navigation .block_tree li.item_with_icon > p {position:relative;}
.block_navigation .block_tree li.item_with_icon > p img {vertical-align:middle;position:absolute;left:0;top:3px}
+.block_navigation .block_tree li.item_with_icon.contains_branch > p img {left:16px;}
+.block_navigation .block_tree li.item_with_icon.contains_branch .tree_item {padding-left:34px;}
.block_navigation .block_tree li ul {padding-left:0;margin:0;}
.block_navigation .block_tree li.depth_2 ul {padding-left:16px;margin:0;}
try {
var object = Y.JSON.parse(outcome.responseText);
if (object.children && object.children.length > 0) {
+ var coursecount = 0;
for (var i in object.children) {
if (typeof(object.children[i])=='object') {
+ if (object.children[i].type == 20) {
+ coursecount++;
+ }
this.addChild(object.children[i]);
}
}
+ if (this.get('type') == 10 && coursecount >= M.block_navigation.courselimit) {
+ this.addViewAllCoursesChild(this);
+ }
this.get('tree').toggleExpansion({target:this.node});
return true;
}
}
}
if (branch.get('type') == 10 && count >= M.block_navigation.courselimit) {
- branch.addChild({
- name : M.str.moodle.viewallcourses,
- title : M.str.moodle.viewallcourses,
- link : M.cfg.wwwroot+'/course/category.php?id='+branch.get('key'),
- haschildren : false,
- icon : {'pix':"i/navigationitem",'component':'moodle'}
- }, branch);
+ this.addViewAllCoursesChild(branch);
}
}
return true;
+ },
+
+ /**
+ * Add a link to view all courses in a category
+ */
+ addViewAllCoursesChild: function(branch) {
+ branch.addChild({
+ name : M.str.moodle.viewallcourses,
+ title : M.str.moodle.viewallcourses,
+ link : M.cfg.wwwroot+'/course/category.php?id='+branch.get('key'),
+ haschildren : false,
+ icon : {'pix':"i/navigationitem",'component':'moodle'}
+ });
}
}
Y.extend(BRANCH, Y.Base, BRANCH.prototype, {
}
$PAGE->set_url('/blog/index.php', $url_params);
+if (empty($CFG->bloglevel)) {
+ print_error('blogdisable', 'blog');
+}
+
//correct tagid if a text tag is provided as a param
if (!empty($tag)) {
if ($tagrec = $DB->get_record_sql("SELECT * FROM {tag} WHERE ". $DB->sql_like('name', '?', false), array("%$tag%"))) {
$courseid = $DB->get_field('groups', 'courseid', array('id'=>$groupid));
}
-if (empty($CFG->bloglevel)) {
+$sitecontext = get_context_instance(CONTEXT_SYSTEM);
+
+// check basic permissions
+if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) {
+ // everybody can see anything - no login required unless site is locked down using forcelogin
+ if ($CFG->forcelogin) {
+ require_login();
+ }
+
+} else if ($CFG->bloglevel == BLOG_SITE_LEVEL) {
+ // users must log in and can not be guests
+ require_login();
+ if (isguestuser()) {
+ // they must have entered the url manually...
+ print_error('blogdisable', 'blog');
+ }
+
+} else if ($CFG->bloglevel == BLOG_USER_LEVEL) {
+ // users can see own blogs only! with the exception of ppl with special cap
+ require_login();
+
+} else {
+ // weird!
print_error('blogdisable', 'blog');
}
-$sitecontext = get_context_instance(CONTEXT_SYSTEM);
if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) {
if ($entryid) {
if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
print_error('siteblogdisable', 'blog');
}
- if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
- require_login();
- }
if (!has_capability('moodle/blog:view', $sitecontext)) {
print_error('cannotviewsiteblog', 'blog');
}
}
// Get the options for the user
- if ($user !== null) {
+ if ($user !== null and !isguestuser($user)) {
// Load for the requested user
$options[CONTEXT_USER+1] = blog_get_options_for_user($user);
}
// Load for the current user
- $options[CONTEXT_USER] = blog_get_options_for_user();
+ if (isloggedin() and !isguestuser()) {
+ $options[CONTEXT_USER] = blog_get_options_for_user();
+ }
}
// If blog level is global then display a link to view all site entries
$mod[$seq]->id = $rawmods[$seq]->instance;
$mod[$seq]->cm = $rawmods[$seq]->id;
$mod[$seq]->mod = $rawmods[$seq]->modname;
+
+ // Oh dear. Inconsistent names left here for backward compatibility.
$mod[$seq]->section = $section->section;
+ $mod[$seq]->sectionid = $rawmods[$seq]->section;
+
+ $mod[$seq]->module = $rawmods[$seq]->module;
+ $mod[$seq]->added = $rawmods[$seq]->added;
+ $mod[$seq]->score = $rawmods[$seq]->score;
$mod[$seq]->idnumber = $rawmods[$seq]->idnumber;
$mod[$seq]->visible = $rawmods[$seq]->visible;
+ $mod[$seq]->visibleold = $rawmods[$seq]->visibleold;
$mod[$seq]->groupmode = $rawmods[$seq]->groupmode;
$mod[$seq]->groupingid = $rawmods[$seq]->groupingid;
$mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly;
$mod[$seq]->indent = $rawmods[$seq]->indent;
$mod[$seq]->completion = $rawmods[$seq]->completion;
$mod[$seq]->extra = "";
- if(!empty($CFG->enableavailability)) {
+ $mod[$seq]->completiongradeitemnumber =
+ $rawmods[$seq]->completiongradeitemnumber;
+ $mod[$seq]->completionview = $rawmods[$seq]->completionview;
+ $mod[$seq]->completionexpected = $rawmods[$seq]->completionexpected;
+ $mod[$seq]->availablefrom = $rawmods[$seq]->availablefrom;
+ $mod[$seq]->availableuntil = $rawmods[$seq]->availableuntil;
+ $mod[$seq]->showavailability = $rawmods[$seq]->showavailability;
+ if (!empty($CFG->enableavailability)) {
condition_info::fill_availability_conditions($rawmods[$seq]);
- $mod[$seq]->availablefrom = $rawmods[$seq]->availablefrom;
- $mod[$seq]->availableuntil = $rawmods[$seq]->availableuntil;
- $mod[$seq]->showavailability = $rawmods[$seq]->showavailability;
$mod[$seq]->conditionscompletion = $rawmods[$seq]->conditionscompletion;
$mod[$seq]->conditionsgrade = $rawmods[$seq]->conditionsgrade;
}
// 'empty'. This list corresponds to code in the cm_info constructor.
foreach(array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly',
'indent', 'completion', 'extra', 'extraclasses', 'onclick', 'content',
- 'icon', 'iconcomponent', 'customdata', 'availablefrom', 'availableuntil',
- 'conditionscompletion', 'conditionsgrade') as $property) {
+ 'icon', 'iconcomponent', 'customdata', 'showavailability', 'availablefrom',
+ 'availableuntil', 'conditionscompletion', 'conditionsgrade',
+ 'completionview', 'completionexpected', 'score') as $property) {
if (property_exists($mod[$seq], $property) &&
empty($mod[$seq]->{$property})) {
unset($mod[$seq]->{$property});
}
}
+ // Special case: this value is usually set to null, but may be 0
+ if (property_exists($mod[$seq], 'completiongradeitemnumber') &&
+ is_null($mod[$seq]->completiongradeitemnumber)) {
+ unset($mod[$seq]->completiongradeitemnumber);
+ }
}
}
}
redirect("$CFG->wwwroot/");
}
-$PAGE->set_url('/enrol/otherusers.php', array('id'=>$course->id));
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($course, $filter);
-$table = new course_enrolment_other_users_table($manager, $PAGE->url);
-$pageurl = new moodle_url($PAGE->url, $manager->get_url_params()+$table->get_url_params());
+$table = new course_enrolment_other_users_table($manager, $PAGE);
+$PAGE->set_url('/enrol/otherusers.php', $manager->get_url_params()+$table->get_url_params());
/***
* Actions will go here
$renderer = $PAGE->get_renderer('core_enrol');
$canassign = has_capability('moodle/role:assign', $manager->get_context());
-$users = $manager->get_other_users_for_display($renderer, $pageurl, $table->sort, $table->sortdirection, $table->page, $table->perpage);
+$users = $manager->get_other_users_for_display($renderer, $PAGE->url, $table->sort, $table->sortdirection, $table->page, $table->perpage);
$assignableroles = $manager->get_assignable_roles(true);
foreach ($users as $userid=>&$user) {
$user['picture'] = $OUTPUT->render($user['picture']);
- $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $assignableroles, $canassign, $pageurl);
+ $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $assignableroles, $canassign, $PAGE->url);
}
$table->set_total_users($manager->get_total_other_users());
*/
protected function render_course_enrolment_users_table(course_enrolment_users_table $table) {
- $table->initialise_javascript($this->page);
+ $table->initialise_javascript();
$content = '';
- $enrolmentselector = $table->get_enrolment_selector($this->page);
+ $enrolmentselector = $table->get_enrolment_selector();
if ($enrolmentselector) {
$content .= $this->output->render($enrolmentselector);
}
- $cohortenroller = $table->get_cohort_enrolment_control($this->page);
+ $cohortenroller = $table->get_cohort_enrolment_control();
if ($cohortenroller) {
$content .= $this->output->render($cohortenroller);
}
$content .= $this->output->render($table->get_paging_bar());
$content .= html_writer::table($table);
$content .= $this->output->render($table->get_paging_bar());
- $enrolmentselector = $table->get_enrolment_selector($this->page);
+ $enrolmentselector = $table->get_enrolment_selector();
if ($enrolmentselector) {
$content .= $this->output->render($enrolmentselector);
}
- $cohortenroller = $table->get_cohort_enrolment_control($this->page);
+ $cohortenroller = $table->get_cohort_enrolment_control();
if ($cohortenroller) {
$content .= $this->output->render($cohortenroller);
}
*/
protected function render_course_enrolment_other_users_table(course_enrolment_other_users_table $table) {
- $table->initialise_javascript($this->page);
+ $table->initialise_javascript();
$content = '';
- $searchbutton = $table->get_user_search_button($this->page);
+ $searchbutton = $table->get_user_search_button();
if ($searchbutton) {
$content .= $this->output->render($searchbutton);
}
$content .= $this->output->render($table->get_paging_bar());
$content .= html_writer::table($table);
$content .= $this->output->render($table->get_paging_bar());
- $searchbutton = $table->get_user_search_button($this->page);
+ $searchbutton = $table->get_user_search_button();
if ($searchbutton) {
$content .= $this->output->render($searchbutton);
}
/**
* The URL of the page for this table
- * @var moodle_url
+ * @var moodle_page
*/
- public $pageurl;
+ public $moodlepage;
/**
* The sort field for this table, should be one of course_enrolment_table::$sortablefields
*
* @param course_enrolment_manager $manager
*/
- public function __construct(course_enrolment_manager $manager, moodle_url $pageurl) {
+ public function __construct(course_enrolment_manager $manager, moodle_page $moodlepage) {
- $this->manager = $manager;
- $this->pageurl = $pageurl;
+ $this->manager = $manager;
+ $this->moodlepage = $moodlepage;
- $this->page = optional_param(self::PAGEVAR, 0, PARAM_INT);
- $this->perpage = optional_param(self::PERPAGEVAR, self::DEFAULTPERPAGE, PARAM_INT);
- $this->sort = optional_param(self::SORTVAR, self::DEFAULTSORT, PARAM_ALPHA);
+ $this->page = optional_param(self::PAGEVAR, 0, PARAM_INT);
+ $this->perpage = optional_param(self::PERPAGEVAR, self::DEFAULTPERPAGE, PARAM_INT);
+ $this->sort = optional_param(self::SORTVAR, self::DEFAULTSORT, PARAM_ALPHA);
$this->sortdirection = optional_param(self::SORTDIRECTIONVAR, self::DEFAULTSORTDIRECTION, PARAM_ALPHA);
$this->attributes = array('class'=>'userenrolment');
$this->head = array();
$this->colclasses = array();
$this->align = array();
- $url = new moodle_url($this->pageurl, $this->get_url_params()+$this->manager->get_url_params());
+ $url = $this->moodlepage->url;
foreach ($fields as $name => $label) {
$newlabel = '';
if (is_array($label)) {
* Sets the users for this table
*
* @param array $users
- * @param moodle_page $page
+ * @return void
*/
public function set_users(array $users) {
$this->users = $users;
}
}
- public function initialise_javascript(moodle_page $page) {
+ public function initialise_javascript() {
if (has_capability('moodle/role:assign', $this->manager->get_context())) {
- $page->requires->strings_for_js(array(
+ $this->moodlepage->requires->strings_for_js(array(
'assignroles',
'confirmunassign',
'confirmunassigntitle',
'userIds'=>array_keys($this->users),
'courseId'=>$this->manager->get_course()->id,
'otherusers'=>isset($this->otherusers));
- $page->requires->yui_module($modules, $function, array($arguments));
+ $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
}
*/
public function get_paging_bar() {
if ($this->pagingbar == null) {
- $this->pagingbar = new paging_bar($this->totalusers, $this->page, $this->perpage, $this->pageurl, self::PAGEVAR);
+ $this->pagingbar = new paging_bar($this->totalusers, $this->page, $this->perpage, $this->moodlepage->url, self::PAGEVAR);
}
return $this->pagingbar;
}
* Returns a button to enrol cohorts or thier users
*
* @staticvar int $count
- * @param moodle_page $page
* @return single_button|false
*/
- public function get_cohort_enrolment_control(moodle_page $page) {
+ public function get_cohort_enrolment_control() {
static $count = 0;
// First make sure that cohorts is enabled
$control->class = 'singlebutton enrolcohortbutton instance'.$count;
$control->formid = 'manuallyenrol_single_'+$count;
if ($count == 1) {
- $page->requires->strings_for_js(array('enrol','synced','enrolcohort','enrolcohortusers'), 'enrol');
- $page->requires->string_for_js('assignroles', 'role');
- $page->requires->string_for_js('cohort', 'cohort');
- $page->requires->string_for_js('users', 'moodle');
- $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
+ $this->moodlepage->requires->strings_for_js(array('enrol','synced','enrolcohort','enrolcohortusers'), 'enrol');
+ $this->moodlepage->requires->string_for_js('assignroles', 'role');
+ $this->moodlepage->requires->string_for_js('cohort', 'cohort');
+ $this->moodlepage->requires->string_for_js('users', 'moodle');
$hasmanualinstance = false;
// No point showing this at all if the user cant manually enrol users
$arguments = array(
'courseid'=>$course->id,
'ajaxurl'=>'/enrol/ajax.php',
- 'url'=>$url->out(false),
+ 'url'=>$this->moodlepage->url->out(false),
'manualEnrolment'=>$hasmanualinstance);
- $page->requires->yui_module($modules, $function, array($arguments));
+ $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
return $control;
}
*
* @return single_button|url_select
*/
- public function get_enrolment_selector(moodle_page $page) {
+ public function get_enrolment_selector() {
static $count = 0;
$instances = $this->manager->get_enrolment_instances();
$control->formid = 'manuallyenrol_select_'+$count;
}
$course = $this->manager->get_course();
- $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
$timeformat = get_string('strftimedatefullshort');
$today = time();
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
if ($count == 1) {
$instance = reset($manuals);
- $page->requires->strings_for_js(array(
+ $this->moodlepage->requires->strings_for_js(array(
'ajaxoneuserfound',
'ajaxxusersfound',
'ajaxnext25',
'startdatetoday',
'durationdays',
'enrolperiod'), 'enrol');
- $page->requires->string_for_js('assignroles', 'role');
- $page->requires->string_for_js('startingfrom', 'moodle');
+ $this->moodlepage->requires->string_for_js('assignroles', 'role');
+ $this->moodlepage->requires->string_for_js('startingfrom', 'moodle');
$modules = array('moodle-enrol-enrolmentmanager', 'moodle-enrol-enrolmentmanager-skin');
$function = 'M.enrol.enrolmentmanager.init';
'instances'=>$arguments,
'courseid'=>$course->id,
'ajaxurl'=>'/enrol/ajax.php',
- 'url'=>$url->out(false),
+ 'url'=>$this->moodlepage->url->out(false),
'optionsStartDate'=>$startdateoptions,
'defaultRole'=>$instance->roleid);
- $page->requires->yui_module($modules, $function, array($arguments));
+ $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
return $control;
}
* @return single_select
*/
public function get_enrolment_type_filter() {
- $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
- $selector = new single_select($url, 'ifilter', array(0=>get_string('all')) + (array)$this->manager->get_enrolment_instance_names(), $this->manager->get_enrolment_filter(), array());
+ $selector = new single_select($this->moodlepage->url, 'ifilter', array(0=>get_string('all')) + (array)$this->manager->get_enrolment_instance_names(), $this->manager->get_enrolment_filter(), array());
$selector->set_label( get_string('enrolmentinstances', 'enrol'));
return $selector;
}
* Constructs the table
*
* @param course_enrolment_manager $manager
- * @param moodle_url $pageurl
+ * @param moodle_page $moodlepage
*/
- public function __construct(course_enrolment_manager $manager, moodle_url $pageurl) {
- parent::__construct($manager, $pageurl);
+ public function __construct(course_enrolment_manager $manager, moodle_page $moodlepage) {
+ parent::__construct($manager, $moodlepage);
$this->attributes = array('class'=>'userenrolment otheruserenrolment');
}
* @param int $page
* @return single_button
*/
- public function get_user_search_button($page) {
- global $CFG;
+ public function get_user_search_button() {
static $count = 0;
if (!has_capability('moodle/role:assign', $this->manager->get_context())) {
return false;
}
$count++;
- $url = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$this->manager->get_context()->id, 'sesskey'=>sesskey()));
+ $url = new moodle_url('/admin/roles/assign.php', array('contextid'=>$this->manager->get_context()->id, 'sesskey'=>sesskey()));
$control = new single_button($url, get_string('assignroles', 'role'), 'get');
$control->class = 'singlebutton assignuserrole instance'.$count;
if ($count == 1) {
- $page->requires->strings_for_js(array(
+ $this->moodlepage->requires->strings_for_js(array(
'ajaxoneuserfound',
'ajaxxusersfound',
'ajaxnext25',
'startdatetoday',
'durationdays',
'enrolperiod'), 'enrol');
- $page->requires->string_for_js('assignrole', 'role');
+ $this->moodlepage->requires->string_for_js('assignrole', 'role');
$modules = array('moodle-enrol-otherusersmanager', 'moodle-enrol-otherusersmanager-skin');
$function = 'M.enrol.otherusersmanager.init';
- $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
$arguments = array(
'courseId'=> $this->manager->get_course()->id,
'ajaxUrl' => '/enrol/ajax.php',
- 'url' => $url->out(false));
- $page->requires->yui_module($modules, $function, array($arguments));
+ 'url' => $this->moodlepage->url->out(false));
+ $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
return $control;
}
$enrol = enrol_get_plugin('self');
$timestart = time();
if ($instance->enrolperiod) {
- $tineend = $timestart + $instance->enrolperiod;
+ $timeend = $timestart + $instance->enrolperiod;
} else {
- $tineend = 0;
+ $timeend = 0;
}
- $this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $tineend);
+ $this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend);
add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere!
if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) {
$action = optional_param('action', '', PARAM_ACTION);
$filter = optional_param('ifilter', 0, PARAM_INT);
-$PAGE->set_url(new moodle_url('/enrol/users.php', array('id'=>$id)));
-
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($course, $filter);
-$table = new course_enrolment_users_table($manager, $PAGE->url);
-$pageurl = new moodle_url($PAGE->url, $manager->get_url_params()+$table->get_url_params());
+$table = new course_enrolment_users_table($manager, $PAGE);
+$PAGE->set_url('/enrol/users.php', $manager->get_url_params()+$table->get_url_params());
// Check if there is an action to take
if ($action) {
list ($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if ($instance && $plugin && $plugin->allow_unenrol($instance) && has_capability("enrol/$instance->enrol:unenrol", $manager->get_context())) {
if ($confirm && $manager->unenrol_user($ue)) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
- $yesurl = new moodle_url($pageurl, array('action'=>'unenrol', 'ue'=>$ue->id, 'confirm'=>1, 'sesskey'=>sesskey()));
+ $yesurl = new moodle_url($PAGE->url, array('action'=>'unenrol', 'ue'=>$ue->id, 'confirm'=>1, 'sesskey'=>sesskey()));
$message = get_string('unenrolconfirm', 'enrol', array('user'=>fullname($user, true), 'course'=>format_string($course->fullname)));
$pagetitle = get_string('unenrol', 'enrol');
- $pagecontent = $OUTPUT->confirm($message, $yesurl, $pageurl);
+ $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
$role = required_param('role', PARAM_INT);
$user = required_param('user', PARAM_INT);
if ($confirm && $manager->unassign_role_from_user($user, $role)) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$user = $DB->get_record('user', array('id'=>$user), '*', MUST_EXIST);
$allroles = $manager->get_all_roles();
$role = $allroles[$role];
- $yesurl = new moodle_url($pageurl, array('action'=>'unassign', 'role'=>$role->id, 'user'=>$user->id, 'confirm'=>1, 'sesskey'=>sesskey()));
+ $yesurl = new moodle_url($PAGE->url, array('action'=>'unassign', 'role'=>$role->id, 'user'=>$user->id, 'confirm'=>1, 'sesskey'=>sesskey()));
$message = get_string('unassignconfirm', 'role', array('user'=>fullname($user, true), 'role'=>$role->localname));
$pagetitle = get_string('unassignarole', 'role', $role->localname);
- $pagecontent = $OUTPUT->confirm($message, $yesurl, $pageurl);
+ $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
$user = $DB->get_record('user', array('id'=>required_param('user', PARAM_INT)), '*', MUST_EXIST);
if (is_enrolled($context, $user) && has_capability('moodle/role:assign', $manager->get_context())) {
$mform = new enrol_users_assign_form(NULL, array('user'=>$user, 'course'=>$course, 'assignable'=>$manager->get_assignable_roles()));
- $mform->set_data($pageurl->params());
+ $mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || ($data && array_key_exists($data->roleid, $manager->get_assignable_roles()) && $manager->assign_role_to_user($data->roleid, $user->id))) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$pagetitle = get_string('assignroles', 'role');
}
$userid = required_param('user', PARAM_INT);
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
if ($confirm && $manager->remove_user_from_group($user, $groupid)) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$group = $manager->get_group($groupid);
if (!$group) {
break;
}
- $yesurl = new moodle_url($pageurl, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey()));
+ $yesurl = new moodle_url($PAGE->url, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey()));
$message = get_string('removefromgroupconfirm', 'group', array('user'=>fullname($user, true), 'group'=>$group->name));
$pagetitle = get_string('removefromgroup', 'group', $group->name);
- $pagecontent = $OUTPUT->confirm($message, $yesurl, $pageurl);
+ $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
$mform = new enrol_users_addmember_form(NULL, array('user'=>$user, 'course'=>$course, 'allgroups'=>$manager->get_all_groups()));
- $mform->set_data($pageurl->params());
+ $mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || ($data && $manager->add_user_to_group($user, $data->groupid))) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$pagetitle = get_string('addgroup', 'group');
}
if ($instance && $plugin && $plugin->allow_manage($instance) && has_capability("enrol/$instance->enrol:manage", $manager->get_context())) {
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
$mform = new enrol_users_edit_form(NULL, array('user'=>$user, 'course'=>$course, 'ue'=>$ue));
- $mform->set_data($pageurl->params());
+ $mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || ($data && $manager->edit_enrolment($ue, $data))) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$pagetitle = fullname($user);
}
$table->set_fields($fields, $renderer);
$canassign = has_capability('moodle/role:assign', $manager->get_context());
-$users = $manager->get_users_for_display($renderer, $pageurl, $table->sort, $table->sortdirection, $table->page, $table->perpage);
+$users = $manager->get_users_for_display($renderer, $PAGE->url, $table->sort, $table->sortdirection, $table->page, $table->perpage);
foreach ($users as $userid=>&$user) {
$user['picture'] = $OUTPUT->render($user['picture']);
- $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $manager->get_assignable_roles(), $canassign, $pageurl);
- $user['group'] = $renderer->user_groups_and_actions($userid, $user['groups'], $manager->get_all_groups(), has_capability('moodle/course:managegroups', $manager->get_context()), $pageurl);
- $user['enrol'] = $renderer->user_enrolments_and_actions($userid, $user['enrolments'], $pageurl);
+ $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $manager->get_assignable_roles(), $canassign, $PAGE->url);
+ $user['group'] = $renderer->user_groups_and_actions($userid, $user['groups'], $manager->get_all_groups(), has_capability('moodle/course:managegroups', $manager->get_context()), $PAGE->url);
+ $user['enrol'] = $renderer->user_enrolments_and_actions($userid, $user['enrolments'], $PAGE->url);
}
$table->set_total_users($manager->get_total_users());
$table->set_users($users);
$texexp = preg_replace('/\\\int\\\left\((.+?),(.+?),(.+?)\\\right\)/s','\int_'. "{\$2}^{\$3}\$1 ",$texexp);
$texexp = preg_replace('/\\\int\\\left\((.+?d[a-z])\\\right\)/s','\int '. "\$1 ",$texexp);
$texexp = preg_replace('/\\\lim\\\left\((.+?),(.+?),(.+?)\\\right\)/s','\lim_'. "{\$2\\to \$3}\$1 ",$texexp);
+ $texexp = str_replace('\mbox', '', $texexp); // now blacklisted in tex, sorry
$texcache->filter = 'algebra';
$texcache->version = 1;
$texcache->md5key = $md5;
// YouTube and Vimeo are great because the files are not served by Moodle server
if (!empty($CFG->filter_mediaplugin_enable_youtube)) {
- $search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/watch\?v=([a-z0-9\-_]+)[^>]*>([^>]*)<\/a>/is';
+ $search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/watch\?v=([a-z0-9\-_]+)[^"#]*(#d=([\d]{1,4})x([\d]{1,4}))?"[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_callback', $newtext);
- $search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/v\/([a-z0-9\-_]*)[^>]+>([^>]*)<\/a>/is';
+ $search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/v\/([a-z0-9\-_]+)[^"#]*(#d=([\d]{1,4})x([\d]{1,4}))?[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_callback', $newtext);
- $search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/view_play_list\?p=([a-z0-9\-_]+)[^>]*>([^>]*)<\/a>/is';
+ $search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/view_play_list\?p=([a-z0-9\-_]+)[^"#]*(#d=([\d]{1,4})x([\d]{1,4}))?[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_playlist_callback', $newtext);
- $search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/p\/([a-z0-9\-_]*)[^>]+>([^>]*)<\/a>/is';
+ $search = '/<a\s[^>]*href="(https?:\/\/www\.youtube(-nocookie)?\.com)\/p\/([a-z0-9\-_]+)[^"#]*(#d=([\d]{1,4})x([\d]{1,4}))?[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_youtube_playlist_callback', $newtext);
}
if (!empty($CFG->filter_mediaplugin_enable_vimeo)) {
- $search = '/<a\s[^>]*href="http:\/\/vimeo\.com\/([0-9]+)"[^>]*>([^>]*)<\/a>/is';
+ $search = '/<a\s[^>]*href="http:\/\/vimeo\.com\/([0-9]+)[^"#]*(#d=([\d]{1,4})x([\d]{1,4}))?[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_vimeo_callback', $newtext);
}
}
if ((!empty($options['noclean']) or !empty($CFG->allowobjectembed)) and !empty($CFG->filter_mediaplugin_enable_swf)) {
- $search = '/<a\s[^>]*href="([^"#\?]+\.swf)([#\?]d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>([^>]*)<\/a>/is';
+ $search = '/<a\s[^>]*href="([^"#\?]+\.swf)([#\?]d=([\d]{1,4})x([\d]{1,4}))?"[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_swf_callback', $newtext);
}
// The rest of legacy formats - these should not be used if possible
if (!empty($CFG->filter_mediaplugin_enable_wmp)) {
- $search = '/<a\s[^>]*href="([^"#\?]+\.(wmv|avi))(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>([^>]*)<\/a>/is';
+ $search = '/<a\s[^>]*href="([^"#\?]+\.(wmv|avi))(\?d=([\d]{1,4})x([\d]{1,4}))?"[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_wmp_callback', $newtext);
}
if (!empty($CFG->filter_mediaplugin_enable_qt)) {
// HTML5 filtering may steal mpeg 4 formats
- $search = '/<a\s[^>]*href="([^"#\?]+\.(mpg|mpeg|mov|mp4|m4v|m4a))(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>([^>]*)<\/a>/is';
+ $search = '/<a\s[^>]*href="([^"#\?]+\.(mpg|mpeg|mov|mp4|m4v|m4a))(\?d=([\d]{1,4})x([\d]{1,4}))?"[^>]*>([^>]*)<\/a>/is';
$newtext = preg_replace_callback($search, 'filter_mediaplugin_qt_callback', $newtext);
}
foreach ($urls as $url) {
$matches = null;
- if (preg_match('/^d=([\d]{1,4}%?)x([\d]{1,4}%?)$/i', $url, $matches)) { // #d=640x480
+ if (preg_match('/^d=([\d]{1,4})x([\d]{1,4})$/i', $url, $matches)) { // #d=640x480
$width = $matches[1];
$height = $matches[2];
continue;
}
- if (preg_match('/\?d=([\d]{1,4}%?)x([\d]{1,4}%?)$/i', $url, $matches)) { // old style file.ext?d=640x480
+ if (preg_match('/\?d=([\d]{1,4})x([\d]{1,4})$/i', $url, $matches)) { // old style file.ext?d=640x480
$width = $matches[1];
$height = $matches[2];
$url = str_replace($matches[0], '', $url);
$site = $link[1];
$videoid = $link[3];
- $info = trim($link[4]);
+ $info = trim($link[7]);
if (empty($info) or strpos($info, 'http') === 0) {
$info = get_string('siteyoutube', 'filter_mediaplugin');
}
$info = s($info);
- $width = FILTER_MEDIAPLUGIN_VIDEO_WIDTH;
- $height = FILTER_MEDIAPLUGIN_VIDEO_HEIGHT;
+ $width = empty($link[5]) ? FILTER_MEDIAPLUGIN_VIDEO_WIDTH : $link[5];
+ $height = empty($link[6]) ? FILTER_MEDIAPLUGIN_VIDEO_HEIGHT : $link[6];
if (false and empty($CFG->xmlstrictheaders)) {
// TODO: remove this once iframe playback starts to work properly in iPads
$site = $link[1];
$playlist = $link[3];
- $info = trim($link[4]);
+ $info = trim($link[7]);
if (empty($info) or strpos($info, 'http') === 0) {
$info = get_string('siteyoutube', 'filter_mediaplugin');
}
$printlink = html_writer::link("$site/view_play_list\?p=$playlist", $info, array('class'=>'mediafallbacklink'));
$info = s($info);
- $width = FILTER_MEDIAPLUGIN_VIDEO_WIDTH;
- $height = FILTER_MEDIAPLUGIN_VIDEO_HEIGHT;
+ $width = empty($link[5]) ? FILTER_MEDIAPLUGIN_VIDEO_WIDTH : $link[5];
+ $height = empty($link[6]) ? FILTER_MEDIAPLUGIN_VIDEO_HEIGHT : $link[6];
// TODO: iframe HTML 5 video not implemented and object does work on iOS devices
}
$videoid = $link[1];
- $info = s(strip_tags($link[2]));
+ $info = s(strip_tags($link[5]));
//Note: resizing via url is not supported, user can click the fullscreen button instead
// iframe embedding is not xhtml strict but it is the only option that seems to work on most devices
- $width = FILTER_MEDIAPLUGIN_VIDEO_WIDTH;
- $height = FILTER_MEDIAPLUGIN_VIDEO_HEIGHT;
+ $width = empty($link[3]) ? FILTER_MEDIAPLUGIN_VIDEO_WIDTH : $link[3];
+ $height = empty($link[4]) ? FILTER_MEDIAPLUGIN_VIDEO_HEIGHT : $link[4];
$output = <<<OET
<span class="mediaplugin mediaplugin_vimeo">
echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block'));
echo $OUTPUT->heading(get_string('courses'), 2, 'headingblock header');
$renderer = $PAGE->get_renderer('core','course');
- echo $renderer->course_category_tree(get_course_category_tree());
+ // if there are too many courses, budiling course category tree could be slow,
+ // users should go to course index page to see the whole list.
+ $coursecount = $DB->count_records('course');
+ if (empty($CFG->numcoursesincombo)) {
+ // if $CFG->numcoursesincombo hasn't been set, use default value 500
+ $CFG->numcoursesincombo = 500;
+ }
+ if ($coursecount > $CFG->numcoursesincombo) {
+ $link = new moodle_url('/course/');
+ echo $OUTPUT->notification(get_string('maxnumcoursesincombo', 'moodle', array('link'=>$link->out(), 'maxnumofcourses'=>$CFG->numcoursesincombo, 'numberofcourses'=>$coursecount)));
+ } else {
+ echo $renderer->course_category_tree(get_course_category_tree());
+ }
print_course_search('', false, 'short');
echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcourses'));
break;
$string['numberofstrings'] = 'Total number of strings: {$a->strings}<br />Missing: {$a->missing} ({$a->missingpercent} %)';
$string['numquestions'] = 'No. questions';
$string['numquestionsandhidden'] = '{$a->numquestions} (+{$a->numhidden} hidden)';
+$string['numcoursesincombo'] = 'Maximum number of courses in combo list';
+$string['numcoursesincombo_help'] = 'The combo list doesn\'t work well with large numbers of courses. When the total number of courses in the site is higher than this setting then a link to the dedicated course listing will be shown instead of trying to display all the courses on the front page.';
$string['opensslrecommended'] = 'Installing the optional OpenSSL library is highly recommended -- it enables Moodle Networking functionality.';
$string['opentogoogle'] = 'Open to Google';
$string['optionalmaintenancemessage'] = 'Optional maintenance message';
$string['maximumupload_help'] = 'This setting determines the largest size of file that can be uploaded to the course, limited by the site-wide setting set by an administrator. Activity modules also include a maximum upload size setting for further restricting the file size.';
$string['maxsize'] = 'Max size: {$a}';
$string['maxfilesize'] = 'Maximum size for new files: {$a}';
+$string['maxnumcoursesincombo'] = 'Browse <a href="{$a->link}">{$a->numberofcourses} courses</a>.';
$string['memberincourse'] = 'People in the course';
$string['messagebody'] = 'Message body';
$string['messagedselectedusers'] = 'Selected users have been messaged and the recipient list has been reset.';
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
}
if ($type === 'mod') {
- // perform cleanup tasks specific for activity modules
+ // perform cleanup tasks specific for activity modules
if (!$module = $DB->get_record('modules', array('name' => $name))) {
print_error('moduledoesnotexist', 'error');
}
if (!$ignorecurrent) {
- // read value from db - other processes might have changed it
+ // read value from db - other processes might have changed it
$value = $DB->get_field('config', 'value', array('name'=>$name));
if ($value and $value > time()) {
- //lock active
+ //lock active
return false;
}
}
/// CLASS DEFINITIONS /////////////////////////////////////////////////////////
+
/**
* Interface for anything appearing in the admin tree
*
public function show_save();
}
+
/**
* Interface implemented by any part_of_admin_tree that has children.
*
}
+
/**
* The object used to represent folders (a.k.a. categories) in the admin tree block.
*
$parent->children[] = $something;
if (is_array($this->category_cache) and ($something instanceof admin_category)) {
if (isset($this->category_cache[$something->name])) {
- debugging('Duplicate admin catefory name: '.$something->name);
+ debugging('Duplicate admin category name: '.$something->name);
} else {
$this->category_cache[$something->name] = $something;
$something->category_cache =& $this->category_cache;
// just in case somebody already added subcategories
if ($child instanceof admin_category) {
if (isset($this->category_cache[$child->name])) {
- debugging('Duplicate admin catefory name: '.$child->name);
+ debugging('Duplicate admin category name: '.$child->name);
} else {
$this->category_cache[$child->name] = $child;
$child->category_cache =& $this->category_cache;
}
}
+
/**
* Root of admin settings tree, does not have any parent.
*
}
}
+
/**
* Links external PHP pages into the admin tree.
*
*/
class admin_externalpage implements part_of_admin_tree {
-/** @var string An internal name for this external page. Must be unique amongst ALL part_of_admin_tree objects */
+ /** @var string An internal name for this external page. Must be unique amongst ALL part_of_admin_tree objects */
public $name;
/** @var string The displayed name for this external page. Usually obtained through get_string(). */
/** @var mixed either string or array of string */
public $path;
+
+ /** @var array list of visible names of page parents */
public $visiblepath;
/**
}
}
+
/**
* Used to group a number of admin_setting objects into a page and add them to the admin tree.
*
*/
class admin_settingpage implements part_of_admin_tree {
-/** @var string An internal name for this external page. Must be unique amongst ALL part_of_admin_tree objects */
+ /** @var string An internal name for this external page. Must be unique amongst ALL part_of_admin_tree objects */
public $name;
/** @var string The displayed name for this external page. Usually obtained through get_string(). */
/** @var mixed string of paths or array of strings of paths */
public $path;
+
+ /** @var array list of visible names of page parents */
public $visiblepath;
/**
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class admin_setting {
-/** @var string unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins. */
+ /** @var string unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins. */
public $name;
/** @var string localised name */
public $visiblename;
public $plugin; // null means main config table
/** @var bool true indicates this setting does not actually save anything, just information */
public $nosave = false;
+ /** @var bool if set, indicates that a change to this setting requires rebuild course cache */
+ public $affectsmodinfo = false;
/**
* Constructor
return 'id_s_'.$this->plugin.'_'.$this->name;
}
+ /**
+ * @param bool $affectsmodinfo If true, changes to this setting will
+ * cause the course cache to be rebuilt
+ */
+ public function set_affects_modinfo($affectsmodinfo) {
+ $this->affectsmodinfo = $affectsmodinfo;
+ }
+
/**
* Returns the config if possible
*
- * @return mixed returns config if successfull else null
+ * @return mixed returns config if successful else null
*/
public function config_read($name) {
global $CFG;
// store change
set_config($name, $value, $this->plugin);
+ // Some admin settings affect course modinfo
+ if ($this->affectsmodinfo) {
+ // Clear course cache for all courses
+ rebuild_course_cache(0, true);
+ }
+
// log change
$log = new stdClass();
$log->userid = during_initial_install() ? 0 :$USER->id; // 0 as user id during install
/**
* Function called if setting updated - cleanup, cache reset, etc.
* @param string $functionname Sets the function name
+ * @return void
*/
public function set_updatedcallback($functionname) {
$this->updatedcallback = $functionname;
}
}
+
/**
* No setting - just heading and text.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_heading extends admin_setting {
-/**
- * not a setting, just text
- * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
- * @param string $heading heading
- * @param string $information text in box
- */
+
+ /**
+ * not a setting, just text
+ * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
+ * @param string $heading heading
+ * @param string $information text in box
+ */
public function __construct($name, $heading, $information) {
$this->nosave = true;
parent::__construct($name, $heading, $information, '');
}
}
+
/**
* The most flexibly setting, user is typing text
*
*/
class admin_setting_configtext extends admin_setting {
-/** @var mixed int means PARAM_XXX type, string is a allowed format in regex */
+ /** @var mixed int means PARAM_XXX type, string is a allowed format in regex */
public $paramtype;
/** @var int default field size */
public $size;
}
}
+
/**
* General text area without html editor.
*
$this->cols = $cols;
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype);
}
+
/**
* Returns an XHTML string for the editor
*
}
}
+
/**
* General text area with html editor.
*/
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype);
editors_head_setup();
}
+
/**
* Returns an XHTML string for the editor
*
}
}
+
/**
* Password field, allows unmasking of password
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configpasswordunmask extends admin_setting_configtext {
-/**
- * Constructor
- * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
- * @param string $visiblename localised
- * @param string $description long localised info
- * @param string $defaultsetting default password
- */
+ /**
+ * Constructor
+ * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
+ * @param string $visiblename localised
+ * @param string $description long localised info
+ * @param string $defaultsetting default password
+ */
public function __construct($name, $visiblename, $description, $defaultsetting) {
parent::__construct($name, $visiblename, $description, $defaultsetting, PARAM_RAW, 30);
}
}
}
+
/**
* Path to directory
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configfile extends admin_setting_configtext {
-/**
- * Constructor
- * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
- * @param string $visiblename localised
- * @param string $description long localised info
- * @param string $defaultdirectory default directory location
- */
+ /**
+ * Constructor
+ * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
+ * @param string $visiblename localised
+ * @param string $description long localised info
+ * @param string $defaultdirectory default directory location
+ */
public function __construct($name, $visiblename, $description, $defaultdirectory) {
parent::__construct($name, $visiblename, $description, $defaultdirectory, PARAM_RAW, 50);
}
}
}
+
/**
* Path to executable file
*
*/
class admin_setting_configexecutable extends admin_setting_configfile {
-/**
- * Returns an XHTML field
- *
- * @param string $data This is the value for the field
- * @param string $query
- * @return string XHTML field
- */
+ /**
+ * Returns an XHTML field
+ *
+ * @param string $data This is the value for the field
+ * @param string $query
+ * @return string XHTML field
+ */
public function output_html($data, $query='') {
$default = $this->get_defaultsetting();
}
}
+
/**
* Path to directory
*
*/
class admin_setting_configdirectory extends admin_setting_configfile {
-/**
- * Returns an XHTML field
- *
- * @param string $data This is the value for the field
- * @param string $query
- * @return string XHTML
- */
+ /**
+ * Returns an XHTML field
+ *
+ * @param string $data This is the value for the field
+ * @param string $query
+ * @return string XHTML
+ */
public function output_html($data, $query='') {
$default = $this->get_defaultsetting();
}
}
+
/**
* Checkbox
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configcheckbox extends admin_setting {
-/** @var string Value used when checked */
+ /** @var string Value used when checked */
public $yes;
/** @var string Value used when not checked */
public $no;
}
}
+
/**
* Multiple checkboxes, each represents different value, stored in csv format
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configmulticheckbox extends admin_setting {
-/** @var array Array of choices value=>label */
+ /** @var array Array of choices value=>label */
public $choices;
/**
}
}
+
/**
* Multiple checkboxes 2, value stored as string 00101011
*
*/
class admin_setting_configmulticheckbox2 extends admin_setting_configmulticheckbox {
-/**
- * Returns the setting if set
- *
- * @return mixed null if not set, else an array of set settings
- */
+ /**
+ * Returns the setting if set
+ *
+ * @return mixed null if not set, else an array of set settings
+ */
public function get_setting() {
$result = $this->config_read($this->name);
if (is_null($result)) {
}
}
+
/**
* Select one value from list
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configselect extends admin_setting {
-/** @var array Array of choices value=>label */
+ /** @var array Array of choices value=>label */
public $choices;
/**
}
}
+
/**
* Select multiple items from list
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configmultiselect extends admin_setting_configselect {
-/**
- * Constructor
- * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
- * @param string $visiblename localised
- * @param string $description long localised info
- * @param array $defaultsetting array of selected items
- * @param array $choices array of $value=>$label for each list item
- */
+ /**
+ * Constructor
+ * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
+ * @param string $visiblename localised
+ * @param string $description long localised info
+ * @param array $defaultsetting array of selected items
+ * @param array $choices array of $value=>$label for each list item
+ */
public function __construct($name, $visiblename, $description, $defaultsetting, $choices) {
parent::__construct($name, $visiblename, $description, $defaultsetting, $choices);
}
* Potential bug in the works should anyone call with this function
* using a vartype that is not an array
*
- * @todo Add vartype handling to ensure $data is an array
* @param array $data
*/
public function write_setting($data) {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configtime extends admin_setting {
-/** @var string Used for setting second select (minutes) */
+ /** @var string Used for setting second select (minutes) */
public $name2;
/**
}
+
/**
* Used to validate a textarea used for ip addresses
*
*/
class admin_setting_configiplist extends admin_setting_configtextarea {
-/**
- * Validate the contents of the textarea as IP addresses
- *
- * Used to validate a new line separated list of IP addresses collected from
- * a textarea control
- *
- * @param string $data A list of IP Addresses separated by new lines
- * @return mixed bool true for success or string:error on failure
- */
+ /**
+ * Validate the contents of the textarea as IP addresses
+ *
+ * Used to validate a new line separated list of IP addresses collected from
+ * a textarea control
+ *
+ * @param string $data A list of IP Addresses separated by new lines
+ * @return mixed bool true for success or string:error on failure
+ */
public function validate($data) {
if(!empty($data)) {
$ips = explode("\n", $data);
$result = true;
foreach($ips as $ip) {
$ip = trim($ip);
- if(preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}$#', $ip, $match) ||
+ if (preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}$#', $ip, $match) ||
preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}(\/\d{1,2})$#', $ip, $match) ||
preg_match('#^(\d{1,3})(\.\d{1,3}){3}(-\d{1,3})$#', $ip, $match)) {
$result = true;
}
}
+
/**
* An admin setting for selecting one or more users who have a capability
* in the system context
}
}
+
/**
* Special checkbox for calendar - resets SESSION vars.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_adminseesall extends admin_setting_configcheckbox {
-/**
- * Calls the parent::__construct with default values
- *
- * name => calendar_adminseesall
- * visiblename => get_string('adminseesall', 'admin')
- * description => get_string('helpadminseesall', 'admin')
- * defaultsetting => 0
- */
+ /**
+ * Calls the parent::__construct with default values
+ *
+ * name => calendar_adminseesall
+ * visiblename => get_string('adminseesall', 'admin')
+ * description => get_string('helpadminseesall', 'admin')
+ * defaultsetting => 0
+ */
public function __construct() {
parent::__construct('calendar_adminseesall', get_string('adminseesall', 'admin'),
get_string('helpadminseesall', 'admin'), '0');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_selectsetup extends admin_setting_configselect {
-/**
- * Reads the setting directly from the database
- *
- * @return mixed
- */
+ /**
+ * Reads the setting directly from the database
+ *
+ * @return mixed
+ */
public function get_setting() {
// read directly from db!
return get_config(NULL, $this->name);
}
}
+
/**
* Special select for frontpage - stores data in course table
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_sitesetselect extends admin_setting_configselect {
-/**
- * Returns the site name for the selected site
- *
- * @see get_site()
- * @return string The site name of the selected site
- */
+ /**
+ * Returns the site name for the selected site
+ *
+ * @see get_site()
+ * @return string The site name of the selected site
+ */
public function get_setting() {
$site = get_site();
return $site->{$this->name};
}
+
/**
* Updates the database and save the setting
*
}
}
+
/**
* Select for blog's bloglevel setting: if set to 0, will set blog_menu
* block to hidden.
* @return string empty or error message
*/
public function write_setting($data) {
- global $DB;
+ global $DB, $CFG;
if ($data['bloglevel'] == 0) {
- $DB->set_field('block', 'visible', 0, array('name' => 'blog_menu'));
+ $blogblocks = $DB->get_records_select('block', "name LIKE 'blog_%' AND visible = 1");
+ foreach ($blogblocks as $block) {
+ $DB->set_field('block', 'visible', 0, array('id' => $block->id));
+ }
} else {
- $DB->set_field('block', 'visible', 1, array('name' => 'blog_menu'));
+ // reenable all blocks only when switching from disabled blogs
+ if (isset($CFG->bloglevel) and $CFG->bloglevel == 0) {
+ $blogblocks = $DB->get_records_select('block', "name LIKE 'blog_%' AND visible = 0");
+ foreach ($blogblocks as $block) {
+ $DB->set_field('block', 'visible', 1, array('id' => $block->id));
+ }
+ }
}
return parent::write_setting($data);
}
}
+
/**
* Special select - lists on the frontpage - hacky
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_courselist_frontpage extends admin_setting {
-/** @var array Array of choices value=>label */
+ /** @var array Array of choices value=>label */
public $choices;
/**
}
return true;
}
+
/**
* Returns the selected settings
*
}
}
+
/**
* Special checkbox for frontpage - stores data in course table
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_sitesetcheckbox extends admin_setting_configcheckbox {
-/**
- * Returns the current sites name
- *
- * @return string
- */
+ /**
+ * Returns the current sites name
+ *
+ * @return string
+ */
public function get_setting() {
$site = get_site();
return $site->{$this->name};
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_sitesettext extends admin_setting_configtext {
-/**
- * Return the current setting
- *
- * @return mixed string or null
- */
+ /**
+ * Return the current setting
+ *
+ * @return mixed string or null
+ */
public function get_setting() {
$site = get_site();
return $site->{$this->name} != '' ? $site->{$this->name} : NULL;
}
}
+
/**
* Special text editor for site description.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_frontpagedesc extends admin_setting {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('summary', get_string('frontpagedescription'), get_string('frontpagedescriptionhelp'), NULL);
editors_head_setup();
}
}
+
/**
* Administration interface for emoticon_manager settings.
*
*/
class admin_setting_emoticons extends admin_setting {
-/**
- * Calls parent::__construct with specific args
- */
+ /**
+ * Calls parent::__construct with specific args
+ */
public function __construct() {
global $CFG;
}
}
+
/**
* Special setting for limiting of the list of available languages.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_langlist extends admin_setting_configtext {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('langlist', get_string('langlist', 'admin'), get_string('configlanglist', 'admin'), '', PARAM_NOTAGS);
}
}
}
+
/**
* Selection of one of the recognised countries using the list
* returned by {@link get_list_of_countries()}.
}
}
+
/**
* Course category selection
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_settings_coursecat_select extends admin_setting_configselect {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct($name, $visiblename, $description, $defaultsetting) {
parent::__construct($name, $visiblename, $description, $defaultsetting, NULL);
}
}
}
+
/**
* Special control for selecting days to backup
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_backupdays extends admin_setting_configmulticheckbox2 {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('backup_auto_weekdays', get_string('automatedbackupschedule','backup'), get_string('automatedbackupschedulehelp','backup'), array(), NULL);
$this->plugin = 'backup';
}
+
/**
* Load the available choices for the select box
*
}
}
+
/**
* Special debug setting
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_debug extends admin_setting_configselect {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('debug', get_string('debug', 'admin'), get_string('configdebug', 'admin'), DEBUG_NONE, NULL);
}
}
}
+
/**
* Special admin control
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_calendar_weekend extends admin_setting {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
$name = 'calendar_weekend';
$visiblename = get_string('calendar_weekend', 'admin');
$default = array ('0', '6'); // Saturdays and Sundays
parent::__construct($name, $visiblename, $description, $default);
}
+
/**
* Gets the current settings as an array
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_pickroles extends admin_setting_configmulticheckbox {
-/** @var array Array of capabilities which identify roles */
+ /** @var array Array of capabilities which identify roles */
private $types;
/**
return false;
}
}
+
/**
* Return the default setting for this control
*
}
}
+
/**
* Text field with an advanced checkbox, that controls a additional $name.'_adv' setting.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configtext_with_advanced extends admin_setting_configtext {
-/**
- * Constructor
- * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
- * @param string $visiblename localised
- * @param string $description long localised info
- * @param array $defaultsetting ('value'=>string, '__construct'=>bool)
- * @param mixed $paramtype int means PARAM_XXX type, string is a allowed format in regex
- * @param int $size default field size
- */
+ /**
+ * Constructor
+ * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
+ * @param string $visiblename localised
+ * @param string $description long localised info
+ * @param array $defaultsetting ('value'=>string, '__construct'=>bool)
+ * @param mixed $paramtype int means PARAM_XXX type, string is a allowed format in regex
+ * @param int $size default field size
+ */
public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $size=null) {
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype, $size);
}
}
}
+
/**
* Checkbox with an advanced checkbox that controls an additional $name.'_adv' config setting.
*
*/
class admin_setting_configcheckbox_with_advanced extends admin_setting_configcheckbox {
-/**
- * Constructor
- * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
- * @param string $visiblename localised
- * @param string $description long localised info
- * @param array $defaultsetting ('value'=>string, 'adv'=>bool)
- * @param string $yes value used when checked
- * @param string $no value used when not checked
- */
+ /**
+ * Constructor
+ * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
+ * @param string $visiblename localised
+ * @param string $description long localised info
+ * @param array $defaultsetting ('value'=>string, 'adv'=>bool)
+ * @param string $yes value used when checked
+ * @param string $no value used when not checked
+ */
public function __construct($name, $visiblename, $description, $defaultsetting, $yes='1', $no='0') {
parent::__construct($name, $visiblename, $description, $defaultsetting, $yes, $no);
}
}
}
+
/**
* Checkbox with an advanced checkbox that controls an additional $name.'_locked' config setting.
*
}
}
+
/**
* Dropdown menu with an advanced checkbox, that controls a additional $name.'_adv' setting.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configselect_with_advanced extends admin_setting_configselect {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct($name, $visiblename, $description, $defaultsetting, $choices) {
parent::__construct($name, $visiblename, $description, $defaultsetting, $choices);
}
}
}
+
/**
* Graded roles in gradebook
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_gradebookroles extends admin_setting_pickroles {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('gradebookroles', get_string('gradebookroles', 'admin'),
get_string('configgradebookroles', 'admin'),
}
}
+
/**
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_regradingcheckbox extends admin_setting_configcheckbox {
-/**
- * Saves the new settings passed in $data
- *
- * @param string $data
- * @return mixed string or Array
- */
+ /**
+ * Saves the new settings passed in $data
+ *
+ * @param string $data
+ * @return mixed string or Array
+ */
public function write_setting($data) {
global $CFG, $DB;
}
}
+
/**
* Which roles to show on course description page
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_coursecontact extends admin_setting_pickroles {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('coursecontact', get_string('coursecontact', 'admin'),
get_string('coursecontact_desc', 'admin'),
}
}
+
/**
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_gradelimiting extends admin_setting_configcheckbox {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
function admin_setting_special_gradelimiting() {
parent::__construct('unlimitedgrades', get_string('unlimitedgrades', 'grades'),
get_string('unlimitedgrades_help', 'grades'), '0', '1', '0');
}
+
/**
* Primary grade export plugin - has state tracking.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_gradeexport extends admin_setting_configmulticheckbox {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('gradeexport', get_string('gradeexport', 'admin'),
get_string('configgradeexport', 'admin'), array(), NULL);
}
}
+
/**
* Grade category settings
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_gradecat_combo extends admin_setting {
-/** @var array Array of choices */
+ /** @var array Array of choices */
public $choices;
/**
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_grade_profilereport extends admin_setting_configselect {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('grade_profilereport', get_string('profilereport', 'grades'), get_string('profilereport_help', 'grades'), 'user', null);
}
}
}
+
/**
* Special class for register auth selection
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_special_registerauth extends admin_setting_configselect {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
parent::__construct('registerauth', get_string('selfregistration', 'auth'), get_string('selfregistration_help', 'auth'), '', null);
}
}
}
+
/**
* Module manage page
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_page_managemods extends admin_externalpage {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
global $CFG;
parent::__construct('managemodules', get_string('modsettings', 'admin'), "$CFG->wwwroot/$CFG->admin/modules.php");
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_manageenrols extends admin_setting {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
$this->nosave = true;
parent::__construct('enrolsui', get_string('manageenrols', 'enrol'), '', '');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_page_manageblocks extends admin_externalpage {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
global $CFG;
parent::__construct('manageblocks', get_string('blocksettings', 'admin'), "$CFG->wwwroot/$CFG->admin/blocks.php");
}
}
+
/**
* Question type manage page
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_page_manageqtypes extends admin_externalpage {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
global $CFG;
parent::__construct('manageqtypes', get_string('manageqtypes', 'admin'), "$CFG->wwwroot/$CFG->admin/qtypes.php");
}
}
+
class admin_page_manageportfolios extends admin_externalpage {
/**
* Calls parent::__construct with specific arguments
}
}
+
class admin_page_managerepositories extends admin_externalpage {
/**
* Calls parent::__construct with specific arguments
}
}
+
/**
* Special class for authentication administration.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_manageauths extends admin_setting {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
$this->nosave = true;
parent::__construct('authsui', get_string('authsettings', 'admin'), '', '');
}
}
+
/**
* Special class for authentication administration.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_manageeditors extends admin_setting {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
$this->nosave = true;
parent::__construct('editorsui', get_string('editorsettings', 'editor'), '', '');
}
}
+
/**
* Special class for license administration.
*
* @return string Always returns ''
*/
public function write_setting($data) {
- // do not write any setting
+ // do not write any setting
return '';
}
return highlight($query, $return);
}
}
+
+
/**
* Special class for filter administration.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_page_managefilters extends admin_externalpage {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
global $CFG;
parent::__construct('managefilters', get_string('filtersettings', 'admin'), "$CFG->wwwroot/$CFG->admin/filters.php");
}
}
+
/**
* Initialise admin page - this function does require login and permission
* checks specified in page definition.
* @param array $extraurlparams an array paramname => paramvalue, or parameters that need to be
* added to the turn blocks editing on/off form, so this page reloads correctly.
* @param string $actualurl if the actual page being viewed is not the normal one for this
- * page (e.g. admin/roles/allowassin.php, instead of admin/roles/manage.php, you can pass the alternate URL here.
+ * page (e.g. admin/roles/allow.php, instead of admin/roles/manage.php, you can pass the alternate URL here.
* @param array $options Additional options that can be specified for page setup.
* pagelayout - This option can be used to set a specific pagelyaout, admin is default.
*/
/**
* Returns the reference to admin tree root
*
- * @return object admin_roow object
+ * @return object admin_root object
*/
function admin_get_root($reload=false, $requirefulltree=true) {
global $CFG, $DB, $OUTPUT;
return false;
}
-
/**
* Moved from admin/replace.php so that we can use this in cron
*
echo $html;
}
+
/**
* Manage repository settings
*
}
}
+
/**
* Special class for management of external services
*
return highlight($query, $return);
}
}
+
+
/**
* Special class for plagiarism administration.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_manageplagiarism extends admin_setting {
-/**
- * Calls parent::__construct with specific arguments
- */
+ /**
+ * Calls parent::__construct with specific arguments
+ */
public function __construct() {
$this->nosave = true;
parent::__construct('plagiarismui', get_string('plagiarismsettings', 'plagiarism'), '', '');
* @return string Always returns ''
*/
public function write_setting($data) {
- // do not write any setting
+ // do not write any setting
return '';
}
}
}
+
/**
* Special class for overview of external services
*
}
+
/**
* Special class for web service protocol administration.
*
}
}
+
/**
* Colour picker
*
mtrace('checking for create_password');
if ($DB->count_records('user_preferences', array('name'=>'create_password', 'value'=>'1'))) {
mtrace('creating passwords for new users');
- $newusers = $DB->get_records_sql("SELECT u.id as id, u.email, u.firstname,
+ $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.firstname,
u.lastname, u.username,
p.id as prefid
FROM {user} u
JOIN {user_preferences} p ON u.id=p.userid
WHERE p.name='create_password' AND p.value='1' AND u.email !='' ");
- foreach ($newusers as $newuserid => $newuser) {
+ foreach ($newusers as $newuser) {
// email user
if (setnew_password_and_mail($newuser)) {
- // remove user pref
- $DB->delete_records('user_preferences', array('id'=>$newuser->prefid));
+ unset_user_preference('create_password', $newuser);
+ set_user_preference('auth_forcepasswordchange', 1, $newuser);
} else {
trigger_error("Could not create and mail new user password!");
}
}
+ $newusers->close();
}
if (!empty($CFG->usetags)) {
/**
* Given one xmldb_table and one xmldb_field, return the SQL statements needed to alter the field in the table
*/
- public function getAlterFieldSQL($xmldb_table, $xmldb_field) {
+ public function getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL) {
$results = array(); /// To store all the needed SQL commands
* - Changes in null/not null require the SET/DROP NOT NULL clause
* - Changes in default require the SET/DROP DEFAULT clause
*/
- public function getAlterFieldSQL($xmldb_table, $xmldb_field) {
+ public function getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL) {
$results = array(); /// To store all the needed SQL commands
/// Get the normla names of the table and field
/**
* Returns the code (array of statements) needed to execute extra statements on table rename
*/
- public function getRenameTableExtraSQL($xmldb_table) {
+ public function getRenameTableExtraSQL($xmldb_table, $newname) {
return array();
}
if ($allowed_types & SQL_PARAMS_NAMED) {
// Need to verify key names because they can contain, originally,
// spaces and other forbidden chars when using sql_xxx() functions and friends.
- $normkey = trim(preg_replace('/[^a-zA-Z0-9-_]/', '_', $key), '-_');
+ $normkey = trim(preg_replace('/[^a-zA-Z0-9_-]/', '_', $key), '-_');
if ($normkey !== $key) {
debugging('Invalid key found in the conditions array.');
}
if ($limitfrom or $limitnum) {
if ($limitnum >= 1) { // Only apply TOP clause if we have any limitnum (limitfrom offset is handled later)
$fetch = $limitfrom + $limitnum;
+ if (PHP_INT_MAX - $limitnum < $limitfrom) { // Check PHP_INT_MAX overflow
+ $fetch = PHP_INT_MAX;
+ }
$sql = preg_replace('/^([\s(])*SELECT([\s]+(DISTINCT|ALL))?(?!\s*TOP\s*\()/i',
"\\1SELECT\\2 TOP $fetch", $sql);
}
$params = array();
}
+ // convert params to ? types
+ list($select, $params, $type) = $this->fix_sql_params($select, $params);
+
/// Get column metadata
$columns = $this->get_columns($table);
$column = $columns[$newfield];
return $error;
}
+ /**
+ * Prepare the statement for execution
+ * @throws dml_connection_exception
+ * @param string $sql
+ * @return resource
+ */
protected function parse_query($sql) {
$stmt = oci_parse($this->oci, $sql);
if ($stmt == false) {
return $stmt;
}
+ /**
+ * Make sure there are no reserved words in param names...
+ * @param string $sql
+ * @param array $params
+ * @return array ($sql, $params) updated query and parameters
+ */
+ protected function tweak_param_names($sql, array $params) {
+ if (empty($params)) {
+ return array($sql, $params);
+ }
+ $newparams = array();
+ foreach ($params as $name=>$value) {
+ $newparams['o_'.$name] = $value;
+ }
+ $sql = preg_replace('/:([a-z0-9_-]+[$a-z0-9_-])/', ':o_$1', $sql);
+ return array($sql, $newparams);
+ }
+
/**
* Return tables in database WITHOUT current prefix
* @return array of table names in lowercase and without prefix
}
foreach($params as $key => $value) {
// Decouple column name and param name as far as sometimes they aren't the same
- $columnname = $key; // Default columnname (for DB introspecting is key), but...
- if ($key == 'newfieldtoset') { // found case where column and key diverge, handle that
+ if ($key == 'o_newfieldtoset') { // found case where column and key diverge, handle that
$columnname = key($value); // columnname is the key of the array
$params[$key] = $value[$columnname]; // set the proper value in the $params array and
$value = $value[$columnname]; // set the proper value in the $value variable
+ } else {
+ $columnname = preg_replace('/^o_/', '', $key); // Default columnname (for DB introspecting is key), but...
}
// Continue processing
// Now, handle already detected LOBs
throw new coding_exception('moodle_database::execute() Multiple sql statements found or bound parameters not used properly in query!');
}
+ list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$this->bind_params($stmt, $params);
list($rawsql, $params) = $this->get_limit_sql($sql, $params, $limitfrom, $limitnum);
- $this->query_start($sql, $params, SQL_QUERY_SELECT);
+ list($rawsql, $params) = $this->tweak_param_names($rawsql, $params);
+ $this->query_start($rawsql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($rawsql);
$this->bind_params($stmt, $params);
$result = oci_execute($stmt, $this->commit_status);
list($rawsql, $params) = $this->get_limit_sql($sql, $params, $limitfrom, $limitnum);
- $this->query_start($sql, $params, SQL_QUERY_SELECT);
+ list($rawsql, $params) = $this->tweak_param_names($rawsql, $params);
+ $this->query_start($rawsql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($rawsql);
$this->bind_params($stmt, $params);
$result = oci_execute($stmt, $this->commit_status);
public function get_fieldset_sql($sql, array $params=null) {
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
+ list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_SELECT);
$stmt = $this->parse_query($sql);
$this->bind_params($stmt, $params);
$id = null;
+ list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_INSERT);
$stmt = $this->parse_query($sql);
$descriptors = $this->bind_params($stmt, $params, $table);
if ($returning) {
- oci_bind_by_name($stmt, ":oracle_id", $id, 10, SQLT_INT);
+ oci_bind_by_name($stmt, ":o_oracle_id", $id, 10, SQLT_INT); // :o_ prefix added in tweak_param_names()
}
$result = oci_execute($stmt, $this->commit_status);
$this->free_descriptors($descriptors);
$sql = "UPDATE {" . $table . "} SET $sets WHERE id=:id";
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
+ list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$descriptors = $this->bind_params($stmt, $params, $table);
$sql = "UPDATE {" . $table . "} SET $newsql $select";
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
+ list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$descriptors = $this->bind_params($stmt, $params, $table);
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
+ list($sql, $params) = $this->tweak_param_names($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_UPDATE);
$stmt = $this->parse_query($sql);
$this->bind_params($stmt, $params);
if ($limitfrom or $limitnum) {
if ($limitnum < 1) {
$limitnum = "ALL";
+ } else if (PHP_INT_MAX - $limitnum < $limitfrom) {
+ // this is a workaround for weird max int problem
+ $limitnum = "ALL";
}
$sql .= " LIMIT $limitnum OFFSET $limitfrom";
}
if ($limitfrom or $limitnum) {
if ($limitnum < 1) {
$limitnum = "ALL";
+ } else if (PHP_INT_MAX - $limitnum < $limitfrom) {
+ // this is a workaround for weird max int problem
+ $limitnum = "ALL";
}
$sql .= " LIMIT $limitnum OFFSET $limitfrom";
}
class dml_test extends UnitTestCase {
private $tables = array();
+ /** @var moodle_database */
private $tdb;
private $data;
public static $includecoverage = array('lib/dml');
$this->assertEqual($inskey2, end($records)->id);
// test 2 tables with aliases and limits with order bys
- $sql = "SELECT t1.id, t1.course AS cid, t2.nametext FROM {{$tablename}} t1, {{$tablename2}} t2
- WHERE t2.course=t1.course ORDER BY t1.course, ". $DB->sql_compare_text('t2.nametext');
+ $sql = "SELECT t1.id, t1.course AS cid, t2.nametext
+ FROM {{$tablename}} t1, {{$tablename2}} t2
+ WHERE t2.course=t1.course
+ ORDER BY t1.course, ". $DB->sql_compare_text('t2.nametext');
$records = $DB->get_records_sql($sql, null, 2, 2); // Skip courses 3 and 6, get 4 and 5
$this->assertEqual(2, count($records));
$this->assertEqual('5', end($records)->cid);
$this->assertEqual('4', reset($records)->cid);
- // test 2 tables with aliases and limits with order bys (limit which is out of range)
- $records = $DB->get_records_sql($sql, null, 2, 21098765432109876543210); // Skip course {3,6}, get {4,5}
+ // test 2 tables with aliases and limits with the highest INT limit works
+ $records = $DB->get_records_sql($sql, null, 2, PHP_INT_MAX); // Skip course {3,6}, get {4,5}
$this->assertEqual(2, count($records));
$this->assertEqual('5', end($records)->cid);
$this->assertEqual('4', reset($records)->cid);
- // test 2 tables with aliases and limits with order bys (limit which is out of range)
- $records = $DB->get_records_sql($sql, null, 21098765432109876543210, 2); // Skip all courses
+ // test 2 tables with aliases and limits with order bys (limit which is highest INT number)
+ $records = $DB->get_records_sql($sql, null, PHP_INT_MAX, 2); // Skip all courses
$this->assertEqual(0, count($records));
- // test 2 tables with aliases and limits with order bys (limit which is out of range)
- $records = $DB->get_records_sql($sql, null, 21098765432109876543210, 21098765432109876543210); // Skip all courses
+ // test 2 tables with aliases and limits with order bys (limit which s highest INT number)
+ $records = $DB->get_records_sql($sql, null, PHP_INT_MAX, PHP_INT_MAX); // Skip all courses
$this->assertEqual(0, count($records));
// TODO: Test limits in queries having DISTINCT clauses
$this->assertEqual(1, count($records));
}
+ public function test_bound_param_reserved() {
+ $DB = $this->tdb;
+ $dbman = $DB->get_manager();
+
+ $table = $this->get_test_table();
+ $tablename = $table->getName();
+
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+ $dbman->create_table($table);
+
+ $DB->insert_record($tablename, array('course' => '1'));
+
+ // make sure reserved words do not cause fatal problems in query parameters
+
+ $DB->execute("UPDATE {{$tablename}} SET course = 1 WHERE ID = :select", array('select'=>1));
+ $DB->get_records_sql("SELECT * FROM {{$tablename}} WHERE course = :select", array('select'=>1));
+ $rs = $DB->get_recordset_sql("SELECT * FROM {{$tablename}} WHERE course = :select", array('select'=>1));
+ $rs->close();
+ $DB->get_fieldset_sql("SELECT id FROM {{$tablename}} WHERE course = :select", array('select'=>1));
+ $DB->set_field_select($tablename, 'course', '1', "id = :select", array('select'=>1));
+ $DB->delete_records_select($tablename, "id = :select", array('select'=>1));
+ }
+
public function test_limits_and_offsets() {
$DB = $this->tdb;
$dbman = $DB->get_manager();
if ($limitfrom or $limitnum) {
if ($limitnum >= 1) { // Only apply TOP clause if we have any limitnum (limitfrom offset is handled later)
$fetch = $limitfrom + $limitnum;
+ if (PHP_INT_MAX - $limitnum < $limitfrom) { // Check PHP_INT_MAX overflow
+ $fetch = PHP_INT_MAX;
+ }
$sql = preg_replace('/^([\s(])*SELECT([\s]+(DISTINCT|ALL))?(?!\s*TOP\s*\()/i',
"\\1SELECT\\2 TOP $fetch", $sql);
}
$params = array ();
}
+ // convert params to ? types
+ list($select, $params, $type) = $this->fix_sql_params($select, $params);
+
/// Get column metadata
$columns = $this->get_columns($table);
$column = $columns[$newfield];
$inserted = false;
if ($ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
- if ($ue->timestart != $timestart or $ue->timeend != $timeend) {
+ //only update if timestart or timeend or status are different.
+ if ($ue->timestart != $timestart or $ue->timeend != $timeend or (!is_null($status) and $ue->status != $status)) {
$ue->timestart = $timestart;
$ue->timeend = $timeend;
+ if (!is_null($status)) {
+ $ue->status = $status;
+ }
$ue->modifier = $USER->id;
$ue->timemodified = time();
$DB->update_record('user_enrolments', $ue);
} else {
$ue = new stdClass();
$ue->enrolid = $instance->id;
- $ue->status = ENROL_USER_ACTIVE;
+ $ue->status = is_null($status) ? ENROL_USER_ACTIVE : $status;
$ue->userid = $userid;
$ue->timestart = $timestart;
$ue->timeend = $timeend;
* @return string if $text was passed in, the rewritten $text is returned. Otherwise NULL.
*/
function file_save_draft_area_files($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) {
- global $CFG, $USER;
+ global $USER;
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
$fs = get_file_storage();
if (is_null($text)) {
return null;
+ } else {
+ return file_rewrite_urls_to_pluginfile($text, $draftitemid, $forcehttps);
}
+}
+
+/**
+ * Convert the draft file area URLs in some content to @@PLUGINFILE@@ tokens
+ * ready to be saved in the database. Normally, this is done automatically by
+ * {@link file_save_draft_area_files()}.
+ * @param string $text the content to process.
+ * @param int $draftitemid the draft file area the content was using.
+ * @param bool $forcehttps whether the content contains https URLs. Default false.
+ * @return string the processed content.
+ */
+function file_rewrite_urls_to_pluginfile($text, $draftitemid, $forcehttps = false) {
+ global $CFG, $USER;
+
+ $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
$wwwroot = $CFG->wwwroot;
if ($forcehttps) {
$text = str_ireplace("$wwwroot/draftfile.php?file=/$usercontext->id/user/draft/$draftitemid/", '@@PLUGINFILE@@/', $text);
}
-
return $text;
}
$file_records = $DB->get_records('files', $conditions);
foreach ($file_records as $file_record) {
- $stored_file = $this->get_file_instance($file_record);
- $stored_file->delete();
+ $this->get_file_instance($file_record)->delete();
}
return true; // BC only
}
+ /**
+ * Delete all the files from certain areas where itemid is limited by an
+ * arbitrary bit of SQL.
+ *
+ * @param int $contextid the id of the context the files belong to. Must be given.
+ * @param string $component the owning component. Must be given.
+ * @param string $filearea the file area name. Must be given.
+ * @param string $itemidstest an SQL fragment that the itemid must match. Used
+ * in the query like WHERE itemid $itemidstest. Must used named parameters,
+ * and may not used named parameters called contextid, component or filearea.
+ * @param array $params any query params used by $itemidstest.
+ */
+ public function delete_area_files_select($contextid, $component,
+ $filearea, $itemidstest, array $params = null) {
+ global $DB;
+
+ $where = "contextid = :contextid
+ AND component = :component
+ AND filearea = :filearea
+ AND itemid $itemidstest";
+ $params['contextid'] = $contextid;
+ $params['component'] = $component;
+ $params['filearea'] = $filearea;
+
+ $file_records = $DB->get_recordset_select('files', $where, $params);
+ foreach ($file_records as $file_record) {
+ $this->get_file_instance($file_record)->delete();
+ }
+ $file_records->close();
+ }
+
/**
* Move all the files in a file area from one context to another.
* @param integer $oldcontextid the context the files are being moved from.
*
* note: $slashed param removed
*
- * @return object submitted data; NULL if not valid or not submitted
+ * @return object submitted data; NULL if not valid or not submitted or cancelled
*/
function get_data() {
$mform =& $this->_form;
- if ($this->is_submitted() and $this->is_validated()) {
+ if (!$this->is_cancelled() and $this->is_submitted() and $this->is_validated()) {
$data = $mform->exportValues();
unset($data['sesskey']); // we do not need to return sesskey
unset($data['_qf__'.$this->_formname]); // we do not need the submission marker too
*
* @global object
* @param int $groupid The id of the group of advcheckboxes this element controls
- * @param string $buttontext The text of the link. Defaults to "select all/none"
+ * @param string $text The text of the link. Defaults to selectallornone ("select all/none")
* @param array $attributes associative array of HTML attributes
* @param int $originalValue The original general state of the checkboxes before the user first clicks this element
*/
- function add_checkbox_controller($groupid, $buttontext, $attributes, $originalValue = 0) {
+ function add_checkbox_controller($groupid, $text = null, $attributes = null, $originalValue = 0) {
global $CFG;
+
+ // Set the default text if none was specified
if (empty($text)) {
$text = get_string('selectallornone', 'form');
}
public $idnumber;
/**
- * Visible setting (0 or 1; if this is 0, students cannot see/access the activity) - from
+ * Time that this course-module was added (unix time) - from course_modules table
+ * @var int
+ */
+ public $added;
+
+ /**
+ * This variable is not used and is included here only so it can be documented.
+ * Once the database entry is removed from course_modules, it should be deleted
+ * here too.
+ * @var int
+ * @deprecated Do not use this variable
+ */
+ public $score;
+
+ /**
+ * Visible setting (0 or 1; if this is 0, students cannot see/access the activity) - from
* course_modules table
* @var int
*/
public $visible;
+ /**
+ * Old visible setting (if the entire section is hidden, the previous value for
+ * visible is stored in this field) - from course_modules table
+ * @var int
+ */
+ public $visibleold;
+
/**
* Group mode (one of the constants NONE, SEPARATEGROUPS, or VISIBLEGROUPS) - from
* course_modules table
*/
public $completion;
+ /**
+ * Set to the item number (usually 0) if completion depends on a particular
+ * grade of this activity, or null if completion does not depend on a grade - from
+ * course_modules table
+ * @var mixed
+ */
+ public $completiongradeitemnumber;
+
+ /**
+ * 1 if 'on view' completion is enabled, 0 otherwise - from course_modules table
+ * @var int
+ */
+ public $completionview;
+
+ /**
+ * Set to a unix time if completion of this activity is expected at a
+ * particular time, 0 if no time set - from course_modules table
+ * @var int
+ */
+ public $completionexpected;
+
/**
* Available date for this activity (0 if not set, or set to seconds since epoch; before this
* date, activity does not display to students) - from course_modules table
*/
public $modname;
+ /**
+ * ID of module - from course_modules table
+ * @var int
+ */
+ public $module;
+
/**
* Name of module instance for display on page e.g. 'General discussion forum' - from cached
* data in modinfo field
*/
public $sectionnum;
+ /**
+ * Section id - from course_modules table
+ * @var int
+ */
+ public $section;
+
/**
* Availability conditions for this course-module based on the completion of other
* course-modules (array from other course-module id to required completion state for that
$this->idnumber = isset($mod->idnumber) ? $mod->idnumber : '';
$this->name = $mod->name;
$this->visible = $mod->visible;
- $this->sectionnum = $mod->section;
+ $this->sectionnum = $mod->section; // Note weirdness with name here
$this->groupmode = isset($mod->groupmode) ? $mod->groupmode : 0;
$this->groupingid = isset($mod->groupingid) ? $mod->groupingid : 0;
$this->groupmembersonly = isset($mod->groupmembersonly) ? $mod->groupmembersonly : 0;
$this->indent = isset($mod->indent) ? $mod->indent : 0;
- $this->completion = isset($mod->completion) ? $mod->completion : 0;
$this->extra = isset($mod->extra) ? $mod->extra : '';
$this->extraclasses = isset($mod->extraclasses) ? $mod->extraclasses : '';
$this->onclick = isset($mod->onclick) ? $mod->onclick : '';
$this->extra = '';
}
- if (!empty($CFG->enableavailability)) {
- // We must have completion information from modinfo. If it's not
- // there, cache needs rebuilding
- if (!isset($mod->showavailability)) {
- throw new modinfo_rebuild_cache_exception(
- 'enableavailability option was changed; rebuilding '.
- 'cache for course ' . $course->id);
- }
- $this->showavailability = $mod->showavailability;
- $this->availablefrom = isset($mod->availablefrom) ? $mod->availablefrom : 0;
- $this->availableuntil = isset($mod->availableuntil) ? $mod->availableuntil : 0;
- $this->conditionscompletion = isset($mod->conditionscompletion)
- ? $mod->conditionscompletion : array();
- $this->conditionsgrade = isset($mod->conditionsgrade)
- ? $mod->conditionsgrade : array();
- }
+ // Note: These fields from $cm were not present in cm_info in Moodle
+ // 2.0.2 and prior. They may not be available if course cache hasn't
+ // been rebuilt since then.
+ $this->section = isset($mod->sectionid) ? $mod->sectionid : 0;
+ $this->module = isset($mod->module) ? $mod->module : 0;
+ $this->added = isset($mod->added) ? $mod->added : 0;
+ $this->score = isset($mod->score) ? $mod->score : 0;
+ $this->visibleold = isset($mod->visibleold) ? $mod->visibleold : 0;
+
+ // Note: it saves effort and database space to always include the
+ // availability and completion fields, even if availability or completion
+ // are actually disabled
+ $this->completion = isset($mod->completion) ? $mod->completion : 0;
+ $this->completiongradeitemnumber = isset($mod->completiongradeitemnumber)
+ ? $mod->completiongradeitemnumber : null;
+ $this->completionview = isset($mod->completionview)
+ ? $mod->completionview : 0;
+ $this->completionexpected = isset($mod->completionexpected)
+ ? $mod->completionexpected : 0;
+ $this->showavailability = isset($mod->showavailability) ? $mod->showavailability : 0;
+ $this->availablefrom = isset($mod->availablefrom) ? $mod->availablefrom : 0;
+ $this->availableuntil = isset($mod->availableuntil) ? $mod->availableuntil : 0;
+ $this->conditionscompletion = isset($mod->conditionscompletion)
+ ? $mod->conditionscompletion : array();
+ $this->conditionsgrade = isset($mod->conditionsgrade)
+ ? $mod->conditionsgrade : array();
// Get module plural name.
// TODO This was a very old performance hack and should now be removed as the information
}
-/**
- * Special exception that may only be thrown within the constructor for course_modinfo to
- * indicate that the cache needs to be rebuilt. Not for use anywhere else.
- */
-class modinfo_rebuild_cache_exception extends coding_exception {
- function __construct($why) {
- // If it ever escapes, that's a code bug
- parent::__construct('This exception should be caught by code', $why);
- }
-}
-
-
/**
* Returns reference to full info about modules in course (including visibility).
* Cached and as fast as possible (0 or 1 db query).
unset($cache[$course->id]); // prevent potential reference problems when switching users
- try {
- $cache[$course->id] = new course_modinfo($course, $userid);
- } catch (modinfo_rebuild_cache_exception $e) {
- debugging($e->debuginfo);
- rebuild_course_cache($course->id, true);
- $course = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
- // This second time we don't catch the exception - if you request cache rebuild twice
- // in a row, that's a bug => coding_exception
- $cache[$course->id] = new course_modinfo($course, $userid);
- }
+ $cache[$course->id] = new course_modinfo($course, $userid);
// Ensure cache does not use too much RAM
if (count($cache) > MAX_MODINFO_CACHE_SIZE) {
//Participants
if (has_capability('moodle/course:viewparticipants', $this->page->context)) {
- require_once($CFG->dirroot.'/blog/lib.php');
$participants = $coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id='.$course->id), self::TYPE_CONTAINER, get_string('participants'), 'participants');
$currentgroup = groups_get_course_group($course, true);
if ($course->id == SITEID) {
$filterselect = $currentgroup;
}
$filterselect = clean_param($filterselect, PARAM_INT);
- if ($CFG->bloglevel >= 3) {
+ if (($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser())))
+ and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) {
$blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect));
$participants->add(get_string('blogs','blog'), $blogsurls->out());
}
$filterselect = 0;
// Blogs
- if (has_capability('moodle/blog:view', $this->page->context)) {
- require_once($CFG->dirroot.'/blog/lib.php');
- if (blog_is_enabled_for_user()) {
- $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect));
- $coursenode->add(get_string('blogs','blog'), $blogsurls->out());
- }
+ if (!empty($CFG->bloglevel)
+ and ($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser())))
+ and has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) {
+ $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect));
+ $coursenode->add(get_string('blogs','blog'), $blogsurls->out());
}
// Notes
$this->load_section_activities($sections[$course->sectionnumber]->sectionnode, $course->sectionnumber, get_fast_modinfo($course));
break;
case self::TYPE_ACTIVITY :
- $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
+ $sql = "SELECT c.*
+ FROM {course} c
+ JOIN {course_modules} cm ON cm.course = c.id
+ WHERE cm.id = :cmid";
+ $params = array('cmid' => $this->instanceid);
+ $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
$modinfo = get_fast_modinfo($course);
$cm = $modinfo->get_cm($this->instanceid);
require_course_login($course, true, $cm);
$this->page->set_context(get_context_instance(CONTEXT_MODULE, $cm->id));
$coursenode = $this->load_course($course);
- $sections = $this->load_course_sections($course, $coursenode);
- foreach ($sections as $section) {
- if ($section->id == $cm->section) {
- $cm->sectionnumber = $section->section;
- break;
- }
- }
if ($course->id == SITEID) {
$modulenode = $this->load_activity($cm, $course, $coursenode->find($cm->id, self::TYPE_ACTIVITY));
} else {
- $activities = $this->load_section_activities($sections[$cm->sectionnumber]->sectionnode, $cm->sectionnumber, get_fast_modinfo($course));
+ $sections = $this->load_course_sections($course, $coursenode);
+ $activities = $this->load_section_activities($sections[$cm->sectionnum]->sectionnode, $cm->sectionnum, get_fast_modinfo($course));
$modulenode = $this->load_activity($cm, $course, $activities[$cm->id]);
}
break;
// everyone who has a role assignment in this course or higher
$params = array($USER->id, "%$searchtext%");
- $users = $DB->get_records_sql("SELECT $ufields,
- FROM {user} u, mc.id as contactlistid, mc.blocked
+ $users = $DB->get_records_sql("SELECT $ufields, mc.id as contactlistid, mc.blocked
+ FROM {user} u
JOIN {role_assignments} ra ON ra.userid = u.id
LEFT JOIN {message_contacts} mc
ON mc.contactid = u.id AND mc.userid = ?
$userto->viewfullnames = array();
$userto->canpost = array();
$userto->markposts = array();
- $userto->enrolledin = array();
// reset the caches
foreach ($coursemodules as $forumid=>$unused) {
$cm =& $coursemodules[$forum->id];
// Do some checks to see if we can bail out now
+ // Only active enrolled users are in the list of subscribers
if (!isset($subscribedusers[$forum->id][$userto->id])) {
continue; // user does not subscribe to this forum
}
- // Verify user is enrollend in course - if not do not send any email
- if (!isset($userto->enrolledin[$course->id])) {
- $userto->enrolledin[$course->id] = is_enrolled(get_context_instance(CONTEXT_COURSE, $course->id));
- }
- if (!$userto->enrolledin[$course->id]) {
- // oops - this user should not receive anything from this course
- continue;
- }
// Don't send email if the forum is Q&A and the user has not posted
if ($forum->type == 'qanda' && !forum_get_user_posted_time($discussion->id, $userto->id)) {
mtrace('Did not email '.$userto->id.' because user has not posted in discussion');
* @return array list of users.
*/
function forum_get_potential_subscribers($forumcontext, $groupid, $fields, $sort) {
- return get_users_by_capability($forumcontext, 'mod/forum:initialsubscriptions', $fields, $sort, '', '', $groupid, '', false, true);
+ global $DB;
+
+ // only active enrolled users or everybody on the frontpage with this capability
+ list($esql, $params) = get_enrolled_sql($forumcontext, 'mod/forum:initialsubscriptions', $groupid, true);
+
+ $sql = "SELECT $fields
+ FROM {user} u
+ JOIN ($esql) je ON je.id = u.id";
+ if ($sort) {
+ $sql = "$sql ORDER BY $sort";
+ } else {
+ $sql = "$sql ORDER BY u.lastname ASC, u.firstname ASC";
+ }
+
+ return $DB->get_records_sql($sql, $params);
}
/**
*/
function forum_subscribed_users($course, $forum, $groupid=0, $context = null, $fields = null) {
global $CFG, $DB;
- $params = array($forum->id);
-
- if ($groupid) {
- $grouptables = ", {groups_members} gm ";
- $groupselect = "AND gm.groupid = ? AND u.id = gm.userid";
- $params[] = $groupid;
- } else {
- $grouptables = '';
- $groupselect = '';
- }
if (empty($fields)) {
$fields ="u.id,
u.mnethostid";
}
- if (forum_is_forcesubscribed($forum)) {
- if (empty($context)) {
- $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- }
- $sort = "u.email ASC";
- $results = forum_get_potential_subscribers($context, $groupid, $fields, $sort);
- } else {
- $results = $DB->get_records_sql("SELECT $fields
- FROM {user} u,
- {forum_subscriptions} s $grouptables
- WHERE s.forum = ?
- AND s.userid = u.id
- AND u.deleted = 0 $groupselect
- ORDER BY u.email ASC", $params);
+ if (empty($context)) {
+ $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
}
- static $guestid = null;
+ if (forum_is_forcesubscribed($forum)) {
+ $results = forum_get_potential_subscribers($context, $groupid, $fields, "u.email ASC");
- if (is_null($guestid)) {
- if ($guest = guest_user()) {
- $guestid = $guest->id;
- } else {
- $guestid = 0;
- }
+ } else {
+ // only active enrolled users or everybody on the frontpage
+ list($esql, $params) = get_enrolled_sql($context, '', $groupid, true);
+ $params['forumid'] = $forum->id;
+ $results = $DB->get_records_sql("SELECT $fields
+ FROM {user} u
+ JOIN ($esql) je ON je.id = u.id
+ JOIN {forum_subscriptions} s ON s.userid = u.id
+ WHERE s.forum = :forumid
+ ORDER BY u.email ASC", $params);
}
// Guest user should never be subscribed to a forum.
- unset($results[$guestid]);
+ unset($results[$CFG->siteguest]);
return $results;
}
/**
* Generate and return the subscribe or unsubscribe link for a forum.
*
- * @global object
- * @global object
- * @global object
* @param object $forum the forum. Fields used are $forum->id and $forum->forcesubscribe.
* @param object $context the context object for this forum.
* @param array $messages text used for the link in its various states
} else if ($cantaccessagroup) {
return $messages['cantaccessgroup'];
} else {
+ if (!is_enrolled($context, $USER, '', true)) {
+ return get_string('no');
+ }
if (is_null($subscribed_forums)) {
$subscribed = forum_is_subscribed($USER->id, $forum);
} else {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
}
- // normal users with temporary guest access can not post
- if (!is_enrolled($context, $user->id) and !is_viewing($context, $user->id)) {
+ // normal users with temporary guest access can not post, suspended users can not post either
+ if (!is_viewing($context, $user->id) and !is_enrolled($context, $user->id, '', true)) {
return false;
}
if (!is_enrolled($context) and !is_viewing($context)) {
// allow guests and not-logged-in to see the button - they are prompted to log in after clicking the link
// normal users with temporary guest access see this button too, they are asked to enrol instead
+ // do not show the button to users with suspended enrolments here
$canstart = enrol_selfenrol_available($course->id);
}
}
}
// for some actions you need to be enrolled, beiing admin is not enough sometimes here
- $enrolled = is_enrolled($PAGE->cm->context);
+ $enrolled = is_enrolled($PAGE->cm->context, $USER, '', false);
+ $activeenrolled = is_enrolled($PAGE->cm->context, $USER, '', true);
$canmanage = has_capability('mod/forum:managesubscriptions', $PAGE->cm->context);
$subscriptionmode = forum_get_forcesubscribed($forumobject);
- $cansubscribe = ($enrolled && $subscriptionmode != FORUM_FORCESUBSCRIBE && ($subscriptionmode != FORUM_DISALLOWSUBSCRIBE || $canmanage));
+ $cansubscribe = ($activeenrolled && $subscriptionmode != FORUM_FORCESUBSCRIBE && ($subscriptionmode != FORUM_DISALLOWSUBSCRIBE || $canmanage));
if ($canmanage) {
$mode = $forumnode->add(get_string('subscriptionmode', 'forum'), null, navigation_node::TYPE_CONTAINER);
break;
}
- } else if ($enrolled) {
+ } else if ($activeenrolled) {
switch ($subscriptionmode) {
case FORUM_CHOOSESUBSCRIBE : // 0
$forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
}
- if ($enrolled && forum_tp_can_track_forums($forumobject)) {
+ if ($enrolled && forum_tp_can_track_forums($forumobject)) { // keep tracking info for users with suspended enrolments
if ($forumobject->trackingtype != FORUM_TRACKING_OPTIONAL) {
//tracking forced on or off in forum settings so dont provide a link here to change it
//could add unclickable text like for forced subscription but not sure this justifies adding another menu item
public function find_users($search) {
global $DB;
- $availableusers = forum_get_potential_subscribers($this->context, $this->currentgroup, $this->required_fields_sql('u'), 'firstname ASC, lastname ASC');
+ $availableusers = forum_get_potential_subscribers($this->context, $this->currentgroup, $this->required_fields_sql('u'), 'u.firstname ASC, u.lastname ASC');
if (empty($availableusers)) {
$availableusers = array();
public function find_users($search) {
global $DB;
list($wherecondition, $params) = $this->search_sql($search, 'u');
-
- $fields = 'SELECT ' . $this->required_fields_sql('u');
- $from = ' FROM {user} u LEFT JOIN {forum_subscriptions} s ON s.userid=u.id';
- $wherecondition .= ' AND s.forum=:forumid';
$params['forumid'] = $this->forumid;
- $order = ' ORDER BY lastname ASC, firstname ASC';
- if ($this->currentgroup) {
- $from .= ", {groups_members} gm ";
- $wherecondition .= " AND gm.groupid = :groupid AND u.id = gm.userid";
- $params['groupid'] = $this->currentgroup;
- }
- if (!$subscribers = $DB->get_records_sql($fields.$from.' WHERE '.$wherecondition.$order, $params)) {
- $subscribers = array();
- }
+ // only active enrolled or everybody on the frontpage
+ list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true);
+ $params = array_merge($params, $eparams);
+
+ $fields = $this->required_fields_sql('u');
+
+ $subscribers = $DB->get_records_sql("SELECT $fields
+ FROM {user} u
+ JOIN ($esql) je ON je.id = u.id
+ JOIN {forum_subscriptions} s ON s.userid = u.id
+ WHERE $wherecondition AND s.forum = :forumid
+ ORDER BY u.lastname ASC, u.firstname ASC", $params);
return array(get_string("existingsubscribers", 'forum') => $subscribers);
}
require_login($course->id, false, $cm);
-if (is_null($mode) and !is_enrolled($context)) { // Guests and visitors can't subscribe - only enrolled
+if (is_null($mode) and !is_enrolled($context, $USER, '', true)) { // Guests and visitors can't subscribe - only enrolled
$PAGE->set_title($course->shortname);
$PAGE->set_heading($course->fullname);
- echo $OUTPUT->header();
- echo $OUTPUT->confirm(get_string('subscribeenrolledonly', 'forum').'<br /><br />'.get_string('liketologin'),
- get_login_url(), new moodle_url('/mod/forum/view.php', array('f'=>$id)));
- echo $OUTPUT->footer();
- exit;
+ if (isguestuser()) {
+ echo $OUTPUT->header();
+ echo $OUTPUT->confirm(get_string('subscribeenrolledonly', 'forum').'<br /><br />'.get_string('liketologin'),
+ get_login_url(), new moodle_url('/mod/forum/view.php', array('f'=>$id)));
+ echo $OUTPUT->footer();
+ exit;
+ } else {
+ // there should not be any links leading to this place, just redirect
+ redirect(new moodle_url('/mod/forum/view.php', array('f'=>$id)), get_string('subscribeenrolledonly', 'forum'));
+ }
}
$returnto = optional_param('backtoindex',0,PARAM_INT)
$params['gradetype'] = GRADE_TYPE_VALUE;
$params['grademax'] = $lesson->grade;
$params['grademin'] = 0;
+ } else if ($lesson->grade < 0) {
+ $params['gradetype'] = GRADE_TYPE_SCALE;
+ $params['scaleid'] = -$lesson->grade;
} else {
$params['gradetype'] = GRADE_TYPE_NONE;
}
if (!is_array($grade)) {
$grades[$key] = $grade = (array) $grade;
}
- $grades[$key]['rawgrade'] = ($grade['rawgrade'] * $lesson->grade / 100);
+ //check raw grade isnt null otherwise we erroneously insert a grade of 0
+ if ($grade['rawgrade'] !== null) {
+ $grades[$key]['rawgrade'] = ($grade['rawgrade'] * $lesson->grade / 100);
+ } else {
+ //setting rawgrade to null just in case user is deleting a grade
+ $grades[$key]['rawgrade'] = null;
+ }
}
}
#page-mod-quiz-view #page .quizgradefeedback,
#page-mod-quiz-view #page .quizattempt {text-align: center;}
#page-mod-quiz-view #page .quizattemptsummary td p {margin-top: 0;}
+#page-mod-quiz-view .generaltable.quizattemptsummary {margin-left:auto;margin-right:auto;}
#page-mod-quiz-view .generalbox#feedback {width:70%;margin-left:auto;margin-right:auto;padding-bottom:15px;}
#page-mod-quiz-view .generalbox#feedback h2 {margin: 0;}
#page-mod-quiz-view .generalbox#feedback h3 {text-align: left;}
}
var content = safeGetElement(document, 'scormpage');
content.insertBefore(logButton, content.firstChild);
-AppendToLog("Moodle SCORM 1.2 API Loaded, Activity: <?php echo $scorm->name; ?>, SCO: <?php echo $sco->identifier; ?>", 0);
// pull in the debugging utilities
if (scorm_debugging($scorm)) {
include_once($CFG->dirroot.'/mod/scorm/datamodels/debug.js.php');
+ echo 'AppendToLog("Moodle SCORM 1.2 API Loaded, Activity: '.$scorm->name.', SCO: '.$sco->identifier.'", 0);';
}
?>
}
if ($play) {
- // it is possible that scoid is still not set, in this case we dont want an empty object
+ // it is possible that $scoid is still not set, in this case we don't want an empty object
if ($scoid) {
$sco = scorm_get_sco($scoid);
}
// pull in the debugging utilities
if (scorm_debugging($scorm)) {
include_once($CFG->dirroot.'/mod/scorm/datamodels/debug.js.php');
+ echo 'AppendToLog("Moodle SCORM 1.3 API Loaded, Activity: '.$scorm->name.', SCO: '.$sco->identifier.'", 0);';
}
?>
}
if ($play) {
- $sco = $DB->get_record('scorm_scoes', array('id'=>$scoid));
+ // it is possible that $scoid is still not set, in this case we don't want an empty object
+ if ($scoid) {
+ $sco = scorm_get_sco($scoid);
+ }
$sco->previd = $previd;
$sco->nextid = $nextid;
$result->sco = $sco;
if ($cancelsure) {
$exporter->cancel_request($logreturn);
} else {
+ portfolio_export_pagesetup($PAGE, $exporter->get('caller'));
$exporter->print_header(get_string('confirmcancel', 'portfolio'));
echo $OUTPUT->box_start();
$yesbutton = new single_button(new moodle_url('/portfolio/add.php', array('id' => $dataid, 'cancel' => 1, 'cancelsure' => 1, 'logreturn' => $logreturn)), get_string('yes'));
var dlg_title = document.createElement('DIV');
dlg_title.className = 'hd';
- dlg_title.innerHTML = 'filepicker';
+ dlg_title.innerHTML = M.str.repository.search;
var dlg_body = document.createElement('DIV');
dlg_body.className = 'bd';
}, true);
search_dialog.cancel();
}
+ Y.one('#fp-search-form').on('keydown', function(e){
+ if (e.keyCode == 13) {
+ dialog_handler();
+ e.preventDefault();
+ }
+ }, this);
search_dialog = new YAHOO.widget.Dialog("fp-search-dlg", {
postmethod: 'async',
draggable: true,
width : "30em",
+ modal: true,
fixedcenter : true,
zindex: 9999991,
visible : false,
.mod-indent-huge {margin-left:300px;}
/* Resourcelib mp3 player size: only width could be changed here, height hardcoded in JS */
-.resourcecontent .resourcemediaplugin_mp3 object {height:25px; width: 600px}
\ No newline at end of file
+.resourcecontent .resourcemediaplugin_mp3 object {height:25px; width: 600px}
+
+/*
+Fix for SubScript & SuperScript
+------------------------------*/
+sub { vertical-align: sub;}
+sup { vertical-align: super;}
// we are looking for all users with this role assigned in this context or higher
$contextlist = get_related_contexts_string($context);
- list($esql, $params) = get_enrolled_sql($context, NULL, $currentgroup);
+ list($esql, $params) = get_enrolled_sql($context, NULL, $currentgroup, true);
$joins = array("FROM {user} u");
$wheres = array();
handle_keyup : function(e) {
// Trigger an ajax search after a delay.
this.cancel_timeout();
- this.timeoutid = setTimeout(function(obj){obj.send_query(false)}, this.querydelay*1000, this);
+ this.timeoutid = Y.later(this.querydelay*1000, e, function(obj){obj.send_query(false)}, this);
// Enable or diable the clear button.
this.clearbutton.set('disabled', (this.get_search_text() == ''));
defined('MOODLE_INTERNAL') || die();
-$version = 2011031600.00; // YYYYMMDD = date of the last version bump
+$version = 2011032100.00; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0.2+ (Build: 20110316)'; // Human-friendly version name