summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/farmer/admin/plugins.php
blob: 74f0e60a10d87c5c30b94d3c76c65ee393645f53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
 * DokuWiki Plugin farmer (Admin Component)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Michael Große <grosse@cosmocode.de>
 * @author  Andreas Gohr <gohr@cosmocode.de>
 */

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

/**
 * Manage Animal Plugin settings
 */
class admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin {

    /** @var helper_plugin_farmer $helper */
    private $helper;

    public function __construct() {
        $this->helper = plugin_load('helper', 'farmer');
    }

    /**
     * handle user request
     */
    public function handle() {
        global $INPUT;
        global $ID;

        $self = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'), true, '&');

        if($INPUT->has('bulk_plugin') && $INPUT->has('state')) {
            $animals = $this->helper->getAllAnimals();
            $plugin = $INPUT->str('bulk_plugin');
            foreach($animals as $animal) {
                $this->helper->setPluginState($plugin, $animal, $INPUT->int('state'));
            }
            msg($this->getLang('plugindone'), 1);
            send_redirect($self);
        }

        if($INPUT->has('bulk_animal') && $INPUT->has('bulk_plugins')) {
            $animal = $INPUT->str('bulk_animal');
            $activePlugins = $INPUT->arr('bulk_plugins');
            foreach($activePlugins as $plugin => $state) {
                $this->helper->setPluginState($plugin, $animal, $state);
            }
            msg($this->getLang('plugindone'), 1);
            send_redirect($self);
        }
    }

    /**
     * output appropriate html
     */
    public function html() {

        echo $this->locale_xhtml('plugins');
        $switchForm = new \dokuwiki\Form\Form();
        $switchForm->addClass('plugin_farmer');
        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio');
        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio');
        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('matrixEdit'))->id('farmer__matrix')->attr('type', 'radio');
        $switchForm->addFieldsetClose();
        echo $switchForm->toHTML();

        /** @var helper_plugin_farmer $helper */
        $helper = plugin_load('helper', 'farmer');
        $plugins = $helper->getAllPlugins();
        array_unshift($plugins, '');

        // All Animals at once
        $bulkForm = new \dokuwiki\Form\Form();
        $bulkForm->id('farmer__pluginsforall');
        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
        $bulkForm->addDropdown('bulk_plugin', $plugins);
        $bulkForm->addButton('state', $this->getLang('default'))->attr('value', '-1')->attr('type', 'submit')->attr('disabled', 'disabled');
        $bulkForm->addButton('state', $this->getLang('activate'))->attr('value', '1')->attr('type', 'submit')->attr('disabled', 'disabled');
        $bulkForm->addButton('state', $this->getLang('deactivate'))->attr('value', '0')->attr('type', 'submit')->attr('disabled', 'disabled');
        $bulkForm->addFieldsetClose();
        echo $bulkForm->toHTML();

        $animals = $helper->getAllAnimals();
        array_unshift($animals, '');

        // One Animal, all the plugins
        $singleForm = new \dokuwiki\Form\Form();
        $singleForm->id('farmer__pluginsforone');
        $singleForm->addFieldsetOpen($this->getLang('singleEditForm'));
        $singleForm->addDropdown('bulk_animal', $animals);
        $singleForm->addTagOpen('div')->addClass('output');
        $singleForm->addTagClose('div');
        $singleForm->addButton('save', $this->getLang('save'))->attr('disabled', 'disabled');

        echo $singleForm->toHTML();


        echo '<div id="farmer__pluginmatrix"></div>';
    }
}