ILIAS  Release_4_0_x_branch Revision 61816
 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-2009 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  $this->ctrl->returnToParent($this);
71  }
72 
77  {
78  ilObjCategoryGUI::_importCategories($this->ref_id,0);
79  }
80 
81 
86  {
87  ilObjCategoryGUI::_importCategories($this->ref_id,1);
88  }
89 
90 
91  function getTabs(&$tabs_gui)
92  {
93  global $rbacsystem, $lng;
94 
95  $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
96 
97  if ($rbacsystem->checkAccess('read',$this->ref_id))
98  {
99  $tabs_gui->addTab('view_content', $lng->txt("content"),
100  $this->ctrl->getLinkTarget($this, ""));
101  }
102 
103  if ($rbacsystem->checkAccess('write',$this->ref_id))
104  {
105  $force_active = ($_GET["cmd"] == "edit")
106  ? true
107  : false;
108  $tabs_gui->addTarget("edit_properties",
109  $this->ctrl->getLinkTarget($this, "edit"), "edit", get_class($this)
110  , "", $force_active);
111  }
112 
113  // parent tabs (all container: edit_permission, clipboard, trash
114  parent::getTabs($tabs_gui);
115 
116  }
117 
118  function &executeCommand()
119  {
120  global $rbacsystem;
121 
122  $next_class = $this->ctrl->getNextClass($this);
123  $cmd = $this->ctrl->getCmd();
124 
125  switch($next_class)
126  {
127  case 'ilcontainerlinklistgui':
128  include_once("./classes/class.ilContainerLinkListGUI.php");
129  $link_list_gui =& new ilContainerLinkListGUI();
130  $ret =& $this->ctrl->forwardCommand($link_list_gui);
131  break;
132 
133  // container page editing
134  case "ilpageobjectgui":
135  $this->prepareOutput(false);
136  $ret = $this->forwardToPageObject();
137  if ($ret != "")
138  {
139  $this->tpl->setContent($ret);
140  }
141  break;
142 
143  case 'ilpermissiongui':
144  $this->prepareOutput();
145  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
146  $perm_gui =& new ilPermissionGUI($this);
147  $ret =& $this->ctrl->forwardCommand($perm_gui);
148  break;
149 
150  case "ilcolumngui":
151  $this->checkPermission("read");
152  $this->prepareOutput();
153  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
154  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
155  ilObjStyleSheet::getContentStylePath($this->object->getStyleSheetId()));
156  $this->renderObject();
157  break;
158 
159  case 'ilobjectcopygui':
160  $this->prepareOutput();
161  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
162  $cp = new ilObjectCopyGUI($this);
163  $cp->setType('root');
164  $this->ctrl->forwardCommand($cp);
165  break;
166 
167  case "ilobjstylesheetgui":
168  $this->forwardToStyleSheet();
169  break;
170 
171  default:
172  $this->prepareOutput();
173  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
174  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
175  ilObjStyleSheet::getContentStylePath($this->object->getStyleSheetId()));
176 
177  if(!$cmd)
178  {
179  $cmd = "render";
180  }
181 
182  $cmd .= "Object";
183  $this->$cmd();
184 
185  break;
186  }
187  return true;
188  }
189 
193  function renderObject()
194  {
195  global $ilTabs;
196 
197  $ilTabs->activateTab("view_content");
199  return $ret;
200  }
201 
202 
208  function editObject()
209  {
210  global $rbacsystem, $lng;
211 
212  if (!$rbacsystem->checkAccess("write", $this->ref_id))
213  {
214  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
215  }
216 
217  $this->ctrl->setParameter($this,"mode","edit");
218 
219  // for lang selection include metadata class
220  include_once "./Services/MetaData/classes/class.ilMDLanguageItem.php";
221 
222  $this->getTemplateFile("edit",'');
223  $this->showSortingSettings();
224 
225  // hide header icon and title
226  $this->tpl->setVariable("TXT_HIDE_HEADER_ICON_AND_TITLE", $lng->txt("cntr_hide_title_and_icon"));
227  if (ilContainer::_lookupContainerSetting($this->object->getId(), "hide_header_icon_and_title"))
228  {
229  $this->tpl->setVariable("CHK_HIDE_ICON", ' checked="checked" ');
230  }
231 
232  $array_push = true;
233 
234  if ($_SESSION["error_post_vars"])
235  {
236  $_SESSION["translation_post"] = $_SESSION["error_post_vars"];
237  $_GET["mode"] = "session";
238  $array_push = false;
239  }
240 
241  // load from db if edit category is called the first time
242  if (($_GET["mode"] != "session"))
243  {
244  $data = $this->object->getTranslations();
245  $_SESSION["translation_post"] = $data;
246  $array_push = false;
247  } // remove a translation from session
248  elseif ($_GET["entry"] != 0)
249  {
250  array_splice($_SESSION["translation_post"]["Fobject"],$_GET["entry"],1,array());
251 
252  if ($_GET["entry"] == $_SESSION["translation_post"]["default_language"])
253  {
254  $_SESSION["translation_post"]["default_language"] = "";
255  }
256  }
257 
258  $data = $_SESSION["translation_post"];
259 
260  // add additional translation form
261  if (!$_GET["entry"] and $array_push)
262  {
263  $count = array_push($data["Fobject"],array("title" => "","desc" => ""));
264  }
265  else
266  {
267  $count = count($data["Fobject"]);
268  }
269 
270  // stripslashes in form?
271  $strip = isset($_SESSION["translation_post"]) ? true : false;
272 
273  // add empty entry, if nothing exists
274  if (count($data["Fobject"]) == 0)
275  {
276  $data["Fobject"][0] =
277  array("title" => "",
278  "desc" => "",
279  "lang" => $lng->getDefaultLanguage()
280  );
281  }
282 
283  foreach ($data["Fobject"] as $key => $val)
284  {
285  // add translation button
286  if ($key == $count -1)
287  {
288  $this->tpl->setCurrentBlock("addTranslation");
289  $this->tpl->setVariable("TXT_ADD_TRANSLATION",$this->lng->txt("add_translation")." >>");
290  $this->tpl->parseCurrentBlock();
291  }
292 
293  // remove translation button
294  if ($key != 0)
295  {
296  $this->tpl->setCurrentBlock("removeTranslation");
297  $this->tpl->setVariable("TXT_REMOVE_TRANSLATION",$this->lng->txt("remove_translation"));
298  $this->ctrl->setParameter($this, "entry", $key);
299  $this->ctrl->setParameter($this, "mode", "edit");
300  $this->tpl->setVariable("LINK_REMOVE_TRANSLATION", $this->ctrl->getLinkTarget($this, "removeTranslation"));
301  $this->tpl->parseCurrentBlock();
302  }
303 
304  // lang selection
305  $this->tpl->addBlockFile("SEL_LANGUAGE", "sel_language", "tpl.lang_selection.html", false);
306  $this->tpl->setVariable("SEL_NAME", "Fobject[".$key."][lang]");
307 
308  $languages = ilMDLanguageItem::_getLanguages();
309 
310  foreach ($languages as $code => $language)
311  {
312  $this->tpl->setCurrentBlock("lg_option");
313  $this->tpl->setVariable("VAL_LG", $code);
314  $this->tpl->setVariable("TXT_LG", $language);
315 
316  if ($code == $val["lang"])
317  {
318  $this->tpl->setVariable("SELECTED", "selected=\"selected\"");
319  }
320 
321  $this->tpl->parseCurrentBlock();
322  }
323 
324  // object data
325  $this->tpl->setCurrentBlock("obj_form");
326 
327  if ($key == 0)
328  {
329  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("repository"));
330  }
331  else
332  {
333  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt("translation")." ".$key);
334  }
335 
336  if ($key == $data["default_language"])
337  {
338  $this->tpl->setVariable("CHECKED", "checked=\"checked\"");
339  }
340 
341  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
342  $this->tpl->setVariable("TXT_DESC", $this->lng->txt("title_long"));
343  $this->tpl->setVariable("TXT_DEFAULT", $this->lng->txt("default"));
344  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
345  $this->tpl->setVariable("TITLE", ilUtil::prepareFormOutput($val["title"],$strip));
346  $this->tpl->setVariable("DESC", ilUtil::stripSlashes($val["desc"]));
347  $this->tpl->setVariable("NUM", $key);
348  $this->tpl->parseCurrentBlock();
349  }
350 
351  $this->showCustomIconsEditing();
352 
353  // global
354  $this->tpl->setCurrentBlock("adm_content");
355  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
356  $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
357  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
358  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
359  $this->tpl->setVariable("CMD_SUBMIT", "update");
360  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
361  }
362 
367  {
368  global $lng;
369 
371  $this->tpl->setDescription("");
372  if (!ilContainer::_lookupContainerSetting($this->object->getId(), "hide_header_icon_and_title"))
373  {
374  if ($this->object->getTitle() == "ILIAS")
375  {
376  $this->tpl->setTitle($lng->txt("repository"));
377  }
378  else
379  {
380  if ($this->object->getDescription() != "")
381  {
382  $this->tpl->setTitle($this->object->getDescription());
383  }
384  }
385  }
386  }
387 
393  function updateObject()
394  {
395  global $rbacsystem;
396  if (!$rbacsystem->checkAccess("write", $this->object->getRefId()))
397  {
398  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
399  }
400  else
401  {
402  $data = $_POST;
403 
404  // default language set?
405  if (!isset($data["default_language"]))
406  {
407  $this->ilias->raiseError($this->lng->txt("msg_no_default_language"),$this->ilias->error_obj->MESSAGE);
408  }
409 
410  // prepare array fro further checks
411  foreach ($data["Fobject"] as $key => $val)
412  {
413  $langs[$key] = $val["lang"];
414  }
415 
416  $langs = array_count_values($langs);
417 
418  // all languages set?
419  if (array_key_exists("",$langs) &&
420  (count($data["Fobject"]) > 1 || $data["Fobject"][0]["title"] != ""))
421  {
422  $this->ilias->raiseError($this->lng->txt("msg_no_language_selected"),$this->ilias->error_obj->MESSAGE);
423  }
424 
425  // no single language is selected more than once?
426  if (array_sum($langs) > count($langs))
427  {
428  $this->ilias->raiseError($this->lng->txt("msg_multi_language_selected"),$this->ilias->error_obj->MESSAGE);
429  }
430 
431  // copy default translation to variable for object data entry
432  $_POST["Fobject"]["title"] = $_POST["Fobject"][$_POST["default_language"]]["title"];
433  $_POST["Fobject"]["desc"] = $_POST["Fobject"][$_POST["default_language"]]["desc"];
434 
435  // first delete all translation entries...
436  $this->object->removeTranslations();
437 
438  // ...and write new translations to object_translation
439  foreach ($data["Fobject"] as $key => $val)
440  {
441  if ($key == $data["default_language"])
442  {
443  $default = 1;
444  }
445  else
446  {
447  $default = 0;
448  }
449 
450  if (trim($val["title"]) != "")
451  {
452  $this->object->addTranslation(ilUtil::stripSlashes($val["title"]),ilUtil::stripSlashes($val["desc"]),$val["lang"],$default);
453  }
454  }
455 
456  // bring back old translation, if no individual translation is given
457  if (trim($_POST["Fobject"]["title"]) == "")
458  {
459  $_POST["Fobject"]["title"] = "ILIAS";
460  }
461 
462  // update object data entry with default translation
463  $this->object->setTitle(ilUtil::stripSlashes($_POST["Fobject"]["title"]));
464  $this->object->setDescription(ilUtil::stripSlashes($_POST["Fobject"]["desc"]));
465 
466  //save custom icons
467  if ($this->ilias->getSetting("custom_icons"))
468  {
469  $this->object->saveIcons($_FILES["cont_big_icon"]['tmp_name'],
470  $_FILES["cont_small_icon"]['tmp_name'], $_FILES["cont_tiny_icon"]['tmp_name']);
471  }
472 
473  $this->update = $this->object->update();
474  }
475 
476  include_once('Services/Container/classes/class.ilContainerSortingSettings.php');
477  $settings = new ilContainerSortingSettings($this->object->getId());
478  $settings->setSortMode((int) $_POST['sorting']);
479  $settings->update();
480 
481  ilContainer::_writeContainerSetting($this->object->getId(), "hide_header_icon_and_title",
482  ilUtil::stripSlashes($_POST["hide_header_icon_and_title"]));
483 
484  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
485  ilUtil::redirect($this->getReturnLocation("update",$this->ctrl->getTargetScript()."?".$this->link_params));
486  }
487 
494  {
495  if (!($_GET["mode"] != "create" or $_GET["mode"] != "edit"))
496  {
497  $message = get_class($this)."::addTranslationObject(): Missing or wrong parameter! mode: ".$_GET["mode"];
498  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
499  }
500 
501  $_SESSION["translation_post"] = $_POST;
502  $this->ctrl->setParameter($this, "entry", 0);
503  $this->ctrl->setParameter($this, "mode", "session");
504  $this->ctrl->setParameter($this, "new_type", $_GET["new_type"]);
505  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
506  }
507 
514  {
515  if (!($_GET["mode"] != "create" or $_GET["mode"] != "edit"))
516  {
517  $message = get_class($this)."::removeTranslationObject(): Missing or wrong parameter! mode: ".$_GET["mode"];
518  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
519  }
520 
521  $this->ctrl->setParameter($this, "entry", $_GET["entry"]);
522  $this->ctrl->setParameter($this, "mode", "session");
523  $this->ctrl->setParameter($this, "new_type", $_GET["new_type"]);
524  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
525 
526  }
527 
534  {
535  $_SESSION["translation_post"] = $_POST;
536  $this->object->removeBigIcon();
537  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
538  }
539 
546  {
547 
548  $_SESSION["translation_post"] = $_POST;
549  $this->object->removeSmallIcon();
550  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
551  }
552 
559  {
560 
561  $_SESSION["translation_post"] = $_POST;
562  $this->object->removeTinyIcon();
563  ilUtil::redirect($this->ctrl->getLinkTarget($this, $_GET["mode"]));
564  }
565 
569  function _goto($a_target)
570  {
571  global $ilAccess, $ilErr, $lng;
572 
573  if ($ilAccess->checkAccess("read", "",1))
574  {
575  $_GET["cmd"] = "frameset";
576  $_GET["ref_id"] = 1;
577  include("repository.php");
578  exit;
579  }
580  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
581  }
582 
588  protected function showSortingSettings()
589  {
590  $this->tpl->setVariable('TXT_SORTING',$this->lng->txt('sorting_header'));
591  $this->tpl->setVariable('TXT_SORT_TITLE',$this->lng->txt('sorting_title_header'));
592  $this->tpl->setVariable('INFO_SORT_TITLE',$this->lng->txt('sorting_info_title'));
593  $this->tpl->setVariable('TXT_SORT_MANUAL',$this->lng->txt('sorting_manual_header'));
594  $this->tpl->setVariable('INFO_SORT_MANUAL',$this->lng->txt('sorting_info_manual'));
595 
596  include_once('Services/Container/classes/class.ilContainerSortingSettings.php');
597  if($this->getCreationMode())
598  {
599  $settings = new ilContainerSortingSettings(0);
600  }
601  else
602  {
603  $settings = new ilContainerSortingSettings($this->object->getId());
604  }
605 
606 
607  $this->tpl->setVariable('RADIO_SORT_TITLE',ilUtil::formRadioButton(
608  $settings->getSortMode() == ilContainer::SORT_TITLE,
609  'sorting',
611  $this->tpl->setVariable('RADIO_SORT_MANUAL',ilUtil::formRadioButton(
612  $settings->getSortMode() == ilContainer::SORT_MANUAL,
613  'sorting',
615  }
616 
617 }
618 ?>