1*24f27905SAndreas Gohr<?php 2*24f27905SAndreas Gohr/** 3*24f27905SAndreas Gohr * DokuWiki Plugin farmer (Admin Component) 4*24f27905SAndreas Gohr * 5*24f27905SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*24f27905SAndreas Gohr * @author Michael Große <grosse@cosmocode.de> 7*24f27905SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 8*24f27905SAndreas Gohr */ 9*24f27905SAndreas Gohr 10*24f27905SAndreas Gohr// must be run within Dokuwiki 11*24f27905SAndreas Gohruse dokuwiki\Form\Form; 12*24f27905SAndreas Gohr 13*24f27905SAndreas Gohrif(!defined('DOKU_INC')) die(); 14*24f27905SAndreas Gohr 15*24f27905SAndreas Gohr/** 16*24f27905SAndreas Gohr * Information about the farm and the current instance 17*24f27905SAndreas Gohr */ 18*24f27905SAndreas Gohrclass admin_plugin_farmer_delete extends DokuWiki_Admin_Plugin { 19*24f27905SAndreas Gohr 20*24f27905SAndreas Gohr /** @var helper_plugin_farmer */ 21*24f27905SAndreas Gohr protected $helper; 22*24f27905SAndreas Gohr 23*24f27905SAndreas Gohr /** 24*24f27905SAndreas Gohr * admin_plugin_farmer_info constructor. 25*24f27905SAndreas Gohr */ 26*24f27905SAndreas Gohr public function __construct() { 27*24f27905SAndreas Gohr $this->helper = plugin_load('helper', 'farmer'); 28*24f27905SAndreas Gohr } 29*24f27905SAndreas Gohr 30*24f27905SAndreas Gohr /** 31*24f27905SAndreas Gohr * @return bool admin only! 32*24f27905SAndreas Gohr */ 33*24f27905SAndreas Gohr public function forAdminOnly() { 34*24f27905SAndreas Gohr return true; 35*24f27905SAndreas Gohr } 36*24f27905SAndreas Gohr 37*24f27905SAndreas Gohr /** 38*24f27905SAndreas Gohr * Should carry out any processing required by the plugin. 39*24f27905SAndreas Gohr */ 40*24f27905SAndreas Gohr public function handle() { 41*24f27905SAndreas Gohr global $INPUT; 42*24f27905SAndreas Gohr global $ID; 43*24f27905SAndreas Gohr if(!$INPUT->has('delete')) return; 44*24f27905SAndreas Gohr 45*24f27905SAndreas Gohr if($INPUT->filter('trim')->str('delanimal') === '') { 46*24f27905SAndreas Gohr msg($this->getLang('delete_noanimal'), -1); 47*24f27905SAndreas Gohr return; 48*24f27905SAndreas Gohr } 49*24f27905SAndreas Gohr 50*24f27905SAndreas Gohr if($INPUT->str('delanimal') != $INPUT->str('confirm')) { 51*24f27905SAndreas Gohr msg($this->getLang('delete_mismatch'), -1); 52*24f27905SAndreas Gohr return; 53*24f27905SAndreas Gohr } 54*24f27905SAndreas Gohr 55*24f27905SAndreas Gohr $animaldir = DOKU_FARMDIR . '/' . $INPUT->str('delanimal'); 56*24f27905SAndreas Gohr 57*24f27905SAndreas Gohr if(!$this->helper->isInPath($animaldir, DOKU_FARMDIR) || !is_dir($animaldir)) { 58*24f27905SAndreas Gohr msg($this->getLang('delete_invalid'), -1); 59*24f27905SAndreas Gohr return; 60*24f27905SAndreas Gohr } 61*24f27905SAndreas Gohr 62*24f27905SAndreas Gohr // let's delete it 63*24f27905SAndreas Gohr $ok = io_rmdir($animaldir, true); 64*24f27905SAndreas Gohr if($ok) { 65*24f27905SAndreas Gohr msg($this->getLang('delete_success'), 1); 66*24f27905SAndreas Gohr } else { 67*24f27905SAndreas Gohr msg($this->getLang('delete_fail'), -1); 68*24f27905SAndreas Gohr } 69*24f27905SAndreas Gohr 70*24f27905SAndreas Gohr $link = wl($ID, array('do'=>'admin', 'page'=>'farmer', 'sub' => 'delete'), true, '&'); 71*24f27905SAndreas Gohr send_redirect($link); 72*24f27905SAndreas Gohr } 73*24f27905SAndreas Gohr 74*24f27905SAndreas Gohr /** 75*24f27905SAndreas Gohr * Render HTML output, e.g. helpful text and a form 76*24f27905SAndreas Gohr */ 77*24f27905SAndreas Gohr public function html() { 78*24f27905SAndreas Gohr 79*24f27905SAndreas Gohr $form = new Form(); 80*24f27905SAndreas Gohr $form->addFieldsetOpen($this->getLang('delete_animal')); 81*24f27905SAndreas Gohr 82*24f27905SAndreas Gohr $animals = $this->helper->getAllAnimals(); 83*24f27905SAndreas Gohr array_unshift($animals, ''); 84*24f27905SAndreas Gohr $form->addDropdown('delanimal', $animals)->addClass('farmer_choosen_animals'); 85*24f27905SAndreas Gohr $form->addTextInput('confirm', $this->getLang('delete_confirm')); 86*24f27905SAndreas Gohr $form->addButton('delete', $this->getLang('delete')); 87*24f27905SAndreas Gohr $form->addFieldsetClose(); 88*24f27905SAndreas Gohr echo $form->toHTML(); 89*24f27905SAndreas Gohr 90*24f27905SAndreas Gohr } 91*24f27905SAndreas Gohr 92*24f27905SAndreas Gohr 93*24f27905SAndreas Gohr} 94*24f27905SAndreas Gohr 95*24f27905SAndreas Gohr// vim:ts=4:sw=4:et: 96