xref: /plugin/farmer/admin/plugins.php (revision 1da41c8bdb9ce0b590d5b69552c4ddb4d0aef860)
1<?php
2
3use dokuwiki\Extension\AdminPlugin;
4use dokuwiki\Form\Form;
5
6/**
7 * DokuWiki Plugin farmer (Admin Component)
8 *
9 * Manage Animal Plugin settings
10 *
11 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
12 * @author  Michael Große <grosse@cosmocode.de>
13 * @author  Andreas Gohr <gohr@cosmocode.de>
14 */
15class admin_plugin_farmer_plugins extends AdminPlugin
16{
17    /** @var helper_plugin_farmer $helper */
18    private $helper;
19
20    public function __construct()
21    {
22        $this->helper = plugin_load('helper', 'farmer');
23    }
24
25    /**
26     * handle user request
27     */
28    public function handle()
29    {
30        global $INPUT;
31        global $ID;
32
33        $self = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'], true, '&');
34
35        if ($INPUT->has('bulk_plugin') && $INPUT->has('state')) {
36            $animals = $this->helper->getAllAnimals();
37            $plugin = $INPUT->str('bulk_plugin');
38            foreach ($animals as $animal) {
39                $this->helper->setPluginState($plugin, $animal, $INPUT->int('state'));
40            }
41            msg($this->getLang('plugindone'), 1);
42            send_redirect($self);
43        }
44
45        if ($INPUT->has('bulk_animal') && $INPUT->has('bulk_plugins')) {
46            $animal = $INPUT->str('bulk_animal');
47            $activePlugins = $INPUT->arr('bulk_plugins');
48            foreach ($activePlugins as $plugin => $state) {
49                $this->helper->setPluginState($plugin, $animal, $state);
50            }
51            msg($this->getLang('plugindone'), 1);
52            send_redirect($self);
53        }
54    }
55
56    /**
57     * output appropriate html
58     */
59    public function html()
60    {
61
62        echo $this->locale_xhtml('plugins');
63        $switchForm = new Form();
64        $switchForm->addClass('plugin_farmer');
65        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
66        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))
67            ->id('farmer__bulk')
68            ->attr('type', 'radio');
69        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))
70            ->id('farmer__single')
71            ->attr('type', 'radio');
72        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('matrixEdit'))
73            ->id('farmer__matrix')
74            ->attr('type', 'radio');
75        $switchForm->addFieldsetClose();
76        echo $switchForm->toHTML();
77
78        /** @var helper_plugin_farmer $helper */
79        $helper = plugin_load('helper', 'farmer');
80        $plugins = $helper->getAllPlugins();
81        array_unshift($plugins, '');
82
83        // All Animals at once
84        $bulkForm = new Form();
85        $bulkForm->id('farmer__pluginsforall');
86        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
87        $bulkForm->addDropdown('bulk_plugin', $plugins);
88        $bulkForm->addButton('state', $this->getLang('default'))
89            ->attr('value', '-1')
90            ->attr('type', 'submit')
91            ->attr('disabled', 'disabled');
92        $bulkForm->addButton('state', $this->getLang('activate'))
93            ->attr('value', '1')
94            ->attr('type', 'submit')
95            ->attr('disabled', 'disabled');
96        $bulkForm->addButton('state', $this->getLang('deactivate'))
97            ->attr('value', '0')
98            ->attr('type', 'submit')
99            ->attr('disabled', 'disabled');
100        $bulkForm->addFieldsetClose();
101        echo $bulkForm->toHTML();
102
103        $animals = $helper->getAllAnimals();
104        array_unshift($animals, '');
105
106        // One Animal, all the plugins
107        $singleForm = new Form();
108        $singleForm->id('farmer__pluginsforone');
109        $singleForm->addFieldsetOpen($this->getLang('singleEditForm'));
110        $singleForm->addDropdown('bulk_animal', $animals);
111        $singleForm->addTagOpen('div')->addClass('output');
112        $singleForm->addTagClose('div');
113        $singleForm->addButton('save', $this->getLang('save'))
114            ->attr('disabled', 'disabled');
115
116        echo $singleForm->toHTML();
117
118
119        echo '<div id="farmer__pluginmatrix"></div>';
120    }
121}
122