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('bulk_plugin') && $INPUT->has('state')) { 35 $animals = $this->helper->getAllAnimals(); 36 $plugin = $INPUT->str('bulk_plugin'); 37 foreach($animals as $animal) { 38 $this->helper->setPluginState($plugin, $animal, $INPUT->int('state')); 39 } 40 msg($this->getLang('plugindone'), 1); 41 send_redirect($self); 42 } 43 44 if($INPUT->has('bulk_animal') && $INPUT->has('bulk_plugins')) { 45 $animal = $INPUT->str('bulk_animal'); 46 $activePlugins = $INPUT->arr('bulk_plugins'); 47 foreach($activePlugins as $plugin => $state) { 48 $this->helper->setPluginState($plugin, $animal, $state); 49 } 50 msg($this->getLang('plugindone'), 1); 51 send_redirect($self); 52 } 53 } 54 55 /** 56 * output appropriate html 57 */ 58 public function html() { 59 60 echo $this->locale_xhtml('plugins'); 61 $switchForm = new \dokuwiki\Form\Form(); 62 $switchForm->addClass('plugin_farmer'); 63 $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 64 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio'); 65 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio'); 66 $switchForm->addFieldsetClose(); 67 echo $switchForm->toHTML(); 68 69 /** @var helper_plugin_farmer $helper */ 70 $helper = plugin_load('helper', 'farmer'); 71 $plugins = $helper->getAllPlugins(); 72 array_unshift($plugins, ''); 73 74 // All Animals at once 75 $bulkForm = new \dokuwiki\Form\Form(); 76 $bulkForm->id('farmer__pluginsforall'); 77 $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 78 $bulkForm->addDropdown('bulk_plugin', $plugins); 79 $bulkForm->addButton('state', $this->getLang('default'))->attr('value', '-1')->attr('type', 'submit')->attr('disabled', 'disabled'); 80 $bulkForm->addButton('state', $this->getLang('activate'))->attr('value', '1')->attr('type', 'submit')->attr('disabled', 'disabled'); 81 $bulkForm->addButton('state', $this->getLang('deactivate'))->attr('value', '0')->attr('type', 'submit')->attr('disabled', 'disabled'); 82 $bulkForm->addFieldsetClose(); 83 echo $bulkForm->toHTML(); 84 85 $animals = $helper->getAllAnimals(); 86 array_unshift($animals, ''); 87 88 // One Animal, all the plugins 89 $singleForm = new \dokuwiki\Form\Form(); 90 $singleForm->id('farmer__pluginsforone'); 91 $singleForm->addFieldsetOpen($this->getLang('singleEditForm')); 92 $singleForm->addDropdown('bulk_animal', $animals); 93 $singleForm->addTagOpen('div')->addClass('output'); 94 $singleForm->addTagClose('div'); 95 $singleForm->addButton('save', $this->getLang('save'))->attr('disabled', 'disabled'); 96 97 echo $singleForm->toHTML(); 98 } 99} 100 101