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');
|
2004-04-18 23:20:53 +00:00
|
|
|
require_once($CFG->libdir.'/blocklib.php');
|
2005-05-28 18:37:47 +00:00
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
2006-10-02 23:06:36 +00:00
|
|
|
require_once($CFG->libdir.'/ddllib.php');
|
|
|
|
|
2006-09-15 09:04:23 +00:00
|
|
|
$adminroot = admin_get_root();
|
|
|
|
admin_externalpage_setup('manageblocks', $adminroot);
|
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);
|
|
|
|
$multiple = optional_param('multiple', 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');
|
2004-10-19 21:04:28 +00:00
|
|
|
$strmultiple = get_string('blockmultiple', 'admin');
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2006-09-02 13:14:57 +00:00
|
|
|
admin_externalpage_print_header($adminroot);
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
print_heading($strmanageblocks);
|
|
|
|
|
|
|
|
/// If data submitted, then process and store.
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (!empty($hide) && confirm_sesskey()) {
|
|
|
|
if (!$block = get_record('block', 'id', $hide)) {
|
2004-04-18 23:20:53 +00:00
|
|
|
error("Block doesn't exist!");
|
|
|
|
}
|
2004-10-19 21:04:28 +00:00
|
|
|
set_field('block', 'visible', '0', 'id', $block->id); // Hide block
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (!empty($show) && confirm_sesskey() ) {
|
|
|
|
if (!$block = get_record('block', 'id', $show)) {
|
2004-04-18 23:20:53 +00:00
|
|
|
error("Block doesn't exist!");
|
|
|
|
}
|
2004-10-19 21:04:28 +00:00
|
|
|
set_field('block', 'visible', '1', 'id', $block->id); // Show block
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (!empty($multiple) && confirm_sesskey()) {
|
|
|
|
if (!$block = blocks_get_record($multiple)) {
|
|
|
|
error("Block doesn't exist!");
|
|
|
|
}
|
|
|
|
$block->multiple = !$block->multiple;
|
|
|
|
update_record('block', $block);
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (!empty($delete) && confirm_sesskey()) {
|
|
|
|
|
|
|
|
if (!$block = blocks_get_record($delete)) {
|
2004-04-18 23:20:53 +00:00
|
|
|
error("Block doesn't exist!");
|
|
|
|
}
|
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
if (!block_is_compatible($block->name)) {
|
|
|
|
$strblockname = $block->name;
|
|
|
|
}
|
|
|
|
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) {
|
2004-04-18 23:20:53 +00:00
|
|
|
notice_yesno(get_string('blockdeleteconfirm', '', $strblockname),
|
2005-05-28 18:37:47 +00:00
|
|
|
'blocks.php?delete='.$block->id.'&confirm=1&sesskey='.$USER->sesskey,
|
2004-04-18 23:20:53 +00:00
|
|
|
'blocks.php');
|
2006-09-02 13:14:57 +00:00
|
|
|
admin_externalpage_print_footer($adminroot);
|
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
|
2004-10-19 21:04:28 +00:00
|
|
|
$instances = get_records('block_instance', 'blockid', $block->id);
|
|
|
|
if(!empty($instances)) {
|
|
|
|
foreach($instances as $instance) {
|
|
|
|
blocks_delete_instance($instance);
|
2006-09-03 17:46:27 +00:00
|
|
|
blocks_delete_instance($instance, true);
|
2004-10-19 21:04:28 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
2006-09-03 17:46:27 +00:00
|
|
|
// Delete block
|
|
|
|
if (!delete_records('block', 'id', $block->id)) {
|
|
|
|
notify("Error occurred while deleting the $strblockname record from blocks table");
|
|
|
|
}
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
// Then the tables themselves
|
|
|
|
if ($tables = $db->Metatables()) {
|
|
|
|
$prefix = $CFG->prefix.$block->name;
|
2006-10-02 23:06:36 +00:00
|
|
|
$prefix2 = $CFG->prefix.'block_'.$block->name;
|
2004-04-18 23:20:53 +00:00
|
|
|
foreach ($tables as $table) {
|
2006-10-02 23:06:36 +00:00
|
|
|
if (strpos($table, $prefix) === 0 || strpos($table, $prefix2) === 0) {
|
|
|
|
/// If the match has been due to the 1st condition, debug to developers
|
|
|
|
if (strpos($table, $prefix) === 0) {
|
|
|
|
debugging('This block has some wrongly named tables. See Moodle Docs coding guidelines (and MDL-6786)', DEBUG_DEVELOPER);
|
|
|
|
}
|
|
|
|
/// Strip prefix from $table
|
|
|
|
$table = preg_replace("/^{$CFG->prefix}/", '', $table);
|
|
|
|
$xmldb_table = new XMLDBTable($table);
|
|
|
|
if (!drop_table($xmldb_table, true, false)) {
|
2004-04-18 23:20:53 +00:00
|
|
|
notify("ERROR: while trying to drop table $table");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
$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
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
if (false === ($blocks = get_records('block'))) {
|
2004-04-18 23:20:53 +00:00
|
|
|
error('No blocks found!'); // Should never happen
|
|
|
|
}
|
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$incompatible = array();
|
|
|
|
|
2004-04-18 23:20:53 +00:00
|
|
|
foreach ($blocks as $block) {
|
2005-04-30 03:22:59 +00:00
|
|
|
if(!block_is_compatible($block->name)) {
|
2006-09-19 22:14:57 +00:00
|
|
|
notify('Block '. $block->name .' is not compatible with the current version of Moodle and needs to be updated by a programmer.');
|
2005-05-28 18:37:47 +00:00
|
|
|
$incompatible[] = $block;
|
2005-04-30 03:22:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-10-19 21:04:28 +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)) {
|
|
|
|
error('One or more blocks are registered in the database, but they all failed to load!');
|
|
|
|
}
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
$table->define_columns(array('name', 'instances', 'version', 'hideshow', 'multiple', 'delete', 'settings'));
|
|
|
|
$table->define_headers(array($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strmultiple, $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('cellspacing', '0');
|
|
|
|
$table->set_attribute('id', 'blocks');
|
|
|
|
$table->set_attribute('class', 'generaltable generalbox');
|
|
|
|
|
|
|
|
$table->setup();
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
foreach ($blockbyname as $blockname => $blockid) {
|
|
|
|
|
|
|
|
$blockobject = $blockobjects[$blockid];
|
|
|
|
|
2005-05-28 18:37:47 +00:00
|
|
|
$delete = '<a href="blocks.php?delete='.$blockid.'&sesskey='.$USER->sesskey.'">'.$strdelete.'</a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
$settings = ''; // By default, no configuration
|
|
|
|
if($blockobject->has_config()) {
|
2005-01-22 19:53:28 +00:00
|
|
|
$settings = '<a href="block.php?block='.$blockid.'">'.$strsettings.'</a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
2004-10-19 21:04:28 +00:00
|
|
|
$count = count_records('block_instance', 'blockid', $blockid);
|
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) {
|
2005-05-28 18:37:47 +00:00
|
|
|
$visible = '<a href="blocks.php?hide='.$blockid.'&sesskey='.$USER->sesskey.'" title="'.$strhide.'">'.
|
2007-01-08 09:14:05 +00:00
|
|
|
'<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon" alt="'.$strhide.'" /></a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
} else {
|
2005-05-28 18:37:47 +00:00
|
|
|
$visible = '<a href="blocks.php?show='.$blockid.'&sesskey='.$USER->sesskey.'" title="'.$strshow.'">'.
|
2007-01-08 09:14:05 +00:00
|
|
|
'<img src="'.$CFG->pixpath.'/i/show.gif" class="icon" alt="'.$strshow.'" /></a>';
|
2004-04-18 23:20:53 +00:00
|
|
|
$class = ' class="dimmed_text"'; // Leading space required!
|
|
|
|
}
|
2004-10-19 21:04:28 +00:00
|
|
|
if ($blockobject->instance_allow_multiple()) {
|
|
|
|
if($blocks[$blockid]->multiple) {
|
2005-05-28 18:37:47 +00:00
|
|
|
$multiple = '<span style="white-space: nowrap;">'.get_string('yes').' (<a href="blocks.php?multiple='.$blockid.'&sesskey='.$USER->sesskey.'">'.get_string('change', 'admin').'</a>)</span>';
|
2004-10-19 21:04:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-05-28 18:37:47 +00:00
|
|
|
$multiple = '<span style="white-space: nowrap;">'.get_string('no').' (<a href="blocks.php?multiple='.$blockid.'&sesskey='.$USER->sesskey.'">'.get_string('change', 'admin').'</a>)</span>';
|
2004-10-19 21:04:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$multiple = '';
|
|
|
|
}
|
2004-04-18 23:20:53 +00:00
|
|
|
|
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>',
|
2004-10-19 21:04:28 +00:00
|
|
|
$count,
|
|
|
|
$blockobject->get_version(),
|
|
|
|
$visible,
|
|
|
|
$multiple,
|
|
|
|
$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)) {
|
|
|
|
print_heading(get_string('incompatibleblocks', 'admin'));
|
|
|
|
|
|
|
|
$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('cellspacing', '0');
|
|
|
|
$table->set_attribute('id', 'incompatible');
|
|
|
|
$table->set_attribute('class', 'generaltable generalbox');
|
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,
|
|
|
|
'<a href="blocks.php?delete='.$block->id.'&sesskey='.$USER->sesskey.'">'.$strdelete.'</a>',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
$table->print_html();
|
|
|
|
}
|
2005-02-08 14:49:57 +00:00
|
|
|
|
2006-09-02 13:14:57 +00:00
|
|
|
admin_externalpage_print_footer($adminroot);
|
2004-04-18 23:20:53 +00:00
|
|
|
|
|
|
|
?>
|