1163ac707SMichael Wilmes<?php 2*f62d0e33SAndreas Gohr 3*f62d0e33SAndreas Gohruse dokuwiki\Form\Form; 4*f62d0e33SAndreas Gohruse dokuwiki\plugin\twofactor\Manager; 5*f62d0e33SAndreas Gohr 6*f62d0e33SAndreas Gohr/** 7163ac707SMichael Wilmes * Twofactor Manager 8163ac707SMichael Wilmes * 9163ac707SMichael Wilmes * Dokuwiki Admin Plugin 10163ac707SMichael Wilmes * Special thanks to the useradmin extension as a starting point for this class 11163ac707SMichael Wilmes * 12163ac707SMichael Wilmes * @author Mike Wilmes <mwilmes@avc.edu> 13163ac707SMichael Wilmes */ 14d0a31016SAndreas Gohrclass admin_plugin_twofactor extends DokuWiki_Admin_Plugin 15d0a31016SAndreas Gohr{ 16*f62d0e33SAndreas Gohr protected $userList = array(); // list of users with attributes 17*f62d0e33SAndreas Gohr protected $filter = array(); // user selection filter(s) 18*f62d0e33SAndreas Gohr protected $start = 0; // index of first user to be displayed 19*f62d0e33SAndreas Gohr protected $last = 0; // index of the last user to be displayed 20*f62d0e33SAndreas Gohr protected $pagesize = 20; // number of users to list on one page 21*f62d0e33SAndreas Gohr protected $disabled = ''; // if disabled set to explanatory string 22*f62d0e33SAndreas Gohr protected $lastdisabled = false; // set to true if last user is unknown and last button is hence buggy 23*f62d0e33SAndreas Gohr 24*f62d0e33SAndreas Gohr /** @var helper_plugin_attribute */ 25*f62d0e33SAndreas Gohr protected $attribute; 26163ac707SMichael Wilmes 27163ac707SMichael Wilmes /** 28163ac707SMichael Wilmes * Constructor 29163ac707SMichael Wilmes */ 30d0a31016SAndreas Gohr public function __construct() 31d0a31016SAndreas Gohr { 32*f62d0e33SAndreas Gohr if (!(Manager::getInstance())->isReady()) return; 33*f62d0e33SAndreas Gohr $this->attribute = plugin_load('helper', 'attribute'); 34*f62d0e33SAndreas Gohr $this->userList = $this->attribute->enumerateUsers('twofactor'); 35163ac707SMichael Wilmes } 362cc41bddSMichael Wilmes 37*f62d0e33SAndreas Gohr /** @inheritdoc */ 38d0a31016SAndreas Gohr public function handle() 39d0a31016SAndreas Gohr { 40163ac707SMichael Wilmes global $INPUT, $INFO; 41163ac707SMichael Wilmes if (!$INFO['isadmin']) return false; 42*f62d0e33SAndreas Gohr if ($this->disabled) { 43b71db9c8SMichael Wilmes // If disabled, don't process anything. 44b71db9c8SMichael Wilmes return true; 45b71db9c8SMichael Wilmes } 46163ac707SMichael Wilmes 47163ac707SMichael Wilmes // extract the command and any specific parameters 48163ac707SMichael Wilmes // submit button name is of the form - fn[cmd][param(s)] 49163ac707SMichael Wilmes $fn = $INPUT->param('fn'); 50163ac707SMichael Wilmes 51163ac707SMichael Wilmes if (is_array($fn)) { 52163ac707SMichael Wilmes $cmd = key($fn); 53163ac707SMichael Wilmes $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null; 54163ac707SMichael Wilmes } else { 55163ac707SMichael Wilmes $cmd = $fn; 56163ac707SMichael Wilmes $param = null; 57163ac707SMichael Wilmes } 58163ac707SMichael Wilmes 59163ac707SMichael Wilmes if ($cmd != "search") { 60*f62d0e33SAndreas Gohr $this->start = $INPUT->int('start', 0); 61*f62d0e33SAndreas Gohr $this->filter = $this->_retrieveFilter(); 62163ac707SMichael Wilmes } 63163ac707SMichael Wilmes 64163ac707SMichael Wilmes switch ($cmd) { 65d0a31016SAndreas Gohr case "reset" : 66d0a31016SAndreas Gohr $this->_resetUser(); 67d0a31016SAndreas Gohr break; 68d0a31016SAndreas Gohr case "search" : 69d0a31016SAndreas Gohr $this->_setFilter($param); 70*f62d0e33SAndreas Gohr $this->start = 0; 71163ac707SMichael Wilmes break; 72163ac707SMichael Wilmes } 73163ac707SMichael Wilmes 74*f62d0e33SAndreas Gohr $this->_user_total = count($this->userList) > 0 ? $this->_getUserCount($this->filter) : -1; 75163ac707SMichael Wilmes 76163ac707SMichael Wilmes // page handling 77163ac707SMichael Wilmes switch ($cmd) { 78d0a31016SAndreas Gohr case 'start' : 79*f62d0e33SAndreas Gohr $this->start = 0; 80d0a31016SAndreas Gohr break; 81d0a31016SAndreas Gohr case 'prev' : 82*f62d0e33SAndreas Gohr $this->start -= $this->pagesize; 83d0a31016SAndreas Gohr break; 84d0a31016SAndreas Gohr case 'next' : 85*f62d0e33SAndreas Gohr $this->start += $this->pagesize; 86d0a31016SAndreas Gohr break; 87d0a31016SAndreas Gohr case 'last' : 88*f62d0e33SAndreas Gohr $this->start = $this->_user_total; 89d0a31016SAndreas Gohr break; 90163ac707SMichael Wilmes } 91163ac707SMichael Wilmes $this->_validatePagination(); 92163ac707SMichael Wilmes return true; 93163ac707SMichael Wilmes } 94163ac707SMichael Wilmes 95163ac707SMichael Wilmes /** 96163ac707SMichael Wilmes * Output appropriate html 97163ac707SMichael Wilmes * 98163ac707SMichael Wilmes * @return bool 99163ac707SMichael Wilmes */ 100d0a31016SAndreas Gohr public function html() 101d0a31016SAndreas Gohr { 102163ac707SMichael Wilmes global $ID, $INFO; 103163ac707SMichael Wilmes 104*f62d0e33SAndreas Gohr $users = $this->getUsers($this->start, $this->pagesize, $this->filter); 105*f62d0e33SAndreas Gohr $pagination = $this->getPagination(); 106163ac707SMichael Wilmes 107*f62d0e33SAndreas Gohr echo $this->locale_xhtml('admin'); 108*f62d0e33SAndreas Gohr 109*f62d0e33SAndreas Gohr echo '<div id="user__manager">'; // FIXME do we reuse styles? 110*f62d0e33SAndreas Gohr echo '<div class="level2">'; 111*f62d0e33SAndreas Gohr 112*f62d0e33SAndreas Gohr // FIXME check if isReady, display info if not 113*f62d0e33SAndreas Gohr 114*f62d0e33SAndreas Gohr $form = new Form(['method' => 'POST']); 115*f62d0e33SAndreas Gohr $form->setHiddenField('do', 'admin'); 116*f62d0e33SAndreas Gohr $form->setHiddenField('page', 'twofactor'); 117*f62d0e33SAndreas Gohr $form->setHiddenField('start', $this->start); 118*f62d0e33SAndreas Gohr 119*f62d0e33SAndreas Gohr $form->addTagOpen('div')->addClass('table'); 120*f62d0e33SAndreas Gohr $form->addTagOpen('table')->addClass('inline'); 121*f62d0e33SAndreas Gohr $form = $this->addTableHead($form); 122*f62d0e33SAndreas Gohr 123*f62d0e33SAndreas Gohr $form->addTagOpen('tbody'); 124*f62d0e33SAndreas Gohr foreach ($users as $user => $userinfo) { 125*f62d0e33SAndreas Gohr $form = $this->addTableUser($form, $user, $userinfo); 126*f62d0e33SAndreas Gohr } 127*f62d0e33SAndreas Gohr $form->addTagClose('tbody'); 128*f62d0e33SAndreas Gohr 129*f62d0e33SAndreas Gohr $form->addTagClose('table'); 130*f62d0e33SAndreas Gohr $form->addTagClose('div'); 131*f62d0e33SAndreas Gohr 132*f62d0e33SAndreas Gohr echo $form->toHTML(); 133*f62d0e33SAndreas Gohr 134b71db9c8SMichael Wilmes return true; 135b71db9c8SMichael Wilmes } 136b71db9c8SMichael Wilmes 137163ac707SMichael Wilmes /** 138*f62d0e33SAndreas Gohr * Add the table headers to the table in the given form 139*f62d0e33SAndreas Gohr * @param Form $form 140*f62d0e33SAndreas Gohr * @return Form 141163ac707SMichael Wilmes */ 142*f62d0e33SAndreas Gohr protected function addTableHead(Form $form) 143*f62d0e33SAndreas Gohr { 144*f62d0e33SAndreas Gohr $form->addTagOpen('thead'); 145*f62d0e33SAndreas Gohr 146*f62d0e33SAndreas Gohr // header 147*f62d0e33SAndreas Gohr $form->addTagOpen('tr'); 148*f62d0e33SAndreas Gohr $form->addTagOpen('th'); 149*f62d0e33SAndreas Gohr $form->addHTML($this->getLang('user_id')); 150*f62d0e33SAndreas Gohr $form->addTagClose('th'); 151*f62d0e33SAndreas Gohr $form->addTagOpen('th'); 152*f62d0e33SAndreas Gohr $form->addHTML($this->getLang('user_name')); 153*f62d0e33SAndreas Gohr $form->addTagClose('th'); 154*f62d0e33SAndreas Gohr $form->addTagOpen('th'); 155*f62d0e33SAndreas Gohr $form->addHTML($this->getLang('user_mail')); 156*f62d0e33SAndreas Gohr $form->addTagClose('th'); 157*f62d0e33SAndreas Gohr $form->addTagOpen('th'); 158*f62d0e33SAndreas Gohr $form->addHTML($this->getLang('action')); 159*f62d0e33SAndreas Gohr $form->addTagClose('th'); 160*f62d0e33SAndreas Gohr $form->addTagClose('tr'); 161*f62d0e33SAndreas Gohr 162*f62d0e33SAndreas Gohr // filter 163*f62d0e33SAndreas Gohr $form->addTagOpen('tr'); 164*f62d0e33SAndreas Gohr $form->addTagOpen('th'); 165*f62d0e33SAndreas Gohr $form->addTextInput('userid'); 166*f62d0e33SAndreas Gohr $form->addTagClose('th'); 167*f62d0e33SAndreas Gohr $form->addTagOpen('th'); 168*f62d0e33SAndreas Gohr $form->addTextInput('username'); 169*f62d0e33SAndreas Gohr $form->addTagClose('th'); 170*f62d0e33SAndreas Gohr $form->addTagOpen('th'); 171*f62d0e33SAndreas Gohr $form->addTextInput('usermail'); 172*f62d0e33SAndreas Gohr $form->addTagClose('th'); 173*f62d0e33SAndreas Gohr $form->addTagOpen('th'); 174*f62d0e33SAndreas Gohr $form->addButton('', $this->getLang('search'))->attr('type', 'submit'); 175*f62d0e33SAndreas Gohr $form->addTagClose('th'); 176*f62d0e33SAndreas Gohr $form->addTagClose('tr'); 177*f62d0e33SAndreas Gohr 178*f62d0e33SAndreas Gohr $form->addTagClose('thead'); 179*f62d0e33SAndreas Gohr return $form; 180163ac707SMichael Wilmes } 181163ac707SMichael Wilmes 182*f62d0e33SAndreas Gohr /** 183*f62d0e33SAndreas Gohr * Add 184*f62d0e33SAndreas Gohr * 185*f62d0e33SAndreas Gohr * @param Form $form 186*f62d0e33SAndreas Gohr * @param $user 187*f62d0e33SAndreas Gohr * @param $userinfo 188*f62d0e33SAndreas Gohr * @return Form 189*f62d0e33SAndreas Gohr */ 190*f62d0e33SAndreas Gohr protected function addTableUser(Form $form, $user, $userinfo) 191*f62d0e33SAndreas Gohr { 192*f62d0e33SAndreas Gohr $form->addTagOpen('tr'); 193*f62d0e33SAndreas Gohr $form->addTagOpen('td'); 194*f62d0e33SAndreas Gohr $form->addHTML(hsc($user)); 195*f62d0e33SAndreas Gohr $form->addTagClose('td'); 196*f62d0e33SAndreas Gohr $form->addTagOpen('td'); 197*f62d0e33SAndreas Gohr $form->addHTML(hsc($userinfo['name'])); 198*f62d0e33SAndreas Gohr $form->addTagClose('td'); 199*f62d0e33SAndreas Gohr $form->addTagOpen('td'); 200*f62d0e33SAndreas Gohr $form->addHTML(hsc($userinfo['mail'])); 201*f62d0e33SAndreas Gohr $form->addTagClose('td'); 202*f62d0e33SAndreas Gohr $form->addTagOpen('td'); 203*f62d0e33SAndreas Gohr $form->addButton('reset[' . $user . ']', $this->getLang('reset'))->attr('type', 'submit'); 204*f62d0e33SAndreas Gohr $form->addTagClose('td'); 205*f62d0e33SAndreas Gohr $form->addTagClose('tr'); 206*f62d0e33SAndreas Gohr return $form; 207163ac707SMichael Wilmes } 208163ac707SMichael Wilmes 209*f62d0e33SAndreas Gohr /** 210*f62d0e33SAndreas Gohr * @return int current start value for pageination 211*f62d0e33SAndreas Gohr */ 212*f62d0e33SAndreas Gohr public function getStart() 213*f62d0e33SAndreas Gohr { 214*f62d0e33SAndreas Gohr return $this->start; 215*f62d0e33SAndreas Gohr } 216163ac707SMichael Wilmes 217*f62d0e33SAndreas Gohr /** 218*f62d0e33SAndreas Gohr * @return int number of users per page 219*f62d0e33SAndreas Gohr */ 220*f62d0e33SAndreas Gohr public function getPagesize() 221*f62d0e33SAndreas Gohr { 222*f62d0e33SAndreas Gohr return $this->pagesize; 223*f62d0e33SAndreas Gohr } 224163ac707SMichael Wilmes 225*f62d0e33SAndreas Gohr /** 226*f62d0e33SAndreas Gohr * @param boolean $lastdisabled 227*f62d0e33SAndreas Gohr */ 228*f62d0e33SAndreas Gohr public function setLastdisabled($lastdisabled) 229*f62d0e33SAndreas Gohr { 230*f62d0e33SAndreas Gohr $this->lastdisabled = $lastdisabled; 231163ac707SMichael Wilmes } 232163ac707SMichael Wilmes 233163ac707SMichael Wilmes /** 234163ac707SMichael Wilmes * Prints a inputfield 235163ac707SMichael Wilmes * 236163ac707SMichael Wilmes * @param string $id 237163ac707SMichael Wilmes * @param string $name 238163ac707SMichael Wilmes * @param string $label 239163ac707SMichael Wilmes * @param string $value 240163ac707SMichael Wilmes * @param bool $cando whether auth backend is capable to do this action 241163ac707SMichael Wilmes * @param int $indent 242163ac707SMichael Wilmes */ 243d0a31016SAndreas Gohr protected function _htmlInputField($id, $name, $label, $value, $cando, $indent = 0) 244d0a31016SAndreas Gohr { 245163ac707SMichael Wilmes $class = $cando ? '' : ' class="disabled"'; 246163ac707SMichael Wilmes echo str_pad('', $indent); 247163ac707SMichael Wilmes 248163ac707SMichael Wilmes if ($name == 'userpass' || $name == 'userpass2') { 249163ac707SMichael Wilmes $fieldtype = 'password'; 250163ac707SMichael Wilmes $autocomp = 'autocomplete="off"'; 251163ac707SMichael Wilmes } elseif ($name == 'usermail') { 252163ac707SMichael Wilmes $fieldtype = 'email'; 253163ac707SMichael Wilmes $autocomp = ''; 254163ac707SMichael Wilmes } else { 255163ac707SMichael Wilmes $fieldtype = 'text'; 256163ac707SMichael Wilmes $autocomp = ''; 257163ac707SMichael Wilmes } 258163ac707SMichael Wilmes $value = hsc($value); 259163ac707SMichael Wilmes 260163ac707SMichael Wilmes echo "<tr $class>"; 261163ac707SMichael Wilmes echo "<td><label for=\"$id\" >$label: </label></td>"; 262163ac707SMichael Wilmes echo "<td>"; 263163ac707SMichael Wilmes if ($cando) { 264163ac707SMichael Wilmes echo "<input type=\"$fieldtype\" id=\"$id\" name=\"$name\" value=\"$value\" class=\"edit\" $autocomp />"; 265163ac707SMichael Wilmes } else { 266163ac707SMichael Wilmes echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />"; 267163ac707SMichael Wilmes echo "<input type=\"$fieldtype\" id=\"$id\" name=\"$name\" value=\"$value\" class=\"edit disabled\" disabled=\"disabled\" />"; 268163ac707SMichael Wilmes } 269163ac707SMichael Wilmes echo "</td>"; 270163ac707SMichael Wilmes echo "</tr>"; 271163ac707SMichael Wilmes } 272163ac707SMichael Wilmes 273163ac707SMichael Wilmes /** 274163ac707SMichael Wilmes * Returns htmlescaped filter value 275163ac707SMichael Wilmes * 276163ac707SMichael Wilmes * @param string $key name of search field 277163ac707SMichael Wilmes * @return string html escaped value 278163ac707SMichael Wilmes */ 279d0a31016SAndreas Gohr protected function _htmlFilter($key) 280d0a31016SAndreas Gohr { 281*f62d0e33SAndreas Gohr if (empty($this->filter)) return ''; 282*f62d0e33SAndreas Gohr return (isset($this->filter[$key]) ? hsc($this->filter[$key]) : ''); 283163ac707SMichael Wilmes } 284163ac707SMichael Wilmes 285163ac707SMichael Wilmes /** 286163ac707SMichael Wilmes * Print hidden inputs with the current filter values 287163ac707SMichael Wilmes * 288163ac707SMichael Wilmes * @param int $indent 289163ac707SMichael Wilmes */ 290d0a31016SAndreas Gohr protected function _htmlFilterSettings($indent = 0) 291d0a31016SAndreas Gohr { 292163ac707SMichael Wilmes 293*f62d0e33SAndreas Gohr ptln("<input type=\"hidden\" name=\"start\" value=\"" . $this->start . "\" />", $indent); 294163ac707SMichael Wilmes 295*f62d0e33SAndreas Gohr foreach ($this->filter as $key => $filter) { 296163ac707SMichael Wilmes ptln("<input type=\"hidden\" name=\"filter[" . $key . "]\" value=\"" . hsc($filter) . "\" />", $indent); 297163ac707SMichael Wilmes } 298163ac707SMichael Wilmes } 299163ac707SMichael Wilmes 300163ac707SMichael Wilmes /** 301163ac707SMichael Wilmes * Reset user (a user has been selected to remove two factor authentication) 302163ac707SMichael Wilmes * 303163ac707SMichael Wilmes * @param string $param id of the user 304163ac707SMichael Wilmes * @return bool whether succesful 305163ac707SMichael Wilmes */ 306d0a31016SAndreas Gohr protected function _resetUser() 307d0a31016SAndreas Gohr { 308163ac707SMichael Wilmes global $INPUT; 309163ac707SMichael Wilmes if (!checkSecurityToken()) return false; 310163ac707SMichael Wilmes 311163ac707SMichael Wilmes $selected = $INPUT->arr('delete'); 312163ac707SMichael Wilmes if (empty($selected)) return false; 313163ac707SMichael Wilmes $selected = array_keys($selected); 314163ac707SMichael Wilmes 315163ac707SMichael Wilmes if (in_array($_SERVER['REMOTE_USER'], $selected)) { 316163ac707SMichael Wilmes msg($this->lang['reset_not_self'], -1); 317163ac707SMichael Wilmes return false; 318163ac707SMichael Wilmes } 319163ac707SMichael Wilmes 320163ac707SMichael Wilmes $count = 0; 321163ac707SMichael Wilmes foreach ($selected as $user) { 322163ac707SMichael Wilmes // All users here have a attribute namespace file. Purge them. 323185a84e4SMichael Wilmes $purged = $this->attribute->purge('twofactor', $user); 324185a84e4SMichael Wilmes foreach ($this->modules as $mod) { 325185a84e4SMichael Wilmes $purged |= $this->attribute->purge($mod->moduleName, $user); 326185a84e4SMichael Wilmes } 327185a84e4SMichael Wilmes $count += $purged ? 1 : 0; 328163ac707SMichael Wilmes } 329163ac707SMichael Wilmes 330163ac707SMichael Wilmes if ($count == count($selected)) { 331163ac707SMichael Wilmes $text = str_replace('%d', $count, $this->lang['reset_ok']); 332163ac707SMichael Wilmes msg("$text.", 1); 333163ac707SMichael Wilmes } else { 334163ac707SMichael Wilmes $part1 = str_replace('%d', $count, $this->lang['reset_ok']); 335163ac707SMichael Wilmes $part2 = str_replace('%d', (count($selected) - $count), $this->lang['reset_fail']); 3362cc41bddSMichael Wilmes // Output results. 337163ac707SMichael Wilmes msg("$part1, $part2", -1); 338163ac707SMichael Wilmes } 339163ac707SMichael Wilmes 340163ac707SMichael Wilmes // Now refresh the user list. 341163ac707SMichael Wilmes $this->_getUsers(); 342163ac707SMichael Wilmes 343163ac707SMichael Wilmes return true; 344163ac707SMichael Wilmes } 345163ac707SMichael Wilmes 346d0a31016SAndreas Gohr protected function _retrieveFilteredUsers($filter = array()) 347d0a31016SAndreas Gohr { 3482cc41bddSMichael Wilmes global $auth; 349163ac707SMichael Wilmes $users = array(); 3502cc41bddSMichael Wilmes $noUsers = is_null($auth) || !$auth->canDo('getUsers'); 351*f62d0e33SAndreas Gohr foreach ($this->userList as $user) { 3522cc41bddSMichael Wilmes if ($noUsers) { 3532cc41bddSMichael Wilmes $userdata = array('user' => $user, 'name' => $user, 'mail' => null); 3542cc41bddSMichael Wilmes } else { 3552cc41bddSMichael Wilmes $userdata = $auth->getUserData($user); 35691cdada2SMichael Wilmes if (!is_array($userdata)) { 35791cdada2SMichael Wilmes $userdata = array('user' => $user, 'name' => null, 'mail' => null); 35891cdada2SMichael Wilmes } 3592cc41bddSMichael Wilmes } 360163ac707SMichael Wilmes $include = true; 361163ac707SMichael Wilmes foreach ($filter as $key => $value) { 362163ac707SMichael Wilmes $include &= strstr($userdata[$key], $value); 363163ac707SMichael Wilmes } 364d0a31016SAndreas Gohr if ($include) { 365d0a31016SAndreas Gohr $users[$user] = $userdata; 366d0a31016SAndreas Gohr } 367163ac707SMichael Wilmes } 368163ac707SMichael Wilmes return $users; 369163ac707SMichael Wilmes } 370163ac707SMichael Wilmes 371d0a31016SAndreas Gohr protected function _getUserCount($filter) 372d0a31016SAndreas Gohr { 373163ac707SMichael Wilmes return count($this->_retrieveFilteredUsers($filter)); 374163ac707SMichael Wilmes } 375163ac707SMichael Wilmes 376*f62d0e33SAndreas Gohr protected function getUsers($start, $pagesize, $filter) 377d0a31016SAndreas Gohr { 378163ac707SMichael Wilmes $users = $this->_retrieveFilteredUsers($filter); 379163ac707SMichael Wilmes return $users; 380163ac707SMichael Wilmes } 381163ac707SMichael Wilmes 382163ac707SMichael Wilmes /** 383163ac707SMichael Wilmes * Retrieve & clean user data from the form 384163ac707SMichael Wilmes * 385163ac707SMichael Wilmes * @param bool $clean whether the cleanUser method of the authentication backend is applied 386163ac707SMichael Wilmes * @return array (user, password, full name, email, array(groups)) 387163ac707SMichael Wilmes */ 388d0a31016SAndreas Gohr protected function _retrieveUser($clean = true) 389d0a31016SAndreas Gohr { 390163ac707SMichael Wilmes /** @var DokuWiki_Auth_Plugin $auth */ 391163ac707SMichael Wilmes global $auth; 392163ac707SMichael Wilmes global $INPUT; 393163ac707SMichael Wilmes 394163ac707SMichael Wilmes $user = array(); 3952cc41bddSMichael Wilmes $user[] = $INPUT->str('userid'); 3962cc41bddSMichael Wilmes $user[] = $INPUT->str('username'); 3972cc41bddSMichael Wilmes $user[] = $INPUT->str('usermail'); 398163ac707SMichael Wilmes 399163ac707SMichael Wilmes return $user; 400163ac707SMichael Wilmes } 401163ac707SMichael Wilmes 402163ac707SMichael Wilmes /** 403163ac707SMichael Wilmes * Set the filter with the current search terms or clear the filter 404163ac707SMichael Wilmes * 405163ac707SMichael Wilmes * @param string $op 'new' or 'clear' 406163ac707SMichael Wilmes */ 407d0a31016SAndreas Gohr protected function _setFilter($op) 408d0a31016SAndreas Gohr { 409163ac707SMichael Wilmes 410*f62d0e33SAndreas Gohr $this->filter = array(); 411163ac707SMichael Wilmes 412163ac707SMichael Wilmes if ($op == 'new') { 4132cc41bddSMichael Wilmes list($user, $name, $mail) = $this->_retrieveUser(); 414163ac707SMichael Wilmes 415*f62d0e33SAndreas Gohr if (!empty($user)) $this->filter['user'] = $user; 416*f62d0e33SAndreas Gohr if (!empty($name)) $this->filter['name'] = $name; 417*f62d0e33SAndreas Gohr if (!empty($mail)) $this->filter['mail'] = $mail; 418163ac707SMichael Wilmes } 419163ac707SMichael Wilmes } 420163ac707SMichael Wilmes 421163ac707SMichael Wilmes /** 422163ac707SMichael Wilmes * Get the current search terms 423163ac707SMichael Wilmes * 424163ac707SMichael Wilmes * @return array 425163ac707SMichael Wilmes */ 426d0a31016SAndreas Gohr protected function _retrieveFilter() 427d0a31016SAndreas Gohr { 428163ac707SMichael Wilmes global $INPUT; 429163ac707SMichael Wilmes 430163ac707SMichael Wilmes $t_filter = $INPUT->arr('filter'); 431163ac707SMichael Wilmes 432163ac707SMichael Wilmes // messy, but this way we ensure we aren't getting any additional crap from malicious users 433163ac707SMichael Wilmes $filter = array(); 434163ac707SMichael Wilmes 435163ac707SMichael Wilmes if (isset($t_filter['user'])) $filter['user'] = $t_filter['user']; 436163ac707SMichael Wilmes if (isset($t_filter['name'])) $filter['name'] = $t_filter['name']; 437163ac707SMichael Wilmes if (isset($t_filter['mail'])) $filter['mail'] = $t_filter['mail']; 438163ac707SMichael Wilmes 439163ac707SMichael Wilmes return $filter; 440163ac707SMichael Wilmes } 441163ac707SMichael Wilmes 442163ac707SMichael Wilmes /** 443163ac707SMichael Wilmes * Validate and improve the pagination values 444163ac707SMichael Wilmes */ 445d0a31016SAndreas Gohr protected function _validatePagination() 446d0a31016SAndreas Gohr { 447163ac707SMichael Wilmes 448*f62d0e33SAndreas Gohr if ($this->start >= $this->_user_total) { 449*f62d0e33SAndreas Gohr $this->start = $this->_user_total - $this->pagesize; 450163ac707SMichael Wilmes } 451*f62d0e33SAndreas Gohr if ($this->start < 0) $this->start = 0; 452163ac707SMichael Wilmes 453*f62d0e33SAndreas Gohr $this->last = min($this->_user_total, $this->start + $this->pagesize); 454163ac707SMichael Wilmes } 455163ac707SMichael Wilmes 456163ac707SMichael Wilmes /** 457163ac707SMichael Wilmes * Return an array of strings to enable/disable pagination buttons 458163ac707SMichael Wilmes * 459163ac707SMichael Wilmes * @return array with enable/disable attributes 460163ac707SMichael Wilmes */ 461*f62d0e33SAndreas Gohr protected function getPagination() 462d0a31016SAndreas Gohr { 463163ac707SMichael Wilmes 464163ac707SMichael Wilmes $disabled = 'disabled="disabled"'; 465163ac707SMichael Wilmes 466163ac707SMichael Wilmes $buttons = array(); 467*f62d0e33SAndreas Gohr $buttons['start'] = $buttons['prev'] = ($this->start == 0) ? $disabled : ''; 468163ac707SMichael Wilmes 469163ac707SMichael Wilmes if ($this->_user_total == -1) { 470163ac707SMichael Wilmes $buttons['last'] = $disabled; 471163ac707SMichael Wilmes $buttons['next'] = ''; 472163ac707SMichael Wilmes } else { 473*f62d0e33SAndreas Gohr $buttons['last'] = $buttons['next'] = (($this->start + $this->pagesize) >= $this->_user_total) ? $disabled : ''; 474163ac707SMichael Wilmes } 475163ac707SMichael Wilmes 476*f62d0e33SAndreas Gohr if ($this->lastdisabled) { 477163ac707SMichael Wilmes $buttons['last'] = $disabled; 478163ac707SMichael Wilmes } 479163ac707SMichael Wilmes 480163ac707SMichael Wilmes return $buttons; 481163ac707SMichael Wilmes } 482163ac707SMichael Wilmes 483163ac707SMichael Wilmes} 484