xref: /plugin/farmer/admin.php (revision 0a5d2da2d569b70aa9be68458b77b2616f382e97)
1<?php
2
3/**
4 * DokuWiki Plugin farmer (Admin Component)
5 *
6 * This is the main admin page. It displays the tabs and then loads the sub components
7 * according to the selected tab
8 *
9 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
10 * @author  Michael Große <grosse@cosmocode.de>
11 * @author  Andreas Gohr <gohr@cosmocode.de>
12 */
13class admin_plugin_farmer extends DokuWiki_Admin_Plugin {
14
15    /** @var helper_plugin_farmer */
16    protected $helper;
17    /** @var array The available pages for the current user in the current wiki */
18    protected $pages;
19    /** @var string The currently selected page */
20    protected $page;
21    /** @var DokuWiki_Admin_Plugin the plugin to use for the current page */
22    protected $adminplugin;
23
24    /**
25     * @return bool we're available for managers and admins
26     */
27    public function forAdminOnly() {
28        return false;
29    }
30
31    /**
32     * Initialize current page
33     */
34    public function __construct() {
35        global $INPUT;
36        $this->helper = plugin_load('helper', 'farmer');
37
38        // set available pages depending on user and animal
39        $isanimal = (bool) $this->helper->getAnimal();
40        if($isanimal || !auth_isadmin()) {
41            $this->pages = array(
42                'info'
43            );
44        } else {
45            if(!$this->helper->checkFarmSetup()) {
46                $this->pages = array(
47                    'setup'
48                );
49            } else {
50                $this->pages = array(
51                    'info',
52                    'config',
53                    'new',
54                    'plugins',
55                );
56            }
57        }
58
59        // make sure current page requested is available
60        $this->page = $INPUT->str('sub');
61        if(!in_array($this->page, $this->pages)) {
62            $this->page = $this->pages[0];
63        }
64
65        // load the sub component
66        $this->adminplugin = plugin_load('admin', 'farmer_' . $this->page);
67        if(!$this->adminplugin) nice_die('Something went wrong loading the plugin component for ' . hsc($this->page));
68    }
69
70    /**
71     * handle user request
72     */
73    public function handle() {
74        $this->adminplugin->handle();
75    }
76
77    /**
78     * output appropriate tab
79     */
80    public function html() {
81        global $ID;
82
83        echo '<div id="plugin__farmer_admin">';
84        echo '<h1>' . $this->getLang('menu') . '</h1>';
85
86        echo '<ul class="tabs" id="plugin__farmer_tabs">';
87        foreach($this->pages as $page) {
88            $link = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => $page));
89            $class = ($page == $this->page) ? 'active' : '';
90
91            echo '<li class="' . $class . '"><a href="' . $link . '">' . $this->getLang('tab_' . $page) . '</a></li>';
92        }
93        echo '</ul>';
94        echo '<div class="panelHeader">';
95        echo $this->locale_xhtml('tab_' . $this->page);
96        echo '</div>';
97        echo '<div class="panelMain">';
98        $this->adminplugin->html();
99        echo '</div>';
100        echo '<div class="panelFooter">';
101        echo $this->locale_xhtml('tab_' . $this->page . '_help');
102        echo '</div>';
103        echo '</div>';
104    }
105
106    /**
107     * @return int
108     */
109    public function getMenuSort() {
110        return 42;
111    }
112
113}
114
115