]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12221 reworked container autoclosing - error() and notice() do not work everywher...
authorskodak <skodak>
Fri, 14 Dec 2007 21:22:38 +0000 (21:22 +0000)
committerskodak <skodak>
Fri, 14 Dec 2007 21:22:38 +0000 (21:22 +0000)
12 files changed:
lang/en_utf8/moodle.php
lib/adminlib.php
lib/weblib.php
message/user.php
mod/chat/gui_header_js/chatinput.php
mod/chat/gui_header_js/users.php
mod/chat/gui_sockets/chatinput.php
mod/glossary/print.php
mod/resource/type/file/localfile.php
mod/resource/type/file/localpath.php
mod/resource/type/file/resource.class.php
mod/resource/type/ims/resource.class.php

index 2e4b88630af3dc12212e2cfaafff1dfd82f0c095..a1e797ec098624becdde2b4355f24c7ede289880 100644 (file)
@@ -1079,6 +1079,7 @@ $string['notenrolledprofile'] = 'This profile is not available because this user
 $string['noteuserschangednonetocourse'] = 'Note: course users need to be restored when restoring user data (in activities, files or messages). This setting has been changed for you.';
 $string['nothingnew'] = 'Nothing new since your last login';
 $string['nothingtodisplay'] = 'Nothing to display';
+$string['notice'] = 'Notice';
 $string['noticenewerbackup'] = 'This backup file has been created with Moodle $a->backuprelease ($a->backupversion) and it\'s newer than your currently installed Moodle $a->serverrelease ($a->serverversion). This could cause some inconsistencies because backwards compatibility of backup files cannot be guaranteed.';
 $string['notifications'] = 'Notifications';
 $string['notifyloginfailuresmessage'] = '$a->time, IP: $a->ip, User: $a->info';
index ffa9b146da7628fa91c7b14e01026b2c93d8c460..1406e9a4ea3b932daf1e196c97061b11a5e38462 100644 (file)
@@ -3115,26 +3115,27 @@ function admin_externalpage_print_header() {
         foreach ($lt1 as $column) {
             switch ($column) {
                 case 'left':
-        echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
-        print_container_start();
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-        print_container_end();
-        echo '</td>';
+                    echo '<td style="width: '.$preferred_width_left.'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(true);
+                    echo '<td id="middle-column">';
+                    print_container_start(true);
+                    $THEME->open_header_containers++; // this is hacky workaround for the error()/notice() autoclosing problems on admin pages
                 break;
 
                 case 'right':
-        if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) {
-            echo '<td style="width: ' . $preferred_width_right . 'px;" id="right-column">';
-            print_container_start();
-            blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
-            print_container_end();
-            echo '</td>';
-        }
+                    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) {
+                        echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
+                        print_container_start();
+                        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
+                        print_container_end();
+                        echo '</td>';
+                    }
                 break;
             }
         }
@@ -3169,27 +3170,27 @@ function admin_externalpage_print_footer() {
         foreach ($lt as $column) {
             switch ($column) {
                 case 'left':
-        echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
-        print_container_start();
-        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
-        print_container_end();
-        echo '</td>';
+                    echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
+                    print_container_start();
+                    blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
+                    print_container_end();
+                    echo '</td>';
                 break;
 
                 case 'middle':
-        print_container_end();
-        echo '</td>';
+                    print_container_end();
+                    $THEME->open_header_containers--; // this is hacky workaround for the error()/notice() autoclosing problems on admin pages
+                    echo '</td>';
                 break;
 
                 case 'right':
-        if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) {
-            echo '<td style="width: ' . $preferred_width_right . 'px;" id="right-column">';
-            print_container_start();
-            blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
-
-            print_container_end();
-            echo '</td>';
-        }
+                    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT)) {
+                        echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
+                        print_container_start();
+                        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
+                        print_container_end();
+                        echo '</td>';
+                    }
                 break;
             }
         }
index 767a9853a50617d7c2eb1bd417dc315d1d52a26b..9d386995394cb0f060942fcbe4fb324a0f7e04d2 100644 (file)
@@ -80,6 +80,13 @@ define('FORMAT_MARKDOWN', '4');   // Markdown-formatted text http://daringfireba
 define('TRUSTTEXT', '#####TRUSTTEXT#####');
 
 
+/**
+ * Javascript related defines
+ */
+define('REQUIREJS_BEFOREHEADER', 0);
+define('REQUIREJS_INHEADER',     1);
+define('REQUIREJS_AFTERHEADER',  2);
+
 /**
  * Allowed tags - string of html tags that can be tested against for safe html tags
  * @global string $ALLOWED_TAGS
@@ -2526,6 +2533,9 @@ function print_header ($title='', $heading='', $navigation='', $focus='',
     $output = ob_get_contents();
     ob_end_clean();
 
+    // container debugging info
+    $THEME->open_header_containers = open_containers();
+
     // Skip to main content, see skip_main_destination().
     if ($pageid=='course-view' or $pageid=='site-index' or $pageid=='course-index') {
         $skiplink = '<a class="skip" href="#maincontent">'.get_string('tocontent', 'access').'</a>';
@@ -2551,10 +2561,6 @@ function print_header ($title='', $heading='', $navigation='', $focus='',
     }
 }
 
-define('REQUIREJS_BEFOREHEADER',0);
-define('REQUIREJS_INHEADER',1);
-define('REQUIREJS_AFTERHEADER',2);
-
 /**
  * Used to include JavaScript libraries.
  *
@@ -2758,12 +2764,14 @@ function print_header_simple($title='', $heading='', $navigation='', $focus='',
 /**
  * Can provide a course object to make the footer contain a link to
  * to the course home page, otherwise the link will go to the site home
- *
- * @uses $CFG
  * @uses $USER
- * @param course $course {@link $COURSE} object containing course information
- * @param ? $usercourse ?
- * @todo Finish documenting this function
+ * @param mixed $course course object, used for course link button or
+ *                      'none' means no user link, only docs link
+ *                      'empty' means nothing printed in footer
+ *                      'home' special frontpage footer
+ * @param object $usercourse course used in user link
+ * @param boolean $return output as string
+ * @return mixed string or void
  */
 function print_footer($course=NULL, $usercourse=NULL, $return=false) {
     global $USER, $CFG, $THEME, $COURSE;
@@ -2773,23 +2781,45 @@ function print_footer($course=NULL, $usercourse=NULL, $return=false) {
         return;
     }
 
-/// Course links
+/// Course links or special footer
     if ($course) {
-        if (is_string($course) && $course == 'none') {          // Don't print any links etc
+        if ($course === 'empty') {
+            // special hack - sometimes we do not want even the docs link in footer
+            $output = '';
+            if (!empty($THEME->open_header_containers)) {
+                for ($i=0; $i<$THEME->open_header_containers; $i++) {
+                    $output .= print_container_end_all(); // containers opened from header
+                }
+            } else {
+                //1.8 theme compatibility
+                $output .= "\n</div>"; // content div
+            }
+            $output .= "\n</div>\n</body>\n</html>"; // close page div started in header
+            if ($return) {
+                return $output;
+            } else {
+                echo $output;
+                return;
+            }
+
+        } else if ($course === 'none') {          // Don't print any links etc
             $homelink = '';
             $loggedinas = '';
             $home  = false;
-        } else if (is_string($course) && $course == 'home') {   // special case for site home page - please do not remove
+
+        } else if ($course === 'home') {   // special case for site home page - please do not remove
             $course = get_site();
             $homelink  = '<div class="sitelink">'.
                '<a title="moodle '. $CFG->release .' ('. $CFG->version .')" href="http://moodle.org/">'.
                '<img style="width:100px;height:30px" src="pix/moodlelogo.gif" alt="moodlelogo" /></a></div>';
             $home  = true;
+
         } else {
             $homelink = '<div class="homelink"><a '.$CFG->frametarget.' href="'.$CFG->wwwroot.
                         '/course/view.php?id='.$course->id.'">'.format_string($course->shortname).'</a></div>';
             $home  = false;
         }
+
     } else {
         $course = get_site();  // Set course as site course by default
         $homelink = '<div class="homelink"><a '.$CFG->frametarget.' href="'.$CFG->wwwroot.'/">'.get_string('home').'</a></div>';
@@ -2818,9 +2848,9 @@ function print_footer($course=NULL, $usercourse=NULL, $return=false) {
         $menu = '';
     }
 
-/// there should be exactly one open container 'content'
-    if (open_containers() != 1) {
-        debugging('Unexpected number of open containers: '.open_containers().', expecting 1.', DEBUG_DEVELOPER);
+/// there should be exactly the same number of open containers as after the header
+    if ($THEME->open_header_containers != open_containers()) {
+        debugging('Unexpected number of open containers: '.open_containers().', expecting '.$THEME->open_header_containers, DEBUG_DEVELOPER);
     }
 
 /// Provide some performance info if required
@@ -3818,8 +3848,9 @@ function print_continue($link, $return=false) {
  *
  * @param string $message, the content of the box
  * @param string $classes, space-separated class names.
- * @param string $ids, space-separated id names.
+ * @param string $idbase
  * @param boolean $return, return as string or just print it
+ * @return mixed string or void
  */
 function print_box($message, $classes='generalbox', $ids='', $return=false) {
 
@@ -3839,8 +3870,9 @@ function print_box($message, $classes='generalbox', $ids='', $return=false) {
  * Replaces print_simple_box_start (see deprecatedlib.php)
  *
  * @param string $classes, space-separated class names.
- * @param string $ids, space-separated id names.
+ * @param string $idbase
  * @param boolean $return, return as string or just print it
+ * @return mixed string or void
  */
 function print_box_start($classes='generalbox', $ids='', $return=false) {
     global $THEME;
@@ -3868,9 +3900,11 @@ function print_box_end($return=false) {
  * Print a message in a standard themed container.
  *
  * @param string $message, the content of the container
+ * @param boolean $clearfix clear both sides
  * @param string $classes, space-separated class names.
- * @param string $ids, space-separated id names.
+ * @param string $idbase
  * @param boolean $return, return as string or just print it
+ * @return string or void
  */
 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
 
@@ -3888,9 +3922,11 @@ function print_container($message, $clearfix=false, $classes='', $idbase='', $re
 /**
  * Starts a container using divs
  *
+ * @param boolean $clearfix clear both sides
  * @param string $classes, space-separated class names.
- * @param string $ids, space-separated id names.
+ * @param string $idbase
  * @param boolean $return, return as string or just print it
+ * @return mixed string or void
  */
 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
     global $THEME;
@@ -3932,12 +3968,13 @@ function print_container_start($clearfix=false, $classes='', $idbase='', $return
 /**
  * Simple function to end a container (see above)
  * @param boolean $return, return as string or just print it
+ * @return mixed string or void
  */
 function print_container_end($return=false) {
     global $THEME;
 
     if (empty($THEME->open_containers)) {
-        debugging('Incorrect closing of custom corners - no more open containers.', DEBUG_DEVELOPER);
+        debugging('Incorrect request to end container - no more open containers.', DEBUG_DEVELOPER);
         $idbase = '';
     } else {
         $idbase = array_pop($THEME->open_containers);
@@ -3971,17 +4008,15 @@ function open_containers() {
 }
 
 /**
- * Force closing of all open containers except the main content one.
+ * Force closing of open containers
  * @param boolean $return, return as string or just print it
+ * @param int $keep number of containers to be kept open - usually theme or page containers
+ * @return mixed string or void
  */
-function print_container_end_all($return=false) {
-    global $THEME;
-
+function print_container_end_all($return=false, $keep=0) {
     $output = '';
-    if (!empty($THEME->open_containers)) {
-        while(count($THEME->open_containers) > 1) { // the last one is the 'content' container
-            $output .= print_container_end($return);
-        }
+    while (open_containers() > $keep) {
+        $output .= print_container_end($return);
     }
 
     if ($return) {
@@ -3996,7 +4031,9 @@ function print_container_end_all($return=false) {
  * Starting part of the surrounding divs for custom corners
  *
  * @param boolean $clearfix, add CLASS "clearfix" to the inner div against collapsing
- * @param mixed   $idbase, optionally, define one idbase to be added to all the elements in the corners
+ * @param string $classes
+ * @param mixed $idbase, optionally, define one idbase to be added to all the elements in the corners
+ * @return string
  */
 function _print_custom_corners_start($clearfix=false, $classes='', $idbase='') {
 /// Analise if we want ids for the custom corner elements
@@ -4031,6 +4068,8 @@ function _print_custom_corners_start($clearfix=false, $classes='', $idbase='') {
 /**
  * Internal function - do not use directly!
  * Ending part of the surrounding divs for custom corners
+ * @param string $idbase
+ * @return string
  */
 function _print_custom_corners_end($idbase) {
 /// Analise if we want ids for the custom corner elements
@@ -5639,7 +5678,7 @@ function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
  */
 function error ($message, $link='') {
 
-    global $CFG, $SESSION;
+    global $CFG, $SESSION, $THEME;
     $message = clean_text($message);   // In case nasties are in here
 
     if (defined('FULLME') && FULLME == 'cron') {
@@ -5653,7 +5692,7 @@ function error ($message, $link='') {
         @header('HTTP/1.0 404 Not Found');
         print_header(get_string('error'));
     } else {
-        print_container_end_all();
+        print_container_end_all(false, $THEME->open_header_containers);
     }
 
     echo '<br />';
@@ -5909,17 +5948,28 @@ function editorshortcutshelpbutton() {
  * @todo Finish documenting this function
  */
 function notice ($message, $link='', $course=NULL) {
-    global $CFG, $SITE;
+    global $CFG, $SITE, $THEME, $COURSE;
 
-    print_container_end_all();
+    $message = clean_text($message);   // In case nasties are in here
 
-    $message = clean_text($message);
+    if (defined('FULLME') && FULLME == 'cron') {
+        // notices in cron should be mtrace'd.
+        mtrace($message);
+        die;
+    }
+
+    if (! defined('HEADER_PRINTED')) {
+        //header not yet printed
+        print_header(get_string('notice'));
+    } else {
+        print_container_end_all(false, $THEME->open_header_containers);
+    }
 
     print_box($message, 'generalbox', 'notice');
     print_continue($link);
 
     if (empty($course)) {
-        print_footer($SITE);
+        print_footer($COURSE);
     } else {
         print_footer($course);
     }
@@ -5978,7 +6028,7 @@ if (!function_exists('error_get_last')) {
  */
 function redirect($url, $message='', $delay=-1) {
 
-    global $CFG;
+    global $CFG, $THEME;
 
     if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) {
        $url = sid_process_url($url);
@@ -6052,7 +6102,7 @@ function redirect($url, $message='', $delay=-1) {
         print_header('', '', '', '', $errorprinted ? '' : ('<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />'));
         $delay += 3; // double redirect prevention, it was sometimes breaking upgrades before 1.7
     } else {
-        print_container_end_all();
+        print_container_end_all(false, $THEME->open_header_containers);
     }
     echo '<div style="text-align:center">';
     echo '<div>'. $message .'</div>';
index 6c54652e4c47acf757afd7ad4c31428b506263b1..5d5565886f96906fb13a23f3436e647005347913 100644 (file)
@@ -87,8 +87,6 @@
 
     echo '</td></tr></table>';
 
-    // this is hack!
-    print_container_end(); // container "content" started in header
-    echo '</div></body></html>'; // close page div started in header
+    print_footer('empty');
 
 ?>
index c389234b418cb9c77f8abbd7a560c2e300777767..f01cdd1a72964a0c318ad3039dd2cd2b386faf63 100644 (file)
@@ -59,7 +59,6 @@
         <input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>" />
         <input type="hidden" name="chat_message" />
     </form>
-</div>
-</div>
-</body>
-</html>
+<?php
+    print_footer('empty');
+?>
index 8ceca1a30b3087447fc6f7a647eabb037d4d6e54..ea1ef674a765fabb3f743cf08b58b18a9224f296 100644 (file)
         echo '</td></tr>';
     }
     // added 2 </div>s, xhtml strict complaints
-    echo '</table></div></div></body></html>';
+    echo '</table>';
+    print_footer('empty');
 
     //
     // Support HTTP Keep-Alive by printing Content-Length
index c33e2ccb86e85c7b5c069493110ca6c8872927de..51697bcfe4d7a5c3e9b26b2299209892e8c1bdd3 100644 (file)
@@ -71,6 +71,6 @@ function reloadusers() {
         <input type="hidden" name="chat_msgidnr" value="0" />
         <input type="hidden" name="chat_sid" value="<?php echo $chat_sid ?>" />
     </form>
-</body>
-
-</html>
+<?php
+    print_footer('empty');
+?>
\ No newline at end of file
index f9f5bde614c5327594c55b1947c7472e214f2695..779cafc7a49896816117453c063ddd2e7d198494 100644 (file)
         }
     }
 
-    echo '</div></div></body></html>';
+    print_footer('empty');
 ?>
index 576e7db020c62e91fddce1a001508db2f5a56bdb..bf5232d7e80982f80de091d5b9ab384f845b28df 100644 (file)
@@ -45,5 +45,6 @@
     </form>
     </div>
 
-    </body>
-    </html>
+<?php
+    print_footer('empty');
+?>
\ No newline at end of file
index c5a2e6f0089b65130d0d30e373ac18c8dc65a73f..ef691baa9dbc09cddc90295d90e658b68056e6d3 100644 (file)
@@ -52,6 +52,6 @@
     </form>
     </fieldset>
     </div>
-
-    </body>
-    </html>
+<?php
+    print_footer('empty');
+?>
\ No newline at end of file
index b16c6d9961b66077a7b825a7d52b5ea5d4d5a57c..fa461245fda38d3930217a08b2e888d29e4e8f2c 100644 (file)
@@ -414,7 +414,7 @@ class resource_file extends resource_base {
                         get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource'));
                 echo '</div>';
             }
-            echo '</div></div></body></html>';
+            print_footer('empty');
             exit;
         }
 
index 664b5d591c903ae5e2dba5d4fef95eaff3ce0c43..ae5dc09d9ba7adde8aa203f8e485a39cf6efb4ef 100644 (file)
@@ -479,12 +479,8 @@ class resource_ims extends resource_base {
             }
         /// content - this produces everything else
             $this->print_ims($cm, $course, $items, $resource, $page);
-        /// Now, let's print the footer. It's harcoded here to save some space
-        /// because it's impossible to use print_footer() to print NOTHING
-        /// Added programatic support to customcorners themes.
-            // this is hack!
-            print_container_end(); // container "content" started in header
-            echo '</div></body></html>'; // close page div started in header
+
+            print_footer('empty');
 
         /// log it.
             add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);