xref: /plugin/farmer/admin/plugins.php (revision 511d09fe80aca707fd730d681ebdff69981eb7e4)
1bc461538SMichael Große<?php
2bc461538SMichael Große/**
30a5d2da2SAndreas Gohr * DokuWiki Plugin farmer (Admin Component)
4bc461538SMichael Große *
50a5d2da2SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
60a5d2da2SAndreas Gohr * @author  Michael Große <grosse@cosmocode.de>
70a5d2da2SAndreas Gohr * @author  Andreas Gohr <gohr@cosmocode.de>
8bc461538SMichael Große */
9bc461538SMichael Große
100a5d2da2SAndreas Gohr// must be run within Dokuwiki
110a5d2da2SAndreas Gohrif(!defined('DOKU_INC')) die();
12bc461538SMichael Große
13bc461538SMichael Große/**
140a5d2da2SAndreas 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;
30114a05a7SAndreas Gohr        global $ID;
31114a05a7SAndreas Gohr
32114a05a7SAndreas Gohr        $self = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'), true, '&');
33bc461538SMichael Große
34af1c6dd8SAndreas Gohr        if($INPUT->has('bulk_plugin') && $INPUT->has('state')) {
35c4a48750SMichael Große            $animals = $this->helper->getAllAnimals();
36af1c6dd8SAndreas Gohr            $plugin = $INPUT->str('bulk_plugin');
370b96e6d7SMichael Große            foreach($animals as $animal) {
38af1c6dd8SAndreas Gohr                $this->helper->setPluginState($plugin, $animal, $INPUT->int('state'));
39bc461538SMichael Große            }
40114a05a7SAndreas Gohr            msg($this->getLang('plugindone'), 1);
41114a05a7SAndreas Gohr            send_redirect($self);
42c4a48750SMichael Große        }
43af1c6dd8SAndreas Gohr
44af1c6dd8SAndreas Gohr        if($INPUT->has('bulk_animal') && $INPUT->has('bulk_plugins')) {
45af1c6dd8SAndreas Gohr            $animal = $INPUT->str('bulk_animal');
46af1c6dd8SAndreas Gohr            $activePlugins = $INPUT->arr('bulk_plugins');
47af1c6dd8SAndreas Gohr            foreach($activePlugins as $plugin => $state) {
48af1c6dd8SAndreas Gohr                $this->helper->setPluginState($plugin, $animal, $state);
490b96e6d7SMichael Große            }
50114a05a7SAndreas Gohr            msg($this->getLang('plugindone'), 1);
51114a05a7SAndreas Gohr            send_redirect($self);
520b96e6d7SMichael Große        }
53bc461538SMichael Große    }
54bc461538SMichael Große
55bc461538SMichael Große    /**
56bc461538SMichael Große     * output appropriate html
57bc461538SMichael Große     */
580b96e6d7SMichael Große    public function html() {
59bc461538SMichael Große
609ed791b7SMichael Große        echo $this->locale_xhtml('plugins');
610b96e6d7SMichael Große        $switchForm = new \dokuwiki\Form\Form();
62e71d78f4SMichael Große        $switchForm->addClass('plugin_farmer');
63fc6a7cc1SMichael Große        $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher'));
64d3a4cfaaSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio');
65d3a4cfaaSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio');
66*511d09feSAndreas Gohr        $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('matrixEdit'))->id('farmer__matrix')->attr('type', 'radio');
670b96e6d7SMichael Große        $switchForm->addFieldsetClose();
680b96e6d7SMichael Große        echo $switchForm->toHTML();
69bc461538SMichael Große
700b96e6d7SMichael Große        /** @var helper_plugin_farmer $helper */
710b96e6d7SMichael Große        $helper = plugin_load('helper', 'farmer');
720b96e6d7SMichael Große        $plugins = $helper->getAllPlugins();
73d3a4cfaaSAndreas Gohr        array_unshift($plugins, '');
740b96e6d7SMichael Große
75af1c6dd8SAndreas Gohr        // All Animals at once
760b96e6d7SMichael Große        $bulkForm = new \dokuwiki\Form\Form();
77af1c6dd8SAndreas Gohr        $bulkForm->id('farmer__pluginsforall');
78fc6a7cc1SMichael Große        $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm'));
79af1c6dd8SAndreas Gohr        $bulkForm->addDropdown('bulk_plugin', $plugins);
80af1c6dd8SAndreas Gohr        $bulkForm->addButton('state', $this->getLang('default'))->attr('value', '-1')->attr('type', 'submit')->attr('disabled', 'disabled');
81af1c6dd8SAndreas Gohr        $bulkForm->addButton('state', $this->getLang('activate'))->attr('value', '1')->attr('type', 'submit')->attr('disabled', 'disabled');
82af1c6dd8SAndreas Gohr        $bulkForm->addButton('state', $this->getLang('deactivate'))->attr('value', '0')->attr('type', 'submit')->attr('disabled', 'disabled');
83415bff3cSMichael Große        $bulkForm->addFieldsetClose();
840b96e6d7SMichael Große        echo $bulkForm->toHTML();
850b96e6d7SMichael Große
86d3a4cfaaSAndreas Gohr        $animals = $helper->getAllAnimals();
87d3a4cfaaSAndreas Gohr        array_unshift($animals, '');
88d3a4cfaaSAndreas Gohr
89af1c6dd8SAndreas Gohr        // One Animal, all the plugins
900b96e6d7SMichael Große        $singleForm = new \dokuwiki\Form\Form();
91af1c6dd8SAndreas Gohr        $singleForm->id('farmer__pluginsforone');
92fc6a7cc1SMichael Große        $singleForm->addFieldsetOpen($this->getLang('singleEditForm'));
93af1c6dd8SAndreas Gohr        $singleForm->addDropdown('bulk_animal', $animals);
94af1c6dd8SAndreas Gohr        $singleForm->addTagOpen('div')->addClass('output');
95415bff3cSMichael Große        $singleForm->addTagClose('div');
96af1c6dd8SAndreas Gohr        $singleForm->addButton('save', $this->getLang('save'))->attr('disabled', 'disabled');
97af1c6dd8SAndreas Gohr
980b96e6d7SMichael Große        echo $singleForm->toHTML();
99*511d09feSAndreas Gohr
100*511d09feSAndreas Gohr
101*511d09feSAndreas Gohr        echo '<div id="farmer__pluginmatrix"></div>';
102bc461538SMichael Große    }
103bc461538SMichael Große}
104bc461538SMichael Große
105