Skip to content

Commit

Permalink
fixes for new admin blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 2, 2006
1 parent 623942a commit 02cc05a
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 40 deletions.
14 changes: 12 additions & 2 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
/// Set up the blank site - to be customized later at the end of install.
if (! $site = get_site()) {
// We are about to create the site "course"
require_once($CFG->dirroot.'/lib/blocklib.php');
require_once($CFG->libdir.'/blocklib.php');

$newsite = new Object();
$newsite->fullname = "";
Expand Down Expand Up @@ -358,6 +358,16 @@
}
}

// initialise default blocks on admin page if needed
if (empty($CFG->adminblocks_initialised)) {
require_once("$CFG->dirroot/$CFG->admin/pagelib.php");
require_once($CFG->libdir.'/blocklib.php');
page_map_class(PAGE_ADMIN, 'page_admin');
$page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
blocks_repopulate_page($page);
set_config('adminblocks_initialised', 1);
}

/// Define the unique site ID code if it isn't already
if (empty($CFG->siteidentifier)) { // Unique site identification code
set_config('siteidentifier', random_string(32));
Expand Down Expand Up @@ -612,4 +622,4 @@



?>
?>
11 changes: 7 additions & 4 deletions admin/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once($CFG->libdir.'/pagelib.php');

define('PAGE_ADMIN', 'admin-index');
define('PAGE_ADMIN', 'admin');

page_map_class(PAGE_ADMIN, 'page_admin');

Expand All @@ -12,7 +12,10 @@ class page_admin extends page_base {
var $pathtosection;
var $visiblepathtosection;

function init_full($section) {
// hack alert!
// this function works around the inability to store the section name
// in default block, maybe we should "improve" the blocks a bit?
function init_extra($section) {
global $CFG;

if($this->full_init_done) {
Expand All @@ -39,9 +42,9 @@ function init_full($section) {
// all done
$this->full_init_done = true;
}

function blocks_get_default() {
return 'admin_2,admin_bookmarks';
return 'admin_tree,admin_bookmarks';
}

// seems reasonable that the only people that can edit blocks on the admin pages
Expand Down
14 changes: 5 additions & 9 deletions admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@

require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir . '/blocklib.php');
require_once($CFG->dirroot . '/admin/pagelib.php');
require_once($CFG->libdir.'/blocklib.php');
require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php');

if ($site = get_site()) {
require_login();
}

define('TEMPORARY_ADMIN_PAGE_ID',26);

define('BLOCK_L_MIN_WIDTH',160);
define('BLOCK_L_MAX_WIDTH',210);

$pagetype = PAGE_ADMIN;
$pageclass = 'page_admin';
page_map_class($pagetype, $pageclass);
page_map_class(PAGE_ADMIN, 'page_admin');

$PAGE = page_create_object($pagetype,TEMPORARY_ADMIN_PAGE_ID);
$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be some id number

$section = optional_param('section', '', PARAM_ALPHAEXT);

$PAGE->init_full($section);
$PAGE->init_extra($section); // hack alert!

$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
$return = optional_param('return','', PARAM_ALPHA);
Expand Down
2 changes: 1 addition & 1 deletion blocks/activity_modules/block_activity_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function get_content() {
}

function applicable_formats() {
return array('all' => true, 'mod' => false, 'my' => false);
return array('all' => true, 'mod' => false, 'my' => false, 'admin' => false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/admin/block_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function load_content_for_course() {
}

function applicable_formats() {
return array('all' => true, 'mod' => false, 'my' => false);
return array('all' => true, 'mod' => false, 'my' => false, 'admin' => false);
}
}

Expand Down
8 changes: 6 additions & 2 deletions blocks/admin_bookmarks/block_admin_bookmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
class block_admin_bookmarks extends block_base {

function init() {
$this->title = "Admin Bookmarks";
$this->version = 2006081800;
$this->title = get_string('adminbookmarks');
$this->version = 2006090300;
}

function applicable_formats() {
return array('site' => true, 'admin' => true);
}

function preferred_width() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php // $Id$

class block_admin_2 extends block_base {
class block_admin_tree extends block_base {

var $currentdepth;
var $spancounter;
Expand All @@ -11,8 +11,8 @@ class block_admin_2 extends block_base {

function init() {
global $PAGE;
$this->title = "Administration (Beta)";
$this->version = 2006081800;
$this->title = get_string('admintree');
$this->version = 2006090300;
$this->currentdepth = 0;
$this->spancounter = 1;
$this->tempcontent = '';
Expand All @@ -21,6 +21,10 @@ function init() {
$this->expandjavascript = '';
}

function applicable_formats() {
return array('site' => true, 'admin' => true);
}

function preferred_width() {
return 210;
}
Expand All @@ -31,7 +35,7 @@ function open_folder($visiblename) {
$this->tempcontent .= "&nbsp;&nbsp;&nbsp;";
}
$this->tempcontent .= '<a href="javascript:toggle(\'vh_span' . $this->spancounter . '\');">';
$this->tempcontent .= '<span id="vh_span' . $this->spancounter . 'indicator"><img src="' . $CFG->wwwroot . '/blocks/admin_2/open.gif" border="0" alt="[open folder]" /></span> ';
$this->tempcontent .= '<span id="vh_span' . $this->spancounter . 'indicator"><img src="' . $CFG->wwwroot . '/blocks/admin_tree/open.gif" border="0" alt="[open folder]" /></span> ';
$this->tempcontent .= $visiblename . '</a><br /><span id="vh_span' . $this->spancounter . '">' . "\n";
$this->currentdepth++;
$this->spancounter++;
Expand All @@ -54,11 +58,11 @@ function build_tree (&$content) {
global $CFG;
if (is_a($content, 'admin_settingpage')) {
if ($content->check_access()) {
$this->create_item($content->visiblename,$CFG->wwwroot.'/admin/settings.php?section=' . $content->name,$CFG->wwwroot .'/blocks/admin_2/item.gif');
$this->create_item($content->visiblename,$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=' . $content->name,$CFG->wwwroot .'/blocks/admin_tree/item.gif');
}
} else if (is_a($content, 'admin_externalpage')) {
if ($content->check_access()) {
$this->create_item($content->visiblename, $content->url, $CFG->wwwroot . '/blocks/admin_2/item.gif');
$this->create_item($content->visiblename, $content->url, $CFG->wwwroot . '/blocks/admin_tree/item.gif');
}
} else if (is_a($content, 'admin_category')) {
if ($content->check_access()) {
Expand Down Expand Up @@ -131,25 +135,25 @@ function get_content() {
$this->content->text .= 'function toggle(spanid) {' . "\n";
$this->content->text .= ' if (getspan(spanid).innerHTML == "") {' . "\n";
$this->content->text .= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_2/open.gif\" border=\"0\" alt=\"[open folder]\" />";' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_tree/open.gif\" border=\"0\" alt=\"[open folder]\" />";' . "\n";
$this->content->text .= ' } else {' . "\n";
$this->content->text .= ' vh_content[spanid] = getspan(spanid).innerHTML;' . "\n";
$this->content->text .= ' getspan(spanid).innerHTML = "";' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_2/closed.gif\" border=\"0\" alt=\"[closed folder]\" />";' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_tree/closed.gif\" border=\"0\" alt=\"[closed folder]\" />";' . "\n";
$this->content->text .= ' }' . "\n";
$this->content->text .= '}' . "\n";

$this->content->text .= 'function collapse(spanid) {' . "\n";
$this->content->text .= ' if (getspan(spanid).innerHTML !== "") {' . "\n";
$this->content->text .= ' vh_content[spanid] = getspan(spanid).innerHTML;' . "\n";
$this->content->text .= ' getspan(spanid).innerHTML = "";' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_2/closed.gif\" border=\"0\" alt=\"[closed folder]\" />";' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_tree/closed.gif\" border=\"0\" alt=\"[closed folder]\" />";' . "\n";
$this->content->text .= ' }' . "\n";
$this->content->text .= '}' . "\n";

$this->content->text .= 'function expand(spanid) {' . "\n";
$this->content->text .= ' getspan(spanid).innerHTML = vh_content[spanid];' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_2/open.gif\" border=\"0\" alt=\"[open folder]\" />";' . "\n";
$this->content->text .= ' getspan(spanid + "indicator").innerHTML = "<img src=\"' . $CFG->wwwroot . '/blocks/admin_tree/open.gif\" border=\"0\" alt=\"[open folder]\" />";' . "\n";
$this->content->text .= '}' . "\n";

$this->content->text .= 'function expandall() {' . "\n";
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
8 changes: 6 additions & 2 deletions blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function _title_html() {
*/
function _add_edit_controls($options) {

global $CFG, $USER;
global $CFG, $USER, $PAGE;

// this is the context relevant to this particular block instance
$blockcontext = get_context_instance(CONTEXT_BLOCK, $this->instance->id);
Expand Down Expand Up @@ -340,7 +340,11 @@ function _add_edit_controls($options) {
if (empty($this->instance->pageid)) {
$this->instance->pageid = 0;
}
$page = page_create_object($this->instance->pagetype, $this->instance->pageid);
if (!empty($PAGE->type) and ($this->instance->pagetype == $PAGE->type) and $this->instance->pageid == $PAGE->id) {
$page = $PAGE;
} else {
$page = page_create_object($this->instance->pagetype, $this->instance->pageid);
}
$script = $page->url_get_full(array('instanceid' => $this->instance->id, 'sesskey' => $USER->sesskey));

// place holder for roles button
Expand Down
12 changes: 4 additions & 8 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2181,20 +2181,16 @@ function admin_externalpage_setup($section, $adminroot) {
global $CFG, $PAGE, $USER;

require_once($CFG->libdir . '/blocklib.php');
require_once($CFG->dirroot . '/admin/pagelib.php');
require_once($CFG->dirroot . '/'.$CFG->admin.'/pagelib.php');

define('TEMPORARY_ADMIN_PAGE_ID',26);

define('BLOCK_L_MIN_WIDTH',160);
define('BLOCK_L_MAX_WIDTH',210);

$pagetype = PAGE_ADMIN;
$pageclass = 'page_admin';
page_map_class($pagetype, $pageclass);
page_map_class(PAGE_ADMIN, 'page_admin');

$PAGE = page_create_object($pagetype,TEMPORARY_ADMIN_PAGE_ID);
$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be some id number

$PAGE->init_full($section);
$PAGE->init_extra($section); // hack alert!

$root = $adminroot->locate($PAGE->section);

Expand Down
2 changes: 1 addition & 1 deletion lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid,

// You can use this to get the blocks to respond to URL actions without much hassle
function blocks_execute_url_action(&$PAGE, &$pageblocks,$pinned=false) {
$blockaction = optional_param('blockaction');
$blockaction = optional_param('blockaction', '', PARAM_ALPHA);

if (empty($blockaction) || !$PAGE->user_allowed_editing() || !confirm_sesskey()) {
return;
Expand Down

0 comments on commit 02cc05a

Please sign in to comment.