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 /** 20 * handle user request 21 */ 22 public function handle() { 23 global $INPUT; 24 $this->helper = plugin_load('helper', 'farmer'); 25 26 if (!$this->helper->checkFarmSetup()) { 27 $this->helper->reloadAdminPage('farmer_createAnimal'); 28 } 29 30 if ($INPUT->has('farmer__submitBulk')) { 31 $animals = $this->helper->getAllAnimals(); 32 $plugin = $INPUT->str('farmer__bulkPluginSelect'); 33 foreach ($animals as $animal) { 34 if ($INPUT->str('farmer__submitBulk') === 'activate') { 35 $this->helper->activatePlugin($plugin, $animal); 36 } else { 37 $this->helper->deactivatePlugin($plugin, $animal); 38 } 39 } 40 } 41 if ($INPUT->has('plugin_farmer')) { 42 $inputArray = $INPUT->arr('plugin_farmer'); 43 if ($inputArray['submit_type'] === 'updateSingleAnimal') { 44 $animal = $inputArray ['selectedAnimal']; 45 $allPlugins = $this->helper->getAllPlugins(); 46 $activePlugins = $INPUT->arr('plugin_farmer_plugins'); 47 foreach ($allPlugins as $plugin) { 48 if (isset($activePlugins[$plugin]) && 49 $activePlugins[$plugin] === 'on') { 50 $this->helper->activatePlugin($plugin,$animal); 51 } else { 52 $this->helper->deactivatePlugin($plugin,$animal); 53 } 54 } 55 } 56 } 57 } 58 59 /** 60 * output appropriate html 61 */ 62 public function html() { 63 echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js"></script>'; 64 echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css" type="text/css" rel="stylesheet" />'; 65 66 echo $this->locale_xhtml('plugins'); 67 $switchForm = new \dokuwiki\Form\Form(); 68 $switchForm->addClass('plugin_farmer'); 69 $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 70 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type','radio')->addClass('block'); 71 $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type','radio')->addClass('block'); 72 $switchForm->addFieldsetClose(); 73 echo $switchForm->toHTML(); 74 75 /** @var helper_plugin_farmer $helper */ 76 $helper = plugin_load('helper', 'farmer'); 77 $plugins = $helper->getAllPlugins(); 78 79 $bulkForm = new \dokuwiki\Form\Form(); 80 $bulkForm->id('farmer__bulkForm'); 81 $bulkForm->addClass('plugin_farmer'); 82 $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 83 $bulkForm->addTagOpen('select')->id('farmer__bulkPluginSelect')->attr('name','farmer__bulkPluginSelect'); 84 $bulkForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 85 $bulkForm->addTagClose('option'); 86 foreach ($plugins as $plugin) { 87 $bulkForm->addTagOpen('option')->attr('value', $plugin); 88 $bulkForm->addHTML($plugin); 89 $bulkForm->addTagClose('option'); 90 } 91 $bulkForm->addTagClose('select'); 92 $bulkForm->addButton('farmer__submitBulk',$this->getLang('activate'))->attr('value','activate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 93 $bulkForm->addButton('farmer__submitBulk',$this->getLang('deactivate'))->attr('value','deactivate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 94 $bulkForm->addFieldsetClose(); 95 echo $bulkForm->toHTML(); 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->addTagOpen('select')->id('farmer__animalSelect')->attr('name', 'plugin_farmer[selectedAnimal]'); 102 $singleForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 103 $singleForm->addTagClose('option'); 104 $animals = $helper->getAllAnimals(); 105 foreach ($animals as $animal) { 106 $singleForm->addTagOpen('option'); 107 $singleForm->addHTML($animal); 108 $singleForm->addTagClose('option'); 109 } 110 $singleForm->addTagClose('select'); 111 $singleForm->addTagOpen('div')->id('farmer__animalPlugins'); 112 $singleForm->addTagClose('div'); 113 $switchForm->addFieldsetClose(); 114 echo $singleForm->toHTML(); 115 } 116 117 public function getMenuText() { 118 return 'Farmer: Change animal plugins'; 119 } 120 121 public function getMenuSort() { 122 return 42; 123 } 124 125} 126 127