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