ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMainMenuGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
32 {
38  var $ilias;
39  var $tpl;
40  var $target;
42 
43 
49  function ilMainMenuGUI($a_target = "_top", $a_use_start_template = false)
50  {
51  global $ilias;
52 
53 
54  $this->tpl = new ilTemplate("tpl.main_buttons.html", true, true);
55  $this->ilias =& $ilias;
56  $this->target = $a_target;
57  $this->start_template = $a_use_start_template;
58  $this->small = false;
59  }
60 
61  function setSmallMode($a_small)
62  {
63  $this->small = $a_small;
64  }
65 
69  function setActive($a_active)
70  {
71  $this->active = $a_active;
72  }
73 
77  function setTemplate(&$tpl)
78  {
79  echo "ilMainMenu->setTemplate is deprecated. Use getHTML instead.";
80  return;
81  $this->tpl =& $tpl;
82  }
83 
87  function getTemplate()
88  {
89  echo "ilMainMenu->getTemplate is deprecated. Use getHTML instead.";
90  return;
91  }
92 
96  function addMenuBlock($a_var = "CONTENT", $a_block = "navigation")
97  {
98  echo "ilMainMenu->addMenuBlick is deprecated. Use getHTML instead.";
99  return;
100  $this->tpl->addBlockFile($a_var, $a_block, "tpl.main_buttons.html");
101  }
102 
106  function setTemplateVars()
107  {
108  global $rbacsystem, $lng, $ilias, $tree, $ilUser;
109 
110 
111  // navigation history
112  require_once("Services/Navigation/classes/class.ilNavigationHistoryGUI.php");
114  $nav_html = $nav_hist->getHTML();
115 
116  if ($nav_html != "")
117  {
118 
119  $this->tpl->setCurrentBlock("nav_history");
120  $this->tpl->setVariable("NAVIGATION_HISTORY", $nav_html);
121  $this->tpl->parseCurrentBlock();
122  }
123 
124  // administration button
126  {
127  $this->tpl->setCurrentBlock("userisadmin");
128  $this->tpl->setVariable("IMG_ADMIN", ilUtil::getImagePath("navbar/admin.gif", false));
129  $this->tpl->setVariable("IMG_SPACE_ADMIN", ilUtil::getImagePath("spacer.gif", false));
130  $this->tpl->setVariable("TXT_ADMINISTRATION", $lng->txt("administration"));
131  $this->tpl->setVariable("SCRIPT_ADMIN", $this->getScriptTarget("ilias.php?baseClass=ilAdministrationGUI"));
132  $this->tpl->setVariable("TARGET_ADMIN", $this->target);
133  if ($this->active == "administration")
134  {
135  $this->tpl->setVariable("MM_CLASS", "MMActive");
136  }
137  else
138  {
139  $this->tpl->setVariable("MM_CLASS", "MMInactive");
140  }
141  $this->tpl->parseCurrentBlock();
142  }
143 
144  // search
145  include_once 'Services/Search/classes/class.ilSearchSettings.php';
146  if($rbacsystem->checkAccess('search',ilSearchSettings::_getSearchSettingRefId()))
147  {
148  $this->tpl->setCurrentBlock("searchbutton");
149  $this->tpl->setVariable("SCRIPT_SEARCH",$this->getScriptTarget('ilias.php?baseClass=ilSearchController'));
150  $this->tpl->setVariable("TARGET_SEARCH",$this->target);
151  $this->tpl->setVariable("TXT_SEARCH", $lng->txt("search"));
152  if ($this->active == "search")
153  {
154  $this->tpl->setVariable("MM_CLASS", "MMActive");
155  }
156  else
157  {
158  $this->tpl->setVariable("MM_CLASS", "MMInactive");
159  }
160  $this->tpl->parseCurrentBlock();
161  }
162 
163 
164  // webshop
165  include_once 'payment/classes/class.ilGeneralSettings.php';
166  if((bool)ilGeneralSettings::_getInstance()->get('shop_enabled'))
167  {
168  $this->tpl->setCurrentBlock('shopbutton');
169  $this->tpl->setVariable('SCRIPT_SHOP', $this->getScriptTarget('ilias.php?baseClass=ilShopController&cmd=clearFilter'));
170  $this->tpl->setVariable('TARGET_SHOP', $this->target);
171 
172  include_once 'payment/classes/class.ilPaymentShoppingCart.php';
173  $objShoppingCart = new ilPaymentShoppingCart($ilUser);
174  $items = $objShoppingCart->getEntries();
175 
176  $this->tpl->setVariable('TXT_SHOP', $lng->txt('shop').(count($items) > 0 ? ' ('.count($items).')' : ''));
177 
178  if($this->active == 'shop')
179  {
180  $this->tpl->setVariable('MM_CLASS', 'MMActive');
181  }
182  else
183  {
184  $this->tpl->setVariable('MM_CLASS', 'MMInactive');
185  }
186  $this->tpl->parseCurrentBlock();
187  }
188 
189  // help button
190  //$this->tpl->setCurrentBlock("userhelp");
191  //$this->tpl->setVariable("TXT_HELP", $lng->txt("help"));
192  //$this->tpl->setVariable("SCRIPT_HELP", "ilias.php?baseClass=ilHelpGUI");
193  //$this->tpl->setVariable("TARGET_HELP", "ilias_help");
194  //$this->tpl->parseCurrentBlock();
195 
196  $this->tpl->setVariable("IMG_SPACE", ilUtil::getImagePath("spacer.gif", false));
197 
198  // mail & desktop button
199  if ($_SESSION["AccountId"] != ANONYMOUS_USER_ID)
200  {
201  $this->tpl->setCurrentBlock("desktopbutton");
202  $this->tpl->setVariable("IMG_DESK", ilUtil::getImagePath("navbar/desk.gif", false));
203  $this->tpl->setVariable("IMG_SPACE_DESK", ilUtil::getImagePath("spacer.gif", false));
204  $this->tpl->setVariable("TXT_PERSONAL_DESKTOP", $lng->txt("personal_desktop"));
205  $this->tpl->setVariable("SCRIPT_DESK", $this->getScriptTarget("ilias.php?baseClass=ilPersonalDesktopGUI&PDHistory=1"));
206  $this->tpl->setVariable("TARGET_DESK", $this->target);
207  if ($this->active == "desktop")
208  {
209  $this->tpl->setVariable("MM_CLASS", "MMActive");
210  }
211  else
212  {
213  $this->tpl->setVariable("MM_CLASS", "MMInactive");
214  }
215  $this->tpl->parseCurrentBlock();
216 
217  include_once "Services/Mail/classes/class.ilMail.php";
218 
219  $mail =& new ilMail($_SESSION["AccountId"]);
220 
221  if($rbacsystem->checkAccess('mail_visible',$mail->getMailObjectReferenceId()))
222  {
223  #$link = "mail_frameset.php";
224  $link = "ilias.php?baseClass=ilMailGUI";
225 
226  if ($mail_id = ilMailbox::hasNewMail($_SESSION["AccountId"]))
227  {
228  $mbox = new ilMailbox($_SESSION["AccountId"]);
229  $mail =& new ilMail($_SESSION['AccountId']);
230  $folder_id = $mbox->getInboxFolder();
231 
232  //$link = "mail_frameset.php?target=".
233  // htmlentities(urlencode("mail_read.php?mobj_id=".
234  // $folder_id."&mail_id=".$mail_id));
235  $add = " ".sprintf($lng->txt("cnt_new"),
236  ilMailbox::_countNewMails($_SESSION["AccountId"]));
237  }
238 
239  $this->tpl->setCurrentBlock("mailbutton");
240  $this->tpl->setVariable("IMG_MAIL", ilUtil::getImagePath("navbar/mail.gif", false));
241  $this->tpl->setVariable("IMG_SPACE_MAIL", ilUtil::getImagePath("spacer.gif", false));
242  $this->tpl->setVariable("TXT_MAIL", $lng->txt("mail").$add);
243  $this->tpl->setVariable("SCRIPT_MAIL", $this->getScriptTarget($link));
244  $this->tpl->setVariable("TARGET_MAIL", $this->target);
245  if ($this->active == "mail")
246  {
247  $this->tpl->setVariable("MM_CLASS", "MMActive");
248  }
249  else
250  {
251  $this->tpl->setVariable("MM_CLASS", "MMInactive");
252  }
253  $this->tpl->parseCurrentBlock();
254  }
255  }
256 
257  // chat invitations
258  include_once 'Modules/Chat/classes/class.ilChatInvitationGUI.php';
259  $chat_invitation_gui = new ilChatInvitationGUI();
260  $chat_invitation_html = $chat_invitation_gui->getHTML();
261  if(trim($chat_invitation_html) != '')
262  {
263  $this->tpl->setCurrentBlock('chatbutton');
264  $this->tpl->setVariable('CHAT_INVITATIONS', $chat_invitation_html);
265  $this->tpl->parseCurrentBlock();
266  }
267 
268  // repository link
269  $this->tpl->setCurrentBlock("rep_button");
270 # $this->tpl->setVariable("SCRIPT_CATALOG",'goto__target__root_1__client__ilias38.html');
271 # #$this->getScriptTarget("repository.php?cmd=frameset&getlast=true"));
272 
273  include_once('classes/class.ilLink.php');
274  $this->tpl->setVariable('SCRIPT_CATALOG',ilLink::_getStaticLink(1,'root',true));
275  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
276  $title = $nd["title"];
277  if ($title == "ILIAS")
278  {
279  $title = $lng->txt("repository");
280  }
281  $this->tpl->setVariable("TXT_CATALOG", $title);
282  if ($this->active == "repository" || $this->active == "")
283  {
284  $this->tpl->setVariable("MM_CLASS", "MMActive");
285  }
286  else
287  {
288  $this->tpl->setVariable("MM_CLASS", "MMInactive");
289  }
290  // set target frame
291  $this->tpl->setVariable("TARGET", $this->target);
292  $this->tpl->parseCurrentBlock();
293 
294 
295  $link_dir = (defined("ILIAS_MODULE"))
296  ? "../"
297  : "";
298 
299  if (!$this->small)
300  {
301 
302  // login stuff
303  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
304  {
305  include_once 'Services/Registration/classes/class.ilRegistrationSettingsGUI.php';
307  {
308  $this->tpl->setCurrentBlock("registration_link");
309  $this->tpl->setVariable("TXT_REGISTER",$lng->txt("register"));
310  $this->tpl->setVariable("LINK_REGISTER", $link_dir."register.php?client_id=".rawurlencode(CLIENT_ID)."&lang=".$ilias->account->getCurrentLanguage());
311  $this->tpl->parseCurrentBlock();
312  }
313 
314  $languages = $lng->getInstalledLanguages();
315 
316  foreach ($languages as $lang_key)
317  {
318  $this->tpl->setCurrentBlock("languages");
319  $this->tpl->setVariable("LANG_KEY", $lang_key);
320  $this->tpl->setVariable("LANG_NAME",
321  ilLanguage::_lookupEntry($lang_key, "meta", "meta_l_".$lang_key));
322  $this->tpl->parseCurrentBlock();
323  }
324 
325  $this->tpl->setVariable("TXT_OK", $lng->txt("ok"));
326  //$this->tpl->setVariable("LANG_FORM_ACTION", "repository.php?ref_id=".$_GET["ref_id"]);
327  $this->tpl->setVariable("LANG_FORM_ACTION", "#");
328  $this->tpl->setVariable("TXT_CHOOSE_LANGUAGE", $lng->txt("choose_language"));
329 
330  $this->tpl->setCurrentBlock("userisanonymous");
331  $this->tpl->setVariable("TXT_NOT_LOGGED_IN",$lng->txt("not_logged_in"));
332  $this->tpl->setVariable("TXT_LOGIN",$lng->txt("log_in"));
333 
334  $target_str = "";
335  if ($_GET["ref_id"] != "")
336  {
337  if ($tree->isInTree($_GET["ref_id"]) && $_GET["ref_id"] != $tree->getRootId())
338  {
339  $obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
340  $type = ilObject::_lookupType($obj_id);
341  $target_str = $type."_".$_GET["ref_id"];
342  }
343  }
344  $this->tpl->setVariable("LINK_LOGIN",
345  $link_dir."login.php?target=".$target_str."&client_id=".rawurlencode(CLIENT_ID)."&cmd=force_login&lang=".$ilias->account->getCurrentLanguage());
346  $this->tpl->parseCurrentBlock();
347  }
348  else
349  {
350  $this->tpl->setCurrentBlock("userisloggedin");
351  $this->tpl->setVariable("TXT_LOGIN_AS",$lng->txt("login_as"));
352  $this->tpl->setVariable("TXT_LOGOUT2",$lng->txt("logout"));
353  $this->tpl->setVariable("LINK_LOGOUT2", $link_dir."logout.php?lang=".$ilias->account->getCurrentLanguage());
354  $this->tpl->setVariable("USERNAME",$ilias->account->getFullname());
355  $this->tpl->parseCurrentBlock();
356  }
357 
358 
359  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
360 
361  $this->tpl->setVariable("TXT_LOGOUT", $lng->txt("logout"));
362 
363  $this->tpl->setVariable("HEADER_ICON", ilUtil::getImagePath("HeaderIcon.png"));
364  $this->tpl->setVariable("HEADER_BG_IMAGE", ilUtil::getImagePath("HeaderBackground.gif"));
365  include_once("./Modules/SystemFolder/classes/class.ilObjSystemFolder.php");
366  $this->tpl->setVariable("TXT_HEADER_TITLE", ilObjSystemFolder::_getHeaderTitle());
367 
368  // set link to return to desktop, not depending on a specific position in the hierarchy
369  //$this->tpl->setVariable("SCRIPT_START", $this->getScriptTarget("start.php"));
370  }
371 
372  $this->tpl->parseCurrentBlock();
373  }
374 
378  function getScriptTarget($a_script)
379  {
380  global $ilias;
381 
382  $script = "./".$a_script;
383 
384  //if ($this->start_template == true)
385  //{
386  //if(is_file("./templates/".$ilias->account->skin."/tpl.start.html"))
387  //{
388  // $script = "./start.php?script=".rawurlencode($script);
389  //}
390  //}
391  if (defined("ILIAS_MODULE"))
392  {
393  $script = ".".$script;
394  }
395  return $script;
396  }
397  // STATIC
399  {
400  global $rbacsystem;
401 
402  if($rbacsystem->checkAccess("visible,read", SYSTEM_FOLDER_ID))
403  {
404  return true;
405  }
406  return false;
407  // Allow all local admins to use the administration
408  return count(ilUtil::_getObjectsByOperations('cat','cat_administrate_users')) ? true : false;
409  }
410 
411  function getHTML()
412  {
413  $this->setTemplateVars();
414  return $this->tpl->get();
415  }
416 }
417 ?>