xref: /plugin/farmer/admin.php (revision b6dd15eb5b9f2f42ad7ea073f31334ab97a1caa1)
1632c5618SAndreas Gohr<?php
2632c5618SAndreas Gohr
3632c5618SAndreas Gohr/**
4632c5618SAndreas Gohr * Plugin Skeleton: Displays "Hello World!"
5632c5618SAndreas Gohr *
6632c5618SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7632c5618SAndreas Gohr * @author     Andreas Gohr <dokuwiki@cosmocode.de>
8632c5618SAndreas Gohr */
9632c5618SAndreas Gohrclass admin_plugin_farmer extends DokuWiki_Admin_Plugin {
10632c5618SAndreas Gohr
11632c5618SAndreas Gohr    /** @var helper_plugin_farmer */
12632c5618SAndreas Gohr    protected $helper;
13632c5618SAndreas Gohr    /** @var array The available pages for the current user in the current wiki*/
14632c5618SAndreas Gohr    protected $pages;
15632c5618SAndreas Gohr    /** @var string The currently selected page */
16632c5618SAndreas Gohr    protected $page;
17632c5618SAndreas Gohr    /** @var DokuWiki_Admin_Plugin the plugin to use for the current page*/
18632c5618SAndreas Gohr    protected $adminplugin;
19632c5618SAndreas Gohr
20632c5618SAndreas Gohr    /**
21632c5618SAndreas Gohr     * @return bool we're available for managers and admins
22632c5618SAndreas Gohr     */
23632c5618SAndreas Gohr    public function forAdminOnly() {
24632c5618SAndreas Gohr        return false;
25632c5618SAndreas Gohr    }
26632c5618SAndreas Gohr
27632c5618SAndreas Gohr    /**
28632c5618SAndreas Gohr     * Initialize current page
29632c5618SAndreas Gohr     */
30632c5618SAndreas Gohr    public function __construct() {
31632c5618SAndreas Gohr        global $INPUT;
32632c5618SAndreas Gohr        $this->helper = plugin_load('helper', 'farmer');
33632c5618SAndreas Gohr
34632c5618SAndreas Gohr        // set available pages depending on user and animal
35632c5618SAndreas Gohr        $isanimal = (bool) $this->helper->getAnimal();
36632c5618SAndreas Gohr        if($isanimal || !auth_isadmin()) {
37632c5618SAndreas Gohr            $this->pages = array(
38632c5618SAndreas Gohr                'info'
39632c5618SAndreas Gohr            );
40632c5618SAndreas Gohr        } else {
41632c5618SAndreas Gohr            if(!$this->helper->checkFarmSetup()) {
42632c5618SAndreas Gohr                $this->pages = array(
43632c5618SAndreas Gohr                    'setup'
44632c5618SAndreas Gohr                );
45632c5618SAndreas Gohr            } else {
46632c5618SAndreas Gohr                $this->pages = array(
47632c5618SAndreas Gohr                    'info',
48632c5618SAndreas Gohr                    'config',
4949f2871cSAndreas Gohr                    'new',
50632c5618SAndreas Gohr                    'plugins',
51632c5618SAndreas Gohr                );
52632c5618SAndreas Gohr            }
53632c5618SAndreas Gohr        }
54632c5618SAndreas Gohr
55632c5618SAndreas Gohr        // make sure current page requested is available
56632c5618SAndreas Gohr        $this->page = $INPUT->str('sub');
57632c5618SAndreas Gohr        if(!in_array($this->page, $this->pages)) {
58632c5618SAndreas Gohr            $this->page = $this->pages[0];
59632c5618SAndreas Gohr        }
60632c5618SAndreas Gohr
61632c5618SAndreas Gohr        // load the sub component
62632c5618SAndreas Gohr        $this->adminplugin = plugin_load('admin', 'farmer_'.$this->page);
63632c5618SAndreas Gohr        if(!$this->adminplugin) nice_die('Something went wrong loading the plugin component for '.hsc($this->page));
64632c5618SAndreas Gohr    }
65632c5618SAndreas Gohr
66632c5618SAndreas Gohr    /**
67632c5618SAndreas Gohr     * handle user request
68632c5618SAndreas Gohr     */
69632c5618SAndreas Gohr    public function handle() {
70632c5618SAndreas Gohr        $this->adminplugin->handle();
71632c5618SAndreas Gohr    }
72632c5618SAndreas Gohr
73632c5618SAndreas Gohr    /**
74632c5618SAndreas Gohr     * output appropriate tab
75632c5618SAndreas Gohr     */
76632c5618SAndreas Gohr    public function html() {
77632c5618SAndreas Gohr        global $ID;
78632c5618SAndreas Gohr
79632c5618SAndreas Gohr        echo '<div id="plugin__farmer_admin">';
80632c5618SAndreas Gohr        echo '<h1>'.$this->getLang('menu').'</h1>';
81632c5618SAndreas Gohr
82632c5618SAndreas Gohr        echo '<ul class="tabs" id="plugin__farmer_tabs">';
83632c5618SAndreas Gohr        foreach($this->pages as $page) {
84632c5618SAndreas Gohr            $link = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => $page));
85632c5618SAndreas Gohr            $class = ($page == $this->page) ? 'active' : '';
86632c5618SAndreas Gohr
87632c5618SAndreas Gohr            echo '<li class="' . $class . '"><a href="' . $link . '">' . $this->getLang('tab_' . $page) . '</a></li>';
88632c5618SAndreas Gohr        }
89632c5618SAndreas Gohr        echo '</ul>';
90632c5618SAndreas Gohr        echo '<div class="panelHeader">';
91632c5618SAndreas Gohr        echo $this->locale_xhtml('tab_'.$this->page);
92632c5618SAndreas Gohr        echo '</div>';
93*b6dd15ebSAndreas Gohr        echo '<div class="panelMain">';
94632c5618SAndreas Gohr        $this->adminplugin->html();
95632c5618SAndreas Gohr        echo '</div>';
96*b6dd15ebSAndreas Gohr        echo '<div class="panelFooter">';
97*b6dd15ebSAndreas Gohr        echo $this->locale_xhtml('tab_'.$this->page.'_help');
98*b6dd15ebSAndreas Gohr        echo '</div>';
99632c5618SAndreas Gohr        echo '</div>';
100632c5618SAndreas Gohr    }
101632c5618SAndreas Gohr
102632c5618SAndreas Gohr    /**
103632c5618SAndreas Gohr     * @return int
104632c5618SAndreas Gohr     */
105632c5618SAndreas Gohr    public function getMenuSort() {
106632c5618SAndreas Gohr        return 42;
107632c5618SAndreas Gohr    }
108632c5618SAndreas Gohr
109632c5618SAndreas Gohr}
110632c5618SAndreas Gohr
111