1<?php
2// must be run within Dokuwiki
3if(!defined('DOKU_INC')) die();
4
5if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
6require_once(DOKU_PLUGIN.'admin.php');
7        //error_reporting(E_ALL);
8       //ini_set('display_errors',true);
9
10/**
11 * All DokuWiki plugins to extend the admin function
12 * need to inherit from this class
13 */
14class admin_plugin_botbouncer_clean extends DokuWiki_Admin_Plugin {
15    var $_auth = null;        // auth object
16    var $_user_total = 0;     // number of registered users
17    var $_filter = array();   // user selection filter(s)
18    var $_start = 0;          // index of first user to be displayed
19    var $_last = 0;           // index of the last user to be displayed
20    var $_pagesize = 50;      // number of users to list on one page
21    var $_edit_user = '';     // set to user selected for editing
22    var $_edit_userdata = array();
23    var $_disabled = '';      // if disabled set to explanatory string
24
25    function __construct() {
26        global $auth;
27
28        $this->setupLocale();
29
30        if (!isset($auth)) {
31          $this->disabled = $this->lang['noauth'];
32        } else if (!$auth->canDo('getUsers')) {
33          $this->disabled = $this->lang['nosupport'];
34        } else {
35
36          // we're good to go
37          $this->_auth = & $auth;
38
39        }
40    }
41
42
43    /**
44     * return some info
45     */
46    function getInfo() {
47        return confToHash(dirname(__FILE__).'/../plugin.info.txt');
48    }
49
50    /**
51     * Access for managers allowed
52     */
53    function forAdminOnly() {
54        return false;
55    }
56
57    /**
58     * return sort order for position in admin menu
59     */
60    function getMenuSort() {
61        return 150;
62    }
63
64    function getMenuText($language) {
65        return $this->getLang('menu_clean');
66    }
67
68    /**
69     * handle user request
70     *
71     * some stuff taken from the usermanager plugin
72     * @@TODO, finish
73     *
74     */
75    function handle() {
76//        error_reporting(E_ALL);
77//        ini_set('display_errors','on');
78        global $INPUT;
79        if (is_null($this->_auth)) return false;
80
81        // extract the command and any specific parameters
82        // submit button name is of the form - fn[cmd][param(s)]
83        $fn   = $INPUT->param('fn');
84
85        if (is_array($fn)) {
86            $cmd = key($fn);
87            $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null;
88        } else {
89            $cmd = $fn;
90            $param = null;
91        }
92
93        if ($cmd != "search") {
94          $this->_start = $INPUT->int('start', 0);
95          $this->_filter = $this->_retrieveFilter();
96        }
97
98        switch($cmd){
99          case "add"    : $this->_addUser(); break;
100          case "delete" : $this->_deleteUser(); break;
101          case "modify" : $this->_modifyUser(); break;
102          case "edit"   : $this->_editUser($param); break;
103          case "search" : $this->_setFilter($param);
104                          $this->_start = 0;
105                          break;
106        }
107
108        $this->_user_total = $this->_auth->canDo('getUserCount') ? $this->_auth->getUserCount($this->_filter) : -1;
109
110        // page handling
111        switch($cmd){
112          case 'start' : $this->_start = 0; break;
113          case 'prev'  : $this->_start -= $this->_pagesize; break;
114          case 'next'  : $this->_start += $this->_pagesize; break;
115          case 'last'  : $this->_start = $this->_user_total; break;
116        }
117        $this->_validatePagination();
118    }
119
120    /**
121     * output appropriate html
122     */
123    function html() {
124        print $this->locale_xhtml('clean');
125
126        $user_list = $this->_auth->retrieveUsers($this->_start, $this->_pagesize, $this->_filter);
127        $users = array_keys($user_list);
128
129   #     var_dump($user_list);
130    }
131
132    function _validatePagination() {
133
134        if ($this->_start >= $this->_user_total) {
135          $this->_start = $this->_user_total - $this->_pagesize;
136        }
137        if ($this->_start < 0) $this->_start = 0;
138
139        $this->_last = min($this->_user_total, $this->_start + $this->_pagesize);
140    }
141
142    function _retrieveFilter() {
143        global $INPUT;
144
145        $t_filter = $INPUT->arr('filter');
146
147        // messy, but this way we ensure we aren't getting any additional crap from malicious users
148        $filter = array();
149
150        if (isset($t_filter['user'])) $filter['user'] = $t_filter['user'];
151        if (isset($t_filter['name'])) $filter['name'] = $t_filter['name'];
152        if (isset($t_filter['mail'])) $filter['mail'] = $t_filter['mail'];
153        if (isset($t_filter['grps'])) $filter['grps'] = $t_filter['grps'];
154
155        return $filter;
156    }
157
158}
159//Setup VIM: ex: et ts=4 :
160