]> git.mjollnir.org Git - moodle.git/commitdiff
admin page cleanup blocks (new ones!)
authorvinkmar <vinkmar>
Fri, 18 Aug 2006 08:25:02 +0000 (08:25 +0000)
committervinkmar <vinkmar>
Fri, 18 Aug 2006 08:25:02 +0000 (08:25 +0000)
blocks/admin_bookmarks/block_admin_bookmarks.php [new file with mode: 0644]
blocks/admin_bookmarks/create.php [new file with mode: 0644]
blocks/admin_bookmarks/delete.php [new file with mode: 0644]

diff --git a/blocks/admin_bookmarks/block_admin_bookmarks.php b/blocks/admin_bookmarks/block_admin_bookmarks.php
new file mode 100644 (file)
index 0000000..4d1ba9b
--- /dev/null
@@ -0,0 +1,62 @@
+<?php  // $Id$
+
+// seems to work...
+// maybe I should add some pretty icons?
+// or possibly add the ability to custom-name things?
+
+class block_admin_bookmarks extends block_base {
+
+    function init() {
+        $this->title = "Admin Bookmarks";
+        $this->version = 2006081800;
+    }
+
+    function preferred_width() {
+        return 210;
+    }
+
+    function create_item($visiblename,$link,$icon) {
+        $this->tempcontent .= '<a href="' . $link . '"><img src="' . $icon . '" border="0" alt="[item]" /> ' . $visiblename . '</a><br />' . "\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 .= '<a href="' . $CFG->wwwroot . '/admin/settings.php?section=' . $bookmark . '">' . $temp->visiblename . '</a>' . '<br />';
+                } elseif ($temp instanceof admin_externalpage) {
+                    $this->content->text .= '<a href="' . $temp->url . '">' . $temp->visiblename . '</a>' . '<br />';
+                }                
+               }
+               } else {
+                       $bookmarks = array();
+               }
+               
+        if (($section = optional_param('section','',PARAM_ALPHAEXT)) && (in_array($section, $bookmarks))) {
+            $this->content->footer = '<a href="' . $CFG->wwwroot . '/blocks/admin_bookmarks/delete.php?section=' . $section . '&returnurl=' . $CFG->wwwroot . '">unbookmark this page</a>';    
+               } elseif ($section = optional_param('section','',PARAM_ALPHAEXT)) {
+           $this->content->footer = '<a href="' . $CFG->wwwroot . '/blocks/admin_bookmarks/create.php?section=' . $section . '">bookmark this page</a>';               
+               }
+       
+           return $this->content;
+
+    }
+}
+
+?>
diff --git a/blocks/admin_bookmarks/create.php b/blocks/admin_bookmarks/create.php
new file mode 100644 (file)
index 0000000..a5ded51
--- /dev/null
@@ -0,0 +1,54 @@
+<?php // $Id$
+
+require('../../config.php');
+
+require_once($CFG->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 (file)
index 0000000..29681ab
--- /dev/null
@@ -0,0 +1,46 @@
+<?php // $Id$
+
+require('../../config.php');
+
+require_once($CFG->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