1<?php 2/* 3 +-----------------------------------------------------------------------------+ 4 | ILIAS open source | 5 +-----------------------------------------------------------------------------+ 6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne | 7 | | 8 | This program is free software; you can redistribute it and/or | 9 | modify it under the terms of the GNU General Public License | 10 | as published by the Free Software Foundation; either version 2 | 11 | of the License, or (at your option) any later version. | 12 | | 13 | This program is distributed in the hope that it will be useful, | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | GNU General Public License for more details. | 17 | | 18 | You should have received a copy of the GNU General Public License | 19 | along with this program; if not, write to the Free Software | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 21 +-----------------------------------------------------------------------------+ 22*/ 23 24/** 25 * @classDescription Base class for all ILIAS Views 26 * 27 * @author Stefan Schneider <schneider@hrz.uni-marburg.de 28 * @version $id$ 29 * 30 * @ingroup ServicesView 31 */ 32abstract class ilBaseViewGUI 33{ 34 35 /* 36 * Spacer CSS Classes 37 */ 38 const TOP_SPACER = "ilFixedTopSpacer"; 39 const TOP_SPACER_BAR_ONLY = "ilFixedTopSpacerBarOnly"; 40 41 42 const ROOT_CONTAINER = "container"; 43 const ROOT_CRS = "crs"; 44 const ROOT_GRP = "grp"; 45 46 /** 47 * override these switches in the view constructor 48 */ 49 50 protected $allow_desktop = true; // deprecated but we should discuss concepts 51 52 protected $view_nav = true; 53 54 protected $use_top_bar_url = false; 55 56 protected $root_type = ROOT_CONTAINER; 57 58 /** 59 * 60 */ 61 62 protected $dic = null; 63 64 protected $ctrl = null; 65 66 protected $ilias = null; 67 68 protected $link_dir = ""; 69 70 /** 71 * home id (ref_id) 72 * The view maybe support a view home link in the topbar (static or dynamically, see topbar_back_url in Member- and LTIView) 73 */ 74 protected $home_id = ''; 75 76 /** 77 * home obj_id 78 */ 79 protected $home_obj_id = ''; 80 81 /** 82 * home type (obj_type of ref_id) 83 * The view maybe support a view home link in the topbar (static or dynamically, see topbar_back_url in Member- and LTIView) 84 */ 85 protected $home_type = ''; 86 87 /** 88 * home title (title of ref_id) 89 */ 90 protected $home_title = ''; 91 92 /** 93 * home Link (see topbar_back_url concept in MainMenuGUI) 94 */ 95 protected $home_url = ''; 96 97 /** 98 * cache ref_ids of home subtree items 99 * if request is in home context $show_home_link = false 100 * else $show_home_link = true 101 */ 102 protected $home_items = []; 103 104 /** 105 * show home link in topbar (similar to topbar_back_url = '' in MainMenu) 106 */ 107 protected $show_home_link = false; 108 109 /** 110 * root folder id 111 * Don't allow any access to higher level objects in this view 112 */ 113 protected $root_folder_id = ROOT_FOLDER_ID; 114 115 /** 116 * all allowed items 117 */ 118 protected $root_folder_items = []; // deprecated 119 120 /** 121 * dynamic tree_root_folder_id 122 * show tree from tree_root_id 123 */ 124 public $tree_root_id = ROOT_FOLDER_ID; 125 126 /** 127 * tree root types 128 * show tree from ref_id with obj_types 129 * if requested obj_type of ref_id is in array of $root_tree_types show this id as tree_root_id, 130 * else lookup if a parent obj_type of the ref_id matches the array and set tree_root_id to the first match 131 */ 132 protected $tree_root_types = []; 133 134 /** 135 * Fix tree_id 136 * Show always tree from id 137 */ 138 protected $fix_tree_id = ''; 139 140 /** 141 * ref_id from current request 142 */ 143 protected $current_ref_id = ""; 144 145 /** 146 * obj_type of current ref_id 147 */ 148 protected $current_type = ""; 149 150 151 public function __construct() 152 { 153 global $DIC, $ilCtrl, $ilias, $lng; 154 $this->dic = $DIC; 155 $this->ctrl = $ilCtrl; 156 $this->ilias = $ilias; 157 $this->link_dir = (defined("ILIAS_MODULE")) 158 ? "../" 159 : ""; 160 } 161 162 /** 163 * @return bool 164 */ 165 public function allowDesktop() 166 { 167 return $this->allow_desktop; 168 } 169 170 /** 171 * @return bool 172 */ 173 public function showViewNav() 174 { 175 return $this->view_nav; 176 } 177 178 /** 179 * spacer_class 180 */ 181 public function spacerClass() 182 { 183 return ($this->topBarOnly) ? self::TOP_SPACER_BAR_ONLY : self::TOP_SPACER; 184 } 185 186 /** 187 * css files are added to the header 188 * @return array 189 */ 190 public function addCss() 191 { 192 return []; 193 } 194 195 /** 196 * content of css files are appended to the main page html just before </body> end tag 197 * @return array 198 */ 199 public function appendInlineCss() 200 { 201 return []; 202 } 203 204 /** 205 * helper function for home link creation 206 */ 207 protected function getHomeLink() 208 { 209 return $this->link_dir . "goto.php?target=" . $this->home_type . "_" . $this->home_id; 210 } 211 212 /** 213 * helper function for cmd link creation 214 */ 215 protected function getCmdLink($cmd) 216 { 217 global $ilCtrl; 218 $targetScript = ($ilCtrl->getTargetScript() !== 'ilias.php') ? "ilias.php" : ""; 219 return $this->link_dir . $targetScript . $ilCtrl->getLinkTargetByClass(array('illtiroutergui',strtolower(get_class($this))), $cmd) . "&baseClass=illtiroutergui"; 220 } 221 222 /** 223 * 224 */ 225 public function redirectToHome($_msg_type = self::MSG_INFO, $_msg = '') 226 { 227 //$msg = ($_msg !== '') ? '&view_msg='.$_msg.'&view_msg_type='.$_msg_type : ''; 228 //$link = $this->getHomeLink().$msg; 229 $_SESSION[$_msg_type] = $_msg; 230 $link = $this->getHomeLink(); 231 $this->dic->logger()->lti()->write("redirectLink: " . $link); 232 ilUtil::redirect($link); 233 exit; 234 } 235 236 public function getHomeTitle() 237 { 238 return ilObject::_lookupTitle($this->home_obj_id); 239 } 240 241 /** 242 * Find effective ref_id for request 243 */ 244 public function findEffectiveRefId() 245 { 246 if ((int) $_GET['ref_id']) { 247 $this->current_type = ilObject::_lookupType($_GET['ref_id'], true); 248 return $this->current_ref_id = (int) $_GET['ref_id']; 249 } 250 251 $target_arr = explode('_', (string) $_GET['target']); 252 if (isset($target_arr[1]) and (int) $target_arr[1]) { 253 $this->current_type = ilObject::_lookupType($target_arr[1], true); 254 $this->home_title = ilObject::_lookupTitle(ilObject::_lookupObjectId($target_arr[1])); 255 return $this->current_ref_id = (int) $target_arr[1]; 256 } 257 } 258 259 public function getHttpPath() 260 { 261 include_once './Services/Http/classes/class.ilHTTPS.php'; 262 $https = new ilHTTPS(); 263 264 if ($https->isDetected()) { 265 $protocol = 'https://'; 266 } else { 267 $protocol = 'http://'; 268 } 269 $host = $_SERVER['HTTP_HOST']; 270 $rq_uri = $_SERVER['REQUEST_URI']; 271 return ilUtil::removeTrailingPathSeparators($protocol . $host . $rq_uri); 272 } 273 274 /** 275 * @return bool 276 */ 277 public function isContainer($obj_type) 278 { 279 //return true; 280 return preg_match("/(crs|grp|cat|root|folder)/", $obj_type); 281 } 282 283 protected function log($txt) 284 { 285 $this->dic->logger()->lti()->write($txt); 286 } 287 288 /** 289 * get session value != '' 290 * 291 * @param $sess_key string 292 * @return string 293 */ 294 public function getSessionValue($sess_key) 295 { 296 if (isset($_SESSION[$sess_key]) && $_SESSION[$sess_key] != '') { 297 return $_SESSION[$sess_key]; 298 } else { 299 return ''; 300 } 301 } 302} 303