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 16*c4a48750SMichael Große /** @var helper_plugin_farmer $helper */ 17*c4a48750SMichael Große private $helper; 18*c4a48750SMichael Große 19bc461538SMichael Große /** 20bc461538SMichael Große * handle user request 21bc461538SMichael Große */ 220b96e6d7SMichael Große public function handle() { 23*c4a48750SMichael Große $this->helper = plugin_load('helper', 'farmer'); 24bc461538SMichael Große 25bc461538SMichael Große if (!file_exists(DOKU_INC . 'inc/preload.php')) { 26bc461538SMichael Große global $ID; 27bc461538SMichael Große $get = $_GET; 28bc461538SMichael Große if(isset($get['id'])) unset($get['id']); 29bc461538SMichael Große $get['page'] = 'farmer_foo'; 30bc461538SMichael Große $self = wl($ID, $get, false, '&'); 31bc461538SMichael Große send_redirect($self); 32bc461538SMichael Große } 33bc461538SMichael Große 34*c4a48750SMichael Große if (isset($_REQUEST['farmer__submitBulk'])) { 35*c4a48750SMichael Große $animals = $this->helper->getAllAnimals(); 360b96e6d7SMichael Große $plugin = $_REQUEST['farmer__bulkPluginSelect']; 370b96e6d7SMichael Große foreach ($animals as $animal) { 38*c4a48750SMichael Große if ($_REQUEST['farmer__submitBulk'] === 'activate') { 39*c4a48750SMichael Große $this->helper->activatePlugin($plugin, $animal); 400b96e6d7SMichael Große } else { 41*c4a48750SMichael Große $this->helper->deactivatePlugin($plugin, $animal); 42bc461538SMichael Große } 43bc461538SMichael Große } 44*c4a48750SMichael Große } 45*c4a48750SMichael Große if (isset($_REQUEST['plugin_farmer'])) { 46*c4a48750SMichael Große if ($_REQUEST['plugin_farmer']['submit_type'] === 'updateSingleAnimal') { 47*c4a48750SMichael Große $animal = $_REQUEST['plugin_farmer']['selectedAnimal']; 48*c4a48750SMichael Große $allPlugins = $this->helper->getAllPlugins(); 49*c4a48750SMichael Große foreach ($allPlugins as $plugin) { 50*c4a48750SMichael Große if (isset($_REQUEST['plugin_farmer_plugins'][$plugin]) && 51*c4a48750SMichael Große $_REQUEST['plugin_farmer_plugins'][$plugin] === 'on') { 52*c4a48750SMichael Große $this->helper->activatePlugin($plugin,$animal); 53*c4a48750SMichael Große } else { 54*c4a48750SMichael Große $this->helper->deactivatePlugin($plugin,$animal); 55bc461538SMichael Große } 560b96e6d7SMichael Große } 57*c4a48750SMichael Große 580b96e6d7SMichael Große } 59*c4a48750SMichael Große 600b96e6d7SMichael Große } 61bc461538SMichael Große } 62bc461538SMichael Große 63bc461538SMichael Große /** 64bc461538SMichael Große * output appropriate html 65bc461538SMichael Große */ 660b96e6d7SMichael Große public function html() { 67bc461538SMichael Große echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js"></script>'; 68bc461538SMichael Große echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css" type="text/css" rel="stylesheet" />'; 69bc461538SMichael Große 700b96e6d7SMichael Große $switchForm = new \dokuwiki\Form\Form(); 710b96e6d7SMichael Große $switchForm->addFieldsetOpen('edit a single animal or all at once?'); 720b96e6d7SMichael Große $switchForm->addRadioButton('bulkSingleSwitch', 'bulk edit all animals')->id('farmer__bulk')->attr('type','radio')->addClass('block'); 730b96e6d7SMichael Große $switchForm->addRadioButton('bulkSingleSwitch', 'edit a single animal')->id('farmer__single')->attr('type','radio')->addClass('block'); 740b96e6d7SMichael Große $switchForm->addFieldsetClose(); 750b96e6d7SMichael Große echo $switchForm->toHTML(); 76bc461538SMichael Große 770b96e6d7SMichael Große /** @var helper_plugin_farmer $helper */ 780b96e6d7SMichael Große $helper = plugin_load('helper', 'farmer'); 790b96e6d7SMichael Große $plugins = $helper->getAllPlugins(); 800b96e6d7SMichael Große 810b96e6d7SMichael Große $bulkForm = new \dokuwiki\Form\Form(); 820b96e6d7SMichael Große $bulkForm->id('farmer__bulkForm'); 83415bff3cSMichael Große $bulkForm->addFieldsetOpen('Activate or deactivate a plugin in all animals'); 840b96e6d7SMichael Große $bulkForm->addHTML('bulk'); 85ae93adddSMichael Große $bulkForm->addTagOpen('select')->id('farmer__bulkPluginSelect')->attr('name','farmer__bulkPluginSelect'); 860b96e6d7SMichael Große $bulkForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 870b96e6d7SMichael Große $bulkForm->addTagClose('option'); 880b96e6d7SMichael Große foreach ($plugins as $plugin) { 890b96e6d7SMichael Große $bulkForm->addTagOpen('option')->attr('value', $plugin); 900b96e6d7SMichael Große $bulkForm->addHTML($plugin); 910b96e6d7SMichael Große $bulkForm->addTagClose('option'); 920b96e6d7SMichael Große } 930b96e6d7SMichael Große $bulkForm->addTagClose('select'); 940b96e6d7SMichael Große $bulkForm->addButton('farmer__submitBulk','Activate')->attr('value','activate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 950b96e6d7SMichael Große $bulkForm->addButton('farmer__submitBulk','Deactivate')->attr('value','deactivate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 96415bff3cSMichael Große $bulkForm->addFieldsetClose(); 970b96e6d7SMichael Große echo $bulkForm->toHTML(); 980b96e6d7SMichael Große 990b96e6d7SMichael Große $singleForm = new \dokuwiki\Form\Form(); 1000b96e6d7SMichael Große $singleForm->id('farmer__singlePluginForm'); 101415bff3cSMichael Große $singleForm->addFieldsetOpen('edit the plugins of a specific animal'); 102415bff3cSMichael Große $singleForm->addTagOpen('select')->id('farmer__animalSelect')->attr('name', 'plugin_farmer[selectedAnimal]'); 1030b96e6d7SMichael Große $singleForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 1040b96e6d7SMichael Große $singleForm->addTagClose('option'); 1050b96e6d7SMichael Große $animals = $helper->getAllAnimals(); 1060b96e6d7SMichael Große foreach ($animals as $animal) { 1070b96e6d7SMichael Große $singleForm->addTagOpen('option'); 1080b96e6d7SMichael Große $singleForm->addHTML($animal); 1090b96e6d7SMichael Große $singleForm->addTagClose('option'); 1100b96e6d7SMichael Große } 1110b96e6d7SMichael Große $singleForm->addTagClose('select'); 112ae93adddSMichael Große $singleForm->addButton('plugin_farmer[submit_type]','Submit')->attr('type','submit')->attr('value','updateSingleAnimal'); 113415bff3cSMichael Große $singleForm->addButton('farmer__reset','Reset')->attr('type','reset'); 114415bff3cSMichael Große $singleForm->addTagOpen('div')->id('farmer__animalPlugins'); 115415bff3cSMichael Große $singleForm->addTagClose('div'); 116ae93adddSMichael Große $singleForm->addButton('plugin_farmer[submit_type]','Submit')->attr('type','submit')->attr('value','updateSingleAnimal'); 117415bff3cSMichael Große $singleForm->addButton('farmer__reset','Reset')->attr('type','reset'); 118ae93adddSMichael Große $switchForm->addFieldsetClose(); 1190b96e6d7SMichael Große echo $singleForm->toHTML(); 120bc461538SMichael Große } 121bc461538SMichael Große 122bc461538SMichael Große public function getMenuText() { 123bc461538SMichael Große return 'Farmer: Change animal plugins'; 124bc461538SMichael Große } 125bc461538SMichael Große 126bc461538SMichael Große public function getMenuSort() { 127bc461538SMichael Große return 42; 128bc461538SMichael Große } 129bc461538SMichael Große 130bc461538SMichael Große} 131bc461538SMichael Große 132