xref: /plugin/farmer/admin/delete.php (revision 341a2d3514259f15502840e8abd56a11b4085405)
124f27905SAndreas Gohr<?php
21da41c8bSAndreas Gohr
31da41c8bSAndreas Gohruse dokuwiki\Extension\AdminPlugin;
41da41c8bSAndreas Gohruse dokuwiki\Form\Form;
51da41c8bSAndreas Gohr
624f27905SAndreas Gohr/**
724f27905SAndreas Gohr * DokuWiki Plugin farmer (Admin Component)
824f27905SAndreas Gohr *
91da41c8bSAndreas Gohr * Information about the farm and the current instance
101da41c8bSAndreas Gohr *
1124f27905SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
1224f27905SAndreas Gohr * @author  Michael Große <grosse@cosmocode.de>
1324f27905SAndreas Gohr * @author  Andreas Gohr <gohr@cosmocode.de>
1424f27905SAndreas Gohr */
151da41c8bSAndreas Gohrclass admin_plugin_farmer_delete extends AdminPlugin
161da41c8bSAndreas Gohr{
1724f27905SAndreas Gohr    /** @var helper_plugin_farmer */
1824f27905SAndreas Gohr    protected $helper;
1924f27905SAndreas Gohr
2024f27905SAndreas Gohr    /**
2124f27905SAndreas Gohr     * admin_plugin_farmer_info constructor.
2224f27905SAndreas Gohr     */
231da41c8bSAndreas Gohr    public function __construct()
241da41c8bSAndreas Gohr    {
2524f27905SAndreas Gohr        $this->helper = plugin_load('helper', 'farmer');
2624f27905SAndreas Gohr    }
2724f27905SAndreas Gohr
28*341a2d35SAndreas Gohr    /** @inheritdoc */
29*341a2d35SAndreas Gohr    public function showInMenu()
301da41c8bSAndreas Gohr    {
31*341a2d35SAndreas Gohr        return false;
3224f27905SAndreas Gohr    }
3324f27905SAndreas Gohr
34*341a2d35SAndreas Gohr    /** @inheritdoc */
351da41c8bSAndreas Gohr    public function handle()
361da41c8bSAndreas Gohr    {
3724f27905SAndreas Gohr        global $INPUT;
3824f27905SAndreas Gohr        global $ID;
3924f27905SAndreas Gohr        if (!$INPUT->has('delete')) return;
4024f27905SAndreas Gohr
4124f27905SAndreas Gohr        if ($INPUT->filter('trim')->str('delanimal') === '') {
4224f27905SAndreas Gohr            msg($this->getLang('delete_noanimal'), -1);
4324f27905SAndreas Gohr            return;
4424f27905SAndreas Gohr        }
4524f27905SAndreas Gohr
4624f27905SAndreas Gohr        if ($INPUT->str('delanimal') != $INPUT->str('confirm')) {
4724f27905SAndreas Gohr            msg($this->getLang('delete_mismatch'), -1);
4824f27905SAndreas Gohr            return;
4924f27905SAndreas Gohr        }
5024f27905SAndreas Gohr
518262a4cbSAndreas Gohr        $animaldir = DOKU_FARMDIR . $INPUT->str('delanimal');
5224f27905SAndreas Gohr
5324f27905SAndreas Gohr        if (!$this->helper->isInPath($animaldir, DOKU_FARMDIR) || !is_dir($animaldir)) {
5424f27905SAndreas Gohr            msg($this->getLang('delete_invalid'), -1);
5524f27905SAndreas Gohr            return;
5624f27905SAndreas Gohr        }
5724f27905SAndreas Gohr
5824f27905SAndreas Gohr        // let's delete it
5924f27905SAndreas Gohr        $ok = io_rmdir($animaldir, true);
6024f27905SAndreas Gohr        if ($ok) {
6124f27905SAndreas Gohr            msg($this->getLang('delete_success'), 1);
6224f27905SAndreas Gohr        } else {
6324f27905SAndreas Gohr            msg($this->getLang('delete_fail'), -1);
6424f27905SAndreas Gohr        }
6524f27905SAndreas Gohr
661da41c8bSAndreas Gohr        $link = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => 'delete'], true, '&');
6724f27905SAndreas Gohr        send_redirect($link);
6824f27905SAndreas Gohr    }
6924f27905SAndreas Gohr
70*341a2d35SAndreas Gohr    /** @inheritdoc */
711da41c8bSAndreas Gohr    public function html()
721da41c8bSAndreas Gohr    {
7324f27905SAndreas Gohr
7424f27905SAndreas Gohr        $form = new Form();
7524f27905SAndreas Gohr        $form->addFieldsetOpen($this->getLang('delete_animal'));
7624f27905SAndreas Gohr
7724f27905SAndreas Gohr        $animals = $this->helper->getAllAnimals();
7824f27905SAndreas Gohr        array_unshift($animals, '');
7943551cfcSMichael Grosse        $form->addDropdown('delanimal', $animals)->addClass('farmer_chosen_animals');
8024f27905SAndreas Gohr        $form->addTextInput('confirm', $this->getLang('delete_confirm'));
8124f27905SAndreas Gohr        $form->addButton('delete', $this->getLang('delete'));
8224f27905SAndreas Gohr        $form->addFieldsetClose();
8324f27905SAndreas Gohr        echo $form->toHTML();
8424f27905SAndreas Gohr    }
8524f27905SAndreas Gohr}
86