1<?php 2/** 3 * DokuWiki Plugin farmer (Admin Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Michael Große <grosse@cosmocode.de> 7 * @author Andreas Gohr <gohr@cosmocode.de> 8 */ 9 10// must be run within Dokuwiki 11if(!defined('DOKU_INC')) die(); 12 13/** 14 * Manage Animal Plugin settings 15 */ 16class admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin { 17 18 /** @var helper_plugin_farmer $helper */ 19 private $helper; 20 21 public function __construct() { 22 $this->helper = plugin_load('helper', 'farmer'); 23 } 24 25 /** 26 * handle user request 27 */ 28 public function handle() { 29 global $INPUT; 30 31 if(!$this->helper->checkFarmSetup()) { 32 $this->helper->reloadAdminPage('farmer_createAnimal'); 33 } 34 35 if($INPUT->has('farmer__submitBulk')) { 36 $animals = $this->helper->getAllAnimals(); 37 $plugin = $INPUT->str('farmer__bulkPluginSelect'); 38 foreach($animals as $animal) { 39 if($INPUT->str('farmer__submitBulk') === 'activate') { 40 $this->helper->activatePlugin($plugin, $animal); 41 } else { 42 $this->helper->deactivatePlugin($plugin, $animal); 43 } 44 } 45 } 46 if($INPUT->has('plugin_farmer')) { 47 $inputArray = $INPUT->arr('plugin_farmer'); 48 if($inputArray['submit_type'] === 'updateSingleAnimal') { 49 $animal = $inputArray ['selectedAnimal']; 50 $allPlugins = $this->helper->getAllPlugins(); 51 $activePlugins = $INPUT->arr('plugin_farmer_plugins'); 52 foreach($allPlugins as $plugin) { 53 if(isset($activePlugins[$plugin]) && 54 $activePlugins[$plugin] === 'on' 55 ) { 56 $this->helper->activatePlugin($plugin, $animal); 57 } else { 58 $this->helper->deactivatePlugin($plugin, $animal); 59 } 60 } 61 } 62 } 63 } 64 65 /** 66 * output appropriate html 67 */ 68 public function html() { 69 70 echo $this->locale_xhtml('plugins'); 71 $switchForm = new \dokuwiki\Form\Form(); 72 $switchForm->addClass('plugin_farmer'); 73 $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 74 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio'); 75 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio'); 76 $switchForm->addFieldsetClose(); 77 echo $switchForm->toHTML(); 78 79 /** @var helper_plugin_farmer $helper */ 80 $helper = plugin_load('helper', 'farmer'); 81 $plugins = $helper->getAllPlugins(); 82 array_unshift($plugins, ''); 83 84 $bulkForm = new \dokuwiki\Form\Form(); 85 $bulkForm->id('farmer__bulkForm'); 86 $bulkForm->addClass('plugin_farmer'); 87 $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 88 $bulkForm->addDropdown('farmer__bulkPluginSelect', $plugins)->id('farmer__bulkPluginSelect'); 89 $bulkForm->addButton('farmer__submitBulk', $this->getLang('activate'))->attr('value', 'activate')->attr('type', 'submit')->attr('disabled', 'disabled'); 90 $bulkForm->addButton('farmer__submitBulk', $this->getLang('deactivate'))->attr('value', 'deactivate')->attr('type', 'submit')->attr('disabled', 'disabled'); 91 $bulkForm->addFieldsetClose(); 92 echo $bulkForm->toHTML(); 93 94 $animals = $helper->getAllAnimals(); 95 array_unshift($animals, ''); 96 97 $singleForm = new \dokuwiki\Form\Form(); 98 $singleForm->id('farmer__singlePluginForm'); 99 $singleForm->addClass('plugin_farmer'); 100 $singleForm->addFieldsetOpen($this->getLang('singleEditForm')); 101 $singleForm->addDropdown('plugin_farmer[selectedAnimal]', $animals)->id('farmer__animalSelect'); 102 $singleForm->addTagOpen('div')->id('farmer__animalPlugins'); 103 $singleForm->addTagClose('div'); 104 $switchForm->addFieldsetClose(); 105 echo $singleForm->toHTML(); 106 } 107} 108 109