ILIAS  Release_4_1_x_branch Revision 61804
 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->parseCurrentBlock();
216  }
217 
218 
219  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
220 
221  $this->tpl->setVariable("TXT_LOGOUT", $lng->txt("logout"));
222  $this->tpl->setVariable("HEADER_ICON", ilUtil::getImagePath("HeaderIcon.png"));
223  $this->tpl->setVariable("HEADER_BG_IMAGE", ilUtil::getImagePath("HeaderBackground.gif"));
224  include_once("./Modules/SystemFolder/classes/class.ilObjSystemFolder.php");
225  $this->tpl->setVariable("TXT_HEADER_TITLE", ilObjSystemFolder::_getHeaderTitle());
226 
227  // set link to return to desktop, not depending on a specific position in the hierarchy
228  //$this->tpl->setVariable("SCRIPT_START", $this->getScriptTarget("start.php"));
229  }
230  else
231  {
232  $this->tpl->setVariable("HEADER_ICON", ilUtil::getImagePath("HeaderIcon.png"));
233  }
234 
235  $this->tpl->setVariable("TXT_MAIN_MENU", $lng->txt("main_menu"));
236 
237  $this->tpl->parseCurrentBlock();
238  }
239 
246  function renderMainMenuListEntries($a_tpl, $a_call_get = true)
247  {
248  global $rbacsystem, $lng, $ilias, $tree, $ilUser, $ilSetting;
249 
250  // personal desktop
251  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
252  {
253  $this->renderEntry($a_tpl, "desktop",
254  $lng->txt("personal_desktop"),
255  $this->getScriptTarget("ilias.php?baseClass=ilPersonalDesktopGUI"),
256  $this->target);
257  }
258 
259  // repository
260  include_once('classes/class.ilLink.php');
261  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
262  $title = $nd["title"];
263  if ($title == "ILIAS")
264  {
265  $title = $lng->txt("repository");
266  }
267  $this->renderEntry($a_tpl, "repository",
268  $title,
269  ilLink::_getStaticLink(1,'root',true),
270  $this->target);
271 
272  // search
273  include_once 'Services/Search/classes/class.ilSearchSettings.php';
274  if($rbacsystem->checkAccess('search',ilSearchSettings::_getSearchSettingRefId()))
275  {
276  $this->renderEntry($a_tpl, "search",
277  $lng->txt("search"),
278  $this->getScriptTarget('ilias.php?baseClass=ilSearchController'),
279  $this->target);
280  }
281 
282  // mail
283  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
284  {
285  include_once "Services/Mail/classes/class.ilMail.php";
286 
287  $mail = new ilMail($_SESSION["AccountId"]);
288  if($rbacsystem->checkAccess('mail_visible',$mail->getMailObjectReferenceId()))
289  {
290  $add = '';
291 
292  if( $new_mails = ilMailbox::_countNewMails($_SESSION["AccountId"]) )
293  {
294  $mail = new ilMail($_SESSION['AccountId']);
295  $add = " ".sprintf($lng->txt("cnt_new"), $new_mails);
296  }
297 
298  $this->renderEntry($a_tpl, "mail",
299  $lng->txt("mail").$add,
300  $this->getScriptTarget("ilias.php?baseClass=ilMailGUI"),
301  $this->target);
302  }
303  }
304 
305 
306  // webshop
307  if(IS_PAYMENT_ENABLED)
308  {
309  $a_tpl->setCurrentBlock('shopbutton');
310  $a_tpl->setVariable('SCRIPT_SHOP', $this->getScriptTarget('ilias.php?baseClass=ilShopController&cmd=clearFilter'));
311  $a_tpl->setVariable('TARGET_SHOP', $this->target);
312 
313  include_once 'Services/Payment/classes/class.ilPaymentShoppingCart.php';
314  $objShoppingCart = new ilPaymentShoppingCart($ilUser);
315  $items = $objShoppingCart->getEntries();
316 
317  $a_tpl->setVariable('TXT_SHOP', $lng->txt('shop'));
318 
319  // shoppingcart
320  if(count($items) > 0 )
321  {
322 
323  $a_tpl->setVariable('SCRIPT_SHOPPINGCART', $this->getScriptTarget('ilias.php?baseClass=ilShopController&cmd=redirect&redirect_class=ilshopshoppingcartgui'));
324  $a_tpl->setVariable('TARGET_SHOPPINGCART', $this->target);
325  $a_tpl->setVariable('TXT_SHOPPINGCART', '('.count($items).')');
326  if($this->active == 'shop')
327  {
328  $a_tpl->setVariable('MM_CLASS_SHOPPINGCART', 'MMActive');
329  }
330  else
331  {
332  $a_tpl->setVariable('MM_CLASS_SHOPPINGCART', 'MMInactive');
333  }
334  }
335 
336  if($this->active == 'shop')
337  {
338  $a_tpl->setVariable('MM_CLASS', 'MMActive');
339  $a_tpl->setVariable("SEL", '<span class="ilAccHidden">('.$lng->txt("stat_selected").')</span>');
340  if(count($items) > 0 )
341  {
342  $a_tpl->setVariable('STYLE_SHOP', 'style="margin-right: 5px;"');
343  }
344  }
345  else
346  {
347  $a_tpl->setVariable('MM_CLASS', 'MMInactive');
348  if(count($items) > 0 )
349  {
350  $a_tpl->setVariable('STYLE_SHOP', 'style="margin-right: 5px;"');
351  }
352  }
353  $a_tpl->parseCurrentBlock();
354 
355  }
356 
357  // administration
359  {
360  $this->renderEntry($a_tpl, "administration",
361  $lng->txt("administration"),
362  $this->getScriptTarget("ilias.php?baseClass=ilAdministrationGUI"),
363  $this->target);
364  }
365 
366 
367  // navigation history
368  require_once("Services/Navigation/classes/class.ilNavigationHistoryGUI.php");
370  $nav_html = $nav_hist->getHTML();
371  if ($nav_html != "")
372  {
373 
374  $a_tpl->setCurrentBlock("nav_history");
375  $a_tpl->setVariable("TXT_LAST_VISITED", $lng->txt("last_visited"));
376  $a_tpl->setVariable("NAVIGATION_HISTORY", $nav_html);
377  $a_tpl->parseCurrentBlock();
378  }
379 
380 
381  // chat messages
382  if ($ilSetting->get('chat_message_notify_status') == 1 && $_REQUEST['baseClass'] != 'ilChatPresentationGUI' && $ilUser->getPref('chat_message_notify_status') == 1) {
383  include_once 'Modules/Chat/classes/class.ilChatMessageNotifyGUI.php';
384  $msg_notify = new ilChatMessageNotifyGUI();
385  $html = $msg_notify->getHtml();
386  if ($html) {
387  $a_tpl->setCurrentBlock("chat_lastmsg");
388  $a_tpl->setVariable('CHAT_LAST_MESSAGE', $html);
389  $a_tpl->parseCurrentBlock();
390  }
391 
392  }
393 
394  // chat invitations
395  include_once 'Modules/Chat/classes/class.ilChatInvitationGUI.php';
396  $chat_invitation_gui = new ilChatInvitationGUI();
397  $chat_invitation_html = $chat_invitation_gui->getHTML();
398  if(trim($chat_invitation_html) != '')
399  {
400  $a_tpl->setCurrentBlock('chatbutton');
401  $a_tpl->setVariable('CHAT_INVITATIONS', $chat_invitation_html);
402  $a_tpl->parseCurrentBlock();
403  }
404 
405  if ($a_call_get)
406  {
407  return $a_tpl->get();
408  }
409 
410  return "";
411  }
412 
419  function renderEntry($a_tpl, $a_id, $a_txt, $a_script, $a_target = "_top")
420  {
421  global $lng;
422 
423  $id = strtolower($a_id);
424  $id_up = strtoupper($a_id);
425  $a_tpl->setCurrentBlock("entry_".$id);
426  $a_tpl->setVariable("TXT_".$id_up, $a_txt);
427  $a_tpl->setVariable("SCRIPT_".$id_up, $a_script);
428  $a_tpl->setVariable("TARGET_".$id_up, $a_target);
429  if ($this->active == $a_id || ($this->active == "" && $a_id == "repository"))
430  {
431  $a_tpl->setVariable("MM_CLASS", "MMActive");
432  $a_tpl->setVariable("SEL", '<span class="ilAccHidden">('.$lng->txt("stat_selected").')</span>');
433  }
434  else
435  {
436  $a_tpl->setVariable("MM_CLASS", "MMInactive");
437  }
438  $a_tpl->parseCurrentBlock();
439  }
440 
441 
445  function getScriptTarget($a_script)
446  {
447  global $ilias;
448 
449  $script = "./".$a_script;
450 
451  //if ($this->start_template == true)
452  //{
453  //if(is_file("./templates/".$ilias->account->skin."/tpl.start.html"))
454  //{
455  // $script = "./start.php?script=".rawurlencode($script);
456  //}
457  //}
458  if (defined("ILIAS_MODULE"))
459  {
460  $script = ".".$script;
461  }
462  return $script;
463  }
464 
466  {
467  global $rbacsystem;
468 
469  if($rbacsystem->checkAccess("visible,read", SYSTEM_FOLDER_ID))
470  {
471  return true;
472  }
473  return false;
474  }
475 
476  function getHTML()
477  {
478  include_once './Services/Container/classes/class.ilMemberViewSettings.php';
480 
481  if($set->isActive())
482  {
483  return $this->getMemberViewHTML();
484  }
485 
486 
487  $this->setTemplateVars();
488  return $this->tpl->get();
489  }
490 
491  protected function getMemberViewHTML()
492  {
493  global $lng;
494 
495  $this->tpl = new ilTemplate('tpl.member_view_main_menu.html',true,true,'Services/MainMenu');
496 
497  $this->tpl->setVariable('TXT_MM_HEADER',$lng->txt('mem_view_long'));
498  $this->tpl->setVariable('TXT_MM_CLOSE_PREVIEW',$lng->txt('mem_view_close'));
499  $this->tpl->setVariable('MM_CLOSE_IMG',ilUtil::getImagePath('cancel.gif'));
500 
501  include_once './classes/class.ilLink.php';
502 
503  $this->tpl->setVariable(
504  'HREF_CLOSE_MM',
506  (int) $_GET['ref_id'],
507  ilObject::_lookupType(ilObject::_lookupObjId((int) $_GET['ref_id'])),
508  array('mv' => 0)));
509 
510  return $this->tpl->get();
511  }
512 }
513 ?>