ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjFileGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "./classes/class.ilObjectGUI.php";
5 require_once "./Modules/File/classes/class.ilObjFile.php";
6 require_once "./Modules/File/classes/class.ilObjFileAccess.php";
7 
20 {
25  function ilObjFileGUI($a_data,$a_id,$a_call_by_reference = true, $a_prepare_output = true)
26  {
27  $this->type = "file";
28  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
29  $this->lng->loadLanguageModule('file');
30  }
31 
32  function _forwards()
33  {
34  return array();
35  }
36 
37  function executeCommand()
38  {
39  global $ilAccess, $ilNavigationHistory, $ilCtrl, $ilUser, $ilTabs;
40 
41  // add entry to navigation history
42  if (!$this->getCreationMode() &&
43  $ilAccess->checkAccess("read", "", $_GET["ref_id"]))
44  {
45  $ilNavigationHistory->addItem($_GET["ref_id"],
46  "repository.php?cmd=infoScreen&ref_id=".$_GET["ref_id"], "file");
47  }
48 
49  $next_class = $this->ctrl->getNextClass($this);
50  $cmd = $this->ctrl->getCmd();
51 
52  if(!$this->getCreationMode())
53  {
54  if(IS_PAYMENT_ENABLED)
55  {
56  include_once 'Services/Payment/classes/class.ilPaymentObject.php';
57  if(ANONYMOUS_USER_ID == $ilUser->getId() && isset($_GET['transaction']))
58  {
59  $transaction = $_GET['transaction'];
60  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
61  $valid_transaction = ilPaymentBookings::_readBookingByTransaction($transaction);
62  }
63 
64  if( ilPaymentObject::_isBuyable($this->object->getRefId() ) &&
65  !ilPaymentObject::_hasAccess($this->object->getRefId(), $transaction) &&
66  !$valid_transaction)
67  {
68  $this->setLocator();
69  $this->tpl->getStandardTemplate();
70 
71  include_once 'Services/Payment/classes/class.ilShopPurchaseGUI.php';
72  $pp = new ilShopPurchaseGUI((int)$_GET['ref_id']);
73  $ret = $this->ctrl->forwardCommand($pp);
74  return true;
75  }
76  }
77  }
78 
79  $this->prepareOutput();
80 
81  switch ($next_class)
82  {
83  case "ilinfoscreengui":
84  $this->infoScreen(); // forwards command
85  break;
86 
87  case 'ilmdeditorgui':
88  $ilTabs->activateTab("id_meta");
89 
90  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
91 
92  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
93  $md_gui->addObserver($this->object,'MDUpdateListener','General');
94 
95  // todo: make this work
96  $md_gui->addObserver($this->object,'MDUpdateListener','Technical');
97 
98  $this->ctrl->forwardCommand($md_gui);
99  break;
100 
101  case 'ilpermissiongui':
102  $ilTabs->activateTab("id_permissions");
103  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
104  $perm_gui =& new ilPermissionGUI($this);
105  $ret =& $this->ctrl->forwardCommand($perm_gui);
106  break;
107 
108  case "ilexportgui":
109  $ilTabs->activateTab("export");
110  include_once("./Services/Export/classes/class.ilExportGUI.php");
111  $exp_gui = new ilExportGUI($this);
112  $exp_gui->addFormat("xml");
113  $ret = $this->ctrl->forwardCommand($exp_gui);
114  break;
115 
116  case 'ilobjectcopygui':
117  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
118  $cp = new ilObjectCopyGUI($this);
119  $cp->setType('file');
120  $this->ctrl->forwardCommand($cp);
121  break;
122 
123  default:
124  if (empty($cmd))
125  {
126  // does not seem to work
127  //$this->ctrl->returnToParent($this);
128  //$cmd = "view";
129  $cmd = "infoScreen";
130  }
131 
132  $cmd .= "Object";
133  $this->$cmd();
134  break;
135  }
136  }
137 
143  function createObject($a_reload_form = "")
144  {
145  global $rbacsystem, $ilCtrl;
146 
147  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
148 
149  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
150  {
151  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
152  }
153 
154  // fill in saved values in case of error
155  $this->getTemplateFile("new",$this->type);
156 
157  if ($a_reload_form != "single_upload")
158  {
159  $this->initSingleUploadForm("create");
160  }
161  $this->tpl->setVariable("SINGLE_UPLOAD_FORM", $this->single_form_gui->getHtml());
162 
163  if ($a_reload_form != "zip_upload")
164  {
165  $this->initZipUploadForm("create");
166  }
167 
168  $this->tpl->setVariable("ZIP_UPLOAD_FORM", $this->zip_form_gui->getHtml());
169 
170  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
171  $this->tpl->setVariable("TXT_TAKE_OVER_STRUCTURE", $this->lng->txt("take_over_structure"));
172  $this->tpl->setVariable("TXT_HEADER_ZIP", $this->lng->txt("header_zip"));
173 
174  $this->fillCloneTemplate('DUPLICATE','file');
175 
176  if (DEVMODE == 1)
177  {
178  $this->initImportForm("file");
179  $this->tpl->setVariable("IMPORT", $this->form->getHTML());
180  }
181  }
182 
188  public function initImportForm($a_new_type = "")
189  {
190  global $lng, $ilCtrl;
191 
192  $lng->loadLanguageModule("file");
193 
194  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
195  $this->form = new ilPropertyFormGUI();
196  $this->form->setTarget("_top");
197 
198  // Import file
199  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
200  $fi = new ilFileInputGUI($lng->txt("import_file"), "importfile");
201  $fi->setSuffixes(array("zip"));
202  $fi->setRequired(true);
203  $this->form->addItem($fi);
204 
205  $this->form->addCommandButton("importFile", $lng->txt("import"));
206  $this->form->addCommandButton("cancel", $lng->txt("cancel"));
207  $this->form->setTitle($lng->txt($a_new_type."_import"));
208 
209  $this->form->setFormAction($ilCtrl->getFormAction($this));
210  }
211 
217  function importFileObject()
218  {
219  global $rbacsystem, $objDefinition, $tpl, $lng;
220 
221  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
222 
223  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
224  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
225  {
226  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
227  }
228  $this->ctrl->setParameter($this, "new_type", $new_type);
229  $this->initImportForm($new_type);
230  if ($this->form->checkInput())
231  {
232  // todo: make some check on manifest file
233  include_once("./Services/Export/classes/class.ilImport.php");
234  $imp = new ilImport((int) $_GET['ref_id']);
235  $new_id = $imp->importObject($newObj, $_FILES["importfile"]["tmp_name"],
236  $_FILES["importfile"]["name"], $new_type);
237  // put new object id into tree
238  if ($new_id > 0)
239  {
240  $newObj = ilObjectFactory::getInstanceByObjId($new_id);
241  $newObj->createReference();
242  $newObj->putInTree($_GET["ref_id"]);
243  $newObj->setPermissions($_GET["ref_id"]);
244  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
245  //$this->afterSave($newObj);
246  $this->ctrl->returnToParent($this);
247  }
248  return;
249  }
250 
251  $this->form->setValuesByPost();
252  $tpl->setContent($this->form->getHtml());
253  }
254 
260  public function initSingleUploadForm($a_mode = "create")
261  {
262  global $lng;
263 
264  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
265  $this->single_form_gui = new ilPropertyFormGUI();
266  $this->single_form_gui->setMultipart(true);
267 
268  // File Title
269  $in_title = new ilTextInputGUI($lng->txt("title"), "title");
270  $in_title->setInfo($this->lng->txt("if_no_title_then_filename"));
271  $in_title->setMaxLength(128);
272  $in_title->setSize(40);
273  $this->single_form_gui->addItem($in_title);
274 
275  // File Description
276  $in_descr = new ilTextAreaInputGUI($lng->txt("description"), "description");
277  $this->single_form_gui->addItem($in_descr);
278 
279  // File
280  $in_file = new ilFileInputGUI($lng->txt("file"), "upload_file");
281  $in_file->setRequired(true);
282  $this->single_form_gui->addItem($in_file);
283 
284  // save and cancel commands
285  if ($a_mode == "create")
286  {
287  $this->single_form_gui->addCommandButton("save", $this->lng->txt($this->type."_add"));
288  $this->single_form_gui->addCommandButton("saveAndMeta", $this->lng->txt("file_add_and_metadata"));
289  $this->single_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
290  }
291  else
292  {
293  //$this->single_form_gui->addCommandButton("update", $lng->txt("save"));
294  //$this->single_form_gui->addCommandButton("cancelUpdate", $lng->txt("cancel"));
295  }
296 
297  $this->single_form_gui->setTableWidth("600px");
298  $this->single_form_gui->setTarget($this->getTargetFrame("save"));
299  $this->single_form_gui->setTitle($this->lng->txt($this->type."_new"));
300  $this->single_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $this->lng->txt('obj_file'));
301 
302  if ($a_mode == "create")
303  {
304  $this->ctrl->setParameter($this, "new_type", "file");
305  }
306  $this->single_form_gui->setFormAction($this->ctrl->getFormAction($this, "save"));
307  }
308 
314  public function initZipUploadForm($a_mode = "create")
315  {
316  global $lng;
317 
318  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
319  $this->zip_form_gui = new ilPropertyFormGUI();
320  $this->zip_form_gui->setMultipart(true);
321 
322  // File
323  $in_file = new ilFileInputGUI($lng->txt("file"), "zip_file");
324  $in_file->setRequired(true);
325  $in_file->setSuffixes(array("zip"));
326  $this->zip_form_gui->addItem($in_file);
327 
328  // Take over structure
329  $in_str = new ilCheckboxInputGUI($this->lng->txt("take_over_structure"), "adopt_structure");
330  $in_str->setInfo($this->lng->txt("take_over_structure_info"));
331  $this->zip_form_gui->addItem($in_str);
332 
333  // save and cancel commands
334  if ($a_mode == "create")
335  {
336  $this->zip_form_gui->addCommandButton("saveUnzip", $this->lng->txt($this->type."_add"));
337  $this->zip_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
338  }
339  else
340  {
341  //$this->zip_form_gui->addCommandButton("update", $lng->txt("save"));
342  //$this->zip_form_gui->addCommandButton("cancelUpdate", $lng->txt("cancel"));
343  }
344 
345  $this->zip_form_gui->setTableWidth("600px");
346  $this->zip_form_gui->setTarget($this->getTargetFrame("save"));
347  $this->zip_form_gui->setTitle($this->lng->txt("header_zip"));
348  $this->zip_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $this->lng->txt('obj_file'));
349 
350  if ($a_mode == "create")
351  {
352  $this->ctrl->setParameter($this, "new_type", "file");
353  }
354  $this->zip_form_gui->setFormAction($this->ctrl->getFormAction($this, "saveUnzip"));
355  }
356 
362  function saveUnzipObject()
363  {
364  global $rbacsystem;
365 
366  $this->initZipUploadForm("create");
367 
368  if ($rbacsystem->checkAccess("create", $_GET["ref_id"], "file")) {
369  if ($this->zip_form_gui->checkInput())
370  {
371  $zip_file = $this->zip_form_gui->getInput("zip_file");
372  $adopt_structure = $this->zip_form_gui->getInput("adopt_structure");
373 
374  include_once ("Services/Utilities/classes/class.ilFileUtils.php");
375 
376  // Create unzip-directory
377  $newDir = ilUtil::ilTempnam();
378  ilUtil::makeDir($newDir);
379 
380  // Check if permission is granted for creation of object, if necessary
381  $type = ilObject::_lookupType((int) $_GET['ref_id'],true);
382  if($type == 'cat' or $type == 'root')
383  {
384  $permission = $rbacsystem->checkAccess("create", $_GET["ref_id"], "cat");
385  $containerType = "Category";
386  }
387  else {
388  $permission = $rbacsystem->checkAccess("create", $_GET["ref_id"], "fold");
389  $containerType = "Folder";
390  }
391 
392  // processZipFile (
393  // Dir to unzip,
394  // Path to uploaded file,
395  // should a structure be created (+ permission check)?
396  // ref_id of parent
397  // object that contains files (folder or category)
398  // should sendInfo be persistent?)
399  try
400  {
401  $processDone = ilFileUtils::processZipFile( $newDir,
402  $zip_file["tmp_name"],
403  ($adopt_structure && $permission),
404  $_GET["ref_id"],
405  $containerType,
406  true);
407  ilUtil::sendSuccess($this->lng->txt("file_added"),true);
408  }
409  catch (ilFileUtilsException $e)
410  {
411  ilUtil::sendFailure($e->getMessage(), true);
412  }
413 
414  ilUtil::delDir($newDir);
415  $this->ctrl->returnToParent($this);
416  }
417  else
418  {
419  $this->zip_form_gui->setValuesByPost();
420  $this->createObject("zip_upload");
421  }
422  }
423  else
424  {
425  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
426  }
427  }
428 
434  function saveObject()
435  {
436  global $objDefinition, $ilUser;
437 
438  $this->initSingleUploadForm("create");
439 
440  if ($this->single_form_gui->checkInput())
441  {
442  $title = $this->single_form_gui->getInput("title");
443  $description = $this->single_form_gui->getInput("description");
444  $upload_file = $this->single_form_gui->getInput("upload_file");
445 
446  if (trim($title) == "")
447  {
448  $title = $upload_file["name"];
449  }
450  else
451  {
452  // BEGIN WebDAV: Ensure that object title ends with the filename extension
453  $fileExtension = ilObjFileAccess::_getFileExtension($upload_file["name"]);
454  $titleExtension = ilObjFileAccess::_getFileExtension($title);
455  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
456  {
457  $title .= '.'.$fileExtension;
458  }
459  // END WebDAV: Ensure that object title ends with the filename extension
460  }
461 
462  // create and insert file in grp_tree
463  include_once("./Modules/File/classes/class.ilObjFile.php");
464  $fileObj = new ilObjFile();
465  $fileObj->setTitle($title);
466  $fileObj->setDescription($description);
467  $fileObj->setFileName($upload_file["name"]);
468  //$fileObj->setFileType($upload_file["type"]);
469  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
470  $fileObj->setFileType(ilMimeTypeUtil::getMimeType(
471  "", $upload_file["name"], $upload_file["type"]));
472  $fileObj->setFileSize($upload_file["size"]);
473  $fileObj->create();
474  $fileObj->createReference();
475  $fileObj->putInTree($_GET["ref_id"]);
476  $fileObj->setPermissions($_GET["ref_id"]);
477  // upload file to filesystem
478  $fileObj->createDirectory();
479  $fileObj->getUploadFile($upload_file["tmp_name"],
480  $upload_file["name"]);
481 
482  // BEGIN ChangeEvent: Record write event.
483  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
485  {
486  ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
487  }
488  // END ChangeEvent: Record write event.
489  ilUtil::sendSuccess($this->lng->txt("file_added"),true);
490 
491  $this->ctrl->setParameter($this, "ref_id", $fileObj->getRefId());
492  if ($this->ctrl->getCmd() == "saveAndMeta")
493  {
494  $target = $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilmdeditorgui"), "listSection", "", false, false);
495  $target = str_replace("new_type=", "nt=", $target);
496  ilUtil::redirect($this->getReturnLocation("save", $target));
497  }
498  else
499  {
500  $this->ctrl->returnToParent($this);
501  }
502  }
503  else
504  {
505  $this->single_form_gui->setValuesByPost();
506  $this->createObject("single_upload");
507  }
508  }
509 
515  function saveAndMetaObject()
516  {
517  $this->saveObject();
518  }
519 
525  function updateObject()
526  {
527  global $ilTabs;
528 
529  $ilTabs->activateTab("id_edit");
530 
531  $this->initPropertiesForm('edit');
532  if(!$this->form->checkInput())
533  {
534  $this->form->setValuesByPost();
535  $this->tpl->setContent($this->form->getHTML());
536  return false;
537  }
538 
539  $data = $this->form->getInput('file');
540 
541  // delete trailing '/' in filename
542  while (substr($data["name"],-1) == '/')
543  {
544  $data["name"] = substr($data["name"],0,-1);
545  }
546 
547  $filename = empty($data["name"]) ? $this->object->getFileName() : $data["name"];
548  $title = $this->form->getInput('title');
549  if(strlen(trim($title)) == 0)
550  {
551  $title = $filename;
552  }
553  else
554  {
555  $title = $this->object->checkFileExtension($filename,$title);
556  }
557  $this->object->setTitle($title);
558 
559  if (!empty($data["name"]))
560  {
561  switch($this->form->getInput('replace'))
562  {
563  case 1:
564  $this->object->deleteVersions();
565  $this->object->clearDataDirectory();
566  $this->object->replaceFile($data['tmp_name'],$data['name']);
567  break;
568  case 0:
569  $this->object->addFileVersion($data['tmp_name'],$data['name']);
570  break;
571  }
572  $this->object->setFileName($data['name']);
573  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
574  $this->object->setFileType(ilMimeTypeUtil::getMimeType(
575  "", $data["name"], $data["type"]));
576  $this->object->setFileSize($data['size']);
577  }
578  $this->object->setDescription($this->form->getInput('description'));
579  $this->update = $this->object->update();
580 
581  // BEGIN ChangeEvent: Record update event.
582  if (!empty($data["name"]))
583  {
584  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
586  {
587  global $ilUser;
588  ilChangeEvent::_recordWriteEvent($this->object->getId(), $ilUser->getId(), 'update');
589  ilChangeEvent::_catchupWriteEvents($this->object->getId(), $ilUser->getId());
590  }
591  }
592  // END ChangeEvent: Record update event.
593 
594  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
595  ilUtil::redirect($this->ctrl->getLinkTarget($this,'edit','',false,false));
596  }
597 
598 
604  function editObject()
605  {
606  global $ilAccess, $ilTabs;
607 
608  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
609  {
610  $this->ilias->raiseError($this->lng->txt("msg_no_perm_write"),$this->ilias->error_obj->MESSAGE);
611  }
612 
613  $ilTabs->activateTab("id_edit");
614 
615  $this->initPropertiesForm('edit');
616  $this->getPropertiesValues('edit');
617 
618  $this->tpl->setContent($this->form->getHTML());
619  return true;
620 
621 
622  $fields = array();
623 
624  if ($_SESSION["error_post_vars"])
625  {
626  // fill in saved values in case of error
627  $fields["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
628  $fields["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"], true);
629  }
630  else
631  {
632  $fields["title"] = ilUtil::prepareFormOutput($this->object->getTitle());
633  $fields["desc"] = ilUtil::prepareFormOutput($this->object->getLongDescription());
634  }
635 
636  $this->getTemplateFile("edit");
637  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
638  $this->tpl->setVariable("TITLE", $fields["title"]);
639  $this->tpl->setVariable("TXT_DESC", $this->lng->txt("desc"));
640  $this->tpl->setVariable("DESC", $fields["desc"]);
641  $this->tpl->setVariable("TXT_REPLACE_FILE", $this->lng->txt("replace_file"));
642  //$this->tpl->parseCurrentBlock();
643 
644  $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
645 
646  $this->tpl->setVariable("FORMACTION", $this->getFormAction("update",$this->ctrl->getFormAction($this, "update").$obj_str));
647  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($this->object->getType()."_edit"));
648  $this->tpl->setVariable("TARGET", $this->getTargetFrame("update"));
649  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
650  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
651  $this->tpl->setVariable("CMD_SUBMIT", "update");
652  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
653  //$this->tpl->parseCurrentBlock();
654  }
655 
656  protected function getPropertiesValues($a_mode = 'edit')
657  {
658  if($a_mode == 'edit')
659  {
660  $val['title'] = $this->object->getTitle();
661  $val['description'] = $this->object->getLongDescription();
662  $this->form->setValuesByArray($val);
663  }
664  return true;
665  }
666 
672  protected function initPropertiesForm($a_mode)
673  {
674  global $lng;
675 
676  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
677 
678  $this->form = new ilPropertyFormGUI();
679  $this->form->setFormAction($this->ctrl->getFormAction($this),'update');
680  $this->form->setTitle($this->lng->txt('file_edit'));
681  $this->form->addCommandButton('update',$this->lng->txt('save'));
682  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
683 
684  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
685  $title->setValue($this->object->getTitle());
686  $title->setInfo($lng->txt("if_no_title_then_filename"));
687  $this->form->addItem($title);
688 
689  $file = new ilFileInputGUI($this->lng->txt('obj_file'),'file');
690  $file->setRequired(false);
691 // $file->enableFileNameSelection('title');
692  $this->form->addItem($file);
693 
694  $group = new ilRadioGroupInputGUI('','replace');
695  $group->setValue(0);
696 
697  $replace = new ilRadioOption($this->lng->txt('replace_file'),1);
698  $replace->setInfo($this->lng->txt('replace_file_info'));
699  $group->addOption($replace);
700 
701 
702  $keep = new ilRadioOption($this->lng->txt('file_new_version'),0);
703  $keep->setInfo($this->lng->txt('file_new_version_info'));
704  $group->addOption($keep);
705 
706  $file->addSubItem($group);
707 
708  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
709  $desc->setRows(3);
710  #$desc->setCols(40);
711  $this->form->addItem($desc);
712  }
713 
714  function sendFileObject()
715  {
716  global $ilAccess, $ilUser, $ilCtrl;
717 
718  if(ANONYMOUS_USER_ID == $ilUser->getId() && isset($_GET['transaction']) )
719  {
720  $this->object->sendFile($_GET["hist_id"]);
721  }
722 
723  if ($ilAccess->checkAccess("read", "", $this->ref_id))
724  {
725  // BEGIN ChangeEvent: Record read event.
726  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
728  {
729  global $ilUser;
730  // Record read event and catchup with write events
731  ilChangeEvent::_recordReadEvent($this->object->getType(), $this->object->getRefId(),
732  $this->object->getId(), $ilUser->getId());
733  }
734  // END ChangeEvent: Record read event.
735 
736  $this->object->sendFile($_GET["hist_id"]);
737  }
738  else
739  {
740  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
741  }
742  return true;
743  }
744 
745 
751  function versionsObject()
752  {
753  global $ilAccess, $ilTabs;
754 
755  $ilTabs->activateTab("id_versions");
756 
757  if (!$ilAccess->checkAccess("write", "", $_GET["ref_id"]))
758  {
759  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
760  }
761 
762  require_once("classes/class.ilHistoryGUI.php");
763 
764  $hist_gui =& new ilHistoryGUI($this->object->getId());
765 
766  // not nice, should be changed, if ilCtrl handling
767  // has been introduced to administration
768  $hist_html = $hist_gui->getVersionsTable(
769  array("ref_id" => $_GET["ref_id"], "cmd" => "versions",
770  "cmdClass" =>$_GET["cmdClass"], "cmdNode" =>$_GET["cmdNode"]));
771 
772  $this->tpl->setVariable("ADM_CONTENT", $hist_html);
773  }
774 
780  function infoScreenObject()
781  {
782  $this->ctrl->setCmd("showSummary");
783  $this->ctrl->setCmdClass("ilinfoscreengui");
784  $this->infoScreen();
785  }
786 
790  function infoScreen()
791  {
792  global $ilAccess, $ilTabs;
793 
794  $ilTabs->activateTab("id_info");
795 
796  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
797  {
798  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
799  }
800 
801  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
802  $info = new ilInfoScreenGUI($this);
803 
804  if ($ilAccess->checkAccess("read", "sendfile", $this->ref_id))
805  {
806  $info->addButton($this->lng->txt("file_read"), $this->ctrl->getLinkTarget($this, "sendfile"));
807  }
808 
809  $info->enablePrivateNotes();
810 
811  if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
812  {
813  $info->enableNews();
814  }
815 
816  // no news editing for files, just notifications
817  $info->enableNewsEditing(false);
818  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
819  {
820  $news_set = new ilSetting("news");
821  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
822 
823  if ($enable_internal_rss)
824  {
825  $info->setBlockProperty("news", "settings", true);
826  $info->setBlockProperty("news", "public_notifications_option", true);
827  }
828  }
829 
830 
831  // standard meta data
832  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
833 
834  $info->addSection($this->lng->txt("file_info"));
835  $info->addProperty($this->lng->txt("filename"),
836  $this->object->getFileName());
837  // BEGIN WebDAV Guess file type.
838  $info->addProperty($this->lng->txt("type"),
839  $this->object->guessFileType());
840  // END WebDAV Guess file type.
841  $info->addProperty($this->lng->txt("size"),
842  ilFormat::formatSize(ilObjFile::_lookupFileSize($this->object->getId()),'long'));
843  $info->addProperty($this->lng->txt("version"),
844  $this->object->getVersion());
845 
846  // forward the command
847  $this->ctrl->forwardCommand($info);
848  }
849 
850 
851  // get tabs
852  function setTabs()
853  {
854  global $ilAccess, $ilTabs, $lng;
855 
856  $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
857 
858  if ($ilAccess->checkAccess("visible", "", $this->ref_id))
859  {
860  $ilTabs->addTab("id_info",
861  $lng->txt("info_short"),
862  $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilinfoscreengui"), "showSummary"));
863  }
864 
865  if ($ilAccess->checkAccess("write", "", $this->ref_id))
866  {
867  $ilTabs->addTab("id_edit",
868  $lng->txt("edit"),
869  $this->ctrl->getLinkTarget($this, "edit"));
870  }
871 
872  if ($ilAccess->checkAccess("write", "", $this->ref_id))
873  {
874  $ilTabs->addTab("id_versions",
875  $lng->txt("versions"),
876  $this->ctrl->getLinkTarget($this, "versions"));
877  }
878 
879  // meta data
880  if ($ilAccess->checkAccess("write", "", $this->ref_id))
881  {
882  $ilTabs->addTab("id_meta",
883  $lng->txt("meta_data"),
884  $this->ctrl->getLinkTargetByClass(array('ilobjfilegui','ilmdeditorgui'),'listSection'));
885  }
886 
887  // export
888  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
889  {
890  $ilTabs->addTab("export",
891  $lng->txt("export"),
892  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
893  }
894 
895  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
896  {
897  $ilTabs->addTab("id_permissions",
898  $lng->txt("perm_settings"),
899  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"));
900  }
901  }
902 
903  function _goto($a_target)
904  {
905  global $ilAccess, $ilErr, $lng;
906 
907  if ($ilAccess->checkAccess("visible", "", $a_target))
908  {
909  $_GET["cmd"] = "infoScreen";
910  $_GET["ref_id"] = $a_target;
911  include("repository.php");
912  exit;
913  }
914  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
915  {
916  $_GET["cmd"] = "frameset";
917  $_GET["target"] = "";
918  $_GET["ref_id"] = ROOT_FOLDER_ID;
919  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
921  include("repository.php");
922  exit;
923  }
924 
925  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
926 
927  }
928 
932  function addLocatorItems()
933  {
934  global $ilLocator;
935 
936  if (is_object($this->object))
937  {
938  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
939  }
940  }
941 
942 } // END class.ilObjFileGUI
943 ?>