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