1<?php
2
3use dokuwiki\Extension\AdminPlugin;
4use dokuwiki\Form\Form;
5use dokuwiki\Form\InputElement;
6use dokuwiki\plugin\sqlite\SQLiteDB;
7
8/**
9 * DokuWiki Plugin watchcycle (Admin Component)
10 *
11 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
12 * @author  Szymon Olewniczak <dokuwiki@cosmocode.de>
13 */
14
15class admin_plugin_watchcycle extends AdminPlugin
16{
17    /**
18     * @return int sort number in admin menu
19     */
20    public function getMenuSort()
21    {
22        return 1;
23    }
24
25    /**
26     * @return bool true if only access for superuser, false is for superusers and moderators
27     */
28    public function forAdminOnly()
29    {
30        return false;
31    }
32
33    /**
34     * Should carry out any processing required by the plugin.
35     */
36    public function handle()
37    {
38    }
39
40    /**
41     * Render HTML output, e.g. helpful text and a form
42     */
43    public function html()
44    {
45        global $ID;
46        /* @var Input */
47        global $INPUT;
48
49        /** @var \helper_plugin_watchcycle_db $dbHelper */
50        $dbHelper = plugin_load('helper', 'watchcycle_db');
51
52        echo '<h1>' . $this->getLang('menu') . '</h1>';
53
54        echo '<div id="plugin__watchcycle_admin">';
55
56        $form = new Form();
57        $filter_input = new InputElement('text', 'filter');
58        $filter_input->attr('placeholder', $this->getLang('search page'));
59
60        $form->addElement($filter_input);
61
62        $form->addButton('', $this->getLang('btn filter'));
63
64        $form->addHTML('<label class="outdated">');
65        $form->addCheckbox('outdated');
66        $form->addHTML($this->getLang('show outdated only'));
67        $form->addHTML('</label>');
68
69
70        echo $form->toHTML();
71        echo '<table>';
72        echo '<tr>';
73        $headers = ['page', 'maintainer', 'cycle', 'current', 'uptodate'];
74        foreach ($headers as $header) {
75            $lang = $this->getLang("h $header");
76            $param = [
77                'do' => 'admin',
78                'page' => 'watchcycle',
79                'sortby' => $header,
80            ];
81            $icon = '';
82            if ($INPUT->str('sortby') == $header) {
83                if ($INPUT->int('desc') == 0) {
84                    $param['desc'] = 1;
85                    $icon = '↑';
86                } else {
87                    $param['desc'] = 0;
88                    $icon = '↓';
89                }
90            }
91            $href = wl($ID, $param);
92
93            echo '<th><a href="' . $href . '">' . $icon . ' ' . $lang . '</a></th>';
94        }
95
96        $rows = $dbHelper->getAll($headers);
97
98        foreach ($rows as $row) {
99            echo '<tr>';
100            echo '<td><a href="' . wl($row['page']) . '" class="wikilink1">' . $row['page'] . '</a></td>';
101            echo '<td>' . $row['maintainer'] . '</td>';
102            echo '<td>' . $row['cycle'] . '</td>';
103            echo '<td>' . $row['current'] . '</td>';
104            $icon = $row['uptodate'] == 1 ? '✓' : '✕';
105            echo '<td>' . $icon . '</td>';
106            echo '</tr>';
107        }
108
109        echo '</tr>';
110        echo '</table>';
111        echo '</div>';
112    }
113}
114