From bb14a9e3b7b8b1d4c86489bb7da7747cc637784c Mon Sep 17 00:00:00 2001 From: vinkmar Date: Fri, 18 Aug 2006 08:25:02 +0000 Subject: [PATCH] admin page cleanup blocks (new ones!) --- .../admin_bookmarks/block_admin_bookmarks.php | 62 +++++++++++++++++++ blocks/admin_bookmarks/create.php | 54 ++++++++++++++++ blocks/admin_bookmarks/delete.php | 46 ++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 blocks/admin_bookmarks/block_admin_bookmarks.php create mode 100644 blocks/admin_bookmarks/create.php create mode 100644 blocks/admin_bookmarks/delete.php diff --git a/blocks/admin_bookmarks/block_admin_bookmarks.php b/blocks/admin_bookmarks/block_admin_bookmarks.php new file mode 100644 index 0000000000..4d1ba9b17c --- /dev/null +++ b/blocks/admin_bookmarks/block_admin_bookmarks.php @@ -0,0 +1,62 @@ +title = "Admin Bookmarks"; + $this->version = 2006081800; + } + + function preferred_width() { + return 210; + } + + function create_item($visiblename,$link,$icon) { + $this->tempcontent .= '[item] ' . $visiblename . '
' . "\n"; + } + + function get_content() { + + global $CFG, $USER, $ADMIN; + + if (!$ADMIN) { + require_once($CFG->dirroot . '/admin/adminlib.php'); + } + + if ($this->content !== NULL) { + return $this->content; + } + + $this->content = new stdClass; + if ($USER->preference['admin_bookmarks']) { + $bookmarks = explode(',',$USER->preference['admin_bookmarks']); + // hmm... just a liiitle (potentially) processor-intensive + // (recall that $ADMIN->locate is a huge recursive call... and we're calling it repeatedly here + foreach($bookmarks as $bookmark) { + $temp = $ADMIN->locate($bookmark); + if ($temp instanceof admin_settingpage) { + $this->content->text .= '' . $temp->visiblename . '' . '
'; + } elseif ($temp instanceof admin_externalpage) { + $this->content->text .= '' . $temp->visiblename . '' . '
'; + } + } + } else { + $bookmarks = array(); + } + + if (($section = optional_param('section','',PARAM_ALPHAEXT)) && (in_array($section, $bookmarks))) { + $this->content->footer = 'unbookmark this page'; + } elseif ($section = optional_param('section','',PARAM_ALPHAEXT)) { + $this->content->footer = 'bookmark this page'; + } + + return $this->content; + + } +} + +?> diff --git a/blocks/admin_bookmarks/create.php b/blocks/admin_bookmarks/create.php new file mode 100644 index 0000000000..a5ded51817 --- /dev/null +++ b/blocks/admin_bookmarks/create.php @@ -0,0 +1,54 @@ +dirroot . '/admin/adminlib.php'); + +if ($section = optional_param('section', '', PARAM_ALPHAEXT)) { + + if ($USER->preference['admin_bookmarks']) { + $bookmarks = explode(',',$USER->preference['admin_bookmarks']); + + if (in_array($section, $bookmarks)) { + error('Bookmark already exists.'); + die; + } + + } else { + $bookmarks = array(); + } + + $temp = $ADMIN->locate($section); + + if ($temp instanceof admin_settingpage || $temp instanceof admin_externalpage) { + + $bookmarks[] = $section; + + $bookmarks = implode(',',$bookmarks); + + set_user_preference('admin_bookmarks', $bookmarks); + + } else { + + error('Invalid section.'); + die; + + } + + if ($temp instanceof admin_settingpage) { + + redirect("$CFG->wwwroot/admin/settings.php?section=" . $section, 'Bookmark added.',1); + + } elseif ($temp instanceof admin_externalpage) { + + redirect($temp->url, 'Bookmark added.', 1); + + } + +} else { + error('Valid section not specified.'); + die; +} + + +?> \ No newline at end of file diff --git a/blocks/admin_bookmarks/delete.php b/blocks/admin_bookmarks/delete.php new file mode 100644 index 0000000000..29681ab8ca --- /dev/null +++ b/blocks/admin_bookmarks/delete.php @@ -0,0 +1,46 @@ +dirroot . '/admin/adminlib.php'); + +if ($section = optional_param('section', '', PARAM_ALPHAEXT)) { + + if ($USER->preference['admin_bookmarks']) { + + $bookmarks = explode(',', $USER->preference['admin_bookmarks']); + + $key = array_search($section, $bookmarks); + + if ($key === false) { + error('Bookmark doesn\'t exist.'); + die; + } + + unset($bookmarks[$key]); + $bookmarks = implode(',',$bookmarks); + set_user_preference('admin_bookmarks', $bookmarks); + + $temp = $ADMIN->locate($section); + + if ($temp instanceof admin_externalpage) { + redirect($temp->url, 'Bookmark deleted.',1); + } elseif ($temp instanceof admin_settingpage) { + redirect($CFG->wwwroot . '/admin/settings.php?section=' . $section, 'Bookmark deleted.',1); + } else { + redirect($CFG->wwwroot, 'Bookmark deleted.',1); + } + die; + + + } + + error('No bookmarks found for current user.'); + die; + +} else { + error('Valid section not specified.'); + die; +} + +?> \ No newline at end of file -- 2.39.5