2004-04-18 23:20:53 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
// Allows the admin to configure blocks (hide/show, delete and configure)
|
|
|
|
|
|
|
|
require_once('../config.php');
|
2006-09-02 13:14:57 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2005-05-28 18:37:47 +00:00
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
2006-10-02 23:06:36 +00:00
|
|
|
|
2007-04-30 17:08:34 +00:00
|
|
|
admin_externalpage_setup('manageblocks');
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2006-03-06 10:02:59 +00:00
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
2004-10-19 21:04:28 +00:00
|
|
|
$hide = optional_param('hide', 0, PARAM_INT);
|
|
|
|
$show = optional_param('show', 0, PARAM_INT);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_INT);
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
/// Print headings
|
|
|
|
|
|
|
|
$strmanageblocks = get_string('manageblocks');
|
|
|
|
$strdelete = get_string('delete');
|
|
|
|
$strversion = get_string('version');
|
|
|
|
$strhide = get_string('hide');
|
|
|
|
$strshow = get_string('show');
|
|
|
|
$strsettings = get_string('settings');
|
2004-10-19 21:04:28 +00:00
|
|
|
$strcourses = get_string('blockinstances', 'admin');
|
2004-04-18 23:20:53 +00:00
|
|
|
$strname = get_string('name');
|
2007-02-21 11:42:48 +00:00
|
|
|
$strshowblockcourse = get_string('showblockcourse');
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
/// If data submitted, then process and store.
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (!empty($hide) && confirm_sesskey()) {
|
2008-05-30 21:16:16 +00:00
|
|
|
if (!$block = $DB->get_record('block', array('id'=>$hide))) {
|
2008-04-09 08:21:51 +00:00
|
|
|
print_error('blockdoesnotexist', 'error');
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
2008-05-30 21:16:16 +00:00
|
|
|
$DB->set_field('block', 'visible', '0', array('id'=>$block->id)); // Hide block
|
2007-12-19 17:35:20 +00:00
|
|
|
admin_get_root(true, false); // settings not required - only pages
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (!empty($show) && confirm_sesskey() ) {
|
2008-05-30 21:16:16 +00:00
|
|
|
if (!$block = $DB->get_record('block', array('id'=>$show))) {
|
2008-04-09 08:21:51 +00:00
|
|
|
print_error('blockdoesnotexist', 'error');
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
2008-05-30 21:16:16 +00:00
|
|
|
$DB->set_field('block', 'visible', '1', array('id'=>$block->id)); // Show block
|
2007-12-19 17:35:20 +00:00
|
|
|
admin_get_root(true, false); // settings not required - only pages
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (!empty($delete) && confirm_sesskey()) {
|
2007-12-19 17:35:20 +00:00
|
|
|
admin_externalpage_print_header();
|
2009-08-06 08:17:12 +00:00
|
|
|
echo $OUTPUT->heading($strmanageblocks);
|
2004-10-19 21:04:28 +00:00
|
|
|
|
|
|
|
if (!$block = blocks_get_record($delete)) {
|
2008-04-09 08:21:51 +00:00
|
|
|
print_error('blockdoesnotexist', 'error');
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
else {
|
|
|
|
$blockobject = block_instance($block->name);
|
|
|
|
$strblockname = $blockobject->get_title();
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
if (!$confirm) {
|
2009-08-20 08:39:07 +00:00
|
|
|
echo $OUTPUT->confirm(get_string('blockdeleteconfirm', '', $strblockname), 'blocks.php?delete='.$block->id.'&confirm=1', 'blocks.php');
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2004-04-18 23:20:53 +00:00
|
|
|
exit;
|
|
|
|
|
|
|
|
} else {
|
2006-07-14 11:17:46 +00:00
|
|
|
// Inform block it's about to be deleted
|
2006-07-29 09:08:56 +00:00
|
|
|
$blockobject = block_instance($block->name);
|
2006-09-03 17:46:27 +00:00
|
|
|
if ($blockobject) {
|
|
|
|
$blockobject->before_delete(); //only if we can create instance, block might have been already removed
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2006-09-03 17:46:27 +00:00
|
|
|
// First delete instances and then block
|
2009-05-07 08:55:10 +00:00
|
|
|
$instances = $DB->get_records('block_instances', array('blockname' => $block->name));
|
2004-10-19 21:04:28 +00:00
|
|
|
if(!empty($instances)) {
|
|
|
|
foreach($instances as $instance) {
|
|
|
|
blocks_delete_instance($instance);
|
|
|
|
}
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2006-09-03 17:46:27 +00:00
|
|
|
// Delete block
|
2008-05-30 21:16:16 +00:00
|
|
|
if (!$DB->delete_records('block', array('id'=>$block->id))) {
|
2009-08-18 04:28:40 +00:00
|
|
|
echo $OUTPUT->notification("Error occurred while deleting the $strblockname record from blocks table");
|
2006-09-03 17:46:27 +00:00
|
|
|
}
|
|
|
|
|
2008-01-03 15:03:32 +00:00
|
|
|
drop_plugin_tables($block->name, "$CFG->dirroot/blocks/$block->name/db/install.xml", false); // old obsoleted table names
|
|
|
|
drop_plugin_tables('block_'.$block->name, "$CFG->dirroot/blocks/$block->name/db/install.xml", false);
|
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
// Delete the capabilities that were defined by this block
|
|
|
|
capabilities_cleanup('block/'.$block->name);
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2007-05-22 10:26:29 +00:00
|
|
|
// remove entent handlers and dequeue pending events
|
|
|
|
events_uninstall('block/'.$block->name);
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
$a->block = $strblockname;
|
|
|
|
$a->directory = $CFG->dirroot.'/blocks/'.$block->name;
|
|
|
|
notice(get_string('blockdeletefiles', '', $a), 'blocks.php');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-19 17:35:20 +00:00
|
|
|
admin_externalpage_print_header();
|
2009-08-06 08:17:12 +00:00
|
|
|
echo $OUTPUT->heading($strmanageblocks);
|
2007-12-19 17:35:20 +00:00
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
/// Main display starts here
|
|
|
|
|
|
|
|
/// Get and sort the existing blocks
|
|
|
|
|
2008-05-30 21:16:16 +00:00
|
|
|
if (!$blocks = $DB->get_records('block')) {
|
2008-04-11 08:13:08 +00:00
|
|
|
print_error('noblocks', 'error'); // Should never happen
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$incompatible = array();
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
foreach ($blocks as $block) {
|
2008-05-30 21:16:16 +00:00
|
|
|
if (($blockobject = block_instance($block->name)) === false) {
|
2004-04-18 23:20:53 +00:00
|
|
|
// Failed to load
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$blockbyname[$blockobject->get_title()] = $block->id;
|
|
|
|
$blockobjects[$block->id] = $blockobject;
|
|
|
|
}
|
2004-06-25 07:01:08 +00:00
|
|
|
|
|
|
|
if(empty($blockbyname)) {
|
2008-04-11 08:13:08 +00:00
|
|
|
print_error('failtoloadblocks', 'error');
|
2004-06-25 07:01:08 +00:00
|
|
|
}
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
ksort($blockbyname);
|
|
|
|
|
|
|
|
/// Print the table of all blocks
|
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$table = new flexible_table('admin-blocks-compatible');
|
|
|
|
|
2009-07-15 08:24:12 +00:00
|
|
|
$table->define_columns(array('name', 'instances', 'version', 'hideshow', 'delete', 'settings'));
|
|
|
|
$table->define_headers(array($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strdelete, $strsettings));
|
2006-07-19 08:13:25 +00:00
|
|
|
$table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php');
|
2005-05-28 18:37:47 +00:00
|
|
|
$table->set_attribute('id', 'blocks');
|
2007-02-22 18:48:38 +00:00
|
|
|
$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
|
2005-05-28 18:37:47 +00:00
|
|
|
$table->setup();
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
foreach ($blockbyname as $blockname => $blockid) {
|
|
|
|
|
|
|
|
$blockobject = $blockobjects[$blockid];
|
2007-12-19 17:35:20 +00:00
|
|
|
$block = $blocks[$blockid];
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2009-01-02 10:36:25 +00:00
|
|
|
$delete = '<a href="blocks.php?delete='.$blockid.'&sesskey='.sesskey().'">'.$strdelete.'</a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
$settings = ''; // By default, no configuration
|
2007-12-19 17:35:20 +00:00
|
|
|
if ($blockobject->has_config()) {
|
|
|
|
if (file_exists($CFG->dirroot.'/blocks/'.$block->name.'/settings.php')) {
|
|
|
|
$settings = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=blocksetting'.$block->name.'">'.$strsettings.'</a>';
|
|
|
|
} else {
|
|
|
|
$settings = '<a href="block.php?block='.$blockid.'">'.$strsettings.'</a>';
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 07:54:30 +00:00
|
|
|
// MDL-11167, blocks can be placed on mymoodle, or the blogs page
|
|
|
|
// and it should not show up on course search page
|
2007-12-19 17:35:20 +00:00
|
|
|
|
2009-05-07 08:55:10 +00:00
|
|
|
$totalcount = $DB->count_records('block_instances', array('blockname'=>$blockname));
|
|
|
|
$count = $DB->count_records('block_instances', array('blockname'=>$blockname, 'pagetypepattern'=>'course-view-*'));
|
2007-10-26 03:25:39 +00:00
|
|
|
|
2007-02-21 11:42:48 +00:00
|
|
|
if ($count>0) {
|
2009-01-02 10:43:12 +00:00
|
|
|
$blocklist = "<a href=\"{$CFG->wwwroot}/course/search.php?blocklist=$blockid&sesskey=".sesskey()."\" ";
|
2007-10-26 03:25:39 +00:00
|
|
|
$blocklist .= "title=\"$strshowblockcourse\" >$totalcount</a>";
|
2007-02-21 11:42:48 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-10-26 03:25:39 +00:00
|
|
|
$blocklist = "$totalcount";
|
2007-02-21 11:42:48 +00:00
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
$class = ''; // Nothing fancy, by default
|
|
|
|
|
2004-04-22 07:11:55 +00:00
|
|
|
if ($blocks[$blockid]->visible) {
|
2009-01-02 10:36:25 +00:00
|
|
|
$visible = '<a href="blocks.php?hide='.$blockid.'&sesskey='.sesskey().'" title="'.$strhide.'">'.
|
2009-07-02 10:53:31 +00:00
|
|
|
'<img src="'.$OUTPUT->old_icon_url('i/hide') . '" class="icon" alt="'.$strhide.'" /></a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
} else {
|
2009-01-02 10:36:25 +00:00
|
|
|
$visible = '<a href="blocks.php?show='.$blockid.'&sesskey='.sesskey().'" title="'.$strshow.'">'.
|
2009-07-02 10:53:31 +00:00
|
|
|
'<img src="'.$OUTPUT->old_icon_url('i/show') . '" class="icon" alt="'.$strshow.'" /></a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
$class = ' class="dimmed_text"'; // Leading space required!
|
|
|
|
}
|
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$table->add_data(array(
|
2005-02-08 14:49:57 +00:00
|
|
|
'<span'.$class.'>'.$blockobject->get_title().'</span>',
|
2007-02-21 11:42:48 +00:00
|
|
|
$blocklist,
|
2007-02-21 16:52:32 +00:00
|
|
|
'<span'.$class.'>'.$blockobject->get_version().'</span>',
|
2004-10-19 21:04:28 +00:00
|
|
|
$visible,
|
|
|
|
$delete,
|
|
|
|
$settings
|
2005-05-28 18:37:47 +00:00
|
|
|
));
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
2005-02-08 14:49:57 +00:00
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$table->print_html();
|
|
|
|
|
|
|
|
if(!empty($incompatible)) {
|
2009-08-06 08:17:12 +00:00
|
|
|
echo $OUTPUT->heading(get_string('incompatibleblocks', 'admin'));
|
2005-05-28 18:37:47 +00:00
|
|
|
|
|
|
|
$table = new flexible_table('admin-blocks-incompatible');
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$table->define_columns(array('block', 'delete'));
|
|
|
|
$table->define_headers(array($strname, $strdelete));
|
2006-07-19 08:13:25 +00:00
|
|
|
$table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php');
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$table->set_attribute('id', 'incompatible');
|
2007-02-22 18:48:38 +00:00
|
|
|
$table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide');
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$table->setup();
|
|
|
|
|
|
|
|
foreach ($incompatible as $block) {
|
|
|
|
$table->add_data(array(
|
|
|
|
$block->name,
|
2009-01-02 10:36:25 +00:00
|
|
|
'<a href="blocks.php?delete='.$block->id.'&sesskey='.sesskey().'">'.$strdelete.'</a>',
|
2005-05-28 18:37:47 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
$table->print_html();
|
|
|
|
}
|
2005-02-08 14:49:57 +00:00
|
|
|
|
2009-08-06 14:12:46 +00:00
|
|
|
echo $OUTPUT->footer();
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
?>
|