1632c5618SAndreas Gohr<?php 2632c5618SAndreas Gohr 3*1da41c8bSAndreas Gohruse dokuwiki\Extension\AdminPlugin; 4*1da41c8bSAndreas Gohr 5632c5618SAndreas Gohr/** 60a5d2da2SAndreas Gohr * DokuWiki Plugin farmer (Admin Component) 7632c5618SAndreas Gohr * 80a5d2da2SAndreas Gohr * This is the main admin page. It displays the tabs and then loads the sub components 90a5d2da2SAndreas Gohr * according to the selected tab 100a5d2da2SAndreas Gohr * 110a5d2da2SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 120a5d2da2SAndreas Gohr * @author Michael Große <grosse@cosmocode.de> 130a5d2da2SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 14632c5618SAndreas Gohr */ 15*1da41c8bSAndreas Gohrclass admin_plugin_farmer extends AdminPlugin 16*1da41c8bSAndreas Gohr{ 17632c5618SAndreas Gohr /** @var helper_plugin_farmer */ 18632c5618SAndreas Gohr protected $helper; 19632c5618SAndreas Gohr /** @var array The available pages for the current user in the current wiki */ 20632c5618SAndreas Gohr protected $pages; 21632c5618SAndreas Gohr /** @var string The currently selected page */ 22632c5618SAndreas Gohr protected $page; 23*1da41c8bSAndreas Gohr /** @var AdminPlugin the plugin to use for the current page */ 24632c5618SAndreas Gohr protected $adminplugin; 25632c5618SAndreas Gohr 26632c5618SAndreas Gohr /** 27632c5618SAndreas Gohr * @return bool we're available for managers and admins 28632c5618SAndreas Gohr */ 29*1da41c8bSAndreas Gohr public function forAdminOnly() 30*1da41c8bSAndreas Gohr { 31632c5618SAndreas Gohr return false; 32632c5618SAndreas Gohr } 33632c5618SAndreas Gohr 34632c5618SAndreas Gohr /** 35632c5618SAndreas Gohr * Initialize current page 36632c5618SAndreas Gohr */ 37*1da41c8bSAndreas Gohr public function __construct() 38*1da41c8bSAndreas Gohr { 39632c5618SAndreas Gohr global $INPUT; 40632c5618SAndreas Gohr $this->helper = plugin_load('helper', 'farmer'); 41632c5618SAndreas Gohr 42632c5618SAndreas Gohr // set available pages depending on user and animal 43632c5618SAndreas Gohr $isanimal = (bool) $this->helper->getAnimal(); 44632c5618SAndreas Gohr if ($isanimal || !auth_isadmin()) { 45*1da41c8bSAndreas Gohr $this->pages = ['info']; 46*1da41c8bSAndreas Gohr } elseif (!$this->helper->checkFarmSetup()) { 47*1da41c8bSAndreas Gohr $this->pages = ['setup']; 48632c5618SAndreas Gohr } else { 49*1da41c8bSAndreas Gohr $this->pages = ['info', 'config', 'new', 'plugins', 'delete']; 50632c5618SAndreas Gohr } 51632c5618SAndreas Gohr 52632c5618SAndreas Gohr // make sure current page requested is available 53632c5618SAndreas Gohr $this->page = $INPUT->str('sub'); 54632c5618SAndreas Gohr if (!in_array($this->page, $this->pages)) { 55632c5618SAndreas Gohr $this->page = $this->pages[0]; 56632c5618SAndreas Gohr } 57632c5618SAndreas Gohr 58632c5618SAndreas Gohr // load the sub component 59632c5618SAndreas Gohr $this->adminplugin = plugin_load('admin', 'farmer_' . $this->page); 60632c5618SAndreas Gohr if (!$this->adminplugin) nice_die('Something went wrong loading the plugin component for ' . hsc($this->page)); 61632c5618SAndreas Gohr } 62632c5618SAndreas Gohr 63632c5618SAndreas Gohr /** 64632c5618SAndreas Gohr * handle user request 65632c5618SAndreas Gohr */ 66*1da41c8bSAndreas Gohr public function handle() 67*1da41c8bSAndreas Gohr { 68632c5618SAndreas Gohr $this->adminplugin->handle(); 69632c5618SAndreas Gohr } 70632c5618SAndreas Gohr 71632c5618SAndreas Gohr /** 72632c5618SAndreas Gohr * output appropriate tab 73632c5618SAndreas Gohr */ 74*1da41c8bSAndreas Gohr public function html() 75*1da41c8bSAndreas Gohr { 76632c5618SAndreas Gohr global $ID; 77632c5618SAndreas Gohr 78632c5618SAndreas Gohr echo '<div id="plugin__farmer_admin">'; 79632c5618SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 80632c5618SAndreas Gohr 81632c5618SAndreas Gohr echo '<ul class="tabs" id="plugin__farmer_tabs">'; 82632c5618SAndreas Gohr foreach ($this->pages as $page) { 83*1da41c8bSAndreas Gohr $link = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => $page]); 84632c5618SAndreas Gohr $class = ($page == $this->page) ? 'active' : ''; 85632c5618SAndreas Gohr 86632c5618SAndreas Gohr echo '<li class="' . $class . '"><a href="' . $link . '">' . $this->getLang('tab_' . $page) . '</a></li>'; 87632c5618SAndreas Gohr } 88632c5618SAndreas Gohr echo '</ul>'; 89632c5618SAndreas Gohr echo '<div class="panelHeader">'; 90632c5618SAndreas Gohr echo $this->locale_xhtml('tab_' . $this->page); 91632c5618SAndreas Gohr echo '</div>'; 92b6dd15ebSAndreas Gohr echo '<div class="panelMain">'; 93632c5618SAndreas Gohr $this->adminplugin->html(); 94632c5618SAndreas Gohr echo '</div>'; 95b6dd15ebSAndreas Gohr echo '<div class="panelFooter">'; 96b6dd15ebSAndreas Gohr echo $this->locale_xhtml('tab_' . $this->page . '_help'); 97b6dd15ebSAndreas Gohr echo '</div>'; 98632c5618SAndreas Gohr echo '</div>'; 99632c5618SAndreas Gohr } 100632c5618SAndreas Gohr 101632c5618SAndreas Gohr /** 102632c5618SAndreas Gohr * @return int 103632c5618SAndreas Gohr */ 104*1da41c8bSAndreas Gohr public function getMenuSort() 105*1da41c8bSAndreas Gohr { 106632c5618SAndreas Gohr return 42; 107632c5618SAndreas Gohr } 108632c5618SAndreas Gohr} 109