Commit 89adb174 authored by defacer's avatar defacer
Browse files

Merging the changes from 1.4 dev branch (site index blocks + various bugfixes)

parent 87722d4f
......@@ -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;
}
}
......
......@@ -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() {
......
......@@ -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
......
......@@ -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();
......
......@@ -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;
}
......
......@@ -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());
}
}
......
......@@ -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 = '';
......
......@@ -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;}
......
......@@ -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;
}
......
......@@ -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;
......
<?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;
}
}
?>
......@@ -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)
......@@ -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);
}
......
......@@ -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));
......
......@@ -52,6 +52,9 @@
optional_variable($_GET['cal_y']);
switch(