From: stronk7 Date: Sun, 18 Apr 2004 23:20:53 +0000 (+0000) Subject: First Official realease of the "Blocks System". X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0f3fe4b6ad1570940839b181261aee2003254d6a;p=moodle.git First Official realease of the "Blocks System". Integrated with Moodle: - Install automatically. - Update course->blockinfo for each course at installation time. - Modified course creation to insert into blockinfo field. - Modified restore to insert into blockinfo field. - Admin options (hide, show, delete, config) from admin page. - Lang strings inserted (en only). - Database support to mysql and postgresql (not tested!!). Moodle, backup and block versions updated to 2004041800. Tested with mysql: Install fresh and upgrade from previous. section_activities block renamed to social_activities and created its own lang file to support name "Social Activities". This can be changed at any time. TODO: ===== Support it really in backup/restore. ???? Enjoy!! Ciao :-) --- diff --git a/admin/block.php b/admin/block.php new file mode 100644 index 0000000000..a3387c39c9 --- /dev/null +++ b/admin/block.php @@ -0,0 +1,60 @@ +libdir.'/blocklib.php'); + + require_login(); + + if (!isadmin()) { + error('Only an admin can use this page'); + } + if (!$site = get_site()) { + error("Site isn't defined!"); + } + + require_variable($_REQUEST['block']); + $blockid = intval($_REQUEST['block']); + + if(($blockrecord = get_record('blocks', 'id', $blockid)) === false) { + error('This block does not exist'); + } + + $block = block_instance($blockrecord->name, NULL); + if($block === false) { + error('Problem in instantiating block object'); + } + +/// If data submitted, then process and store. + + if ($config = data_submitted()) { + unset($config['block']); // This will always be set if we have reached this point + $block->handle_config($config); + print_header(); + redirect("$CFG->wwwroot/$CFG->admin/blocks.php", get_string("changessaved"), 1); + exit; + } + +/// Otherwise print the form. + + $stradmin = get_string('administration'); + $strconfiguration = get_string('configuration'); + $strmanageblocks = get_string('manageblocks'); + $strblockname = $block->get_title(); + + print_header($site->shortname.': '.$strblockname.": $strconfiguration", $site->fullname, + "$stradmin -> ". + "$strconfiguration -> ". + "$strmanageblocks -> ".$strblockname); + + print_heading($strblockname); + + print_simple_box('
'.get_string('configwarning').'
', 'center', '50%'); + echo '
'; + + $block->print_config(); + + print_footer(); + +?> diff --git a/admin/blocks.php b/admin/blocks.php new file mode 100644 index 0000000000..aedf3dc28f --- /dev/null +++ b/admin/blocks.php @@ -0,0 +1,181 @@ +libdir.'/blocklib.php'); + + optional_variable($_GET['hide']); + optional_variable($_GET['show']); + optional_variable($_GET['delete']); + optional_variable($_GET['confirm'], 0); + $delete = $_GET['delete']; // Dependency remover + + require_login(); + + if (!isadmin()) { + error("Only administrators can use this page!"); + } + + if (!$site = get_site()) { + error("Site isn't defined!"); + } + + +/// Print headings + + $stradministration = get_string('administration'); + $strconfiguration = get_string('configuration'); + $strmanageblocks = get_string('manageblocks'); + $strdelete = get_string('delete'); + $strversion = get_string('version'); + $strhide = get_string('hide'); + $strshow = get_string('show'); + $strsettings = get_string('settings'); + $strcourses = get_string('courses'); + $strname = get_string('name'); + + print_header("$site->shortname: $strmanageblocks", "$site->fullname", + "$stradministration -> ". + "$strconfiguration -> $strmanageblocks"); + + print_heading($strmanageblocks); + + +/// If data submitted, then process and store. + + if (!empty($_GET['hide'])) { + if (!$block = get_record('blocks', 'id', $_GET['hide'])) { + error("Block doesn't exist!"); + } + set_field('blocks', 'visible', '0', 'id', $block->id); // Hide block + + // [pj] There is no need to do this, since print_course_blocks() + // will not display blocks which are disabled. In fact, the + // comment "This block is hidden. Don't show it." there + // suggests that this db update SHOULDN'T be needed. + ///I'M NOT SURE IF THIS IS THE CORRECT APPROACH + //blocks_update_every_block_by_id($block->id, "hide"); // Hide blocks in all courses by id + } + + if (!empty($_GET['show'])) { + if (!$block = get_record('blocks', 'id', $_GET['show'])) { + error("Block doesn't exist!"); + } + set_field('blocks', 'visible', '1', 'id', $block->id); // Show block + // [pj] See note above + ///I'M NOT SURE IF THIS IS THE CORRECT APPROACH + //blocks_update_every_block_by_id($block->id,"show"); // Show blocks in all courses by id + } + + if (!empty($delete)) { + + if (!$block = get_record('blocks', 'id', $delete)) { + error("Block doesn't exist!"); + } + + $strblockname = get_string('modulename', 'block_'.$block->name); + + if (!$_GET['confirm']) { + notice_yesno(get_string('blockdeleteconfirm', '', $strblockname), + 'blocks.php?delete='.$block->id.'&confirm=1', + 'blocks.php'); + print_footer(); + exit; + + } else { + // Delete block + if (!delete_records('blocks', 'id', $block->id)) { + notify("Error occurred while deleting the $strblockname record from blocks table"); + } + + blocks_update_every_block_by_id($block->id, 'delete'); // Delete blocks in all courses by id + + // Then the tables themselves + + if ($tables = $db->Metatables()) { + $prefix = $CFG->prefix.$block->name; + foreach ($tables as $table) { + if (strpos($table, $prefix) === 0) { + if (!execute_sql("DROP TABLE $table", false)) { + notify("ERROR: while trying to drop table $table"); + } + } + } + } + + $a->block = $strblockname; + $a->directory = $CFG->dirroot.'/blocks/'.$block->name; + notice(get_string('blockdeletefiles', '', $a), 'blocks.php'); + } + } + +/// Main display starts here + +/// Get and sort the existing blocks + + if (!$blocks = get_records('blocks')) { + error('No blocks found!'); // Should never happen + } + + foreach ($blocks as $block) { + if(($blockobject = block_instance($block->name, NULL)) === false) { + // Failed to load + continue; + } + $blockbyname[$blockobject->get_title()] = $block->id; + $blockobjects[$block->id] = $blockobject; + } + ksort($blockbyname); + +/// Print the table of all blocks + + if (empty($THEME->custompix)) { + $pixpath = '../pix'; + // [pj] This is not used anywhere, but I'm leaving it in for the future + //$modpixpath = '../mod'; + } else { + $pixpath = '../theme/'.$CFG->theme.'/pix'; + // [pj] This is not used anywhere, but I'm leaving it in for the future + //$modpixpath = '../theme/'.$CFG->theme.'/pix/mod'; + } + + $table->head = array ($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strdelete, $strsettings); + $table->align = array ('LEFT', 'RIGHT', 'LEFT', 'CENTER', 'CENTER', 'CENTER'); + $table->wrap = array ("NOWRAP", "", "", "", "",""); + $table->size = array ("100%", "10", "10", "10", "10","12"); + $table->width = "100"; + + foreach ($blockbyname as $blockname => $blockid) { + + // [pj] This is not used anywhere, but I'm leaving it in for the future + //$icon = "name/icon.gif\" hspace=10 height=16 width=16 border=0>"; + $blockobject = $blockobjects[$blockid]; + + $delete = ''.$strdelete.''; + + $settings = ''; // By default, no configuration + if($blockobject->has_config()) { + $settings = ''.$strsettings.''; + } + + $count = blocks_get_courses_using_block_by_id($blockid); + $class = ''; // Nothing fancy, by default + + if ($block->visible) { + $visible = ''. + ''; + } else { + $visible = ''. + ''; + $class = ' class="dimmed_text"'; // Leading space required! + } + + $table->data[] = array (''.$blockobject->get_title().'

', $count, $blockobject->get_version(), $visible, $delete, $settings); + } + echo '

'; + print_table($table); + echo '

'; + print_footer(); + +?> diff --git a/admin/index.php b/admin/index.php index 2d6e13ce21..1f939ab965 100644 --- a/admin/index.php +++ b/admin/index.php @@ -194,11 +194,16 @@ /// Upgrade backup/restore system if necessary - require_once("$CFG->dirroot/backup/lib.php"); upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards - +/// Upgrade blocks system if necessary + require_once("$CFG->dirroot/lib/blocklib.php"); + upgrade_blocks_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + +/// Check all blocks and load (or upgrade them if necessary) + upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards + /// Find and check all modules and load them up or upgrade them if necessary if (!$mods = get_list_of_plugins("mod") ) { @@ -374,6 +379,8 @@ get_string("adminhelplanguage")."
"; $configdata .= " ".get_string("managemodules")." - ". get_string("adminhelpmanagemodules")."
"; + $configdata .= " ".get_string("manageblocks")." - ". + get_string("adminhelpmanageblocks")."
"; $configdata .= " ".get_string("managefilters")." - ". get_string("adminhelpmanagefilters")."
"; if (!isset($CFG->disablescheduledbackups)) { diff --git a/backup/backup.php b/backup/backup.php index 0869a69e4a..338f128641 100644 --- a/backup/backup.php +++ b/backup/backup.php @@ -6,6 +6,7 @@ require_once ("../config.php"); require_once ("lib.php"); require_once ("backuplib.php"); + require_once ("$CFG->libdir/blocklib.php"); optional_variable($id); // course id optional_variable($cancel); diff --git a/backup/lib.php b/backup/lib.php index 8a8fdb173f..ebddb96b0f 100644 --- a/backup/lib.php +++ b/backup/lib.php @@ -339,7 +339,7 @@ $db->debug = false; if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) { notify(get_string("databasesuccess"), "green"); - notify(get_string("databaseupgradebackups", "", $backup_release)); + notify(get_string("databaseupgradebackups", "", $backup_version)); print_continue($continueto); exit; } else { @@ -362,7 +362,7 @@ $db->debug=false; if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) { notify(get_string("databasesuccess"), "green"); - notify(get_string("databaseupgradebackups", "", $backup_release)); + notify(get_string("databaseupgradebackups", "", $backup_version)); print_continue($continueto); exit; } else { diff --git a/backup/restore.php b/backup/restore.php index fe4a33edaa..12753fc810 100644 --- a/backup/restore.php +++ b/backup/restore.php @@ -9,6 +9,7 @@ require_once ("../course/lib.php"); require_once ("lib.php"); require_once ("restorelib.php"); + require_once("$CFG->libdir/blocklib.php"); //Optional optional_variable($id); diff --git a/backup/restorelib.php b/backup/restorelib.php index af2f42b22e..787d0eccad 100644 --- a/backup/restorelib.php +++ b/backup/restorelib.php @@ -363,6 +363,7 @@ $course->summary = addslashes($course_header->course_summary); $course->format = addslashes($course_header->course_format); $course->showgrades = addslashes($course_header->course_showgrades); + $course->blockinfo = addslashes($course_header->blockinfo); $course->newsitems = addslashes($course_header->course_newsitems); $course->teacher = addslashes($course_header->course_teacher); $course->teachers = addslashes($course_header->course_teachers); @@ -381,6 +382,18 @@ $course->visible = addslashes($course_header->course_visible); $course->timecreated = addslashes($course_header->course_timecreated); $course->timemodified = addslashes($course_header->course_timemodified); + //Adjust blockinfo field. + //NOTE: For now, it's imposible to find it in backup files because it isn't saved, + // so, we always rebuid it with defaults. + if (!$course->blockinfo) { + //Create blockinfo default content + if ($course->format == "social") { + $course->blockinfo = blocks_get_default_blocks (NULL,"participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,admin,course_list"); + } else { + //For topics and weeks formats (default built in the function) + $course->blockinfo = blocks_get_default_blocks(); + } + } //Now insert the record $newid = insert_record("course",$course); if ($newid) { diff --git a/backup/version.php b/backup/version.php index 5de75d2c0c..b32bfb1229 100644 --- a/backup/version.php +++ b/backup/version.php @@ -5,6 +5,6 @@ // database (backup_version) to determine whether upgrades should // be performed (see db/backup_*.php) -$backup_version = 2004041000; // The current version is a date (YYYYMMDDXX) +$backup_version = 2004041800; // The current version is a date (YYYYMMDDXX) $backup_release = "1.3 development"; // User-friendly version number diff --git a/blocks/README.txt b/blocks/README.txt new file mode 100644 index 0000000000..4c6153233f --- /dev/null +++ b/blocks/README.txt @@ -0,0 +1,42 @@ +CREATING NEW BLOCKS +------------------------------------------------------------------------------- + +You have to derive a class that extends MoodleBlock. + +The derived class MUST: + + * Implement a constructor that: + 1. Sets $this->content_type (BLOCK_TYPE_LIST or BLOCK_TYPE_TEXT) + 2. Sets $this->header (BLOCK_SHOW_HEADER or BLOCK_HIDE_HEADER) + 3. Sets $this->title + 4. Sets $this->version + 5. Sets $this->course equal to its only argument + +The derived class MAY: + + * Declare that the block has a configuration interface. + To do so: + + 1. Define a method has_config() {return true;} + 2. Define a method print_config() that prints whatever + configuration interface you want to have. + 3. Define a method handle_config($data) that does what + is needed. $data comes straight from data_submitted(). + + * Limit the course formats it can be displayed in. + To do so: + + 1. Define a method applicable_formats() which returns a + bitwise AND of one or more COURSE_FORMAT_XXX defined + constants. + + * Select a "preferred" width which the course format will try to honor. + To do so: + + 1. Define a method preferred_width() which returns a number + measured in pixels. + + * Declare that the block is going to hide its header. + To do so: + + 1. Define a method hide_header() {return true;} diff --git a/blocks/activity_modules/block_activity_modules.php b/blocks/activity_modules/block_activity_modules.php new file mode 100644 index 0000000000..15add1b56f --- /dev/null +++ b/blocks/activity_modules/block_activity_modules.php @@ -0,0 +1,39 @@ +title = get_string('activities'); + $this->content_type = BLOCK_TYPE_LIST; + $this->course = $course; + $this->version = 2004041000; + } + + function get_content() { + global $USER, $CFG; + + // This is really NOT pretty, but let's do it simple for now... + global $modnamesused, $modnamesplural; + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->items = array(); + $this->content->icons = array(); + $this->content->footer = ''; + + if ($modnamesused) { + foreach ($modnamesused as $modname => $modfullname) { + if ($modname != 'label') { + $this->content->items[] = ''.$modnamesplural[$modname].''; + $this->content->icons[] = ''; + } + } + } + + return $this->content; + } +} + +?> diff --git a/blocks/activity_modules/db/mysql.php b/blocks/activity_modules/db/mysql.php new file mode 100644 index 0000000000..1556053c44 --- /dev/null +++ b/blocks/activity_modules/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('administration'); + $this->content_type = BLOCK_TYPE_LIST; + $this->course = $course; + $this->version = 2004041000; + } + function get_content() { + global $USER, $CFG, $THEME; + + require_once($CFG->dirroot.'/mod/forum/lib.php'); + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->items = array(); + $this->content->icons = array(); + $this->content->footer = ''; + + if (isguest()) { + return $this->content; + } + + if (isteacher($this->course->id)) { + + $isteacheredit = isteacheredit($this->course->id); + + if ($isteacheredit) { + $this->content->icons[]=''; + if (isediting($this->course->id)) { + $this->content->items[]=''.get_string('turneditingoff').''; + } else { + $this->content->items[]=''.get_string('turneditingon').''; + } + $this->content->items[]=''.get_string('settings').'...'; + $this->content->icons[]=''; + + if (iscreator() or !empty($CFG->teacherassignteachers)) { + if (!$this->course->teachers) { + $this->course->teachers = get_string('defaultcourseteachers'); + } + $this->content->items[]=''.$this->course->teachers.'...'; + $this->content->icons[]=''; + } + + if (!$this->course->students) { + $this->course->students = get_string('defaultcoursestudents'); + } + $this->content->items[]=''.$this->course->students.'...'; + $this->content->icons[]=''; + + $this->content->items[]=''.get_string('backup').'...'; + $this->content->icons[]=''; + + $this->content->items[]=''.get_string('restore').'...'; + $this->content->icons[]=''; + $this->content->items[]=''.get_string('scales').'...'; + $this->content->icons[]=''; + } + + $this->content->items[]=''.get_string('grades').'...'; + $this->content->icons[]=''; + + $this->content->items[]=''.get_string('logs').'...'; + $this->content->icons[]=''; + + if ($isteacheredit) { + $this->content->items[]=''.get_string('files').'...'; + $this->content->icons[]=''; + } + + $this->content->items[]=''.get_string('help').'...'; + $this->content->icons[]=''; + + if ($teacherforum = forum_get_course_forum($this->course->id, 'teacher')) { + $this->content->items[]=''.get_string('nameteacher', 'forum').''; + $this->content->icons[]=''; + } + + } else if (!isguest()) { // Students menu + if ($this->course->showgrades) { + $this->content->items[]=''.get_string('grades').'...'; + $this->content->icons[]=''; + } + if ($this->course->showreports) { + $this->content->items[]=''.get_string('activityreport').'...'; + $this->content->icons[]=''; + } + if (is_internal_auth()) { + $this->content->items[]=''.get_string('changepassword').'...'; + $this->content->icons[]=''; + } else if ($CFG->changepassword) { + $this->content->items[]=''.get_string('changepassword').'...'; + $this->content->icons[]=''; + } + if ($CFG->allowunenroll) { + $this->content->items[]=''.get_string('unenrolme', '', $this->course->shortname).'...'; + $this->content->icons[]=''; + } + } + + return $this->content; + } +} + +/* +function block_admin(&$course) { + + global $USER, $CFG, $THEME; + + $block = New object; + + $block->title = get_string('administration'); + $block->type = BLOCK_TYPE_LIST; + + if (isguest()) { + return $block; + } + + if (isteacher($course->id)) { + + $isteacheredit = isteacheredit($course->id); + + if ($isteacheredit) { + $block->icons[]="pixpath/i/edit.gif\" height=16 width=16 alt=\"\">"; + if (isediting($course->id)) { + $block->items[]="id&edit=off\">".get_string("turneditingoff").""; + } else { + $block->items[]="id&edit=on\">".get_string("turneditingon").""; + } + $block->items[]="id\">".get_string("settings")."..."; + $block->icons[]="pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; + + if (iscreator() or !empty($CFG->teacherassignteachers)) { + if (!$course->teachers) { + $course->teachers = get_string("defaultcourseteachers"); + } + $block->items[]="id\">$course->teachers..."; + $block->icons[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; + } + + if (!$course->students) { + $course->students = get_string("defaultcoursestudents"); + } + $block->items[]="id\">$course->students..."; + $block->icons[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; + + $block->items[]="wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."..."; + $block->icons[]="pixpath/i/backup.gif\" height=16 width=16 alt=\"\">"; + + $block->items[]="wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."..."; + $block->icons[]="pixpath/i/restore.gif\" height=16 width=16 alt=\"\">"; + $block->items[]="id\">".get_string("scales")."..."; + $block->icons[]="pixpath/i/scales.gif\" height=16 width=16 alt=\"\">"; + } + + $block->items[]="id\">".get_string("grades")."..."; + $block->icons[]="pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; + + $block->items[]="id\">".get_string("logs")."..."; + $block->icons[]="pixpath/i/log.gif\" height=16 width=16 alt=\"\">"; + + if ($isteacheredit) { + $block->items[]="wwwroot/files/index.php?id=$course->id\">".get_string("files")."..."; + $block->icons[]="pixpath/i/files.gif\" height=16 width=16 alt=\"\">"; + } + + $block->items[]="wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."..."; + $block->icons[]="modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">"; + + if ($teacherforum = forum_get_course_forum($course->id, "teacher")) { + $block->items[]="wwwroot/mod/forum/view.php?f=$teacherforum->id\">$teacherforum->name"; + $block->icons[]="modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">"; + } + + } else if (!isguest()) { // Students menu + if ($course->showgrades) { + $block->items[]="id\">".get_string("grades")."..."; + $block->icons[]="pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; + } + if ($course->showreports) { + $block->items[]="id&user=$USER->id\">".get_string("activityreport")."..."; + $block->icons[]="pixpath/i/report.gif\" height=16 width=16 alt=\"\">"; + } + if (is_internal_auth()) { + $block->items[]="wwwroot/login/change_password.php?id=$course->id\">". + get_string("changepassword")."..."; + $block->icons[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; + } else if ($CFG->changepassword) { + $block->items[]="changepassword\">".get_string("changepassword")."..."; + $block->icons[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; + } + if ($CFG->allowunenroll) { + $block->items[]="id\">".get_string("unenrolme", "", $course->shortname)."..."; + $block->icons[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; + } + } + + return $block; +} +*/ +?> diff --git a/blocks/admin/db/mysql.php b/blocks/admin/db/mysql.php new file mode 100644 index 0000000000..30a5d48d45 --- /dev/null +++ b/blocks/admin/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('calendar', 'calendar'); + $this->content_type = BLOCK_TYPE_TEXT; + $this->course = $course; + $this->version = 2004041000; + } + + function get_content() { + global $USER, $CFG, $SESSION; + optional_variable($_GET['cal_m']); + optional_variable($_GET['cal_y']); + + require_once($CFG->dirroot.'/calendar/lib.php'); + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->text = ''; + $this->content->footer = ''; + + calendar_session_vars(); + + if($this->course === NULL) { + // Overrides: use no course at all + $courseshown = false; + $defaultcourses = NULL; + } + else { + $courseshown = $this->course->id; + $defaultcourses = array($courseshown => 1); + } + + // We 'll need this later + calendar_set_referring_course($courseshown); + + if($courseshown !== false && is_int($SESSION->cal_show_course) && $SESSION->cal_show_course != $courseshown) { + // There is a filter in action that shows events from a course other than the current + // Obviously we have to cut it out + $SESSION->cal_show_course = true; + } + else if($courseshown !== false && is_array($SESSION->cal_show_course) && !in_array($courseshown, $SESSION->cal_show_course)) { + // Same as above, only there are many courses being shown. Unfortunately, not this one. + $SESSION->cal_show_course = true; + } + + // Be VERY careful with the format for default courses arguments! + // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions. + + calendar_set_filters($courses, $group, $user, $defaultcourses, $defaultcourses); + + if($courseshown == 1) { + // For the front page + $this->content->text .= calendar_overlib_html(); + $this->content->text .= calendar_top_controls('frontpage', array('m' => $_GET['cal_m'], 'y' => $_GET['cal_y'])); + $this->content->text.= calendar_get_mini($courses, $group, $user, $_GET['cal_m'], $_GET['cal_y']); + // No filters for now + } + else { + // For any other course + $this->content->text .= calendar_overlib_html(); + $this->content->text .= calendar_top_controls('course', array('id' => $courseshown, 'm' => $_GET['cal_m'], 'y' => $_GET['cal_y'])); + $this->content->text .= calendar_get_mini($courses, $group, $user, $_GET['cal_m'], $_GET['cal_y']); + $this->content->text .= calendar_filter_controls('course'); + } + + return $this->content; + } +} + +?> diff --git a/blocks/calendar_month/db/mysql.php b/blocks/calendar_month/db/mysql.php new file mode 100644 index 0000000000..b467db451c --- /dev/null +++ b/blocks/calendar_month/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('upcomingevents', 'calendar'); + $this->content_type = BLOCK_TYPE_TEXT; + $this->course = $course; + $this->version = 2004041000; + } + + function get_content() { + global $USER, $CFG, $SESSION; + optional_variable($_GET['cal_m']); + optional_variable($_GET['cal_y']); + + require_once($CFG->dirroot.'/calendar/lib.php'); + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->text = ''; + $this->content->footer = ''; + + if($this->course === NULL) { + // Overrides: use no course at all + $courseshown = false; + $defaultcourses = NULL; + } + else { + $courseshown = $this->course->id; + $defaultcourses = array($courseshown => 1); + } + + // We 'll need this later + calendar_set_referring_course($courseshown); + + if($courseshown !== false && is_int($SESSION->cal_show_course) && $SESSION->cal_show_course != $courseshown) { + // There is a filter in action that shows events from a course other than the current + // Obviously we have to cut it out + $SESSION->cal_show_course = true; + } + else if($courseshown !== false && is_array($SESSION->cal_show_course) && !in_array($courseshown, $SESSION->cal_show_course)) { + // Same as above, only there are many courses being shown. Unfortunately, not this one. + $SESSION->cal_show_course = true; + } + + // Be VERY careful with the format for default courses arguments! + // Correct formatting is [courseid] => 1 to be concise with moodlelib.php functions. + + calendar_set_filters($courses, $group, $user, $defaultcourses, $defaultcourses); + + $this->content->text = calendar_get_sideblock_upcoming($courses, $group, $user, get_user_preferences('calendar_lookahead', CALENDAR_UPCOMING_DAYS), get_user_preferences('calendar_maxevents', CALENDAR_UPCOMING_MAXEVENTS)); + + if(empty($this->content->text)) { + $this->content->text = '
'.get_string('noupcomingevents', 'calendar').'
'; + } + + return $this->content; + } +} + +?> diff --git a/blocks/calendar_upcoming/db/mysql.php b/blocks/calendar_upcoming/db/mysql.php new file mode 100644 index 0000000000..32653d49c3 --- /dev/null +++ b/blocks/calendar_upcoming/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('mycourses'); + $this->content_type = BLOCK_TYPE_LIST; + $this->course = $course; + $this->version = 2004041800; + } + + function get_content() { + global $THEME, $CFG, $USER; + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->items = array(); + $this->content->icons = array(); + $this->content->footer = ''; + + 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\" "; + $this->content->items[]="shortname\" ". + "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname"; + $this->content->icons[]=$icon; + } + $this->title = get_string('mycourses'); + $this->content->footer = "

wwwroot/course/index.php\">".get_string("fulllistofcourses")."..."; + return $this->content; + } + } + + $categories = get_categories("0"); // Parent = 0 ie top-level categories only + if ($categories) { //Check we have categories + if (count($categories) > 1) { // Just print top level category links + foreach ($categories as $category) { + $linkcss = $category->visible ? "" : " class=\"dimmed\" "; + $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->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\" "; + $this->content->items[]="shortname\" ". + "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")."..."; + } else { + $this->content->items = array(); + $this->content->icons = array(); + $this->content->footer = get_string('nocoursesyet'); + } + $this->title = get_string('courses'); + } + } + return $this->content; + } +} + +?> diff --git a/blocks/course_list/db/mysql.php b/blocks/course_list/db/mysql.php new file mode 100644 index 0000000000..f02c929896 --- /dev/null +++ b/blocks/course_list/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('blockname','block_course_summary'); + $this->content_type = BLOCK_TYPE_TEXT; + $this->course = $course; + $this->version = 2004041400; + } + + function get_content() { + global $USER, $CFG; + + $this->content = New object; + $this->content->text = ''; + $this->content->footer = ''; + $this->content->text = format_text($this->course->summary, FORMAT_HTML); + + return $this->content; + } + + function hide_header() {return true;} +} + +?> diff --git a/blocks/course_summary/db/mysql.php b/blocks/course_summary/db/mysql.php new file mode 100644 index 0000000000..301a19aa9a --- /dev/null +++ b/blocks/course_summary/db/mysql.php @@ -0,0 +1,33 @@ +prefix}blocks` ( + `id` int(10) unsigned NOT NULL auto_increment, + `name` varchar(40) NOT NULL default '', + `version` int(10) NOT NULL default '0', + `cron` int(10) unsigned NOT NULL default '0', + `lastcron` int(10) unsigned NOT NULL default '0', + `visible` tinyint(1) NOT NULL default '1', + PRIMARY KEY (`id`) + ) + COMMENT = 'To register and update all the available blocks'"); + } + + //Finally, return result + return $result; +} +?> diff --git a/blocks/db/mysql.sql b/blocks/db/mysql.sql new file mode 100644 index 0000000000..36f2bde8c1 --- /dev/null +++ b/blocks/db/mysql.sql @@ -0,0 +1,15 @@ +# $Id$ +# +# Table structure for table `blocks` +# + +CREATE TABLE `prefix_blocks` ( + `id` int(10) unsigned NOT NULL auto_increment, + `name` varchar(40) NOT NULL default '', + `version` int(10) NOT NULL default '0', + `cron` int(10) unsigned NOT NULL default '0', + `lastcron` int(10) unsigned NOT NULL default '0', + `visible` tinyint(1) NOT NULL default '1', + PRIMARY KEY (`id`) +) TYPE=MyISAM; +# -------------------------------------------------------- diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php new file mode 100644 index 0000000000..1e36b53385 --- /dev/null +++ b/blocks/moodleblock.class.php @@ -0,0 +1,207 @@ +title; + } + function get_content_type() { + // Intentionally doesn't check if a content_type is set, for _test_self() + return $this->content_type; + } + function get_version() { + // Intentionally doesn't check if a version is set, for _test_self() + return $this->version; + } + function get_header() { + // Intentionally doesn't check if a header is set, for _test_self() + return $this->header; + } + function refresh_content() { + // Nothing special here, depends on content() + $this->content = NULL; + return $this->get_content(); + } + function print_block() { + // Wrap it up, in case we have buttons too + $title = '

'.$this->title.'
'; + if($this->edit_controls !== NULL) { + $title .= $this->edit_controls; + } + $this->get_content(); + + switch($this->content_type) { + case BLOCK_TYPE_TEXT: + if ($this->edit_controls !== NULL || !$this->hide_header()) { + print_side_block($title, $this->content->text, NULL, NULL, $this->content->footer); + } else { + print_side_block(NULL, $this->content->text, NULL, NULL, $this->content->footer); + } + break; + case BLOCK_TYPE_LIST: + if ($this->edit_controls !== NULL || !$this->hide_header()) { + print_side_block($title, '', $this->content->items, $this->content->icons, $this->content->footer); + } else { + print_side_block(NULL, '', $this->content->items, $this->content->icons, $this->content->footer); + } + break; + } + } + function print_shadow() { + $title = '
'.$this->title.'
'; + if($this->edit_controls !== NULL) { + $title .= $this->edit_controls; + } + print_side_block($title, ' ', NULL, NULL, ''); + } + function add_edit_controls($options, $blockid) { + global $CFG, $THEME; + + // The block may be disabled + $blockid = intval($blockid); + $enabled = $blockid > 0; + $blockid = abs($blockid); + + if (!isset($this->str)) { + $this->str->delete = get_string('delete'); + $this->str->moveup = get_string('moveup'); + $this->str->movedown = get_string('movedown'); + $this->str->moveright = get_string('moveright'); + $this->str->moveleft = get_string('moveleft'); + $this->str->hide = get_string('hide'); + $this->str->show = get_string('show'); + } + + $path = $CFG->wwwroot.'/course'; + + if (empty($THEME->custompix)) { + $pixpath = $path.'/../pix'; + } else { + $pixpath = $path.'/../theme/'.$CFG->theme.'/pix'; + } + + $movebuttons = '
'; + + if($enabled) { + $icon = '/t/hide.gif'; + $title = $this->str->hide; + } + else { + $icon = '/t/show.gif'; + $title = $this->str->show; + } + + $movebuttons .= '' . + ''; + + $movebuttons .= '' . + ''; + + if ($options & BLOCK_MOVE_LEFT) { + $movebuttons .= '' . + ''; + } + if ($options & BLOCK_MOVE_UP) { + $movebuttons .= '' . + ''; + } + if ($options & BLOCK_MOVE_DOWN) { + $movebuttons .= '' . + ''; + } + if ($options & BLOCK_MOVE_RIGHT) { + $movebuttons .= '' . + ''; + } + + $movebuttons .= '
'; + $this->edit_controls = $movebuttons; + } + + function _self_test() { + // Tests if this block has been implemented correctly. + // Also, $errors isn't used right now + $errors = array(); + + $correct = true; + if($this->get_title() === NULL) { + $errors[] = 'title_not_set'; + $correct = false; + } + if(!in_array($this->get_content_type(), array(BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT))) { + $errors[] = 'invalid_content_type'; + $correct = false; + } + if($this->get_content() === NULL) { + $errors[] = 'content_not_set'; + $correct = false; + } + if($this->get_version() === NULL) { + $errors[] = 'version_not_set'; + $correct = false; + } + $allformats = COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL; + if(!($this->applicable_formats() & $allformats)) { + $errors[] = 'no_course_formats'; + $correct = false; + } + $width = $this->preferred_width(); + if(!is_int($width) || $width <= 0) { + $errors[] = 'invalid_width'; + $correct = false; + } + return $correct; + } + + function has_config() { + return false; + } + function print_config() { + // This does nothing, it's here to prevent errors from + // derived classes if they implement has_config() but not print_config() + } + function handle_config() { + // This does nothing, it's here to prevent errors from + // derived classes if they implement has_config() but not handle_config() + } + function applicable_formats() { + // Default case: the block can be used in all course types + return COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS | COURSE_FORMAT_SOCIAL; + } + function preferred_width() { + // Default case: the block wants to be 180 pixels wide + return 180; + } + function hide_header() { + //Default, false--> the header is showed + return false; + } +} + +?> diff --git a/blocks/news_items/block_news_items.php b/blocks/news_items/block_news_items.php new file mode 100644 index 0000000000..42a610991a --- /dev/null +++ b/blocks/news_items/block_news_items.php @@ -0,0 +1,38 @@ +title = get_string('latestnews'); + $this->content_type = BLOCK_TYPE_TEXT; + $this->course = $course; + $this->version = 2004041200; + } + + function get_content() { + global $CFG; + + if($this->content !== NULL) { + return $this->content; + } + + require_once($CFG->dirroot.'/course/lib.php'); + + $this->content = New object; + $this->content->text = ''; + $this->content->footer = ''; + + if ($this->course->newsitems) { + $news = forum_get_course_forum($this->course->id, 'news'); + // Slightly hacky way to do it but... + ob_start(); + echo ''; + forum_print_latest_discussions($news->id, $this->course->newsitems, "minimal", "", get_current_group($this->course->id)); + echo ''; + $this->content->text = ob_get_contents(); + ob_end_clean(); + } + return $this->content; + } +} + +?> diff --git a/blocks/news_items/db/mysql.php b/blocks/news_items/db/mysql.php new file mode 100644 index 0000000000..829618f227 --- /dev/null +++ b/blocks/news_items/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('blockname','block_online_users'); + $this->content_type = BLOCK_TYPE_TEXT; + $this->course = $course; + $this->version = 2004041800; + } + + function has_config() {return true;} + + function print_config() { + global $CFG, $THEME; + print_simple_box_start('center', '', $THEME->cellheading); + include($CFG->dirroot.'/blocks/'.$this->name().'/config.html'); + print_simple_box_end(); + return true; + } + function handle_config($config) { + foreach ($config as $name => $value) { + set_config($name, $value); + } + return true; + } + + function get_content() { + global $USER, $CFG; + + $timetoshowusers = 300; //Seconds default + + if (isset($CFG->block_online_users_timetosee)) { + $timetoshowusers = $CFG->block_online_users_timetosee * 60; + } + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->text = ''; + $this->content->footer = ''; + + //Calculate if we are in separate groups + $isseparategroups = ($this->course->groupmode == SEPARATEGROUPS and $this->course->groupmodeforce and + !isteacheredit($this->course->id)); + + //Get the user current group + $currentgroup = $isseparategroups ? get_current_group($this->course->id) : NULL; + + $groupmembers = ""; + $select = ""; + + //Add this to the SQL to show only group users + if ($currentgroup !== NULL) { + $groupmembers = ", {$CFG->prefix}groups_members gm "; + $select .= " AND u.id = gm.userid AND gm.groupid = '$currentgroup'"; + } + + $timefrom = time()-$timetoshowusers; + + $students = get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.picture, s.timeaccess + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_students s + $groupmembers + WHERE u.id = s.userid and + s.course = {$this->course->id} and + s.timeaccess > $timefrom $select"); + + $teachers = get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.picture, s.timeaccess + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_teachers s + $groupmembers + WHERE u.id = s.userid and + s.course = {$this->course->id} and + s.timeaccess > $timefrom $select"); + + if ($teachers || $students) { + if ($students) { + foreach ($students as $student) { + $student->fullname = fullname($student); + $users[$student->id] = $student; + } + } + if ($teachers) { + foreach ($teachers as $teacher) { + $teacher->fullname = fullname($teacher); + $users[$teacher->id] = $teacher; + } + } + } else { + $users = null; + } + + //Calculate minutes + $minutes = floor($timetoshowusers/60); + + $this->content->text = "
(".get_string("periodnminutes","block_online_users",$minutes).")
"; + + //Now, we have in users, the list of users to show + //Because they are online + if ($users !== null) { + foreach ($users as $user) { + $this->content->text .= '
'; + $timeago = format_time(time() - $user->timeaccess); + if ($user->picture==0) { + $this->content->text .= ' '; + } else { + if ($CFG->slasharguments) { + $imgtag = ' '; + } else { + $imgtag = ' '; + } + $this->content->text .= $imgtag; + } + $this->content->text .= ''.$user->fullname.'
'; + } +/* + $table->align = array("right","left"); + $table->cellpadding = 1; + $table->cellspacing = 1; + $table->data[] = array("pixpath/i/user.gif\" height=16 width=16 alt=\"\">",$user->fullname); + } + // Slightly hacky way to do it but... + ob_start(); + print_table($table); + //$this->content->text .= "
".ob_get_contents(); + ob_end_clean(); +*/ + } else { + $this->content->text .= "

".get_string("none")."

"; + } + + return $this->content; + } +} + +?> diff --git a/blocks/online_users/config.html b/blocks/online_users/config.html new file mode 100644 index 0000000000..3ba2c952a1 --- /dev/null +++ b/blocks/online_users/config.html @@ -0,0 +1,24 @@ +
+ + + + + + + + + + +

block_online_users_timetosee:

+ + + + +
+ ">
+ +
diff --git a/blocks/online_users/db/mysql.php b/blocks/online_users/db/mysql.php new file mode 100644 index 0000000000..f8f77e3c39 --- /dev/null +++ b/blocks/online_users/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('people'); + $this->content_type = BLOCK_TYPE_LIST; + $this->course = $course; + $this->version = 2004041800; + } + + function get_content() { + global $USER, $CFG; + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->items = array(); + $this->content->icons = array(); + $this->content->footer = ''; + + $strgroups = get_string('groups'); + $strgroupmy = get_string('groupmy'); + + $this->content->items[]=''.get_string('participants').''; + $this->content->icons[]=''; + + if ($this->course->groupmode or !$this->course->groupmodeforce) { + if ($this->course->groupmode == VISIBLEGROUPS or isteacheredit($this->course->id)) { + $this->content->items[]=''.$strgroups.''; + $this->content->icons[]=''; + } else if ($this->course->groupmode == SEPARATEGROUPS and $this->course->groupmodeforce) { + // Show nothing + } else if ($currentgroup = get_current_group($this->course->id)) { + $this->content->items[]=''.$strgroupmy.''; + $this->content->icons[]=''; + } + } + + $fullname = fullname($USER, true); + $editmyprofile = ''.get_string('editmyprofile').''; + if ($USER->description) { + $this->content->items[]= $editmyprofile; + } else { + $this->content->items[]= $editmyprofile." *"; + } + $this->content->icons[]=''; + + return $this->content; + } +} + +?> diff --git a/blocks/participants/db/mysql.php b/blocks/participants/db/mysql.php new file mode 100644 index 0000000000..c955da82eb --- /dev/null +++ b/blocks/participants/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('recentactivity'); + $this->content_type = BLOCK_TYPE_TEXT; + $this->course = $course; + $this->version = 2004041000; + } + + function get_content() { + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->text = ''; + $this->content->footer = ''; + + if ($this->course->showrecent) { + // Slightly hacky way to do it but... + ob_start(); + print_recent_activity($this->course); + $this->content->text = ob_get_contents(); + ob_end_clean(); + } + + return $this->content; + } +} + +?> diff --git a/blocks/recent_activity/db/mysql.php b/blocks/recent_activity/db/mysql.php new file mode 100644 index 0000000000..3888f031e3 --- /dev/null +++ b/blocks/recent_activity/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('search', 'forum'); + $this->content_type = BLOCK_TYPE_TEXT; + $this->course = $course; + $this->version = 2004041000; + } + + function get_content() { + global $USER, $CFG, $SESSION; + optional_variable($_GET['cal_m']); + optional_variable($_GET['cal_y']); + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->text = ''; + $this->content->footer = ''; + + $form = forum_print_search_form($this->course, '', true); + $this->content->text = '
'.$form.'
'; + + return $this->content; + } +} + +?> diff --git a/blocks/search_forums/db/mysql.php b/blocks/search_forums/db/mysql.php new file mode 100644 index 0000000000..00f4d5e811 --- /dev/null +++ b/blocks/search_forums/db/mysql.php @@ -0,0 +1,33 @@ +title = get_string('blockname','block_social_activities'); + $this->content_type = BLOCK_TYPE_LIST; + $this->course = $course; + $this->version = 2004041800; + } + + function applicable_formats() { + return COURSE_FORMAT_SOCIAL; + } + + function get_content() { + global $USER, $CFG; + + if($this->content !== NULL) { + return $this->content; + } + + $this->content = New object; + $this->content->items = array(); + $this->content->icons = array(); + $this->content->footer = ''; + + // To make our day, we start with an ugly hack + global $sections, $mods, $modnames; + + $section = $sections[0]; + // That wasn't so bad, was it? + + $groupbuttons = $this->course->groupmode; + $groupbuttonslink = (!$this->course->groupmodeforce); + $isteacher = isteacher($this->course->id); + $isediting = isediting($this->course->id); + $ismoving = ismoving($this->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($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/social_activities/db/mysql.php b/blocks/social_activities/db/mysql.php new file mode 100644 index 0000000000..8932b10458 --- /dev/null +++ b/blocks/social_activities/db/mysql.php @@ -0,0 +1,33 @@ +libdir/blocklib.php"); optional_variable($id, 0); // course id optional_variable($category, 0); // category id @@ -58,6 +59,14 @@ } else { $form->timecreated = time(); + //Create blockinfo default content + if ($form->format == "social") { + $form->blockinfo = blocks_get_default_blocks (NULL,"participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,admin,course_list"); + } else { + //For topics and weeks formats (default built in the function) + $form->blockinfo = blocks_get_default_blocks(); + } + if ($newcourseid = insert_record("course", $form)) { // Set up new course $section = NULL; $section->course = $newcourseid; // Create a default section. diff --git a/course/format/social/format.php b/course/format/social/format.php index 305eeffc15..4cf2474320 100644 --- a/course/format/social/format.php +++ b/course/format/social/format.php @@ -1,99 +1,69 @@ -dirroot/mod/forum/lib.php"); require_once("$CFG->dirroot/mod/resource/lib.php"); - $leftwidth = 210; - $strgroups = get_string("groups"); - $strgroupmy = get_string("groupmy"); -?> - - - - "; - - echo " - -
- id\">".get_string("participants").""; - $modicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; - - if ($course->groupmode or !$course->groupmodeforce) { - if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) { - $moddata[]="id\">$strgroups"; - $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; - } else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) { - // Show nothing - } else if ($currentgroup) { - $moddata[]="id\">$strgroupmy"; - $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; - } - } - - $fullname = fullname($USER, true); - $editmyprofile = "id&course=$course->id\">". - get_string("editmyprofile").""; - if ($USER->description) { - $moddata[]= $editmyprofile; - } else { - $moddata[]= $editmyprofile." *"; - } - $modicon[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; - print_side_block(get_string("people"), "", $moddata, $modicon, "", $leftwidth); - - -/// Print a form to search forums - $searchform = forum_print_search_form($course, "", true); - $searchform = "
$searchform
"; - print_side_block(get_string("search","forum"), $searchform, "", "", "", $leftwidth); - -/// Print the calendar - calendar_print_side_blocks(); + // Bounds for block widths + define('BLOCK_L_MIN_WIDTH', 100); + define('BLOCK_L_MAX_WIDTH', 210); + define('BLOCK_R_MIN_WIDTH', 100); + define('BLOCK_R_MAX_WIDTH', 210); + optional_variable($preferred_width_left, 0); + optional_variable($preferred_width_right, 0); + $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH); + $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH); + $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH); + $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH); -/// Then, print all the available resources (Section 0) - print_section_block(get_string("activities"), $course, $sections[0], - $mods, $modnames, $modnamesused, true, "100%"); - - -/// Print all the recent activity - // Print all the recent activity - if ($course->showrecent) { - print_side_block_start(get_string("recentactivity"), $leftwidth, "sideblockrecentactivity"); - print_recent_activity($course); - print_side_block_end(); + $strgroups = get_string("groups"); + $strgroupmy = get_string("groupmy"); + $editing = isediting($course->id); + + echo ''; + echo ''; + + if(block_have_active($leftblocks) || $editing) { + echo ''; + } + + echo "'; + + if(block_have_active($rightblocks) || $editing) { + echo ''; + } + echo ''; + echo '
'; + print_course_blocks($course, $leftblocks, BLOCK_LEFT); + echo '"; + if ($social = forum_get_course_forum($course->id, "social")) { + if (forum_is_subscribed($USER->id, $social->id)) { + $subtext = get_string("unsubscribe", "forum"); + } else { + $subtext = get_string("subscribe", "forum"); + } + $headertext = "". + "
". + get_string("socialheadline"). + "". + "id\">$subtext
"; + print_heading_block($headertext); + echo "\"\"
"; + + forum_print_latest_discussions($social->id, 10, "plain", "", false); + + } else { + notify("Could not find or create a social forum here"); + } + echo '
'; + if ($editing && !empty($missingblocks)) { + block_print_add_block($course->id, $missingblocks); } + print_course_blocks($course, $rightblocks, BLOCK_RIGHT); + print_spacer(1, 120, true); + echo '
'; -/// Admin links and controls - print_course_admin_links($course); - -/// My courses - print_courses_sideblock(0, "$leftwidth"); - - echo "
"; - if ($social = forum_get_course_forum($course->id, "social")) { - if (forum_is_subscribed($USER->id, $social->id)) { - $subtext = get_string("unsubscribe", "forum"); - } else { - $subtext = get_string("subscribe", "forum"); - } - $headertext = "". - "
". - get_string("socialheadline"). - "". - "id\">$subtext
"; - print_heading_block($headertext); - echo "\"\"
"; - - forum_print_latest_discussions($social->id, 10, "plain", "", $currentgroup); - - } else { - notify("Could not find or create a social forum here"); - } - ?> -
- +?> diff --git a/course/format/topics/format.php b/course/format/topics/format.php index 7cfbe476f4..29b83a25e4 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -2,12 +2,25 @@ // Display the whole course as "topics" made of of modules // In fact, this is very similar to the "weeks" format, in that // each "topic" is actually a week. The main difference is that - // the dates aren't printed - it's just an aesthetic thing for + // the dates aren't printed - it's just an aesthetic thing for // courses that aren't so rigidly defined by time. // Included from "view.php" require_once("$CFG->dirroot/mod/forum/lib.php"); + // Bounds for block widths + define('BLOCK_L_MIN_WIDTH', 100); + define('BLOCK_L_MAX_WIDTH', 210); + define('BLOCK_R_MIN_WIDTH', 100); + define('BLOCK_R_MAX_WIDTH', 210); + + optional_variable($preferred_width_left, 0); + optional_variable($preferred_width_right, 0); + $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH); + $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH); + $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH); + $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH); + if (isset($topic)) { $displaysection = course_set_display($course->id, $topic); } else { @@ -25,10 +38,6 @@ } } - if ($course->newsitems) { - $news = forum_get_course_forum($course->id, "news"); - } - $streditsummary = get_string("editsummary"); $stradd = get_string("add"); $stractivities = get_string("activities"); @@ -36,7 +45,7 @@ $strtopic = get_string("topic"); $strgroups = get_string("groups"); $strgroupmy = get_string("groupmy"); - if (isediting($course->id)) { + if ($editing) { $strstudents = moodle_strtolower($course->students); $strtopichide = get_string("topichide", "", $strstudents); $strtopicshow = get_string("topicshow", "", $strstudents); @@ -50,66 +59,18 @@ /// Layout the whole page as three big columns. echo ""; -/// The left column ... + echo "\n"; - echo "'; } - print_side_block($stractivities, "", $moddata, $modicon); - -/// Print the calendar - calendar_print_side_blocks(); - -/// Print a form to search forums - $searchform = forum_print_search_form($course, "", true); - $searchform = "
$searchform
"; - print_side_block(get_string("search","forum"), $searchform); - -/// Admin links and controls - print_course_admin_links($course); - -/// My courses - print_courses_sideblock(0, "180"); /// Start main column - echo ""; echo ""; echo ""; echo ""; @@ -223,7 +184,7 @@ echo ""; - + if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students echo ""; } echo ""; - if (!empty($news)) { - print_side_block_start(get_string("latestnews"), 210, "sideblocklatestnews"); - echo ""; - forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "", $currentgroup); - echo ""; - print_side_block_end(); - } - - // Print all the recent activity - if ($course->showrecent) { - print_side_block_start(get_string("recentactivity"), 210, "sideblockrecentactivity"); - print_recent_activity($course); - print_side_block_end(); + // The right column + if(block_have_active($rightblocks) || $editing) { + echo ''; } - echo "
"; - -/// Links to people - $moddata[]="id\">".get_string("participants").""; - $modicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; - - if ($course->groupmode or !$course->groupmodeforce) { - if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) { - $moddata[]="id\">$strgroups"; - $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; - } else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) { - // Show nothing - } else if ($currentgroup) { - $moddata[]="id\">$strgroupmy"; - $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; - } - } +/// The left column ... - $fullname = fullname($USER, true); - $editmyprofile = "id&course=$course->id\">".get_string("editmyprofile").""; - if ($USER->description) { - $moddata[]= $editmyprofile; - } else { - $moddata[]= $editmyprofile." *"; - } - $modicon[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; - print_side_block(get_string("people"), "", $moddata, $modicon); - - -/// Links to all activity modules by type - $moddata = array(); - $modicon = array(); - if ($modnamesused) { - foreach ($modnamesused as $modname => $modfullname) { - if ($modname != "label") { - $moddata[] = "id\">".$modnamesplural[$modname].""; - $modicon[] = "modpixpath/$modname/icon.gif\" height=16 width=16 alt=\"\">"; - } - } + if(block_have_active($leftblocks) || $editing) { + echo ''; + print_course_blocks($course, $leftblocks, BLOCK_LEFT); + echo '"; + echo ""; print_heading_block(get_string("topicoutline"), "100%", "outlineheadingblock"); print_spacer(8, 1, true); @@ -131,7 +92,7 @@ } -/// Print Section 0 +/// Print Section 0 $section = 0; $thissection = $sections[$section]; @@ -140,7 +101,7 @@ echo "
cellheading\" class=\"topicsoutlineside\" valign=top width=20> cellcontent\" class=\"topicsoutlinecontent\" width=\"100%\">"; - + echo format_text($thissection->summary, FORMAT_HTML); if (isediting($course->id)) { @@ -148,18 +109,18 @@ " href=\"editsection.php?id=$thissection->id\">pixpath/t/edit.gif\" ". " height=11 width=11 border=0 alt=\"$streditsummary\">
"; } - + echo '
'; - + print_section($course, $thissection, $mods, $modnamesused); - + if (isediting($course->id)) { echo "
"; - popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", + popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", $modnames, "section$section", "", "$stradd...", "mods", $stractivities); echo "
"; } - + echo "
cellheading\" class=\"topicsoutlineside\" valign=top align=center width=10>"; echo " 
"; echo "

$section

"; echo "
"; echo get_string("notavailable"); @@ -240,16 +201,16 @@ } echo '
'; - + print_section($course, $thissection, $mods, $modnamesused); - + if (isediting($course->id)) { echo "
"; - popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", + popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", $modnames, "section$section", "", "$stradd..."); echo "
"; } - + echo "
"; @@ -303,35 +264,26 @@ if (!empty($sectionmenu)) { echo "
"; - echo popup_form("$CFG->wwwroot/course/view.php?id=$course->id&", $sectionmenu, + echo popup_form("$CFG->wwwroot/course/view.php?id=$course->id&", $sectionmenu, "sectionmenu", "", get_string("jumpto"), "", "", true); echo "
"; } - - if (!empty($news) or $course->showrecent) { - echo "
"; - /// Print all the news items. + echo "'; + if ($editing && !empty($missingblocks)) { + block_print_add_block($course->id, $missingblocks); } - + print_course_blocks($course, $rightblocks, BLOCK_RIGHT); print_spacer(1, 120, true); + echo '
\n"; + echo "\n"; + echo "\n"; ?> diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index 2d6dd1eda5..921b8ea84a 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -4,6 +4,18 @@ require_once("$CFG->dirroot/mod/forum/lib.php"); + // Bounds for block widths + define('BLOCK_L_MIN_WIDTH', 100); + define('BLOCK_L_MAX_WIDTH', 210); + define('BLOCK_R_MIN_WIDTH', 100); + define('BLOCK_R_MAX_WIDTH', 210); + + optional_variable($preferred_width_left, 0); + optional_variable($preferred_width_right, 0); + $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH); + $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH); + $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH); + $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH); if (isset($week)) { $displaysection = course_set_display($course->id, $week); @@ -18,7 +30,7 @@ if ($course->newsitems) { $news = forum_get_course_forum($course->id, "news"); } - + $streditsummary = get_string("editsummary"); $stradd = get_string("add"); $stractivities = get_string("activities"); @@ -26,7 +38,7 @@ $strweek = get_string("week"); $strgroups = get_string("groups"); $strgroupmy = get_string("groupmy"); - if (isediting($course->id)) { + if ($editing) { $strstudents = moodle_strtolower($course->students); $strweekhide = get_string("weekhide", "", $strstudents); $strweekshow = get_string("weekshow", "", $strstudents); @@ -38,63 +50,15 @@ /// Layout the whole page as three big columns. echo ""; -/// The left column ... + echo "\n"; - echo "'; } - $modicon[]="pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; - print_side_block(get_string("people"), "", $moddata, $modicon); - - -/// Then all the links to activities by type - $moddata = array(); - $modicon = array(); - if ($modnamesused) { - foreach ($modnamesused as $modname => $modfullname) { - if ($modname != "label") { - $moddata[] = "id\">".$modnamesplural[$modname].""; - $modicon[] = "modpixpath/$modname/icon.gif\" height=16 width=16 alt=\"\">"; - } - } - } - print_side_block($stractivities, "", $moddata, $modicon); - -/// Print the calendar - calendar_print_side_blocks(); - -/// Print a form to search forums - $searchform = forum_print_search_form($course, "", true); - $searchform = "
$searchform
"; - print_side_block(get_string("search","forum"), $searchform); - -/// Admin links and controls - print_course_admin_links($course); - -/// My courses - print_courses_sideblock(0, "180"); /// Start main column echo ""; - } + } echo ""; + + // The right column + if(block_have_active($rightblocks) || $editing) { + echo ''; } - echo "
"; - -/// Links to people - $moddata[]="id\">".get_string("participants").""; - $modicon[]="pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; - - if ($course->groupmode or !$course->groupmodeforce) { - if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) { - $moddata[]="id\">$strgroups"; - $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; - } else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) { - // Show nothing - } else if ($currentgroup) { - $moddata[]="id\">$strgroupmy"; - $modicon[]="pixpath/i/group.gif\" height=16 width=16 alt=\"\">"; - } - } +/// The left column ... - $fullname = fullname($USER, true); - $editmyprofile = "id&course=$course->id\">".get_string("editmyprofile").""; - if ($USER->description) { - $moddata[]= $editmyprofile; - } else { - $moddata[]= $editmyprofile." *"; + if(block_have_active($leftblocks) || $editing) { + echo ''; + print_course_blocks($course, $leftblocks, BLOCK_LEFT); + echo '"; @@ -136,12 +100,12 @@ } echo '
'; - + print_section($course, $thissection, $mods, $modnamesused); if (isediting($course->id)) { echo "
"; - popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", + popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", $modnames, "section$section", "", "$stradd...", "mods", $stractivities); echo "
"; } @@ -234,17 +198,17 @@ if (isediting($course->id)) { echo "
"; - popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", + popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&add=", $modnames, "section$section", "", "$stradd..."); echo "
"; } echo "
"; echo ""; - if ($displaysection == $section) { + if ($displaysection == $section) { echo "id&week=all\" title=\"$strshowallweeks\">". "pixpath/i/all.gif\" height=25 width=16 border=0>
"; } else { @@ -285,34 +249,25 @@ if (!empty($sectionmenu)) { echo "
"; - echo popup_form("$CFG->wwwroot/course/view.php?id=$course->id&", $sectionmenu, + echo popup_form("$CFG->wwwroot/course/view.php?id=$course->id&", $sectionmenu, "sectionmenu", "", get_string("jumpto"), "", "", true); echo "
"; } - - if (!empty($news) or !empty($course->showrecent)) { - echo "
"; - - // Print all the news items. - - if (!empty($news)) { - print_side_block_start(get_string("latestnews"), 210, "sideblocklatestnews"); - echo ""; - forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "", $currentgroup); - echo ""; - print_side_block_end(); - } - - // Print all the recent activity - if (!empty($course->showrecent)) { - print_side_block_start(get_string("recentactivity"), 210, "sideblockrecentactivity"); - print_recent_activity($course); - print_side_block_end(); + + + echo "'; + if ($editing && !empty($missingblocks)) { + block_print_add_block($course->id, $missingblocks); } - + print_course_blocks($course, $rightblocks, BLOCK_RIGHT); print_spacer(1, 120, true); + echo '
\n"; - + echo "\n"; + echo "\n"; ?> diff --git a/course/view.php b/course/view.php index f9d8501f8f..b17d0a3233 100644 --- a/course/view.php +++ b/course/view.php @@ -4,6 +4,7 @@ require_once("../config.php"); require_once("lib.php"); + require_once("$CFG->libdir/blocklib.php"); require_once('../calendar/lib.php'); optional_variable($id); @@ -14,11 +15,11 @@ } if (!empty($_GET['name'])) { - if (! $course = get_record("course", "shortname", $name) ) { + if (! ($course = get_record("course", "shortname", $name)) ) { error("That's an invalid short course name"); } } else { - if (! $course = get_record("course", "id", $id) ) { + if (! ($course = get_record("course", "id", $id)) ) { error("That's an invalid course id"); } } @@ -27,8 +28,58 @@ add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id"); + if (!file_exists($CFG->dirroot.'/course/format/'.$course->format.'/format.php')) { + $course->format = 'weeks'; // Default format is weeks + } + + // Can't avoid this... :( + switch($course->format) { + case 'weeks': + $courseformat = COURSE_FORMAT_WEEKS; + break; + case 'topics': + $courseformat = COURSE_FORMAT_TOPICS; + break; + case 'social': + $courseformat = COURSE_FORMAT_SOCIAL; + break; + default: + $courseformat = 0; + } + + // Doing this now so we can pass the results to block_action() + // and dodge the overhead of doing the same work twice. + + $blocks = $course->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 (!isset($USER->editing)) { + $USER->editing = false; + } + + $editing = false; + if (isteacheredit($course->id)) { - if (isset($edit)) { + if (isset($edit)) { if ($edit == "on") { $USER->editing = true; } else if ($edit == "off") { @@ -36,6 +87,8 @@ } } + $editing = $USER->editing; + if (isset($hide)) { set_section_visible($course->id, $hide, "0"); } @@ -44,6 +97,33 @@ set_section_visible($course->id, $show, "1"); } + if (isset($_GET['blockaction'])) { + if (isset($_GET['blockid'])) { + block_action($course, $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'); + 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; + } + } + } + } + + $preferred_width_left = blocks_preferred_width($leftblocks, $recblocks); + $preferred_width_right = blocks_preferred_width($rightblocks, $recblocks); + if (!empty($section)) { if (!empty($move)) { if (!move_section($course, $section, $move)) { @@ -61,13 +141,11 @@ redirect("$CFG->wwwroot/"); } - $currentgroup = get_current_group($course->id); - $strcourse = get_string("course"); $loggedinas = "

".user_login_string($course, $USER)."

"; - print_header("$strcourse: $course->fullname", "$course->fullname", "$course->shortname", + print_header("$strcourse: $course->fullname", "$course->fullname", "$course->shortname", "", "", true, update_course_icon($course->id), $loggedinas); get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); @@ -92,10 +170,6 @@ } } - if (!file_exists("$CFG->dirroot/course/format/$course->format/format.php")) { // Default format is weeks - $course->format = "weeks"; - } - require("$CFG->dirroot/course/format/$course->format/format.php"); // Include the actual course format print_footer(); diff --git a/lang/en/block_course_summary.php b/lang/en/block_course_summary.php new file mode 100644 index 0000000000..ab005424a5 --- /dev/null +++ b/lang/en/block_course_summary.php @@ -0,0 +1,4 @@ + diff --git a/lang/en/block_online_users.php b/lang/en/block_online_users.php new file mode 100644 index 0000000000..bae12c3fee --- /dev/null +++ b/lang/en/block_online_users.php @@ -0,0 +1,6 @@ + diff --git a/lang/en/block_social_activities.php b/lang/en/block_social_activities.php new file mode 100644 index 0000000000..e754986a9f --- /dev/null +++ b/lang/en/block_social_activities.php @@ -0,0 +1,4 @@ + diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 25e2ca43cb..9dea4c7a1c 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -42,6 +42,7 @@ $string['adminhelpcourses'] = 'Define courses and categories and assign people t $string['adminhelpedituser'] = 'Browse the list of user accounts and edit any of them'; $string['adminhelplanguage'] = 'For checking and editing the current language pack'; $string['adminhelplogs'] = 'Browse logs of all activity on this site'; +$string['adminhelpmanageblocks'] = 'Manage installed blocks and their settings'; $string['adminhelpmanagedatabase'] = 'Access the database directly (be careful!)'; $string['adminhelpmanagefilters'] = 'Choose text filters and related settings'; $string['adminhelpmanagemodules'] = 'Manage installed modules and their settings'; @@ -99,6 +100,8 @@ $string['backupsavetohelp'] = 'Full path to the directory where you want to save $string['backupuserfileshelp'] = 'Choose whether user files (eg profile images) should be included in automated backups'; $string['backupusershelp'] = 'Select whether you want to include all the users in the server or only the needed users for each course'; $string['backupversion'] = 'Backup Version'; +$string['blocksetup'] = 'Setting up block tables'; +$string['blocksuccess'] = '$a tables have been set up correctly'; $string['bycourseorder'] = 'By course order'; $string['cancel'] = 'Cancel'; $string['categories'] = 'Course categories'; @@ -220,6 +223,7 @@ $string['databaseperformance'] = 'Database performance'; $string['databasesetup'] = 'Setting up database'; $string['databasesuccess'] = 'Database was successfully upgraded'; $string['databaseupgradebackups'] = 'Backup version is now $a'; +$string['databaseupgradeblocks'] = 'Blocks version is now $a'; $string['databaseupgrades'] = 'Upgrading database'; $string['datemostrecentfirst'] = 'Date - most recent first'; $string['datemostrecentlast'] = 'Date - most recent last'; @@ -531,6 +535,7 @@ $string['logs'] = 'Logs'; $string['mainmenu'] = 'Main menu'; $string['makeafolder'] = 'Make a folder'; $string['makeeditable'] = 'If you make \'$a\' editable by the web server process (eg apache) then you could edit this file directly from this page'; +$string['manageblocks'] = 'Blocks'; $string['managedatabase'] = 'Database'; $string['managefilters'] = 'Filters'; $string['managemodules'] = 'Modules'; diff --git a/lib/blocklib.php b/lib/blocklib.php new file mode 100644 index 0000000000..6a24173523 --- /dev/null +++ b/lib/blocklib.php @@ -0,0 +1,784 @@ +dirroot.'/blocks/moodleblock.class.php'); + $classname = 'CourseBlock_'.$blockname; + @include_once($CFG->dirroot.'/blocks/'.$blockname.'/block_'.$blockname.'.php'); + + // After all this, return value indicating success or failure + return class_exists($classname); +} + +//This function determines if there is some active block in an array of blocks +function block_have_active($array) { + foreach($array as $blockid) { + if($blockid > 0) { + return true; + } + } + return false; +} + +//This function print the one side of blocks in course main page +function print_course_blocks(&$course, $blocksarray, $side) { + global $CFG; + + $isediting = isediting($course->id); + $ismoving = ismoving($course->id); + $isteacheredit = isteacheredit($course->id); + + if(!empty($blocksarray)) { + // Include the base class + @include_once($CFG->dirroot.'/blocks/moodleblock.class.php'); + if(!class_exists('moodleblock')) { + error('Class MoodleBlock is not defined or file not found for /course/blocks/moodleblock.class.php'); + } + + $blockdata = get_records('blocks', 'visible', 1); + if($blockdata !== false) { + + $lastblock = end($blocksarray); + $firstblock = reset($blocksarray); + + foreach($blocksarray as $blockid) { + if(!isset($blockdata[abs($blockid)])) { + // This block is hidden. Don't show it. + continue; + } + + $blockname = $blockdata[abs($blockid)]->name; + $block = block_instance($blockname, $course); + if($block === false) { + // Something went wrong + continue; + } + + // There are various sanity checks commented out below + // because the block detection code should have already done them long ago. + + /* + if(!is_subclass_of($block, 'MoodleBlock')) { + // Error: you have to derive from MoodleBlock + continue; + } + + if($content === NULL || $title === NULL) { + // Error: This shouldn't have happened + continue; + } + */ + if ($isediting && !$ismoving && $isteacheredit) { + $options = 0; + $options |= BLOCK_MOVE_UP * ($blockid != $firstblock); + $options |= BLOCK_MOVE_DOWN * ($blockid != $lastblock); + $options |= ($side == BLOCK_LEFT) ? BLOCK_MOVE_RIGHT : BLOCK_MOVE_LEFT; + $block->add_edit_controls($options, $blockid); + } + + if($blockid < 0) { + // We won't print this block... + if($isediting) { + // Unless we 're in editing mode, in which case we 'll print a 'shadow' + $block->print_shadow(); + } + continue; + } + // So simple... + $block->print_block(); + } + } + } +} + +//This iterates over an array of blocks and calculates the preferred width +function blocks_preferred_width($blockarray, $blockinfos) { + $width = 0; + + if(!is_array($blockarray) || empty($blockarray)) { + return 0; + } + foreach($blockarray as $blockid) { + if(isset($blockinfos[$blockid])) { + $blockname = $blockinfos[$blockid]->name; + $pref = block_method_result($blockname, 'preferred_width'); + if($pref === NULL) { + continue; + } + if($pref > $width) { + $width = $pref; + } + } + } + return $width; +} + + +// $course passed by reference for speed +// $leftblocks, $rightblocks passed by reference because block_action() needs to +// update the arrays so that the change can be shown immediately. + +function block_action(&$course, &$leftblocks, &$rightblocks, $blockaction, $blockid) { + + $blockid = abs(intval($blockid)); // Just to make sure + + switch($blockaction) { + case 'toggle': + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block !== false) { + if($block->side == BLOCK_LEFT) { + $leftblocks[$block->position] = -$leftblocks[$block->position]; + } + else { + $rightblocks[$block->position] = -$rightblocks[$block->position]; + } + } + break; + case 'delete': + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block !== false) { + if($block->side == BLOCK_LEFT) { + unset($leftblocks[$block->position]); + } + else { + unset($rightblocks[$block->position]); + } + } + break; + case 'add': + // Toggle to enabled, or add it if it doesn't exist at all + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block === false) { + // It doesn't exist at all, so add it + $rightblocks[] = $blockid; + } + else if($block->enabled == false) { + // Enable it + if($block->side == BLOCK_LEFT) { + $leftblocks[$block->position] = -$leftblocks[$block->position]; + } + else { + $rightblocks[$block->position] = -$rightblocks[$block->position]; + } + } + break; + case 'moveup': + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block !== false) { + if($block->side == BLOCK_LEFT) { + if(isset($leftblocks[$block->position - 1])) { + // We can move it upwards + $oldblock = $leftblocks[$block->position - 1]; + $leftblocks[$block->position - 1] = $leftblocks[$block->position]; // not $blockid, as this loses the sign + $leftblocks[$block->position] = $oldblock; + } + } + else { + if(isset($rightblocks[$block->position - 1])) { + // We can move it upwards + $oldblock = $rightblocks[$block->position - 1]; + $rightblocks[$block->position - 1] = $rightblocks[$block->position]; // not $blockid, as this loses the sign + $rightblocks[$block->position] = $oldblock; + } + } + } + break; + case 'movedown': + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block !== false) { + if($block->side == BLOCK_LEFT) { + if(isset($leftblocks[$block->position + 1])) { + // We can move it downwards + $oldblock = $leftblocks[$block->position + 1]; + $leftblocks[$block->position + 1] = $leftblocks[$block->position]; // not $blockid, as this loses the sign + $leftblocks[$block->position] = $oldblock; + } + } + else { + if(isset($rightblocks[$block->position + 1])) { + // We can move it downwards + $oldblock = $rightblocks[$block->position + 1]; + $rightblocks[$block->position + 1] = $rightblocks[$block->position]; // not $blockid, as this loses the sign + $rightblocks[$block->position] = $oldblock; + } + } + } + break; + case 'moveside': + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block !== false) { + if($block->side == BLOCK_LEFT) { + unset($leftblocks[$block->position]); + $rightblocks[] = $block->enabled ? $blockid : -$blockid; + } + else { + unset($rightblocks[$block->position]); + $leftblocks[] = $block->enabled ? $blockid : -$blockid; + } + } + break; + } + + $course->blockinfo = implode(',', $leftblocks).':'.implode(',',$rightblocks); + set_field('course', 'blockinfo', $course->blockinfo, 'id', $course->id); + +} + +// Searches for the block with ID $blockid in one or more of the two +// blocks arrays. If not found, returns boolean false. Otherwise, +// returns an object $finding where: +// $finding->side = BLOCK_LEFT or BLOCK_RIGHT +// $finding->enabled = true or false +// $finding->position = index of corresponding array where found + +function block_find($blockid, $leftblocks, $rightblocks) { + + if(($blockid = abs($blockid)) == 0) { + return false; + } + + $finding->side = BLOCK_LEFT; + $finding->enabled = true; + $finding->position = NULL; + + // First, search for the "enabled" block, since that's what we + // will be doing most of the time. + + $key = array_search($blockid, $leftblocks); + if($key !== false && $key !== NULL) { + $finding->position = $key; + return $finding; + } + $key = array_search($blockid, $rightblocks); + if($key !== false && $key !== NULL) { + $finding->position = $key; + $finding->side = BLOCK_RIGHT; + return $finding; + } + + // "enabled" block not found. Now search for the disabled block. + $finding->enabled = false; + $blockid = -$blockid; + + $key = array_search($blockid, $leftblocks); + if($key !== false && $key !== NULL) { + $finding->position = $key; + return $finding; + } + $key = array_search($blockid, $rightblocks); + if($key !== false && $key !== NULL) { + $finding->position = $key; + $finding->side = BLOCK_RIGHT; + return $finding; + } + + // Nothing found :( + + return false; +} + +//This function prints the add_block popup as necessary +function block_print_add_block($courseid, $missingblocks) { + if (isediting($courseid)) { + $title = get_string('add'); + if(!empty($missingblocks)) { + $blockdata = get_records_list('blocks', 'id', implode(',', $missingblocks)); + if($blockdata !== false) { + foreach($blockdata as $block) { + $blockobject = block_instance($block->name, NULL); + if($blockobject === false) { + continue; + } + $menu[$block->id] = $blockobject->get_title(); + } + $content = popup_form('view.php?id='.$courseid.'&blockaction=add&blockid=',$menu,'add_block','','choose','','',true); + $content = '
'.$content.'
'; + print_side_block($title, $content, NULL, NULL, NULL); + } + } + } +} + +function upgrade_blocks_db($continueto) { +/// This function upgrades the blocks tables, if necessary +/// It's called from admin/index.php + + global $CFG, $db; + + require_once ("$CFG->dirroot/blocks/version.php"); // Get code versions + + if (empty($CFG->blocks_version)) { // Blocks have never been installed. + $strdatabaseupgrades = get_string("databaseupgrades"); + print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades, + "", "", false, " ", " "); + + $db->debug=true; + if (modify_database("$CFG->dirroot/blocks/db/$CFG->dbtype.sql")) { + $db->debug = false; + if (set_config("blocks_version", $blocks_version)) { + notify(get_string("databasesuccess"), "green"); + notify(get_string("databaseupgradeblocks", "", $blocks_version)); + print_continue($continueto); + exit; + } else { + error("Upgrade of blocks system failed! (Could not update version in config table)"); + } + } else { + error("Blocks tables could NOT be set up successfully!"); + } + } + + + if ($blocks_version > $CFG->blocks_version) { // Upgrade tables + $strdatabaseupgrades = get_string("databaseupgrades"); + print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades); + + require_once ("$CFG->dirroot/blocks/db/$CFG->dbtype.php"); + + $db->debug=true; + if (blocks_upgrade($CFG->blocks_version)) { + $db->debug=false; + if (set_config("blocks_version", $blocks_version)) { + notify(get_string("databasesuccess"), "green"); + notify(get_string("databaseupgradeblocks", "", $blocks_version)); + print_continue($continueto); + exit; + } else { + error("Upgrade of blocks system failed! (Could not update version in config table)"); + } + } else { + $db->debug=false; + error("Upgrade failed! See blocks/version.php"); + } + + } else if ($blocks_version < $CFG->blocks_version) { + notify("WARNING!!! The code you are using is OLDER than the version that made these databases!"); + } +} + +//This function finds all available blocks and install them +//into blocks table or do all the upgrade process if newer +function upgrade_blocks_plugins($continueto) { + + global $CFG; + + $blocktitles = array(); + $invalidblocks = array(); + $validblocks = array(); + $notices = array(); + + //Count the number of blocks in db + $blockcount = count_records("blocks"); + //If there isn't records. This is the first install, so I remember it + if ($blockcount == 0) { + $first_install = true; + } else { + $first_install = false; + } + + $site = get_site(); + + if (!$blocks = get_list_of_plugins("blocks") ) { + error("No blocks installed!"); + } + + @include_once($CFG->dirroot."/blocks/moodleblock.class.php"); + if(!class_exists('moodleblock')) { + error('Class MoodleBlock is not defined or file not found for /blocks/moodleblock.class.php'); + } + + foreach ($blocks as $blockname) { + + if ($blockname == "NEWBLOCK" || $blockname == 'db') { // Someone has unzipped the template, ignore it + continue; + } + + $fullblock = "$CFG->dirroot/blocks/$blockname"; + + if ( is_readable($fullblock."/block_".$blockname.".php")) { + include_once($fullblock."/block_".$blockname.".php"); + } else { + $notices[] = "Block $blockname: ".$fullblock."/block_".$blockname.".php was not readable"; + continue; + } + + if ( is_readable("$fullblock/db/$CFG->dbtype.php")) { + include_once("$fullblock/db/$CFG->dbtype.php"); # defines upgrading function + } else { + $notices[] ="Block $blockname: $fullblock/db/$CFG->dbtype.php was not readable"; + continue; + } + + $classname = 'CourseBlock_'.$blockname; + if(!class_exists($classname)) { + $notices[] = "Block $blockname: $classname not implemented"; + continue; + } + + // Let's see if it supports some basic methods + $methods = get_class_methods($classname); + if(!in_array(strtolower($classname), $methods)) { + // No constructor + $notices[] = "Block $blockname: class does not have a constructor"; + $invalidblocks[] = $blockname; + continue; + } + + unset($block); + + $blockobj = New $classname($site); + + // Inherits from MoodleBlock? + if(!is_subclass_of($blockobj, "moodleblock")) { + $notices[] = "Block $blockname: class does not inherit from MoodleBlock"; + continue; + } + + // OK, it's as we all hoped. For further tests, the object will do them itself. + if(!$blockobj->_self_test()) { + $notices[] = "Block $blockname: self test failed"; + continue; + } + $block->version = $blockobj->get_version(); + + if (!isset($block->version)) { + $notices[] = "Block $blockname: hasn't version support"; + continue; + } + + $block->name = $blockname; // The name MUST match the directory + $blocktitle = $blockobj->get_title(); + + if ($currblock = get_record("blocks", "name", $block->name)) { + if ($currblock->version == $block->version) { + // do nothing + } else if ($currblock->version < $block->version) { + if (empty($updated_blocks)) { + $strblocksetup = get_string("blocksetup"); + print_header($strblocksetup, $strblocksetup, $strblocksetup, "", "", false, " ", " "); + } + print_heading("$block->name block needs upgrading"); + $upgrade_function = $block->name."_upgrade"; + if (function_exists($upgrade_function)) { + $db->debug=true; + if ($upgrade_function($currblock->version, $block)) { + $db->debug=false; + // OK so far, now update the blocks record + $block->id = $currblock->id; + if (! update_record("blocks", $block)) { + error("Could not update block $block->name record in blocks table!"); + } + notify(get_string('blocksuccess', '', $blocktitle), 'green'); + echo "
"; + } else { + $db->debug=false; + notify("Upgrading block $block->name from $currblock->version to $block->version FAILED!"); + } + } + $updated_blocks = true; + } else { + error("Version mismatch: block $block->name can't downgrade $currblock->version -> $block->version !"); + } + + } else { // block not installed yet, so install it + + // [pj] Normally this would be inline in the if, but we need to + // check for NULL (necessary for 4.0.5 <= PHP < 4.2.0) + $conflictblock = array_search($blocktitle, $blocktitles); + if($conflictblock !== false && $conflictblock !== NULL) { + + // Duplicate block titles are not allowed, they confuse people + // AND PHP's associative arrays ;) + error('Naming conflict: block '.$block->name.' has the same title with an existing block, '.$conflictblock.'!'); + } + if (empty($updated_blocks)) { + $strblocksetup = get_string("blocksetup"); + print_header($strblocksetup, $strblocksetup, $strblocksetup, "", "", false, " ", " "); + } + print_heading($block->name); + $updated_blocks = true; + $db->debug = true; + set_time_limit(0); // To allow slow databases to complete the long SQL + if (modify_database("$fullblock/db/$CFG->dbtype.sql")) { + $db->debug = false; + if ($block->id = insert_record('blocks', $block)) { + notify(get_string('blocksuccess', '', $blocktitle), 'green'); + echo "
"; + } else { + error("$block->name block could not be added to the block list!"); + } + } else { + error("Block $block->name tables could NOT be set up successfully!"); + } + } + + $blocktitles[$block->name] = $blocktitle; + } + + if(!empty($notices)) { + foreach($notices as $notice) { + notify($notice); + } + } + + //Finally, if we are in the first_install, update every course blockinfo field with + //default values. + if ($first_install) { + //Iterate over each course + if ($courses = get_records("course")) { + foreach ($courses as $course) { + //Dependig of the format, insert some values + if ($course->format == "social") { + $blockinfo = blocks_get_default_blocks ($course->id, "participants,search_forums,calendar_month,calendar_upcoming,social_activities,recent_activity,admin,course_list"); + } else { + //For topics and weeks formats (default built in the function) + $blockinfo = blocks_get_default_blocks($course->id); + } + if ($CFG->debug) { + echo 'Updating blockinfo for course: '.$course->shortname.'('.$blockinfo.')
'; + } + } + } + } + + if (!empty($updated_blocks)) { + print_continue($continueto); + die; + } +} + +//This function returns the number of courses currently using the block +function blocks_get_courses_using_block_by_id($blockid) { + + $num = 0; + + if ($courses = get_records("course")) { + foreach($courses as $course) { + $blocks = str_replace(":",",",$course->blockinfo); + $blocksarr = explode(",",$blocks); + if (block_find($blockid,$blocksarr,array())) { + $num++; + } + } + } + + return $num; +} + +//This function hides a block in all courses using it +function blocks_update_every_block_by_id($blockid,$action) { + + if ($courses = get_records("course")) { + foreach($courses as $course) { + //Calculate left and right blocks + $blocks = $course->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); + } + + switch($action) { + case 'show': + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block !== false) { + if($block->side == BLOCK_LEFT) { + $leftblocks[$block->position] = abs($leftblocks[$block->position]); + } + else { + $rightblocks[$block->position] = abs($rightblocks[$block->position]); + } + } + break; + case 'hide': + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block !== false) { + if($block->side == BLOCK_LEFT) { + $leftblocks[$block->position] = -abs($leftblocks[$block->position]); + } + else { + $rightblocks[$block->position] = -abs($rightblocks[$block->position]); + } + } + break; + case 'delete': + $block = block_find($blockid, $leftblocks, $rightblocks); + if($block !== false) { + if($block->side == BLOCK_LEFT) { + unset($leftblocks[$block->position]); + } + else { + unset($rightblocks[$block->position]); + } + } + break; + } + $course->blockinfo = implode(',', $leftblocks).':'.implode(',',$rightblocks); + set_field('course', 'blockinfo', $course->blockinfo, 'id', $course->id); + } + } +} + +// [pj] I didn't like the block_get_X_by_Y() functions because +// we should be able to do without them with clever coding, +// so I set out to see if they could be removed somehow. +// Only block_get_default_blocks() depends on them, and that +// one is used nowhere at the moment. So I 'm commenting +// them out until a use IS found. +// [el] Uncommented to be used in the installation process, when +// inserting new courses and when restoring courses. Perhaps +// they can be modified, but previously related processes +// will use them since now. + +//This function returns the id of the block, searching it by name +function block_get_id_by_name ($blockname) { + + if ($block = get_record("blocks","name",$blockname)) { + return $block->id; + } else { + return 0; + } +} + +//This function returns the name of the block, searching it by id +function block_get_name_by_id ($blockid) { + + if ($block = get_record("blocks","id",$blockid)) { + return $block->name; + } else { + return NULL; + } +} + +//This function return the necessary contents to update course->blockinfo +//with default values. It accepts a list of block_names as parameter. They +//will be converted to their blockids equivalent. If a course is specified +//then the function will update the field too! + +function blocks_get_default_blocks ($courseid = NULL, $blocknames="participants,activity_modules,calendar_month,calendar_upcoming,search_forums,admin,course_list:news_items,recent_activity") { + + //Calculate left and right blocks + $blocksn = $blocknames; + $delimpos = strpos($blocksn, ':'); + + if($delimpos === false) { + // No ':' found, we have all left blocks + $leftblocksn = explode(',', $blocksn); + $rightblocksn = array(); + } else if($delimpos === 0) { + // ':' at start of string, we have all right blocks + $blocksn = substr($blocksn, 1); + $leftblocksn = array(); + $rightblocksn = explode(',', $blocksn); + } + else { + // Both left and right blocks + $leftpartn = substr($blocksn, 0, $delimpos); + $rightpartn = substr($blocksn, $delimpos + 1); + $leftblocksn = explode(',', $leftpartn); + $rightblocksn = explode(',', $rightpartn); + } + + //Now I have blocks separated + + $leftblocks = array(); + $rightblocks = array(); + + if ($leftblocksn) { + foreach($leftblocksn as $leftblockn) { + //Convert blockname to id + $leftblock = block_get_id_by_name($leftblockn); + if ($leftblock) { + //Check it's visible + if($block = get_record("blocks","id",$leftblock,"visible","1")) { + $leftblocks[] = $leftblock; + } + } + } + } + + if ($rightblocksn) { + foreach($rightblocksn as $rightblockn) { + //Convert blockname to id + $rightblock = block_get_id_by_name($rightblockn); + if ($rightblock) { + //Check it's visible + if($block = get_record("blocks","id",$rightblock,"visible","1")) { + $rightblocks[] = $rightblock; + } + } + } + } + + //Calculate the blockinfo field + if ($leftblocks || $rightblocks) { + $blockinfo = ''; + if ($leftblocks) { + $blockinfo .= implode(",", $leftblocks); + } + if ($rightblocks) { + $blockinfo .= ':'.implode(",",$rightblocks); + } + } else { + $blockinfo = ''; + } + + //If a course has been specified, update it + if ($courseid) { + set_field('course', "blockinfo", $blockinfo, "id", $courseid); + } + + //Returns the blockinfo + return $blockinfo; +} + +?> diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 53b204d00a..2f2e169c0a 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -721,6 +721,10 @@ function main_upgrade($oldversion=0) { execute_sql("UPDATE {$CFG->prefix}course SET lang = 'cs' WHERE lang = 'cz'"); } + if ($oldversion < 2004041800) { /// Integrate Block System from contrib + table_column("course", "", "blockinfo", "varchar", "255", "", "", "not null", "modinfo"); + } + return $result; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 0e971daa42..877abbb0ef 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -38,6 +38,7 @@ CREATE TABLE `prefix_course` ( `format` varchar(10) NOT NULL default 'topics', `showgrades` smallint(2) unsigned NOT NULL default '1', `modinfo` longtext NOT NULL, + `blockinfo` varchar(255) NOT NULL default '', `newsitems` smallint(5) unsigned NOT NULL default '1', `teacher` varchar(100) NOT NULL default 'Teacher', `teachers` varchar(100) NOT NULL default 'Teachers', diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 0426823946..55a446389c 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -466,6 +466,10 @@ function main_upgrade($oldversion=0) { execute_sql("UPDATE {$CFG->prefix}course SET lang = 'cs' WHERE lang = 'cz'"); } + if ($oldversion < 2004041800) { /// Integrate Block System from contrib + table_column("course", "", "blockinfo", "varchar", "255", "", "", "not null", "modinfo"); + } + return $result; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index 5741ad8702..0d8c57ace6 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -16,6 +16,7 @@ CREATE TABLE prefix_course ( format varchar(10) NOT NULL default 'topics', showgrades integer NOT NULL default '1', modinfo text NOT NULL default '', + blockinfo varchar(255) NOT NULL default '', newsitems integer NOT NULL default '1', teacher varchar(100) NOT NULL default 'Teacher', teachers varchar(100) NOT NULL default 'Teachers', diff --git a/version.php b/version.php index befc20b470..86dce984fe 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2004040500; // The current version is a date (YYYYMMDDXX) +$version = 2004041800; // The current version is a date (YYYYMMDDXX) $release = "1.3 development"; // User-friendly version number