xref: /plugin/farmer/admin/plugins.php (revision 37a9ac83856cd935c637fbd5495efcad96d4abd9)
1bc461538SMichael Große<?php
2bc461538SMichael Große/**
3bc461538SMichael Große * Plugin Skeleton: Displays "Hello World!"
4bc461538SMichael Große *
5bc461538SMichael Große * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6bc461538SMichael Große * @author     Christopher Smith <chris@jalakai.co.uk>
7bc461538SMichael Große */
8bc461538SMichael Große
9bc461538SMichael Große
10bc461538SMichael Große/**
11bc461538SMichael Große * All DokuWiki plugins to extend the admin function
12bc461538SMichael Große * need to inherit from this class
13bc461538SMichael Große */
14bc461538SMichael Großeclass admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin {
15bc461538SMichael Große
16c4a48750SMichael Große    /** @var helper_plugin_farmer $helper */
17c4a48750SMichael Große    private $helper;
18c4a48750SMichael Große
19bc461538SMichael Große    /**
20bc461538SMichael Große     * handle user request
21bc461538SMichael Große     */
220b96e6d7SMichael Große    public function handle() {
23*37a9ac83SMichael Große        global $INPUT;
24c4a48750SMichael Große        $this->helper = plugin_load('helper', 'farmer');
25bc461538SMichael Große
26d9ec4524SMichael Große        if (!$this->helper->checkFarmSetup()) {
274d120480SMichael Große            $this->helper->reloadAdminPage('farmer_createAnimal');
28bc461538SMichael Große        }
29bc461538SMichael Große
30*37a9ac83SMichael Große        if ($INPUT->has('farmer__submitBulk')) {
31c4a48750SMichael Große            $animals = $this->helper->getAllAnimals();
32*37a9ac83SMichael Große            $plugin = $INPUT->str('farmer__bulkPluginSelect');
330b96e6d7SMichael Große            foreach ($animals as $animal) {
34*37a9ac83SMichael Große                if ($INPUT->str('farmer__submitBulk') === 'activate') {
35c4a48750SMichael Große                    $this->helper->activatePlugin($plugin, $animal);
360b96e6d7SMichael Große                } else {
37c4a48750SMichael Große                    $this->helper->deactivatePlugin($plugin, $animal);
38bc461538SMichael Große                }
39bc461538SMichael Große            }
40c4a48750SMichael Große        }
41*37a9ac83SMichael Große        if ($INPUT->has('plugin_farmer')) {
42*37a9ac83SMichael Große            $inputArray = $INPUT->arr('plugin_farmer');
43*37a9ac83SMichael Große            if ($inputArray['submit_type'] === 'updateSingleAnimal') {
44*37a9ac83SMichael Große                $animal = $inputArray ['selectedAnimal'];
45c4a48750SMichael Große                $allPlugins = $this->helper->getAllPlugins();
46*37a9ac83SMichael Große                $activePlugins = $INPUT->arr('plugin_farmer_plugins');
47c4a48750SMichael Große                foreach ($allPlugins as $plugin) {
48*37a9ac83SMichael Große                    if (isset($activePlugins[$plugin]) &&
49*37a9ac83SMichael Große                        $activePlugins[$plugin] === 'on') {
50c4a48750SMichael Große                        $this->helper->activatePlugin($plugin,$animal);
51c4a48750SMichael Große                    } else {
52c4a48750SMichael Große                        $this->helper->deactivatePlugin($plugin,$animal);
53bc461538SMichael Große                    }
540b96e6d7SMichael Große                }
550b96e6d7SMichael Große            }
560b96e6d7SMichael Große        }
57bc461538SMichael Große    }
58bc461538SMichael Große
59bc461538SMichael Große    /**
60bc461538SMichael Große     * output appropriate html
61bc461538SMichael Große     */
620b96e6d7SMichael Große    public function html() {
63bc461538SMichael Große        echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js"></script>';
64bc461538SMichael Große        echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css" type="text/css" rel="stylesheet" />';
65bc461538SMichael Große
669ed791b7SMichael Große        echo $this->locale_xhtml('plugins');
670b96e6d7SMichael Große        $switchForm = new \dokuwiki\Form\Form();
68e71d78f4SMichael Große        $switchForm->addClass('plugin_farmer');
69fc6a7cc1SMichael Große        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
70fc6a7cc1SMichael Große        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type','radio')->addClass('block');
71fc6a7cc1SMichael Große        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type','radio')->addClass('block');
720b96e6d7SMichael Große        $switchForm->addFieldsetClose();
730b96e6d7SMichael Große        echo $switchForm->toHTML();
74bc461538SMichael Große
750b96e6d7SMichael Große        /** @var helper_plugin_farmer $helper */
760b96e6d7SMichael Große        $helper = plugin_load('helper', 'farmer');
770b96e6d7SMichael Große        $plugins = $helper->getAllPlugins();
780b96e6d7SMichael Große
790b96e6d7SMichael Große        $bulkForm = new \dokuwiki\Form\Form();
800b96e6d7SMichael Große        $bulkForm->id('farmer__bulkForm');
81e71d78f4SMichael Große        $bulkForm->addClass('plugin_farmer');
82fc6a7cc1SMichael Große        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
83ae93adddSMichael Große        $bulkForm->addTagOpen('select')->id('farmer__bulkPluginSelect')->attr('name','farmer__bulkPluginSelect');
840b96e6d7SMichael Große        $bulkForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', "");
850b96e6d7SMichael Große        $bulkForm->addTagClose('option');
860b96e6d7SMichael Große        foreach ($plugins as $plugin) {
870b96e6d7SMichael Große            $bulkForm->addTagOpen('option')->attr('value', $plugin);
880b96e6d7SMichael Große            $bulkForm->addHTML($plugin);
890b96e6d7SMichael Große            $bulkForm->addTagClose('option');
900b96e6d7SMichael Große        }
910b96e6d7SMichael Große        $bulkForm->addTagClose('select');
92fc6a7cc1SMichael Große        $bulkForm->addButton('farmer__submitBulk',$this->getLang('activate'))->attr('value','activate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton');
93fc6a7cc1SMichael Große        $bulkForm->addButton('farmer__submitBulk',$this->getLang('deactivate'))->attr('value','deactivate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton');
94415bff3cSMichael Große        $bulkForm->addFieldsetClose();
950b96e6d7SMichael Große        echo $bulkForm->toHTML();
960b96e6d7SMichael Große
970b96e6d7SMichael Große        $singleForm = new \dokuwiki\Form\Form();
980b96e6d7SMichael Große        $singleForm->id('farmer__singlePluginForm');
99e71d78f4SMichael Große        $singleForm->addClass('plugin_farmer');
100fc6a7cc1SMichael Große        $singleForm->addFieldsetOpen($this->getLang('singleEditForm'));
101415bff3cSMichael Große        $singleForm->addTagOpen('select')->id('farmer__animalSelect')->attr('name', 'plugin_farmer[selectedAnimal]');
1020b96e6d7SMichael Große        $singleForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', "");
1030b96e6d7SMichael Große        $singleForm->addTagClose('option');
1040b96e6d7SMichael Große        $animals = $helper->getAllAnimals();
1050b96e6d7SMichael Große        foreach ($animals as $animal) {
1060b96e6d7SMichael Große            $singleForm->addTagOpen('option');
1070b96e6d7SMichael Große            $singleForm->addHTML($animal);
1080b96e6d7SMichael Große            $singleForm->addTagClose('option');
1090b96e6d7SMichael Große        }
1100b96e6d7SMichael Große        $singleForm->addTagClose('select');
111415bff3cSMichael Große        $singleForm->addTagOpen('div')->id('farmer__animalPlugins');
112415bff3cSMichael Große        $singleForm->addTagClose('div');
113ae93adddSMichael Große        $switchForm->addFieldsetClose();
1140b96e6d7SMichael Große        echo $singleForm->toHTML();
115bc461538SMichael Große    }
116bc461538SMichael Große
117bc461538SMichael Große    public function getMenuText() {
118bc461538SMichael Große        return 'Farmer: Change animal plugins';
119bc461538SMichael Große    }
120bc461538SMichael Große
121bc461538SMichael Große    public function getMenuSort() {
122bc461538SMichael Große        return 42;
123bc461538SMichael Große    }
124bc461538SMichael Große
125bc461538SMichael Große}
126bc461538SMichael Große
127