1bc461538SMichael Große<?php 2bc461538SMichael Große/** 30a5d2da2SAndreas Gohr * DokuWiki Plugin farmer (Admin Component) 4bc461538SMichael Große * 50a5d2da2SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 60a5d2da2SAndreas Gohr * @author Michael Große <grosse@cosmocode.de> 70a5d2da2SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 8bc461538SMichael Große */ 9bc461538SMichael Große 100a5d2da2SAndreas Gohr// must be run within Dokuwiki 110a5d2da2SAndreas Gohrif(!defined('DOKU_INC')) die(); 12bc461538SMichael Große 13bc461538SMichael Große/** 140a5d2da2SAndreas Gohr * Manage Animal Plugin settings 15bc461538SMichael Große */ 16bc461538SMichael Großeclass admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin { 17bc461538SMichael Große 18c4a48750SMichael Große /** @var helper_plugin_farmer $helper */ 19c4a48750SMichael Große private $helper; 20c4a48750SMichael Große 2165dd3ddfSAndreas Gohr public function __construct() { 2265dd3ddfSAndreas Gohr $this->helper = plugin_load('helper', 'farmer'); 2365dd3ddfSAndreas Gohr } 2465dd3ddfSAndreas Gohr 25bc461538SMichael Große /** 26bc461538SMichael Große * handle user request 27bc461538SMichael Große */ 280b96e6d7SMichael Große public function handle() { 2937a9ac83SMichael Große global $INPUT; 30114a05a7SAndreas Gohr global $ID; 31114a05a7SAndreas Gohr 32114a05a7SAndreas Gohr $self = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => 'plugins'), true, '&'); 33bc461538SMichael Große 34*af1c6dd8SAndreas Gohr if($INPUT->has('bulk_plugin') && $INPUT->has('state')) { 35c4a48750SMichael Große $animals = $this->helper->getAllAnimals(); 36*af1c6dd8SAndreas Gohr $plugin = $INPUT->str('bulk_plugin'); 370b96e6d7SMichael Große foreach($animals as $animal) { 38*af1c6dd8SAndreas Gohr $this->helper->setPluginState($plugin, $animal, $INPUT->int('state')); 39bc461538SMichael Große } 40114a05a7SAndreas Gohr msg($this->getLang('plugindone'), 1); 41114a05a7SAndreas Gohr send_redirect($self); 42c4a48750SMichael Große } 43*af1c6dd8SAndreas Gohr 44*af1c6dd8SAndreas Gohr if($INPUT->has('bulk_animal') && $INPUT->has('bulk_plugins')) { 45*af1c6dd8SAndreas Gohr $animal = $INPUT->str('bulk_animal'); 46*af1c6dd8SAndreas Gohr $activePlugins = $INPUT->arr('bulk_plugins'); 47*af1c6dd8SAndreas Gohr foreach($activePlugins as $plugin => $state) { 48*af1c6dd8SAndreas Gohr $this->helper->setPluginState($plugin, $animal, $state); 490b96e6d7SMichael Große } 50114a05a7SAndreas Gohr msg($this->getLang('plugindone'), 1); 51114a05a7SAndreas Gohr send_redirect($self); 520b96e6d7SMichael Große } 53bc461538SMichael Große } 54bc461538SMichael Große 55bc461538SMichael Große /** 56bc461538SMichael Große * output appropriate html 57bc461538SMichael Große */ 580b96e6d7SMichael Große public function html() { 59bc461538SMichael Große 609ed791b7SMichael Große echo $this->locale_xhtml('plugins'); 610b96e6d7SMichael Große $switchForm = new \dokuwiki\Form\Form(); 62e71d78f4SMichael Große $switchForm->addClass('plugin_farmer'); 63fc6a7cc1SMichael Große $switchForm->addFieldsetOpen($this->getLang('bulkSingleSwitcher')); 64d3a4cfaaSAndreas Gohr $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('bulkEdit'))->id('farmer__bulk')->attr('type', 'radio'); 65d3a4cfaaSAndreas Gohr $switchForm->addRadioButton('bulkSingleSwitch', $this->getLang('singleEdit'))->id('farmer__single')->attr('type', 'radio'); 660b96e6d7SMichael Große $switchForm->addFieldsetClose(); 670b96e6d7SMichael Große echo $switchForm->toHTML(); 68bc461538SMichael Große 690b96e6d7SMichael Große /** @var helper_plugin_farmer $helper */ 700b96e6d7SMichael Große $helper = plugin_load('helper', 'farmer'); 710b96e6d7SMichael Große $plugins = $helper->getAllPlugins(); 72d3a4cfaaSAndreas Gohr array_unshift($plugins, ''); 730b96e6d7SMichael Große 74*af1c6dd8SAndreas Gohr // All Animals at once 750b96e6d7SMichael Große $bulkForm = new \dokuwiki\Form\Form(); 76*af1c6dd8SAndreas Gohr $bulkForm->id('farmer__pluginsforall'); 77fc6a7cc1SMichael Große $bulkForm->addFieldsetOpen($this->getLang('bulkEditForm')); 78*af1c6dd8SAndreas Gohr $bulkForm->addDropdown('bulk_plugin', $plugins); 79*af1c6dd8SAndreas Gohr $bulkForm->addButton('state', $this->getLang('default'))->attr('value', '-1')->attr('type', 'submit')->attr('disabled', 'disabled'); 80*af1c6dd8SAndreas Gohr $bulkForm->addButton('state', $this->getLang('activate'))->attr('value', '1')->attr('type', 'submit')->attr('disabled', 'disabled'); 81*af1c6dd8SAndreas Gohr $bulkForm->addButton('state', $this->getLang('deactivate'))->attr('value', '0')->attr('type', 'submit')->attr('disabled', 'disabled'); 82415bff3cSMichael Große $bulkForm->addFieldsetClose(); 830b96e6d7SMichael Große echo $bulkForm->toHTML(); 840b96e6d7SMichael Große 85d3a4cfaaSAndreas Gohr $animals = $helper->getAllAnimals(); 86d3a4cfaaSAndreas Gohr array_unshift($animals, ''); 87d3a4cfaaSAndreas Gohr 88*af1c6dd8SAndreas Gohr // One Animal, all the plugins 890b96e6d7SMichael Große $singleForm = new \dokuwiki\Form\Form(); 90*af1c6dd8SAndreas Gohr $singleForm->id('farmer__pluginsforone'); 91fc6a7cc1SMichael Große $singleForm->addFieldsetOpen($this->getLang('singleEditForm')); 92*af1c6dd8SAndreas Gohr $singleForm->addDropdown('bulk_animal', $animals); 93*af1c6dd8SAndreas Gohr $singleForm->addTagOpen('div')->addClass('output'); 94415bff3cSMichael Große $singleForm->addTagClose('div'); 95*af1c6dd8SAndreas Gohr $singleForm->addButton('save', $this->getLang('save'))->attr('disabled', 'disabled'); 96*af1c6dd8SAndreas Gohr 970b96e6d7SMichael Große echo $singleForm->toHTML(); 98bc461538SMichael Große } 99bc461538SMichael Große} 100bc461538SMichael Große 101