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 19bc461538SMichael Große /** 20bc461538SMichael Große * handle user request 21bc461538SMichael Große */ 220b96e6d7SMichael Große public function handle() { 23c4a48750SMichael Große $this->helper = plugin_load('helper', 'farmer'); 24bc461538SMichael Große 25d9ec4524SMichael Große if (!$this->helper->checkFarmSetup()) { 264d120480SMichael Große $this->helper->reloadAdminPage('farmer_createAnimal'); 27bc461538SMichael Große } 28bc461538SMichael Große 29c4a48750SMichael Große if (isset($_REQUEST['farmer__submitBulk'])) { 30c4a48750SMichael Große $animals = $this->helper->getAllAnimals(); 310b96e6d7SMichael Große $plugin = $_REQUEST['farmer__bulkPluginSelect']; 320b96e6d7SMichael Große foreach ($animals as $animal) { 33c4a48750SMichael Große if ($_REQUEST['farmer__submitBulk'] === 'activate') { 34c4a48750SMichael Große $this->helper->activatePlugin($plugin, $animal); 350b96e6d7SMichael Große } else { 36c4a48750SMichael Große $this->helper->deactivatePlugin($plugin, $animal); 37bc461538SMichael Große } 38bc461538SMichael Große } 39c4a48750SMichael Große } 40c4a48750SMichael Große if (isset($_REQUEST['plugin_farmer'])) { 41c4a48750SMichael Große if ($_REQUEST['plugin_farmer']['submit_type'] === 'updateSingleAnimal') { 42c4a48750SMichael Große $animal = $_REQUEST['plugin_farmer']['selectedAnimal']; 43c4a48750SMichael Große $allPlugins = $this->helper->getAllPlugins(); 44c4a48750SMichael Große foreach ($allPlugins as $plugin) { 45c4a48750SMichael Große if (isset($_REQUEST['plugin_farmer_plugins'][$plugin]) && 46c4a48750SMichael Große $_REQUEST['plugin_farmer_plugins'][$plugin] === 'on') { 47c4a48750SMichael Große $this->helper->activatePlugin($plugin,$animal); 48c4a48750SMichael Große } else { 49c4a48750SMichael Große $this->helper->deactivatePlugin($plugin,$animal); 50bc461538SMichael Große } 510b96e6d7SMichael Große } 52c4a48750SMichael Große 530b96e6d7SMichael Große } 54c4a48750SMichael Große 550b96e6d7SMichael Große } 56bc461538SMichael Große } 57bc461538SMichael Große 58bc461538SMichael Große /** 59bc461538SMichael Große * output appropriate html 60bc461538SMichael Große */ 610b96e6d7SMichael Große public function html() { 62bc461538SMichael Große echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js"></script>'; 63bc461538SMichael Große echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css" type="text/css" rel="stylesheet" />'; 64bc461538SMichael Große 65*9ed791b7SMichael Große echo $this->locale_xhtml('plugins'); 660b96e6d7SMichael Große $switchForm = new \dokuwiki\Form\Form(); 67fc6a7cc1SMichael Große $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 68fc6a7cc1SMichael Große $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type','radio')->addClass('block'); 69fc6a7cc1SMichael Große $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type','radio')->addClass('block'); 700b96e6d7SMichael Große $switchForm->addFieldsetClose(); 710b96e6d7SMichael Große echo $switchForm->toHTML(); 72bc461538SMichael Große 730b96e6d7SMichael Große /** @var helper_plugin_farmer $helper */ 740b96e6d7SMichael Große $helper = plugin_load('helper', 'farmer'); 750b96e6d7SMichael Große $plugins = $helper->getAllPlugins(); 760b96e6d7SMichael Große 770b96e6d7SMichael Große $bulkForm = new \dokuwiki\Form\Form(); 780b96e6d7SMichael Große $bulkForm->id('farmer__bulkForm'); 79fc6a7cc1SMichael Große $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 80ae93adddSMichael Große $bulkForm->addTagOpen('select')->id('farmer__bulkPluginSelect')->attr('name','farmer__bulkPluginSelect'); 810b96e6d7SMichael Große $bulkForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 820b96e6d7SMichael Große $bulkForm->addTagClose('option'); 830b96e6d7SMichael Große foreach ($plugins as $plugin) { 840b96e6d7SMichael Große $bulkForm->addTagOpen('option')->attr('value', $plugin); 850b96e6d7SMichael Große $bulkForm->addHTML($plugin); 860b96e6d7SMichael Große $bulkForm->addTagClose('option'); 870b96e6d7SMichael Große } 880b96e6d7SMichael Große $bulkForm->addTagClose('select'); 89fc6a7cc1SMichael Große $bulkForm->addButton('farmer__submitBulk',$this->getLang('activate'))->attr('value','activate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 90fc6a7cc1SMichael Große $bulkForm->addButton('farmer__submitBulk',$this->getLang('deactivate'))->attr('value','deactivate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 91415bff3cSMichael Große $bulkForm->addFieldsetClose(); 920b96e6d7SMichael Große echo $bulkForm->toHTML(); 930b96e6d7SMichael Große 940b96e6d7SMichael Große $singleForm = new \dokuwiki\Form\Form(); 950b96e6d7SMichael Große $singleForm->id('farmer__singlePluginForm'); 96fc6a7cc1SMichael Große $singleForm->addFieldsetOpen($this->getLang('singleEditForm')); 97415bff3cSMichael Große $singleForm->addTagOpen('select')->id('farmer__animalSelect')->attr('name', 'plugin_farmer[selectedAnimal]'); 980b96e6d7SMichael Große $singleForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 990b96e6d7SMichael Große $singleForm->addTagClose('option'); 1000b96e6d7SMichael Große $animals = $helper->getAllAnimals(); 1010b96e6d7SMichael Große foreach ($animals as $animal) { 1020b96e6d7SMichael Große $singleForm->addTagOpen('option'); 1030b96e6d7SMichael Große $singleForm->addHTML($animal); 1040b96e6d7SMichael Große $singleForm->addTagClose('option'); 1050b96e6d7SMichael Große } 1060b96e6d7SMichael Große $singleForm->addTagClose('select'); 107415bff3cSMichael Große $singleForm->addTagOpen('div')->id('farmer__animalPlugins'); 108415bff3cSMichael Große $singleForm->addTagClose('div'); 109ae93adddSMichael Große $switchForm->addFieldsetClose(); 1100b96e6d7SMichael Große echo $singleForm->toHTML(); 111bc461538SMichael Große } 112bc461538SMichael Große 113bc461538SMichael Große public function getMenuText() { 114bc461538SMichael Große return 'Farmer: Change animal plugins'; 115bc461538SMichael Große } 116bc461538SMichael Große 117bc461538SMichael Große public function getMenuSort() { 118bc461538SMichael Große return 42; 119bc461538SMichael Große } 120bc461538SMichael Große 121bc461538SMichael Große} 122bc461538SMichael Große 123