|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // Allows the admin to configure blocks (hide/show, delete and configure) 00004 00005 require_once('../config.php'); 00006 require_once($CFG->libdir.'/adminlib.php'); 00007 require_once($CFG->libdir.'/tablelib.php'); 00008 00009 admin_externalpage_setup('manageblocks'); 00010 00011 $confirm = optional_param('confirm', 0, PARAM_BOOL); 00012 $hide = optional_param('hide', 0, PARAM_INT); 00013 $show = optional_param('show', 0, PARAM_INT); 00014 $delete = optional_param('delete', 0, PARAM_INT); 00015 $unprotect = optional_param('unprotect', 0, PARAM_INT); 00016 $protect = optional_param('protect', 0, PARAM_INT); 00017 00019 00020 $strmanageblocks = get_string('manageblocks'); 00021 $strdelete = get_string('delete'); 00022 $strversion = get_string('version'); 00023 $strhide = get_string('hide'); 00024 $strshow = get_string('show'); 00025 $strsettings = get_string('settings'); 00026 $strcourses = get_string('blockinstances', 'admin'); 00027 $strname = get_string('name'); 00028 $strshowblockcourse = get_string('showblockcourse'); 00029 $strprotecthdr = get_string('blockprotect', 'admin'). $OUTPUT->help_icon('blockprotect','admin'); 00030 $strprotect = get_string('blockprotect', 'admin'); 00031 $strunprotect = get_string('blockunprotect', 'admin'); 00032 00034 00035 if (!empty($hide) && confirm_sesskey()) { 00036 if (!$block = $DB->get_record('block', array('id'=>$hide))) { 00037 print_error('blockdoesnotexist', 'error'); 00038 } 00039 $DB->set_field('block', 'visible', '0', array('id'=>$block->id)); // Hide block 00040 admin_get_root(true, false); // settings not required - only pages 00041 } 00042 00043 if (!empty($show) && confirm_sesskey() ) { 00044 if (!$block = $DB->get_record('block', array('id'=>$show))) { 00045 print_error('blockdoesnotexist', 'error'); 00046 } 00047 $DB->set_field('block', 'visible', '1', array('id'=>$block->id)); // Show block 00048 admin_get_root(true, false); // settings not required - only pages 00049 } 00050 00051 if (!isset($CFG->undeletableblocktypes) || (!is_array($CFG->undeletableblocktypes) && !is_string($CFG->undeletableblocktypes))) { 00052 $undeletableblocktypes = array('navigation', 'settings'); 00053 } else if (is_string($CFG->undeletableblocktypes)) { 00054 $undeletableblocktypes = explode(',', $CFG->undeletableblocktypes); 00055 } else { 00056 $undeletableblocktypes = $CFG->undeletableblocktypes; 00057 } 00058 00059 if (!empty($protect) && confirm_sesskey()) { 00060 if (!$block = $DB->get_record('block', array('id'=>$protect))) { 00061 print_error('blockdoesnotexist', 'error'); 00062 } 00063 if (!in_array($block->name, $undeletableblocktypes)) { 00064 $undeletableblocktypes[] = $block->name; 00065 set_config('undeletableblocktypes', implode(',', $undeletableblocktypes)); 00066 } 00067 admin_get_root(true, false); // settings not required - only pages 00068 } 00069 00070 if (!empty($unprotect) && confirm_sesskey()) { 00071 if (!$block = $DB->get_record('block', array('id'=>$unprotect))) { 00072 print_error('blockdoesnotexist', 'error'); 00073 } 00074 if (in_array($block->name, $undeletableblocktypes)) { 00075 $undeletableblocktypes = array_diff($undeletableblocktypes, array($block->name)); 00076 set_config('undeletableblocktypes', implode(',', $undeletableblocktypes)); 00077 } 00078 admin_get_root(true, false); // settings not required - only pages 00079 } 00080 00081 if (!empty($delete) && confirm_sesskey()) { 00082 echo $OUTPUT->header(); 00083 echo $OUTPUT->heading($strmanageblocks); 00084 00085 if (!$block = blocks_get_record($delete)) { 00086 print_error('blockdoesnotexist', 'error'); 00087 } 00088 00089 if (get_string_manager()->string_exists('pluginname', "block_$block->name")) { 00090 $strblockname = get_string('pluginname', "block_$block->name"); 00091 } else { 00092 $strblockname = $block->name; 00093 } 00094 00095 if (!$confirm) { 00096 echo $OUTPUT->confirm(get_string('blockdeleteconfirm', '', $strblockname), 'blocks.php?delete='.$block->id.'&confirm=1', 'blocks.php'); 00097 echo $OUTPUT->footer(); 00098 exit; 00099 00100 } else { 00101 uninstall_plugin('block', $block->name); 00102 00103 $a = new stdClass(); 00104 $a->block = $strblockname; 00105 $a->directory = $CFG->dirroot.'/blocks/'.$block->name; 00106 notice(get_string('blockdeletefiles', '', $a), 'blocks.php'); 00107 } 00108 } 00109 00110 echo $OUTPUT->header(); 00111 echo $OUTPUT->heading($strmanageblocks); 00112 00114 00116 00117 if (!$blocks = $DB->get_records('block', array(), 'name ASC')) { 00118 print_error('noblocks', 'error'); // Should never happen 00119 } 00120 00121 $incompatible = array(); 00122 00124 00125 $table = new flexible_table('admin-blocks-compatible'); 00126 00127 $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'undeletable', 'delete', 'settings')); 00128 $table->define_headers(array($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strprotecthdr, $strdelete, $strsettings)); 00129 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php'); 00130 $table->set_attribute('class', 'compatibleblockstable blockstable generaltable'); 00131 $table->setup(); 00132 $tablerows = array(); 00133 00134 foreach ($blocks as $blockid=>$block) { 00135 $blockname = $block->name; 00136 00137 if (!file_exists("$CFG->dirroot/blocks/$blockname/block_$blockname.php")) { 00138 $blockobject = false; 00139 $strblockname = '<span class="notifyproblem">'.$blockname.' ('.get_string('missingfromdisk').')</span>'; 00140 $plugin = new stdClass(); 00141 $plugin->version = $block->version; 00142 00143 } else { 00144 $plugin = new stdClass(); 00145 $plugin->version = '???'; 00146 if (file_exists("$CFG->dirroot/blocks/$blockname/version.php")) { 00147 include("$CFG->dirroot/blocks/$blockname/version.php"); 00148 } 00149 00150 if (!$blockobject = block_instance($block->name)) { 00151 $incompatible[] = $block; 00152 continue; 00153 } 00154 $strblockname = get_string('pluginname', 'block_'.$blockname); 00155 } 00156 00157 $delete = '<a href="blocks.php?delete='.$blockid.'&sesskey='.sesskey().'">'.$strdelete.'</a>'; 00158 00159 $settings = ''; // By default, no configuration 00160 if ($blockobject and $blockobject->has_config()) { 00161 $blocksettings = admin_get_root()->locate('blocksetting' . $block->name); 00162 00163 if ($blocksettings instanceof admin_externalpage) { 00164 $settings = '<a href="' . $blocksettings->url . '">' . get_string('settings') . '</a>'; 00165 } else if ($blocksettings instanceof admin_settingpage) { 00166 $settings = '<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=blocksetting'.$block->name.'">'.$strsettings.'</a>'; 00167 } else { 00168 $settings = '<a href="block.php?block='.$blockid.'">'.$strsettings.'</a>'; 00169 } 00170 } 00171 00172 // MDL-11167, blocks can be placed on mymoodle, or the blogs page 00173 // and it should not show up on course search page 00174 00175 $totalcount = $DB->count_records('block_instances', array('blockname'=>$blockname)); 00176 $count = $DB->count_records('block_instances', array('blockname'=>$blockname, 'pagetypepattern'=>'course-view-*')); 00177 00178 if ($count>0) { 00179 $blocklist = "<a href=\"{$CFG->wwwroot}/course/search.php?blocklist=$blockid&sesskey=".sesskey()."\" "; 00180 $blocklist .= "title=\"$strshowblockcourse\" >$totalcount</a>"; 00181 } 00182 else { 00183 $blocklist = "$totalcount"; 00184 } 00185 $class = ''; // Nothing fancy, by default 00186 00187 if (!$blockobject) { 00188 // ignore 00189 $visible = ''; 00190 } else if ($blocks[$blockid]->visible) { 00191 $visible = '<a href="blocks.php?hide='.$blockid.'&sesskey='.sesskey().'" title="'.$strhide.'">'. 00192 '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon" alt="'.$strhide.'" /></a>'; 00193 } else { 00194 $visible = '<a href="blocks.php?show='.$blockid.'&sesskey='.sesskey().'" title="'.$strshow.'">'. 00195 '<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon" alt="'.$strshow.'" /></a>'; 00196 $class = ' class="dimmed_text"'; // Leading space required! 00197 } 00198 00199 if ($block->version == $plugin->version) { 00200 $version = $block->version; 00201 } else { 00202 $version = "$block->version ($plugin->version)"; 00203 } 00204 00205 if (!$blockobject) { 00206 // ignore 00207 $undeletable = ''; 00208 } else if (in_array($blockname, $undeletableblocktypes)) { 00209 $undeletable = '<a href="blocks.php?unprotect='.$blockid.'&sesskey='.sesskey().'" title="'.$strunprotect.'">'. 00210 '<img src="'.$OUTPUT->pix_url('t/unlock') . '" class="icon" alt="'.$strunprotect.'" /></a>'; 00211 } else { 00212 $undeletable = '<a href="blocks.php?protect='.$blockid.'&sesskey='.sesskey().'" title="'.$strprotect.'">'. 00213 '<img src="'.$OUTPUT->pix_url('t/unlock_gray') . '" class="icon" alt="'.$strprotect.'" /></a>'; 00214 } 00215 00216 $row = array( 00217 '<span'.$class.'>'.$strblockname.'</span>', 00218 $blocklist, 00219 '<span'.$class.'>'.$version.'</span>', 00220 $visible, 00221 $undeletable, 00222 $delete, 00223 $settings 00224 ); 00225 $tablerows[] = array(strip_tags($strblockname), $row); // first element will be used for sorting 00226 } 00227 00228 collatorlib::asort($tablerows); 00229 foreach ($tablerows as $row) { 00230 $table->add_data($row[1]); 00231 } 00232 00233 $table->print_html(); 00234 00235 if (!empty($incompatible)) { 00236 echo $OUTPUT->heading(get_string('incompatibleblocks', 'blockstable', 'admin')); 00237 00238 $table = new flexible_table('admin-blocks-incompatible'); 00239 00240 $table->define_columns(array('block', 'delete')); 00241 $table->define_headers(array($strname, $strdelete)); 00242 $table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php'); 00243 00244 $table->set_attribute('class', 'incompatibleblockstable generaltable'); 00245 00246 $table->setup(); 00247 00248 foreach ($incompatible as $block) { 00249 $table->add_data(array( 00250 $block->name, 00251 '<a href="blocks.php?delete='.$block->id.'&sesskey='.sesskey().'">'.$strdelete.'</a>', 00252 )); 00253 } 00254 $table->print_html(); 00255 } 00256 00257 echo $OUTPUT->footer(); 00258 00259