From 7130fb212cc34bbeeee8b15de4b5fe884aaa7597 Mon Sep 17 00:00:00 2001
From: tjhunt <tjhunt>
Date: Fri, 8 May 2009 03:30:58 +0000
Subject: [PATCH] blocklib: MDL-19010 once again you can add blocks, at least
 on the coures page.

---
 lib/blocklib.php | 15 ++++++---------
 lib/weblib.php   | 11 +++++++----
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/lib/blocklib.php b/lib/blocklib.php
index a2d3876a81..7df64a96ab 100644
--- a/lib/blocklib.php
+++ b/lib/blocklib.php
@@ -1051,7 +1051,7 @@ function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceori
             }
 
             $region = $page->blocks->get_default_region();
-            $weight = $DB->get_field_sql("SELECT MAX(weight) FROM {block_instances} 
+            $weight = $DB->get_field_sql("SELECT MAX(defaultweight) FROM {block_instances} 
                     WHERE contextid = ? AND defaultregion = ?", array($page->context->id, $region));
             $pagetypepattern = $page->pagetype;
             if (strpos($pagetypepattern, 'course-view') === 0) {
@@ -1295,21 +1295,18 @@ function blocks_print_adminblock($page, $blockmanager) {
         $strblocks = '<div class="title"><h2>';
         $strblocks .= get_string('blocks');
         $strblocks .= '</h2></div>';
+
         $stradd    = get_string('add');
         foreach ($missingblocks as $blockid) {
             $block = blocks_get_record($blockid);
             $blockobject = block_instance($block->name);
-            if ($blockobject === false) {
-                continue;
-            }
-            if(!$blockobject->user_can_addto($page)) {
-                continue;
+            if ($blockobject !== false && $blockobject->user_can_addto($page)) {
+                $menu[$block->id] = $blockobject->get_title();
             }
-            $menu[$block->id] = $blockobject->get_title();
         }
-        asort($menu);
+        asort($menu, SORT_LOCALE_STRING);
 
-        $target = $page->url->out(array('sesskey' => sesskey(), 'blockaction' => 'add'));
+        $target = $page->url->out(false, array('sesskey' => sesskey(), 'blockaction' => 'add'));
         $content = popup_form($target.'&amp;blockid=', $menu, 'add_block', '', $stradd .'...', '', '', true);
         print_side_block($strblocks, $content, NULL, NULL, NULL, array('class' => 'block_adminblock'));
     }
diff --git a/lib/weblib.php b/lib/weblib.php
index cc08fa943f..2c67564d7f 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -373,18 +373,21 @@ class moodle_url {
     /**
      * Output url
      *
-     * @param boolean $noquerystring whether to output page params as a query string in the url.
+     * @param boolean $omitquerystring whether to output page params as a query string in the url.
      * @param array $overrideparams params to add to the output url, these override existing ones with the same name.
      * @return string url
      */
-    public function out($noquerystring = false, $overrideparams = array()) {
+    public function out($omitquerystring = false, $overrideparams = array()) {
         $uri = $this->scheme ? $this->scheme.':'.((strtolower($this->scheme) == 'mailto') ? '':'//'): '';
         $uri .= $this->user ? $this->user.($this->pass? ':'.$this->pass:'').'@':'';
         $uri .= $this->host ? $this->host : '';
         $uri .= $this->port ? ':'.$this->port : '';
         $uri .= $this->path ? $this->path : '';
-        if (!$noquerystring) {
-            $uri .= (count($this->params)||count($overrideparams)) ? '?'.$this->get_query_string($overrideparams) : '';
+        if (!$omitquerystring) {
+            $querystring = $this->get_query_string($overrideparams);
+            if ($querystring) {
+                $uri .= '?' . $querystring;
+            }
         }
         $uri .= $this->fragment ? '#'.$this->fragment : '';
         return $uri;
-- 
2.39.5