xref: /plugin/farmer/admin/delete.php (revision 8262a4cbfa75b904634931087aeac13ac2fa2168)
124f27905SAndreas Gohr<?php
224f27905SAndreas Gohr/**
324f27905SAndreas Gohr * DokuWiki Plugin farmer (Admin Component)
424f27905SAndreas Gohr *
524f27905SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
624f27905SAndreas Gohr * @author  Michael Große <grosse@cosmocode.de>
724f27905SAndreas Gohr * @author  Andreas Gohr <gohr@cosmocode.de>
824f27905SAndreas Gohr */
924f27905SAndreas Gohr
1024f27905SAndreas Gohr// must be run within Dokuwiki
1124f27905SAndreas Gohruse dokuwiki\Form\Form;
1224f27905SAndreas Gohr
1324f27905SAndreas Gohrif(!defined('DOKU_INC')) die();
1424f27905SAndreas Gohr
1524f27905SAndreas Gohr/**
1624f27905SAndreas Gohr * Information about the farm and the current instance
1724f27905SAndreas Gohr */
1824f27905SAndreas Gohrclass admin_plugin_farmer_delete extends DokuWiki_Admin_Plugin {
1924f27905SAndreas Gohr
2024f27905SAndreas Gohr    /** @var helper_plugin_farmer */
2124f27905SAndreas Gohr    protected $helper;
2224f27905SAndreas Gohr
2324f27905SAndreas Gohr    /**
2424f27905SAndreas Gohr     * admin_plugin_farmer_info constructor.
2524f27905SAndreas Gohr     */
2624f27905SAndreas Gohr    public function __construct() {
2724f27905SAndreas Gohr        $this->helper = plugin_load('helper', 'farmer');
2824f27905SAndreas Gohr    }
2924f27905SAndreas Gohr
3024f27905SAndreas Gohr    /**
3124f27905SAndreas Gohr     * @return bool admin only!
3224f27905SAndreas Gohr     */
3324f27905SAndreas Gohr    public function forAdminOnly() {
3424f27905SAndreas Gohr        return true;
3524f27905SAndreas Gohr    }
3624f27905SAndreas Gohr
3724f27905SAndreas Gohr    /**
3824f27905SAndreas Gohr     * Should carry out any processing required by the plugin.
3924f27905SAndreas Gohr     */
4024f27905SAndreas Gohr    public function handle() {
4124f27905SAndreas Gohr        global $INPUT;
4224f27905SAndreas Gohr        global $ID;
4324f27905SAndreas Gohr        if(!$INPUT->has('delete')) return;
4424f27905SAndreas Gohr
4524f27905SAndreas Gohr        if($INPUT->filter('trim')->str('delanimal') === '') {
4624f27905SAndreas Gohr            msg($this->getLang('delete_noanimal'), -1);
4724f27905SAndreas Gohr            return;
4824f27905SAndreas Gohr        }
4924f27905SAndreas Gohr
5024f27905SAndreas Gohr        if($INPUT->str('delanimal') != $INPUT->str('confirm')) {
5124f27905SAndreas Gohr            msg($this->getLang('delete_mismatch'), -1);
5224f27905SAndreas Gohr            return;
5324f27905SAndreas Gohr        }
5424f27905SAndreas Gohr
55*8262a4cbSAndreas Gohr        $animaldir = DOKU_FARMDIR . $INPUT->str('delanimal');
5624f27905SAndreas Gohr
5724f27905SAndreas Gohr        if(!$this->helper->isInPath($animaldir, DOKU_FARMDIR) || !is_dir($animaldir)) {
5824f27905SAndreas Gohr            msg($this->getLang('delete_invalid'), -1);
5924f27905SAndreas Gohr            return;
6024f27905SAndreas Gohr        }
6124f27905SAndreas Gohr
6224f27905SAndreas Gohr        // let's delete it
6324f27905SAndreas Gohr        $ok = io_rmdir($animaldir, true);
6424f27905SAndreas Gohr        if($ok) {
6524f27905SAndreas Gohr            msg($this->getLang('delete_success'), 1);
6624f27905SAndreas Gohr        } else {
6724f27905SAndreas Gohr            msg($this->getLang('delete_fail'), -1);
6824f27905SAndreas Gohr        }
6924f27905SAndreas Gohr
7024f27905SAndreas Gohr        $link = wl($ID, array('do'=>'admin', 'page'=>'farmer', 'sub' => 'delete'), true, '&');
7124f27905SAndreas Gohr        send_redirect($link);
7224f27905SAndreas Gohr    }
7324f27905SAndreas Gohr
7424f27905SAndreas Gohr    /**
7524f27905SAndreas Gohr     * Render HTML output, e.g. helpful text and a form
7624f27905SAndreas Gohr     */
7724f27905SAndreas Gohr    public function html() {
7824f27905SAndreas Gohr
7924f27905SAndreas Gohr        $form = new Form();
8024f27905SAndreas Gohr        $form->addFieldsetOpen($this->getLang('delete_animal'));
8124f27905SAndreas Gohr
8224f27905SAndreas Gohr        $animals = $this->helper->getAllAnimals();
8324f27905SAndreas Gohr        array_unshift($animals, '');
8424f27905SAndreas Gohr        $form->addDropdown('delanimal', $animals)->addClass('farmer_choosen_animals');
8524f27905SAndreas Gohr        $form->addTextInput('confirm', $this->getLang('delete_confirm'));
8624f27905SAndreas Gohr        $form->addButton('delete', $this->getLang('delete'));
8724f27905SAndreas Gohr        $form->addFieldsetClose();
8824f27905SAndreas Gohr        echo $form->toHTML();
8924f27905SAndreas Gohr
9024f27905SAndreas Gohr    }
9124f27905SAndreas Gohr
9224f27905SAndreas Gohr
9324f27905SAndreas Gohr}
9424f27905SAndreas Gohr
9524f27905SAndreas Gohr// vim:ts=4:sw=4:et:
96