ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMainMenuGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
12 {
18  var $ilias;
19  var $tpl;
20  var $target;
22 
23 
29  function ilMainMenuGUI($a_target = "_top", $a_use_start_template = false)
30  {
31  global $ilias;
32 
33 
34  $this->tpl = new ilTemplate("tpl.main_menu.html", true, true,
35  "Services/MainMenu");
36  $this->ilias =& $ilias;
37  $this->target = $a_target;
38  $this->start_template = $a_use_start_template;
39  $this->small = false;
40  }
41 
42  function setSmallMode($a_small)
43  {
44  $this->small = $a_small;
45  }
46 
50  function setActive($a_active)
51  {
52  $this->active = $a_active;
53  }
54 
58  function setTemplate(&$tpl)
59  {
60  echo "ilMainMenu->setTemplate is deprecated. Use getHTML instead.";
61  return;
62  $this->tpl =& $tpl;
63  }
64 
68  function getTemplate()
69  {
70  echo "ilMainMenu->getTemplate is deprecated. Use getHTML instead.";
71  return;
72  }
73 
78  public function setLoginTargetPar($a_val)
79  {
80  $this->login_target_par = $a_val;
81  }
82 
86  public function getLoginTargetPar()
87  {
88  return $this->login_target_par;
89  }
90 
94  function setTemplateVars()
95  {
96  global $rbacsystem, $lng, $ilias, $tree, $ilUser, $ilSetting, $ilPluginAdmin;
97 
98 
99  // search
100  include_once 'Services/Search/classes/class.ilSearchSettings.php';
101  if($rbacsystem->checkAccess('search',ilSearchSettings::_getSearchSettingRefId()))
102  {
103  include_once './Services/Search/classes/class.ilMainMenuSearchGUI.php';
104  $main_search = new ilMainMenuSearchGUI();
105  if(strlen($html = $main_search->getHTML()))
106  {
107  $this->tpl->setVariable('SEARCHBOX',$html);
108  }
109  }
110 
111  // user interface hook [uihk]
112  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "UIComponent", "uihk");
113  $plugin_html = false;
114  foreach ($pl_names as $pl)
115  {
116  $ui_plugin = ilPluginAdmin::getPluginObject(IL_COMP_SERVICE, "UIComponent", "uihk", $pl);
117  $gui_class = $ui_plugin->getUIClassInstance();
118  $resp = $gui_class->getHTML("Services/MainMenu", "main_menu_list_entries",
119  array("main_menu_gui" => $this));
120  if ($resp["mode"] != ilUIHookPluginGUI::KEEP)
121  {
122  $plugin_html = true;
123  break; // first one wins
124  }
125  }
126 
127  // default html
128  if (!$plugin_html || $resp["mode"] != ilUIHookPluginGUI::REPLACE)
129  {
130  $mmle_tpl = new ilTemplate("tpl.main_menu_list_entries.html", true, true, "Services/MainMenu");
131  $mmle_html = $this->renderMainMenuListEntries($mmle_tpl);
132  }
133 
134  // combine plugin and default html
135  if ($plugin_html)
136  {
137  $mmle_html = $gui_class->modifyHTML($mmle_html, $resp);
138  }
139 
140  $this->tpl->setVariable("MAIN_MENU_LIST_ENTRIES", $mmle_html);
141 
142  $link_dir = (defined("ILIAS_MODULE"))
143  ? "../"
144  : "";
145 
146  if (!$this->small)
147  {
148 
149  // login stuff
150  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
151  {
152  include_once 'Services/Registration/classes/class.ilRegistrationSettingsGUI.php';
154  {
155  $this->tpl->setCurrentBlock("registration_link");
156  $this->tpl->setVariable("TXT_REGISTER",$lng->txt("register"));
157  $this->tpl->setVariable("LINK_REGISTER", $link_dir."register.php?client_id=".rawurlencode(CLIENT_ID)."&lang=".$ilias->account->getCurrentLanguage());
158  $this->tpl->parseCurrentBlock();
159  }
160 
161  // language selection
162  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
163  $selection = new ilAdvancedSelectionListGUI();
164  $selection->setFormSelectMode("change_lang_to", "ilLanguageSelection", true,
165  "#", "ilNavHistory", "ilNavHistoryForm",
166  "_top", $lng->txt("ok"), "ilLogin");
167  //$selection->setListTitle($lng->txt("choose_language"));
168  $selection->setListTitle($lng->txt("language"));
169  $selection->setItemLinkClass("small");
170  $languages = $lng->getInstalledLanguages();
171  //var_dump($_SERVER);
172  foreach ($languages as $lang_key)
173  {
174  $base = substr($_SERVER["REQUEST_URI"], strrpos($_SERVER["REQUEST_URI"], "/") + 1);
175  $base = str_replace("lang=", "", $base);
176  $link = ilUtil::appendUrlParameterString($base,
177  "lang=".$lang_key);
178  $selection->addItem(ilLanguage::_lookupEntry($lang_key, "meta", "meta_l_".$lang_key),
179  $lang_key, $link, "", "", "_top");
180  }
181  if (count($languages) > 0)
182  {
183  $this->tpl->setVariable("LANG_SELECT", $selection->getHTML());
184  }
185 
186  $this->tpl->setCurrentBlock("userisanonymous");
187  $this->tpl->setVariable("TXT_NOT_LOGGED_IN",$lng->txt("not_logged_in"));
188  $this->tpl->setVariable("TXT_LOGIN",$lng->txt("log_in"));
189 
190  $target_str = "";
191  if ($this->getLoginTargetPar() != "")
192  {
193  $target_str = $this->getLoginTargetPar();
194  }
195  else if ($_GET["ref_id"] != "")
196  {
197  if ($tree->isInTree($_GET["ref_id"]) && $_GET["ref_id"] != $tree->getRootId())
198  {
199  $obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
200  $type = ilObject::_lookupType($obj_id);
201  $target_str = $type."_".$_GET["ref_id"];
202  }
203  }
204  $this->tpl->setVariable("LINK_LOGIN",
205  $link_dir."login.php?target=".$target_str."&client_id=".rawurlencode(CLIENT_ID)."&cmd=force_login&lang=".$ilias->account->getCurrentLanguage());
206  $this->tpl->parseCurrentBlock();
207  }
208  else
209  {
210  $this->tpl->setCurrentBlock("userisloggedin");
211  $this->tpl->setVariable("TXT_LOGIN_AS",$lng->txt("login_as"));
212  $this->tpl->setVariable("TXT_LOGOUT2",$lng->txt("logout"));
213  $this->tpl->setVariable("LINK_LOGOUT2", $link_dir."logout.php?lang=".$ilias->account->getCurrentLanguage());
214  $this->tpl->setVariable("USERNAME",$ilias->account->getFullname());
215  $this->tpl->setVariable("MATRICULATION",$ilias->account->getMatriculation());
216  $this->tpl->setVariable("TXT_LOGIN",$lng->txt("login"));
217  $this->tpl->setVariable("LOGIN",$ilias->account->getLogin());
218  $this->tpl->parseCurrentBlock();
219  }
220 
221 
222  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
223 
224  $this->tpl->setVariable("TXT_LOGOUT", $lng->txt("logout"));
225  $this->tpl->setVariable("HEADER_ICON", ilUtil::getImagePath("HeaderIcon.png"));
226  $this->tpl->setVariable("HEADER_BG_IMAGE", ilUtil::getImagePath("HeaderBackground.gif"));
227  include_once("./Modules/SystemFolder/classes/class.ilObjSystemFolder.php");
228  $this->tpl->setVariable("TXT_HEADER_TITLE", ilObjSystemFolder::_getHeaderTitle());
229 
230  // set link to return to desktop, not depending on a specific position in the hierarchy
231  //$this->tpl->setVariable("SCRIPT_START", $this->getScriptTarget("start.php"));
232  }
233  else
234  {
235  $this->tpl->setVariable("HEADER_ICON", ilUtil::getImagePath("HeaderIcon.png"));
236  }
237 
238  $this->tpl->setVariable("TXT_MAIN_MENU", $lng->txt("main_menu"));
239 
240  $this->tpl->parseCurrentBlock();
241  }
242 
249  function renderMainMenuListEntries($a_tpl, $a_call_get = true)
250  {
251  global $rbacsystem, $lng, $ilias, $tree, $ilUser, $ilSetting;
252 
253  // personal desktop
254  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
255  {
256  $this->renderEntry($a_tpl, "desktop",
257  $lng->txt("personal_desktop"),
258  $this->getScriptTarget("ilias.php?baseClass=ilPersonalDesktopGUI"),
259  $this->target);
260  }
261 
262  // repository
263  include_once('classes/class.ilLink.php');
264  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
265  $title = $nd["title"];
266  if ($title == "ILIAS")
267  {
268  $title = $lng->txt("repository");
269  }
270  $this->renderEntry($a_tpl, "repository",
271  $title,
272  ilLink::_getStaticLink(1,'root',true),
273  $this->target);
274 
275  // search
276  include_once 'Services/Search/classes/class.ilSearchSettings.php';
277  if($rbacsystem->checkAccess('search',ilSearchSettings::_getSearchSettingRefId()))
278  {
279  $this->renderEntry($a_tpl, "search",
280  $lng->txt("search"),
281  $this->getScriptTarget('ilias.php?baseClass=ilSearchController'),
282  $this->target);
283  }
284 
285  // mail
286  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
287  {
288  include_once "Services/Mail/classes/class.ilMail.php";
289 
290  $mail = new ilMail($_SESSION["AccountId"]);
291  if($rbacsystem->checkAccess('mail_visible',$mail->getMailObjectReferenceId()))
292  {
293  $add = '';
294 
295  if( $new_mails = ilMailbox::_countNewMails($_SESSION["AccountId"]) )
296  {
297  $mail = new ilMail($_SESSION['AccountId']);
298  $add = " ".sprintf($lng->txt("cnt_new"), $new_mails);
299  }
300 
301  $this->renderEntry($a_tpl, "mail",
302  $lng->txt("mail").$add,
303  $this->getScriptTarget("ilias.php?baseClass=ilMailGUI"),
304  $this->target);
305  }
306  }
307 
308 
309  // webshop
310  if(IS_PAYMENT_ENABLED)
311  {
312  $a_tpl->setCurrentBlock('shopbutton');
313  $a_tpl->setVariable('SCRIPT_SHOP', $this->getScriptTarget('ilias.php?baseClass=ilShopController&cmd=clearFilter'));
314  $a_tpl->setVariable('TARGET_SHOP', $this->target);
315 
316  include_once 'Services/Payment/classes/class.ilPaymentShoppingCart.php';
317  $objShoppingCart = new ilPaymentShoppingCart($ilUser);
318  $items = $objShoppingCart->getEntries();
319 
320  $a_tpl->setVariable('TXT_SHOP', $lng->txt('shop'));
321 
322  // shoppingcart
323  if(count($items) > 0 )
324  {
325 
326  $a_tpl->setVariable('SCRIPT_SHOPPINGCART', $this->getScriptTarget('ilias.php?baseClass=ilShopController&cmd=redirect&redirect_class=ilshopshoppingcartgui'));
327  $a_tpl->setVariable('TARGET_SHOPPINGCART', $this->target);
328  $a_tpl->setVariable('TXT_SHOPPINGCART', '('.count($items).')');
329  if($this->active == 'shop')
330  {
331  $a_tpl->setVariable('MM_CLASS_SHOPPINGCART', 'MMActive');
332  }
333  else
334  {
335  $a_tpl->setVariable('MM_CLASS_SHOPPINGCART', 'MMInactive');
336  }
337  }
338 
339  if($this->active == 'shop')
340  {
341  $a_tpl->setVariable('MM_CLASS', 'MMActive');
342  $a_tpl->setVariable("SEL", '<span class="ilAccHidden">('.$lng->txt("stat_selected").')</span>');
343  if(count($items) > 0 )
344  {
345  $a_tpl->setVariable('STYLE_SHOP', 'style="margin-right: 5px;"');
346  }
347  }
348  else
349  {
350  $a_tpl->setVariable('MM_CLASS', 'MMInactive');
351  if(count($items) > 0 )
352  {
353  $a_tpl->setVariable('STYLE_SHOP', 'style="margin-right: 5px;"');
354  }
355  }
356  $a_tpl->parseCurrentBlock();
357 
358  }
359 
360  // administration
362  {
363  $this->renderEntry($a_tpl, "administration",
364  $lng->txt("administration"),
365  $this->getScriptTarget("ilias.php?baseClass=ilAdministrationGUI"),
366  $this->target);
367  }
368 
369 
370  // navigation history
371  require_once("Services/Navigation/classes/class.ilNavigationHistoryGUI.php");
373  $nav_html = $nav_hist->getHTML();
374  if ($nav_html != "")
375  {
376 
377  $a_tpl->setCurrentBlock("nav_history");
378  $a_tpl->setVariable("TXT_LAST_VISITED", $lng->txt("last_visited"));
379  $a_tpl->setVariable("NAVIGATION_HISTORY", $nav_html);
380  $a_tpl->parseCurrentBlock();
381  }
382 
383 
384  if ($a_call_get)
385  {
386  return $a_tpl->get();
387  }
388 
389  return "";
390  }
391 
398  function renderEntry($a_tpl, $a_id, $a_txt, $a_script, $a_target = "_top")
399  {
400  global $lng;
401 
402  $id = strtolower($a_id);
403  $id_up = strtoupper($a_id);
404  $a_tpl->setCurrentBlock("entry_".$id);
405  $a_tpl->setVariable("TXT_".$id_up, $a_txt);
406  $a_tpl->setVariable("SCRIPT_".$id_up, $a_script);
407  $a_tpl->setVariable("TARGET_".$id_up, $a_target);
408  if ($this->active == $a_id || ($this->active == "" && $a_id == "repository"))
409  {
410  $a_tpl->setVariable("MM_CLASS", "MMActive");
411  $a_tpl->setVariable("SEL", '<span class="ilAccHidden">('.$lng->txt("stat_selected").')</span>');
412  }
413  else
414  {
415  $a_tpl->setVariable("MM_CLASS", "MMInactive");
416  }
417  $a_tpl->parseCurrentBlock();
418  }
419 
420 
424  function getScriptTarget($a_script)
425  {
426  global $ilias;
427 
428  $script = "./".$a_script;
429 
430  //if ($this->start_template == true)
431  //{
432  //if(is_file("./templates/".$ilias->account->skin."/tpl.start.html"))
433  //{
434  // $script = "./start.php?script=".rawurlencode($script);
435  //}
436  //}
437  if (defined("ILIAS_MODULE"))
438  {
439  $script = ".".$script;
440  }
441  return $script;
442  }
443 
445  {
446  global $rbacsystem;
447 
448  if($rbacsystem->checkAccess("visible,read", SYSTEM_FOLDER_ID))
449  {
450  return true;
451  }
452  return false;
453  }
454 
455  function getHTML()
456  {
457  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
459 
460  if($set->isActive())
461  {
462  return $this->getMemberViewHTML();
463  }
464 
465 
466  $this->setTemplateVars();
467  return $this->tpl->get();
468  }
469 
470  protected function getMemberViewHTML()
471  {
472  global $lng;
473 
474  $this->tpl = new ilTemplate('tpl.member_view_main_menu.html',true,true,'Services/MainMenu');
475 
476  $this->tpl->setVariable('TXT_MM_HEADER',$lng->txt('mem_view_long'));
477  $this->tpl->setVariable('TXT_MM_CLOSE_PREVIEW',$lng->txt('mem_view_close'));
478  $this->tpl->setVariable('MM_CLOSE_IMG',ilUtil::getImagePath('cancel.gif'));
479 
480  include_once './classes/class.ilLink.php';
481 
482  $this->tpl->setVariable(
483  'HREF_CLOSE_MM',
485  (int) $_GET['ref_id'],
486  ilObject::_lookupType(ilObject::_lookupObjId((int) $_GET['ref_id'])),
487  array('mv' => 0)));
488 
489  return $this->tpl->get();
490  }
491 }
492 ?>