Skip to content

Commit

Permalink
Da monster-commit of blocks version 2!
Browse files Browse the repository at this point in the history
Code based on the work of Daryl Hawes for the blog module. Thanks, Daryl!

Please test the hell out of it as it's sure to have issues that need to be
ironed out.
  • Loading branch information
defacer committed Oct 19, 2004
1 parent 2defdcd commit 9b4b78f
Show file tree
Hide file tree
Showing 38 changed files with 1,185 additions and 937 deletions.
6 changes: 3 additions & 3 deletions admin/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

require_variable($_REQUEST['block']);
$blockid = intval($_REQUEST['block']);

if(($blockrecord = get_record('blocks', 'id', $blockid)) === false) {
if(($blockrecord = blocks_get_record($blockid)) === false) {
error('This block does not exist');
}

$block = block_instance($blockrecord->name, NULL);
$block = block_instance($blockrecord->name);
if($block === false) {
error('Problem in instantiating block object');
}
Expand Down
83 changes: 58 additions & 25 deletions admin/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
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
$hide = optional_param('hide', 0, PARAM_INT);
$show = optional_param('show', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
$multiple = optional_param('multiple', 0, PARAM_INT);

require_login();

Expand All @@ -32,8 +32,9 @@
$strhide = get_string('hide');
$strshow = get_string('show');
$strsettings = get_string('settings');
$strcourses = get_string('courses');
$strcourses = get_string('blockinstances', 'admin');
$strname = get_string('name');
$strmultiple = get_string('blockmultiple', 'admin');

print_header("$site->shortname: $strmanageblocks", "$site->fullname",
"<a href=\"index.php\">$stradministration</a> -> ".
Expand All @@ -44,27 +45,35 @@

/// If data submitted, then process and store.

if (!empty($_GET['hide']) and confirm_sesskey()) {
if (!$block = get_record('blocks', 'id', $_GET['hide'])) {
if (!empty($hide) && confirm_sesskey()) {
if (!$block = get_record('block', 'id', $hide)) {
error("Block doesn't exist!");
}
set_field('blocks', 'visible', '0', 'id', $block->id); // Hide block
set_field('block', 'visible', '0', 'id', $block->id); // Hide block
}

if (!empty($_GET['show']) and confirm_sesskey() ) {
if (!$block = get_record('blocks', 'id', $_GET['show'])) {
if (!empty($show) && confirm_sesskey() ) {
if (!$block = get_record('block', 'id', $show)) {
error("Block doesn't exist!");
}
set_field('blocks', 'visible', '1', 'id', $block->id); // Show block
set_field('block', 'visible', '1', 'id', $block->id); // Show block
}

if (!empty($delete) and confirm_sesskey()) {
if (!empty($multiple) && confirm_sesskey()) {
if (!$block = blocks_get_record($multiple)) {
error("Block doesn't exist!");
}
$block->multiple = !$block->multiple;
update_record('block', $block);
}

if (!$block = get_record('blocks', 'id', $delete)) {
if (!empty($delete) && confirm_sesskey()) {

if (!$block = blocks_get_record($delete)) {
error("Block doesn't exist!");
}

$blockobject = block_instance($block->name, $site);
$blockobject = block_instance($block->name);
$strblockname = $blockobject->get_title();

if (!$_GET['confirm']) {
Expand All @@ -76,11 +85,16 @@

} else {
// Delete block
if (!delete_records('blocks', 'id', $block->id)) {
if (!delete_records('block', '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
$instances = get_records('block_instance', 'blockid', $block->id);
if(!empty($instances)) {
foreach($instances as $instance) {
blocks_delete_instance($instance);
}
}

// Then the tables themselves

Expand All @@ -105,12 +119,12 @@

/// Get and sort the existing blocks

if (false === ($blocks = get_records('blocks'))) {
if (false === ($blocks = get_records('block'))) {
error('No blocks found!'); // Should never happen
}

foreach ($blocks as $block) {
if(($blockobject = block_instance($block->name, NULL)) === false) {
if(($blockobject = block_instance($block->name)) === false) {
// Failed to load
continue;
}
Expand All @@ -136,11 +150,11 @@
//$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";
$table->head = array ($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strmultiple, $strdelete, $strsettings);
$table->align = array ('LEFT', 'RIGHT', 'LEFT', 'CENTER', 'CENTER', 'CENTER', 'CENTER');
$table->wrap = array ('NOWRAP', '', '', '', '', '', '');
$table->size = array ('100%', '10', '10', '10', '10','12');
$table->width = '100';

foreach ($blockbyname as $blockname => $blockid) {

Expand All @@ -155,7 +169,7 @@
$settings = '<a href="block.php?block='.$blockid.'&sesskey='.$USER->sesskey.'">'.$strsettings.'</a>';
}

$count = blocks_get_courses_using_block_by_id($blockid);
$count = count_records('block_instance', 'blockid', $blockid);
$class = ''; // Nothing fancy, by default

if ($blocks[$blockid]->visible) {
Expand All @@ -166,8 +180,27 @@
'<img src="'.$pixpath.'/i/show.gif" style="height: 16px; width: 16px;" alt=\"\" /></a>';
$class = ' class="dimmed_text"'; // Leading space required!
}
if ($blockobject->instance_allow_multiple()) {
if($blocks[$blockid]->multiple) {
$multiple = '<nobr>'.get_string('yes').' (<a href="blocks.php?multiple='.$blockid.'&sesskey='.$USER->sesskey.'">'.get_string('change', 'admin').'</a>)</nobr>';
}
else {
$multiple = '<nobr>'.get_string('no').' (<a href="blocks.php?multiple='.$blockid.'&sesskey='.$USER->sesskey.'">'.get_string('change', 'admin').'</a>)</nobr>';
}
}
else {
$multiple = '';
}

$table->data[] = array ('<p'.$class.'>'.$blockobject->get_title().'</p>', $count, $blockobject->get_version(), $visible, $delete, $settings);
$table->data[] = array(
'<p'.$class.'>'.$blockobject->get_title().'</p>',
$count,
$blockobject->get_version(),
$visible,
$multiple,
$delete,
$settings
);
}
echo '<p>';
print_table($table);
Expand Down
9 changes: 7 additions & 2 deletions admin/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if (!empty($USER->id)) { // Additional identity check
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
//error(get_string('confirmsesskeybad', 'error'));
}
}

Expand All @@ -38,9 +38,14 @@
// [pj] We are about to create the site, so let's add some blocks...
// calendar_month is included as a Moodle feature advertisement ;-)
require_once($CFG->dirroot.'/lib/blocklib.php');
$form->blockinfo = blocks_get_default_blocks(NULL, blocks_get_config_default('site'));

if ($newid = insert_record("course", $form)) {
// Site created, add blocks for it
$page = new stdClass;
$page->type = MOODLE_PAGE_COURSE;
$page->id = $newid;
blocks_repopulate_page($page); // Return value not checked because you can always edit later

$cat->name = get_string("miscellaneous");
if (insert_record("course_categories", $cat)) {
redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
Expand Down
7 changes: 3 additions & 4 deletions blocks/activity_modules/block_activity_modules.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?PHP //$Id$

class CourseBlock_activity_modules extends MoodleBlock {
function CourseBlock_activity_modules($course) {
function init() {
$this->title = get_string('activities');
$this->content_type = BLOCK_TYPE_LIST;
$this->course = $course;
$this->version = 2004041000;
}

Expand All @@ -18,15 +17,15 @@ function get_content() {
return $this->content;
}

$this->content = New object;
$this->content = new stdClass;
$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="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$this->course->id.'">'.$modnamesplural[$modname].'</a>';
$this->content->items[] = '<a href="'.$CFG->wwwroot.'/mod/'.$modname.'/index.php?id='.$this->instance->pageid.'">'.$modnamesplural[$modname].'</a>';
$this->content->icons[] = '<img src="'.$CFG->modpixpath.'/'.$modname.'/icon.gif" height="16" width="16" alt="" />';
}
}
Expand Down
65 changes: 33 additions & 32 deletions blocks/admin/block_admin.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php //$Id$

class CourseBlock_admin extends MoodleBlock {
function CourseBlock_admin($course) {
function init() {
$this->title = get_string('administration');
$this->content_type = BLOCK_TYPE_LIST;
$this->course = $course;
$this->version = 2004081200;
}

Expand All @@ -14,14 +13,14 @@ function get_content() {
return $this->content;
}

$this->content = New object;
$this->content = new stdClass;
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';

if (empty($this->course)) {
if (empty($this->instance)) {
$this->content = '';
} else if ($this->course->id == SITEID) {
} else if ($this->instance->pageid == SITEID) {
$this->load_content_for_site();
} else {
$this->load_content_for_course();
Expand Down Expand Up @@ -77,81 +76,83 @@ function load_content_for_course() {
return $this->content;
}

if (isteacher($this->course->id)) {
$course = get_record('course', 'id', $this->instance->pageid);

$isteacheredit = isteacheredit($this->course->id);
if (isteacher($this->instance->pageid)) {

$isteacheredit = isteacheredit($this->instance->pageid);

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>';
if (isediting($this->instance->pageid)) {
$this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&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="view.php?id='.$this->instance->pageid.'&amp;edit=on">'.get_string('turneditingon').'</a>';
}
$this->content->items[]='<a href="edit.php?id='.$this->course->id.'">'.get_string('settings').'...</a>';
$this->content->items[]='<a href="edit.php?id='.$this->instance->pageid.'">'.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');
if (iscreator() || !empty($CFG->teacherassignteachers)) {
if (!$course->teachers) {
$course->teachers = get_string('defaultcourseteachers');
}
$this->content->items[]='<a href="teacher.php?id='.$this->course->id.'">'.$this->course->teachers.'...</a>';
$this->content->items[]='<a href="teacher.php?id='.$this->instance->pageid.'">'.$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');
if (!$course->students) {
$course->students = get_string('defaultcoursestudents');
}
$this->content->items[]='<a href="student.php?id='.$this->course->id.'">'.$this->course->students.'...</a>';
$this->content->items[]='<a href="student.php?id='.$this->instance->pageid.'">'.$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->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->instance->pageid.'">'.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->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&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->items[]='<a href="scales.php?id='.$this->instance->pageid.'">'.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->items[]='<a href="grades.php?id='.$this->instance->pageid.'">'.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->items[]='<a href="log.php?id='.$this->instance->pageid.'">'.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->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'">'.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->items[]='<a href="'.$CFG->wwwroot.'/doc/view.php?id='.$this->instance->pageid.'&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')) {
if ($teacherforum = forum_get_course_forum($this->instance->pageid, '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>';
if ($course->showgrades) {
$this->content->items[]='<a href="grade.php?id='.$this->instance->pageid.'">'.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>';
if ($course->showreports) {
$this->content->items[]='<a href="user.php?id='.$this->instance->pageid.'&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->items[]='<a href="'.$CFG->wwwroot.'/login/change_password.php?id='.$this->instance->pageid.'">'.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->items[]='<a href="unenrol.php?id='.$this->instance->pageid.'">'.get_string('unenrolme', '', $course->shortname).'...</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" height="16" width="16" alt="" />';
}
}
Expand Down
Loading

0 comments on commit 9b4b78f

Please sign in to comment.