From 89adb17442815058ff107ae4778919c5417682ce Mon Sep 17 00:00:00 2001 From: defacer Date: Fri, 28 May 2004 10:53:54 +0000 Subject: [PATCH] Merging the changes from 1.4 dev branch (site index blocks + various bugfixes) --- blocks/admin/block_admin.php | 58 ++- .../calendar_month/block_calendar_month.php | 6 +- .../block_calendar_upcoming.php | 8 +- blocks/course_list/block_course_list.php | 14 +- .../course_summary/block_course_summary.php | 10 +- blocks/moodleblock.class.php | 15 +- blocks/news_items/block_news_items.php | 7 +- blocks/online_users/block_online_users.php | 6 +- blocks/participants/block_participants.php | 18 +- blocks/section_links/block_section_links.php | 9 +- .../site_main_menu/block_site_main_menu.php | 126 +++++ blocks/version.php | 2 +- calendar/event.php | 26 +- calendar/lib.php | 22 +- calendar/set.php | 10 +- calendar/view.php | 20 +- course/format/topics/format.php | 6 +- course/lib.php | 434 ++---------------- index.php | 291 ++++++------ lib/blocklib.php | 18 +- lib/weblib.php | 84 +++- version.php | 4 +- 22 files changed, 587 insertions(+), 607 deletions(-) create mode 100644 blocks/site_main_menu/block_site_main_menu.php diff --git a/blocks/admin/block_admin.php b/blocks/admin/block_admin.php index 77d524d76a..8eb6a9f97d 100644 --- a/blocks/admin/block_admin.php +++ b/blocks/admin/block_admin.php @@ -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[] = ''.get_string('configuration').'...'; + $this->content->icons[] = ''; + + $this->content->items[] = ''.get_string('users').'...'; + $this->content->icons[] = ''; + } + + if (iscreator()) { + $this->content->items[] = ''.get_string('courses').''; + $this->content->icons[] = ''; + } + + if (isadmin()) { + $this->content->items[] = ''.get_string('logs').''; + $this->content->icons[] = ''; + + $this->content->items[] = ''.get_string('sitefiles').''; + $this->content->icons[] = ''; + + if (file_exists($CFG->dirroot.'/'.$CFG->admin.'/'.$CFG->dbtype)) { + $this->content->items[] = ''.get_string('managedatabase').''; + $this->content->icons[] = ''; + } + $this->content->footer = ''.get_string('admin').'...'; + } + } + + 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[]=''.get_string('grades').'...'; $this->content->icons[]=''; @@ -102,8 +152,6 @@ class CourseBlock_admin extends MoodleBlock { $this->content->icons[]=''; } } - - return $this->content; } } diff --git a/blocks/calendar_month/block_calendar_month.php b/blocks/calendar_month/block_calendar_month.php index 06b4071b5d..6f9bbe3745 100644 --- a/blocks/calendar_month/block_calendar_month.php +++ b/blocks/calendar_month/block_calendar_month.php @@ -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() { diff --git a/blocks/calendar_upcoming/block_calendar_upcoming.php b/blocks/calendar_upcoming/block_calendar_upcoming.php index 49e2eda3fc..6eb8baff39 100644 --- a/blocks/calendar_upcoming/block_calendar_upcoming.php +++ b/blocks/calendar_upcoming/block_calendar_upcoming.php @@ -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 = '
'.get_string('gotocalendar', 'calendar').'...'; - $this->content->footer .= '
'.get_string('newevent', 'calendar').'...'; + $this->content->footer .= '
'.get_string('newevent', 'calendar').'...'; if($this->course === NULL) { // Overrides: use no course at all diff --git a/blocks/course_list/block_course_list.php b/blocks/course_list/block_course_list.php index 980bf7c5df..c48ea436f4 100644 --- a/blocks/course_list/block_course_list.php +++ b/blocks/course_list/block_course_list.php @@ -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 = "

wwwroot/course/index.php\">".get_string("fulllistofcourses")."..."; + $this->content->footer = "wwwroot/course/index.php\">".get_string("fulllistofcourses")."..."; return $this->content; } } @@ -53,12 +57,12 @@ class CourseBlock_course_list extends MoodleBlock { $this->content->items[]="wwwroot/course/category.php?id=$category->id\">$category->name"; $this->content->icons[]=$icon; } - $this->content->footer = "

wwwroot/course/\">".get_string("searchcourses")."..."; + $this->content->footer = "wwwroot/course/\">".get_string("searchcourses")."..."; $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"; $this->content->icons[]=$icon; } - $this->content->footer = "

wwwroot/course/index.php\">".get_string("fulllistofcourses")."..."; + $this->content->footer = "wwwroot/course/index.php\">".get_string("fulllistofcourses")."..."; } else { $this->content->items = array(); $this->content->icons = array(); diff --git a/blocks/course_summary/block_course_summary.php b/blocks/course_summary/block_course_summary.php index 69e00e4046..86963a5eb6 100644 --- a/blocks/course_summary/block_course_summary.php +++ b/blocks/course_summary/block_course_summary.php @@ -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; } diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index 49038d9f9c..0940956812 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -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, ' ', 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()); } } diff --git a/blocks/news_items/block_news_items.php b/blocks/news_items/block_news_items.php index 42a610991a..7357713672 100644 --- a/blocks/news_items/block_news_items.php +++ b/blocks/news_items/block_news_items.php @@ -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 = ''; diff --git a/blocks/online_users/block_online_users.php b/blocks/online_users/block_online_users.php index 9b7b9f6521..755eecf522 100644 --- a/blocks/online_users/block_online_users.php +++ b/blocks/online_users/block_online_users.php @@ -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;} diff --git a/blocks/participants/block_participants.php b/blocks/participants/block_participants.php index b1ae1edb33..9ed78fc408 100644 --- a/blocks/participants/block_participants.php +++ b/blocks/participants/block_participants.php @@ -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 = ''.get_string('editmyprofile').''; - if ($USER->description) { - $this->content->items[]= $editmyprofile; - } else { - $this->content->items[]= $editmyprofile." *"; + if(!empty($USER)) { + $fullname = fullname($USER, true); + $editmyprofile = ''.get_string('editmyprofile').''; + if ($USER->description) { + $this->content->items[]= $editmyprofile; + } else { + $this->content->items[]= $editmyprofile." *"; + } + $this->content->icons[]=''; } - $this->content->icons[]=''; return $this->content; } diff --git a/blocks/section_links/block_section_links.php b/blocks/section_links/block_section_links.php index 525e2f5b87..57349ee9d6 100644 --- a/blocks/section_links/block_section_links.php +++ b/blocks/section_links/block_section_links.php @@ -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 .= "
$linktext"; } - - $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 index 0000000000..9d99bb1e5d --- /dev/null +++ b/blocks/site_main_menu/block_site_main_menu.php @@ -0,0 +1,126 @@ +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[] = ' '; + $this->content->icons[] = $USER->activitycopyname.' ('.$strcancel.')'; + } + + 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 = '
'.make_editing_buttons($mod, true, true); + } else { + $editbuttons = ''; + } + if ($mod->visible || $isteacher) { + if ($ismoving) { + if ($mod->id == $USER->activitycopy) { + continue; + } + $this->content->items[] = ''. + ''.$strmovehere.''; + $this->content->icons[] = ''; + } + $instancename = urldecode($modinfo[$modnumber]->name); + if (!empty($CFG->filterall)) { + $instancename = filter_text(''.$instancename.'', $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[] = ''.$instancename.''.$editbuttons; + $this->content->icons[] = ''.$mod->modfullname.''; + } + } + } + } + + if ($ismoving) { + $this->content->items[] = ''. + ''.$strmovehere.''; + $this->content->icons[] = ''; + } + + if ($isediting && $modnames) { + $this->content->footer = '

'. + popup_form($CFG->wwwroot.'/course/mod.php?id='.$this->course->id.'&section='.$section->section.'&add=', + $modnames, 'section0', '', get_string('add').'...', 'mods', get_string('activities'), true) . '
'; + } else { + $this->content->footer = ''; + } + + return $this->content; + } +} + +?> diff --git a/blocks/version.php b/blocks/version.php index acb59cc956..05834435d2 100644 --- a/blocks/version.php +++ b/blocks/version.php @@ -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) diff --git a/calendar/event.php b/calendar/event.php index 6167f29b62..7031a87d45 100644 --- a/calendar/event.php +++ b/calendar/event.php @@ -71,6 +71,22 @@ $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'); @@ -230,7 +246,7 @@ $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(); } @@ -261,7 +277,7 @@ $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) { @@ -391,7 +407,7 @@ $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)) { @@ -424,7 +440,7 @@ 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); } diff --git a/calendar/lib.php b/calendar/lib.php index 4d1170b2f9..d0815fc904 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -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)); diff --git a/calendar/set.php b/calendar/set.php index 0b78e8e8ff..066fa0ce16 100644 --- a/calendar/set.php +++ b/calendar/set.php @@ -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) { @@ -85,12 +88,7 @@ $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; } diff --git a/calendar/view.php b/calendar/view.php index 399ba26ed8..d91050e891 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -95,8 +95,16 @@ // 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); + } } } @@ -151,7 +159,7 @@ // START: Last column (3-month display) echo ''; - 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.'&cal_m='.$mon.'&cal_y='.$yr; // For filtering @@ -207,7 +215,7 @@ function calendar_show_day($d, $m, $y, $courses, $groups, $users) { $text.= ''; } - print_side_block_start($text, '', 'mycalendar'); + print_side_block_start($text, array('class' => 'mycalendar')); echo '

'.calendar_top_controls('day', array('d' => $d, 'm' => $m, 'y' => $y)).'

'; if (empty($events)) { @@ -316,7 +324,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) { $text.= ''; } - 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.= ''; } - print_side_block_start($text, '', 'mycalendar'); + print_side_block_start($text, array('class' => 'mycalendar')); if ($events) { foreach ($events as $event) { calendar_print_event($event); diff --git a/course/format/topics/format.php b/course/format/topics/format.php index edce8e0ab8..6412a992bd 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -98,7 +98,7 @@ $thissection = $sections[$section]; if ($thissection->summary or $thissection->sequence or isediting($course->id)) { - echo ""; + echo ''; echo "cellheading\" class=\"topicsoutlineside\" valign=top width=20> "; echo "cellcontent\" class=\"topicsoutlinecontent\" width=\"100%\">"; @@ -190,11 +190,11 @@ echo ""; if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students - echo ""; + echo ''; echo get_string("notavailable"); echo ""; } else { - echo ""; + echo ''; echo format_text($thissection->summary, FORMAT_HTML); diff --git a/course/lib.php b/course/lib.php index b31906b969..f2bffe6174 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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[] = " pixpath/t/move.gif\" height=\"11\" width=\"11\">"; - $moddata[] = "$USER->activitycopyname (wwwroot/course/mod.php?cancelcopy=true\">$strcancel)"; - } - - 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 = "
".make_editing_buttons($mod, $absolute, true); - } else { - $editbuttons = ""; - } - if ($mod->visible or $isteacher) { - if ($ismoving) { - if ($mod->id == $USER->activitycopy) { - continue; - } - $modicon[] = ""; - $moddata[] = "wwwroot/course/mod.php?moveto=$mod->id\">". - "pixpath/movehere.gif\" ". - " alt=\"$strmovehere\" border=\"0\">"; - } - $instancename = urldecode($modinfo[$modnumber]->name); - if (!empty($CFG->filterall)) { - $instancename = filter_text("$instancename", $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[] = "\"$mod-modfullname\">"; - $moddata[] = "modfullname\" $linkcss $extra". - "href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename". - "$editbuttons"; - } - } - } - } - if ($ismoving) { - $modicon[] = ""; - $moddata[] = "wwwroot/course/mod.php?movetosection=$section->id\">". - "pixpath/movehere.gif\" ". - " alt=\"$strmovehere\" border=\"0\">"; - } - if ($isediting) { - $editmenu = popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section->section&add=", - $modnames, "section0", "", get_string("add")."...", "mods", get_string("activities"), true); - $editmenu = "
$editmenu
"; - } 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 "\n"; + echo '
'; if (!empty($section->sequence)) { $sectionmods = explode(",", $section->sequence); @@ -1016,199 +903,9 @@ function print_heading_block($heading, $width="100%", $class="headingblock") { echo "
"; } -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 "
$footer
"; - } - } else { - echo ""; - if ($list) { - foreach ($list as $key => $string) { - echo "cellcontent2\">"; - if ($icons) { - echo ""; - } - echo ""; - echo ""; - } - } - if ($footer) { - echo "cellcontent2\">"; - echo ""; - } - echo "
".$icons[$key]."$string
'; - echo "
$footer
"; - echo "
"; - } - - 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 ""; - if ($heading) { - echo ""; - echo ""; - echo ""; - } - echo ""; - echo ""; - echo "
cellheading\">$heading
cellcontent2\">"; -} - -function print_side_block_end() { - echo "

"; -} - - -function print_admin_links ($siteid, $width=180) { - global $CFG, $THEME; - - if (isadmin()) { - $moddata[]="wwwroot/$CFG->admin/configure.php\">".get_string("configuration")."..."; - $modicon[]="pixpath/i/admin.gif\" height=16 width=16 alt=\"\" />"; - - $moddata[]="wwwroot/$CFG->admin/users.php\">".get_string("users")."..."; - $modicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\" />"; - } - - if (iscreator()) { - $moddata[]="wwwroot/course/index.php?edit=on\">".get_string("courses").""; - $modicon[]="pixpath/i/course.gif\" height=16 width=16 alt=\"\" />"; - $fulladmin = ""; - } - - if (isadmin()) { - $moddata[]="wwwroot/course/log.php?id=$siteid\">".get_string("logs").""; - $modicon[]="pixpath/i/log.gif\" height=16 width=16 alt=\"\" />"; - - $moddata[]="wwwroot/files/index.php?id=$siteid\">".get_string("sitefiles").""; - $modicon[]="pixpath/i/files.gif\" height=16 width=16 alt=\"\" />"; - - if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) { - $moddata[]="wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">". - get_string("managedatabase").""; - $modicon[]="pixpath/i/db.gif\" height=16 width=16 alt=\"\" />"; - } - $fulladmin = "

wwwroot/$CFG->admin/\">".get_string("admin")."..."; - } - - print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width); - - echo "wwwroot/pix/spacer.gif\" width=\"$width\" height=1>
"; -} - -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[]="pixpath/i/edit.gif\" height=16 width=16 alt=\"\">"; - if (isediting($course->id)) { - $admindata[]="id&edit=off\">".get_string("turneditingoff").""; - } else { - $admindata[]="id&edit=on\">".get_string("turneditingon").""; - } - $admindata[]="id\">".get_string("settings")."..."; - $adminicon[]="pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; - - if (iscreator() or !empty($CFG->teacherassignteachers)) { - if (!$course->teachers) { - $course->teachers = get_string("defaultcourseteachers"); - } - $admindata[]="id\">$course->teachers..."; - $adminicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; - } - - if (!$course->students) { - $course->students = get_string("defaultcoursestudents"); - } - $admindata[]="id\">$course->students..."; - $adminicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; - - $admindata[]="wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."..."; - $adminicon[]="pixpath/i/backup.gif\" height=16 width=16 alt=\"\">"; - - $admindata[]="wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."..."; - $adminicon[]="pixpath/i/restore.gif\" height=16 width=16 alt=\"\">"; - $admindata[]="id\">".get_string("scales")."..."; - $adminicon[]="pixpath/i/scales.gif\" height=16 width=16 alt=\"\">"; - } - - $admindata[]="id\">".get_string("grades")."..."; - $adminicon[]="pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; - - $admindata[]="id\">".get_string("logs")."..."; - $adminicon[]="pixpath/i/log.gif\" height=16 width=16 alt=\"\">"; - - if ($isteacheredit) { - $admindata[]="wwwroot/files/index.php?id=$course->id\">".get_string("files")."..."; - $adminicon[]="pixpath/i/files.gif\" height=16 width=16 alt=\"\">"; - } - - $admindata[]="wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."..."; - $adminicon[]="modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">"; - - if ($teacherforum = forum_get_course_forum($course->id, "teacher")) { - $admindata[]="wwwroot/mod/forum/view.php?f=$teacherforum->id\">".get_string("nameteacher","forum").""; - $adminicon[]="modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">"; - } - - } else if (!isguest()) { // Students menu - if ($course->showgrades) { - $admindata[]="id\">".get_string("grades")."..."; - $adminicon[]="pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; - } - if ($course->showreports) { - $admindata[]="id&user=$USER->id\">".get_string("activityreport")."..."; - $adminicon[]="pixpath/i/report.gif\" height=16 width=16 alt=\"\">"; - } - if (is_internal_auth()) { - $admindata[]="wwwroot/login/change_password.php?id=$course->id\">". - get_string("changepassword")."..."; - $adminicon[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; - } else if ($CFG->changepassword) { - $admindata[]="changepassword\">".get_string("changepassword")."..."; - $adminicon[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; - } - if ($CFG->allowunenroll) { - $admindata[]="id\">".get_string("unenrolme", "", $course->shortname)."..."; - $adminicon[]="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 ""; } - + echo "$catimage"; echo ""; echo "wwwroot/course/category.php?id=$category->id\">$category->name"; @@ -1343,8 +1040,8 @@ function print_category_info($category, $depth) { echo "\"\"pixpath/spacer.gif\">"; } if ($course->summary) { - link_to_popup_window ("/course/info.php?id=$course->id", "courseinfo", - "\"$strsummary\"pixpath/i/info.gif\">", + link_to_popup_window ("/course/info.php?id=$course->id", "courseinfo", + "\"$strsummary\"pixpath/i/info.gif\">", 400, 500, $strsummary); } else { echo "\"\"pixpath/spacer.gif\">"; @@ -1360,7 +1057,7 @@ function print_category_info($category, $depth) { print_spacer(10, $indent); echo ""; } - + echo ""; echo "wwwroot/course/category.php?id=$category->id\">$category->name"; echo ""; @@ -1369,68 +1066,7 @@ function print_category_info($category, $depth) { echo "\n\n"; } -function print_courses_sideblock($category=0, $width="100%") { - global $CFG, $THEME, $USER; - if (empty($THEME->custompix)) { - $icon = "wwwroot/pix/i/course.gif\"". - " height=\"16\" width=\"16\" alt=\"".get_string("course")."\">"; - } else { - $icon = "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[]="shortname\" ". - "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname"; - $modicon[]=$icon; - } - $fulllist = "

wwwroot/course/index.php\">".get_string("fulllistofcourses")."...

"; - 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[]="wwwroot/course/category.php?id=$category->id\">$category->name"; - $modicon[]=$icon; - } - $fulllist = "

wwwroot/course/\">".get_string("searchcourses")."...

"; - $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[]="shortname\" ". - "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname"; - $modicon[]=$icon; - } - $fulllist = "

wwwroot/course/index.php\">".get_string("fulllistofcourses")."...

"; - } 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 ""; echo ""; echo "
"; - echo "

wwwroot/course/view.php?id=$course->id\">$course->fullname

"; if ($teachers = get_course_teachers($course->id)) { echo "

\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"); diff --git a/index.php b/index.php index 7612c5c66c..8f6311637a 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,10 @@ 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 = "

admin/site.php\">"; + $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; + } ?> - id); - - if ($site->newsitems > 0 or $sections[0]->sequence or isediting($site->id) or isadmin()) { - - echo ""; - } - if ($lastcolumn) { - echo ""; - - if ($lastcolumn) { - echo ""; - } - ?> + '; + print_course_blocks($site, $leftblocks, BLOCK_LEFT); + echo ''; + } + + echo ''; + if(block_have_active($rightblocks) || $editing || isadmin()) { + echo ''; + } +?>
"; - $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 "
".update_course_icon($site->id)."
"; - echo "
"; - } - - 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 ""; - forum_print_latest_discussions($news->id, $site->newsitems, "minimal", "", false); - echo ""; - print_side_block_end(); - } - } - break; - } - print_spacer(1,$side); - } - - if (iscreator()) { - if (!$firstcolumn) { - echo "
"; - $firstcolumn=true; - } - print_admin_links($site->id, $side); - } - - if ($firstcolumn) { - echo ""; - } else { - echo ""; - } - - 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 = " - -
$newsforum->name - id\">$subtext -
"; - } 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 "
"; - print_simple_box(format_text($site->summary, FORMAT_HTML).$site_summary_editbuttons, - "", "100%", $THEME->cellcontent2, 5, "siteinfo"); - print_spacer(1,$side); - echo "'; + 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 = " + +
$newsforum->name + id\">$subtext +
"; + } 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 '
'; + if (isadmin()) { + echo '
'.update_course_icon($site->id).'
'; + echo '
'; + } + print_course_blocks($site, $rightblocks, BLOCK_RIGHT); + if ($editing && !empty($missingblocks)) { + block_print_blocks_admin($site->id, $missingblocks); + } + echo '
- + diff --git a/lib/blocklib.php b/lib/blocklib.php index 6610c9c9d8..1e412fea0d 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -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.'&blockaction=add&blockid=', + + if($courseid == 1) { + $target = 'index.php'; + } + else { + $target = 'view.php'; + } + $content = popup_form($target.'?id='.$courseid.'&blockaction=add&blockid=', $menu, 'add_block', '', "$stradd...", '', '', true); $content = '
'.$content.'
'; 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)) { diff --git a/lib/weblib.php b/lib/weblib.php index 88b8fab939..9fc2b5a899 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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 "
$footer
"; + } + } else { + echo ""; + if ($list) { + foreach ($list as $key => $string) { + echo "cellcontent2\">"; + if ($icons) { + echo ""; + } + echo ""; + echo ""; + } + } + if ($footer) { + echo "cellcontent2\">"; + echo ""; + } + echo "
".$icons[$key]."$string
'; + echo "
$footer
"; + echo "
"; + } + + 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 ''; + if ($heading) { + echo ''; + } + echo '
'.$heading.'
'; +} + +function print_side_block_end() { + echo '

'; + echo "\n"; +} + + // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: ?> diff --git a/version.php b/version.php index 6952004b3e..807ddf565e 100644 --- a/version.php +++ b/version.php @@ -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 ?> -- 2.39.5