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; 30*114a05a7SAndreas Gohr global $ID; 31*114a05a7SAndreas Gohr 32*114a05a7SAndreas Gohr $self = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'), true, '&'); 33bc461538SMichael Große 3437a9ac83SMichael Große if($INPUT->has('farmer__submitBulk')) { 35c4a48750SMichael Große $animals = $this->helper->getAllAnimals(); 3637a9ac83SMichael Große $plugin = $INPUT->str('farmer__bulkPluginSelect'); 370b96e6d7SMichael Große foreach($animals as $animal) { 3837a9ac83SMichael Große if($INPUT->str('farmer__submitBulk') === 'activate') { 39c4a48750SMichael Große $this->helper->activatePlugin($plugin, $animal); 400b96e6d7SMichael Große } else { 41c4a48750SMichael Große $this->helper->deactivatePlugin($plugin, $animal); 42bc461538SMichael Große } 43bc461538SMichael Große } 44*114a05a7SAndreas Gohr msg($this->getLang('plugindone'), 1); 45*114a05a7SAndreas Gohr send_redirect($self); 46c4a48750SMichael Große } 4737a9ac83SMichael Große if($INPUT->has('plugin_farmer')) { 4837a9ac83SMichael Große $inputArray = $INPUT->arr('plugin_farmer'); 4937a9ac83SMichael Große if($inputArray['submit_type'] === 'updateSingleAnimal') { 5037a9ac83SMichael Große $animal = $inputArray ['selectedAnimal']; 51c4a48750SMichael Große $allPlugins = $this->helper->getAllPlugins(); 5237a9ac83SMichael Große $activePlugins = $INPUT->arr('plugin_farmer_plugins'); 53c4a48750SMichael Große foreach($allPlugins as $plugin) { 5437a9ac83SMichael Große if(isset($activePlugins[$plugin]) && 550a5d2da2SAndreas Gohr $activePlugins[$plugin] === 'on' 560a5d2da2SAndreas Gohr ) { 57c4a48750SMichael Große $this->helper->activatePlugin($plugin, $animal); 58c4a48750SMichael Große } else { 59c4a48750SMichael Große $this->helper->deactivatePlugin($plugin, $animal); 60bc461538SMichael Große } 610b96e6d7SMichael Große } 620b96e6d7SMichael Große } 63*114a05a7SAndreas Gohr msg($this->getLang('plugindone'), 1); 64*114a05a7SAndreas Gohr send_redirect($self); 650b96e6d7SMichael Große } 66bc461538SMichael Große } 67bc461538SMichael Große 68bc461538SMichael Große /** 69bc461538SMichael Große * output appropriate html 70bc461538SMichael Große */ 710b96e6d7SMichael Große public function html() { 72bc461538SMichael Große 739ed791b7SMichael Große echo $this->locale_xhtml('plugins'); 740b96e6d7SMichael Große $switchForm = new \dokuwiki\Form\Form(); 75e71d78f4SMichael Große $switchForm->addClass('plugin_farmer'); 76fc6a7cc1SMichael Große $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 77d3a4cfaaSAndreas Gohr $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio'); 78d3a4cfaaSAndreas Gohr $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio'); 790b96e6d7SMichael Große $switchForm->addFieldsetClose(); 800b96e6d7SMichael Große echo $switchForm->toHTML(); 81bc461538SMichael Große 820b96e6d7SMichael Große /** @var helper_plugin_farmer $helper */ 830b96e6d7SMichael Große $helper = plugin_load('helper', 'farmer'); 840b96e6d7SMichael Große $plugins = $helper->getAllPlugins(); 85d3a4cfaaSAndreas Gohr array_unshift($plugins, ''); 860b96e6d7SMichael Große 870b96e6d7SMichael Große $bulkForm = new \dokuwiki\Form\Form(); 880b96e6d7SMichael Große $bulkForm->id('farmer__bulkForm'); 89e71d78f4SMichael Große $bulkForm->addClass('plugin_farmer'); 90fc6a7cc1SMichael Große $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 91d3a4cfaaSAndreas Gohr $bulkForm->addDropdown('farmer__bulkPluginSelect', $plugins)->id('farmer__bulkPluginSelect'); 92d3a4cfaaSAndreas Gohr $bulkForm->addButton('farmer__submitBulk', $this->getLang('activate'))->attr('value', 'activate')->attr('type', 'submit')->attr('disabled', 'disabled'); 93d3a4cfaaSAndreas Gohr $bulkForm->addButton('farmer__submitBulk', $this->getLang('deactivate'))->attr('value', 'deactivate')->attr('type', 'submit')->attr('disabled', 'disabled'); 94415bff3cSMichael Große $bulkForm->addFieldsetClose(); 950b96e6d7SMichael Große echo $bulkForm->toHTML(); 960b96e6d7SMichael Große 97d3a4cfaaSAndreas Gohr $animals = $helper->getAllAnimals(); 98d3a4cfaaSAndreas Gohr array_unshift($animals, ''); 99d3a4cfaaSAndreas Gohr 1000b96e6d7SMichael Große $singleForm = new \dokuwiki\Form\Form(); 1010b96e6d7SMichael Große $singleForm->id('farmer__singlePluginForm'); 102e71d78f4SMichael Große $singleForm->addClass('plugin_farmer'); 103fc6a7cc1SMichael Große $singleForm->addFieldsetOpen($this->getLang('singleEditForm')); 104d3a4cfaaSAndreas Gohr $singleForm->addDropdown('plugin_farmer[selectedAnimal]', $animals)->id('farmer__animalSelect'); 105415bff3cSMichael Große $singleForm->addTagOpen('div')->id('farmer__animalPlugins'); 106415bff3cSMichael Große $singleForm->addTagClose('div'); 107ae93adddSMichael Große $switchForm->addFieldsetClose(); 1080b96e6d7SMichael Große echo $singleForm->toHTML(); 109bc461538SMichael Große } 110bc461538SMichael Große} 111bc461538SMichael Große 112