1<?php
2/**
3 * DokuWiki Plugin autologoff (Admin Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr <gohr@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class admin_plugin_autologoff extends DokuWiki_Admin_Plugin {
13    /** @var  helper_plugin_autologoff */
14    private $helper;
15
16    public function __construct(){
17        $this->helper = $this->loadHelper('autologoff', false);
18    }
19
20
21    /**
22     * @return int sort number in admin menu
23     */
24    public function getMenuSort() {
25        return 500;
26    }
27
28    /**
29     * @return bool true if only access for superuser, false is for superusers and moderators
30     */
31    public function forAdminOnly() {
32        return false;
33    }
34
35    /**
36     * Should carry out any processing required by the plugin.
37     */
38    public function handle() {
39        if(isset($_REQUEST['remove']) && checkSecurityToken()){
40            $this->helper->remove_entry($_REQUEST['remove']);
41        }
42
43        if(isset($_REQUEST['usergroup']) && checkSecurityToken()){
44            $this->helper->add_entry($_REQUEST['usergroup'], $_REQUEST['time']);
45        }
46
47
48    }
49
50    /**
51     * Render HTML output, e.g. helpful text and a form
52     */
53    public function html() {
54        echo $this->locale_xhtml('intro');
55
56        $config = $this->helper->load_config();
57
58        echo '<form action="'.script().'" method="post">';
59        echo '<input type="hidden" name="do" value="admin" />';
60        echo '<input type="hidden" name="page" value="autologoff" />';
61        echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
62
63        echo '<table class="inline">';
64        echo '<tr>';
65        echo '<th>'.$this->getLang('usergroup').'</th>';
66        echo '<th>'.$this->getLang('time').'</th>';
67        echo '<th></th>';
68        echo '</tr>';
69
70        foreach($config as $usergroup => $time){
71
72            $url = wl('',array(
73                              'do' => 'admin',
74                              'page' => 'autologoff',
75                              'remove' => $usergroup,
76                              'sectok' => getSecurityToken()
77                         ));
78
79            echo '<tr>';
80            echo '<td>'.hsc($usergroup).'</td>';
81            echo '<td>'.hsc($time).'</td>';
82            echo '<td><a href="'.$url.'">'.$this->getLang('remove').'</a></td>';
83            echo '</tr>';
84        }
85
86        echo '<tr>';
87        echo '<td><input type="text" name="usergroup" class="edit" /></td>';
88        echo '<td><input type="text" name="time" class="edit" /></td>';
89        echo '<td><input type="submit" class="button" value="'.$this->getLang('save').'" /></td>';
90        echo '</tr>';
91
92
93        echo '</table>';
94        echo '</form>';
95
96    }
97}
98
99// vim:ts=4:sw=4:et:
100