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