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 :-)
This commit is contained in:
stronk7
2004-04-18 23:20:53 +00:00
parent e8f1458ce1
commit 0f3fe4b6ad
65 changed files with 2961 additions and 282 deletions
+60
View File
@@ -0,0 +1,60 @@
<?PHP // $Id$
// block.php - allows admin to edit all local configuration variables for a block
require_once('../config.php');
require_once($CFG->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,
"<a href=\"index.php\">$stradmin</a> -> ".
"<a href=\"configure.php\">$strconfiguration</a> -> ".
"<a href=\"blocks.php\">$strmanageblocks</a> -> ".$strblockname);
print_heading($strblockname);
print_simple_box('<center>'.get_string('configwarning').'</center>', 'center', '50%');
echo '<br />';
$block->print_config();
print_footer();
?>
+181
View File
@@ -0,0 +1,181 @@
<?PHP // $Id$
// Allows the admin to configure blocks (hide/show, delete and configure)
require_once('../config.php');
require_once($CFG->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",
"<a href=\"index.php\">$stradministration</a> -> ".
"<a href=\"configure.php\">$strconfiguration</a> -> $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.'&amp;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 = "<img src=\"$modpixpath/$block->name/icon.gif\" hspace=10 height=16 width=16 border=0>";
$blockobject = $blockobjects[$blockid];
$delete = '<a href="blocks.php?delete='.$blockid.'">'.$strdelete.'</a>';
$settings = ''; // By default, no configuration
if($blockobject->has_config()) {
$settings = '<a href="block.php?block='.$blockid.'">'.$strsettings.'</a>';
}
$count = blocks_get_courses_using_block_by_id($blockid);
$class = ''; // Nothing fancy, by default
if ($block->visible) {
$visible = '<a href="blocks.php?hide='.$blockid.'" title="'.$strhide.'">'.
'<img src="'.$pixpath.'/i/hide.gif" style="height: 16px; width: 16px;" /></a>';
} else {
$visible = '<a href="blocks.php?show='.$blockid.'" title="'.$strshow.'">'.
'<img src="'.$pixpath.'/i/show.gif" style="height: 16px; width: 16px;" /></a>';
$class = ' class="dimmed_text"'; // Leading space required!
}
$table->data[] = array ('<p'.$class.'>'.$blockobject->get_title().'</p>', $count, $blockobject->get_version(), $visible, $delete, $settings);
}
echo '<p>';
print_table($table);
echo '</p>';
print_footer();
?>
+9 -2
View File
@@ -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")."</font><br />";
$configdata .= "<font size=+1>&nbsp;</font><a href=\"modules.php\">".get_string("managemodules")."</a> - <font size=1>".
get_string("adminhelpmanagemodules")."</font><br />";
$configdata .= "<font size=+1>&nbsp;</font><a href=\"blocks.php\">".get_string("manageblocks")."</a> - <font size=1>".
get_string("adminhelpmanageblocks")."</font><br />";
$configdata .= "<font size=+1>&nbsp;</font><a href=\"filters.php\">".get_string("managefilters")."</a> - <font size=1>".
get_string("adminhelpmanagefilters")."</font><br />";
if (!isset($CFG->disablescheduledbackups)) {
+1
View File
@@ -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);
+2 -2
View File
@@ -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 {
+1
View File
@@ -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);
+13
View File
@@ -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) {
+1 -1
View File
@@ -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
+42
View File
@@ -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;}
@@ -0,0 +1,39 @@
<?PHP //$Id$
class CourseBlock_activity_modules extends MoodleBlock {
function CourseBlock_activity_modules($course) {
$this->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[] = '<a href="../mod/'.$modname.'/index.php?id='.$this->course->id.'">'.$modnamesplural[$modname].'</a>';
$this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$modname.'/icon.gif" height="16" width="16" alt="">';
}
}
}
return $this->content;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function activity_modules_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
+206
View File
@@ -0,0 +1,206 @@
<?PHP //$Id$
class CourseBlock_admin extends MoodleBlock {
function CourseBlock_admin($course) {
$this->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[]='<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="">';
if (isediting($this->course->id)) {
$this->content->items[]='<a href="view.php?id='.$this->course->id.'&amp;edit=off">'.get_string('turneditingoff').'</a>';
} else {
$this->content->items[]='<a href="view.php?id='.$this->course->id.'&amp;edit=on">'.get_string('turneditingon').'</a>';
}
$this->content->items[]='<a href="edit.php?id='.$this->course->id.'">'.get_string('settings').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/settings.gif" height="16" width="16" alt="">';
if (iscreator() or !empty($CFG->teacherassignteachers)) {
if (!$this->course->teachers) {
$this->course->teachers = get_string('defaultcourseteachers');
}
$this->content->items[]='<a href="teacher.php?id='.$this->course->id.'">'.$this->course->teachers.'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="">';
}
if (!$this->course->students) {
$this->course->students = get_string('defaultcoursestudents');
}
$this->content->items[]='<a href="student.php?id='.$this->course->id.'">'.$this->course->students.'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="">';
$this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->course->id.'">'.get_string('backup').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/backup.gif" height="16" width="16" alt="">';
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->course->id.'&amp;wdir=/backupdata">'.get_string('restore').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" height="16" width="16" alt="">';
$this->content->items[]='<a href="scales.php?id='.$this->course->id.'">'.get_string('scales').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/scales.gif" height="16" width="16" alt="">';
}
$this->content->items[]='<a href="grades.php?id='.$this->course->id.'">'.get_string('grades').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" height="16" width="16" alt="">';
$this->content->items[]='<a href="log.php?id='.$this->course->id.'">'.get_string('logs').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/log.gif" height="16" width="16" alt="">';
if ($isteacheredit) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->course->id.'">'.get_string('files').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/files.gif" height="16" width="16" alt="">';
}
$this->content->items[]='<a href="'.$CFG->wwwroot.'/doc/view.php?id='.$this->course->id.'&amp;file=teacher.html">'.get_string('help').'...</a>';
$this->content->icons[]='<img src="'.$CFG->modpixpath.'/resource/icon.gif" height="16" width="16" alt="">';
if ($teacherforum = forum_get_course_forum($this->course->id, 'teacher')) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/mod/forum/view.php?f='.$teacherforum->id.'">'.get_string('nameteacher', 'forum').'</a>';
$this->content->icons[]='<img src="'.$CFG->modpixpath.'/forum/icon.gif" height="16" width="16" alt="">';
}
} else if (!isguest()) { // Students menu
if ($this->course->showgrades) {
$this->content->items[]='<a href="grade.php?id='.$this->course->id.'">'.get_string('grades').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" height="16" width="16" alt="">';
}
if ($this->course->showreports) {
$this->content->items[]='<a href="user.php?id='.$this->course->id.'&amp;user='.$USER->id.'">'.get_string('activityreport').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/report.gif" height="16" width="16" alt="">';
}
if (is_internal_auth()) {
$this->content->items[]='<a href="'.$CFG->wwwroot.'/login/change_password.php?id='.$this->course->id.'">'.get_string('changepassword').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" height="16" width="16" alt="">';
} else if ($CFG->changepassword) {
$this->content->items[]='<a href="'.$CFG->changepassword.'">'.get_string('changepassword').'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" height="16" width="16" alt="">';
}
if ($CFG->allowunenroll) {
$this->content->items[]='<a href="unenrol.php?id='.$this->course->id.'">'.get_string('unenrolme', '', $this->course->shortname).'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" height="16" width="16" alt="">';
}
}
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[]="<img src=\"$CFG->pixpath/i/edit.gif\" height=16 width=16 alt=\"\">";
if (isediting($course->id)) {
$block->items[]="<a href=\"view.php?id=$course->id&edit=off\">".get_string("turneditingoff")."</a>";
} else {
$block->items[]="<a href=\"view.php?id=$course->id&edit=on\">".get_string("turneditingon")."</a>";
}
$block->items[]="<a href=\"edit.php?id=$course->id\">".get_string("settings")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/settings.gif\" height=16 width=16 alt=\"\">";
if (iscreator() or !empty($CFG->teacherassignteachers)) {
if (!$course->teachers) {
$course->teachers = get_string("defaultcourseteachers");
}
$block->items[]="<a href=\"teacher.php?id=$course->id\">$course->teachers...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
}
if (!$course->students) {
$course->students = get_string("defaultcoursestudents");
}
$block->items[]="<a href=\"student.php?id=$course->id\">$course->students...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
$block->items[]="<a href=\"$CFG->wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/backup.gif\" height=16 width=16 alt=\"\">";
$block->items[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/restore.gif\" height=16 width=16 alt=\"\">";
$block->items[]="<a href=\"scales.php?id=$course->id\">".get_string("scales")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/scales.gif\" height=16 width=16 alt=\"\">";
}
$block->items[]="<a href=\"grades.php?id=$course->id\">".get_string("grades")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/grades.gif\" height=16 width=16 alt=\"\">";
$block->items[]="<a href=\"log.php?id=$course->id\">".get_string("logs")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/log.gif\" height=16 width=16 alt=\"\">";
if ($isteacheredit) {
$block->items[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/files.gif\" height=16 width=16 alt=\"\">";
}
$block->items[]="<a href=\"$CFG->wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...</a>";
$block->icons[]="<img src=\"$CFG->modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">";
if ($teacherforum = forum_get_course_forum($course->id, "teacher")) {
$block->items[]="<a href=\"$CFG->wwwroot/mod/forum/view.php?f=$teacherforum->id\">$teacherforum->name</a>";
$block->icons[]="<img src=\"$CFG->modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">";
}
} else if (!isguest()) { // Students menu
if ($course->showgrades) {
$block->items[]="<a href=\"grade.php?id=$course->id\">".get_string("grades")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/grades.gif\" height=16 width=16 alt=\"\">";
}
if ($course->showreports) {
$block->items[]="<a href=\"user.php?id=$course->id&user=$USER->id\">".get_string("activityreport")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/report.gif\" height=16 width=16 alt=\"\">";
}
if (is_internal_auth()) {
$block->items[]="<a href=\"$CFG->wwwroot/login/change_password.php?id=$course->id\">".
get_string("changepassword")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
} else if ($CFG->changepassword) {
$block->items[]="<a href=\"$CFG->changepassword\">".get_string("changepassword")."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
}
if ($CFG->allowunenroll) {
$block->items[]="<a href=\"unenrol.php?id=$course->id\">".get_string("unenrolme", "", $course->shortname)."...</a>";
$block->icons[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
}
}
return $block;
}
*/
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function admin_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
@@ -0,0 +1,75 @@
<?PHP //$Id$
class CourseBlock_calendar_month extends MoodleBlock {
function CourseBlock_calendar_month($course) {
$this->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;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function calendar_month_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
@@ -0,0 +1,64 @@
<?PHP //$Id$
class CourseBlock_calendar_upcoming extends MoodleBlock {
function CourseBlock_calendar_upcoming ($course) {
$this->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 = '<div style="font-size: 0.8em; text-align: center;">'.get_string('noupcomingevents', 'calendar').'</div>';
}
return $this->content;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function calendar_upcoming_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
+82
View File
@@ -0,0 +1,82 @@
<?PHP //$Id$
class CourseBlock_course_list extends MoodleBlock {
function CourseBlock_course_list ($course) {
$this->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 = "<img src=\"$CFG->wwwroot/pix/i/course.gif\"".
" height=\"16\" width=\"16\" alt=\"".get_string("course")."\">";
} else {
$icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/course.gif\"".
" height=\"16\" width=\"16\" alt=\"".get_string("course")."\">";
}
if (isset($USER->id) and !isadmin()) { // Just print My Courses
if ($courses = get_my_courses($USER->id)) {
foreach ($courses as $course) {
if (!$course->category) {
continue;
}
$linkcss = $course->visible ? "" : " class=\"dimmed\" ";
$this->content->items[]="<a $linkcss title=\"$course->shortname\" ".
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
$this->content->icons[]=$icon;
}
$this->title = get_string('mycourses');
$this->content->footer = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...";
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[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>";
$this->content->icons[]=$icon;
}
$this->content->footer = "<p><a href=\"$CFG->wwwroot/course/\">".get_string("searchcourses")."</a>...";
$this->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[]="<a $linkcss title=\"$course->shortname\" ".
"href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
$this->content->icons[]=$icon;
}
$this->content->footer = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>...";
} else {
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = get_string('nocoursesyet');
}
$this->title = get_string('courses');
}
}
return $this->content;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function course_list_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
@@ -0,0 +1,25 @@
<?PHP //$Id$
class CourseBlock_course_summary extends MoodleBlock {
function CourseBlock_course_summary ($course) {
$this->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;}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function course_summary_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
+43
View File
@@ -0,0 +1,43 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function blocks_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = execute_sql("CREATE TABLE `{$CFG->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;
}
?>
+15
View File
@@ -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;
# --------------------------------------------------------
+207
View File
@@ -0,0 +1,207 @@
<?php
define('BLOCK_TYPE_LIST', 1);
define('BLOCK_TYPE_TEXT', 2);
class MoodleBlock {
var $str;
var $title = NULL;
var $course = NULL;
var $content_type = NULL;
var $content = NULL;
var $edit_controls = NULL;
var $version = NULL;
function name() {
// Returns the block name, as present in the class name,
// the database, the block directory, etc etc.
static $myname;
if($myname === NULL) {
$myname = strtolower(get_class($this));
$myname = substr($myname, strpos($myname, '_') + 1);
}
return $myname;
}
function get_content() {
// This should be implemented by the derived class.
return NULL;
}
function get_title() {
// Intentionally doesn't check if a title is set, for _test_self()
return $this->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 = '<div style="float: left;">'.$this->title.'</div>';
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 = '<div style="float: left;">'.$this->title.'</div>';
if($this->edit_controls !== NULL) {
$title .= $this->edit_controls;
}
print_side_block($title, '&nbsp;', 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 = '<div style="float: right;">';
if($enabled) {
$icon = '/t/hide.gif';
$title = $this->str->hide;
}
else {
$icon = '/t/show.gif';
$title = $this->str->show;
}
$movebuttons .= '<a style="margin-right: 10px;" title="'.$title.'" href="'.$path.'/view.php?id='.$this->course->id.'&amp;blockaction=toggle&amp;blockid='.$blockid.'">' .
'<img src="'.$pixpath.$icon.'" /></a>';
$movebuttons .= '<a style="margin-right: 10px;" title="'.$this->str->delete.'" href="'.$path.'/view.php?id='.$this->course->id.'&amp;blockaction=delete&amp;blockid='.$blockid.'">' .
'<img src="'.$pixpath.'/t/delete.gif" /></a>';
if ($options & BLOCK_MOVE_LEFT) {
$movebuttons .= '<a style="margin-right: 3px;" title="'.$this->str->moveleft.'" href="'.$path.'/view.php?id='.$this->course->id.'&amp;blockaction=moveside&amp;blockid='.$blockid.'">' .
'<img src="'.$pixpath.'/t/left.gif" /></a>';
}
if ($options & BLOCK_MOVE_UP) {
$movebuttons .= '<a style="margin-right: 3px;" title="'.$this->str->moveup.'" href="'.$path.'/view.php?id='.$this->course->id.'&amp;blockaction=moveup&amp;blockid='.$blockid.'">' .
'<img src="'.$pixpath.'/t/up.gif" /></a>';
}
if ($options & BLOCK_MOVE_DOWN) {
$movebuttons .= '<a style="margin-right: 3px;" title="'.$this->str->movedown.'" href="'.$path.'/view.php?id='.$this->course->id.'&amp;blockaction=movedown&amp;blockid='.$blockid.'">' .
'<img src="'.$pixpath.'/t/down.gif" /></a>';
}
if ($options & BLOCK_MOVE_RIGHT) {
$movebuttons .= '<a style="margin-right: 3px;" title="'.$this->str->moveright.'" href="'.$path.'/view.php?id='.$this->course->id.'&amp;blockaction=moveside&amp;blockid='.$blockid.'">' .
'<img src="'.$pixpath.'/t/right.gif" /></a>';
}
$movebuttons .= '</div>';
$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;
}
}
?>
+38
View File
@@ -0,0 +1,38 @@
<?PHP //$Id$
class CourseBlock_news_items extends MoodleBlock {
function CourseBlock_news_items ($course) {
$this->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 '<font size="-2">';
forum_print_latest_discussions($news->id, $this->course->newsitems, "minimal", "", get_current_group($this->course->id));
echo '</font>';
$this->content->text = ob_get_contents();
ob_end_clean();
}
return $this->content;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function news_items_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
+138
View File
@@ -0,0 +1,138 @@
<?PHP //$Id$
class CourseBlock_online_users extends MoodleBlock {
function CourseBlock_online_users ($course) {
$this->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 = "<font size=\"-2\"><div align=center>(".get_string("periodnminutes","block_online_users",$minutes).")</div></font>";
//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 .= '<div style="text-align: left; font-size: 0.75em; padding-top: 5px;">';
$timeago = format_time(time() - $user->timeaccess);
if ($user->picture==0) {
$this->content->text .= '<img src="'.$CFG->pixpath.'/i/user.gif" style="height: 16px; width=16px; vertical-align: middle;" alt=""> ';
} else {
if ($CFG->slasharguments) {
$imgtag = '<img src="'.$CFG->wwwroot.'/user/pix.php/'.$user->id.'/f2.jpg" style="height: 16px; width=16px; vertical-align: middle;" alt=""> ';
} else {
$imgtag = '<img src="'.$CFG->wwwroot.'/user/pix.php?file=/'.$user->id.'/f2.jpg" style="height: 16px; width=16px; vertical-align: middle;" alt=""> ';
}
$this->content->text .= $imgtag;
}
$this->content->text .= '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$this->course->id.'" title="'.$timeago.'">'.$user->fullname.'</a></div>';
}
/*
$table->align = array("right","left");
$table->cellpadding = 1;
$table->cellspacing = 1;
$table->data[] = array("<img src=\"$CFG->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 .= "<br>".ob_get_contents();
ob_end_clean();
*/
} else {
$this->content->text .= "<font size=\"-1\"><p align=center>".get_string("none")."</p></font>";
}
return $this->content;
}
}
?>
+24
View File
@@ -0,0 +1,24 @@
<form method="post" action="block.php">
<table cellpadding="9" cellspacing="0">
<tr valign="top">
<td align="right"><p>block_online_users_timetosee:</td>
<td>
<input name="block" type="hidden" value="<?php echo intval($_REQUEST['block']); ?>" />
<input name="block_online_users_timetosee" type="text" size="5" value="<?php if(isset($CFG->block_online_users_timetosee)) {
p($CFG->block_online_users_timetosee);
} else {
p(5);
} ?>" />
</td>
<td>
<?php print_string("configtimetosee", "block_online_users") ?>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="<?php print_string("savechanges") ?>"></td>
</tr>
</table>
</form>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function online_users_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
@@ -0,0 +1,54 @@
<?PHP //$Id$
class CourseBlock_participants extends MoodleBlock {
function CourseBlock_participants ($course) {
$this->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[]='<a title="'.get_string('listofallpeople').'" href="../user/index.php?id='.$this->course->id.'">'.get_string('participants').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="">';
if ($this->course->groupmode or !$this->course->groupmodeforce) {
if ($this->course->groupmode == VISIBLEGROUPS or isteacheredit($this->course->id)) {
$this->content->items[]='<a title="'.$strgroups.'" href="groups.php?id='.$this->course->id.'">'.$strgroups.'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" height="16" width="16" alt="">';
} else if ($this->course->groupmode == SEPARATEGROUPS and $this->course->groupmodeforce) {
// Show nothing
} else if ($currentgroup = get_current_group($this->course->id)) {
$this->content->items[]='<a title="'.$strgroupmy.'" href="group.php?id='.$this->course->id.'">'.$strgroupmy.'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" height="16" width="16" alt="">';
}
}
$fullname = fullname($USER, true);
$editmyprofile = '<a title="'.$fullname.'" href="../user/edit.php?id='.$USER->id.'&amp;course='.$this->course->id.'">'.get_string('editmyprofile').'</a>';
if ($USER->description) {
$this->content->items[]= $editmyprofile;
} else {
$this->content->items[]= $editmyprofile." <blink>*</blink>";
}
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" height="16" width="16" alt="">';
return $this->content;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function participants_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
class CourseBlock_recent_activity extends MoodleBlock {
function CourseBlock_recent_activity ($course) {
$this->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;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function recent_activity_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
@@ -0,0 +1,31 @@
<?PHP //$Id$
class CourseBlock_search_forums extends MoodleBlock {
function CourseBlock_search_forums ($course) {
$this->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 = '<div align="center">'.$form.'</div>';
return $this->content;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function search_forums_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
View File
@@ -0,0 +1,123 @@
<?php //$Id$
class CourseBlock_social_activities extends MoodleBlock {
function CourseBlock_social_activities ($course) {
$this->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[] = '&nbsp;<img align="bottom" src="'.$CFG->pixpath.'/t/move.gif" height="11" width="11">';
$this->content->icons[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true">'.$strcancel.'</a>)';
}
if (!empty($section->sequence)) {
$sectionmods = explode(',', $section->sequence);
foreach ($sectionmods as $modnumber) {
if (empty($mods[$modnumber])) {
continue;
}
$mod = $mods[$modnumber];
if ($isediting && !$ismoving) {
if ($groupbuttons) {
if (! $mod->groupmodelink = $groupbuttonslink) {
$mod->groupmode = $this->course->groupmode;
}
} else {
$mod->groupmode = false;
}
$editbuttons = '<br />'.make_editing_buttons($mod, true, true);
} else {
$editbuttons = '';
}
if ($mod->visible || $isteacher) {
if ($ismoving) {
if ($mod->id == $USER->activitycopy) {
continue;
}
$this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'">'.
'<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0"></a>';
$this->content->icons[] = '';
}
$instancename = urldecode($modinfo[$modnumber]->name);
if (!empty($CFG->filterall)) {
$instancename = filter_text('<nolink>'.$instancename.'</nolink>', $this->course->id);
}
$linkcss = $mod->visible ? '' : ' class="dimmed" ';
if (!empty($modinfo[$modnumber]->extra)) {
$extra = urldecode($modinfo[$modnumber]->extra);
} else {
$extra = '';
}
if ($mod->modname == 'label') {
$this->content->items[] = format_text($extra, FORMAT_HTML).$editbuttons;
$this->content->icons[] = '';
} else {
$this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons;
$this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$mod->modname.'/icon.gif" height="16" width="16" alt="'.$mod->modfullname.'">';
}
}
}
}
if ($ismoving) {
$this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'">'.
'<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0"></a>';
$this->content->icons[] = '';
}
if ($isediting && $modnames) {
$this->content->footer = '<div style="text-align: right;">'.
popup_form($CFG->wwwroot.'/course/mod.php?id='.$this->course->id.'&amp;section='.$section->section.'&amp;add=',
$modnames, 'section0', '', get_string('add').'...', 'mods', get_string('activities'), true) . '</div>';
} else {
$this->content->footer = '';
}
return $this->content;
}
}
?>
+33
View File
@@ -0,0 +1,33 @@
<?PHP //$Id$
//
// This file keeps track of upgrades to Moodle's
// blocks system.
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installtion to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// Versions are defined by backup_version.php
//
// This file is tailored to MySQL
function social_activities_upgrade($oldversion=0) {
global $CFG;
$result = true;
if ($oldversion < 2004041000 and $result) {
$result = true; //Nothing to do
}
//Finally, return result
return $result;
}
+8
View File
@@ -0,0 +1,8 @@
<?PHP //$Id$
// This file defines the current version of the
// blocks code that is being used. This can be
// compared against the values stored in the
// database (blocks_version) to determine whether upgrades should
// be performed (see db/backup_*.php)
$blocks_version = 2004041500; // The current version is a date (YYYYMMDDXX)
+9
View File
@@ -3,6 +3,7 @@
require_once("../config.php");
require_once("lib.php");
require_once("$CFG->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.
+61 -91
View File
@@ -1,99 +1,69 @@
<?php // $Id$
<?php
// social.php - course format featuring social forum
// included from view.php
require_once("$CFG->dirroot/mod/forum/lib.php");
require_once("$CFG->dirroot/mod/resource/lib.php");
$leftwidth = 210;
// 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);
$strgroups = get_string("groups");
$strgroupmy = get_string("groupmy");
$editing = isediting($course->id);
echo '<table width="100%" border="0" cellspacing="5" cellpadding="5">';
echo '<tr>';
if(block_have_active($leftblocks) || $editing) {
echo '<td style="vertical-align: top; width: '.$preferred_width_left.'px;">';
print_course_blocks($course, $leftblocks, BLOCK_LEFT);
echo '</td>';
}
echo "<td width=\"*\" valign=\"top\">";
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 = "<table border=0 width=100% cellpadding=0 cellspacing=0><tr><td>".
get_string("socialheadline").
"</td><td align=right><font size=1>".
"<a href=\"../mod/forum/subscribe.php?id=$social->id\">$subtext</a></td>".
"</tr></table>";
print_heading_block($headertext);
echo "<img alt=\"\" height=7 src=\"../pix/spacer.gif\"><br>";
forum_print_latest_discussions($social->id, 10, "plain", "", false);
} else {
notify("Could not find or create a social forum here");
}
echo '</td>';
if(block_have_active($rightblocks) || $editing) {
echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;">';
if ($editing && !empty($missingblocks)) {
block_print_add_block($course->id, $missingblocks);
}
print_course_blocks($course, $rightblocks, BLOCK_RIGHT);
print_spacer(1, 120, true);
echo '</td>';
}
echo '</tr>';
echo '</table>';
?>
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="<?php echo $leftwidth?>" valign="top">
<?php
$moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
if ($course->groupmode or !$course->groupmodeforce) {
if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) {
$moddata[]="<a title=\"$strgroups\" href=\"groups.php?id=$course->id\">$strgroups</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
} else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) {
// Show nothing
} else if ($currentgroup) {
$moddata[]="<a title=\"$strgroupmy\" href=\"group.php?id=$course->id\">$strgroupmy</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
}
}
$fullname = fullname($USER, true);
$editmyprofile = "<a title=\"$fullname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".
get_string("editmyprofile")."</A>";
if ($USER->description) {
$moddata[]= $editmyprofile;
} else {
$moddata[]= $editmyprofile." <blink>*</blink>";
}
$modicon[]="<img src=\"$CFG->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 = "<div align=\"center\">$searchform</div>";
print_side_block(get_string("search","forum"), $searchform, "", "", "", $leftwidth);
/// Print the calendar
calendar_print_side_blocks();
/// 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();
}
/// Admin links and controls
print_course_admin_links($course);
/// My courses
print_courses_sideblock(0, "$leftwidth");
echo "</td>";
echo "<td width=\"*\" valign=\"top\">";
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 = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=headingblockcontent><tr><td>".
get_string("socialheadline").
"</td><td align=right><font size=1>".
"<a href=\"../mod/forum/subscribe.php?id=$social->id\">$subtext</a></td>".
"</tr></table>";
print_heading_block($headertext);
echo "<img alt=\"\" height=7 src=\"../pix/spacer.gif\"><br>";
forum_print_latest_discussions($social->id, 10, "plain", "", $currentgroup);
} else {
notify("Could not find or create a social forum here");
}
?>
</td>
</tr>
</table>
+45 -93
View File
@@ -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 "<table border=0 cellpadding=3 cellspacing=0 width=100%>";
echo "<tr valign=top>\n";
/// The left column ...
echo "<tr valign=top><td valign=top width=180>";
/// Links to people
$moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
if ($course->groupmode or !$course->groupmodeforce) {
if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) {
$moddata[]="<a title=\"$strgroups\" href=\"groups.php?id=$course->id\">$strgroups</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
} else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) {
// Show nothing
} else if ($currentgroup) {
$moddata[]="<a title=\"$strgroupmy\" href=\"group.php?id=$course->id\">$strgroupmy</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
}
if(block_have_active($leftblocks) || $editing) {
echo '<td style="vertical-align: top; width: '.$preferred_width_left.'px;">';
print_course_blocks($course, $leftblocks, BLOCK_LEFT);
echo '</td>';
}
$fullname = fullname($USER, true);
$editmyprofile = "<a title=\"$fullname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".get_string("editmyprofile")."</a>";
if ($USER->description) {
$moddata[]= $editmyprofile;
} else {
$moddata[]= $editmyprofile." <blink>*</blink>";
}
$modicon[]="<img src=\"$CFG->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[] = "<a href=\"../mod/$modname/index.php?id=$course->id\">".$modnamesplural[$modname]."</a>";
$modicon[] = "<img src=\"$CFG->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 = "<div align=\"center\">$searchform</div>";
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 "</td><td width=\"*\">";
echo "<td width=\"*\">";
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 "<tr>";
echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"topicsoutlineside\" valign=top width=20>&nbsp;</td>";
echo "<td valign=top bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontent\" width=\"100%\">";
echo format_text($thissection->summary, FORMAT_HTML);
if (isediting($course->id)) {
@@ -148,18 +109,18 @@
" href=\"editsection.php?id=$thissection->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
" height=11 width=11 border=0 alt=\"$streditsummary\"></a><br />";
}
echo '<br clear="all">';
print_section($course, $thissection, $mods, $modnamesused);
if (isediting($course->id)) {
echo "<div align=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", "$stradd...", "mods", $stractivities);
echo "</div>";
}
echo "</td>";
echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"topicsoutlineside\" valign=top align=center width=10>";
echo "&nbsp;</td></tr>";
@@ -223,7 +184,7 @@
echo "<td nowrap $colorsides valign=top width=20>";
echo "<p align=center><font size=3><b>$section</b></font></p>";
echo "</td>";
if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students
echo "<td valign=top align=center $colormain width=\"100%\">";
echo get_string("notavailable");
@@ -240,16 +201,16 @@
}
echo '<br clear="all">';
print_section($course, $thissection, $mods, $modnamesused);
if (isediting($course->id)) {
echo "<div align=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", "$stradd...");
echo "</div>";
}
echo "</td>";
}
echo "<td nowrap $colorsides valign=top align=center width=10>";
@@ -303,35 +264,26 @@
if (!empty($sectionmenu)) {
echo "<center>";
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 "</center>";
}
if (!empty($news) or $course->showrecent) {
echo "</td><td width=210>";
/// Print all the news items.
echo "</td>";
if (!empty($news)) {
print_side_block_start(get_string("latestnews"), 210, "sideblocklatestnews");
echo "<font size=\"-2\">";
forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "", $currentgroup);
echo "</font>";
print_side_block_end();
// The right column
if(block_have_active($rightblocks) || $editing) {
echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;">';
if ($editing && !empty($missingblocks)) {
block_print_add_block($course->id, $missingblocks);
}
// 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();
}
print_course_blocks($course, $rightblocks, BLOCK_RIGHT);
print_spacer(1, 120, true);
echo '</td>';
}
echo "</td></tr></table>\n";
echo "</tr>\n";
echo "</table>\n";
?>
+37 -82
View File
@@ -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,64 +50,16 @@
/// Layout the whole page as three big columns.
echo "<table border=0 cellpadding=3 cellspacing=0 width=100%>";
echo "<tr valign=top>\n";
/// The left column ...
echo "<tr valign=top><td valign=top width=180>";
/// Links to people
$moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
if ($course->groupmode or !$course->groupmodeforce) {
if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) {
$moddata[]="<a title=\"$strgroups\" href=\"groups.php?id=$course->id\">$strgroups</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
} else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) {
// Show nothing
} else if ($currentgroup) {
$moddata[]="<a title=\"$strgroupmy\" href=\"group.php?id=$course->id\">$strgroupmy</a>";
$modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
}
if(block_have_active($leftblocks) || $editing) {
echo '<td style="vertical-align: top; width: '.$preferred_width_left.'px;">';
print_course_blocks($course, $leftblocks, BLOCK_LEFT);
echo '</td>';
}
$fullname = fullname($USER, true);
$editmyprofile = "<a title=\"$fullname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".get_string("editmyprofile")."</a>";
if ($USER->description) {
$moddata[]= $editmyprofile;
} else {
$moddata[]= $editmyprofile." <blink>*</blink>";
}
$modicon[]="<img src=\"$CFG->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[] = "<a href=\"../mod/$modname/index.php?id=$course->id\">".$modnamesplural[$modname]."</a>";
$modicon[] = "<img src=\"$CFG->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 = "<div align=\"center\">$searchform</div>";
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 "</td><td width=\"*\">";
print_heading_block(get_string("weeklyoutline"), "100%", "outlineheadingblock");
@@ -136,12 +100,12 @@
}
echo '<br clear="all">';
print_section($course, $thissection, $mods, $modnamesused);
if (isediting($course->id)) {
echo "<div align=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", "$stradd...", "mods", $stractivities);
echo "</div>";
}
@@ -234,17 +198,17 @@
if (isediting($course->id)) {
echo "<div align=right>";
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
$modnames, "section$section", "", "$stradd...");
echo "</div>";
}
echo "</td>";
}
}
echo "<td nowrap $colorsides valign=top align=center width=10>";
echo "<font size=1>";
if ($displaysection == $section) {
if ($displaysection == $section) {
echo "<a href=\"view.php?id=$course->id&week=all\" title=\"$strshowallweeks\">".
"<img src=\"$CFG->pixpath/i/all.gif\" height=25 width=16 border=0></a><br />";
} else {
@@ -285,34 +249,25 @@
if (!empty($sectionmenu)) {
echo "<center>";
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 "</center>";
}
if (!empty($news) or !empty($course->showrecent)) {
echo "</td><td width=210>";
// Print all the news items.
if (!empty($news)) {
print_side_block_start(get_string("latestnews"), 210, "sideblocklatestnews");
echo "<font size=\"-2\">";
forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "", $currentgroup);
echo "</font>";
print_side_block_end();
echo "</td>";
// The right column
if(block_have_active($rightblocks) || $editing) {
echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;">';
if ($editing && !empty($missingblocks)) {
block_print_add_block($course->id, $missingblocks);
}
// 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();
}
print_course_blocks($course, $rightblocks, BLOCK_RIGHT);
print_spacer(1, 120, true);
echo '</td>';
}
echo "</td></tr></table>\n";
echo "</tr>\n";
echo "</table>\n";
?>
+84 -10
View File
@@ -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 = "<p class=\"logininfo\">".user_login_string($course, $USER)."</p>";
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();
+4
View File
@@ -0,0 +1,4 @@
<?PHP // $Id$
$string['blockname'] = 'Course Summary';
?>
+6
View File
@@ -0,0 +1,6 @@
<?PHP // $Id$
$string['blockname'] = 'Online Users';
$string['periodnminutes'] = 'last $a minutes';
$string['configtimetosee'] = 'Number of minutes to detect an user as currently online';
?>
+4
View File
@@ -0,0 +1,4 @@
<?PHP // $Id$
$string['blockname'] = 'Social Activities';
?>
+5
View File
@@ -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';
+784
View File
@@ -0,0 +1,784 @@
<?PHP //$Id$
//This library includes all the necessary stuff to use blocks in course pages
define('BLOCK_LEFT', 11);
define('BLOCK_RIGHT', 12);
define('BLOCK_MOVE_LEFT', 0x01);
define('BLOCK_MOVE_RIGHT', 0x02);
define('BLOCK_MOVE_UP', 0x04);
define('BLOCK_MOVE_DOWN', 0x08);
define('COURSE_FORMAT_WEEKS', 0x01);
define('COURSE_FORMAT_TOPICS', 0x02);
define('COURSE_FORMAT_SOCIAL', 0x04);
//This function retrieves a method-defined property of a class WITHOUT instantiating an object
//It seems that the only way to use the :: operator with variable class names is eval() :(
//For caveats with this technique, see the PHP docs on operator ::
function block_method_result($blockname, $method) {
if(!block_load_class($blockname)) {
return NULL;
}
return eval('return CourseBlock_'.$blockname.'::'.$method.'();');
}
//This function creates a new object of the specified block class
function block_instance($blockname, $argument) {
if(!block_load_class($blockname)) {
return false;
}
$classname = 'CourseBlock_'.$blockname;
return New $classname($argument);
}
//This function loads the necessary class files for a block
//Whenever you want to load a block, use this first
function block_load_class($blockname) {
global $CFG;
@include_once($CFG->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.'&amp;blockaction=add&amp;blockid=',$menu,'add_block','','choose','','',true);
$content = '<div align="center">'.$content.'</div>';
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, "&nbsp;", "&nbsp;");
$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, "&nbsp;", "&nbsp;");
}
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 "<HR>";
} 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('<strong>Naming conflict</strong>: block <strong>'.$block->name.'</strong> has the same title with an existing block, <strong>'.$conflictblock.'</strong>!');
}
if (empty($updated_blocks)) {
$strblocksetup = get_string("blocksetup");
print_header($strblocksetup, $strblocksetup, $strblocksetup, "", "", false, "&nbsp;", "&nbsp;");
}
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 "<HR>";
} 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.')<br>';
}
}
}
}
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;
}
?>
+4
View File
@@ -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;
}
+1
View File
@@ -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',
+4
View File
@@ -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;
}
+1
View File
@@ -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',
+1 -1
View File
@@ -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