ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjRootFolderGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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 
36 require_once "./Services/Container/classes/class.ilContainerGUI.php";
37 require_once "./Modules/Category/classes/class.ilObjCategoryGUI.php";
38 
40 {
45  function ilObjRootFolderGUI($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
46  {
47  global $lng;
48 
49  $this->type = "root";
50  $this->ilContainerGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
51 
52  $lng->loadLanguageModule("cntr");
53  }
54 
59  {
60  ilObjCategoryGUI::_importCategoriesForm($this->ref_id, $this->tpl);
61  }
62 
69  {
70  ilUtil::sendInfo($this->lng->txt("action_aborted"),true);
71  $this->ctrl->returnToParent($this);
72  }
73 
78  {
79  ilObjCategoryGUI::_importCategories($this->ref_id,0);
80  }
81 
82 
87  {
88  ilObjCategoryGUI::_importCategories($this->ref_id,1);
89  }
90 
91 
92  function getTabs(&$tabs_gui)
93  {
94  global $rbacsystem;
95 
96  $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
97 
98  if ($rbacsystem->checkAccess('read',$this->ref_id))
99  {
100  $tabs_gui->addTarget("view_content",
101  $this->ctrl->getLinkTarget($this, ""),
102  array("", "view", "render"));
103  }
104 
105  if ($rbacsystem->checkAccess('write',$this->ref_id))
106  {
107  $force_active = ($_GET["cmd"] == "edit")
108  ? true
109  : false;
110  $tabs_gui->addTarget("edit_properties",
111  $this->ctrl->getLinkTarget($this, "edit"), "edit", get_class($this)
112  , "", $force_active);
113  }
114 
115  // parent tabs (all container: edit_permission, clipboard, trash
116  parent::getTabs($tabs_gui);
117 
118  }
119 
120  function &executeCommand()
121  {
122  global $rbacsystem;
123 
124  $next_class = $this->ctrl->getNextClass($this);
125  $cmd = $this->ctrl->getCmd();
126 
127  switch($next_class)
128  {
129  case 'ilcontainerlinklistgui':
130  include_once("./classes/class.ilContainerLinkListGUI.php");
131  $link_list_gui =& new ilContainerLinkListGUI();
132  $ret =& $this->ctrl->forwardCommand($link_list_gui);
133  break;
134 
135  // container page editing
136  case "ilpageobjectgui":
137  $this->checkPermission("write");
138  $this->prepareOutput(false);
139  $ret = $this->forwardToPageObject();
140  if ($ret != "")
141  {
142  $this->tpl->setContent($ret);
143  }
144 
145  /*$this->tpl->getStandardTemplate();
146  $this->setLocator();
147  ilUtil::sendInfo();
148  ilUtil::infoPanel();
149  //$this->prepareOutput(false);
150  $ret = $this->forwardToPageObject();
151  $this->setTitleAndDescription();
152  $this->setPageEditorTabs();
153  return $ret;*/
154  break;
155 
156  case 'ilpermissiongui':
157  $this->prepareOutput();
158  include_once("./classes/class.ilPermissionGUI.php");
159  $perm_gui =& new ilPermissionGUI($this);
160  $ret =& $this->ctrl->forwardCommand($perm_gui);
161  break;
162 
163  default:
164  $this->prepareOutput();
165  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
166  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
168 
169  if(!$cmd)
170  {
171  $cmd = "render";
172  }
173 
174  $cmd .= "Object";
175  $this->$cmd();
176 
177  break;
178  }
179  return true;
180  }
181 
187  function editObject()
188  {
189  global $rbacsystem, $lng;
190 
191  if (!$rbacsystem->checkAccess("write", $this->ref_id))
192  {
193  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
194  }
195 
196  $this->ctrl->setParameter($this,"mode","edit");
197 
198  // for lang selection include metadata class
199  include_once "./Services/MetaData/classes/class.ilMDLanguageItem.php";
200 
201  $this->getTemplateFile("edit",'');
202  $this->showSortingSettings();
203 
204  // hide header icon and title
205  $this->tpl->setVariable("TXT_HIDE_HEADER_ICON_AND_TITLE", $lng->txt("cntr_hide_title_and_icon"));
206  if (ilContainer::_lookupContainerSetting($this->object->getId(), "hide_header_icon_and_title"))
207  {
208  $this->tpl->setVariable("CHK_HIDE_ICON", ' checked="checked" ');
209  }
210 
211  $array_push = true;
212 
213  if ($_SESSION["error_post_vars"])
214  {
215  $_SESSION["translation_post"] = $_SESSION["error_post_vars"];
216  $_GET["mode"] = "session";
217  $array_push = false;
218  }
219 
220  // load from db if edit category is called the first time
221  if (($_GET["mode"] != "session"))
222  {
223  $data = $this->object->getTranslations();
224  $_SESSION["translation_post"] = $data;
225  $array_push = false;
226  } // remove a translation from session
227  elseif ($_GET["entry"] != 0)
228  {
229  array_splice($_SESSION["translation_post"]["Fobject"],$_GET["entry"],1,array());
230 
231  if ($_GET["entry"] == $_SESSION["translation_post"]["default_language"])
232  {
233  $_SESSION["translation_post"]["default_language"] = "";
234  }
235  }
236 
237  $data = $_SESSION["translation_post"];
238 
239  // add additional translation form
240  if (!$_GET["entry"] and $array_push)
241  {
242  $count = array_push($data["Fobject"],array("title" => "","desc" => ""));
243  }
244  else
245  {
246  $count = count($data["Fobject"]);
247  }
248 
249  // stripslashes in form?
250  $strip = isset($_SESSION["translation_post"]) ? true : false;
251 
252  // add empty entry, if nothing exists
253  if (count($data["Fobject"]) == 0)
254  {
255  $data["Fobject"][0] =
256  array("title" => "",
257  "desc" => "",
258  "lang" => $lng->getDefaultLanguage()
259  );
260  }
261 
262  foreach ($data["Fobject"] as $key => $val)
263  {
264  // add translation button
265  if ($key == $count -1)
266  {
267  $this->tpl->setCurrentBlock("addTranslation");
268  $this->tpl->setVariable("TXT_ADD_TRANSLATION",$this->lng->txt("add_translation")." >>");
269  $this->tpl->parseCurrentBlock();
270  }
271 
272  // remove translation button
273  if ($key != 0)
274  {
275  $this->tpl->setCurrentBlock("removeTranslation");
276  $this->tpl->setVariable("TXT_REMOVE_TRANSLATION",$this->lng->txt("remove_translation"));
277  $this->ctrl->setParameter($this, "entry", $key);
278  $this->ctrl->setParameter($this, "mode", "edit");
279  $this->tpl->setVariable("LINK_REMOVE_TRANSLATION", $this->ctrl->getLinkTarget($this, "removeTranslation"));
280  $this->tpl->parseCurrentBlock();
281  }
282 
283  // lang selection
284  $this->tpl->addBlockFile("SEL_LANGUAGE", "sel_language", "tpl.lang_selection.html", false);
285  $this->tpl->setVariable("SEL_NAME", "Fobject[".$key."][lang]");
286 
287  $languages = ilMDLanguageItem::_getLanguages();
288 
289  foreach ($languages as $code => $language)
290  {
291  $this->tpl->setCurrentBlock("lg_option");
292  $this->tpl->setVariable("VAL_LG", $code);
293  $this->tpl->setVariable("TXT_LG", $language);
294 
295  if ($code == $val["lang"])
296  {
297  $this->tpl->setVariable("SELECTED", "selected=\"selected\"");
298  }
299 
300  $this->tpl->parseCurrentBlock();
301  }
302 
303  // object data
304  $this->tpl->setCurrentBlock("obj_form");
305 
306  if ($key == 0)
307  {
308  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("repository"));
309  }
310  else
311  {
312  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("translation")." ".$key);
313  }
314 
315  if ($key == $data["default_language"])
316  {
317  $this->tpl->setVariable("CHECKED", "checked=\"checked\"");
318  }
319 
320  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
321  $this->tpl->setVariable("TXT_DESC", $this->lng->txt("title_long"));
322  $this->tpl->setVariable("TXT_DEFAULT", $this->lng->txt("default"));
323  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
324  $this->tpl->setVariable("TITLE", ilUtil::prepareFormOutput($val["title"],$strip));
325  $this->tpl->setVariable("DESC", ilUtil::stripSlashes($val["desc"]));
326  $this->tpl->setVariable("NUM", $key);
327  $this->tpl->parseCurrentBlock();
328  }
329 
330  $this->showCustomIconsEditing();
331 
332  // global
333  $this->tpl->setCurrentBlock("adm_content");
334  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
335  $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
336  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
337  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
338  $this->tpl->setVariable("CMD_SUBMIT", "update");
339  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
340  }
341 
346  {
347  global $lng;
348 
350  $this->tpl->setDescription("");
351  if ($this->object->getTitle() == "ILIAS")
352  {
353  $this->tpl->setTitle($lng->txt("repository"));
354  }
355  else
356  {
357  if ($this->object->getDescription() != "")
358  {
359  $this->tpl->setTitle($this->object->getDescription());
360  }
361  }
362  }
363 
369  function updateObject()
370  {
371  global $rbacsystem;
372  if (!$rbacsystem->checkAccess("write", $this->object->getRefId()))
373  {
374  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
375  }
376  else
377  {
378  $data = $_POST;
379 
380  // default language set?
381  if (!isset($data["default_language"]))
382  {
383  $this->ilias->raiseError($this->lng->txt("msg_no_default_language"),$this->ilias->error_obj->MESSAGE);
384  }
385 
386  // prepare array fro further checks
387  foreach ($data["Fobject"] as $key => $val)
388  {
389  $langs[$key] = $val["lang"];
390  }
391 
392  $langs = array_count_values($langs);
393 
394  // all languages set?
395  if (array_key_exists("",$langs) &&
396  (count($data["Fobject"]) > 1 || $data["Fobject"][0]["title"] != ""))
397  {
398  $this->ilias->raiseError($this->lng->txt("msg_no_language_selected"),$this->ilias->error_obj->MESSAGE);
399  }
400 
401  // no single language is selected more than once?
402  if (array_sum($langs) > count($langs))
403  {
404  $this->ilias->raiseError($this->lng->txt("msg_multi_language_selected"),$this->ilias->error_obj->MESSAGE);
405  }
406 
407  // copy default translation to variable for object data entry
408  $_POST["Fobject"]["title"] = $_POST["Fobject"][$_POST["default_language"]]["title"];
409  $_POST["Fobject"]["desc"] = $_POST["Fobject"][$_POST["default_language"]]["desc"];
410 
411  // first delete all translation entries...
412  $this->object->removeTranslations();
413 
414  // ...and write new translations to object_translation
415  foreach ($data["Fobject"] as $key => $val)
416  {
417  if ($key == $data["default_language"])
418  {
419  $default = 1;
420  }
421  else
422  {
423  $default = 0;
424  }
425 
426  if (trim($val["title"]) != "")
427  {
428  $this->object->addTranslation(ilUtil::stripSlashes($val["title"]),ilUtil::stripSlashes($val["desc"]),$val["lang"],$default);
429  }
430  }
431 
432  // bring back old translation, if no individual translation is given
433  if (trim($_POST["Fobject"]["title"]) == "")
434  {
435  $_POST["Fobject"]["title"] = "ILIAS";
436  }
437 
438  // update object data entry with default translation
439  $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
440  $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
441 
442  //save custom icons
443  if ($this->ilias->getSetting("custom_icons"))
444  {
445  $this->object->saveIcons($_FILES["cont_big_icon"]['tmp_name'],
446  $_FILES["cont_small_icon"]['tmp_name'], $_FILES["cont_tiny_icon"]['tmp_name']);
447  }
448 
449  $this->update = $this->object->update();
450  }
451 
452  include_once('Services/Container/classes/class.ilContainerSortingSettings.php');
453  $settings = new ilContainerSortingSettings($this->object->getId());
454  $settings->setSortMode((int) $_POST['sorting']);
455  $settings->update();
456 
457  ilContainer::_writeContainerSetting($this->object->getId(), "hide_header_icon_and_title",
458  ilUtil::stripSlashes($_POST["hide_header_icon_and_title"]));
459 
460  ilUtil::sendInfo($this->lng->txt("msg_obj_modified"),true);
461  ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getTargetScript()."?".$this->link_params));
462  }
463 
470  {
471  if (!($_GET["mode"] != "create" or $_GET["mode"] != "edit"))
472  {
473  $message = get_class($this)."::addTranslationObject(): Missing or wrong parameter! mode: ".$_GET["mode"];
474  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
475  }
476 
477  $_SESSION["translation_post"] = $_POST;
478  $this->ctrl->setParameter($this, "entry", 0);
479  $this->ctrl->setParameter($this, "mode", "session");
480  $this->ctrl->setParameter($this, "new_type", $_GET["new_type"]);
481  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
482  }
483 
490  {
491  if (!($_GET["mode"] != "create" or $_GET["mode"] != "edit"))
492  {
493  $message = get_class($this)."::removeTranslationObject(): Missing or wrong parameter! mode: ".$_GET["mode"];
494  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
495  }
496 
497  $this->ctrl->setParameter($this, "entry", $_GET["entry"]);
498  $this->ctrl->setParameter($this, "mode", "session");
499  $this->ctrl->setParameter($this, "new_type", $_GET["new_type"]);
500  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
501 
502  }
503 
510  {
511  $_SESSION["translation_post"] = $_POST;
512  $this->object->removeBigIcon();
513  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
514  }
515 
522  {
523 
524  $_SESSION["translation_post"] = $_POST;
525  $this->object->removeSmallIcon();
526  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
527  }
528 
535  {
536 
537  $_SESSION["translation_post"] = $_POST;
538  $this->object->removeTinyIcon();
539  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
540  }
541 
545  function getActions()
546  {
548  unset($d["link"]); // in root folder we have only categories (cannot be linked)
549  return $d;
550  }
551 
555  function _goto($a_target)
556  {
557  global $ilAccess, $ilErr, $lng;
558 
559  if ($ilAccess->checkAccess("read", "",1))
560  {
561  $_GET["cmd"] = "frameset";
562  $_GET["ref_id"] = 1;
563  include("repository.php");
564  exit;
565  }
566  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
567  }
568 
574  protected function showSortingSettings()
575  {
576  $this->tpl->setVariable('TXT_SORTING',$this->lng->txt('sorting_header'));
577  $this->tpl->setVariable('TXT_SORT_TITLE',$this->lng->txt('sorting_title_header'));
578  $this->tpl->setVariable('INFO_SORT_TITLE',$this->lng->txt('sorting_info_title'));
579  $this->tpl->setVariable('TXT_SORT_MANUAL',$this->lng->txt('sorting_manual_header'));
580  $this->tpl->setVariable('INFO_SORT_MANUAL',$this->lng->txt('sorting_info_manual'));
581 
582  include_once('Services/Container/classes/class.ilContainerSortingSettings.php');
583  if($this->getCreationMode())
584  {
585  $settings = new ilContainerSortingSettings(0);
586  }
587  else
588  {
589  $settings = new ilContainerSortingSettings($this->object->getId());
590  }
591 
592 
593  $this->tpl->setVariable('RADIO_SORT_TITLE',ilUtil::formRadioButton(
594  $settings->getSortMode() == ilContainer::SORT_TITLE,
595  'sorting',
597  $this->tpl->setVariable('RADIO_SORT_MANUAL',ilUtil::formRadioButton(
598  $settings->getSortMode() == ilContainer::SORT_MANUAL,
599  'sorting',
601  }
602 
603 }
604 ?>