xref: /plugin/farmer/admin/plugins.php (revision 0a5d2da2d569b70aa9be68458b77b2616f382e97)
1bc461538SMichael Große<?php
2bc461538SMichael Große/**
3*0a5d2da2SAndreas Gohr * DokuWiki Plugin farmer (Admin Component)
4bc461538SMichael Große *
5*0a5d2da2SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6*0a5d2da2SAndreas Gohr * @author  Michael Große <grosse@cosmocode.de>
7*0a5d2da2SAndreas Gohr * @author  Andreas Gohr <gohr@cosmocode.de>
8bc461538SMichael Große */
9bc461538SMichael Große
10*0a5d2da2SAndreas Gohr// must be run within Dokuwiki
11*0a5d2da2SAndreas Gohrif(!defined('DOKU_INC')) die();
12bc461538SMichael Große
13bc461538SMichael Große/**
14*0a5d2da2SAndreas Gohr * Manage Animal Plugin settings
15bc461538SMichael Große */
16bc461538SMichael Großeclass admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin {
17bc461538SMichael Große
18c4a48750SMichael Große    /** @var helper_plugin_farmer $helper */
19c4a48750SMichael Große    private $helper;
20c4a48750SMichael Große
2165dd3ddfSAndreas Gohr    public function __construct() {
2265dd3ddfSAndreas Gohr        $this->helper = plugin_load('helper', 'farmer');
2365dd3ddfSAndreas Gohr    }
2465dd3ddfSAndreas Gohr
25bc461538SMichael Große    /**
26bc461538SMichael Große     * handle user request
27bc461538SMichael Große     */
280b96e6d7SMichael Große    public function handle() {
2937a9ac83SMichael Große        global $INPUT;
30bc461538SMichael Große
31d9ec4524SMichael Große        if(!$this->helper->checkFarmSetup()) {
324d120480SMichael Große            $this->helper->reloadAdminPage('farmer_createAnimal');
33bc461538SMichael Große        }
34bc461538SMichael Große
3537a9ac83SMichael Große        if($INPUT->has('farmer__submitBulk')) {
36c4a48750SMichael Große            $animals = $this->helper->getAllAnimals();
3737a9ac83SMichael Große            $plugin = $INPUT->str('farmer__bulkPluginSelect');
380b96e6d7SMichael Große            foreach($animals as $animal) {
3937a9ac83SMichael Große                if($INPUT->str('farmer__submitBulk') === 'activate') {
40c4a48750SMichael Große                    $this->helper->activatePlugin($plugin, $animal);
410b96e6d7SMichael Große                } else {
42c4a48750SMichael Große                    $this->helper->deactivatePlugin($plugin, $animal);
43bc461538SMichael Große                }
44bc461538SMichael Große            }
45c4a48750SMichael Große        }
4637a9ac83SMichael Große        if($INPUT->has('plugin_farmer')) {
4737a9ac83SMichael Große            $inputArray = $INPUT->arr('plugin_farmer');
4837a9ac83SMichael Große            if($inputArray['submit_type'] === 'updateSingleAnimal') {
4937a9ac83SMichael Große                $animal = $inputArray ['selectedAnimal'];
50c4a48750SMichael Große                $allPlugins = $this->helper->getAllPlugins();
5137a9ac83SMichael Große                $activePlugins = $INPUT->arr('plugin_farmer_plugins');
52c4a48750SMichael Große                foreach($allPlugins as $plugin) {
5337a9ac83SMichael Große                    if(isset($activePlugins[$plugin]) &&
54*0a5d2da2SAndreas Gohr                        $activePlugins[$plugin] === 'on'
55*0a5d2da2SAndreas Gohr                    ) {
56c4a48750SMichael Große                        $this->helper->activatePlugin($plugin, $animal);
57c4a48750SMichael Große                    } else {
58c4a48750SMichael Große                        $this->helper->deactivatePlugin($plugin, $animal);
59bc461538SMichael Große                    }
600b96e6d7SMichael Große                }
610b96e6d7SMichael Große            }
620b96e6d7SMichael Große        }
63bc461538SMichael Große    }
64bc461538SMichael Große
65bc461538SMichael Große    /**
66bc461538SMichael Große     * output appropriate html
67bc461538SMichael Große     */
680b96e6d7SMichael Große    public function html() {
69bc461538SMichael Große
709ed791b7SMichael Große        echo $this->locale_xhtml('plugins');
710b96e6d7SMichael Große        $switchForm = new \dokuwiki\Form\Form();
72e71d78f4SMichael Große        $switchForm->addClass('plugin_farmer');
73fc6a7cc1SMichael Große        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
74d3a4cfaaSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio');
75d3a4cfaaSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio');
760b96e6d7SMichael Große        $switchForm->addFieldsetClose();
770b96e6d7SMichael Große        echo $switchForm->toHTML();
78bc461538SMichael Große
790b96e6d7SMichael Große        /** @var helper_plugin_farmer $helper */
800b96e6d7SMichael Große        $helper = plugin_load('helper', 'farmer');
810b96e6d7SMichael Große        $plugins = $helper->getAllPlugins();
82d3a4cfaaSAndreas Gohr        array_unshift($plugins, '');
830b96e6d7SMichael Große
840b96e6d7SMichael Große        $bulkForm = new \dokuwiki\Form\Form();
850b96e6d7SMichael Große        $bulkForm->id('farmer__bulkForm');
86e71d78f4SMichael Große        $bulkForm->addClass('plugin_farmer');
87fc6a7cc1SMichael Große        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
88d3a4cfaaSAndreas Gohr        $bulkForm->addDropdown('farmer__bulkPluginSelect', $plugins)->id('farmer__bulkPluginSelect');
89d3a4cfaaSAndreas Gohr        $bulkForm->addButton('farmer__submitBulk', $this->getLang('activate'))->attr('value', 'activate')->attr('type', 'submit')->attr('disabled', 'disabled');
90d3a4cfaaSAndreas Gohr        $bulkForm->addButton('farmer__submitBulk', $this->getLang('deactivate'))->attr('value', 'deactivate')->attr('type', 'submit')->attr('disabled', 'disabled');
91415bff3cSMichael Große        $bulkForm->addFieldsetClose();
920b96e6d7SMichael Große        echo $bulkForm->toHTML();
930b96e6d7SMichael Große
94d3a4cfaaSAndreas Gohr        $animals = $helper->getAllAnimals();
95d3a4cfaaSAndreas Gohr        array_unshift($animals, '');
96d3a4cfaaSAndreas Gohr
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'));
101d3a4cfaaSAndreas Gohr        $singleForm->addDropdown('plugin_farmer[selectedAnimal]', $animals)->id('farmer__animalSelect');
102415bff3cSMichael Große        $singleForm->addTagOpen('div')->id('farmer__animalPlugins');
103415bff3cSMichael Große        $singleForm->addTagClose('div');
104ae93adddSMichael Große        $switchForm->addFieldsetClose();
1050b96e6d7SMichael Große        echo $singleForm->toHTML();
106bc461538SMichael Große    }
107bc461538SMichael Große}
108bc461538SMichael Große
109