]> git.mjollnir.org Git - moodle.git/commitdiff
Merging the changes from 1.4 dev branch (site index blocks + various bugfixes)
authordefacer <defacer>
Fri, 28 May 2004 10:53:54 +0000 (10:53 +0000)
committerdefacer <defacer>
Fri, 28 May 2004 10:53:54 +0000 (10:53 +0000)
22 files changed:
blocks/admin/block_admin.php
blocks/calendar_month/block_calendar_month.php
blocks/calendar_upcoming/block_calendar_upcoming.php
blocks/course_list/block_course_list.php
blocks/course_summary/block_course_summary.php
blocks/moodleblock.class.php
blocks/news_items/block_news_items.php
blocks/online_users/block_online_users.php
blocks/participants/block_participants.php
blocks/section_links/block_section_links.php
blocks/site_main_menu/block_site_main_menu.php [new file with mode: 0644]
blocks/version.php
calendar/event.php
calendar/lib.php
calendar/set.php
calendar/view.php
course/format/topics/format.php
course/lib.php
index.php
lib/blocklib.php
lib/weblib.php
version.php

index 77d524d76a04c17bcc137c833665044be4f404b0..8eb6a9f97d27e844886cb37d412e7d2836782677 100644 (file)
@@ -5,13 +5,16 @@ class CourseBlock_admin extends MoodleBlock {
         $this->title = get_string('administration');
         $this->content_type = BLOCK_TYPE_LIST;
         $this->course = $course;
-        $this->version = 2004041000;
+        $this->version = 2005052800;
     }
+
+    function applicable_formats() {
+        return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE;
+    }
+
     function get_content() {
         global $USER, $CFG, $THEME;
 
-        require_once($CFG->dirroot.'/mod/forum/lib.php');
-
         if($this->content !== NULL) {
             return $this->content;
         }
@@ -21,6 +24,52 @@ class CourseBlock_admin extends MoodleBlock {
         $this->content->icons = array();
         $this->content->footer = '';
 
+        if($this->course->id == 1) {
+            $this->load_content_for_site();
+        }
+        else {
+            $this->load_content_for_course();
+        }
+
+        return $this->content;
+    }
+
+
+    function load_content_for_site() {
+        global $CFG;
+
+        if (isadmin()) {
+            $this->content->items[] = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/configure.php">'.get_string('configuration').'</a>...';
+            $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/admin.gif" height="16" width="16" alt="" />';
+
+            $this->content->items[] = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/users.php">'.get_string('users').'</a>...';
+            $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="" />';
+        }
+
+        if (iscreator()) {
+            $this->content->items[] = '<a href="'.$CFG->wwwroot.'/course/index.php?edit=on">'.get_string('courses').'</a>';
+            $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/course.gif" height="16" width="16" alt="" />';
+        }
+
+        if (isadmin()) {
+            $this->content->items[] = '<a href="'.$CFG->wwwroot.'/course/log.php?id=1">'.get_string('logs').'</a>';
+            $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/log.gif" height="16" width="16" alt="" />';
+
+            $this->content->items[] = '<a href="'.$CFG->wwwroot.'/files/index.php?id=1">'.get_string('sitefiles').'</a>';
+            $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/files.gif" height="16" width="16" alt="" />';
+
+            if (file_exists($CFG->dirroot.'/'.$CFG->admin.'/'.$CFG->dbtype)) {
+                $this->content->items[] = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/'.$CFG->dbtype.'/frame.php">'.get_string('managedatabase').'</a>';
+                $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/db.gif" height="16" width="16" alt="" />';
+            }
+            $this->content->footer = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/">'.get_string('admin').'</a>...';
+        }
+    }
+
+    function load_content_for_course() {
+        global $CFG;
+        require_once($CFG->dirroot.'/mod/forum/lib.php');
+
         if (isguest()) {
             return $this->content;
         }
@@ -82,6 +131,7 @@ class CourseBlock_admin extends MoodleBlock {
             }
 
         } else if (!isguest()) {  // Students menu
+
             if ($this->course->showgrades) {
                 $this->content->items[]='<a href="grade.php?id='.$this->course->id.'">'.get_string('grades').'...</a>';
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" height="16" width="16" alt="">';
@@ -102,8 +152,6 @@ class CourseBlock_admin extends MoodleBlock {
                 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" height="16" width="16" alt="">';
             }
         }
-
-        return $this->content;
     }
 }
 
index 06b4071b5d3077e3b976d460e12b2edd2a9474b3..6f9bbe3745ca5747e4ad882167ce8931d0298180 100644 (file)
@@ -5,7 +5,11 @@ class CourseBlock_calendar_month extends MoodleBlock {
         $this->title = get_string('calendar', 'calendar');
         $this->content_type = BLOCK_TYPE_TEXT;
         $this->course = $course;
-        $this->version = 2004052400;
+        $this->version = 2005052600;
+    }
+
+    function applicable_formats() {
+        return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE;
     }
 
     function get_content() {
index 49e2eda3fced7ff7c80ffa7f528637b578cc9827..6eb8baff39177ab582fa26c627a5efffcb04cdd0 100644 (file)
@@ -5,7 +5,11 @@ class CourseBlock_calendar_upcoming extends MoodleBlock {
         $this->title = get_string('upcomingevents', 'calendar');
         $this->content_type = BLOCK_TYPE_TEXT;
         $this->course = $course;
-        $this->version = 2004052400;
+        $this->version = 2004052600;
+    }
+
+    function applicable_formats() {
+        return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE;
     }
 
     function get_content() {
@@ -22,7 +26,7 @@ class CourseBlock_calendar_upcoming extends MoodleBlock {
         $this->content = New object;
         $this->content->text = '';
         $this->content->footer = '<br /><a href="'.$CFG->wwwroot.'/calendar/view.php?view=upcoming&amp;course='.$this->course->id.'">'.get_string('gotocalendar', 'calendar').'</a>...';
-        $this->content->footer .= '<br /><a href="'.$CFG->wwwroot.'/calendar/event.php?action=new">'.get_string('newevent', 'calendar').'</a>...';
+        $this->content->footer .= '<br /><a href="'.$CFG->wwwroot.'/calendar/event.php?action=new&amp;course='.$this->course->id.'">'.get_string('newevent', 'calendar').'</a>...';
 
         if($this->course === NULL) {
             // Overrides: use no course at all
index 980bf7c5dfc524acff62e88e64d11a4c49905807..c48ea436f474cd29bc129828f98a783db3fba951 100644 (file)
@@ -5,7 +5,11 @@ class CourseBlock_course_list extends MoodleBlock {
         $this->title = get_string('mycourses');
         $this->content_type = BLOCK_TYPE_LIST;
         $this->course = $course;
-        $this->version = 2004041800;
+        $this->version = 2005052600;
+    }
+
+    function applicable_formats() {
+        return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE;
     }
 
     function get_content() {
@@ -40,7 +44,7 @@ class CourseBlock_course_list extends MoodleBlock {
                     $this->content->icons[]=$icon;
                 }
                 $this->title = get_string('mycourses');
-                $this->content->footer = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...";
+                $this->content->footer = "<a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...";
                 return $this->content;
             }
         }
@@ -53,12 +57,12 @@ class CourseBlock_course_list extends MoodleBlock {
                     $this->content->items[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>";
                     $this->content->icons[]=$icon;
                 }
-                $this->content->footer = "<p><a href=\"$CFG->wwwroot/course/\">".get_string("searchcourses")."</a>...";
+                $this->content->footer = "<a href=\"$CFG->wwwroot/course/\">".get_string("searchcourses")."</a>...";
                 $this->title = get_string('categories');
             } else {                          // Just print course names of single category
                 $category = array_shift($categories);
                 $courses = get_courses($category->id);
-    
+
                 if ($courses) {
                     foreach ($courses as $course) {
                         $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
@@ -66,7 +70,7 @@ class CourseBlock_course_list extends MoodleBlock {
                                    "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
                         $this->content->icons[]=$icon;
                     }
-                    $this->content->footer = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...";
+                    $this->content->footer = "<a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...";
                 } else {
                     $this->content->items = array();
                     $this->content->icons = array();
index 69e00e40466b1786ee1b01c906114e48044c29df..86963a5eb6d83f67c734614a406b084907be7483 100644 (file)
@@ -5,20 +5,22 @@ class CourseBlock_course_summary extends MoodleBlock {
         $this->title = get_string('blockname','block_course_summary');
         $this->content_type = BLOCK_TYPE_TEXT;
         $this->course = $course;
-        $this->version = 2004041400;
+        $this->version = 2004052600;
+    }
+
+    function applicable_formats() {
+        return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE;
     }
 
     function get_content() {
-        global $USER, $CFG;
 
         if($this->content !== NULL) {
             return $this->content;
         }
 
         $this->content = New object;
-        $this->content->text = '';
-        $this->content->footer = '';
         $this->content->text = format_text($this->course->summary, FORMAT_HTML);
+        $this->content->footer = '';
 
         return $this->content;
     }
index 49038d9f9c3c4477680da5c23ba06bcfe124c826..0940956812417df6ace870588b8ed12ffd3a60eb 100644 (file)
@@ -69,9 +69,9 @@ class MoodleBlock {
                     break;
                 }
                 if ($this->edit_controls !== NULL || !$this->hide_header()) {
-                    print_side_block($title, $this->content->text, NULL, NULL, $this->content->footer);
+                    print_side_block($title, $this->content->text, NULL, NULL, $this->content->footer, $this->html_attributes());
                 } else {
-                    print_side_block(NULL, $this->content->text, NULL, NULL, $this->content->footer);
+                    print_side_block(NULL, $this->content->text, NULL, NULL, $this->content->footer, $this->html_attributes());
                 }
             break;
             case BLOCK_TYPE_LIST:
@@ -79,9 +79,9 @@ class MoodleBlock {
                     break;
                 }
                 if ($this->edit_controls !== NULL || !$this->hide_header()) {
-                    print_side_block($title, '', $this->content->items, $this->content->icons, $this->content->footer);
+                    print_side_block($title, '', $this->content->items, $this->content->icons, $this->content->footer, $this->html_attributes());
                 } else {
-                    print_side_block(NULL, '', $this->content->items, $this->content->icons, $this->content->footer);
+                    print_side_block(NULL, '', $this->content->items, $this->content->icons, $this->content->footer, $this->html_attributes());
                 }
             break;
         }
@@ -93,6 +93,7 @@ class MoodleBlock {
         }
         print_side_block($title, '&nbsp;', NULL, NULL, '');
     }
+
     function add_edit_controls($options, $blockid) {
         global $CFG, $THEME;
 
@@ -179,7 +180,7 @@ class MoodleBlock {
             $errors[] = 'version_not_set';
             $correct = false;
         }
-        $allformats = COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL;
+        $allformats = COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE;
         if(!($this->applicable_formats() & $allformats)) {
             $errors[] = 'no_course_formats';
             $correct = false;
@@ -216,8 +217,8 @@ class MoodleBlock {
         return false;
     }
     function html_attributes() {
-        // Default case: we want no extra attributes
-        return false;
+        // Default case: just an id for the block, with our name in it
+        return array('id' => 'block_'.$this->name());
     }
 }
 
index 42a610991a307201b2409fbb23329ec46b3610db..735771367234b45a8ad85e9450fa65d30ccced4b 100644 (file)
@@ -5,7 +5,11 @@ class CourseBlock_news_items extends MoodleBlock {
         $this->title = get_string('latestnews');
         $this->content_type = BLOCK_TYPE_TEXT;
         $this->course = $course;
-        $this->version = 2004041200;
+        $this->version = 2004052600;
+    }
+
+    function applicable_formats() {
+        return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE;
     }
 
     function get_content() {
@@ -16,6 +20,7 @@ class CourseBlock_news_items extends MoodleBlock {
         }
 
         require_once($CFG->dirroot.'/course/lib.php');
+        require_once($CFG->dirroot.'/mod/forum/lib.php');
 
         $this->content = New object;
         $this->content->text = '';
index 9b7b9f65219c450a3e31035f5711482241d8a42b..755eecf52292d80d1ebb414a823613030657fdf7 100644 (file)
@@ -5,7 +5,11 @@ class CourseBlock_online_users extends MoodleBlock {
         $this->title = get_string('blockname','block_online_users');
         $this->content_type = BLOCK_TYPE_TEXT;
         $this->course = $course;
-        $this->version = 2004041800;
+        $this->version = 2004052700;
+    }
+
+    function applicable_formats() {
+        return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL | COURSE_FORMAT_SITE;
     }
 
     function has_config() {return true;}
index b1ae1edb33b319ffda297044e9d2b4a2128ba452..9ed78fc408f86d4fdd95abb934ba2277227b97e7 100644 (file)
@@ -5,7 +5,7 @@ class CourseBlock_participants extends MoodleBlock {
         $this->title = get_string('people');
         $this->content_type = BLOCK_TYPE_LIST;
         $this->course = $course;
-        $this->version = 2004041800;
+        $this->version = 2004052600;
     }
 
     function get_content() {
@@ -38,14 +38,16 @@ class CourseBlock_participants extends MoodleBlock {
             }
         }
 
-        $fullname = fullname($USER, true);
-        $editmyprofile = '<a title="'.$fullname.'" href="../user/edit.php?id='.$USER->id.'&amp;course='.$this->course->id.'">'.get_string('editmyprofile').'</a>';
-        if ($USER->description) {
-            $this->content->items[]= $editmyprofile;
-        } else {
-            $this->content->items[]= $editmyprofile." <blink>*</blink>";
+        if(!empty($USER)) {
+            $fullname = fullname($USER, true);
+            $editmyprofile = '<a title="'.$fullname.'" href="../user/edit.php?id='.$USER->id.'&amp;course='.$this->course->id.'">'.get_string('editmyprofile').'</a>';
+            if ($USER->description) {
+                $this->content->items[]= $editmyprofile;
+            } else {
+                $this->content->items[]= $editmyprofile." <blink>*</blink>";
+            }
+            $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" height="16" width="16" alt="">';
         }
-        $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" height="16" width="16" alt="">';
 
         return $this->content;
     }
index 525e2f5b8747af6fcd4839002654416e32965176..57349ee9d69de9b976bd6f6bdf52e268a33c0bde 100644 (file)
@@ -14,9 +14,9 @@ class CourseBlock_section_links extends MoodleBlock {
         }
         $this->content_type = BLOCK_TYPE_TEXT;
         $this->course = $course;
-        $this->version = 2004050500;
+        $this->version = 2004052800;
     }
-    
+
     function applicable_formats() {
         return (COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS);
     }
@@ -62,9 +62,8 @@ class CourseBlock_section_links extends MoodleBlock {
         if ($highlight) {
             $text .= "<br><a href=\"$link#$highlight\">$linktext</a>";
         }
-        
-        $this->content = New object;
-        $this->content->header = 'Hello';
+
+        $this->content = New stdClass;
         $this->content->footer = '';
         $this->content->text = $text;
         return $this->content;
diff --git a/blocks/site_main_menu/block_site_main_menu.php b/blocks/site_main_menu/block_site_main_menu.php
new file mode 100644 (file)
index 0000000..9d99bb1
--- /dev/null
@@ -0,0 +1,126 @@
+<?php   //$Id$
+
+class CourseBlock_site_main_menu extends MoodleBlock {
+    function CourseBlock_site_main_menu ($course) {
+        $this->title = get_string('mainmenu');
+        $this->content_type = BLOCK_TYPE_LIST;
+        $this->course = $course;
+        $this->version = 2004052700;
+    }
+
+    function applicable_formats() {
+        return COURSE_FORMAT_SITE;
+    }
+
+    function get_content() {
+        global $USER, $CFG;
+
+        if($this->content !== NULL) {
+            return $this->content;
+        }
+
+        $this->content = New stdClass;
+        $this->content->items = array();
+        $this->content->icons = array();
+        $this->content->footer = '';
+
+        $isteacher = isteacher($this->course->id);
+        $isediting = isediting($this->course->id);
+        $ismoving = ismoving($this->course->id);
+
+        $sections = get_all_sections($this->course->id);
+        $section = $sections[0];
+
+        if($section->sequence || $isediting) {
+            get_all_mods($this->course->id, $mods, $modnames, $modnamesplural, $modnamesused);
+        }
+
+        $groupbuttons = $this->course->groupmode;
+        $groupbuttonslink = (!$this->course->groupmodeforce);
+
+        if ($ismoving) {
+            $strmovehere = get_string('movehere');
+            $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
+            $strcancel= get_string('cancel');
+            $stractivityclipboard = $USER->activitycopyname;
+        }
+
+        $modinfo = unserialize($this->course->modinfo);
+        $editbuttons = '';
+
+        if ($ismoving) {
+            $this->content->items[] = '&nbsp;<img align="bottom" src="'.$CFG->pixpath.'/t/move.gif" height="11" width="11">';
+            $this->content->icons[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true">'.$strcancel.'</a>)';
+        }
+
+        if (!empty($section->sequence)) {
+            $sectionmods = explode(',', $section->sequence);
+            foreach ($sectionmods as $modnumber) {
+                if (empty($mods[$modnumber])) {
+                    continue;
+                }
+                $mod = $mods[$modnumber];
+                if ($isediting && !$ismoving) {
+                    if ($groupbuttons) {
+                        if (! $mod->groupmodelink = $groupbuttonslink) {
+                            $mod->groupmode = $this->course->groupmode;
+                        }
+
+                    } else {
+                        $mod->groupmode = false;
+                    }
+                    $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
+                } else {
+                    $editbuttons = '';
+                }
+                if ($mod->visible || $isteacher) {
+                    if ($ismoving) {
+                        if ($mod->id == $USER->activitycopy) {
+                            continue;
+                        }
+                        $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'">'.
+                            '<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0"></a>';
+                        $this->content->icons[] = '';
+                   }
+                    $instancename = urldecode($modinfo[$modnumber]->name);
+                    if (!empty($CFG->filterall)) {
+                        $instancename = filter_text('<nolink>'.$instancename.'</nolink>', $this->course->id);
+                    }
+                    $linkcss = $mod->visible ? '' : ' class="dimmed" ';
+                    if (!empty($modinfo[$modnumber]->extra)) {
+                        $extra = urldecode($modinfo[$modnumber]->extra);
+                    } else {
+                        $extra = '';
+                    }
+
+                    if ($mod->modname == 'label') {
+                        $this->content->items[] = format_text($extra, FORMAT_HTML).$editbuttons;
+                        $this->content->icons[] = '';
+                    } else {
+                        $this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
+                            ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons;
+                        $this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$mod->modname.'/icon.gif" height="16" width="16" alt="'.$mod->modfullname.'">';
+                    }
+                }
+            }
+        }
+
+        if ($ismoving) {
+            $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'">'.
+                                      '<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0"></a>';
+            $this->content->icons[] = '';
+        }
+
+        if ($isediting && $modnames) {
+            $this->content->footer = '<div style="text-align: right;">'.
+                popup_form($CFG->wwwroot.'/course/mod.php?id='.$this->course->id.'&amp;section='.$section->section.'&amp;add=',
+                           $modnames, 'section0', '', get_string('add').'...', 'mods', get_string('activities'), true) . '</div>';
+        } else {
+            $this->content->footer = '';
+        }
+
+        return $this->content;
+    }
+}
+
+?>
index acb59cc956b40d436ebcb1ab222b7556d9fa5529..05834435d26f6ec147b43c4cf14647dd517904e3 100644 (file)
@@ -5,4 +5,4 @@
 // database (blocks_version) to determine whether upgrades should
 // be performed (see db/backup_*.php)
 
-$blocks_version = 2004052400;   // The current version is a date (YYYYMMDDXX)
+$blocks_version = 2004052700;   // The current version is a date (YYYYMMDDXX)
index 6167f29b62fd0841fd67520a1d830db5725fd276..7031a87d455d6e6012c77b30b4866731a0c92cdf 100644 (file)
         $defaultformat = FORMAT_MOODLE;
     }
 
+    // If a course has been supplied in the URL, change the filters to show that one
+    if(!empty($_GET['course'])) {
+        if(is_numeric($_GET['course']) && $_GET['course'] > 0 && record_exists('course', 'id', $_GET['course'])) {
+            if($_GET['course'] == 1) {
+                // If coming from the home page, show all courses
+                $SESSION->cal_courses_shown = calendar_get_default_courses(true);
+                calendar_set_referring_course(0);
+            }
+            else {
+                // Otherwise show just this one
+                $SESSION->cal_courses_shown = intval($_GET['course']);
+                calendar_set_referring_course($SESSION->cal_courses_shown);
+            }
+        }
+    }
+
     switch($_REQUEST['action']) {
         case 'delete':
             $title = get_string('deleteevent', 'calendar');
                 $d = $eventtime['mday'];
                 $y = $eventtime['year'];
                 // Display confirmation form
-                print_side_block_start(get_string('deleteevent', 'calendar').': '.$event->name, '', 'mycalendar');
+                print_side_block_start(get_string('deleteevent', 'calendar').': '.$event->name, array('class' => 'mycalendar'));
                 include('event_delete.html');
                 print_side_block_end();
             }
                     $form->minutes = '';
                 }
             }
-            print_side_block_start(get_string('editevent', 'calendar'), '', 'mycalendar');
+            print_side_block_start(get_string('editevent', 'calendar'), array('class' => 'mycalendar'));
             include('event_edit.html');
             print_side_block_end();
             if ($usehtmleditor) {
                 $header = ' ('.$header.')';
             }
 
-            print_side_block_start(get_string('newevent', 'calendar').$header, '', 'mycalendar');
+            print_side_block_start(get_string('newevent', 'calendar').$header, array('class' => 'mycalendar'));
             if($_REQUEST['type'] == 'select') {
                 $defaultcourse = $SESSION->cal_course_referer;
                 if(isteacheredit($defaultcourse, $USER->id)) {
     echo calendar_overlib_html();
     calendar_set_filters($courses, $groups, $users, $defaultcourses, $defaultcourses);
 
-    print_side_block_start(get_string('monthlyview', 'calendar'), '', 'sideblockmain');
+    print_side_block_start(get_string('monthlyview', 'calendar'));
     list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
     list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
 
@@ -507,7 +523,7 @@ function calendar_get_allowed_types(&$allowed) {
     $allowed->courses = false; // This may change just below
     $allowed->site = isadmin($USER->id);
 
-    if(!empty($SESSION->cal_course_referer) && isteacheredit($SESSION->cal_course_referer, $USER->id)) {
+    if(!empty($SESSION->cal_course_referer) && $SESSION->cal_course_referer > 1 && isteacheredit($SESSION->cal_course_referer, $USER->id)) {
         $allowed->courses = array($SESSION->cal_course_referer => 1);
         $allowed->groups = get_groups($SESSION->cal_course_referer);
     }
index 4d1170b2f9bbef3fab09bebb3d811979f8db1854..d0815fc90466717157d49769e02ff16c0f921c7e 100644 (file)
@@ -922,11 +922,21 @@ function calendar_session_vars() {
         $SESSION->cal_show_course = true;
     }
     if(!isset($SESSION->cal_show_user)) {
-        $SESSION->cal_show_user = isset($USER->id) ? $USER->id : false;
+        $SESSION->cal_show_user = true;
     }
     if(empty($SESSION->cal_courses_shown)) {
         $SESSION->cal_courses_shown = calendar_get_default_courses(true);
     }
+    if(empty($SESSION->cal_users_shown)) {
+        // The empty() instead of !isset() here makes a whole world of difference,
+        // as it will automatically change to the user's id when the user first logs
+        // in. With !isset(), it would never do that.
+        $SESSION->cal_users_shown = isset($USER->id) ? $USER->id : false;
+    }
+    else if(is_numeric($SESSION->cal_users_shown) && !empty($USER->id) && $SESSION->cal_users_shown != $USER->id) {
+        // Follow the white rabbit, for example if a teacher logs in as a student
+        $SESSION->cal_users_shown = $USER->id;
+    }
 }
 
 function calendar_overlib_html() {
@@ -987,12 +997,8 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
     }
 
     if($SESSION->cal_show_user || $ignorefilters) {
-        // This ignores the "which user to see" setting
-        // The functionality to do that does exist, but this was
-        // the most painless way to solve bug 1323. And anyway,
-        // it wasn't being used anywhere.
-        $user = $USER->id;
-        //$user = $SESSION->cal_show_user;
+        // This doesn't work for arrays yet (maybe someday it will)
+        $user = $SESSION->cal_users_shown;
     }
     else {
         $user = false;
@@ -1010,7 +1016,7 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
         // For each course...
         foreach($groupcourses as $courseid) {
             // If the user is an editing teacher in there,
-            if(isteacheredit($courseid, $USER->id)) {
+            if(!empty($USER) && isteacheredit($courseid, $USER->id)) {
                 // Show events from all groups
                 if(($grouprecords = get_groups($courseid)) !== false) {
                     $grouparray = array_merge($grouparray, array_keys($grouprecords));
index 0b78e8e8ff71465a2b6208b6b1ce7cbbdd5a3808..066fa0ce16b73e9c85f9d075ad35f1eb51e4696f 100644 (file)
@@ -52,6 +52,9 @@
     optional_variable($_GET['cal_y']);
 
     switch($_GET['var']) {
+        case 'setuser':
+            // Not implemented yet (or possibly at all)
+        break;
         case 'setcourse':
             $id = intval($_GET['id']);
             if($id == 0) {
             $SESSION->cal_show_global = !$SESSION->cal_show_global;
         break;
         case 'showuser':
-            if($SESSION->cal_show_user) {
-                $SESSION->cal_show_user = false;
-            }
-            else {
-                $SESSION->cal_show_user = $USER->id;
-            }
+            $SESSION->cal_show_user = !$SESSION->cal_show_user;
         break;
     }
 
index 399ba26ed8933d78c0a020f9874cec6a6387e843..d91050e8911bd7a806ef2c534b6209c844cfda50 100644 (file)
     // If a course has been supplied in the URL, change the filters to show that one
     if(!empty($_GET['course'])) {
         if(is_numeric($_GET['course']) && $_GET['course'] > 0 && record_exists('course', 'id', $_GET['course'])) {
-            $SESSION->cal_courses_shown = intval($_GET['course']);
-            calendar_set_referring_course($SESSION->cal_courses_shown);
+            if($_GET['course'] == 1) {
+                // If coming from the home page, show all courses
+                $SESSION->cal_courses_shown = calendar_get_default_courses(true);
+                calendar_set_referring_course(0);
+            }
+            else {
+                // Otherwise show just this one
+                $SESSION->cal_courses_shown = intval($_GET['course']);
+                calendar_set_referring_course($SESSION->cal_courses_shown);
+            }
         }
     }
 
 
     // START: Last column (3-month display)
     echo '<td style="vertical-align: top; width: 180px;">';
-    print_side_block_start(get_string('monthlyview', 'calendar'), '', 'sideblockmain');
+    print_side_block_start(get_string('monthlyview', 'calendar'));
     list($prevmon, $prevyr) = calendar_sub_month($mon, $yr);
     list($nextmon, $nextyr) = calendar_add_month($mon, $yr);
     $getvars = 'cal_d='.$day.'&amp;cal_m='.$mon.'&amp;cal_y='.$yr; // For filtering
@@ -207,7 +215,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) {
         $text.= '</form></div>';
     }
 
-    print_side_block_start($text, '', 'mycalendar');
+    print_side_block_start($text, array('class' => 'mycalendar'));
     echo '<p>'.calendar_top_controls('day', array('d' => $d, 'm' => $m, 'y' => $y)).'</p>';
 
     if (empty($events)) {
@@ -316,7 +324,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
         $text.= '</form></div>';
     }
 
-    print_side_block_start($text, '', 'mycalendar');
+    print_side_block_start($text, array('class' => 'mycalendar'));
 
     echo calendar_top_controls('month', array('m' => $m, 'y' => $y));
 
@@ -513,7 +521,7 @@ function calendar_show_upcoming_events($courses, $groups, $users, $futuredays, $
         $text.= '</form></div>';
     }
 
-    print_side_block_start($text, '', 'mycalendar');
+    print_side_block_start($text, array('class' => 'mycalendar'));
     if ($events) {
         foreach ($events as $event) {
             calendar_print_event($event);
index edce8e0ab8593c9b83c59ac5d11195ac1e08e7a9..6412a992bd1dcbd3a8e1b9d98bcd93b9f5286f58 100644 (file)
@@ -98,7 +98,7 @@
     $thissection = $sections[$section];
 
     if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
-        echo "<tr>";
+        echo '<tr id="section_0">';
         echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"topicsoutlineside\" valign=top width=20>&nbsp;</td>";
         echo "<td valign=top bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontent\" width=\"100%\">";
 
             echo "</td>";
 
             if (!isteacher($course->id) and !$thissection->visible) {   // Hidden for students
-                echo "<td valign=top align=center $colormain width=\"100%\">";
+                echo '<td id="section_'.($section).'" style="vertical-align:top; text-align: center; width: 100%;" '.$colormain.'>';
                 echo get_string("notavailable");
                 echo "</td>";
             } else {
-                echo "<td valign=top $colormain width=\"100%\">";
+                echo '<td id="section_'.($section).'" style="vertical-align:top; width: 100%;" '.$colormain.'>';
 
                 echo format_text($thissection->summary, FORMAT_HTML);
 
index b31906b969540fb508df8efc1397f201ca16cd4c..f2bffe6174c3591eb2152a41a9ce3a4253fb1f60 100644 (file)
@@ -31,13 +31,13 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
 
         // Get all the possible users
         $users = array();
-    
+
         if ($course->category) {
             $courseusers = get_course_users($course->id);
         } else {
             $courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname");
-        } 
-     
+        }
+
         if ($courseusers) {
             foreach ($courseusers as $courseuser) {
                 $users[$courseuser->id] = fullname($courseuser, $isteacher);
@@ -46,7 +46,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
         if ($guest = get_guest()) {
             $users[$guest->id] = fullname($guest);
         }
-     
+
         if (isadmin()) {
             if ($ccc = get_records("course", "", "", "fullname")) {
                 foreach ($ccc as $cc) {
@@ -54,7 +54,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
                         $courses["$cc->id"] = "$cc->fullname";
                     } else {
                         $courses["$cc->id"] = " $cc->fullname (Site)";
-                    } 
+                    }
                 }
             }
             asort($courses);
@@ -84,7 +84,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
             foreach ($modinfo as $mod) {
                 if ($mod->mod == "label") {
                     continue;
-                }  
+                }
                 if (!$mod->visible and !$isteacher) {
                     continue;
                 }
@@ -370,10 +370,10 @@ function make_log_url($module, $url) {
 }
 
 
-function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100, 
+function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
                    $url="", $modname="", $modid=0, $modaction="") {
 
-// It is assumed that $date is the GMT time of midnight for that day, 
+// It is assumed that $date is the GMT time of midnight for that day,
 // and so the next 86400 seconds worth of logs are printed.
 
     global $CFG, $db;
@@ -475,7 +475,7 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
 
 function print_recent_activity($course) {
     // $course is an object
-    // This function trawls through the logs looking for 
+    // This function trawls through the logs looking for
     // anything new since the user's last login
 
     global $CFG, $USER, $THEME, $SESSION;
@@ -521,7 +521,7 @@ function print_recent_activity($course) {
 
     // Next, have there been any modifications to the course structure?
 
-    $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND 
+    $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND
                                        module = 'course' AND action LIKE '% mod'", "time ASC");
 
     if ($logs) {
@@ -538,7 +538,7 @@ function print_recent_activity($course) {
             $tempmod->id = $info[1];
             //Obtain the visible property from the instance
             $modvisible = instance_is_visible($info[0],$tempmod);
-            
+
             //Only if the mod is visible
             if ($modvisible) {
                 switch ($log->action) {
@@ -553,7 +553,7 @@ function print_recent_activity($course) {
                        }
                     break;
                     case "delete mod":
-                       if (!empty($changelist["$log->info"]["operation"]) and 
+                       if (!empty($changelist["$log->info"]["operation"]) and
                                   $changelist["$log->info"]["operation"] == "add") {
                            $changelist["$log->info"] = NULL;
                        } else {
@@ -581,7 +581,7 @@ function print_recent_activity($course) {
                 }
             }
         }
-    }    
+    }
 
 
     // If this site uses Library module, then print recent items
@@ -616,7 +616,7 @@ function print_recent_activity($course) {
 
 
 function get_array_of_activities($courseid) {
-// For a given course, returns an array of course activity objects 
+// For a given course, returns an array of course activity objects
 // Each item in the array contains he following properties:
 //  cm - course module id
 //  mod - name of the module (eg forum)
@@ -709,8 +709,8 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
 
 
 function get_all_sections($courseid) {
-    
-    return get_records("course_sections", "course", "$courseid", "section", 
+
+    return get_records("course_sections", "course", "$courseid", "section",
                        "section, id, course, summary, sequence, visible");
 }
 
@@ -759,119 +759,6 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
     }
 }
 
-function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused, 
-                             $absolute=true, $width="100%") {
-
-    global $CFG, $USER, $THEME;
-    static $groupbuttons;
-    static $isteacher;
-    static $isediting;
-    static $ismoving;
-    static $strmovehere;
-    static $strmovefull;
-    static $strcancel;
-    static $stractivityclipboard;
-
-    if (!isset($isteacher)) {
-        $groupbuttons = $course->groupmode and !$course->groupmodeforce;
-        $isteacher = isteacher($course->id);
-        $isediting = isediting($course->id);
-        $ismoving = ismoving($course->id);
-        if ($ismoving) {
-            $strmovehere = get_string("movehere");
-            $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
-            $strcancel= get_string("cancel");
-            $stractivityclipboard = $USER->activitycopyname;
-        }
-    }
-
-    $modinfo = unserialize($course->modinfo);
-    $moddata = array();
-    $modicon = array();
-    $editbuttons = "";
-
-    if ($ismoving) {
-        $modicon[] = "&nbsp;<img align=bottom src=\"$CFG->pixpath/t/move.gif\" height=\"11\" width=\"11\">";
-        $moddata[] = "$USER->activitycopyname&nbsp;(<a href=\"$CFG->wwwroot/course/mod.php?cancelcopy=true\">$strcancel</a>)";
-    }
-
-    if (!empty($section->sequence)) {
-
-        $sectionmods = explode(",", $section->sequence);
-
-
-        foreach ($sectionmods as $modnumber) {
-            if (empty($mods[$modnumber])) {
-                continue;
-            }
-            $mod = $mods[$modnumber];
-            if ($isediting and !$ismoving) {
-                if (!$groupbuttons) {
-                    $mod->groupmode = false;
-                }
-                $editbuttons = "<br />".make_editing_buttons($mod, $absolute, true);
-            } else {
-                $editbuttons = "";
-            }
-            if ($mod->visible or $isteacher) {
-                if ($ismoving) {
-                    if ($mod->id == $USER->activitycopy) {
-                        continue;
-                    }
-                    $modicon[] = "";
-                    $moddata[] = "<a title=\"$strmovefull\"".
-                                 " href=\"$CFG->wwwroot/course/mod.php?moveto=$mod->id\">".
-                                 "<img height=\"16\" width=\"80\" src=\"$CFG->pixpath/movehere.gif\" ".
-                                 " alt=\"$strmovehere\" border=\"0\"></a>";
-                }
-                $instancename = urldecode($modinfo[$modnumber]->name);
-                if (!empty($CFG->filterall)) {
-                    $instancename = filter_text("<nolink>$instancename</nolink>", $course->id);
-                }
-                $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
-                if (!empty($modinfo[$modnumber]->extra)) {
-                    $extra = urldecode($modinfo[$modnumber]->extra);
-                } else {
-                    $extra = "";
-                }
-
-                if (!empty($modinfo[$modnumber]->icon)) {
-                    $icon = "$CFG->pixpath/".urldecode($modinfo[$modnumber]->icon);
-                } else {
-                    $icon = "$CFG->modpixpath/$mod->modname/icon.gif";
-                }
-
-                if ($mod->modname == "label") {
-                    $modicon[] = "";
-                    $moddata[] = format_text($extra, FORMAT_HTML).$editbuttons;
-                } else {
-                    $modicon[] = "<img src=\"$icon\"".
-                                 " height=\"16\" width=\"16\" alt=\"$mod->modfullname\">";
-                    $moddata[] = "<a title=\"$mod->modfullname\" $linkcss $extra".
-                                 "href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a>".
-                                 "$editbuttons";
-                }
-            }
-        }
-    }
-    if ($ismoving) {
-        $modicon[] = "";
-        $moddata[] = "<a title=\"$strmovefull\"".
-                     " href=\"$CFG->wwwroot/course/mod.php?movetosection=$section->id\">".
-                     "<img height=\"16\" width=\"80\" src=\"$CFG->pixpath/movehere.gif\" ".
-                     " alt=\"$strmovehere\" border=\"0\"></a>";
-    }
-    if ($isediting) {
-        $editmenu = popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section->section&add=", 
-                   $modnames, "section0", "", get_string("add")."...", "mods", get_string("activities"), true);
-        $editmenu = "<div align=right>$editmenu</div>";
-    } else {
-        $editmenu = "";
-    }
-
-    print_side_block($heading, "", $moddata, $modicon, $editmenu, $width);
-}
-
 
 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") {
 /// Prints a section full of activity modules
@@ -900,7 +787,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
 
     $modinfo = unserialize($course->modinfo);
 
-    echo "<table width=\"$width\" cellpadding=1 cellspacing=0>\n";
+    echo '<table width="'.$width.'" cellpadding="1" cellspacing="0">';
     if (!empty($section->sequence)) {
 
         $sectionmods = explode(",", $section->sequence);
@@ -1016,199 +903,9 @@ function print_heading_block($heading, $width="100%", $class="headingblock") {
     echo "</td></tr></table>";
 }
 
-function print_side_block($heading="", $content="", $list=NULL, $icons=NULL, $footer="", $width=180) {
-// Prints a nice side block with an optional header.  The content can either 
-// be a block of HTML or a list of text with optional icons.
-    
-    global $THEME;
-
-    print_side_block_start($heading, $width);
-
-    if ($content) {
-        echo "$content";
-        if ($footer) {
-            echo "<center><font size=\"-2\">$footer</font></center>";
-        }
-    } else {
-        echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
-        if ($list) {
-            foreach ($list as $key => $string) {
-                echo "<tr bgcolor=\"$THEME->cellcontent2\">";
-                if ($icons) {
-                    echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">".$icons[$key]."</td>";
-                }
-                echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"*\"><font size=\"-1\">$string</font></td>";
-                echo "</tr>";
-            }
-        }
-        if ($footer) {
-            echo "<tr bgcolor=\"$THEME->cellcontent2\">";
-            echo "<td class=\"sideblocklinks\" ";
-            if ($icons) {
-                echo ' colspan="2" ';
-            }
-            echo '>';
-            echo "<center><font size=\"-2\">$footer</font></center>";
-            echo "</td></tr>";
-        }
-        echo "</table>";
-    }
-
-    print_side_block_end();
-}
-
-function print_side_block_start($heading="", $width=180, $class="sideblockmain") {
-// Starts a nice side block with an optional header.
-    
-    global $THEME;
-
-    echo "<table class=\"sideblock\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";
-    if ($heading) {
-        echo "<tr>";
-        echo "<td class=\"sideblockheading\" bgcolor=\"$THEME->cellheading\">$heading</td>";
-        echo "</tr>";
-    }
-    echo "<tr>";
-    echo "<td class=\"$class\" bgcolor=\"$THEME->cellcontent2\">";
-}
-
-function print_side_block_end() {
-    echo "</td></tr>";
-    echo "</table><br />";
-}
-
-
-function print_admin_links ($siteid, $width=180) {
-    global $CFG, $THEME;
-    
-    if (isadmin()) {
-        $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">".get_string("configuration")."</a>...";
-        $modicon[]="<img src=\"$CFG->pixpath/i/admin.gif\" height=16 width=16 alt=\"\" />";
-
-        $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/users.php\">".get_string("users")."</a>...";
-        $modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\" />";
-    }
-
-    if (iscreator()) {
-        $moddata[]="<a href=\"$CFG->wwwroot/course/index.php?edit=on\">".get_string("courses")."</a>";
-        $modicon[]="<img src=\"$CFG->pixpath/i/course.gif\" height=16 width=16 alt=\"\" />";
-        $fulladmin = "";
-    }
-
-    if (isadmin()) {
-        $moddata[]="<a href=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("logs")."</a>";
-        $modicon[]="<img src=\"$CFG->pixpath/i/log.gif\" height=16 width=16 alt=\"\" />";
-
-        $moddata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$siteid\">".get_string("sitefiles")."</a>";
-        $modicon[]="<img src=\"$CFG->pixpath/i/files.gif\" height=16 width=16 alt=\"\" />";
-
-        if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
-            $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">".
-                        get_string("managedatabase")."</a>";
-            $modicon[]="<img src=\"$CFG->pixpath/i/db.gif\" height=16 width=16 alt=\"\" />";
-        }
-        $fulladmin = "<p><a href=\"$CFG->wwwroot/$CFG->admin/\">".get_string("admin")."</a>...";
-    }
-
-    print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width);
-
-    echo "<img src=\"$CFG->wwwroot/pix/spacer.gif\" width=\"$width\" height=1><br>";
-}
-
-function print_course_admin_links($course, $width=180) {
-    global $USER, $CFG, $THEME;
-
-    if (isguest()) {
-        return true;
-    }
-
-    if (isteacher($course->id)) {
-
-        $isteacheredit = isteacheredit($course->id);
-
-        if ($isteacheredit) {
-            $adminicon[]="<img src=\"$CFG->pixpath/i/edit.gif\" height=16 width=16 alt=\"\">";
-            if (isediting($course->id)) {
-                $admindata[]="<a href=\"view.php?id=$course->id&edit=off\">".get_string("turneditingoff")."</a>";
-            } else {
-                $admindata[]="<a href=\"view.php?id=$course->id&edit=on\">".get_string("turneditingon")."</a>";
-            }
-            $admindata[]="<a href=\"edit.php?id=$course->id\">".get_string("settings")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/settings.gif\" height=16 width=16 alt=\"\">";
-
-            if (iscreator() or !empty($CFG->teacherassignteachers)) {
-                if (!$course->teachers) {
-                    $course->teachers = get_string("defaultcourseteachers");
-                }
-                $admindata[]="<a href=\"teacher.php?id=$course->id\">$course->teachers...</a>";
-                $adminicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
-            }
-
-            if (!$course->students) {
-                $course->students = get_string("defaultcoursestudents");
-            }
-            $admindata[]="<a href=\"student.php?id=$course->id\">$course->students...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
-
-            $admindata[]="<a href=\"$CFG->wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/backup.gif\" height=16 width=16 alt=\"\">";
-        
-            $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/restore.gif\" height=16 width=16 alt=\"\">";
-            $admindata[]="<a href=\"scales.php?id=$course->id\">".get_string("scales")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/scales.gif\" height=16 width=16 alt=\"\">";
-        }
-    
-        $admindata[]="<a href=\"grades.php?id=$course->id\">".get_string("grades")."...</a>";
-        $adminicon[]="<img src=\"$CFG->pixpath/i/grades.gif\" height=16 width=16 alt=\"\">";
-    
-        $admindata[]="<a href=\"log.php?id=$course->id\">".get_string("logs")."...</a>";
-        $adminicon[]="<img src=\"$CFG->pixpath/i/log.gif\" height=16 width=16 alt=\"\">";
-
-        if ($isteacheredit) {
-            $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/files.gif\" height=16 width=16 alt=\"\">";
-        }
-
-        $admindata[]="<a href=\"$CFG->wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...</a>";
-        $adminicon[]="<img src=\"$CFG->modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">";
-
-        if ($teacherforum = forum_get_course_forum($course->id, "teacher")) {
-            $admindata[]="<a href=\"$CFG->wwwroot/mod/forum/view.php?f=$teacherforum->id\">".get_string("nameteacher","forum")."</a>";
-            $adminicon[]="<img src=\"$CFG->modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">";
-        }
-
-    } else if (!isguest()) {  // Students menu
-        if ($course->showgrades) {
-            $admindata[]="<a href=\"grade.php?id=$course->id\">".get_string("grades")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/grades.gif\" height=16 width=16 alt=\"\">";
-        }
-        if ($course->showreports) {
-            $admindata[]="<a href=\"user.php?id=$course->id&user=$USER->id\">".get_string("activityreport")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/report.gif\" height=16 width=16 alt=\"\">";
-        }
-        if (is_internal_auth()) {
-            $admindata[]="<a href=\"$CFG->wwwroot/login/change_password.php?id=$course->id\">".
-                          get_string("changepassword")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
-        } else if ($CFG->changepassword) {
-            $admindata[]="<a href=\"$CFG->changepassword\">".get_string("changepassword")."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
-        }
-        if ($CFG->allowunenroll) {
-            $admindata[]="<a href=\"unenrol.php?id=$course->id\">".get_string("unenrolme", "", $course->shortname)."...</a>";
-            $adminicon[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
-        }
-    } 
-
-    if (!empty($admindata)) {
-        print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width);
-    }
-}
-
 
 function make_categories_list(&$list, &$parents, $category=NULL, $path="") {
-/// Given an empty array, this function recursively travels the 
+/// Given an empty array, this function recursively travels the
 /// categories, building up a nice list for display.  It also makes
 /// an array that list all the parents for each category.
 
@@ -1231,14 +928,14 @@ function make_categories_list(&$list, &$parents, $category=NULL, $path="") {
                 }
                 $parents[$cat->id][] = $category->id;
             }
-            make_categories_list($list, $parents, $cat, $path);         
+            make_categories_list($list, $parents, $cat, $path);
         }
     }
 }
 
 
 function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1) {
-/// Recursive function to print out all the categories in a nice format 
+/// Recursive function to print out all the categories in a nice format
 /// with or without courses included
     global $CFG;
     if (isset($CFG->max_category_depth)&&($depth >= $CFG->max_category_depth)) {
@@ -1255,7 +952,7 @@ function print_whole_category_list($category=NULL, $displaylist=NULL, $parentsli
         } else {
             return;  // Don't bother printing children of invisible categories
         }
-        
+
     } else {
         $category->id = "0";
     }
@@ -1274,7 +971,7 @@ function print_whole_category_list($category=NULL, $displaylist=NULL, $parentsli
             $down = $last ? false : true;
             $first = false;
 
-            print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1);         
+            print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1);
         }
     }
 }
@@ -1315,7 +1012,7 @@ function print_category_info($category, $depth) {
             print_spacer(10, $indent);
             echo "</td>";
         }
-    
+
         echo "<td valign=\"top\">$catimage</td>";
         echo "<td valign=\"top\" width=\"100%\" class=\"categoryname\">";
         echo "<a $catlinkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>";
@@ -1343,8 +1040,8 @@ function print_category_info($category, $depth) {
                     echo "<img alt=\"\" height=16 width=18 border=0 src=\"$CFG->pixpath/spacer.gif\">";
                 }
                 if ($course->summary) {
-                    link_to_popup_window ("/course/info.php?id=$course->id", "courseinfo", 
-                                          "<img hspace=1 alt=\"$strsummary\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/info.gif\">", 
+                    link_to_popup_window ("/course/info.php?id=$course->id", "courseinfo",
+                                          "<img hspace=1 alt=\"$strsummary\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/info.gif\">",
                                            400, 500, $strsummary);
                 } else {
                     echo "<img alt=\"\" height=16 width=18 border=0 src=\"$CFG->pixpath/spacer.gif\">";
@@ -1360,7 +1057,7 @@ function print_category_info($category, $depth) {
             print_spacer(10, $indent);
             echo "</td>";
         }
-    
+
         echo "<td valign=\"top\" width=\"100%\" class=\"categoryname\">";
         echo "<a $catlinkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>";
         echo "</td>";
@@ -1369,68 +1066,7 @@ function print_category_info($category, $depth) {
     echo "\n</table>\n";
 }
 
-function print_courses_sideblock($category=0, $width="100%") {
-    global $CFG, $THEME, $USER;
 
-    if (empty($THEME->custompix)) {
-        $icon  = "<img src=\"$CFG->wwwroot/pix/i/course.gif\"".
-                 " height=\"16\" width=\"16\" alt=\"".get_string("course")."\">";
-    } else {
-        $icon  = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/course.gif\"".
-                 " height=\"16\" width=\"16\" alt=\"".get_string("course")."\">";
-    }
-
-    if (isset($USER->id) and !isadmin()) {    // Just print My Courses
-        if ($courses = get_my_courses($USER->id)) {
-            foreach ($courses as $course) {
-                if (!$course->category) {
-                    continue;
-                }
-                $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
-                $moddata[]="<a $linkcss title=\"$course->shortname\" ".
-                           "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
-                $modicon[]=$icon;
-            }
-            $fulllist = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...</p>";
-            print_side_block( get_string("mycourses"), "", $moddata, $modicon, $fulllist, $width);
-            return;
-        }
-    }
-
-    $categories = get_categories("0");  // Parent = 0   ie top-level categories only
-    if (count($categories) > 1) {     // Just print top level category links
-        foreach ($categories as $category) {
-            $linkcss = $category->visible ? "" : " class=\"dimmed\" ";
-            $moddata[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>";
-            $modicon[]=$icon;
-        }
-        $fulllist = "<p><a href=\"$CFG->wwwroot/course/\">".get_string("searchcourses")."</a>...</p>";
-        $blocktitle = get_string("categories");
-
-    } else {                          // Just print course names of single category
-        $category = array_shift($categories);
-        $courses = get_courses($category->id);
-
-        if ($courses) {
-            foreach ($courses as $course) {
-                $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
-                $moddata[]="<a $linkcss title=\"$course->shortname\" ".
-                           "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
-                $modicon[]=$icon;
-            }   
-            $fulllist = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...</p>";
-        } else {
-            $moddata = array();
-            $modicon = array();
-            $fulllist = get_string("nocoursesyet");
-        }
-        $blocktitle = get_string("courses");
-    }
-
-    print_side_block($blocktitle, "", $moddata, $modicon, $fulllist, $width);
-}
-
-    
 function print_courses($category, $width="100%") {
 /// Category is 0 (for all courses) or an object
 
@@ -1477,7 +1113,7 @@ function print_course($course, $width="100%") {
     echo "<table width=\"100%\">";
     echo "<tr valign=top>";
     echo "<td valign=top width=\"50%\" class=\"courseboxinfo\">";
-    echo "<p><font size=3><b><a title=\"".get_string("entercourse")."\" 
+    echo "<p><font size=3><b><a title=\"".get_string("entercourse")."\"
               $linkcss href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a></b></font></p>";
     if ($teachers = get_course_teachers($course->id)) {
         echo "<p><font size=\"1\">\n";
@@ -1622,13 +1258,13 @@ function add_mod_to_section($mod, $beforemod=NULL) {
         } else {
             $newsequence = "$section->sequence,$mod->coursemodule";
         }
-        
+
         if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) {
             return $section->id;     // Return course_sections ID that was used.
         } else {
             return 0;
         }
-       
+
     } else {  // Insert a new record
         $section->course = $mod->course;
         $section->section = $mod->section;
@@ -1681,7 +1317,7 @@ function delete_mod_from_section($mod, $section) {
         } else {
             return false;
         }
-       
+
     }
     return false;
 }
@@ -1732,7 +1368,7 @@ function moveto_module($mod, $section, $beforemod=NULL) {
 /// Update module itself if necessary
 
     if ($mod->section != $section->id) {
-        $mod->section = $section->id; 
+        $mod->section = $section->id;
 
         if (!update_record("course_modules", $mod)) {
             return false;
@@ -1792,7 +1428,7 @@ function move_module($cm, $move) {
 
             } else {               // Push onto end of previous section
                 $prevsectionnumber = $thissection->section - 1;
-                if (! $prevsection = get_record("course_sections", "course", "$thissection->course", 
+                if (! $prevsection = get_record("course_sections", "course", "$thissection->course",
                                                                    "section", "$prevsectionnumber")) {
                     error("Previous section ($prevsection->id) doesn't exist");
                 }
@@ -1824,7 +1460,7 @@ function move_module($cm, $move) {
             $swap = $mods[$thepos-1];
             $mods[$thepos-1] = $mods[$thepos];
             $mods[$thepos] = $swap;
-            
+
             $newsequence = implode(",", $mods);
             if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
                 error("This section could not be updated");
@@ -1836,7 +1472,7 @@ function move_module($cm, $move) {
 
         if ($last) {
             $nextsectionnumber = $thissection->section + 1;
-            if ($nextsection = get_record("course_sections", "course", "$thissection->course", 
+            if ($nextsection = get_record("course_sections", "course", "$thissection->course",
                                                                "section", "$nextsectionnumber")) {
 
                 if (!empty($nextsection->sequence)) {
@@ -1868,7 +1504,7 @@ function move_module($cm, $move) {
             $swap = $mods[$thepos+1];
             $mods[$thepos+1] = $mods[$thepos];
             $mods[$thepos] = $swap;
-            
+
             $newsequence = implode(",", $mods);
             if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
                 error("This section could not be updated");
index 7612c5c66cfe6312fca5e32cc1f7748981b19acb..8f6311637a96edbcbd13ce48e88df2d6a1700597 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,9 +1,10 @@
 <?PHP  // $Id$
        // index.php - the front page.
-    
+
     require_once("config.php");
     require_once("course/lib.php");
-    require_once("mod/resource/lib.php"); 
+    require_once('lib/blocklib.php');
+    require_once("mod/resource/lib.php");
     require_once("mod/forum/lib.php");
 
     if (! $site = get_site()) {
                  "<meta name=\"description\" content=\"".s(strip_tags($site->summary))."\">",
                  true, "", "$loginstring$langmenu");
 
-    $firstcolumn = false;  // for now
-    $lastcolumn = false;   // for now
-    $side = 175;
+    $editing = isediting($site->id);
+
+    $courseformat = COURSE_FORMAT_SITE;
+
+    // Doing this now so we can pass the results to block_action()
+    // and dodge the overhead of doing the same work twice.
 
-    $site_summary_editbuttons = '';
-    if (isediting($site->id)) {
-        $site_summary_editbuttons = "<br><center><a href=\"$CFG->admin/site.php\"><img src=\"pix/i/edit.gif\" border=0></a>";
+    $blocks = $site->blockinfo;
+    $delimpos = strpos($blocks, ':');
+
+    if($delimpos === false) {
+        // No ':' found, we have all left blocks
+        $leftblocks = explode(',', $blocks);
+        $rightblocks = array();
+    }
+    else if($delimpos === 0) {
+        // ':' at start of string, we have all right blocks
+        $blocks = substr($blocks, 1);
+        $leftblocks = array();
+        $rightblocks = explode(',', $blocks);
+    }
+    else {
+        // Both left and right blocks
+        $leftpart = substr($blocks, 0, $delimpos);
+        $rightpart = substr($blocks, $delimpos + 1);
+        $leftblocks = explode(',', $leftpart);
+        $rightblocks = explode(',', $rightpart);
     }
 
-    if ($site->summary) {
-        $lastcolumn = true;
+    if($editing) {
+        if (isset($_GET['blockaction'])) {
+            if (isset($_GET['blockid'])) {
+                block_action($site, $leftblocks, $rightblocks, strtolower($_GET['blockaction']), intval($_GET['blockid']));
+            }
+        }
+
+        // This has to happen after block_action() has possibly updated the two arrays
+        $allblocks = array_merge($leftblocks, $rightblocks);
+
+        $missingblocks = array();
+        $recblocks = get_records('blocks','visible','1');
+
+        // Note down which blocks are going to get displayed
+        blocks_used($allblocks, $recblocks);
+
+        if($editing && $recblocks) {
+            foreach($recblocks as $recblock) {
+                // If it's not hidden or displayed right now...
+                if(!in_array($recblock->id, $allblocks) && !in_array(-($recblock->id), $allblocks)) {
+                    // And if it's applicable for display in this format...
+                    if(block_method_result($recblock->name, 'applicable_formats') & $courseformat) {
+                        // Add it to the missing blocks
+                        $missingblocks[] = $recblock->id;
+                    }
+                }
+            }
+        }
     }
+    else {
+        // Note down which blocks are going to get displayed
+        $allblocks = array_merge($leftblocks, $rightblocks);
+        $recblocks = get_records('blocks','visible','1');
+        blocks_used($allblocks, $recblocks);
+    }
+
+    // If the block width cache is not set, set it
+    if(!isset($SESSION->blockcache->width->{$site->id}) || $editing) {
+        // This query might be optimized away if we 're in editing mode
+        if(!isset($recblocks)) {
+            $recblocks = get_records('blocks','visible','1');
+        }
+        $preferred_width_left = blocks_preferred_width($leftblocks, $recblocks);
+        $preferred_width_right = blocks_preferred_width($rightblocks, $recblocks);
 
+        // This may be kind of organizational overkill, granted...
+        // But is there any real need to simplify the structure?
+        $SESSION->blockcache->width->{$site->id}->left = $preferred_width_left;
+        $SESSION->blockcache->width->{$site->id}->right = $preferred_width_right;
+    }
+    else {
+        $preferred_width_left = $SESSION->blockcache->width->{$site->id}->left;
+        $preferred_width_right = $SESSION->blockcache->width->{$site->id}->right;
+    }
 
 ?>
 
 
 <table width="100%" border="0" cellspacing="5" cellpadding="5">
   <tr>
-  <?PHP 
-     $sections = get_all_sections($site->id);
-  
-     if ($site->newsitems > 0 or $sections[0]->sequence or isediting($site->id) or isadmin()) {
-
-         echo "<td width=\"$side\" valign=top nowrap>"; 
-         $firstcolumn=true;
-  
-         if ($sections[0]->sequence or isediting($site->id)) {
-             get_all_mods($site->id, $mods, $modnames, $modnamesplural, $modnamesused);
-             print_section_block(get_string("mainmenu"), $site, $sections[0], 
-                                 $mods, $modnames, $modnamesused, true, $side);
-         }
-
-         if (isadmin()) {
-             echo "<div align=\"center\">".update_course_icon($site->id)."</div>";
-             echo "<br />";
-         }
-
-         switch ($CFG->frontpage) {
-             case FRONTPAGENEWS:       // print news links on the side
-                 print_courses_sideblock(0, "$side");
-             break;
-    
-             case FRONTPAGECOURSELIST:
-             case FRONTPAGECATEGORYNAMES:
-                 if ($site->newsitems) {
-                     if ($news = forum_get_course_forum($site->id, "news")) {
-                         print_side_block_start(get_string("latestnews"), $side, "sideblocklatestnews");
-                         echo "<font size=\"-2\">";
-                         forum_print_latest_discussions($news->id, $site->newsitems, "minimal", "", false);
-                         echo "</font>";
-                         print_side_block_end();
-                     }
-                 }
-             break;
-         } 
-         print_spacer(1,$side);
-     }
-     if (iscreator()) {
-         if (!$firstcolumn) {
-             echo "<td width=\"$side\" valign=top nowrap>"; 
-             $firstcolumn=true;
-         }
-         print_admin_links($site->id, $side);
-     }
-
-     if ($firstcolumn) {
-         echo "</td>";
-     }
-     if ($lastcolumn) {
-         echo "<td width=\"70%\" valign=\"top\">";
-     } else {
-         echo "<td width=\"100%\" valign=\"top\">";
-     }
-
-     switch ($CFG->frontpage) {     /// Display the main part of the front page.
-         case FRONTPAGENEWS:
-             if (! $newsforum = forum_get_course_forum($site->id, "news")) {
-                 error("Could not find or create a main news forum for the site");
-             }
-    
-             if (isset($USER->id)) {
-                 $SESSION->fromdiscussion = "$CFG->wwwroot";
-                 if (forum_is_subscribed($USER->id, $newsforum->id)) {
-                     $subtext = get_string("unsubscribe", "forum");
-                 } else {
-                     $subtext = get_string("subscribe", "forum");
-                 }
-                 $headertext = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=headingblockcontent><tr>
-                                <td>$newsforum->name</td>
-                                <td align=right><font size=1>
-                                <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
-                                </td></tr></table>";
-             } else {
-                 $headertext = $newsforum->name;
-             }
-             print_heading_block($headertext);
-             print_spacer(8,1);
-             forum_print_latest_discussions($newsforum->id, $site->newsitems);
-         break;
-    
-         case FRONTPAGECOURSELIST:
-         case FRONTPAGECATEGORYNAMES:
-             if (isset($USER->id) and !isset($USER->admin)) {
-                 print_heading_block(get_string("mycourses"));
-                 print_spacer(8,1);
-                 print_my_moodle();
-             } else {
-                 if (count_records("course_categories") > 1) {
-                     if ($CFG->frontpage == FRONTPAGECOURSELIST) {
-                         print_heading_block(get_string("availablecourses"));
-                     } else {
-                         print_heading_block(get_string("categories"));
-                     }
-                     print_spacer(8,1);
-                     print_simple_box_start("center", "100%");
-                     print_whole_category_list();
-                     print_simple_box_end();
-                     print_course_search("", false, "short");
-                 } else {
-                     print_heading_block(get_string("availablecourses"));
-                     print_spacer(8,1);
-                     print_courses(0, "100%");
-                 }
-             }
-         break;
-
-     }
-
-     echo "</td>";
-
-     if ($lastcolumn) {
-         echo "<td width=\"30%\" valign=\"top\">";
-         print_simple_box(format_text($site->summary, FORMAT_HTML).$site_summary_editbuttons, 
-                          "", "100%", $THEME->cellcontent2, 5, "siteinfo");
-         print_spacer(1,$side);
-         echo "</td>";
-     }
-  ?>
+  <?PHP
+
+    if(block_have_active($leftblocks) || $editing) {
+        echo '<td style="vertical-align: top; width: '.$preferred_width_left.'px;">';
+        print_course_blocks($site, $leftblocks, BLOCK_LEFT);
+        echo '</td>';
+    }
+
+    echo '<td style="vertical-align: top;">';
+    switch ($CFG->frontpage) {     /// Display the main part of the front page.
+        case FRONTPAGENEWS:
+            if (! $newsforum = forum_get_course_forum($site->id, "news")) {
+                error("Could not find or create a main news forum for the site");
+            }
+
+            if (isset($USER->id)) {
+                $SESSION->fromdiscussion = "$CFG->wwwroot";
+                if (forum_is_subscribed($USER->id, $newsforum->id)) {
+                    $subtext = get_string("unsubscribe", "forum");
+                } else {
+                    $subtext = get_string("subscribe", "forum");
+                }
+                $headertext = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=headingblockcontent><tr>
+                               <td>$newsforum->name</td>
+                               <td align=right><font size=1>
+                               <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
+                               </td></tr></table>";
+            } else {
+                $headertext = $newsforum->name;
+            }
+            print_heading_block($headertext);
+            print_spacer(8,1);
+            forum_print_latest_discussions($newsforum->id, $site->newsitems);
+        break;
+
+        case FRONTPAGECOURSELIST:
+        case FRONTPAGECATEGORYNAMES:
+            if (isset($USER->id) and !isset($USER->admin)) {
+                print_heading_block(get_string("mycourses"));
+                print_spacer(8,1);
+                print_my_moodle();
+            } else {
+                if (count_records("course_categories") > 1) {
+                    if ($CFG->frontpage == FRONTPAGECOURSELIST) {
+                        print_heading_block(get_string("availablecourses"));
+                    } else {
+                        print_heading_block(get_string("categories"));
+                    }
+                    print_spacer(8,1);
+                    print_simple_box_start("center", "100%");
+                    print_whole_category_list();
+                    print_simple_box_end();
+                    print_course_search("", false, "short");
+                } else {
+                    print_heading_block(get_string("availablecourses"));
+                    print_spacer(8,1);
+                    print_courses(0, "100%");
+                }
+            }
+        break;
+
+    }
+
+    echo '</td>';
+    if(block_have_active($rightblocks) || $editing || isadmin()) {
+        echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;">';
+        if (isadmin()) {
+            echo '<div align="center">'.update_course_icon($site->id).'</div>';
+            echo '<br />';
+        }
+        print_course_blocks($site, $rightblocks, BLOCK_RIGHT);
+        if ($editing && !empty($missingblocks)) {
+            block_print_blocks_admin($site->id, $missingblocks);
+        }
+        echo '</td>';
+    }
+?>
 
   </tr>
 </table>
 
-<?PHP print_footer("home");     // Please do not modify this line ?>
+<?PHP print_footer('home');     // Please do not modify this line ?>
 
index 6610c9c9d84c3c09eb3c300fa890666b0b5fcfd3..1e412fea0da4024f43ac38438aae805fb011f74c 100644 (file)
@@ -9,9 +9,10 @@ define('BLOCK_MOVE_RIGHT',  0x02);
 define('BLOCK_MOVE_UP',     0x04);
 define('BLOCK_MOVE_DOWN',   0x08);
 
-define('COURSE_FORMAT_WEEKS',   0x01);
-define('COURSE_FORMAT_TOPICS',  0x02);
-define('COURSE_FORMAT_SOCIAL',  0x04);
+define('COURSE_FORMAT_SITE',    0x01);
+define('COURSE_FORMAT_WEEKS',   0x02);
+define('COURSE_FORMAT_TOPICS',  0x04);
+define('COURSE_FORMAT_SOCIAL',  0x08);
 
 //This function retrieves a method-defined property of a class WITHOUT instantiating an object
 //It seems that the only way to use the :: operator with variable class names is eval() :(
@@ -327,7 +328,14 @@ function block_print_blocks_admin($courseid, $missingblocks) {
                     }
                     $menu[$block->id] = $blockobject->get_title();
                 }
-                $content = popup_form('view.php?id='.$courseid.'&amp;blockaction=add&amp;blockid=',
+
+                if($courseid == 1) {
+                    $target = 'index.php';
+                }
+                else {
+                    $target = 'view.php';
+                }
+                $content = popup_form($target.'?id='.$courseid.'&amp;blockaction=add&amp;blockid=',
                                       $menu, 'add_block', '', "$stradd...", '', '', true);
                 $content = '<div align="center">'.$content.'</div>';
                 print_side_block($strblocks, $content, NULL, NULL, NULL);
@@ -718,7 +726,7 @@ function block_get_name_by_id ($blockid) {
 //then the function will update the field too!
 
 function blocks_get_default_blocks ($courseid = NULL, $blocknames="") {
+
     global $CFG;
 
     if (empty($blocknames)) {
index 88b8fab939463cba7cfb551255ea817cf93ce57e..9fc2b5a89914f34ff600bb8fdf9373f4162b672e 100644 (file)
@@ -1012,7 +1012,6 @@ function print_footer ($course=NULL) {
 // to the course home page, otherwise the link will go to the site home
     global $USER, $CFG, $THEME;
 
-
 /// Course links
     if ($course) {
         if ($course == "home") {   // special case for site home page - please do not remove
@@ -2216,5 +2215,88 @@ function rebuildnolinktag($text) {
     return $text;
 }
 
+// ================================================
+// THREE FUNCTIONS MOVED HERE FROM course/lib.php
+// ================================================
+
+function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array()) {
+// Prints a nice side block with an optional header.  The content can either
+// be a block of HTML or a list of text with optional icons.
+
+    global $THEME;
+
+    print_side_block_start($heading, $attributes);
+
+    if ($content) {
+        echo $content;
+        if ($footer) {
+            echo "<center><font size=\"-2\">$footer</font></center>";
+        }
+    } else {
+        echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
+        if ($list) {
+            foreach ($list as $key => $string) {
+                echo "<tr bgcolor=\"$THEME->cellcontent2\">";
+                if ($icons) {
+                    echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">".$icons[$key]."</td>";
+                }
+                echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"*\"><font size=\"-1\">$string</font></td>";
+                echo "</tr>";
+            }
+        }
+        if ($footer) {
+            echo "<tr bgcolor=\"$THEME->cellcontent2\">";
+            echo "<td class=\"sideblocklinks\" ";
+            if ($icons) {
+                echo ' colspan="2" ';
+            }
+            echo '>';
+            echo "<center><font size=\"-2\">$footer</font></center>";
+            echo "</td></tr>";
+        }
+        echo "</table>";
+    }
+
+    print_side_block_end();
+}
+
+function print_side_block_start($heading='', $attributes = array()) {
+// Starts a nice side block with an optional header.
+    global $THEME;
+
+    // If there are no special attributes, give a default CSS class
+    if(empty($attributes) || !is_array($attributes)) {
+        $attributes = array('class' => 'sideblock');
+    }
+    else if(!isset($attributes['class'])) {
+        $attributes['class'] = 'sideblock';
+    }
+    else if(!strpos($attributes['class'], 'sideblock')) {
+        $attributes['class'] .= ' sideblock';
+    }
+    // OK, the class is surely there and in addition to anything
+    // else, it's tagged as a sideblock
+
+    $attrtext = '';
+    foreach($attributes as $attr => $val) {
+       $attrtext .= ' '.$attr.'="'.$val.'"';
+    }
+
+    // [pj] UGLY UGLY UGLY! I hate myself for doing this!
+    // When the Lord Moodle 2.0 cometh, his mercy shalt move all this mess
+    // to CSS and banish the evil to the abyss from whence it came.
+    echo '<table style="width: 100%;" cellspacing="0" cellpadding="5"'.$attrtext.'>';
+    if ($heading) {
+        echo '<thead class="sideblockheading"><tr><td>'.$heading.'</td></tr></thead>';
+    }
+    echo '<tbody style="background-color: '.$THEME->cellcontent2.';"><tr><td class="sideblockmain">';
+}
+
+function print_side_block_end() {
+    echo '</td></tr></tbody></table><br />';
+    echo "\n";
+}
+
+
 // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
 ?>
index 6952004b3e43142389dac922427e78661db457c4..807ddf565e2d5f25ff264dfaa9b5fecb2dc8a63d 100644 (file)
@@ -5,9 +5,9 @@
 // database to determine whether upgrades should
 // be performed (see lib/db/*.php)
 
-$version = 2004052500;   // The current version is a date (YYYYMMDDXX)
+$version = 2004052800;   // The current version is a date (YYYYMMDDXX)
 
-$release = "1.3";   // User-friendly version number
+$release = "1.4 development";   // User-friendly version number
 
 
 ?>