Merge branch 'MDL-25621' of git://github.com/samhemelryk/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 21 Mar 2011 20:32:50 +0000 (21:32 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 21 Mar 2011 20:32:50 +0000 (21:32 +0100)
60 files changed:
admin/blocks.php
admin/bloglevelupgrade.php
admin/cli/install.php
admin/settings/appearance.php
admin/settings/plugins.php
admin/settings/server.php
admin/settings/subsystems.php
admin/uploaduser_form.php
blocks/blog_menu/block_blog_menu.php
blocks/blog_recent/block_blog_recent.php
blocks/blog_tags/block_blog_tags.php
blocks/blog_tags/edit_form.php
blocks/navigation/block_navigation.php
blocks/navigation/styles.css
blocks/navigation/yui/navigation/navigation.js
blog/index.php
blog/lib.php
course/lib.php
enrol/otherusers.php
enrol/renderer.php
enrol/self/lib.php
enrol/users.php
filter/algebra/filter.php
filter/mediaplugin/filter.php
index.php
lang/en/admin.php
lang/en/moodle.php
lib/adminlib.php
lib/cronlib.php
lib/ddl/mssql_sql_generator.php
lib/ddl/postgres_sql_generator.php
lib/ddl/sql_generator.php
lib/dml/moodle_database.php
lib/dml/mssql_native_moodle_database.php
lib/dml/oci_native_moodle_database.php
lib/dml/pgsql_native_moodle_database.php
lib/dml/simpletest/testdml.php
lib/dml/sqlsrv_native_moodle_database.php
lib/enrollib.php
lib/filelib.php
lib/filestorage/file_storage.php
lib/formslib.php
lib/modinfolib.php
lib/navigationlib.php
message/lib.php
mod/forum/lib.php
mod/forum/subscribe.php
mod/lesson/lib.php
mod/quiz/styles.css
mod/scorm/datamodels/debug.js.php
mod/scorm/datamodels/scorm_12.js.php
mod/scorm/datamodels/scorm_12lib.php
mod/scorm/datamodels/scorm_13.js.php
mod/scorm/datamodels/scorm_13lib.php
portfolio/add.php
repository/filepicker.js
theme/base/style/core.css
user/index.php
user/selector/module.js
version.php

index 6b57e67..17b0350 100644 (file)
 
         $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>';
index 1edc0b1..0c069c1 100644 (file)
@@ -90,7 +90,7 @@ function bloglevelupgrade_entries($blogentries, $forum, $cm, $groupid=-1) {
         $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;
index 0acea3d..fc643b5 100644 (file)
@@ -415,7 +415,7 @@ if (isset($maturity)) {
             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')) {
index 125ea4c..2808163 100644 (file)
@@ -63,10 +63,10 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
     // 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),
@@ -130,7 +130,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
 
     // 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));
index 825673c..af1266e 100644 (file)
@@ -367,7 +367,7 @@ if ($hassiteconfig) {
     }
     $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')));
@@ -385,6 +385,8 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext))
         }
     }
 }
+
+// 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'));
@@ -397,8 +399,31 @@ if ($hassiteconfig && !empty($CFG->enableplagiarism)) {
     }
 }
 $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)) {
index 7f6647f..807bf75 100644 (file)
@@ -227,6 +227,8 @@ $ADMIN->add('server', new admin_externalpage('phpinfo', get_string('phpinfo'), "
 // "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
index c7735e6..49ca205 100644 (file)
@@ -37,9 +37,10 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
     $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));
 }
index fe53116..af0dd74 100644 (file)
@@ -231,7 +231,7 @@ class admin_uploaduser_form2 extends moodleform {
         $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);
 
index b431a39..9b237ec 100644 (file)
@@ -1,5 +1,4 @@
 <?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
@@ -56,27 +51,37 @@ class block_blog_menu extends block_base {
     }
 
     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
@@ -92,9 +97,7 @@ class block_blog_menu extends block_base {
         // 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'));
index 478b458..20313b6 100644 (file)
@@ -1,5 +1,4 @@
 <?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
@@ -48,22 +45,36 @@ class block_blog_recent extends block_base {
     }
 
     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();
index a5d8250..c3fa8d8 100644 (file)
@@ -1,12 +1,33 @@
 <?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() {
@@ -42,29 +63,47 @@ class block_blog_tags extends block_base {
     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 = '';
 
@@ -129,7 +168,7 @@ class block_blog_tags extends block_base {
 
         /// 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.
@@ -163,7 +202,7 @@ class block_blog_tags extends block_base {
     }
 }
 
-function blog_tags_sort($a, $b) {
+function block_blog_tags_sort($a, $b) {
     global $CFG;
 
     if (empty($CFG->tagsort)) {
@@ -175,7 +214,7 @@ function blog_tags_sort($a, $b) {
     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;
     }
index 7dd134e..1571066 100644 (file)
@@ -43,7 +43,7 @@ class block_blog_tags_edit_form extends block_edit_form {
             $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),
@@ -55,13 +55,13 @@ class block_blog_tags_edit_form extends block_edit_form {
             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);
     }
 }
index 71ad007..77cc00a 100644 (file)
@@ -118,6 +118,7 @@ class block_navigation extends block_base {
             '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));
     }
 
index 8e204dd..63763eb 100644 (file)
@@ -3,6 +3,8 @@
 .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;}
index f2522d8..1dfb76a 100644 (file)
@@ -310,11 +310,18 @@ BRANCH.prototype = {
         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;
             }
@@ -345,16 +352,23 @@ BRANCH.prototype = {
                 }
             }
             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, {
index 7827e4c..2ba9884 100644 (file)
@@ -34,6 +34,10 @@ foreach ($url_params as $var => $val) {
 }
 $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%"))) {
@@ -52,11 +56,32 @@ if (!empty($groupid) && empty($courseid)) {
     $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) {
@@ -83,9 +108,6 @@ if ((empty($courseid) ? true : $courseid == SITEID) && empty($userid)) {
     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');
     }
index 1137e8e..e4ac277 100644 (file)
@@ -398,12 +398,14 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
         }
 
         // 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
index 3fd1438..889dd45 100644 (file)
@@ -1082,20 +1082,32 @@ function get_array_of_activities($courseid) {
                    $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;
                    }
@@ -1152,13 +1164,19 @@ function get_array_of_activities($courseid) {
                    // '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);
+                   }
                }
             }
         }
index 9bbcee9..f7ffc36 100644 (file)
@@ -42,12 +42,11 @@ if ($course->id == SITEID) {
     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
@@ -82,11 +81,11 @@ $table->set_fields($fields, $OUTPUT);
 
 $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());
index 5235c63..d7a9cb4 100644 (file)
@@ -40,14 +40,14 @@ class core_enrol_renderer extends plugin_renderer_base {
      */
     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);
         }
@@ -55,11 +55,11 @@ class core_enrol_renderer extends plugin_renderer_base {
         $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);
         }
@@ -74,10 +74,10 @@ class core_enrol_renderer extends plugin_renderer_base {
      */
     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);
         }
@@ -85,7 +85,7 @@ class core_enrol_renderer extends plugin_renderer_base {
         $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);
         }
@@ -287,9 +287,9 @@ class course_enrolment_table extends html_table implements renderable {
 
     /**
      * 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
@@ -345,14 +345,14 @@ class course_enrolment_table extends html_table implements renderable {
      *
      * @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');
@@ -396,7 +396,7 @@ class course_enrolment_table extends html_table implements renderable {
         $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)) {
@@ -450,7 +450,7 @@ class course_enrolment_table extends html_table implements renderable {
      * Sets the users for this table
      *
      * @param array $users
-     * @param moodle_page $page
+     * @return void
      */
     public function set_users(array $users) {
         $this->users = $users;
@@ -483,9 +483,9 @@ class course_enrolment_table extends html_table implements renderable {
         }
     }
 
-    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',
@@ -499,7 +499,7 @@ class course_enrolment_table extends html_table implements renderable {
                 '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));
         }
     }
 
@@ -510,7 +510,7 @@ class course_enrolment_table extends html_table implements renderable {
      */
     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;
     }
@@ -568,10 +568,9 @@ class course_enrolment_users_table extends course_enrolment_table {
      * 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
@@ -590,11 +589,10 @@ class course_enrolment_users_table extends course_enrolment_table {
         $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
@@ -614,9 +612,9 @@ class course_enrolment_users_table extends course_enrolment_table {
             $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;
     }
@@ -627,7 +625,7 @@ class course_enrolment_users_table extends course_enrolment_table {
      *
      * @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();
@@ -662,7 +660,6 @@ class course_enrolment_users_table extends course_enrolment_table {
                 $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);
@@ -674,7 +671,7 @@ class course_enrolment_users_table extends course_enrolment_table {
 
             if ($count == 1) {
                 $instance = reset($manuals);
-                $page->requires->strings_for_js(array(
+                $this->moodlepage->requires->strings_for_js(array(
                     'ajaxoneuserfound',
                     'ajaxxusersfound',
                     'ajaxnext25',
@@ -689,8 +686,8 @@ class course_enrolment_users_table extends course_enrolment_table {
                     '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';
@@ -698,10 +695,10 @@ class course_enrolment_users_table extends course_enrolment_table {
                     '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;
         }
@@ -713,8 +710,7 @@ class course_enrolment_users_table extends course_enrolment_table {
      * @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;
     }
@@ -736,10 +732,10 @@ class course_enrolment_other_users_table extends course_enrolment_table {
      * 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');
     }
 
@@ -750,18 +746,17 @@ class course_enrolment_other_users_table extends course_enrolment_table {
      * @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',
@@ -776,16 +771,15 @@ class course_enrolment_other_users_table extends course_enrolment_table {
                     '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;
     }
index 99f4779..6a5f38a 100644 (file)
@@ -209,12 +209,12 @@ class enrol_self_plugin extends enrol_plugin {
                 $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) {
index 16e114b..f206e5c 100644 (file)
@@ -33,8 +33,6 @@ $id      = required_param('id', PARAM_INT); // course id
 $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);
 
@@ -47,8 +45,8 @@ require_capability('moodle/course:enrolreview', $context);
 $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) {
@@ -71,13 +69,13 @@ 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;
             }
@@ -90,15 +88,15 @@ if ($action) {
                 $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;
             }
@@ -111,10 +109,10 @@ if ($action) {
             $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');
                 }
@@ -130,16 +128,16 @@ if ($action) {
                 $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;
             }
@@ -153,10 +151,10 @@ if ($action) {
                 $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');
                 }
@@ -172,10 +170,10 @@ if ($action) {
             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);
                 }
@@ -220,12 +218,12 @@ $fields = array(
 $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);
index a6fc6a2..54ffaff 100644 (file)
@@ -219,6 +219,7 @@ class filter_algebra extends moodle_text_filter {
                   $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;
index dfc9239..d946cbe 100644 (file)
@@ -84,21 +84,21 @@ class filter_mediaplugin extends moodle_text_filter {
         // 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);
         }
 
@@ -124,7 +124,7 @@ class filter_mediaplugin extends moodle_text_filter {
         }
 
         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);
         }
 
@@ -137,13 +137,13 @@ class filter_mediaplugin extends moodle_text_filter {
         // 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);
         }
 
@@ -186,12 +186,12 @@ function filter_mediaplugin_parse_alternatives($url, $defaultwidth = 0, $default
     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);
@@ -663,14 +663,14 @@ function filter_mediaplugin_youtube_callback($link) {
     $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
@@ -712,15 +712,15 @@ function filter_mediaplugin_youtube_playlist_callback($link) {
     $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
 
@@ -751,13 +751,13 @@ function filter_mediaplugin_vimeo_callback($link) {
     }
 
     $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">
index 8aa5b3a..7c3472d 100644 (file)
--- a/index.php
+++ b/index.php
                 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;
index 178c85c..915cb7a 100644 (file)
@@ -764,6 +764,8 @@ $string['numberofmissingstrings'] = 'Number of missing strings: {$a}';
 $string['numberofstrings'] = 'Total number of strings: {$a->strings}<br />Missing: {$a->missing} ({$a->missingpercent}&nbsp;%)';
 $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';
index 1958e41..faa6d9c 100644 (file)
@@ -980,6 +980,7 @@ $string['maximumupload'] = 'Maximum upload size';
 $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.';
index f249aa3..ffbd3d2 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -172,7 +171,7 @@ function uninstall_plugin($type, $name) {
     }
 
     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');
@@ -470,11 +469,11 @@ function set_cron_lock($name, $until, $ignorecurrent=false) {
     }
 
     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;
         }
     }
@@ -631,6 +630,7 @@ function is_dataroot_insecure($fetchtest=false) {
 
 /// CLASS DEFINITIONS /////////////////////////////////////////////////////////
 
+
 /**
  * Interface for anything appearing in the admin tree
  *
@@ -702,6 +702,7 @@ interface part_of_admin_tree {
     public function show_save();
 }
 
+
 /**
  * Interface implemented by any part_of_admin_tree that has children.
  *
@@ -730,6 +731,7 @@ interface parentable_part_of_admin_tree extends part_of_admin_tree {
 
 }
 
+
 /**
  * The object used to represent folders (a.k.a. categories) in the admin tree block.
  *
@@ -882,7 +884,7 @@ class admin_category implements parentable_part_of_admin_tree {
             $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;
@@ -890,7 +892,7 @@ class admin_category implements parentable_part_of_admin_tree {
                         // 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;
@@ -945,6 +947,7 @@ class admin_category implements parentable_part_of_admin_tree {
     }
 }
 
+
 /**
  * Root of admin settings tree, does not have any parent.
  *
@@ -1006,6 +1009,7 @@ class admin_root extends admin_category {
     }
 }
 
+
 /**
  * Links external PHP pages into the admin tree.
  *
@@ -1015,7 +1019,7 @@ class admin_root extends admin_category {
  */
 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(). */
@@ -1035,6 +1039,8 @@ class admin_externalpage implements part_of_admin_tree {
 
     /** @var mixed either string or array of string */
     public $path;
+
+    /** @var array list of visible names of page parents */
     public $visiblepath;
 
     /**
@@ -1150,6 +1156,7 @@ class admin_externalpage implements part_of_admin_tree {
     }
 }
 
+
 /**
  * Used to group a number of admin_setting objects into a page and add them to the admin tree.
  *
@@ -1157,7 +1164,7 @@ class admin_externalpage implements part_of_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(). */
@@ -1177,6 +1184,8 @@ class admin_settingpage implements part_of_admin_tree {
 
     /** @var mixed string of paths or array of strings of paths */
     public $path;
+
+    /** @var array list of visible names of page parents */
     public $visiblepath;
 
     /**
@@ -1359,7 +1368,7 @@ class admin_settingpage implements part_of_admin_tree {
  * @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;
@@ -1373,6 +1382,8 @@ abstract class admin_setting {
     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
@@ -1434,10 +1445,18 @@ abstract class admin_setting {
         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;
@@ -1480,6 +1499,12 @@ abstract class admin_setting {
         // 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
@@ -1540,6 +1565,7 @@ abstract class admin_setting {
     /**
      * 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;
@@ -1581,18 +1607,20 @@ abstract class admin_setting {
     }
 }
 
+
 /**
  * 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, '');
@@ -1640,6 +1668,7 @@ class admin_setting_heading extends admin_setting {
     }
 }
 
+
 /**
  * The most flexibly setting, user is typing text
  *
@@ -1647,7 +1676,7 @@ class admin_setting_heading extends admin_setting {
  */
 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;
@@ -1734,6 +1763,7 @@ class admin_setting_configtext extends admin_setting {
     }
 }
 
+
 /**
  * General text area without html editor.
  *
@@ -1757,6 +1787,7 @@ class admin_setting_configtextarea extends admin_setting_configtext {
         $this->cols = $cols;
         parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype);
     }
+
     /**
      * Returns an XHTML string for the editor
      *
@@ -1778,6 +1809,7 @@ class admin_setting_configtextarea extends admin_setting_configtext {
     }
 }
 
+
 /**
  * General text area with html editor.
  */
@@ -1798,6 +1830,7 @@ class admin_setting_confightmleditor extends admin_setting_configtext {
         parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype);
         editors_head_setup();
     }
+
     /**
      * Returns an XHTML string for the editor
      *
@@ -1822,19 +1855,20 @@ class admin_setting_confightmleditor extends admin_setting_configtext {
     }
 }
 
+
 /**
  * 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);
     }
@@ -1887,19 +1921,20 @@ if (is_ie) {
     }
 }
 
+
 /**
  * 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);
     }
@@ -1933,6 +1968,7 @@ class admin_setting_configfile extends admin_setting_configtext {
     }
 }
 
+
 /**
  * Path to executable file
  *
@@ -1940,13 +1976,13 @@ class admin_setting_configfile extends admin_setting_configtext {
  */
 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();
 
@@ -1966,6 +2002,7 @@ class admin_setting_configexecutable extends admin_setting_configfile {
     }
 }
 
+
 /**
  * Path to directory
  *
@@ -1973,13 +2010,13 @@ class admin_setting_configexecutable extends admin_setting_configfile {
  */
 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();
 
@@ -1999,13 +2036,14 @@ class admin_setting_configdirectory extends admin_setting_configfile {
     }
 }
 
+
 /**
  * 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;
@@ -2085,13 +2123,14 @@ class admin_setting_configcheckbox extends admin_setting {
     }
 }
 
+
 /**
  * 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;
 
     /**
@@ -2256,6 +2295,7 @@ class admin_setting_configmulticheckbox extends admin_setting {
     }
 }
 
+
 /**
  * Multiple checkboxes 2, value stored as string 00101011
  *
@@ -2263,11 +2303,11 @@ class admin_setting_configmulticheckbox extends admin_setting {
  */
 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)) {
@@ -2313,13 +2353,14 @@ class admin_setting_configmulticheckbox2 extends admin_setting_configmulticheckb
     }
 }
 
+
 /**
  * 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;
 
     /**
@@ -2472,20 +2513,21 @@ class admin_setting_configselect extends admin_setting {
     }
 }
 
+
 /**
  * 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);
     }
@@ -2512,7 +2554,6 @@ class admin_setting_configmultiselect extends admin_setting_configselect {
      * 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) {
@@ -2619,7 +2660,7 @@ class admin_setting_configmultiselect extends admin_setting_configselect {
  * @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;
 
     /**
@@ -2696,6 +2737,7 @@ class admin_setting_configtime extends admin_setting {
 
 }
 
+
 /**
  * Used to validate a textarea used for ip addresses
  *
@@ -2703,15 +2745,15 @@ class admin_setting_configtime extends admin_setting {
  */
 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);
@@ -2721,7 +2763,7 @@ class admin_setting_configiplist extends admin_setting_configtextarea {
         $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;
@@ -2738,6 +2780,7 @@ class admin_setting_configiplist extends admin_setting_configtextarea {
     }
 }
 
+
 /**
  * An admin setting for selecting one or more users who have a capability
  * in the system context
@@ -2855,20 +2898,21 @@ class admin_setting_users_with_capability extends admin_setting_configmultiselec
     }
 }
 
+
 /**
  * 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');
@@ -2893,11 +2937,11 @@ class admin_setting_special_adminseesall extends admin_setting_configcheckbox {
  * @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);
@@ -2919,22 +2963,24 @@ class admin_setting_special_selectsetup extends admin_setting_configselect {
     }
 }
 
+
 /**
  * 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
      *
@@ -2957,6 +3003,7 @@ class admin_setting_sitesetselect extends admin_setting_configselect {
     }
 }
 
+
 /**
  * Select for blog's bloglevel setting: if set to 0, will set blog_menu
  * block to hidden.
@@ -2971,23 +3018,33 @@ class admin_setting_bloglevel extends admin_setting_configselect {
      * @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;
 
     /**
@@ -3025,6 +3082,7 @@ class admin_setting_courselist_frontpage extends admin_setting {
         }
         return true;
     }
+
     /**
      * Returns the selected settings
      *
@@ -3098,17 +3156,18 @@ class admin_setting_courselist_frontpage extends admin_setting {
     }
 }
 
+
 /**
  * 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};
@@ -3139,11 +3198,11 @@ class admin_setting_sitesetcheckbox extends admin_setting_configcheckbox {
  * @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;
@@ -3191,15 +3250,16 @@ class admin_setting_sitesettext extends admin_setting_configtext {
     }
 }
 
+
 /**
  * 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();
@@ -3247,6 +3307,7 @@ class admin_setting_special_frontpagedesc extends admin_setting {
     }
 }
 
+
 /**
  * Administration interface for emoticon_manager settings.
  *
@@ -3254,9 +3315,9 @@ class admin_setting_special_frontpagedesc extends admin_setting {
  */
 class admin_setting_emoticons extends admin_setting {
 
-/**
- * Calls parent::__construct with specific args
- */
+    /**
    * Calls parent::__construct with specific args
    */
     public function __construct() {
         global $CFG;
 
@@ -3465,15 +3526,16 @@ class admin_setting_emoticons extends admin_setting {
     }
 }
 
+
 /**
  * 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);
     }
@@ -3491,6 +3553,7 @@ class admin_setting_langlist extends admin_setting_configtext {
     }
 }
 
+
 /**
  * Selection of one of the recognised countries using the list
  * returned by {@link get_list_of_countries()}.
@@ -3519,15 +3582,16 @@ class admin_settings_country_select extends admin_setting_configselect {
     }
 }
 
+
 /**
  * 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);
     }
@@ -3548,19 +3612,21 @@ class admin_settings_coursecat_select extends admin_setting_configselect {
     }
 }
 
+
 /**
  * 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
      *
@@ -3579,15 +3645,16 @@ class admin_setting_special_backupdays extends admin_setting_configmulticheckbox
     }
 }
 
+
 /**
  * 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);
     }
@@ -3610,15 +3677,16 @@ class admin_setting_special_debug extends admin_setting_configselect {
     }
 }
 
+
 /**
  * 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');
@@ -3626,6 +3694,7 @@ class admin_setting_special_calendar_weekend extends admin_setting {
         $default = array ('0', '6'); // Saturdays and Sundays
         parent::__construct($name, $visiblename, $description, $default);
     }
+
     /**
      * Gets the current settings as an array
      *
@@ -3699,7 +3768,7 @@ class admin_setting_special_calendar_weekend extends admin_setting {
  * @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;
 
     /**
@@ -3737,6 +3806,7 @@ class admin_setting_pickroles extends admin_setting_configmulticheckbox {
             return false;
         }
     }
+
     /**
      * Return the default setting for this control
      *
@@ -3760,21 +3830,22 @@ class admin_setting_pickroles extends admin_setting_configmulticheckbox {
     }
 }
 
+
 /**
  * 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);
     }
@@ -3846,6 +3917,7 @@ class admin_setting_configtext_with_advanced extends admin_setting_configtext {
     }
 }
 
+
 /**
  * Checkbox with an advanced checkbox that controls an additional $name.'_adv' config setting.
  *
@@ -3854,15 +3926,15 @@ class admin_setting_configtext_with_advanced extends admin_setting_configtext {
  */
 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);
     }
@@ -3950,6 +4022,7 @@ EOT;
     }
 }
 
+
 /**
  * Checkbox with an advanced checkbox that controls an additional $name.'_locked' config setting.
  *
@@ -4051,15 +4124,16 @@ class admin_setting_configcheckbox_with_lock extends admin_setting_configcheckbo
     }
 }
 
+
 /**
  * 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);
     }
@@ -4136,15 +4210,16 @@ class admin_setting_configselect_with_advanced extends admin_setting_configselec
     }
 }
 
+
 /**
  * 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'),
@@ -4152,17 +4227,18 @@ class admin_setting_special_gradebookroles extends admin_setting_pickroles {
     }
 }
 
+
 /**
  *
  * @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;
 
@@ -4179,15 +4255,16 @@ class admin_setting_regradingcheckbox extends admin_setting_configcheckbox {
     }
 }
 
+
 /**
  * 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'),
@@ -4195,14 +4272,15 @@ class admin_setting_special_coursecontact extends admin_setting_pickroles {
     }
 }
 
+
 /**
  *
  * @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');
@@ -4240,15 +4318,16 @@ class admin_setting_special_gradelimiting extends admin_setting_configcheckbox {
 
 }
 
+
 /**
  * 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);
@@ -4274,13 +4353,14 @@ class admin_setting_special_gradeexport extends admin_setting_configmulticheckbo
     }
 }
 
+
 /**
  * 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;
 
     /**
@@ -4413,9 +4493,9 @@ class admin_setting_gradecat_combo extends admin_setting {
  * @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);
     }
@@ -4447,15 +4527,16 @@ class admin_setting_grade_profilereport extends admin_setting_configselect {
     }
 }
 
+
 /**
  * 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);
     }
@@ -4504,15 +4585,16 @@ class admin_setting_special_registerauth extends admin_setting_configselect {
     }
 }
 
+
 /**
  * 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");
@@ -4567,9 +4649,9 @@ class admin_page_managemods extends admin_externalpage {
  * @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'), '', '');
@@ -4763,9 +4845,9 @@ class admin_setting_manageenrols extends admin_setting {
  * @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");
@@ -4812,15 +4894,16 @@ class admin_page_manageblocks extends admin_externalpage {
     }
 }
 
+
 /**
  * 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");
@@ -4859,6 +4942,7 @@ class admin_page_manageqtypes extends admin_externalpage {
     }
 }
 
+
 class admin_page_manageportfolios extends admin_externalpage {
     /**
      * Calls parent::__construct with specific arguments
@@ -4910,6 +4994,7 @@ class admin_page_manageportfolios extends admin_externalpage {
     }
 }
 
+
 class admin_page_managerepositories extends admin_externalpage {
     /**
      * Calls parent::__construct with specific arguments
@@ -4961,15 +5046,16 @@ class admin_page_managerepositories extends admin_externalpage {
     }
 }
 
+
 /**
  * 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'), '', '');
@@ -5163,15 +5249,16 @@ class admin_setting_manageauths extends admin_setting {
     }
 }
 
+
 /**
  * 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'), '', '');
@@ -5329,6 +5416,7 @@ class admin_setting_manageeditors extends admin_setting {
     }
 }
 
+
 /**
  * Special class for license administration.
  *
@@ -5367,7 +5455,7 @@ class admin_setting_managelicenses extends admin_setting {
      * @return string Always returns ''
      */
     public function write_setting($data) {
-    // do not write any setting
+        // do not write any setting
         return '';
     }
 
@@ -5422,15 +5510,17 @@ class admin_setting_managelicenses extends admin_setting {
         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");
@@ -5474,6 +5564,7 @@ class admin_page_managefilters extends admin_externalpage {
     }
 }
 
+
 /**
  * Initialise admin page - this function does require login and permission
  * checks specified in page definition.
@@ -5487,7 +5578,7 @@ class admin_page_managefilters extends admin_externalpage {
  * @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.
  */
@@ -5583,7 +5674,7 @@ function admin_externalpage_setup($section, $extrabutton = '', array $extraurlpa
 /**
  * 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;
@@ -5958,7 +6049,6 @@ function any_new_admin_settings($node) {
     return false;
 }
 
-
 /**
  * Moved from admin/replace.php so that we can use this in cron
  *
@@ -6213,6 +6303,7 @@ function print_plugin_tables() {
     echo $html;
 }
 
+
 /**
  * Manage repository settings
  *
@@ -6463,6 +6554,7 @@ class admin_setting_managerepository extends admin_setting {
     }
 }
 
+
 /**
  * Special class for management of external services
  *
@@ -6645,15 +6737,17 @@ class admin_setting_manageexternalservices extends admin_setting {
         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'), '', '');
@@ -6683,7 +6777,7 @@ class admin_setting_manageplagiarism extends admin_setting {
      * @return string Always returns ''
      */
     public function write_setting($data) {
-    // do not write any setting
+        // do not write any setting
         return '';
     }
 
@@ -6732,6 +6826,7 @@ class admin_setting_manageplagiarism extends admin_setting {
     }
 }
 
+
 /**
  * Special class for overview of external services
  *
@@ -7003,6 +7098,7 @@ class admin_setting_webservicesoverview extends admin_setting {
 
 }
 
+
 /**
  * Special class for web service protocol administration.
  *
@@ -7291,6 +7387,7 @@ class admin_setting_managewebservicetokens extends admin_setting {
     }
 }
 
+
 /**
  * Colour picker
  *
index 11d478a..ea7c115 100644 (file)
@@ -287,22 +287,23 @@ function cron_run() {
         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)) {
index b88fdde..2067a44 100644 (file)
@@ -282,7 +282,7 @@ class mssql_sql_generator extends sql_generator {
     /**
      * 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
 
index 31b8374..cb8e00b 100644 (file)
@@ -208,7 +208,7 @@ class postgres_sql_generator extends sql_generator {
      *     - 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
index 1d400e8..059c620 100644 (file)
@@ -1140,7 +1140,7 @@ abstract class sql_generator {
     /**
      * 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();
     }
 
index b21edf1..2d6b2be 100644 (file)
@@ -521,7 +521,7 @@ abstract class moodle_database {
                 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.');
                     }
index be9fdb1..bf28990 100644 (file)
@@ -694,6 +694,9 @@ class mssql_native_moodle_database extends moodle_database {
         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);
             }
@@ -1002,6 +1005,9 @@ class mssql_native_moodle_database extends moodle_database {
             $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];
index 1ab255f..2197563 100644 (file)
@@ -340,6 +340,12 @@ class oci_native_moodle_database extends moodle_database {
         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) {
@@ -348,6 +354,24 @@ class oci_native_moodle_database extends moodle_database {
         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
@@ -843,11 +867,12 @@ class oci_native_moodle_database extends moodle_database {
             }
             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
@@ -940,6 +965,7 @@ class oci_native_moodle_database extends moodle_database {
             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);
@@ -1002,7 +1028,8 @@ class oci_native_moodle_database extends moodle_database {
 
         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);
@@ -1035,7 +1062,8 @@ class oci_native_moodle_database extends moodle_database {
 
         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);
@@ -1073,6 +1101,7 @@ class oci_native_moodle_database extends moodle_database {
     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);
@@ -1135,11 +1164,12 @@ class oci_native_moodle_database extends moodle_database {
 
         $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);
@@ -1246,6 +1276,7 @@ class oci_native_moodle_database extends moodle_database {
         $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);
@@ -1335,6 +1366,7 @@ class oci_native_moodle_database extends moodle_database {
         $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);
@@ -1365,6 +1397,7 @@ class oci_native_moodle_database extends moodle_database {
 
         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);
index 030e954..4f82eda 100644 (file)
@@ -623,6 +623,9 @@ class pgsql_native_moodle_database extends moodle_database {
         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";
         }
@@ -662,6 +665,9 @@ class pgsql_native_moodle_database extends moodle_database {
         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";
         }
index 8c88572..6a71f4e 100644 (file)
@@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die();
 
 class dml_test extends UnitTestCase {
     private $tables = array();
+    /** @var moodle_database */
     private $tdb;
     private $data;
     public  static $includecoverage = array('lib/dml');
@@ -1082,25 +1083,27 @@ class dml_test extends UnitTestCase {
         $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
@@ -3711,6 +3714,31 @@ class dml_test extends UnitTestCase {
         $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();
index a319935..e686ac5 100644 (file)
@@ -763,6 +763,9 @@ class sqlsrv_native_moodle_database extends moodle_database {
         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);
             }
@@ -1073,6 +1076,9 @@ class sqlsrv_native_moodle_database extends moodle_database {
             $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];
index 96a70f0..1bb1ca3 100644 (file)
@@ -1055,9 +1055,13 @@ abstract class enrol_plugin {
 
         $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);
@@ -1065,7 +1069,7 @@ abstract class enrol_plugin {
         } 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;
index dd4ae18..3e86263 100644 (file)
@@ -608,7 +608,7 @@ function file_get_submitted_draft_itemid($elname) {
  * @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();
@@ -717,7 +717,24 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
 
     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) {
@@ -739,7 +756,6 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
         $text = str_ireplace("$wwwroot/draftfile.php?file=/$usercontext->id/user/draft/$draftitemid/", '@@PLUGINFILE@@/', $text);
     }
 
-
     return $text;
 }
 
index 383da52..79f9770 100644 (file)
@@ -434,13 +434,43 @@ class file_storage {
 
         $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.
index ab03871..91e49bd 100644 (file)
@@ -476,12 +476,12 @@ abstract class moodleform {
      *
      * 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
@@ -954,12 +954,14 @@ abstract class moodleform {
      *
      * @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');
         }
index 50888fb..722eec1 100644 (file)
@@ -340,12 +340,34 @@ class cm_info extends stdClass  {
     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
@@ -380,6 +402,27 @@ class cm_info extends stdClass  {
      */
     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
@@ -429,6 +472,12 @@ class cm_info extends stdClass  {
      */
     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
@@ -443,6 +492,12 @@ class cm_info extends stdClass  {
      */
     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
@@ -786,12 +841,11 @@ class cm_info extends stdClass  {
         $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 : '';
@@ -809,22 +863,32 @@ class cm_info extends stdClass  {
             $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
@@ -963,18 +1027,6 @@ class cm_info extends stdClass  {
 }
 
 
-/**
- * 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).
@@ -1016,16 +1068,7 @@ function get_fast_modinfo(&$course, $userid=0) {
 
     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) {
index 5376bed..6824ee6 100644 (file)
@@ -1967,7 +1967,6 @@ class global_navigation extends navigation_node {
 
         //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) {
@@ -1978,7 +1977,8 @@ class global_navigation extends navigation_node {
                 $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());
             }
@@ -2036,12 +2036,11 @@ class global_navigation extends navigation_node {
         $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
@@ -2247,23 +2246,22 @@ class global_navigation_for_ajax extends global_navigation {
                 $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;
index c0524b9..e034c41 100644 (file)
@@ -1441,8 +1441,8 @@ function message_search_users($courseid, $searchtext, $sort='', $exceptions='')
 
         // 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 = ?
index 3900fff..2417a6f 100644 (file)
@@ -496,7 +496,6 @@ function forum_cron() {
             $userto->viewfullnames = array();
             $userto->canpost       = array();
             $userto->markposts     = array();
-            $userto->enrolledin    = array();
 
             // reset the caches
             foreach ($coursemodules as $forumid=>$unused) {
@@ -514,18 +513,11 @@ function forum_cron() {
                 $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');
@@ -2796,7 +2788,21 @@ function forum_get_user_discussions($courseid, $userid, $groupid=0) {
  * @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);
 }
 
 /**
@@ -2813,16 +2819,6 @@ function forum_get_potential_subscribers($forumcontext, $groupid, $fields, $sort
  */
 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,
@@ -2846,35 +2842,28 @@ function forum_subscribed_users($course, $forum, $groupid=0, $context = null, $f
                   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;
 }
@@ -4457,9 +4446,6 @@ function forum_post_subscription($post, $forum) {
 /**
  * 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
@@ -4490,6 +4476,9 @@ function forum_get_subscribe_link($forum, $context, $messages = array(), $cantac
     } 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 {
@@ -4782,8 +4771,8 @@ function forum_user_can_post($forum, $discussion, $user=NULL, $cm=NULL, $course=
         $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;
     }
 
@@ -5066,6 +5055,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=-1, $di
         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);
         }
     }
@@ -7516,11 +7506,12 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi
     }
 
     // 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);
@@ -7549,7 +7540,7 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi
                 break;
         }
 
-    } else if ($enrolled) {
+    } else if ($activeenrolled) {
 
         switch ($subscriptionmode) {
             case FORUM_CHOOSESUBSCRIBE : // 0
@@ -7582,7 +7573,7 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi
         $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
@@ -7732,7 +7723,7 @@ class forum_potential_subscriber_selector extends forum_subscriber_selector_base
     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();
@@ -7796,21 +7787,20 @@ class forum_existing_subscriber_selector extends forum_subscriber_selector_base
     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);
     }
index 021c1d7..6cdc2f1 100644 (file)
@@ -80,14 +80,19 @@ if ($groupmode && !forum_is_subscribed($user->id, $forum) && !has_capability('mo
 
 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)
index ed5a0a0..813ff4c 100644 (file)
@@ -469,6 +469,9 @@ function lesson_grade_item_update($lesson, $grades=NULL) {
         $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;
     }
@@ -487,7 +490,13 @@ function lesson_grade_item_update($lesson, $grades=NULL) {
             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;
+            }
         }
     }
 
index c264a4f..0f5ffea 100644 (file)
@@ -53,6 +53,7 @@ table#categoryquestions td,
 #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;}
index 8976d12..ce27636 100644 (file)
@@ -735,5 +735,4 @@ if (getLoggingActive() == "A") {
 }
 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);
 
index 7331813..8d466a4 100644 (file)
@@ -641,6 +641,7 @@ var API = new SCORMapi1_2();
 // 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);';
 }
  ?>
 
index 4319dca..dcae0e4 100644 (file)
@@ -313,7 +313,7 @@ function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$sco
         }
 
         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);
             }
index fd514a8..5fdce9a 100644 (file)
@@ -1278,5 +1278,6 @@ var API_1484_11 = new SCORMapi1_3();
 // 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);';
 }
  ?>
index 3630285..d78b444 100644 (file)
@@ -207,7 +207,10 @@ function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$sco
         }
 
         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;
index 91f96e2..696c32a 100644 (file)
@@ -94,6 +94,7 @@ if (!empty($dataid)) {
         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'));
index 6f30b23..90f872e 100644 (file)
@@ -1117,7 +1117,7 @@ M.core_filepicker.init = function(Y, options) {
 
                             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';
@@ -1147,11 +1147,18 @@ M.core_filepicker.init = function(Y, options) {
                                 }, 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,
index 5de5641..4a9552f 100644 (file)
@@ -698,4 +698,10 @@ body.tag .managelink {padding: 5px;}
 .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;}
index d94cd21..bb2a853 100644 (file)
     // 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();
 
index d53b5e0..e6818c8 100644 (file)
@@ -89,7 +89,7 @@ M.core_user.init_user_selector = function (Y, name, hash, extrafields, lastsearc
         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() == ''));
index 4a51179..41cd7dd 100644 (file)
@@ -30,7 +30,7 @@
 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