xref: /plugin/farmer/admin/plugins.php (revision 78c63d53eceed4e4fefa3c3a46e14844b75d6565)
1<?php
2/**
3 * DokuWiki Plugin farmer (Admin Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Große <grosse@cosmocode.de>
7 * @author  Andreas Gohr <gohr@cosmocode.de>
8 */
9
10// must be run within Dokuwiki
11if(!defined('DOKU_INC')) die();
12
13/**
14 * Manage Animal Plugin settings
15 */
16class admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin {
17
18    /** @var helper_plugin_farmer $helper */
19    private $helper;
20
21    public function __construct() {
22        $this->helper = plugin_load('helper', 'farmer');
23    }
24
25    /**
26     * handle user request
27     */
28    public function handle() {
29        global $INPUT;
30
31        if($INPUT->has('farmer__submitBulk')) {
32            $animals = $this->helper->getAllAnimals();
33            $plugin = $INPUT->str('farmer__bulkPluginSelect');
34            foreach($animals as $animal) {
35                if($INPUT->str('farmer__submitBulk') === 'activate') {
36                    $this->helper->activatePlugin($plugin, $animal);
37                } else {
38                    $this->helper->deactivatePlugin($plugin, $animal);
39                }
40            }
41        }
42        if($INPUT->has('plugin_farmer')) {
43            $inputArray = $INPUT->arr('plugin_farmer');
44            if($inputArray['submit_type'] === 'updateSingleAnimal') {
45                $animal = $inputArray ['selectedAnimal'];
46                $allPlugins = $this->helper->getAllPlugins();
47                $activePlugins = $INPUT->arr('plugin_farmer_plugins');
48                foreach($allPlugins as $plugin) {
49                    if(isset($activePlugins[$plugin]) &&
50                        $activePlugins[$plugin] === 'on'
51                    ) {
52                        $this->helper->activatePlugin($plugin, $animal);
53                    } else {
54                        $this->helper->deactivatePlugin($plugin, $animal);
55                    }
56                }
57            }
58        }
59    }
60
61    /**
62     * output appropriate html
63     */
64    public function html() {
65
66        echo $this->locale_xhtml('plugins');
67        $switchForm = new \dokuwiki\Form\Form();
68        $switchForm->addClass('plugin_farmer');
69        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
70        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio');
71        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio');
72        $switchForm->addFieldsetClose();
73        echo $switchForm->toHTML();
74
75        /** @var helper_plugin_farmer $helper */
76        $helper = plugin_load('helper', 'farmer');
77        $plugins = $helper->getAllPlugins();
78        array_unshift($plugins, '');
79
80        $bulkForm = new \dokuwiki\Form\Form();
81        $bulkForm->id('farmer__bulkForm');
82        $bulkForm->addClass('plugin_farmer');
83        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
84        $bulkForm->addDropdown('farmer__bulkPluginSelect', $plugins)->id('farmer__bulkPluginSelect');
85        $bulkForm->addButton('farmer__submitBulk', $this->getLang('activate'))->attr('value', 'activate')->attr('type', 'submit')->attr('disabled', 'disabled');
86        $bulkForm->addButton('farmer__submitBulk', $this->getLang('deactivate'))->attr('value', 'deactivate')->attr('type', 'submit')->attr('disabled', 'disabled');
87        $bulkForm->addFieldsetClose();
88        echo $bulkForm->toHTML();
89
90        $animals = $helper->getAllAnimals();
91        array_unshift($animals, '');
92
93        $singleForm = new \dokuwiki\Form\Form();
94        $singleForm->id('farmer__singlePluginForm');
95        $singleForm->addClass('plugin_farmer');
96        $singleForm->addFieldsetOpen($this->getLang('singleEditForm'));
97        $singleForm->addDropdown('plugin_farmer[selectedAnimal]', $animals)->id('farmer__animalSelect');
98        $singleForm->addTagOpen('div')->id('farmer__animalPlugins');
99        $singleForm->addTagClose('div');
100        $switchForm->addFieldsetClose();
101        echo $singleForm->toHTML();
102    }
103}
104
105