Index: lib/weblib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/weblib.php,v
retrieving revision 1.1297
diff -u -r1.1297 weblib.php
--- lib/weblib.php	8 Jul 2009 03:27:27 -0000	1.1297
+++ lib/weblib.php	8 Jul 2009 12:41:40 -0000
@@ -5112,6 +5112,7 @@
     global $CFG, $SITE, $PAGE;
 
     $PAGE->set_pagetype('maintenance-message');
+    $PAGE->set_generaltype('maintenance');
     print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home');
     print_heading(get_string('sitemaintenance', 'admin'));
     if (isset($CFG->maintenance_message) and !html_is_blank($CFG->maintenance_message)) {
Index: lib/questionlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/questionlib.php,v
retrieving revision 1.206
diff -u -r1.206 questionlib.php
--- lib/questionlib.php	3 Jul 2009 06:19:27 -0000	1.206
+++ lib/questionlib.php	8 Jul 2009 12:41:37 -0000
@@ -1458,7 +1458,7 @@
  * @return string
  */
 function question_get_feedback_image($fraction, $selected=true) {
-    global $CFG;
+    global $CFG, $OUTPUT;
     static $icons = array('correct' => 'tick_green', 'partiallycorrect' => 'tick_amber',
             'incorrect' => 'cross_red');
 
Index: lib/outputlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/outputlib.php,v
retrieving revision 1.26
diff -u -r1.26 outputlib.php
--- lib/outputlib.php	8 Jul 2009 09:01:20 -0000	1.26
+++ lib/outputlib.php	8 Jul 2009 12:41:35 -0000
@@ -267,8 +267,9 @@
     /**
      * Names of the regions where blocks may appear on the page.
      *
-     * For each region you list in $THEME->blockregions you must call
-     * blocks_print_group with that region id somewhere in your layout template.
+     * For each region you list here you must do
+     *      echo $OUTPUT->blocks_for_region($regionname);
+     * or the equivalent, somewhere in your layout template.
      *
      * @var array
      */
@@ -597,9 +598,9 @@
         }
 
         // Parse the name that was found.
-        if (strpos('standard:', $templatefile) === 0) {
+        if (strpos($templatefile, 'standard:') === 0) {
             $templatepath = $CFG->themedir . '/standard/' . substr($templatefile, 9);
-        } else if (strpos('parent:', $templatefile) === 0) {
+        } else if (strpos($templatefile, 'parent:') === 0) {
             if (empty($this->parent)) {
                 throw new coding_exception('This theme (' . $this->name .
                         ') does not have a parent. You cannot specify a layout template like ' .
@@ -627,7 +628,8 @@
      * @param $property e.g. 'modsheets'.
      */
     protected function update_legacy_plugin_sheets($plugintype, $property) {
-        if (property_exists($this, $property)) {
+        // In Moodle 1.9, modsheets etc. were ignored if standardsheets was false.
+        if (!empty($this->standardsheets) && property_exists($this, $property)) {
             debugging('$THEME->' . $property . ' is deprecated. Please use the new $THEME->pluginsheets instead.', DEBUG_DEVELOPER);
             if (!empty($this->$property) && !in_array($plugintype, $this->pluginsheets)) {
                 $this->pluginsheets[] = $plugintype;
@@ -650,14 +652,6 @@
         $this->update_legacy_plugin_sheets('format', 'formatsheets');
         $this->update_legacy_plugin_sheets('gradereport', 'gradereportsheets');
 
-        if (empty($this->standardsheets)) {
-            // In Moodle 1.9, these settings were dependant on each other. They
-            // are now independant, at least at the time when the CSS is served,
-            // to this is necessary to maintain backwards compatibility. Hmm.
-            // What if you don't want this?
-            $this->pluginsheets = array();
-        }
-
         if (!empty($this->langsheets)) {
             debugging('$THEME->langsheets is no longer supported. No languages were ' .
                     'using it for anything, and it did not seem to serve any purpose.', DEBUG_DEVELOPER);
@@ -983,7 +977,7 @@
         }
     }
 
-    /* Implement the subclass method. */
+    /* Implement the interface method. */
     public function get_renderer($module, $page) {
         foreach ($this->prefixes as $prefix) {
             $classname = $prefix . $module . '_renderer';
@@ -1897,16 +1891,16 @@
      * @return string the HTML to be output.
      */
     function block($bc) {
-        $bc = clone($bc);
+        $bc = clone($bc); // Avoid messing up the object passed in.
         $bc->prepare();
 
-        $title = strip_tags($bc->title);
-        if (empty($title)) {
+        $skiptitle = strip_tags($bc->title);
+        if (empty($skiptitle)) {
             $output = '';
             $skipdest = '';
         } else {
             $output = $this->output_tag('a', array('href' => '#sb-' . $bc->skipid, 'class' => 'skip-block'),
-                    get_string('skipa', 'access', $title));
+                    get_string('skipa', 'access', $skiptitle));
             $skipdest = $this->output_tag('span', array('id' => 'sb-' . $bc->skipid, 'class' => 'skip-block-to'), '');
         }
 
@@ -1914,40 +1908,30 @@
         $bc->attributes['class'] = $bc->get_classes_string();
         $output .= $this->output_start_tag('div', $bc->attributes);
 
-        if ($bc->heading) {
-            // Some callers pass in complete html for the heading, which may include
-            // complicated things such as the 'hide block' button; some just pass in
-            // text. If they only pass in plain text i.e. it doesn't include a
-            // <div>, then we add in standard tags that make it look like a normal
-            // page block including the h2 for accessibility
-            if (strpos($bc->heading, '</div>') === false) {
-                $bc->heading = $this->output_tag('div', array('class' => 'title'),
-                        $this->output_tag('h2', null, $bc->heading));
-            }
-
-            $output .= $this->output_tag('div', array('class' => 'header'), $bc->heading);
+        $controlshtml = '';
+        foreach ($bc->controls as $control) {
+            $controlshtml .= $this->output_tag('a', array('class' => 'icon',
+                    'title' => $control['caption'], 'href' => $control['url']),
+                    $this->output_tag('img',  array('src' => $control['icon'],
+                    'alt' => $control['caption'])));
+        }
+        if ($controlshtml) {
+            $controlshtml = $this->output_tag('div', array('class' => 'controls'), $controlshtml);
+        }
+
+        $title = '';
+        if ($bc->title) {
+            $title = $this->output_tag('h2', null, $bc->title);
+        }
+
+        if ($title || $controlshtml) {
+            $output .= $this->output_tag('div', array('class' => 'header'),
+                    $this->output_tag('div', array('class' => 'title'),
+                    $title . $controlshtml));
         }
 
         $output .= $this->output_start_tag('div', array('class' => 'content'));
-
-        if ($bc->content) {
-            $output .= $bc->content;
-
-        } else if ($bc->list) {
-            $row = 0;
-            $items = array();
-            foreach ($bc->list as $key => $string) {
-                $item = $this->output_start_tag('li', array('class' => 'r' . $row));
-                if ($bc->icons) {
-                    $item .= $this->output_tag('div', array('class' => 'icon column c0'), $bc->icons[$key]);
-                }
-                $item .= $this->output_tag('div', array('class' => 'column c1'), $string);
-                $item .= $this->output_end_tag('li');
-                $items[] = $item;
-                $row = 1 - $row; // Flip even/odd.
-            }
-            $output .= $this->output_tag('ul', array('class' => 'list'), implode("\n", $items));
-        }
+        $output .= $bc->content;
 
         if ($bc->footer) {
             $output .= $this->output_tag('div', array('class' => 'footer'), $bc->footer);
@@ -1955,15 +1939,58 @@
 
         $output .= $this->output_end_tag('div');
         $output .= $this->output_end_tag('div');
+        if ($bc->annotation) {
+            $output .= $this->output_tag('div', array('class' => 'blockannotation'), $bc->annotation);
+        }
         $output .= $skipdest;
 
-        if (!empty($CFG->allowuserblockhiding) && isset($attributes['id'])) {
-            $strshow = addslashes_js(get_string('showblocka', 'access', $title));
-            $strhide = addslashes_js(get_string('hideblocka', 'access', $title));
-            $output .= $this->page->requires->js_function_call('elementCookieHide', array(
-                    $bc->id, $strshow, $strhide))->asap();
+        if ($bc->collapsible != block_contents::NOT_HIDEABLE) {
+            $userpref = 'block' . $bc->blockinstanceid . 'hidden';
+            user_preference_allow_ajax_update($userpref, PARAM_BOOL);
+            $this->page->requires->yui_lib('dom');
+            $this->page->requires->yui_lib('event');
+            $plaintitle = strip_tags($bc->title);
+            $this->page->requires->js_function_call('new block_hider', array($bc->id, $userpref,
+                    get_string('hideblocka', 'access', $plaintitle), get_string('showblocka', 'access', $plaintitle),
+                    $this->old_icon_url('t/switch_minus'), $this->old_icon_url('t/switch_plus')));
+        }
+
+        return $output;
+    }
+
+    /**
+     * Render the contents of a block_list.
+     * @param array $icons the icon for each item.
+     * @param array $items the content of each item.
+     * @return string HTML
+     */
+    public function list_block_contents($icons, $items) {
+        $row = 0;
+        $lis = array();
+        foreach ($items as $key => $string) {
+            $item = $this->output_start_tag('li', array('class' => 'r' . $row));
+            if ($icons) {
+                $item .= $this->output_tag('div', array('class' => 'icon column c0'), $icons[$key]);
+            }
+            $item .= $this->output_tag('div', array('class' => 'column c1'), $string);
+            $item .= $this->output_end_tag('li');
+            $lis[] = $item;
+            $row = 1 - $row; // Flip even/odd.
         }
+        return $this->output_tag('ul', array('class' => 'list'), implode("\n", $lis));
+    }
 
+    /**
+     * Output all the blocks in a particular region.
+     * @param $region the name of a region on this page.
+     * @return string the HTML to be output.
+     */
+    public function blocks_for_region($region) {
+        $blockcontents = $this->page->blocks->get_content_for_region($region, $this);
+        $output = '';
+        foreach ($blockcontents as $bc) {
+            $output .= $this->block($bc);
+        }
         return $output;
     }
 
@@ -2387,57 +2414,107 @@
 
 
 /**
- * This class hold all the information required to describe a Moodle block.
+ * This class represents how a block appears on a page.
  *
- * That is, it holds all the different bits of HTML content that need to be put into the block.
+ * During output, each block instance is asked to return a block_contents object,
+ * those are then passed to the $OUTPUT->block function for display.
+ *
+ * {@link $contents} should probably be generated using a moodle_block_..._renderer.
+ *
+ * Other block-like things that need to appear on the page, for example the
+ * add new block UI, are also represented as block_contents objects.
  *
  * @copyright 2009 Tim Hunt
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  * @since     Moodle 2.0
  */
 class block_contents extends moodle_html_component {
+    /** @var int used to set $skipid. */
     protected static $idcounter = 1;
+
+    const NOT_HIDEABLE = 0;
+    const VISIBLE = 1;
+    const HIDDEN = 2;
+
     /**
-     * @param string $heading HTML for the heading. Can include full HTML or just
-     *   plain text - plain text will automatically be enclosed in the appropriate
-     *   heading tags.
+     * @param integer $skipid All the blocks (or things that look like blocks)
+     * printed on a page are given a unique number that can be used to construct
+     * id="" attributes. This is set automatically be the {@link prepare()} method.
+     * Do not try to set it manually.
      */
-    public $heading = '';
+    public $skipid;
+
     /**
-     * @param string $title Plain text title, as embedded in the $heading.
+     * @var integer If this is the contents of a real block, this should be set to
+     * the block_instance.id. Otherwise this should be set to 0.
+     */
+    public $blockinstanceid = 0;
+
+    /**
+     * @var integer if this is a real block instance, and there is a corresponding
+     * block_position.id for the block on this page, this should be set to that id.
+     * Otherwise it should be 0.
+     */
+    public $blockpositionid = 0;
+
+    /**
+     * @param array $attributes an array of attribute => value pairs that are put on the
+     * outer div of this block. {@link $id} and {@link $classes} attributes should be set separately.
+     */
+    public $attributes = array();
+
+    /**
+     * @param string $title The title of this block. If this came from user input,
+     * it should already have had format_string() processing done on it. This will
+     * be output inside <h2> tags. Please do not cause invalid XHTML.
      */
     public $title = '';
+
     /**
      * @param string $content HTML for the content
      */
     public $content = '';
+
     /**
      * @param array $list an alternative to $content, it you want a list of things with optional icons.
      */
-    public $list = array();
-    /**
-     * @param array $icons optional icons for the things in $list.
-     */
-    public $icons = array();
+    public $footer = '';
+
     /**
-     * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
+     * Any small print that should appear under the block to explain to the
+     * teacher about the block, for example 'This is a sticky block that was
+     * added in the system context.'
+     * @var string
      */
-    public $footer = '';
+    public $annotation = '';
+
     /**
-     * @param array $attributes an array of attribute => value pairs that are put on the
-     * outer div of this block. {@link $id} and {@link $classes} attributes should be set separately.
+     * @var integer one of the constants NOT_HIDEABLE, VISIBLE, HIDDEN. Whether
+     * the user can toggle whether this block is visible.
      */
-    public $attributes = array();
+    public $collapsible = self::NOT_HIDEABLE;
+
     /**
-     * @param integer $skipid do not set this manually. It is set automatically be the {@link prepare()} method.
+     * A (possibly empty) array of editing controls. Each element of this array
+     * should be an array('url' => $url, 'icon' => $icon, 'caption' => $caption)
+     * @var array
      */
-    public $skipid;
+    public $controls = array();
 
     /* @see lib/moodle_html_component#prepare() */
     public function prepare() {
         $this->skipid = self::$idcounter;
         self::$idcounter += 1;
         $this->add_class('sideblock');
+        if (empty($this->blockinstanceid) || !strip_tags($this->title)) {
+            $this->collapsible = self::NOT_HIDEABLE;
+        }
+        if ($this->collapsible == self::HIDDEN) {
+            $this->add_class('hidden');
+        }
+        if (!empty($this->controls)) {
+            $this->add_class('block_with_controls');
+        }
         parent::prepare();
     }
 }
Index: lib/pagelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/pagelib.php,v
retrieving revision 1.134
diff -u -r1.134 pagelib.php
--- lib/pagelib.php	3 Jul 2009 09:03:50 -0000	1.134
+++ lib/pagelib.php	8 Jul 2009 12:41:35 -0000
@@ -888,6 +888,10 @@
     public function initialise_theme_and_output() {
         global $OUTPUT, $PAGE, $SITE, $THEME;
 
+        if (!empty($this->_wherethemewasinitialised)) {
+            return;
+        }
+
         if (!$this->_course && !during_initial_install()) {
             $this->set_course($SITE);
         }
Index: lib/upgradelib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/upgradelib.php,v
retrieving revision 1.27
diff -u -r1.27 upgradelib.php
--- lib/upgradelib.php	3 Jul 2009 13:35:36 -0000	1.27
+++ lib/upgradelib.php	8 Jul 2009 12:41:38 -0000
@@ -725,7 +725,7 @@
     } else {
         if (!CLI_SCRIPT and !$PAGE->headerprinted) {
             $strupgrade  = get_string('upgradingversion', 'admin');
-
+            $PAGE->set_generaltype('maintenance');
             upgrade_get_javascript();
             print_header($strupgrade.' - Moodle '.$CFG->target_release, $strupgrade,
                 build_navigation(array(array('name' => $strupgrade, 'link' => null, 'type' => 'misc'))), '',
@@ -764,7 +764,7 @@
         ignore_user_abort(false);
         if ($continueurl) {
             print_continue($continueurl);
-            print_footer('upgrade');
+            print_footer();
             die;
         }
     }
Index: lib/setuplib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/setuplib.php,v
retrieving revision 1.66
diff -u -r1.66 setuplib.php
--- lib/setuplib.php	7 Jul 2009 04:37:12 -0000	1.66
+++ lib/setuplib.php	8 Jul 2009 12:41:37 -0000
@@ -297,7 +297,7 @@
     }
     $moreinfourl = $errordocroot . '/en/error/' . $modulelink . '/' . $errorcode;
 
-    if (empty($link) && !defined('ADMIN_EXT_HEADER_PRINTED')) {
+    if (empty($link)) {
         if (!empty($SESSION->fromurl)) {
             $link = $SESSION->fromurl;
             unset($SESSION->fromurl);
Index: lib/blocklib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/blocklib.php,v
retrieving revision 1.186
diff -u -r1.186 blocklib.php
--- lib/blocklib.php	1 Jul 2009 05:54:27 -0000	1.186
+++ lib/blocklib.php	8 Jul 2009 12:41:33 -0000
@@ -18,16 +18,16 @@
 /**
  * Block Class and Functions
  *
- * @todo Document what this file does
- * 
+ * This file defines the {@link block_manager} class, 
+ *
  * @package   moodlecore
  * @copyright 1999 onwards Martin Dougiamas  http://dougiamas.com
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
- /**
-  * Block Defines
-  */
+/**
+ * Block Defines
+ */
 define('BLOCK_MOVE_LEFT',   0x01);
 define('BLOCK_MOVE_RIGHT',  0x02);
 define('BLOCK_MOVE_UP',     0x04);
@@ -41,19 +41,19 @@
 define('BLOCKS_PINNED_FALSE',1);
 define('BLOCKS_PINNED_BOTH',2);
 
-require_once($CFG->libdir.'/pagelib.php');
-
 /**
+ * Exception thrown when someone tried to do something with a block that does
+ * not exist on a page.
  *
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @package moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since     Moodle 2.0
  */
 class block_not_on_page_exception extends moodle_exception {
     /**
      * Contructor
-     *
-     * @param int $instanceid
-     * @param object $page
+     * @param int $instanceid the block instance id of the block that was looked for.
+     * @param object $page the current page.
      */
     public function __construct($instanceid, $page) {
         $a = new stdClass;
@@ -64,47 +64,36 @@
 }
 
 /**
- * Block Manager
- *
  * This class keeps track of the block that should appear on a moodle_page.
+ *
  * The page to work with as passed to the constructor.
- * The only fields of moodle_page that is uses are ->context, ->pagetype and
- * ->subpage, so instead of passing a full moodle_page object, you may also
- * pass a stdClass object with those three fields. These field values are read
- * only at the point that the load_blocks() method is called. It is the caller's
- * responsibility to ensure that those fields do not subsequently change.
- *
- *
- * Note about the weird 'implements ArrayAccess' part of the declaration:
- *
- * ArrayAccess is a magic PHP5 thing. If your class implements the ArrayAccess
- * interface, then other code can use the $object[$index] syntax, and it will
- * call the offsetGet method of the object.
- * See http://php.net/manual/en/class.arrayaccess.php
- *
- * So, why do we do this here? Basically, some of the deprecated blocks methods
- * like blocks_setup used to return an array of blocks on the page, with array
- * keys BLOCK_POS_LEFT, BLOCK_POS_RIGHT. We can keep legacy code that calls those
- * deprecated functions mostly working by changing blocks_setup to return the
- * block_manger object, and then use 'implements ArrayAccess' so that the right
- * thing happens when legacy code does something like $pageblocks[BLOCK_POS_LEFT].
  *
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @package moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since     Moodle 2.0
  */
-class block_manager implements ArrayAccess {
+class block_manager {
 
 /// Field declarations =========================================================
-    /** @var object */
+
+    /** @var moodle_page the moodle_page we aremanaging blocks for. */
     protected $page;
-    /** @var array */
+
+    /** @var array region name => 1.*/
     protected $regions = array();
-    /** @var string */
+
+    /** @var string the region where new blocks are added.*/
     protected $defaultregion;
-    /** @var array */
-    protected $allblocks = null; // Will be get_records('blocks');
-    /** @var array */
-    protected $addableblocks = null; // Will be a subset of $allblocks.
+
+    /** @var array will be $DB->get_records('blocks') */
+    protected $allblocks = null;
+
+    /**
+     * @var array blocks that this user can add to this page. Will be a subset
+     * of $allblocks. Access this via the {@link get_addable_blocks()} method
+     * to ensure it is lazy-loaded.
+     */
+    protected $addableblocks = null;
 
     /**
      * Will be an array region-name => array(db rows loaded in load_blocks);
@@ -120,12 +109,19 @@
     protected $blockinstances = array();
 
     /**
-     * array region-name => array(block_content objects) what acutally needs to
+     * array region-name => array(block_contents objects) what acutally needs to
      * be displayed in each region.
      * @var array
      */
     protected $visibleblockcontent = array();
 
+    /**
+     * array region-name => array(block_contents objects) extra block-like things
+     * to be displayed in each region, before the real blocks.
+     * @var array
+     */
+    protected $extracontent = array();
+
 /// Constructor ================================================================
 
     /**
@@ -146,6 +142,7 @@
      * @return array the internal names of the regions on this page where block may appear.
      */
     public function get_regions() {
+        $this->page->initialise_theme_and_output();
         return array_keys($this->regions);
     }
 
@@ -158,6 +155,7 @@
      * to a theme with different block positions.)
      */
     public function get_default_region() {
+        $this->page->initialise_theme_and_output();
         return $this->defaultregion;
     }
 
@@ -243,19 +241,35 @@
     /**
      * Returns an array of block content objects that exist in a region
      *
-     * @param $region a block region that exists on this page.
-     * @return array of block block_content objects for all the blocks in a region.
+     * @param string $region a block region that exists on this page.
+     * @return array of block block_contents objects for all the blocks in a region.
      */
-    public function get_content_for_region($region) {
+    public function get_content_for_region($region, $output) {
         $this->check_is_loaded();
-        $this->ensure_content_created($region);
+        $this->ensure_content_created($region, $output);
         return $this->visibleblockcontent[$region];
     }
 
     /**
+     * Determine whether a region contains anything. (Either any real blocks, or
+     * the add new block UI.)
+     * @param string $region a block region that exists on this page.
+     * @return boolean Whether there is anything in this region.
+     */
+    public function region_has_content($region) {
+        $this->ensure_instances_exist($region);
+        $this->check_is_loaded();
+        if ($this->page->user_is_editing() && $this->page->user_can_edit_blocks()) {
+            // If editing is on, we need all the block regions visible, for the
+            // move blocks UI.
+            return true;
+        }
+        return !empty($this->blockinstances[$region]) || !empty($this->extracontent[$region]);
+    }
+
+    /**
      * Get an array of all of the installed blocks.
      *
-     * @global object
      * @return array contents of the block table.
      */
     public function get_installed_blocks() {
@@ -305,16 +319,29 @@
         $this->defaultregion = $defaultregion;
     }
 
+    /**
+     * Add something that looks like a block, but which isn't an actual block_instance,
+     * to this page.
+     *
+     * @param block_contents $bc the content of the block like thing.
+     * @param string $region a block region that exists on this page.
+     */
+    public function add_pretend_block($bc, $region) {
+        $this->page->initialise_theme_and_output();
+        $this->check_region_is_known($region);
+        if (array_key_exists($region, $this->visibleblockcontent)) {
+            throw new coding_exception('block_manager has already prepared the blocks in region ' .
+                    $region . 'for output. It is too late to add a pretend block.');
+        }
+        $this->extracontent[$region][] = $bc;
+    }
+
 /// Actions ====================================================================
 
     /**
      * This method actually loads the blocks for our page from the database.
      *
-     * @global object
-     * @global object
-     * @uses SQL_PARAMS_NAMED
      * @param bool|null $includeinvisible
-     * @return void
      */
     public function load_blocks($includeinvisible = NULL) {
         global $DB, $CFG;
@@ -365,6 +392,7 @@
         );
         $sql = "SELECT
                     bi.id,
+                    bp.id AS blockpositionid,
                     bi.blockname,
                     bi.contextid,
                     bi.showinsubcontexts,
@@ -411,9 +439,6 @@
      * Add a block to the current page, or related pages. The block is added to
      * context $this->page->contextid. If $pagetypepattern $subpagepattern
      *
-     * @global object
-     * @uses CONTEXT_COURSE
-     * @uses CONTEXT_BLOCK
      * @param string $blockname The type of block to add.
      * @param string $region the block region on this page to add the block to.
      * @param integer $weight determines the order where this block appears in the region.
@@ -600,14 +625,10 @@
      * @param array $instances An array of block instances
      * @return array An array of content vars
      */
-    protected function create_block_content($instances) {
+    protected function create_block_contents($instances, $output) {
         $results = array();
         foreach ($instances as $instance) {
-            if ($instance->is_empty()) {
-                continue;
-            }
-
-            $content = $instance->get_content();
+            $content = $instance->get_content_for_output($output);
             if (!empty($content)) {
                 $results[] = $content;
             }
@@ -616,6 +637,44 @@
     }
 
     /**
+     * Return a {@link block_contents} representing the add a new block UI, if
+     * this user is allowed to see it.
+     *
+     * @return block_contents an appropriate block_contents, or null if the user
+     * cannot add any blocks here.
+     */
+    function add_block_ui($output) {
+        if (!$this->page->user_is_editing() || !$this->page->user_can_edit_blocks()) {
+            return null;
+        }
+
+        $bc = new block_contents();
+        $bc->title = get_string('addblock');
+        $bc->add_class('block_adminblock');
+
+        $missingblocks = array_keys($this->get_addable_blocks());
+        if (empty($missingblocks)) {
+            $bc->title = get_string('noblockstoaddhere');
+            return $bc;
+        }
+
+        $menu = array();
+        foreach ($missingblocks as $blockid) {
+            $block = blocks_get_record($blockid);
+            $blockobject = block_instance($block->name);
+            if ($blockobject !== false && $blockobject->user_can_addto($page)) {
+                $menu[$block->id] = $blockobject->get_title();
+            }
+        }
+        asort($menu, SORT_LOCALE_STRING);
+
+        // TODO convert to $OUTPUT.
+        $target = $this->page->url->out(false, array('sesskey' => sesskey(), 'blockaction' => 'add'));
+        $bc->content = popup_form($target.'&amp;blockid=', $menu, 'add_block', '', get_string('adddots'), '', '', true);
+        return $bc;
+    }
+
+    /**
      * Ensure block instances exist for a given region
      * 
      * @param string $region Check for bi's with the instance with this name
@@ -633,66 +692,23 @@
      *
      * @param string $region The name of the region to check
      */
-    protected function ensure_content_created($region) {
+    protected function ensure_content_created($region, $output) {
         $this->ensure_instances_exist($region);
         if (!array_key_exists($region, $this->visibleblockcontent)) {
-            $this->visibleblockcontent[$region] =
-                    $this->create_block_content($this->blockinstances[$region]);
+            $contents = array();
+            if (array_key_exists($region, $this->extracontent)) {
+                $contents += $this->extracontent[$region];
+            }
+            $contents += $this->create_block_contents($this->blockinstances[$region], $output);
+            if ($region == $this->defaultregion) {
+                $addblockui = $this->add_block_ui($output);
+                if ($addblockui) {
+                    $contents[] = $addblockui;
+                }
+            }
+            $this->visibleblockcontent[$region] = $contents;
         }
     }
-
-/// Deprecated stuff for backwards compatibility ===============================
-    /** @deprecated Remains to ensure backwards compatibility */
-    public function offsetSet($offset, $value) {
-    }
-    /** @deprecated Remains to ensure backwards compatibility */
-    public function offsetExists($offset) {
-        return $this->is_known_region($offset);
-    }
-    /** @deprecated Remains to ensure backwards compatibility */
-    public function offsetUnset($offset) {
-    }
-    /** @deprecated Remains to ensure backwards compatibility */
-    public function offsetGet($offset) {
-        return $this->get_blocks_for_region($offset);
-    }
-}
-
-/**
- * This class holds all the information required to view a block.
- *
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @package moodlecore
- */
-abstract class block_content {
-    /** @var int    Id used to uniquely identify this block in the HTML. */
-    public $id = null;
-    /** @var array  Class names to add to this block's container in the HTML. */
-    public $classes = array();
-    /** @var string The content that appears in the title bar at the top of the block (HTML). */
-    public $heading = null;
-    /** @var string Plain text name of this block instance, used in the skip links. */
-    public $title = null;
-    /**
-     * A (possibly empty) array of editing controls. Array keys should be a
-     * short string, e.g. 'edit', 'move' and the values are the HTML of the icons.
-     * @var array
-     */
-    public $editingcontrols = array();
-    /** @var string The content that appears within the block, as HTML. */
-    public $content = null;
-    /** @var string The content that appears at the end of the block. */
-    public $footer = null;
-    /**
-     * Any small print that should appear under the block to explain to the
-     * teacher about the block, for example 'This is a sticky block that was
-     * added in the system context.'
-     * @var string
-     */
-    public $annotation = null;
-    /** @var string The result of the preferred_width method, which the theme may choose to use, or ignore. */
-    public $preferredwidth = null;
-    public abstract function get_content();
 }
 
 /// Helper functions for working with block classes ============================
@@ -739,7 +755,6 @@
 /**
  * Load the block class for a particular type of block.
  *
- * @global object
  * @param string $blockname the name of the block.
  * @return boolean success or failure.
  */
@@ -788,7 +803,7 @@
 function blocks_remove_inappropriate($course) {
     // TODO
     return;
-    $blockmanager = blocks_get_by_page($page);
+    $blockmanager = array(); blocks_get_by_page($page);
 
     if(empty($blockmanager)) {
         return;
@@ -839,8 +854,6 @@
 /**
  * Delete a block, and associated data.
  *
- * @global object
- * @uses CONTEXT_BLOCK
  * @param object $instance a row from the block_instances table
  * @param bool $nolongerused legacy parameter. Not used, but kept for bacwards compatibility.
  * @param bool $skipblockstables for internal use only. Makes @see blocks_delete_all_for_context() more efficient.
@@ -860,27 +873,8 @@
 }
 
 /**
- * @deprecated since 2.0
- * Delete all the blocks from a particular page.
- *
- * @global object
- * @param string $pagetype the page type.
- * @param integer $pageid the page id.
- * @return bool success or failure.
- */
-function blocks_delete_all_on_page($pagetype, $pageid) {
-    global $DB;
-
-    debugging('Call to deprecated function blocks_delete_all_on_page. ' .
-            'This function cannot work any more. Doing nothing. ' .
-            'Please update your code to use another method.', DEBUG_DEVELOPER);
-    return false;
-}
-
-/**
  * Delete all the blocks that belong to a particular context.
  *
- * @global object
  * @param int $contextid the context id.
  */
 function blocks_delete_all_for_context($contextid) {
@@ -895,98 +889,54 @@
 }
 
 /**
- * Accepts an array of block instances and checks to see if any of them have content to display
- * (causing them to calculate their content in the process). Returns true or false. Parameter passed
- * by reference for speed; the array is actually not modified.
- *
- * @todo Deprecate this function
- * @deprecated
+ * @deprecated since 2.0
+ * Delete all the blocks from a particular page.
  *
- * @param object $blockmanager
- * @param string $region
- * @return bool
+ * @param string $pagetype the page type.
+ * @param integer $pageid the page id.
+ * @return bool success or failure.
  */
-function blocks_have_content(&$blockmanager, $region) {
-    // TODO deprecate
-    $content = $blockmanager->get_content_for_region($region);
-    return !empty($content);
+function blocks_delete_all_on_page($pagetype, $pageid) {
+    global $DB;
+
+    debugging('Call to deprecated function blocks_delete_all_on_page. ' .
+            'This function cannot work any more. Doing nothing. ' .
+            'Please update your code to use a block_manager method $PAGE->blocks->....', DEBUG_DEVELOPER);
+    return false;
 }
 
 /**
- * This function prints one group of blocks in a page
+ * Dispite what this function is called, it seems to be mostly used to populate
+ * the default blocks when a new course (or whatever) is created.
  *
- * @todo Complete this function
+ * @deprecated since 2.0
  *
- * @global object
- * @global object
- * @global object
- * @param object $page
- * @param object $blockmanager
- * @param string $region
+ * @param object $page the page to add default blocks to.
+ * @return boolean success or failure.
  */
-function blocks_print_group($page, $blockmanager, $region) {
-    global $COURSE, $CFG, $USER;
-
-    $isediting = $page->user_is_editing();
-    $groupblocks = $blockmanager->get_blocks_for_region($region);
+function blocks_repopulate_page($page) {
+    global $CFG;
 
-    foreach($groupblocks as $instance) {
-        if (($isediting && empty($instance->pinned))) {
-            $options = 0;
-            // The block can be moved up if it's NOT the first one in its position. If it is, we look at the OR clause:
-            // the first block might still be able to move up if the page says so (i.e., it will change position)
-// TODO            $options |= BLOCK_MOVE_UP    * ($instance->weight != 0          || ($page->blocks_move_position($instance, BLOCK_MOVE_UP)   != $instance->position));
-            // Same thing for downward movement
-// TODO            $options |= BLOCK_MOVE_DOWN  * ($instance->weight != $maxweight || ($page->blocks_move_position($instance, BLOCK_MOVE_DOWN) != $instance->position));
-            // For left and right movements, it's up to the page to tell us whether they are allowed
-// TODO            $options |= BLOCK_MOVE_RIGHT * ($page->blocks_move_position($instance, BLOCK_MOVE_RIGHT) != $instance->position);
-// TODO            $options |= BLOCK_MOVE_LEFT  * ($page->blocks_move_position($instance, BLOCK_MOVE_LEFT ) != $instance->position);
-            // Finally, the block can be configured if the block class either allows multiple instances, or if it specifically
-            // allows instance configuration (multiple instances override that one). It doesn't have anything to do with what the
-            // administrator has allowed for this block in the site admin options.
-            $options |= BLOCK_CONFIGURE * ( $instance->instance_allow_multiple() || $instance->instance_allow_config() );
-            $instance->_add_edit_controls($options);
-        }
-
-        if (false /* TODO */&& !$instance->visible && empty($COURSE->javascriptportal)) {
-            if ($isediting) {
-                $instance->_print_shadow();
-            }
-        } else {
-            global $COURSE;
-            if(!empty($COURSE->javascriptportal)) {
-                 $COURSE->javascriptportal->currentblocksection = $region;
-            }
-            $instance->_print_block();
-        }
-        if (!empty($COURSE->javascriptportal)
-                    && (empty($instance->pinned) || !$instance->pinned)) {
-            $COURSE->javascriptportal->block_add('inst'.$instance->id, !$instance->visible);
-        }
-    } // End foreach
+    debugging('Call to deprecated function blocks_repopulate_page. ' .
+            'Use a more specific method like blocks_add_default_course_blocks, ' .
+            'or just call $PAGE->blocks->add_blocks()', DEBUG_DEVELOPER);
 
-    if ($page->blocks->get_default_region() == $region &&
-            $page->user_is_editing() && $page->user_can_edit_blocks()) {
-        blocks_print_adminblock($page, $blockmanager);
+    /// If the site override has been defined, it is the only valid one.
+    if (!empty($CFG->defaultblocks_override)) {
+        $blocknames = $CFG->defaultblocks_override;
+    } else {
+        $blocknames = $page->blocks_get_default();
     }
-}
 
-/**
- * This iterates over an array of blocks and calculates the preferred width
- * Parameter passed by reference for speed; it's not modified.
- *
- * @todo Finish this function
- *
- * @param mixed $instances
- */
-function blocks_preferred_width($instances) {
-    $width = 210;
+    $blocks = blocks_parse_default_blocks_list($blocknames);
+    $page->blocks->add_blocks($blocks);
+
+    return true;
 }
 
 /**
- * Get the block record for a particulr blockid.
+ * Get the block record for a particular blockid - that is, a particul type os block.
  *
- * @global object
  * @param $int blockid block type id. If null, an array of all block types is returned.
  * @param bool $notusedanymore No longer used.
  * @return array|object row from block table, or all rows.
@@ -1028,28 +978,8 @@
 }
 
 /**
- * Simple entry point for anyone that wants to use blocks
+ * TODO Document this function, description
  *
- * @uses BLOCKS_PINNED_FALSE
- * @param object $page
- * @return array
- */
-function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
-    $page->blocks->load_blocks();
-    blocks_execute_url_action($page, $page->blocks);
-    return $page->blocks;
-}
-
-/**
- * @todo Document this function, description
- *
- * @global object
- * @global object
- * @global object
- * @uses BLOCK_MOVE_UP
- * @uses BLOCK_MOVE_DOWN
- * @uses BLOCK_MOVE_RIGHT
- * @uses BLOCK_MOVE_LEFT
  * @param object $page The page object
  * @param object $blockmanager The block manager object
  * @param string $blockaction One of [config, add, delete]
@@ -1272,10 +1202,10 @@
 }
 
 /**
+ * TODO deprecate
+ *
  * You can use this to get the blocks to respond to URL actions without much hassle
  *
- * @uses PARAM_ALPHA
- * @uses PARAM_INT
  * @param object $PAGE
  * @param object $blockmanager
  * @param bool $pinned
@@ -1299,6 +1229,7 @@
 }
 
 /**
+ * TODO deprecate
  * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
  * in order to reduce code repetition.
  *
@@ -1348,10 +1279,9 @@
 
 
 /**
+ * TODO deprecate
  * Moves a block to the new position (column) and weight (sort order).
  *
- * @global object
- * @global object
  * @param object $instance The block instance to be moved.
  * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
  * @param string $destweight The destination sort order. If NULL, we add to the end
@@ -1368,9 +1298,9 @@
     throw new moodle_exception('Sorry, blocks editing is currently broken. Will be fixed. See MDL-19010.');
 
     if ($pinned) {
-        $blocklist = blocks_get_pinned($page);
+        $blocklist = array(); //blocks_get_pinned($page);
     } else {
-        $blocklist = blocks_get_by_page($page);
+        $blocklist = array(); //blocks_get_by_page($page);
     }
 
     if ($blocklist[$instance->position][$instance->weight]->id != $instance->id) {
@@ -1425,137 +1355,11 @@
     return $DB->update_record($table, $instance);
 }
 
-
-/**
- * Returns an array consisting of 2 arrays:
- * 1) Array of pinned blocks for position BLOCK_POS_LEFT
- * 2) Array of pinned blocks for position BLOCK_POS_RIGHT
- *
- * @global object
- * @param object $page
- */
-function blocks_get_pinned($page) {
-    global $DB;
-
-    $visible = true;
-    $select = "pagetype = ?";
-    $params = array($page->pagetype);
-
-     if ($visible) {
-        $select .= " AND visible = 1";
-     }
-
-    $blocks = $DB->get_records_select('block_pinned_old', $select, $params, 'position, weight');
-
-    $regions = $page->blocks->get_regions();
-    $arr = array();
-
-    foreach($regions as $key => $region) {
-        $arr[$region] = array();
-    }
-
-    if(empty($blocks)) {
-        return $arr;
-    }
-
-    foreach($blocks as $block) {
-        $block->pinned = true; // so we know we can't move it.
-        // make up an instanceid if we can..
-        $block->pageid = $page->get_id();
-        $arr[$block->position][$block->weight] = $block;
-    }
-
-    return $arr;
-}
-
-
-/**
- * Similar to blocks_get_by_page(), except that, the array returned includes
- * pinned blocks as well. Pinned blocks are always appended before normal
- * block instances.
- *
- * @param object $page
- * @return array
- */
-function blocks_get_by_page_pinned($page) {
-    $pinned = blocks_get_pinned($page);
-    $user = blocks_get_by_page($page);
-
-    $weights = array();
-
-    foreach ($pinned as $pos => $arr) {
-        $weights[$pos] = count($arr);
-    }
-
-    foreach ($user as $pos => $blocks) {
-        if (!array_key_exists($pos,$pinned)) {
-             $pinned[$pos] = array();
-        }
-        if (!array_key_exists($pos,$weights)) {
-            $weights[$pos] = 0;
-        }
-        foreach ($blocks as $block) {
-            $pinned[$pos][$weights[$pos]] = $block;
-            $weights[$pos]++;
-        }
-    }
-    return $pinned;
-}
-
-
-/**
- * Returns an array of blocks for the page. Pinned blocks are excluded.
- *
- * @todo Check backwards compatibility hack
- * @global object
- * @param object $page
- */
-function blocks_get_by_page($page) {
-    global $DB;
-
-    // TODO check the backwards compatibility hack.
-    return $page->blocks;
-}
-
-/**
- * This function prints the block to admin blocks as necessary
- *
- * @global object
- * @uses SORT_LOCALE_STRING
- * @param object $page
- * @param object $blockmanager
- */
-function blocks_print_adminblock($page, $blockmanager) {
-    global $USER;
-
-    $missingblocks = array_keys($page->blocks->get_addable_blocks());
-
-    if (!empty($missingblocks)) {
-        $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 && $blockobject->user_can_addto($page)) {
-                $menu[$block->id] = $blockobject->get_title();
-            }
-        }
-        asort($menu, SORT_LOCALE_STRING);
-
-        $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'));
-    }
-}
+// Functions for programatically adding default blocks to pages ================
 
 /**
  * Parse a list of default blocks. See config-dist for a description of the format.
  *
- * @uses BLOCK_POS_LEFT
- * @uses BLOCK_POS_RIGHT
  * @param string $blocksstr
  * @return array
  */
@@ -1572,9 +1376,6 @@
 }
 
 /**
- * @global object
- * @uses BLOCK_POS_LEFT
- * @uses BLOCK_POS_RIGHT
  * @return array the blocks that should be added to the site course by default.
  */
 function blocks_get_default_site_course_blocks() {
@@ -1593,10 +1394,6 @@
 /**
  * Add the default blocks to a course.
  *
- * @global object
- * @uses SITEID
- * @uses BLOCK_POS_LEFT
- * @uses BLOCK_POS_RIGHT
  * @param object $course a course object.
  */
 function blocks_add_default_course_blocks($course) {
@@ -1646,44 +1443,9 @@
 
 /**
  * Add the default system-context blocks. E.g. the admin tree.
- *
- * @uses BLOCK_POS_LEFT
- * @uses CONTEXT_SYSTEM
  */
 function blocks_add_default_system_blocks() {
     $page = new moodle_page();
     $page->set_context(get_context_instance(CONTEXT_SYSTEM));
     $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_tree', 'admin_bookmarks')), 'admin-*');
 }
-
-/**
- * Dispite what this function is called, it seems to be mostly used to populate
- * the default blocks when a new course (or whatever) is created.
- *
- * @deprecated since 2.0
- * @global object
- * @uses DEBUG_DEVELOPER
- * @param object $page the page to add default blocks to.
- * @return boolean success or failure.
- */
-function blocks_repopulate_page($page) {
-    global $CFG;
-
-    debugging('Call to deprecated function blocks_repopulate_page. ' .
-            'Use a more specific method like blocks_add_default_course_blocks, ' .
-            'or just call $PAGE->blocks->add_blocks()', DEBUG_DEVELOPER);
-
-    /// If the site override has been defined, it is the only valid one.
-    if (!empty($CFG->defaultblocks_override)) {
-        $blocknames = $CFG->defaultblocks_override;
-    } else {
-        $blocknames = $page->blocks_get_default();
-    }
-
-    $blocks = blocks_parse_default_blocks_list($blocknames);
-    $page->blocks->add_blocks($blocks);
-
-    return true;
-}
-
-?>
Index: theme/standard/config.php
===================================================================
RCS file: /cvsroot/moodle/moodle/theme/standard/config.php,v
retrieving revision 1.29
diff -u -r1.29 config.php
--- theme/standard/config.php	7 Jul 2009 05:05:07 -0000	1.29
+++ theme/standard/config.php	8 Jul 2009 12:41:43 -0000
@@ -47,6 +47,8 @@
 $THEME->layouttemplates = array(
     'normal' => 'layout.php',
     'home' => 'layout-home.php',
+    'popup' => 'layout-popup.php',
+    'maintenance' => 'layout-popup.php',
 );
 $THEME->blockregions = array('side-pre', 'side-post');
 $THEME->defaultblockregion = 'side-post';
Index: theme/standard/styles_layout.css
===================================================================
RCS file: /cvsroot/moodle/moodle/theme/standard/styles_layout.css,v
retrieving revision 1.697
diff -u -r1.697 styles_layout.css
--- theme/standard/styles_layout.css	2 Jul 2009 09:18:26 -0000	1.697
+++ theme/standard/styles_layout.css	8 Jul 2009 12:41:44 -0000
@@ -50,14 +50,14 @@
   margin-top: 8px;
 }
 
-#layout-table #left-column,
-#layout-table #middle-column,
-#layout-table #right-column
+#layout-table #region-side-pre,
+#layout-table #content,
+#layout-table #region-side-post
 {
   vertical-align:top;
 }
 
-#layout-table #middle-column {
+#layout-table #content {
   padding-left:12px;
   padding-right:12px;
 }
@@ -1569,16 +1569,19 @@
   margin: 0px 2px;
 }
 
-#left-column .hidden .header,
-#right-column .hidden .header
-{
+.block-region .hidden .header {
   border-bottom-width: 1px;
   border-bottom-style: solid;
 }
+#region-side-pre,
+#region-side-post {
+  width: 12em;
+}
+#content {
+  width: auto;
+}
 
-#left-column .hidden .content,
-#right-column .hidden .content
-{
+.block-region .hidden .content {
   display: none;
 }
 
@@ -2194,24 +2197,6 @@
 .topics-format .block_calendar_month .minicalendar td {
   padding: 0.1em 0 0.1em 1px;
 }
-.weeks-format #middle-column ,
-.topics-format #middle-column {
-  margin: 0 12.5em 0 12.5em;
-}
-.weeks-format #left-column,
-.weeks-format #right-column,
-.topics-format #left-column,
-.topics-format #right-column {
-  width: 11.5em;
-}
-.weeks-format #left-column,
-.topics-format #left-column {
-  float: left;
-}
-.weeks-format #right-column,
-.topics-format #right-column {
-  float: right;
-}
 .weeks li.section ,
 .topics li.section {
   margin-bottom: 0.5em;
@@ -2334,20 +2319,20 @@
   margin-bottom: 15px;
 }
 
-body#admin-course-index #middle-column .editcourse {
+body#admin-course-index .editcourse {
   margin-left:auto;
   margin-right:auto;
   margin-top:20px;
   margin-bottom:20px;
 }
 
-body#admin-course-index #middle-column .editcourse th,
-body#admin-course-index #middle-column .editcourse td {
+body#admin-course-index .editcourse th,
+body#admin-course-index .editcourse td {
   padding-left:10px;
   padding-right:10px;
 }
 
-body#admin-course-index #middle-column .editcourse .count {
+body#admin-course-index .editcourse .count {
   text-align:right;
 }
 
@@ -4366,16 +4351,6 @@
 #passwordform {
   margin: 1em 0;
 }
-#mod-quiz-attempt #middle-column,
-#mod-quiz-review #middle-column {
-  text-align: center;
-  margin: 0 0 0 12.5em;
-}
-#mod-quiz-attempt #left-column,
-#mod-quiz-review #left-column {
-  width: 11.5em;
-  float: left;
-}
 #mod-quiz-attempt .submitbtns,
 #mod-quiz-review .submitbtns {
   text-align: left;
@@ -4603,10 +4578,6 @@
   text-align: center;
   margin: 6px 0;
 }
-#mod-quiz-attempt #left-column,
-#mod-quiz-review #left-column {
-  padding-top: 1px;
-}
 #quiznavigation .qnbutton {
   display: block;
   float: left;
Index: theme/standard/styles_ie7.css
===================================================================
RCS file: /cvsroot/moodle/moodle/theme/standard/styles_ie7.css,v
retrieving revision 1.15
diff -u -r1.15 styles_ie7.css
--- theme/standard/styles_ie7.css	26 Nov 2008 04:03:45 -0000	1.15
+++ theme/standard/styles_ie7.css	8 Jul 2009 12:41:43 -0000
@@ -56,9 +56,6 @@
 form.mform .fcheckbox input {
   margin-left: -3px;
 }
-#mod-quiz-review #middle-column {
-  height: 1%;
-}
 .mod-quiz div.tabtree a span img.iconsmall {
   margin: 0;
   vertical-align: baseline;
Index: theme/standard/layout.php
===================================================================
RCS file: /cvsroot/moodle/moodle/theme/standard/layout.php,v
retrieving revision 1.1
diff -u -r1.1 layout.php
--- theme/standard/layout.php	26 Jun 2009 09:06:17 -0000	1.1
+++ theme/standard/layout.php	8 Jul 2009 12:41:43 -0000
@@ -27,9 +27,26 @@
 <?php } ?>
 <!-- END OF HEADER -->
 
-    <div id="content" class="clearfix">
-        [MAIN CONTENT GOES HERE]
-    </div>
+<!-- Note, we will not be using tables for layout evenutally. However, for now
+     I have enough other things to worry about that I don't have time to make
+     a multi-column cross-browser layout too, so this is a temporary hack. -->
+    <table id="layout-table" summary="layout">
+        <tr>
+            <?php if ($PAGE->blocks->region_has_content('side-pre')) { ?>
+            <td id="region-side-pre" class="block-region">
+                <?php echo $OUTPUT->blocks_for_region('side-pre') ?>
+            </td>
+            <?php } ?>
+            <td id="content">
+                [MAIN CONTENT GOES HERE]
+            </td>
+            <?php if ($PAGE->blocks->region_has_content('side-post')) { ?>
+            <td id="region-side-post" class="block-region">
+                <?php echo $OUTPUT->blocks_for_region('side-post') ?>
+            </td>
+            <?php } ?>
+        </tr>
+    </table>
 
 <!-- START OF FOOTER -->
     <div id="footer" class="clearfix">
Index: mod/quiz/attempt.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/attempt.php,v
retrieving revision 1.162
diff -u -r1.162 attempt.php
--- mod/quiz/attempt.php	12 Jun 2009 12:13:07 -0000	1.162
+++ mod/quiz/attempt.php	8 Jul 2009 12:41:41 -0000
@@ -76,6 +76,11 @@
 
 /// Print the quiz page ////////////////////////////////////////////////////////
 
+    // Arrange for the navigation to be displayed.
+    $navbc = $attemptobj->get_navigation_panel('quiz_attempt_nav_panel', $page);
+    $firstregion = reset($PAGE->blocks->get_regions());
+    $PAGE->blocks->add_pretend_block($navbc, $firstregion);
+
     // Print the page header
     $PAGE->requires->yui_lib('event');
     $title = get_string('attempt', 'quiz', $attemptobj->get_attempt_number());
@@ -126,18 +131,6 @@
     echo $PAGE->requires->js_function_call('init_quiz_form')->asap();
     echo '<div>';
 
-/// Print the navigation panel in a left column.
-    print_container_start();
-    echo '<div id="left-column">';
-    $attemptobj->print_navigation_panel('quiz_attempt_nav_panel', $page);
-    echo '</div>';
-    print_container_end();
-
-/// Start the main column.
-    echo '<div id="middle-column">';
-    print_container_start();
-    echo skip_main_destination();
-
 /// Print all the questions
     foreach ($attemptobj->get_question_ids($page) as $id) {
         $attemptobj->print_question($id, false, $attemptobj->attempt_url($id, $page));
@@ -167,16 +160,10 @@
     echo '<input type="hidden" name="questionids" value="' .
             implode(',', $attemptobj->get_question_ids($page)) . "\" />\n";
 
-    // End middle column.
-    print_container_end();
-
     // Finish the form
     echo '</div>';
-    echo '</div>';
     echo "</form>\n";
 
-    echo '<div class="clearer"></div>';
-
     // Finish the page
     $accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
     if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
Index: mod/quiz/review.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/review.php,v
retrieving revision 1.91
diff -u -r1.91 review.php
--- mod/quiz/review.php	15 Jun 2009 07:57:53 -0000	1.91
+++ mod/quiz/review.php	8 Jul 2009 12:41:43 -0000
@@ -71,6 +71,11 @@
         $strreviewtitle = get_string('reviewofattempt', 'quiz', $attemptobj->get_attempt_number());
     }
 
+/// Arrange for the navigation to be displayed.
+    $navbc = $attemptobj->get_navigation_panel('quiz_review_nav_panel', $page);
+    $firstregion = reset($PAGE->blocks->get_regions());
+    $PAGE->blocks->add_pretend_block($navbc, $firstregion);
+
 /// Print the page header
     $PAGE->requires->js('mod/quiz/quiz.js');
     $headtags = $attemptobj->get_html_head_contributions($page);
@@ -100,17 +105,6 @@
     }
     print_heading($strreviewtitle);
 
-/// Print the navigation panel in a left column.
-    print_container_start();
-    echo '<div id="left-column">';
-    $attemptobj->print_navigation_panel('quiz_review_nav_panel', $page);
-    echo '</div>';
-    print_container_end();
-
-/// Start the main column.
-    echo '<div id="middle-column">';
-    echo skip_main_destination();
-
 /// Summary table start ============================================================================
 
 /// Work out some time-related things.
@@ -247,11 +241,6 @@
     }
     echo "</div>";
 
-    // End middle column.
-    echo '</div>';
-
-    echo '<div class="clearer"></div>';
-
     // Finish the page
     if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
         print_footer('empty');
Index: mod/quiz/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/view.php,v
retrieving revision 1.167
diff -u -r1.167 view.php
--- mod/quiz/view.php	25 Jun 2009 06:58:43 -0000	1.167
+++ mod/quiz/view.php	8 Jul 2009 12:41:43 -0000
@@ -57,8 +57,6 @@
 
 /// Initialize $PAGE, compute blocks
     $PAGE->set_url('mod/quiz/view.php', array('id' => $cm->id));
-    $pageblocks = blocks_setup($PAGE);
-    $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
 
     $edit = optional_param('edit', -1, PARAM_BOOL);
     if ($edit != -1 && $PAGE->user_allowed_editing()) {
@@ -88,20 +86,6 @@
     $navigation = build_navigation(array(), $cm);
     print_header($title, $course->fullname, $navigation, '', '', true, $buttons, navmenu($course, $cm), false, $bodytags);
 
-/// Print any blocks on the left of the page.
-    echo '<table id="layout-table"><tr>';
-    if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
-        echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
-        print_container_start();
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-        print_container_end();
-        echo "</td>\n";
-    }
-
-/// Start the main part of the page
-    echo '<td id="middle-column">';
-    print_container_start();
-
 /// Print heading and tabs (if there is more than one).
     $currenttab = 'info';
     include('tabs.php');
@@ -133,7 +117,8 @@
     if (isguestuser()) {
         notice_yesno('<p>' . get_string('guestsno', 'quiz') . "</p>\n\n<p>" .
                 get_string('liketologin') . "</p>\n", get_login_url(), get_referer(false));
-        finish_page($course);
+        print_footer($course);
+        exit;
     }
 
 /// If they are not enrolled in this course in a good enough role, tell them to enrol.
@@ -141,7 +126,8 @@
         print_box('<p>' . get_string('youneedtoenrol', 'quiz') . "</p>\n\n<p>" .
                 print_continue($CFG->wwwroot . '/course/view.php?id=' . $course->id, true) .
                 "</p>\n", 'generalbox', 'notice');
-        finish_page($course);
+        print_footer($course);
+        exit;
     }
 
 /// Get this user's attempts.
@@ -398,23 +384,10 @@
     }
     print_box_end();
 
-    // Should we not be seeing if we need to print right-hand-side blocks?
-
-    finish_page($course);
-    
     // Mark module as viewed (note, we do this here and not in finish_page,
     // otherwise the 'not enrolled' error conditions would result in marking 
     // 'viewed', I think it's better if they don't.)
     $completion=new completion_info($course);
-    $completion->set_module_viewed(cm);
-
-// Utility functions =================================================================
+    $completion->set_module_viewed($cm);
 
-function finish_page($course) {
-    global $THEME;
-    print_container_end();
-    echo '</td></tr></table>';
     print_footer($course);
-    exit;
-}
-?>
Index: mod/quiz/attemptlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/attemptlib.php,v
retrieving revision 1.39
diff -u -r1.39 attemptlib.php
--- mod/quiz/attemptlib.php	12 Jun 2009 12:13:07 -0000	1.39
+++ mod/quiz/attemptlib.php	8 Jul 2009 12:41:42 -0000
@@ -707,9 +707,9 @@
                 $this->context, $this->cm);
     }
 
-    public function print_navigation_panel($panelclass, $page) {
+    public function get_navigation_panel($panelclass, $page) {
         $panel = new $panelclass($this, $this->get_review_options(), $page);
-        $panel->display();
+        return $panel->get_contents();
     }
 
     /// List of all this user's attempts for people who can see reports.
@@ -807,8 +807,13 @@
             $page = 0;
         }
         $fragment = '';
-        if ($questionid && $questionid != reset($this->pagequestionids[$page])) {
-            $fragment = '#q' . $questionid;
+        if ($questionid) {
+            if ($questionid == reset($this->pagequestionids[$page])) {
+                // First question on page, go to top.
+                $fragment = '#';
+            } else {
+                $fragment = '#q' . $questionid;
+            }
         }
         $param = '';
         if ($showall) {
@@ -936,15 +941,19 @@
         return $classes;
     }
 
-    public function display() {
-        $strquiznavigation = get_string('quiznavigation', 'quiz');
+    public function get_contents() {
         $content = '';
         if ($this->attemptobj->get_quiz()->showuserpicture) {
             $content .= $this->get_user_picture() . "\n";
         }
         $content .= $this->get_question_buttons() . "\n";
         $content .= '<div class="othernav">' . "\n" . $this->get_end_bits() . "\n</div>\n";
-        print_side_block($strquiznavigation, $content, NULL, NULL, '', array('id' => 'quiznavigation'), $strquiznavigation);
+
+        $bc = new block_contents();
+        $bc->id = 'quiznavigation';
+        $bc->title = get_string('quiznavigation', 'quiz');
+        $bc->content = $content;
+        return $bc;
     }
 }
 
Index: mod/quiz/locallib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/locallib.php,v
retrieving revision 1.180
diff -u -r1.180 locallib.php
--- mod/quiz/locallib.php	3 Jul 2009 07:55:31 -0000	1.180
+++ mod/quiz/locallib.php	8 Jul 2009 12:41:43 -0000
@@ -362,39 +362,6 @@
     return $layout.'0';
 }
 
-/**
- * Print navigation panel for quiz attempt and review pages
- *
- * @param integer $page     The number of the current page (counting from 0).
- * @param integer $pages    The total number of pages.
- */
-function quiz_print_navigation_panel($page, $pages) {
-    //$page++;
-    echo '<div class="paging pagingbar">';
-    echo '<span class="title">' . get_string('page') . ':</span>';
-    if ($page > 0) {
-        // Print previous link
-        $strprev = get_string('previous');
-        echo '<a class="previous" href="javascript:navigate(' . ($page - 1) . ');" title="'
-         . $strprev . '">(' . $strprev . ')</a>';
-    }
-    for ($i = 0; $i < $pages; $i++) {
-        if ($i == $page) {
-            echo '<span class="thispage">'.($i+1).'</span>';
-        } else {
-            echo '<a href="javascript:navigate(' . ($i) . ');">'.($i+1).'</a>';
-        }
-    }
-
-    if ($page < $pages - 1) {
-        // Print next link
-        $strnext = get_string('next');
-        echo '<a class="next" href="javascript:navigate(' . ($page + 1) . ');" title="'
-         . $strnext . '">(' . $strnext . ')</a>';
-    }
-    echo '</div>';
-}
-
 /// Functions to do with quiz grades //////////////////////////////////////////
 
 /**
Index: mod/quiz/accessrules.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/quiz/accessrules.php,v
retrieving revision 1.23
diff -u -r1.23 accessrules.php
--- mod/quiz/accessrules.php	2 Jul 2009 06:46:47 -0000	1.23
+++ mod/quiz/accessrules.php	8 Jul 2009 12:41:41 -0000
@@ -158,6 +158,7 @@
     }
 
     public function show_attempt_timer_if_needed($attempt, $timenow) {
+        global $PAGE;
         $timeleft = false;
         foreach ($this->_rules as $rule) {
             $ruletimeleft = $rule->time_left($attempt, $timenow);
Index: lang/en_utf8/moodle.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/moodle.php,v
retrieving revision 1.240
diff -u -r1.240 moodle.php
--- lang/en_utf8/moodle.php	3 Jul 2009 09:03:50 -0000	1.240
+++ lang/en_utf8/moodle.php	8 Jul 2009 12:41:33 -0000
@@ -21,7 +21,9 @@
 $string['add'] = 'Add';
 $string['addactivity'] = 'Add an activity...';
 $string['addadmin'] = 'Add admin';
+$string['addblock'] = 'Add a block';
 $string['addcreator'] = 'Add course creator';
+$string['adddots'] = 'Add...';
 $string['added'] = 'Added $a';
 $string['addedrecip'] = 'Added $a new recipient';
 $string['addedrecips'] = 'Added $a new recipients';
@@ -217,6 +219,7 @@
 $string['childcourses'] = 'Child courses';
 $string['choose'] = 'Choose';
 $string['choosecourse'] = 'Choose a course';
+$string['choosedots'] = 'Choose...';
 $string['chooseenrolmethod'] = 'Choose enrolment plugin';
 $string['chooselivelogs'] = 'Or watch current activity';
 $string['chooselogs'] = 'Choose which logs you want to see';
@@ -1105,6 +1108,7 @@
 $string['next'] = 'Next';
 $string['nextsection'] = 'Next section';
 $string['no'] = 'No';
+$string['noblockstoaddhere'] = 'There are no blocks that you can add to this page.';
 $string['nobody'] = 'Nobody';
 $string['nochange'] = 'No change';
 $string['nocoursesfound'] = 'No courses were found with the words \'$a\'';
Index: admin/settings/plugins.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/settings/plugins.php,v
retrieving revision 1.42
diff -u -r1.42 plugins.php
--- admin/settings/plugins.php	19 Jun 2009 14:26:00 -0000	1.42
+++ admin/settings/plugins.php	8 Jul 2009 12:41:31 -0000
@@ -44,7 +44,6 @@
 
     $ADMIN->add('modules', new admin_category('blocksettings', get_string('blocks')));
     $ADMIN->add('blocksettings', new admin_page_manageblocks());
-    $ADMIN->add('blocksettings', new admin_externalpage('stickyblocks', get_string('stickyblocks', 'admin'), "$CFG->wwwroot/$CFG->admin/stickyblocks.php"));
     if ($blocks = $DB->get_records('block')) {
         $blockbyname = array();
 
Index: course/rest.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/rest.php,v
retrieving revision 1.16
diff -u -r1.16 rest.php
--- course/rest.php	13 Jun 2009 17:17:11 -0000	1.16
+++ course/rest.php	8 Jul 2009 12:41:31 -0000
@@ -25,25 +25,10 @@
     die;
 }
 
-$PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
-$pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
-
-if (!empty($instanceid)) {
-    throw new moodle_exception('ajax blocks editing currently broken. MDL-19010');
-//    $blockinstance = blocks_find_instance($instanceid, $pageblocks);
-//    if (!$blockinstance || $blockinstance->pageid != $course->id
-//                        || $blockinstance->pagetype != 'course-view') {
-//        error_log('AJAX commands.php: Bad block ID '.$instanceid);
-//        die;
-//    }
-}
-
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
 require_login($course);
 require_capability('moodle/course:update', $context);
 
-
-
 // OK, now let's process the parameters and do stuff
 switch($_SERVER['REQUEST_METHOD']) {
     case 'POST':
Index: mod/resource/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/resource/lib.php,v
retrieving revision 1.120
diff -u -r1.120 lib.php
--- mod/resource/lib.php	2 Jul 2009 15:01:22 -0000	1.120
+++ mod/resource/lib.php	8 Jul 2009 12:41:43 -0000
@@ -108,27 +108,11 @@
 
     /**
      * Display the resource with the course blocks.
-     *
-     * @global stdClass
-     * @uses PAGE_COURSE_VIEW
-     * @uses PARAM_BOOL
-     * @uses BLOCK_POS_LEFT
-     * @uses BLOCK_POS_RIGHT
      */
     function display_course_blocks_start() {
-        global $CFG, $USER, $THEME;
-
-        require_once($CFG->dirroot.'/course/lib.php'); //required by some blocks
-
-        $PAGE = page_create_object(PAGE_COURSE_VIEW, $this->course->id);
-        $PAGE->set_url('mod/resource/view.php', array('id' => $this->cm->id));
-        $this->PAGE = $PAGE;
-        $pageblocks = blocks_setup($PAGE);
-
-        $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
+        global $CFG, $USER, $PAGE;
 
     /// Print the page header
-
         $edit = optional_param('edit', -1, PARAM_BOOL);
 
         if (($edit != -1) and $PAGE->user_allowed_editing()) {
@@ -140,53 +124,11 @@
 
         $PAGE->print_header($this->course->shortname.': %fullname%', $morenavlinks, "", "",
                             update_module_button($this->cm->id, $this->course->id, $this->strresource));
-
-        echo '<table id="layout-table"><tr>';
-
-            $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
-        foreach ($lt as $column) {
-            $lt1[] = $column;
-            if ($column == 'middle') break;
-        }
-        foreach ($lt1 as $column) {
-            switch ($column) {
-                case 'left':
-                    if((blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
-                        echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
-                        print_container_start();
-                        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-                        print_container_end();
-                        echo '</td>';
-                    }
-                break;
-
-                case 'middle':
-                    echo '<td id="middle-column">';
-                    print_container_start(false, 'middle-column-wrap');
-                    echo '<div id="resource">';
-                break;
-
-                case 'right':
-                    if((blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing())) {
-                        echo '<td style="width: '.$blocks_preferred_width.'px;" id="right-column">';
-                        print_container_start();
-                        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
-                        print_container_end();
-                        echo '</td>';
-                    }
-                break;
-            }
-        }
     }
 
 
     /**
      * Finish displaying the resource with the course blocks
-     *
-     * @global stdClass
-     * @global object
-     * @uses BLOCK_POS_LEFT
-     * @uses BLOCK_POS_RIGHT
      */
     function display_course_blocks_end() {
         global $CFG, $THEME;
Index: course/format/weeks/format.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/format/weeks/format.php,v
retrieving revision 1.93
diff -u -r1.93 format.php
--- course/format/weeks/format.php	2 Jul 2009 10:53:32 -0000	1.93
+++ course/format/weeks/format.php	8 Jul 2009 12:41:31 -0000
@@ -57,44 +57,6 @@
     }
 
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
-/* Internet Explorer min-width fix. (See theme/standard/styles_layout.css: min-width for Firefox.)
-   Window width: 800px, Firefox 763px, IE 752px. (Window width: 640px, Firefox 602px, IE 588px.)    
-*/
-?>
-
-<!--[if IE]>
-  <style type="text/css">
-  .weeks-format { width: expression(document.body.clientWidth < 800 ? "752px" : "auto"); }
-  </style>
-<![endif]-->
-<?php
-/// Layout the whole page as three big columns (was, id="layout-table")
-    echo '<div class="weeks-format">';
-
-/// The left column ...
-
-    if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
-        print_container_start();
-        echo '<div id="left-column">';
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-        echo '</div>';
-        print_container_end();
-    }
-    
-/// The right column, BEFORE the middle-column.
-    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
-        print_container_start();
-        echo '<div id="right-column">';
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
-        echo '</div>';
-        print_container_end();
-    }
-
-/// Start main column
-    echo '<div id="middle-column">';
-    print_container_start();
-
-    echo skip_main_destination();
 
     //Print the Your progress icon if the track completion is enabled
     $completioninfo = new completion_info($course);
@@ -123,7 +85,7 @@
 
         // Note, 'right side' is BEFORE content.
         echo '<li id="section-0" class="section main" >';
-	echo '<div class="left side">&nbsp;</div>';
+        echo '<div class="left side">&nbsp;</div>';
         echo '<div class="right side" >&nbsp;</div>';        
         echo '<div class="content">';
         
@@ -286,11 +248,3 @@
                    'sectionmenu', '', get_string('jumpto'), '', '', true);
         echo '</div>';
     }
-
-    print_container_end();
-    echo '</div>';
-
-    echo '</div>';
-    echo '<div class="clearer"></div>';
-
-?>
Index: tag/search.php
===================================================================
RCS file: /cvsroot/moodle/moodle/tag/search.php,v
retrieving revision 1.16
diff -u -r1.16 search.php
--- tag/search.php	14 Jan 2009 08:49:35 -0000	1.16
+++ tag/search.php	8 Jul 2009 12:41:43 -0000
@@ -14,6 +14,18 @@
 $page    = optional_param('page', 0, PARAM_INT); // which page to show
 $perpage = optional_param('perpage', 18, PARAM_INT);
 
+$params = array();
+if ($query) {
+    $params['query'] = $query;
+}
+if ($page) {
+    $params['page'] = $page;
+}
+if ($perpage) {
+    $params['perpage'] = $perpage;
+}
+$PAGE->set_url('tag/search.php', $params);
+
 $navlinks = array();
 $navlinks[] = array('name' => get_string('tags', 'tag'), 'link' => "{$CFG->wwwroot}/tag/search.php", 'type' => '');
 $navigation = build_navigation($navlinks);
Index: tag/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/tag/index.php,v
retrieving revision 1.35
diff -u -r1.35 index.php
--- tag/index.php	6 May 2009 09:11:07 -0000	1.35
+++ tag/index.php	8 Jul 2009 12:41:43 -0000
@@ -33,7 +33,6 @@
 $PAGE->set_url('tag/index.php', array('id' => $tag->id));
 $PAGE->set_subpage($tag->id);
 $PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
-$pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH);
 
 if (($edit != -1) and $PAGE->user_allowed_editing()) {
     $USER->editing = $edit;
@@ -61,23 +60,6 @@
     echo '<div class="managelink"><a href="'. $CFG->wwwroot .'/tag/manage.php">'. get_string('managetags', 'tag') .'</a></div>' ;
 }
 
-echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
-echo '<tr valign="top">';
-
-//----------------- left column -----------------
-
-$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
-
-if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) {
-    echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
-    blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-    echo '</td>';
-}
-
-//----------------- middle column -----------------
-
-echo '<td valign="top" id="middle-column">';
-
 $tagname  = tag_display_name($tag);
 
 if ($tag->flag > 0 && has_capability('moodle/tag:manage', $systemcontext)) {
@@ -168,20 +150,5 @@
     print_box_end();
 }
 
-echo '</td>';
-
-//----------------- right column -----------------
-
-$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
-
-if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing()) {
-    echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="right-column">';
-    blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
-    echo '</td>';
-}
-
-/// Finish the page
-echo '</tr></table>';
-
 print_footer();
 ?>
Index: course/format/scorm/format.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/format/scorm/format.php,v
retrieving revision 1.13
diff -u -r1.13 format.php
--- course/format/scorm/format.php	22 Oct 2007 06:43:02 -0000	1.13
+++ course/format/scorm/format.php	8 Jul 2009 12:41:31 -0000
@@ -5,53 +5,13 @@
     $module = $course->format;
     require_once($CFG->dirroot.'/mod/'.$module.'/locallib.php');
 
-    // Bounds for block widths
-    // more flexible for theme designers taken from theme config.php
-    $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
-    $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
-    $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
-    $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
-
-    define('BLOCK_L_MIN_WIDTH', $lmin);
-    define('BLOCK_L_MAX_WIDTH', $lmax);
-    define('BLOCK_R_MIN_WIDTH', $rmin);
-    define('BLOCK_R_MAX_WIDTH', $rmax);
-  
-    $preferred_width_left  = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),  
-                                            BLOCK_L_MAX_WIDTH);
-    $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 
-                                            BLOCK_R_MAX_WIDTH);
-
     $strgroups  = get_string('groups');
     $strgroupmy = get_string('groupmy');
     $editing    = $PAGE->user_is_editing();
 
-    echo '<table id="layout-table" cellspacing="0" summary="'.get_string('layouttable').'">';
-    echo '<tr>';
-
-    if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
-        echo '<td style="width:'.$preferred_width_left.'px" id="left-column">';
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-        echo '</td>';
-    }
-
-    echo '<td id="middle-column">'. skip_main_destination();
     $moduleformat = $module.'_course_format_display';
     if (function_exists($moduleformat)) {
         $moduleformat($USER,$course);
     } else { 
         notify('The module '. $module. ' does not support single activity course format');
     }
-    echo '</td>';
-
-    // The right column
-    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
-        echo '<td style="width:'.$preferred_width_right.'px" id="right-column">';
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
-        echo '</td>';
-    }
-
-    echo '</tr>';
-    echo '</table>';
-
-?>
Index: admin/stickyblocks.php
===================================================================
RCS file: admin/stickyblocks.php
diff -N admin/stickyblocks.php
--- admin/stickyblocks.php	6 May 2009 09:23:38 -0000	1.23
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,90 +0,0 @@
-<?PHP // $Id: stickyblocks.php,v 1.23 2009/05/06 09:23:38 tjhunt Exp $
-
-    require_once('../config.php');
-    require_once($CFG->dirroot.'/lib/pagelib.php');
-
-    $pt  = optional_param('pt', null, PARAM_SAFEDIR); //alhanumeric and -
-
-    $pagetypes = array('my-index' => array('id' => 'my-index',
-                                              'lib' => '/lib/pagelib.php',
-                                              'name' => get_string('mymoodle','admin')),
-                       PAGE_COURSE_VIEW => array('id' => PAGE_COURSE_VIEW,
-                                                'lib' => '/lib/pagelib.php',
-                                                'name' => get_string('stickyblockscourseview','admin'))
-                       // ... more?
-                       );
-
-    // for choose_from_menu
-    $options = array();
-    foreach ($pagetypes as $p) {
-        $options[$p['id']] = $p['name'];
-    }
-
-    require_login();
-
-    require_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM));
-
-    // first thing to do is print the dropdown menu
-
-    $strtitle = get_string('stickyblocks','admin');
-    $strheading = get_string('adminhelpstickyblocks');
-
-
-
-    if (!empty($pt)) {
-
-        require_once($CFG->dirroot.$pagetypes[$pt]['lib']);
-
-        define('ADMIN_STICKYBLOCKS',$pt);
-
-        $PAGE = page_create_object($pt, SITEID);
-        $blocks = blocks_setup($PAGE, BLOCKS_PINNED_TRUE);
-        $blocks_preferred_width = bounded_number(180, blocks_preferred_width($blocks[BLOCK_POS_LEFT]), 210);
-
-        $navlinks = array(array('name' => get_string('administration'),
-                                'link' => "$CFG->wwwroot/$CFG->admin/index.php",
-                                'type' => 'misc'));
-        $navlinks[] = array('name' => $strtitle, 'link' => null, 'type' => 'misc');
-        $navigation = build_navigation($navlinks);
-        print_header($strtitle,$strtitle,$navigation);
-
-        echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
-        echo '<tr valign="top">';
-
-        echo '<td valign="top" style="width: '.$blocks_preferred_width.'px;" id="left-column">';
-        print_container_start();
-        blocks_print_group($PAGE, $blocks, BLOCK_POS_LEFT);
-        print_container_end();
-        echo '</td>';
-        echo '<td valign="top" id="middle-column">';
-        print_container_start();
-
-    } else {
-        require_once($CFG->libdir.'/adminlib.php');
-        admin_externalpage_setup('stickyblocks');
-        admin_externalpage_print_header();
-    }
-
-
-    print_box_start();
-    print_heading($strheading);
-    popup_form("$CFG->wwwroot/$CFG->admin/stickyblocks.php?pt=", $options, 'selecttype', $pt, 'choose', '', '', false, 'self', get_string('stickyblockspagetype','admin').': ');
-    echo '<p>'.get_string('stickyblocksduplicatenotice','admin').'</p>';
-    print_box_end();
-
-
-    if (!empty($pt)) {
-        print_container_end();
-        echo '</td>';
-        echo '<td valign="top" style="width: '.$blocks_preferred_width.'px;" id="right-column">';
-        print_container_start();
-        blocks_print_group($PAGE, $blocks, BLOCK_POS_RIGHT);
-        print_container_end();
-        echo '</td>';
-        echo '</tr></table>';
-        print_footer();
-    } else {
-        admin_externalpage_print_footer();
-    }
-
-?>
Index: admin/index.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/index.php,v
retrieving revision 1.391
diff -u -r1.391 index.php
--- admin/index.php	26 Jun 2009 09:38:15 -0000	1.391
+++ admin/index.php	8 Jul 2009 12:41:30 -0000
@@ -105,7 +105,7 @@
 $CFG->xmlstrictheaders = false;
 
 if (!core_tables_exist()) {
-    // hide errors from headers in case debug enabled in config.php
+    $PAGE->set_generaltype('maintenance');
 
     // fake some settings
     $CFG->docroot = 'http://docs.moodle.org';
@@ -127,7 +127,7 @@
         echo '<br />';
         notice_yesno(get_string('doyouagree'), "index.php?agreelicense=1&lang=$CFG->lang",
                                                "http://docs.moodle.org/en/License");
-        print_footer('upgrade');
+        print_footer();
         die;
     }
     if (empty($confirmrelease)) {
@@ -147,7 +147,7 @@
             print_continue("index.php?agreelicense=1&amp;confirmrelease=1&amp;lang=$CFG->lang");
         }
 
-        print_footer('upgrade');
+        print_footer();
         die;
     }
 
@@ -178,6 +178,8 @@
 }
 
 if ($version > $CFG->version) {  // upgrade
+    $PAGE->set_generaltype('maintenance');
+
     $a->oldversion = "$CFG->release ($CFG->version)";
     $a->newversion = "$release ($version)";
     $strdatabasechecking = get_string('databasechecking', '', $a);
@@ -187,7 +189,7 @@
         print_header($strdatabasechecking, $stradministration, $navigation, '', '', false, '&nbsp;', '&nbsp;');
 
         notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=1', 'index.php');
-        print_footer('upgrade');
+        print_footer();
         exit;
 
     } else if (empty($confirmrelease)){
@@ -212,7 +214,7 @@
             print_continue('index.php?confirmupgrade=1&amp;confirmrelease=1');
         }
 
-        print_footer('upgrade');
+        print_footer();
         die;
 
     } elseif (empty($confirmplugins)) {
Index: mod/lesson/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/lesson/view.php,v
retrieving revision 1.151
diff -u -r1.151 view.php
--- mod/lesson/view.php	8 May 2009 09:00:41 -0000	1.151
+++ mod/lesson/view.php	8 Jul 2009 12:41:41 -0000
@@ -501,10 +501,6 @@
 
         $PAGE->set_url('mod/lesson/view.php', array('id' => $cm->id, 'pageid' => $page->id));
         $PAGE->set_subpage($page->id);
-        $pageblocks = blocks_setup($PAGE);
-
-        $leftcolumnwidth  = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
-        $rightcolumnwidth = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
 
         if (($edit != -1) and $PAGE->user_allowed_editing()) {
             $USER->editing = $edit;
Index: theme/standardwhite/layout-popup.php
===================================================================
RCS file: theme/standardwhite/layout-popup.php
diff -N theme/standardwhite/layout-popup.php
--- theme/standardwhite/layout-popup.php	30 Jun 2009 07:57:41 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,34 +0,0 @@
-<?php echo $OUTPUT->doctype() ?>
-<html <?php echo $OUTPUT->htmlattributes() ?>>
-<head>
-    <title><?php echo $PAGE->title ?></title>
-    <link rel="shortcut icon" href="<?php echo $CFG->themewww .'/'. current_theme() ?>/favicon.ico" />
-    <?php echo $OUTPUT->standard_head_html() ?>
-</head>
-<body id="<?php echo $PAGE->pagetype ?>" class="<?php echo $PAGE->bodyclasses ?>">
-<?php echo $OUTPUT->standard_top_of_body_html() ?>
-
-<div id="page">
-
-<?php if ($navigation) { // This is the navigation bar with breadcrumbs  ?>
-    <div class="navbar clearfix">
-        <div class="breadcrumb"><?php print_navigation($navigation); ?></div>
-        <div class="navbutton"><?php echo $PAGE->button; ?></div>
-    </div>
-<?php } else if ($PAGE->heading) { // If no navigation, but a heading, then print a line ?>
-    <hr />
-<?php } ?>
-<!-- END OF HEADER -->
-
-    <div id="content" class="clearfix">
-        [MAIN CONTENT GOES HERE]
-    </div>
-
-<!-- START OF FOOTER -->
-    <div id="footer" class="clearfix">
-
-    </div>
-</div>
-<?php echo $OUTPUT->standard_end_of_body_html() ?>
-</body>
-</html>
\ No newline at end of file
Index: theme/standardwhite/layout-home.php
===================================================================
RCS file: theme/standardwhite/layout-home.php
diff -N theme/standardwhite/layout-home.php
--- theme/standardwhite/layout-home.php	26 Jun 2009 09:06:18 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,46 +0,0 @@
-<?php echo $OUTPUT->doctype() ?>
-<html <?php echo $OUTPUT->htmlattributes() ?>>
-<head>
-    <?php echo $OUTPUT->standard_head_html() ?>
-    <title><?php echo $PAGE->title ?></title>
-    <link rel="shortcut icon" href="<?php echo $CFG->themewww .'/'. current_theme() ?>/favicon.ico" />
-    <meta name="description" content="<?php echo strip_tags(format_text($SITE->summary, FORMAT_HTML)) ?>" />
-</head>
-<body id="<?php echo $PAGE->pagetype ?>" class="<?php echo $PAGE->bodyclasses ?>">
-<?php echo $OUTPUT->standard_top_of_body_html() ?>
-
-<div id="page">
-
-    <div id="header-home" class="clearfix">
-        <h1 class="headermain"><?php echo $PAGE->heading ?></h1>
-        <div class="headermenu"><?php
-        if ($menu) {
-            echo $menu;
-        } else {
-            echo $OUTPUT->login_info();
-        }
-        ?></div>
-    </div>
-    <hr />
-<!-- END OF HEADER -->
-
-    <div id="content" class="clearfix">
-        [MAIN CONTENT GOES HERE]
-    </div>
-
-<!-- START OF FOOTER -->
-    <div id="footer" class="clearfix">
-        <p class="helplink">
-        <?php echo page_doc_link(get_string('moodledocslink')) ?>
-        </p>
-
-        <?php
-        echo $OUTPUT->login_info();
-        echo $OUTPUT->home_link();
-        echo $OUTPUT->standard_footer_html();
-        ?>
-    </div>
-</div>
-<?php echo $OUTPUT->standard_end_of_body_html() ?>
-</body>
-</html>
\ No newline at end of file
Index: mod/chat/view.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/chat/view.php,v
retrieving revision 1.83
diff -u -r1.83 view.php
--- mod/chat/view.php	6 May 2009 09:29:06 -0000	1.83
+++ mod/chat/view.php	8 Jul 2009 12:41:40 -0000
@@ -62,11 +62,6 @@
 // Initialize $PAGE, compute blocks
     $PAGE->set_url('mod/chat/view.php', array('id' => $cm->id));
 
-    // Note: MDL-19010 there will be further changes to printing header and blocks.
-    // The code will be much nicer than this eventually.
-    $pageblocks = blocks_setup($PAGE);
-    $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
-
 /// Print the page header
     $strenterchat    = get_string('enterchat', 'chat');
     $stridle         = get_string('idle', 'chat');
@@ -91,133 +86,103 @@
     $navigation = build_navigation(array(), $cm);
     print_header($title, $course->fullname, $navigation, '', '', true, $buttons, navmenu($course, $cm));
 
-    echo '<table id="layout-table"><tr>';
+    /// Check to see if groups are being used here
+    $groupmode = groups_get_activity_groupmode($cm);
+    $currentgroup = groups_get_activity_group($cm, true);
+    groups_print_activity_menu($cm, "view.php?id=$cm->id");
+
+    if ($currentgroup) {
+        $groupselect = " AND groupid = '$currentgroup'";
+        $groupparam = "&amp;groupid=$currentgroup";
+    } else {
+        $groupselect = "";
+        $groupparam = "";
+    }
+
+    if ($chat->studentlogs or has_capability('mod/chat:readlog',$context)) {
+        if ($msg = $DB->get_records_select('chat_messages', "chatid = ? $groupselect", array($chat->id))) {
+            echo '<div class="reportlink">';
+            echo "<a href=\"report.php?id=$cm->id\">".
+                get_string('viewreport', 'chat').'</a>';
+            echo '</div>';
+        }
+    }
 
-    $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
-    foreach ($lt as $column) {
-        switch ($column) {
-            case 'left':
-
-                if(!empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing())) {
-                    echo '<td style="width: '.$blocks_preferred_width.'px;" id="left-column">';
-                    print_container_start();
-                    blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-                    print_container_end();
-                    echo '</td>';
-                }
-                break;
-
-            case 'middle':
-
-                echo '<td id="middle-column">';
-                print_container_start();
-
-                /// Check to see if groups are being used here
-                $groupmode = groups_get_activity_groupmode($cm);
-                $currentgroup = groups_get_activity_group($cm, true);
-                groups_print_activity_menu($cm, "view.php?id=$cm->id");
-
-                if ($currentgroup) {
-                    $groupselect = " AND groupid = '$currentgroup'";
-                    $groupparam = "&amp;groupid=$currentgroup";
-                } else {
-                    $groupselect = "";
-                    $groupparam = "";
-                }
-
-                if ($chat->studentlogs or has_capability('mod/chat:readlog',$context)) {
-                    if ($msg = $DB->get_records_select('chat_messages', "chatid = ? $groupselect", array($chat->id))) {
-                        echo '<div class="reportlink">';
-                        echo "<a href=\"report.php?id=$cm->id\">".
-                            get_string('viewreport', 'chat').'</a>';
-                        echo '</div>';
-                    }
-                }
-
-
-                print_heading(format_string($chat->name));
-
-                if (has_capability('mod/chat:chat',$context)) {
-                    /// Print the main part of the page
-                    print_box_start('generalbox', 'enterlink');
-                    // users with screenreader set, will only see 1 link, to the manual refresh page
-                    // for better accessibility
-                    if (!empty($USER->screenreader)) {
-                        $chattarget = "/mod/chat/gui_basic/index.php?id=$chat->id$groupparam";
-                    } else {
-                        $chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam"; 
-                    }
-
-                    echo '<p>';
-                    link_to_popup_window ($chattarget,
-                            "chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, get_string('modulename', 'chat'));
-                    echo '</p>';
-
-                    if ($CFG->enableajax) {
-                        echo '<p>';
-                        link_to_popup_window ("/mod/chat/gui_ajax/index.php?id=$chat->id$groupparam",
-                            "chat$course->id$chat->id$groupparam", get_string('ajax_gui', 'message'), 500, 700, get_string('modulename', 'chat'));
-                        echo '</p>';
-                    }
-
-                    // if user is using screen reader, then there is no need to display this link again
-                    if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) {
-                        // show frame/js-less alternative
-                        echo '<p>(';
-                        link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
-                            "chat$course->id$chat->id$groupparam", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat'));
-                        echo ')</p>';
-                    }
-
-                    print_box_end();
-
-                } else {
-                    print_box_start('generalbox', 'notallowenter');
-                    echo '<p>'.get_string('notallowenter', 'chat').'</p>';
-                    print_box_end();
-                }
-
-                if ($chat->chattime and $chat->schedule) {  // A chat is scheduled
-                    echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
-                } else {
-                    echo '<br />';
-                }
-
-                if ($chat->intro) {
-                    print_box(format_module_intro('chat', $chat, $cm->id), 'generalbox', 'intro');
-                }
-
-                chat_delete_old_users();
-
-                if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
-                    $timenow = time();
-                    print_simple_box_start('center');
-                    print_heading($strcurrentusers);
-                    echo '<table id="chatcurrentusers">';
-                    foreach ($chatusers as $chatuser) {
-                        $lastping = $timenow - $chatuser->lastmessageping;
-                        echo '<tr><td class="chatuserimage">';
-                        echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
-                        print_user_picture($chatuser, 0, $chatuser->picture, false, false, false);
-                        echo '</a></td><td class="chatuserdetails">';
-                        echo '<p>';
-                        echo fullname($chatuser).'<br />';
-                        echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
-                        echo '</p>';
-                        echo '</td></tr>';
-                    }
-                    echo '</table>';
-                    print_simple_box_end();
-                }
 
-                print_container_end();
-                echo '</td>';
+    print_heading(format_string($chat->name));
+
+    if (has_capability('mod/chat:chat',$context)) {
+        /// Print the main part of the page
+        print_box_start('generalbox', 'enterlink');
+        // users with screenreader set, will only see 1 link, to the manual refresh page
+        // for better accessibility
+        if (!empty($USER->screenreader)) {
+            $chattarget = "/mod/chat/gui_basic/index.php?id=$chat->id$groupparam";
+        } else {
+            $chattarget = "/mod/chat/gui_$CFG->chat_method/index.php?id=$chat->id$groupparam"; 
+        }
+
+        echo '<p>';
+        link_to_popup_window ($chattarget,
+                "chat$course->id$chat->id$groupparam", "$strenterchat", 500, 700, get_string('modulename', 'chat'));
+        echo '</p>';
+
+        if ($CFG->enableajax) {
+            echo '<p>';
+            link_to_popup_window ("/mod/chat/gui_ajax/index.php?id=$chat->id$groupparam",
+                "chat$course->id$chat->id$groupparam", get_string('ajax_gui', 'message'), 500, 700, get_string('modulename', 'chat'));
+            echo '</p>';
+        }
 
-                break;
+        // if user is using screen reader, then there is no need to display this link again
+        if ($CFG->chat_method == 'header_js' && empty($USER->screenreader)) {
+            // show frame/js-less alternative
+            echo '<p>(';
+            link_to_popup_window ("/mod/chat/gui_basic/index.php?id=$chat->id$groupparam",
+                "chat$course->id$chat->id$groupparam", get_string('noframesjs', 'message'), 500, 700, get_string('modulename', 'chat'));
+            echo ')</p>';
         }
+
+        print_box_end();
+
+    } else {
+        print_box_start('generalbox', 'notallowenter');
+        echo '<p>'.get_string('notallowenter', 'chat').'</p>';
+        print_box_end();
     }
 
-    echo '</tr></table>';
+    if ($chat->chattime and $chat->schedule) {  // A chat is scheduled
+        echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
+    } else {
+        echo '<br />';
+    }
+
+    if ($chat->intro) {
+        print_box(format_module_intro('chat', $chat, $cm->id), 'generalbox', 'intro');
+    }
+
+    chat_delete_old_users();
+
+    if ($chatusers = chat_get_users($chat->id, $currentgroup, $cm->groupingid)) {
+        $timenow = time();
+        print_simple_box_start('center');
+        print_heading($strcurrentusers);
+        echo '<table id="chatcurrentusers">';
+        foreach ($chatusers as $chatuser) {
+            $lastping = $timenow - $chatuser->lastmessageping;
+            echo '<tr><td class="chatuserimage">';
+            echo "<a href=\"$CFG->wwwroot/user/view.php?id=$chatuser->id&amp;course=$chat->course\">";
+            print_user_picture($chatuser, 0, $chatuser->picture, false, false, false);
+            echo '</a></td><td class="chatuserdetails">';
+            echo '<p>';
+            echo fullname($chatuser).'<br />';
+            echo "<span class=\"idletime\">$stridle: ".format_time($lastping)."</span>";
+            echo '</p>';
+            echo '</td></tr>';
+        }
+        echo '</table>';
+        print_simple_box_end();
+    }
 
     print_footer($course);
 
Index: course/format/topics/format.php
===================================================================
RCS file: /cvsroot/moodle/moodle/course/format/topics/format.php,v
retrieving revision 1.100
diff -u -r1.100 format.php
--- course/format/topics/format.php	2 Jul 2009 10:53:33 -0000	1.100
+++ course/format/topics/format.php	8 Jul 2009 12:41:31 -0000
@@ -67,45 +67,6 @@
         $strmovedown = get_string('movedown');
     }
 
-/* Internet Explorer min-width fix. (See theme/standard/styles_layout.css: min-width for Firefox.)
-   Window width: 800px, Firefox 763px, IE 752px. (Window width: 640px, Firefox 602px, IE 588px.)    
-*/
-?>
-
-<!--[if IE]>
-  <style type="text/css">
-  .topics-format { width: expression(document.body.clientWidth < 800 ? "752px" : "auto"); }
-  </style>
-<![endif]-->
-<?php
-/// Layout the whole page as three big columns (was, id="layout-table")
-    echo '<div class="topics-format">';
-
-/// The left column ...
-
-    if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
-        echo '<div id="left-column">';
-        print_container_start();
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-        print_container_end();
-        echo '</div>';
-    }
-    
-/// The right column, BEFORE the middle-column.
-    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
-        echo '<div id="right-column">';
-        print_container_start();
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
-        print_container_end();
-        echo '</div>';
-    }
-
-/// Start main column
-    echo '<div id="middle-column">';
-    print_container_start();
-
-    echo skip_main_destination();
-
     // Print the Your progress icon if the track completion is enabled
     $completioninfo = new completion_info($course);
     $completioninfo->print_help_icon();
@@ -295,11 +256,3 @@
                    'sectionmenu', '', get_string('jumpto'), '', '', true);
         echo '</div>';
     }
-
-    print_container_end();
-    echo '</div>';
-
-    echo '</div>';
-    echo '<div class="clearer"></div>';
-
-?>
Index: test.php
===================================================================
RCS file: test.php
diff -N test.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+<?php
+$things = array('block', 'mod', 'format');
+unset($things[array_search('mod', $things)]);
+echo '<pre>';
+var_dump($things);
+echo '</pre>';
+
+?>
Index: theme/standard/layout-popup.php
===================================================================
RCS file: theme/standard/layout-popup.php
diff -N theme/standard/layout-popup.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ theme/standard/layout-popup.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,41 @@
+<?php echo $OUTPUT->doctype() ?>
+<html <?php echo $OUTPUT->htmlattributes() ?>>
+<head>
+    <title><?php echo $PAGE->title ?></title>
+    <link rel="shortcut icon" href="<?php echo $CFG->themewww .'/'. current_theme() ?>/favicon.ico" />
+    <?php echo $OUTPUT->standard_head_html() ?>
+</head>
+<body id="<?php echo $PAGE->pagetype ?>" class="<?php echo $PAGE->bodyclasses ?>">
+<?php echo $OUTPUT->standard_top_of_body_html() ?>
+
+<div id="page">
+
+<?php if ($PAGE->heading) { ?>
+    <div id="header" class="clearfix">
+        <h1 class="headermain"><?php echo $PAGE->heading ?></h1>
+        <div class="headermenu"><?php echo $menu ?></div>
+    </div>
+<?php } ?>
+
+<?php if ($navigation) { // This is the navigation bar with breadcrumbs  ?>
+    <div class="navbar clearfix">
+        <div class="breadcrumb"><?php print_navigation($navigation); ?></div>
+        <div class="navbutton"><?php echo $PAGE->button; ?></div>
+    </div>
+<?php } else if ($PAGE->heading) { // If no navigation, but a heading, then print a line ?>
+    <hr />
+<?php } ?>
+<!-- END OF HEADER -->
+
+    <div id="content" class="clearfix">
+        [MAIN CONTENT GOES HERE]
+    </div>
+
+<!-- START OF FOOTER -->
+    <div id="footer" class="clearfix">
+        <?php echo $OUTPUT->standard_footer_html() ?>
+    </div>
+</div>
+<?php echo $OUTPUT->standard_end_of_body_html() ?>
+</body>
+</html>
