xref: /plugin/farmer/admin/plugins.php (revision 341a2d3514259f15502840e8abd56a11b4085405)
1bc461538SMichael Große<?php
21da41c8bSAndreas Gohr
31da41c8bSAndreas Gohruse dokuwiki\Extension\AdminPlugin;
41da41c8bSAndreas Gohruse dokuwiki\Form\Form;
51da41c8bSAndreas Gohr
6bc461538SMichael Große/**
70a5d2da2SAndreas Gohr * DokuWiki Plugin farmer (Admin Component)
8bc461538SMichael Große *
91da41c8bSAndreas Gohr * Manage Animal Plugin settings
101da41c8bSAndreas 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 */
151da41c8bSAndreas Gohrclass admin_plugin_farmer_plugins extends AdminPlugin
161da41c8bSAndreas Gohr{
17c4a48750SMichael Große    /** @var helper_plugin_farmer $helper */
18c4a48750SMichael Große    private $helper;
19c4a48750SMichael Große
201da41c8bSAndreas Gohr    public function __construct()
211da41c8bSAndreas Gohr    {
2265dd3ddfSAndreas Gohr        $this->helper = plugin_load('helper', 'farmer');
2365dd3ddfSAndreas Gohr    }
2465dd3ddfSAndreas Gohr
25*341a2d35SAndreas Gohr    /** @inheritdoc */
26*341a2d35SAndreas Gohr    public function showInMenu()
27*341a2d35SAndreas Gohr    {
28*341a2d35SAndreas Gohr        return false;
29*341a2d35SAndreas Gohr    }
30*341a2d35SAndreas Gohr
31*341a2d35SAndreas Gohr    /** @inheritdoc */
321da41c8bSAndreas Gohr    public function handle()
331da41c8bSAndreas Gohr    {
3437a9ac83SMichael Große        global $INPUT;
35114a05a7SAndreas Gohr        global $ID;
36114a05a7SAndreas Gohr
371da41c8bSAndreas Gohr        $self = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'], true, '&');
38bc461538SMichael Große
39af1c6dd8SAndreas Gohr        if ($INPUT->has('bulk_plugin') && $INPUT->has('state')) {
40c4a48750SMichael Große            $animals = $this->helper->getAllAnimals();
41af1c6dd8SAndreas Gohr            $plugin = $INPUT->str('bulk_plugin');
420b96e6d7SMichael Große            foreach ($animals as $animal) {
43af1c6dd8SAndreas Gohr                $this->helper->setPluginState($plugin, $animal, $INPUT->int('state'));
44bc461538SMichael Große            }
45114a05a7SAndreas Gohr            msg($this->getLang('plugindone'), 1);
46114a05a7SAndreas Gohr            send_redirect($self);
47c4a48750SMichael Große        }
48af1c6dd8SAndreas Gohr
49af1c6dd8SAndreas Gohr        if ($INPUT->has('bulk_animal') && $INPUT->has('bulk_plugins')) {
50af1c6dd8SAndreas Gohr            $animal = $INPUT->str('bulk_animal');
51af1c6dd8SAndreas Gohr            $activePlugins = $INPUT->arr('bulk_plugins');
52af1c6dd8SAndreas Gohr            foreach ($activePlugins as $plugin => $state) {
53af1c6dd8SAndreas Gohr                $this->helper->setPluginState($plugin, $animal, $state);
540b96e6d7SMichael Große            }
55114a05a7SAndreas Gohr            msg($this->getLang('plugindone'), 1);
56114a05a7SAndreas Gohr            send_redirect($self);
570b96e6d7SMichael Große        }
58bc461538SMichael Große    }
59bc461538SMichael Große
60*341a2d35SAndreas Gohr    /** @inheritdoc */
611da41c8bSAndreas Gohr    public function html()
621da41c8bSAndreas Gohr    {
63bc461538SMichael Große
649ed791b7SMichael Große        echo $this->locale_xhtml('plugins');
651da41c8bSAndreas Gohr        $switchForm = new Form();
66e71d78f4SMichael Große        $switchForm->addClass('plugin_farmer');
67fc6a7cc1SMichael Große        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
681da41c8bSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))
691da41c8bSAndreas Gohr            ->id('farmer__bulk')
701da41c8bSAndreas Gohr            ->attr('type', 'radio');
711da41c8bSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))
721da41c8bSAndreas Gohr            ->id('farmer__single')
731da41c8bSAndreas Gohr            ->attr('type', 'radio');
741da41c8bSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('matrixEdit'))
751da41c8bSAndreas Gohr            ->id('farmer__matrix')
761da41c8bSAndreas Gohr            ->attr('type', 'radio');
770b96e6d7SMichael Große        $switchForm->addFieldsetClose();
780b96e6d7SMichael Große        echo $switchForm->toHTML();
79bc461538SMichael Große
800b96e6d7SMichael Große        /** @var helper_plugin_farmer $helper */
810b96e6d7SMichael Große        $helper = plugin_load('helper', 'farmer');
820b96e6d7SMichael Große        $plugins = $helper->getAllPlugins();
83d3a4cfaaSAndreas Gohr        array_unshift($plugins, '');
840b96e6d7SMichael Große
85af1c6dd8SAndreas Gohr        // All Animals at once
861da41c8bSAndreas Gohr        $bulkForm = new Form();
87af1c6dd8SAndreas Gohr        $bulkForm->id('farmer__pluginsforall');
88fc6a7cc1SMichael Große        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
89af1c6dd8SAndreas Gohr        $bulkForm->addDropdown('bulk_plugin', $plugins);
901da41c8bSAndreas Gohr        $bulkForm->addButton('state', $this->getLang('default'))
911da41c8bSAndreas Gohr            ->attr('value', '-1')
921da41c8bSAndreas Gohr            ->attr('type', 'submit')
931da41c8bSAndreas Gohr            ->attr('disabled', 'disabled');
941da41c8bSAndreas Gohr        $bulkForm->addButton('state', $this->getLang('activate'))
951da41c8bSAndreas Gohr            ->attr('value', '1')
961da41c8bSAndreas Gohr            ->attr('type', 'submit')
971da41c8bSAndreas Gohr            ->attr('disabled', 'disabled');
981da41c8bSAndreas Gohr        $bulkForm->addButton('state', $this->getLang('deactivate'))
991da41c8bSAndreas Gohr            ->attr('value', '0')
1001da41c8bSAndreas Gohr            ->attr('type', 'submit')
1011da41c8bSAndreas Gohr            ->attr('disabled', 'disabled');
102415bff3cSMichael Große        $bulkForm->addFieldsetClose();
1030b96e6d7SMichael Große        echo $bulkForm->toHTML();
1040b96e6d7SMichael Große
105d3a4cfaaSAndreas Gohr        $animals = $helper->getAllAnimals();
106d3a4cfaaSAndreas Gohr        array_unshift($animals, '');
107d3a4cfaaSAndreas Gohr
108af1c6dd8SAndreas Gohr        // One Animal, all the plugins
1091da41c8bSAndreas Gohr        $singleForm = new Form();
110af1c6dd8SAndreas Gohr        $singleForm->id('farmer__pluginsforone');
111fc6a7cc1SMichael Große        $singleForm->addFieldsetOpen($this->getLang('singleEditForm'));
112af1c6dd8SAndreas Gohr        $singleForm->addDropdown('bulk_animal', $animals);
113af1c6dd8SAndreas Gohr        $singleForm->addTagOpen('div')->addClass('output');
114415bff3cSMichael Große        $singleForm->addTagClose('div');
1151da41c8bSAndreas Gohr        $singleForm->addButton('save', $this->getLang('save'))
1161da41c8bSAndreas Gohr            ->attr('disabled', 'disabled');
117af1c6dd8SAndreas Gohr
1180b96e6d7SMichael Große        echo $singleForm->toHTML();
119511d09feSAndreas Gohr
120511d09feSAndreas Gohr
121511d09feSAndreas Gohr        echo '<div id="farmer__pluginmatrix"></div>';
122bc461538SMichael Große    }
123bc461538SMichael Große}
124