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