*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_TWOFACTOR_PLUGIN_IMAGES')) define('DOKU_TWOFACTOR_PLUGIN_IMAGES',DOKU_BASE.'lib/plugins/twofactor/images/'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_twofactor extends DokuWiki_Admin_Plugin { protected $_auth = null; // auth object protected $_user_list = array(); // number of users with attributes protected $_filter = array(); // user selection filter(s) protected $_start = 0; // index of first user to be displayed protected $_last = 0; // index of the last user to be displayed protected $_pagesize = 20; // number of users to list on one page protected $_disabled = ''; // if disabled set to explanatory string protected $_lastdisabled = false; // set to true if last user is unknown and last button is hence buggy /** * Constructor */ public function __construct(){ global $auth; if (!isset($auth)) { $this->_disabled = $this->lang['noauth']; } else if (!$auth->canDo('getUsers')) { $this->_disabled = $this->lang['nosupport']; } else { // we're good to go $this->_auth = & $auth; } $this->setupLocale(); $requireAttribute = $this->getConf("enable") === 1; $this->attribute = $requireAttribute ? $this->loadHelper('attribute', 'Attribute plugin required!') : null; $this->_getUsers(); } protected function _getUsers() { if (!is_null($this->attribute)) { $attr = $this->attribute; $this->_user_list = $this->attribute->enumerateUsers('twofactor'); } else { msg($this->lang['no_purpose'], -1); } } /** * Return prompt for admin menu * * @param string $language * @return string */ public function getMenuText($language) { global $INFO; if (!$INFO['isadmin']) return parent::getMenuText($language); return $this->getLang('menu').' '.$this->_disabled; } /** * return sort order for position in admin menu * * @return int */ public function getMenuSort() { return 2; } /** * @return int current start value for pageination */ public function getStart() { return $this->_start; } /** * @return int number of users per page */ public function getPagesize() { return $this->_pagesize; } /** * @param boolean $lastdisabled */ public function setLastdisabled($lastdisabled) { $this->_lastdisabled = $lastdisabled; } /** * Handle user request * * @return bool */ public function handle() { global $INPUT, $INFO; if (!$INFO['isadmin']) return false; // extract the command and any specific parameters // submit button name is of the form - fn[cmd][param(s)] $fn = $INPUT->param('fn'); if (is_array($fn)) { $cmd = key($fn); $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null; } else { $cmd = $fn; $param = null; } if ($cmd != "search") { $this->_start = $INPUT->int('start', 0); $this->_filter = $this->_retrieveFilter(); } switch($cmd){ case "reset" : $this->_resetUser(); break; case "search" : $this->_setFilter($param); $this->_start = 0; break; } $this->_user_total = count($this->_user_list) > 0 ? $this->_getUserCount($this->_filter) : -1; // page handling switch($cmd){ case 'start' : $this->_start = 0; break; case 'prev' : $this->_start -= $this->_pagesize; break; case 'next' : $this->_start += $this->_pagesize; break; case 'last' : $this->_start = $this->_user_total; break; } $this->_validatePagination(); return true; } /** * Output appropriate html * * @return bool */ public function html() { global $ID, $INFO; if(!$INFO['isadmin']) { print $this->lang['badauth']; return false; } $user_list = $this->_retrieveUsers($this->_start, $this->_pagesize, $this->_filter); $page_buttons = $this->_pagination(); print $this->locale_xhtml('intro'); print $this->locale_xhtml('list'); ptln("
".sprintf($this->lang['summary'],$this->_start+1,$this->_last,$this->_getUserCount($this->_filter),count($this->_user_list))."
"); } else { if(count($this->_user_list) < 0) { $allUserTotal = 0; } else { $allUserTotal = count($this->_user_list); } ptln("".sprintf($this->lang['nonefound'], $allUserTotal)."
"); } ptln(""); ptln("