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    /** @inheritdoc */
26    public function showInMenu()
27    {
28        return false;
29    }
30
31    /** @inheritdoc */
32    public function handle()
33    {
34        global $INPUT;
35        global $ID;
36
37        $self = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'], true, '&');
38
39        if ($INPUT->has('bulk_plugin') && $INPUT->has('state')) {
40            $animals = $this->helper->getAllAnimals();
41            $plugin = $INPUT->str('bulk_plugin');
42            foreach ($animals as $animal) {
43                $this->helper->setPluginState($plugin, $animal, $INPUT->int('state'));
44            }
45            msg($this->getLang('plugindone'), 1);
46            send_redirect($self);
47        }
48
49        if ($INPUT->has('bulk_animal') && $INPUT->has('bulk_plugins')) {
50            $animal = $INPUT->str('bulk_animal');
51            $activePlugins = $INPUT->arr('bulk_plugins');
52            foreach ($activePlugins as $plugin => $state) {
53                $this->helper->setPluginState($plugin, $animal, $state);
54            }
55            msg($this->getLang('plugindone'), 1);
56            send_redirect($self);
57        }
58    }
59
60    /** @inheritdoc */
61    public function html()
62    {
63
64        echo $this->locale_xhtml('plugins');
65        $switchForm = new Form();
66        $switchForm->addClass('plugin_farmer');
67        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
68        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))
69            ->id('farmer__bulk')
70            ->attr('type', 'radio');
71        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))
72            ->id('farmer__single')
73            ->attr('type', 'radio');
74        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('matrixEdit'))
75            ->id('farmer__matrix')
76            ->attr('type', 'radio');
77        $switchForm->addFieldsetClose();
78        echo $switchForm->toHTML();
79
80        /** @var helper_plugin_farmer $helper */
81        $helper = plugin_load('helper', 'farmer');
82        $plugins = $helper->getAllPlugins();
83        array_unshift($plugins, '');
84
85        // All Animals at once
86        $bulkForm = new Form();
87        $bulkForm->id('farmer__pluginsforall');
88        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
89        $bulkForm->addDropdown('bulk_plugin', $plugins);
90        $bulkForm->addButton('state', $this->getLang('default'))
91            ->attr('value', '-1')
92            ->attr('type', 'submit')
93            ->attr('disabled', 'disabled');
94        $bulkForm->addButton('state', $this->getLang('activate'))
95            ->attr('value', '1')
96            ->attr('type', 'submit')
97            ->attr('disabled', 'disabled');
98        $bulkForm->addButton('state', $this->getLang('deactivate'))
99            ->attr('value', '0')
100            ->attr('type', 'submit')
101            ->attr('disabled', 'disabled');
102        $bulkForm->addFieldsetClose();
103        echo $bulkForm->toHTML();
104
105        $animals = $helper->getAllAnimals();
106        array_unshift($animals, '');
107
108        // One Animal, all the plugins
109        $singleForm = new Form();
110        $singleForm->id('farmer__pluginsforone');
111        $singleForm->addFieldsetOpen($this->getLang('singleEditForm'));
112        $singleForm->addDropdown('bulk_animal', $animals);
113        $singleForm->addTagOpen('div')->addClass('output');
114        $singleForm->addTagClose('div');
115        $singleForm->addButton('save', $this->getLang('save'))
116            ->attr('disabled', 'disabled');
117
118        echo $singleForm->toHTML();
119
120
121        echo '<div id="farmer__pluginmatrix"></div>';
122    }
123}
124