xref: /plugin/farmer/admin/plugins.php (revision 1da41c8bdb9ce0b590d5b69552c4ddb4d0aef860)
1bc461538SMichael Große<?php
2*1da41c8bSAndreas Gohr
3*1da41c8bSAndreas Gohruse dokuwiki\Extension\AdminPlugin;
4*1da41c8bSAndreas Gohruse dokuwiki\Form\Form;
5*1da41c8bSAndreas Gohr
6bc461538SMichael Große/**
70a5d2da2SAndreas Gohr * DokuWiki Plugin farmer (Admin Component)
8bc461538SMichael Große *
9*1da41c8bSAndreas Gohr * Manage Animal Plugin settings
10*1da41c8bSAndreas Gohr *
110a5d2da2SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
120a5d2da2SAndreas Gohr * @author  Michael Große <grosse@cosmocode.de>
130a5d2da2SAndreas Gohr * @author  Andreas Gohr <gohr@cosmocode.de>
14bc461538SMichael Große */
15*1da41c8bSAndreas Gohrclass admin_plugin_farmer_plugins extends AdminPlugin
16*1da41c8bSAndreas Gohr{
17c4a48750SMichael Große    /** @var helper_plugin_farmer $helper */
18c4a48750SMichael Große    private $helper;
19c4a48750SMichael Große
20*1da41c8bSAndreas Gohr    public function __construct()
21*1da41c8bSAndreas Gohr    {
2265dd3ddfSAndreas Gohr        $this->helper = plugin_load('helper', 'farmer');
2365dd3ddfSAndreas Gohr    }
2465dd3ddfSAndreas Gohr
25bc461538SMichael Große    /**
26bc461538SMichael Große     * handle user request
27bc461538SMichael Große     */
28*1da41c8bSAndreas Gohr    public function handle()
29*1da41c8bSAndreas Gohr    {
3037a9ac83SMichael Große        global $INPUT;
31114a05a7SAndreas Gohr        global $ID;
32114a05a7SAndreas Gohr
33*1da41c8bSAndreas Gohr        $self = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'], true, '&');
34bc461538SMichael Große
35af1c6dd8SAndreas Gohr        if ($INPUT->has('bulk_plugin') && $INPUT->has('state')) {
36c4a48750SMichael Große            $animals = $this->helper->getAllAnimals();
37af1c6dd8SAndreas Gohr            $plugin = $INPUT->str('bulk_plugin');
380b96e6d7SMichael Große            foreach ($animals as $animal) {
39af1c6dd8SAndreas Gohr                $this->helper->setPluginState($plugin, $animal, $INPUT->int('state'));
40bc461538SMichael Große            }
41114a05a7SAndreas Gohr            msg($this->getLang('plugindone'), 1);
42114a05a7SAndreas Gohr            send_redirect($self);
43c4a48750SMichael Große        }
44af1c6dd8SAndreas Gohr
45af1c6dd8SAndreas Gohr        if ($INPUT->has('bulk_animal') && $INPUT->has('bulk_plugins')) {
46af1c6dd8SAndreas Gohr            $animal = $INPUT->str('bulk_animal');
47af1c6dd8SAndreas Gohr            $activePlugins = $INPUT->arr('bulk_plugins');
48af1c6dd8SAndreas Gohr            foreach ($activePlugins as $plugin => $state) {
49af1c6dd8SAndreas Gohr                $this->helper->setPluginState($plugin, $animal, $state);
500b96e6d7SMichael Große            }
51114a05a7SAndreas Gohr            msg($this->getLang('plugindone'), 1);
52114a05a7SAndreas Gohr            send_redirect($self);
530b96e6d7SMichael Große        }
54bc461538SMichael Große    }
55bc461538SMichael Große
56bc461538SMichael Große    /**
57bc461538SMichael Große     * output appropriate html
58bc461538SMichael Große     */
59*1da41c8bSAndreas Gohr    public function html()
60*1da41c8bSAndreas Gohr    {
61bc461538SMichael Große
629ed791b7SMichael Große        echo $this->locale_xhtml('plugins');
63*1da41c8bSAndreas Gohr        $switchForm = new Form();
64e71d78f4SMichael Große        $switchForm->addClass('plugin_farmer');
65fc6a7cc1SMichael Große        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
66*1da41c8bSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))
67*1da41c8bSAndreas Gohr            ->id('farmer__bulk')
68*1da41c8bSAndreas Gohr            ->attr('type', 'radio');
69*1da41c8bSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))
70*1da41c8bSAndreas Gohr            ->id('farmer__single')
71*1da41c8bSAndreas Gohr            ->attr('type', 'radio');
72*1da41c8bSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('matrixEdit'))
73*1da41c8bSAndreas Gohr            ->id('farmer__matrix')
74*1da41c8bSAndreas Gohr            ->attr('type', 'radio');
750b96e6d7SMichael Große        $switchForm->addFieldsetClose();
760b96e6d7SMichael Große        echo $switchForm->toHTML();
77bc461538SMichael Große
780b96e6d7SMichael Große        /** @var helper_plugin_farmer $helper */
790b96e6d7SMichael Große        $helper = plugin_load('helper', 'farmer');
800b96e6d7SMichael Große        $plugins = $helper->getAllPlugins();
81d3a4cfaaSAndreas Gohr        array_unshift($plugins, '');
820b96e6d7SMichael Große
83af1c6dd8SAndreas Gohr        // All Animals at once
84*1da41c8bSAndreas Gohr        $bulkForm = new Form();
85af1c6dd8SAndreas Gohr        $bulkForm->id('farmer__pluginsforall');
86fc6a7cc1SMichael Große        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
87af1c6dd8SAndreas Gohr        $bulkForm->addDropdown('bulk_plugin', $plugins);
88*1da41c8bSAndreas Gohr        $bulkForm->addButton('state', $this->getLang('default'))
89*1da41c8bSAndreas Gohr            ->attr('value', '-1')
90*1da41c8bSAndreas Gohr            ->attr('type', 'submit')
91*1da41c8bSAndreas Gohr            ->attr('disabled', 'disabled');
92*1da41c8bSAndreas Gohr        $bulkForm->addButton('state', $this->getLang('activate'))
93*1da41c8bSAndreas Gohr            ->attr('value', '1')
94*1da41c8bSAndreas Gohr            ->attr('type', 'submit')
95*1da41c8bSAndreas Gohr            ->attr('disabled', 'disabled');
96*1da41c8bSAndreas Gohr        $bulkForm->addButton('state', $this->getLang('deactivate'))
97*1da41c8bSAndreas Gohr            ->attr('value', '0')
98*1da41c8bSAndreas Gohr            ->attr('type', 'submit')
99*1da41c8bSAndreas Gohr            ->attr('disabled', 'disabled');
100415bff3cSMichael Große        $bulkForm->addFieldsetClose();
1010b96e6d7SMichael Große        echo $bulkForm->toHTML();
1020b96e6d7SMichael Große
103d3a4cfaaSAndreas Gohr        $animals = $helper->getAllAnimals();
104d3a4cfaaSAndreas Gohr        array_unshift($animals, '');
105d3a4cfaaSAndreas Gohr
106af1c6dd8SAndreas Gohr        // One Animal, all the plugins
107*1da41c8bSAndreas Gohr        $singleForm = new Form();
108af1c6dd8SAndreas Gohr        $singleForm->id('farmer__pluginsforone');
109fc6a7cc1SMichael Große        $singleForm->addFieldsetOpen($this->getLang('singleEditForm'));
110af1c6dd8SAndreas Gohr        $singleForm->addDropdown('bulk_animal', $animals);
111af1c6dd8SAndreas Gohr        $singleForm->addTagOpen('div')->addClass('output');
112415bff3cSMichael Große        $singleForm->addTagClose('div');
113*1da41c8bSAndreas Gohr        $singleForm->addButton('save', $this->getLang('save'))
114*1da41c8bSAndreas Gohr            ->attr('disabled', 'disabled');
115af1c6dd8SAndreas Gohr
1160b96e6d7SMichael Große        echo $singleForm->toHTML();
117511d09feSAndreas Gohr
118511d09feSAndreas Gohr
119511d09feSAndreas Gohr        echo '<div id="farmer__pluginmatrix"></div>';
120bc461538SMichael Große    }
121bc461538SMichael Große}
122