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 global $ID; 31 32 $self = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'), true, '&'); 33 34 if($INPUT->has('farmer__submitBulk')) { 35 $animals = $this->helper->getAllAnimals(); 36 $plugin = $INPUT->str('farmer__bulkPluginSelect'); 37 foreach($animals as $animal) { 38 if($INPUT->str('farmer__submitBulk') === 'activate') { 39 $this->helper->activatePlugin($plugin, $animal); 40 } else { 41 $this->helper->deactivatePlugin($plugin, $animal); 42 } 43 } 44 msg($this->getLang('plugindone'), 1); 45 send_redirect($self); 46 } 47 if($INPUT->has('plugin_farmer')) { 48 $inputArray = $INPUT->arr('plugin_farmer'); 49 if($inputArray['submit_type'] === 'updateSingleAnimal') { 50 $animal = $inputArray ['selectedAnimal']; 51 $allPlugins = $this->helper->getAllPlugins(); 52 $activePlugins = $INPUT->arr('plugin_farmer_plugins'); 53 foreach($allPlugins as $plugin) { 54 if(isset($activePlugins[$plugin]) && 55 $activePlugins[$plugin] === 'on' 56 ) { 57 $this->helper->activatePlugin($plugin, $animal); 58 } else { 59 $this->helper->deactivatePlugin($plugin, $animal); 60 } 61 } 62 } 63 msg($this->getLang('plugindone'), 1); 64 send_redirect($self); 65 } 66 } 67 68 /** 69 * output appropriate html 70 */ 71 public function html() { 72 73 echo $this->locale_xhtml('plugins'); 74 $switchForm = new \dokuwiki\Form\Form(); 75 $switchForm->addClass('plugin_farmer'); 76 $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 77 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio'); 78 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio'); 79 $switchForm->addFieldsetClose(); 80 echo $switchForm->toHTML(); 81 82 /** @var helper_plugin_farmer $helper */ 83 $helper = plugin_load('helper', 'farmer'); 84 $plugins = $helper->getAllPlugins(); 85 array_unshift($plugins, ''); 86 87 $bulkForm = new \dokuwiki\Form\Form(); 88 $bulkForm->id('farmer__bulkForm'); 89 $bulkForm->addClass('plugin_farmer'); 90 $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 91 $bulkForm->addDropdown('farmer__bulkPluginSelect', $plugins)->id('farmer__bulkPluginSelect'); 92 $bulkForm->addButton('farmer__submitBulk', $this->getLang('activate'))->attr('value', 'activate')->attr('type', 'submit')->attr('disabled', 'disabled'); 93 $bulkForm->addButton('farmer__submitBulk', $this->getLang('deactivate'))->attr('value', 'deactivate')->attr('type', 'submit')->attr('disabled', 'disabled'); 94 $bulkForm->addFieldsetClose(); 95 echo $bulkForm->toHTML(); 96 97 $animals = $helper->getAllAnimals(); 98 array_unshift($animals, ''); 99 100 $singleForm = new \dokuwiki\Form\Form(); 101 $singleForm->id('farmer__singlePluginForm'); 102 $singleForm->addClass('plugin_farmer'); 103 $singleForm->addFieldsetOpen($this->getLang('singleEditForm')); 104 $singleForm->addDropdown('plugin_farmer[selectedAnimal]', $animals)->id('farmer__animalSelect'); 105 $singleForm->addTagOpen('div')->id('farmer__animalPlugins'); 106 $singleForm->addTagClose('div'); 107 $switchForm->addFieldsetClose(); 108 echo $singleForm->toHTML(); 109 } 110} 111 112