1632c5618SAndreas Gohr<?php 2632c5618SAndreas Gohr 3632c5618SAndreas Gohr/** 4*0a5d2da2SAndreas Gohr * DokuWiki Plugin farmer (Admin Component) 5632c5618SAndreas Gohr * 6*0a5d2da2SAndreas Gohr * This is the main admin page. It displays the tabs and then loads the sub components 7*0a5d2da2SAndreas Gohr * according to the selected tab 8*0a5d2da2SAndreas Gohr * 9*0a5d2da2SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 10*0a5d2da2SAndreas Gohr * @author Michael Große <grosse@cosmocode.de> 11*0a5d2da2SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 12632c5618SAndreas Gohr */ 13632c5618SAndreas Gohrclass admin_plugin_farmer extends DokuWiki_Admin_Plugin { 14632c5618SAndreas Gohr 15632c5618SAndreas Gohr /** @var helper_plugin_farmer */ 16632c5618SAndreas Gohr protected $helper; 17632c5618SAndreas Gohr /** @var array The available pages for the current user in the current wiki */ 18632c5618SAndreas Gohr protected $pages; 19632c5618SAndreas Gohr /** @var string The currently selected page */ 20632c5618SAndreas Gohr protected $page; 21632c5618SAndreas Gohr /** @var DokuWiki_Admin_Plugin the plugin to use for the current page */ 22632c5618SAndreas Gohr protected $adminplugin; 23632c5618SAndreas Gohr 24632c5618SAndreas Gohr /** 25632c5618SAndreas Gohr * @return bool we're available for managers and admins 26632c5618SAndreas Gohr */ 27632c5618SAndreas Gohr public function forAdminOnly() { 28632c5618SAndreas Gohr return false; 29632c5618SAndreas Gohr } 30632c5618SAndreas Gohr 31632c5618SAndreas Gohr /** 32632c5618SAndreas Gohr * Initialize current page 33632c5618SAndreas Gohr */ 34632c5618SAndreas Gohr public function __construct() { 35632c5618SAndreas Gohr global $INPUT; 36632c5618SAndreas Gohr $this->helper = plugin_load('helper', 'farmer'); 37632c5618SAndreas Gohr 38632c5618SAndreas Gohr // set available pages depending on user and animal 39632c5618SAndreas Gohr $isanimal = (bool) $this->helper->getAnimal(); 40632c5618SAndreas Gohr if($isanimal || !auth_isadmin()) { 41632c5618SAndreas Gohr $this->pages = array( 42632c5618SAndreas Gohr 'info' 43632c5618SAndreas Gohr ); 44632c5618SAndreas Gohr } else { 45632c5618SAndreas Gohr if(!$this->helper->checkFarmSetup()) { 46632c5618SAndreas Gohr $this->pages = array( 47632c5618SAndreas Gohr 'setup' 48632c5618SAndreas Gohr ); 49632c5618SAndreas Gohr } else { 50632c5618SAndreas Gohr $this->pages = array( 51632c5618SAndreas Gohr 'info', 52632c5618SAndreas Gohr 'config', 5349f2871cSAndreas Gohr 'new', 54632c5618SAndreas Gohr 'plugins', 55632c5618SAndreas Gohr ); 56632c5618SAndreas Gohr } 57632c5618SAndreas Gohr } 58632c5618SAndreas Gohr 59632c5618SAndreas Gohr // make sure current page requested is available 60632c5618SAndreas Gohr $this->page = $INPUT->str('sub'); 61632c5618SAndreas Gohr if(!in_array($this->page, $this->pages)) { 62632c5618SAndreas Gohr $this->page = $this->pages[0]; 63632c5618SAndreas Gohr } 64632c5618SAndreas Gohr 65632c5618SAndreas Gohr // load the sub component 66632c5618SAndreas Gohr $this->adminplugin = plugin_load('admin', 'farmer_' . $this->page); 67632c5618SAndreas Gohr if(!$this->adminplugin) nice_die('Something went wrong loading the plugin component for ' . hsc($this->page)); 68632c5618SAndreas Gohr } 69632c5618SAndreas Gohr 70632c5618SAndreas Gohr /** 71632c5618SAndreas Gohr * handle user request 72632c5618SAndreas Gohr */ 73632c5618SAndreas Gohr public function handle() { 74632c5618SAndreas Gohr $this->adminplugin->handle(); 75632c5618SAndreas Gohr } 76632c5618SAndreas Gohr 77632c5618SAndreas Gohr /** 78632c5618SAndreas Gohr * output appropriate tab 79632c5618SAndreas Gohr */ 80632c5618SAndreas Gohr public function html() { 81632c5618SAndreas Gohr global $ID; 82632c5618SAndreas Gohr 83632c5618SAndreas Gohr echo '<div id="plugin__farmer_admin">'; 84632c5618SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 85632c5618SAndreas Gohr 86632c5618SAndreas Gohr echo '<ul class="tabs" id="plugin__farmer_tabs">'; 87632c5618SAndreas Gohr foreach($this->pages as $page) { 88632c5618SAndreas Gohr $link = wl($ID, array('do' => 'admin', 'page' => 'farmer', 'sub' => $page)); 89632c5618SAndreas Gohr $class = ($page == $this->page) ? 'active' : ''; 90632c5618SAndreas Gohr 91632c5618SAndreas Gohr echo '<li class="' . $class . '"><a href="' . $link . '">' . $this->getLang('tab_' . $page) . '</a></li>'; 92632c5618SAndreas Gohr } 93632c5618SAndreas Gohr echo '</ul>'; 94632c5618SAndreas Gohr echo '<div class="panelHeader">'; 95632c5618SAndreas Gohr echo $this->locale_xhtml('tab_' . $this->page); 96632c5618SAndreas Gohr echo '</div>'; 97b6dd15ebSAndreas Gohr echo '<div class="panelMain">'; 98632c5618SAndreas Gohr $this->adminplugin->html(); 99632c5618SAndreas Gohr echo '</div>'; 100b6dd15ebSAndreas Gohr echo '<div class="panelFooter">'; 101b6dd15ebSAndreas Gohr echo $this->locale_xhtml('tab_' . $this->page . '_help'); 102b6dd15ebSAndreas Gohr echo '</div>'; 103632c5618SAndreas Gohr echo '</div>'; 104632c5618SAndreas Gohr } 105632c5618SAndreas Gohr 106632c5618SAndreas Gohr /** 107632c5618SAndreas Gohr * @return int 108632c5618SAndreas Gohr */ 109632c5618SAndreas Gohr public function getMenuSort() { 110632c5618SAndreas Gohr return 42; 111632c5618SAndreas Gohr } 112632c5618SAndreas Gohr 113632c5618SAndreas Gohr} 114632c5618SAndreas Gohr 115