1bc461538SMichael Große<?php 2bc461538SMichael Große/** 3bc461538SMichael Große * Plugin Skeleton: Displays "Hello World!" 4bc461538SMichael Große * 5bc461538SMichael Große * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6bc461538SMichael Große * @author Christopher Smith <chris@jalakai.co.uk> 7bc461538SMichael Große */ 8bc461538SMichael Große 9bc461538SMichael Große 10bc461538SMichael Große/** 11bc461538SMichael Große * All DokuWiki plugins to extend the admin function 12bc461538SMichael Große * need to inherit from this class 13bc461538SMichael Große */ 14bc461538SMichael Großeclass admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin { 15bc461538SMichael Große 16c4a48750SMichael Große /** @var helper_plugin_farmer $helper */ 17c4a48750SMichael Große private $helper; 18c4a48750SMichael Große 1965dd3ddfSAndreas Gohr public function __construct() { 2065dd3ddfSAndreas Gohr $this->helper = plugin_load('helper', 'farmer'); 2165dd3ddfSAndreas Gohr } 2265dd3ddfSAndreas Gohr 23bc461538SMichael Große /** 24bc461538SMichael Große * handle user request 25bc461538SMichael Große */ 260b96e6d7SMichael Große public function handle() { 2737a9ac83SMichael Große global $INPUT; 28bc461538SMichael Große 29d9ec4524SMichael Große if (!$this->helper->checkFarmSetup()) { 304d120480SMichael Große $this->helper->reloadAdminPage('farmer_createAnimal'); 31bc461538SMichael Große } 32bc461538SMichael Große 3337a9ac83SMichael Große if ($INPUT->has('farmer__submitBulk')) { 34c4a48750SMichael Große $animals = $this->helper->getAllAnimals(); 3537a9ac83SMichael Große $plugin = $INPUT->str('farmer__bulkPluginSelect'); 360b96e6d7SMichael Große foreach ($animals as $animal) { 3737a9ac83SMichael Große if ($INPUT->str('farmer__submitBulk') === 'activate') { 38c4a48750SMichael Große $this->helper->activatePlugin($plugin, $animal); 390b96e6d7SMichael Große } else { 40c4a48750SMichael Große $this->helper->deactivatePlugin($plugin, $animal); 41bc461538SMichael Große } 42bc461538SMichael Große } 43c4a48750SMichael Große } 4437a9ac83SMichael Große if ($INPUT->has('plugin_farmer')) { 4537a9ac83SMichael Große $inputArray = $INPUT->arr('plugin_farmer'); 4637a9ac83SMichael Große if ($inputArray['submit_type'] === 'updateSingleAnimal') { 4737a9ac83SMichael Große $animal = $inputArray ['selectedAnimal']; 48c4a48750SMichael Große $allPlugins = $this->helper->getAllPlugins(); 4937a9ac83SMichael Große $activePlugins = $INPUT->arr('plugin_farmer_plugins'); 50c4a48750SMichael Große foreach ($allPlugins as $plugin) { 5137a9ac83SMichael Große if (isset($activePlugins[$plugin]) && 5237a9ac83SMichael Große $activePlugins[$plugin] === 'on') { 53c4a48750SMichael Große $this->helper->activatePlugin($plugin,$animal); 54c4a48750SMichael Große } else { 55c4a48750SMichael Große $this->helper->deactivatePlugin($plugin,$animal); 56bc461538SMichael Große } 570b96e6d7SMichael Große } 580b96e6d7SMichael Große } 590b96e6d7SMichael Große } 60bc461538SMichael Große } 61bc461538SMichael Große 62bc461538SMichael Große /** 63bc461538SMichael Große * output appropriate html 64bc461538SMichael Große */ 650b96e6d7SMichael Große public function html() { 66bc461538SMichael Große 679ed791b7SMichael Große echo $this->locale_xhtml('plugins'); 680b96e6d7SMichael Große $switchForm = new \dokuwiki\Form\Form(); 69e71d78f4SMichael Große $switchForm->addClass('plugin_farmer'); 70fc6a7cc1SMichael Große $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 71*d3a4cfaaSAndreas Gohr $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type','radio'); 72*d3a4cfaaSAndreas Gohr $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type','radio'); 730b96e6d7SMichael Große $switchForm->addFieldsetClose(); 740b96e6d7SMichael Große echo $switchForm->toHTML(); 75bc461538SMichael Große 760b96e6d7SMichael Große /** @var helper_plugin_farmer $helper */ 770b96e6d7SMichael Große $helper = plugin_load('helper', 'farmer'); 780b96e6d7SMichael Große $plugins = $helper->getAllPlugins(); 79*d3a4cfaaSAndreas Gohr array_unshift($plugins, ''); 800b96e6d7SMichael Große 810b96e6d7SMichael Große $bulkForm = new \dokuwiki\Form\Form(); 820b96e6d7SMichael Große $bulkForm->id('farmer__bulkForm'); 83e71d78f4SMichael Große $bulkForm->addClass('plugin_farmer'); 84fc6a7cc1SMichael Große $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 85*d3a4cfaaSAndreas Gohr $bulkForm->addDropdown('farmer__bulkPluginSelect', $plugins)->id('farmer__bulkPluginSelect'); 86*d3a4cfaaSAndreas Gohr $bulkForm->addButton('farmer__submitBulk',$this->getLang('activate'))->attr('value','activate')->attr('type','submit')->attr('disabled','disabled'); 87*d3a4cfaaSAndreas Gohr $bulkForm->addButton('farmer__submitBulk',$this->getLang('deactivate'))->attr('value','deactivate')->attr('type','submit')->attr('disabled','disabled'); 88415bff3cSMichael Große $bulkForm->addFieldsetClose(); 890b96e6d7SMichael Große echo $bulkForm->toHTML(); 900b96e6d7SMichael Große 91*d3a4cfaaSAndreas Gohr $animals = $helper->getAllAnimals(); 92*d3a4cfaaSAndreas Gohr array_unshift($animals, ''); 93*d3a4cfaaSAndreas Gohr 940b96e6d7SMichael Große $singleForm = new \dokuwiki\Form\Form(); 950b96e6d7SMichael Große $singleForm->id('farmer__singlePluginForm'); 96e71d78f4SMichael Große $singleForm->addClass('plugin_farmer'); 97fc6a7cc1SMichael Große $singleForm->addFieldsetOpen($this->getLang('singleEditForm')); 98*d3a4cfaaSAndreas Gohr $singleForm->addDropdown('plugin_farmer[selectedAnimal]', $animals)->id('farmer__animalSelect'); 99415bff3cSMichael Große $singleForm->addTagOpen('div')->id('farmer__animalPlugins'); 100415bff3cSMichael Große $singleForm->addTagClose('div'); 101ae93adddSMichael Große $switchForm->addFieldsetClose(); 1020b96e6d7SMichael Große echo $singleForm->toHTML(); 103bc461538SMichael Große } 104bc461538SMichael Große} 105bc461538SMichael Große 106