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