1<?php 2/** 3 * Plugin Skeleton: Displays "Hello World!" 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Christopher Smith <chris@jalakai.co.uk> 7 */ 8 9 10/** 11 * All DokuWiki plugins to extend the admin function 12 * need to inherit from this class 13 */ 14class admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin { 15 16 /** @var helper_plugin_farmer $helper */ 17 private $helper; 18 19 public function __construct() { 20 $this->helper = plugin_load('helper', 'farmer'); 21 } 22 23 /** 24 * handle user request 25 */ 26 public function handle() { 27 global $INPUT; 28 29 if (!$this->helper->checkFarmSetup()) { 30 $this->helper->reloadAdminPage('farmer_createAnimal'); 31 } 32 33 if ($INPUT->has('farmer__submitBulk')) { 34 $animals = $this->helper->getAllAnimals(); 35 $plugin = $INPUT->str('farmer__bulkPluginSelect'); 36 foreach ($animals as $animal) { 37 if ($INPUT->str('farmer__submitBulk') === 'activate') { 38 $this->helper->activatePlugin($plugin, $animal); 39 } else { 40 $this->helper->deactivatePlugin($plugin, $animal); 41 } 42 } 43 } 44 if ($INPUT->has('plugin_farmer')) { 45 $inputArray = $INPUT->arr('plugin_farmer'); 46 if ($inputArray['submit_type'] === 'updateSingleAnimal') { 47 $animal = $inputArray ['selectedAnimal']; 48 $allPlugins = $this->helper->getAllPlugins(); 49 $activePlugins = $INPUT->arr('plugin_farmer_plugins'); 50 foreach ($allPlugins as $plugin) { 51 if (isset($activePlugins[$plugin]) && 52 $activePlugins[$plugin] === 'on') { 53 $this->helper->activatePlugin($plugin,$animal); 54 } else { 55 $this->helper->deactivatePlugin($plugin,$animal); 56 } 57 } 58 } 59 } 60 } 61 62 /** 63 * output appropriate html 64 */ 65 public function html() { 66 67 echo $this->locale_xhtml('plugins'); 68 $switchForm = new \dokuwiki\Form\Form(); 69 $switchForm->addClass('plugin_farmer'); 70 $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 71 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type','radio')->addClass('block'); 72 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type','radio')->addClass('block'); 73 $switchForm->addFieldsetClose(); 74 echo $switchForm->toHTML(); 75 76 /** @var helper_plugin_farmer $helper */ 77 $helper = plugin_load('helper', 'farmer'); 78 $plugins = $helper->getAllPlugins(); 79 80 $bulkForm = new \dokuwiki\Form\Form(); 81 $bulkForm->id('farmer__bulkForm'); 82 $bulkForm->addClass('plugin_farmer'); 83 $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 84 $bulkForm->addTagOpen('select')->id('farmer__bulkPluginSelect')->attr('name','farmer__bulkPluginSelect'); 85 $bulkForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 86 $bulkForm->addTagClose('option'); 87 foreach ($plugins as $plugin) { 88 $bulkForm->addTagOpen('option')->attr('value', $plugin); 89 $bulkForm->addHTML($plugin); 90 $bulkForm->addTagClose('option'); 91 } 92 $bulkForm->addTagClose('select'); 93 $bulkForm->addButton('farmer__submitBulk',$this->getLang('activate'))->attr('value','activate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 94 $bulkForm->addButton('farmer__submitBulk',$this->getLang('deactivate'))->attr('value','deactivate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 95 $bulkForm->addFieldsetClose(); 96 echo $bulkForm->toHTML(); 97 98 $singleForm = new \dokuwiki\Form\Form(); 99 $singleForm->id('farmer__singlePluginForm'); 100 $singleForm->addClass('plugin_farmer'); 101 $singleForm->addFieldsetOpen($this->getLang('singleEditForm')); 102 $singleForm->addTagOpen('select')->id('farmer__animalSelect')->attr('name', 'plugin_farmer[selectedAnimal]'); 103 $singleForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 104 $singleForm->addTagClose('option'); 105 $animals = $helper->getAllAnimals(); 106 foreach ($animals as $animal) { 107 $singleForm->addTagOpen('option'); 108 $singleForm->addHTML($animal); 109 $singleForm->addTagClose('option'); 110 } 111 $singleForm->addTagClose('select'); 112 $singleForm->addTagOpen('div')->id('farmer__animalPlugins'); 113 $singleForm->addTagClose('div'); 114 $switchForm->addFieldsetClose(); 115 echo $singleForm->toHTML(); 116 } 117} 118 119