ILIAS  Release_5_0_x_branch Revision 61816
 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 "./Services/Object/classes/class.ilObject2GUI.php";
5 require_once "./Modules/File/classes/class.ilObjFile.php";
6 require_once "./Modules/File/classes/class.ilObjFileAccess.php";
7 
21 {
22  function getType()
23  {
24  return "file";
25  }
26 
27  // ???
28  function _forwards()
29  {
30  return array();
31  }
32 
33  function executeCommand()
34  {
35  global $ilNavigationHistory, $ilCtrl, $ilUser, $ilTabs, $ilAccess, $ilErr;
36 
37  $next_class = $this->ctrl->getNextClass($this);
38  $cmd = $this->ctrl->getCmd();
39 
40  if($this->id_type == self::WORKSPACE_NODE_ID)
41  {
42  include_once "Services/Form/classes/class.ilFileInputGUI.php";
44  }
45 
46  if(!$this->getCreationMode())
47  {
48  // do not move this payment block!!
49  if(IS_PAYMENT_ENABLED)
50  {
51  include_once './Services/Payment/classes/class.ilPaymentObject.php';
52  if(ANONYMOUS_USER_ID == $ilUser->getId() && isset($_GET['transaction']))
53  {
54  $transaction = $_GET['transaction'];
55  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
56  $valid_transaction = ilPaymentBookings::_readBookingByTransaction($transaction);
57  }
58 
59  if(ilPaymentObject::_requiresPurchaseToAccess($this->node_id, $type = (isset($_GET['purchasetype'])
60  ? $_GET['purchasetype'] : NULL) ))
61  {
62  $this->setLocator();
63  $this->tpl->getStandardTemplate();
64 
65  include_once './Services/Payment/classes/class.ilShopPurchaseGUI.php';
66  $pp = new ilShopPurchaseGUI((int)$this->node_id);
67  $ret = $this->ctrl->forwardCommand($pp);
68  return true;
69  }
70  }
71  else if($this->id_type == self::REPOSITORY_NODE_ID
72  && $this->checkPermissionBool("read"))
73  {
74  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->node_id);
75  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "infoScreen");
76  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
77 
78  // add entry to navigation history
79  $ilNavigationHistory->addItem($this->node_id,
80  $link, "file");
81  }
82  }
83 
84  $this->prepareOutput();
85 
86  switch ($next_class)
87  {
88  case "ilinfoscreengui":
89  $this->infoScreenForward(); // forwards command
90  break;
91 
92  case 'ilmdeditorgui':
93  if(!$this->checkPermissionBool("write"))
94  {
95  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
96  }
97 
98  $ilTabs->activateTab("id_meta");
99 
100  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
101 
102  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
103  $md_gui->addObserver($this->object,'MDUpdateListener','General');
104 
105  // todo: make this work
106  $md_gui->addObserver($this->object,'MDUpdateListener','Technical');
107 
108  $this->ctrl->forwardCommand($md_gui);
109  break;
110 
111  // repository permissions
112  case 'ilpermissiongui':
113  $ilTabs->activateTab("id_permissions");
114  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
115  $perm_gui =& new ilPermissionGUI($this);
116  $ret =& $this->ctrl->forwardCommand($perm_gui);
117  break;
118 
119  case "ilexportgui":
120  $ilTabs->activateTab("export");
121  include_once("./Services/Export/classes/class.ilExportGUI.php");
122  $exp_gui = new ilExportGUI($this);
123  $exp_gui->addFormat("xml");
124  $ret = $this->ctrl->forwardCommand($exp_gui);
125  break;
126 
127  case 'ilobjectcopygui':
128  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
129  $cp = new ilObjectCopyGUI($this);
130  $cp->setType('file');
131  $this->ctrl->forwardCommand($cp);
132  break;
133 
134  // personal workspace permissions
135  case "ilworkspaceaccessgui";
136  $ilTabs->activateTab("id_permissions");
137  include_once('./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php');
138  $wspacc = new ilWorkspaceAccessGUI($this->node_id, $this->getAccessHandler());
139  $this->ctrl->forwardCommand($wspacc);
140  break;
141 
142  case "ilcommonactiondispatchergui":
143  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
145  $this->ctrl->forwardCommand($gui);
146  break;
147 
148  default:
149  // in personal workspace use object2gui
150  if($this->id_type == self::WORKSPACE_NODE_ID)
151  {
152  $this->addHeaderAction();
153 
154  // coming from goto we need default command
155  if (empty($cmd))
156  {
157  $ilCtrl->setCmd("infoScreen");
158  }
159  $ilTabs->clearTargets();
160  return parent::executeCommand();
161  }
162 
163  if (empty($cmd))
164  {
165  $cmd = "infoScreen";
166  }
167 
168  $this->$cmd();
169  break;
170  }
171 
172  $this->addHeaderAction();
173  }
174 
175  protected function initCreationForms()
176  {
177  $forms = array();
178 
179  if($this->id_type == self::WORKSPACE_NODE_ID)
180  {
181  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
183  {
184  $this->lng->loadLanguageModule("file");
185  ilUtil::sendFailure($this->lng->txt("personal_workspace_quota_exceeded_warning"), true);
186  $this->ctrl->redirect($this, "cancel");
187  }
188  }
189 
190  // use drag-and-drop upload if configured
191  require_once("Services/FileUpload/classes/class.ilFileUploadSettings.php");
193  {
194  $forms[] = $this->initMultiUploadForm();
195  }
196  else
197  {
198  $forms[] = $this->initSingleUploadForm();
199  $forms[] = $this->initZipUploadForm();
200  }
201 
202  // repository only
203  if($this->id_type != self::WORKSPACE_NODE_ID)
204  {
205  $forms[self::CFORM_IMPORT] = $this->initImportForm('file');
206  $forms[self::CFORM_CLONE] = $this->fillCloneTemplate(null, "file");
207  }
208 
209  return $forms;
210  }
211 
215  public function initSingleUploadForm()
216  {
217  global $lng;
218 
219  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
220  $single_form_gui = new ilPropertyFormGUI();
221  $single_form_gui->setMultipart(true);
222 
223  // File Title
224  $in_title = new ilTextInputGUI($lng->txt("title"), "title");
225  $in_title->setInfo($this->lng->txt("if_no_title_then_filename"));
226  $in_title->setSize(min(40, ilObject::TITLE_LENGTH));
227  $in_title->setMaxLength(ilObject::TITLE_LENGTH);
228  $single_form_gui->addItem($in_title);
229 
230  // File Description
231  $in_descr = new ilTextAreaInputGUI($lng->txt("description"), "description");
232  $single_form_gui->addItem($in_descr);
233 
234  // File
235  $in_file = new ilFileInputGUI($lng->txt("file"), "upload_file");
236  $in_file->setRequired(true);
237  $single_form_gui->addItem($in_file);
238 
239  $single_form_gui->addCommandButton("save", $this->lng->txt($this->type."_add"));
240  $single_form_gui->addCommandButton("saveAndMeta", $this->lng->txt("file_add_and_metadata"));
241  $single_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
242 
243  $single_form_gui->setTableWidth("600px");
244  $single_form_gui->setTarget($this->getTargetFrame("save"));
245  $single_form_gui->setTitle($this->lng->txt($this->type."_new"));
246  $single_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.svg'), $this->lng->txt('obj_file'));
247 
248  $this->ctrl->setParameter($this, "new_type", "file");
249 
250  $single_form_gui->setFormAction($this->ctrl->getFormAction($this, "save"));
251 
252  return $single_form_gui;
253  }
254 
260  function save()
261  {
262  global $objDefinition, $ilUser;
263 
264  if (!$this->checkPermissionBool("create", "", "file"))
265  {
266  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
267  }
268 
269  $single_form_gui = $this->initSingleUploadForm();
270 
271  if ($single_form_gui->checkInput())
272  {
273  $title = $single_form_gui->getInput("title");
274  $description = $single_form_gui->getInput("description");
275  $upload_file = $single_form_gui->getInput("upload_file");
276 
277  if (trim($title) == "")
278  {
279  $title = $upload_file["name"];
280  }
281  else
282  {
283  // BEGIN WebDAV: Ensure that object title ends with the filename extension
284  $fileExtension = ilObjFileAccess::_getFileExtension($upload_file["name"]);
285  $titleExtension = ilObjFileAccess::_getFileExtension($title);
286  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
287  {
288  $title .= '.'.$fileExtension;
289  }
290  // END WebDAV: Ensure that object title ends with the filename extension
291  }
292 
293  // create and insert file in grp_tree
294  include_once("./Modules/File/classes/class.ilObjFile.php");
295  $fileObj = new ilObjFile();
296  $fileObj->setTitle($title);
297  $fileObj->setDescription($description);
298  $fileObj->setFileName($upload_file["name"]);
299  //$fileObj->setFileType($upload_file["type"]);
300  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
301  $fileObj->setFileType(ilMimeTypeUtil::getMimeType(
302  "", $upload_file["name"], $upload_file["type"]));
303  $fileObj->setFileSize($upload_file["size"]);
304  $this->object_id = $fileObj->create();
305 
306  $this->putObjectInTree($fileObj, $this->parent_id);
307 
308  // upload file to filesystem
309  $fileObj->createDirectory();
310  $fileObj->getUploadFile($upload_file["tmp_name"],
311  $upload_file["name"]);
312 
313  $this->handleAutoRating($fileObj);
314 
315  // BEGIN ChangeEvent: Record write event.
316  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
317  ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
318  // END ChangeEvent: Record write event.
319 
320  ilUtil::sendSuccess($this->lng->txt("file_added"),true);
321 
322  if ($this->ctrl->getCmd() == "saveAndMeta")
323  {
324  $this->ctrl->setParameter($this, "new_type", "");
325  $target = $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilmdeditorgui"), "listSection", "", false, false);
326  ilUtil::redirect($target);
327  }
328  else
329  {
330  $this->ctrl->returnToParent($this);
331  }
332  }
333  else
334  {
335  $single_form_gui->setValuesByPost();
336  $this->tpl->setContent($single_form_gui->getHTML());
337  }
338  }
339 
345  function saveAndMeta()
346  {
347  $this->save();
348  }
349 
353  public function initZipUploadForm($a_mode = "create")
354  {
355  global $lng;
356 
357  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
358  $zip_form_gui = new ilPropertyFormGUI();
359  $zip_form_gui->setMultipart(true);
360 
361  // File
362  $in_file = new ilFileInputGUI($lng->txt("file"), "zip_file");
363  $in_file->setRequired(true);
364  $in_file->setSuffixes(array("zip"));
365  $zip_form_gui->addItem($in_file);
366 
367  // Take over structure
368  $in_str = new ilCheckboxInputGUI($this->lng->txt("take_over_structure"), "adopt_structure");
369  $in_str->setInfo($this->lng->txt("take_over_structure_info"));
370  $zip_form_gui->addItem($in_str);
371 
372  $zip_form_gui->addCommandButton("saveUnzip", $this->lng->txt($this->type."_add"));
373  $zip_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
374 
375  $zip_form_gui->setTableWidth("600px");
376  $zip_form_gui->setTarget($this->getTargetFrame("save"));
377  $zip_form_gui->setTitle($this->lng->txt("header_zip"));
378  $zip_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.svg'), $this->lng->txt('obj_file'));
379 
380  $this->ctrl->setParameter($this, "new_type", "file");
381 
382  $zip_form_gui->setFormAction($this->ctrl->getFormAction($this, "saveUnzip"));
383 
384  return $zip_form_gui;
385  }
386 
392  function saveUnzip()
393  {
394  $zip_form_gui = $this->initZipUploadForm();
395 
396  if ($this->checkPermissionBool("create", "", "file"))
397  {
398  if ($zip_form_gui->checkInput())
399  {
400  $zip_file = $zip_form_gui->getInput("zip_file");
401  $adopt_structure = $zip_form_gui->getInput("adopt_structure");
402 
403  include_once ("Services/Utilities/classes/class.ilFileUtils.php");
404 
405  // Create unzip-directory
406  $newDir = ilUtil::ilTempnam();
407  ilUtil::makeDir($newDir);
408 
409  // Check if permission is granted for creation of object, if necessary
410  if($this->id_type != self::WORKSPACE_NODE_ID)
411  {
412 
413  $type = ilObject::_lookupType((int)$this->parent_id, true);
414  }
415  else
416  {
417  $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
418  }
419 
420  $tree = $access_handler = null;
421  switch($type)
422  {
423  // workspace structure
424  case 'wfld':
425  case 'wsrt':
426  $permission = $this->checkPermissionBool("create", "", "wfld");
427  $containerType = "WorkspaceFolder";
428  $tree = $this->tree;
429  $access_handler = $this->getAccessHandler();
430  break;
431 
432  // use categories as structure
433  case 'cat':
434  case 'root':
435  $permission = $this->checkPermissionBool("create", "", "cat");
436  $containerType = "Category";
437  break;
438 
439  // use folders as structure (in courses)
440  default:
441  $permission = $this->checkPermissionBool("create", "", "fold");
442  $containerType = "Folder";
443  break;
444  }
445  // processZipFile (
446  // Dir to unzip,
447  // Path to uploaded file,
448  // should a structure be created (+ permission check)?
449  // ref_id of parent
450  // object that contains files (folder or category)
451  // should sendInfo be persistent?)
452  try
453  {
454  $processDone = ilFileUtils::processZipFile( $newDir,
455  $zip_file["tmp_name"],
456  ($adopt_structure && $permission),
457  $this->parent_id,
458  $containerType,
459  $tree,
461  ilUtil::sendSuccess($this->lng->txt("file_added"),true);
462  }
463  catch (ilFileUtilsException $e)
464  {
465  ilUtil::sendFailure($e->getMessage(), true);
466  }
467 
468  ilUtil::delDir($newDir);
469  $this->ctrl->returnToParent($this);
470  }
471  else
472  {
473  $zip_form_gui->setValuesByPost();
474  $this->tpl->setContent($zip_form_gui->getHTML());
475  }
476  }
477  else
478  {
479  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
480  }
481  }
482 
488  function update()
489  {
490  global $ilTabs;
491 
492  $form = $this->initPropertiesForm();
493  if(!$form->checkInput())
494  {
495  $ilTabs->activateTab("settings");
496  $form->setValuesByPost();
497  $this->tpl->setContent($form->getHTML());
498  return false;
499  }
500 
501  $data = $form->getInput('file');
502 
503  // delete trailing '/' in filename
504  while (substr($data["name"],-1) == '/')
505  {
506  $data["name"] = substr($data["name"],0,-1);
507  }
508 
509  $filename = empty($data["name"]) ? $this->object->getFileName() : $data["name"];
510  $title = $form->getInput('title');
511  if(strlen(trim($title)) == 0)
512  {
513  $title = $filename;
514  }
515  else
516  {
517  $title = $this->object->checkFileExtension($filename,$title);
518  }
519  $this->object->setTitle($title);
520 
521  if (!empty($data["name"]))
522  {
523  switch($form->getInput('replace'))
524  {
525  case 1:
526  $this->object->deleteVersions();
527  $this->object->clearDataDirectory();
528  $this->object->replaceFile($data['tmp_name'],$data['name']);
529  break;
530  case 0:
531  $this->object->addFileVersion($data['tmp_name'],$data['name']);
532  break;
533  }
534  $this->object->setFileName($data['name']);
535  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
536  $this->object->setFileType(ilMimeTypeUtil::getMimeType(
537  "", $data["name"], $data["type"]));
538  $this->object->setFileSize($data['size']);
539  }
540 
541  $this->object->setDescription($form->getInput('description'));
542  $this->object->setRating($form->getInput('rating'));
543 
544  $this->update = $this->object->update();
545 
546  // BEGIN ChangeEvent: Record update event.
547  if (!empty($data["name"]))
548  {
549  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
550  global $ilUser;
551  ilChangeEvent::_recordWriteEvent($this->object->getId(), $ilUser->getId(), 'update');
552  ilChangeEvent::_catchupWriteEvents($this->object->getId(), $ilUser->getId());
553  }
554  // END ChangeEvent: Record update event.
555 
556  // Update ecs export settings
557  include_once 'Modules/File/classes/class.ilECSFileSettings.php';
558  $ecs = new ilECSFileSettings($this->object);
559  $ecs->handleSettingsUpdate();
560 
561  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
562  ilUtil::redirect($this->ctrl->getLinkTarget($this,'edit','',false,false));
563  }
564 
570  function edit()
571  {
572  global $ilTabs, $ilErr;
573 
574  if (!$this->checkPermissionBool("write"))
575  {
576  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"));
577  }
578 
579  $ilTabs->activateTab("settings");
580 
581  $form = $this->initPropertiesForm();
582 
583  $val = array();
584  $val['title'] = $this->object->getTitle();
585  $val['description'] = $this->object->getLongDescription();
586  $val['rating'] = $this->object->hasRating();
587  $form->setValuesByArray($val);
588 
589  // Edit ecs export settings
590  include_once 'Modules/File/classes/class.ilECSFileSettings.php';
591  $ecs = new ilECSFileSettings($this->object);
592  $ecs->addSettingsToForm($form, 'file');
593 
594  $this->tpl->setContent($form->getHTML());
595  return true;
596  }
597 
603  protected function initPropertiesForm()
604  {
605  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
606 
607  $this->lng->loadLanguageModule('file');
608 
609  $form = new ilPropertyFormGUI();
610  $form->setFormAction($this->ctrl->getFormAction($this),'update');
611  $form->setTitle($this->lng->txt('file_edit'));
612  $form->addCommandButton('update',$this->lng->txt('save'));
613  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
614 
615  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
616  $title->setValue($this->object->getTitle());
617  $title->setInfo($this->lng->txt("if_no_title_then_filename"));
618  $form->addItem($title);
619 
620  $upload_possible = true;
621  if($this->id_type == self::WORKSPACE_NODE_ID)
622  {
623  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
624  $upload_possible = ilDiskQuotaHandler::isUploadPossible();
625  }
626 
627  if($upload_possible)
628  {
629  $file = new ilFileInputGUI($this->lng->txt('obj_file'),'file');
630  $file->setRequired(false);
631  // $file->enableFileNameSelection('title');
632  $form->addItem($file);
633 
634  $group = new ilRadioGroupInputGUI('','replace');
635  $group->setValue(0);
636 
637  $replace = new ilRadioOption($this->lng->txt('replace_file'),1);
638  $replace->setInfo($this->lng->txt('replace_file_info'));
639  $group->addOption($replace);
640 
641 
642  $keep = new ilRadioOption($this->lng->txt('file_new_version'),0);
643  $keep->setInfo($this->lng->txt('file_new_version_info'));
644  $group->addOption($keep);
645 
646  $file->addSubItem($group);
647  }
648  else
649  {
650  $file = new ilNonEditableValueGUI($this->lng->txt('obj_file'));
651  $file->setValue($this->lng->txt("personal_workspace_quota_exceeded_warning"));
652  $form->addItem($file);
653  }
654 
655  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
656  $desc->setRows(3);
657  #$desc->setCols(40);
658  $form->addItem($desc);
659 
660  if($this->id_type == self::REPOSITORY_NODE_ID)
661  {
662  $this->lng->loadLanguageModule('rating');
663  $rate = new ilCheckboxInputGUI($this->lng->txt('rating_activate_rating'), 'rating');
664  $rate->setInfo($this->lng->txt('rating_activate_rating_info'));
665  $form->addItem($rate);
666  }
667 
668  return $form;
669  }
670 
671  function sendFile()
672  {
673  global $ilUser, $ilCtrl;
674 
675  if(ANONYMOUS_USER_ID == $ilUser->getId() && isset($_GET['transaction']) )
676  {
677  $this->object->sendFile($_GET["hist_id"]);
678  }
679 
680  if ($this->checkPermissionBool("read"))
681  {
682  // BEGIN ChangeEvent: Record read event.
683  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
684  global $ilUser;
685  // Record read event and catchup with write events
686  ilChangeEvent::_recordReadEvent($this->object->getType(), $this->object->getRefId(),
687  $this->object->getId(), $ilUser->getId());
688  // END ChangeEvent: Record read event.
689 
690  $this->object->sendFile($_GET["hist_id"]);
691  }
692  else
693  {
694  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
695  }
696  return true;
697  }
698 
699 
705  function versions()
706  {
707  global $ilTabs;
708 
709  $ilTabs->activateTab("id_versions");
710 
711  if (!$this->checkPermissionBool("write"))
712  {
713  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
714  }
715 
716  // get versions
717  $versions = $this->object->getVersions();
718 
719  // build versions table
720  require_once("Modules/File/classes/class.ilFileVersionTableGUI.php");
721  $table = new ilFileVersionTableGUI($this, "versions");
722  $table->setMaxCount(sizeof($versions));
723  $table->setData($versions);
724 
725  $this->tpl->setVariable("ADM_CONTENT", $table->getHTML());
726  }
727 
733  function infoScreen()
734  {
735  $this->ctrl->setCmd("showSummary");
736  $this->ctrl->setCmdClass("ilinfoscreengui");
737  $this->infoScreenForward();
738  }
739 
743  function infoScreenForward()
744  {
745  global $ilTabs, $ilErr, $ilToolbar;
746 
747  $ilTabs->activateTab("id_info");
748 
749  if (!$this->checkPermissionBool("visible"))
750  {
751  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
752  }
753 
754  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
755  $info = new ilInfoScreenGUI($this);
756 
757  if ($this->checkPermissionBool("read", "sendfile"))
758  {
759  // #9876
760  $this->lng->loadLanguageModule("file");
761 
762  // #14378
763  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
764  $button = ilLinkButton::getInstance();
765  $button->setCaption("file_download");
766  $button->setPrimary(true);
767 
768  // get permanent download link for repository
769  if ($this->id_type == self::REPOSITORY_NODE_ID)
770  {
771  $button->setUrl(ilObjFileAccess::_getPermanentDownloadLink($this->node_id));
772  }
773  else
774  {
775  $button->setUrl($this->ctrl->getLinkTarget($this, "sendfile"));
776  }
777 
778  $ilToolbar->addButtonInstance($button);
779  }
780 
781  $info->enablePrivateNotes();
782 
783  if ($this->checkPermissionBool("read"))
784  {
785  $info->enableNews();
786  }
787 
788  // no news editing for files, just notifications
789  $info->enableNewsEditing(false);
790  if ($this->checkPermissionBool("write"))
791  {
792  $news_set = new ilSetting("news");
793  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
794 
795  if ($enable_internal_rss)
796  {
797  $info->setBlockProperty("news", "settings", true);
798  $info->setBlockProperty("news", "public_notifications_option", true);
799  }
800  }
801 
802 
803  // standard meta data
804  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
805 
806  $info->addSection($this->lng->txt("file_info"));
807  $info->addProperty($this->lng->txt("filename"),
808  $this->object->getFileName());
809  // BEGIN WebDAV Guess file type.
810  $info->addProperty($this->lng->txt("type"),
811  $this->object->guessFileType());
812  // END WebDAV Guess file type.
813  $info->addProperty($this->lng->txt("size"),
814  ilFormat::formatSize(ilObjFile::_lookupFileSize($this->object->getId()),'long'));
815  $info->addProperty($this->lng->txt("version"),
816  $this->object->getVersion());
817 
818  // using getVersions function instead of ilHistory direct
819  $uploader = $this->object->getVersions();
820  $uploader = array_shift($uploader);
821  $uploader = $uploader["user_id"];
822 
823  $this->lng->loadLanguageModule("file");
824  include_once "Services/User/classes/class.ilUserUtil.php";
825  $info->addProperty($this->lng->txt("file_uploaded_by"), ilUserUtil::getNamePresentation($uploader));
826 
827  // download link added in repository
828  if ($this->id_type == self::REPOSITORY_NODE_ID && $this->checkPermissionBool("read", "sendfile"))
829  {
830  $tpl = new ilTemplate("tpl.download_link.html", true, true, "Modules/File");
831  $tpl->setVariable("LINK", ilObjFileAccess::_getPermanentDownloadLink($this->node_id));
832  $info->addProperty($this->lng->txt("download_link"), $tpl->get());
833  }
834 
835  if($this->id_type == self::WORKSPACE_NODE_ID)
836  {
837  $info->addProperty($this->lng->txt("perma_link"), $this->getPermanentLinkWidget());
838  }
839 
840  // display previews
841  include_once("./Services/Preview/classes/class.ilPreview.php");
842  if (!$this->ctrl->isAsynch() &&
843  ilPreview::hasPreview($this->object->getId(), $this->object->getType()) &&
844  $this->checkPermissionBool("read"))
845  {
846  include_once("./Services/Preview/classes/class.ilPreviewGUI.php");
847 
848  // get context for access checks later on
849  $context;
850  switch ($this->id_type)
851  {
852  case self::WORKSPACE_NODE_ID:
853  case self::WORKSPACE_OBJECT_ID:
855  break;
856 
857  default:
859  break;
860  }
861 
862  $preview = new ilPreviewGUI($this->node_id, $context, $this->object->getId(), $this->access_handler);
863  $info->addProperty($this->lng->txt("preview"), $preview->getInlineHTML());
864  }
865 
866  // forward the command
867  // $this->ctrl->setCmd("showSummary");
868  // $this->ctrl->setCmdClass("ilinfoscreengui");
869  $this->ctrl->forwardCommand($info);
870  }
871 
872 
873  // get tabs
874  function setTabs()
875  {
876  global $ilTabs, $lng, $ilHelp;
877 
878  $ilHelp->setScreenIdComponent("file");
879 
880  $this->ctrl->setParameter($this,"ref_id",$this->node_id);
881 
882  if ($this->checkPermissionBool("visible"))
883  {
884  $ilTabs->addTab("id_info",
885  $lng->txt("info_short"),
886  $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilinfoscreengui"), "showSummary"));
887  }
888 
889  if ($this->checkPermissionBool("write"))
890  {
891  $ilTabs->addTab("settings",
892  $lng->txt("edit"),
893  $this->ctrl->getLinkTarget($this, "edit"));
894  }
895 
896  if ($this->checkPermissionBool("write"))
897  {
898  $ilTabs->addTab("id_versions",
899  $lng->txt("versions"),
900  $this->ctrl->getLinkTarget($this, "versions"));
901  }
902 
903  // meta data
904  if ($this->checkPermissionBool("write"))
905  {
906  $ilTabs->addTab("id_meta",
907  $lng->txt("meta_data"),
908  $this->ctrl->getLinkTargetByClass(array('ilobjfilegui','ilmdeditorgui'),'listSection'));
909  }
910 
911  // export
912  if ($this->checkPermissionBool("write"))
913  {
914  $ilTabs->addTab("export",
915  $lng->txt("export"),
916  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
917  }
918 
919  // will add permission tab if needed
920  parent::setTabs();
921  }
922 
923  public static function _goto($a_target, $a_additional = null)
924  {
925  global $ilErr, $lng, $ilAccess;
926 
927  if($a_additional && substr($a_additional, -3) == "wsp")
928  {
929  $_GET["baseClass"] = "ilsharedresourceGUI";
930  $_GET["wsp_id"] = $a_target;
931  include("ilias.php");
932  exit;
933  }
934 
935  // added support for direct download goto links
936  if($a_additional && substr($a_additional, -8) == "download")
937  {
938  ilObjectGUI::_gotoRepositoryNode($a_target, "sendfile");
939  }
940 
941  // static method, no workspace support yet
942 
943  if ($ilAccess->checkAccess("visible", "", $a_target))
944  {
945  ilObjectGUI::_gotoRepositoryNode($a_target, "infoScreen");
946  }
947  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
948  {
949  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
952  }
953 
954  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
955  }
956 
960  function addLocatorItems()
961  {
962  global $ilLocator;
963 
964  if (is_object($this->object))
965  {
966  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
967  }
968  }
969 
975  public function initMultiUploadForm()
976  {
977  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
978  $dnd_form_gui = new ilPropertyFormGUI();
979  $dnd_form_gui->setMultipart(true);
980  $dnd_form_gui->setHideLabels();
981 
982  // file input
983  include_once("Services/Form/classes/class.ilDragDropFileInputGUI.php");
984  $dnd_input = new ilDragDropFileInputGUI($this->lng->txt("files"), "upload_files");
985  $dnd_input->setArchiveSuffixes(array("zip"));
986  $dnd_input->setCommandButtonNames("uploadFiles", "cancel");
987  $dnd_form_gui->addItem($dnd_input);
988 
989  // add commands
990  $dnd_form_gui->addCommandButton("uploadFiles", $this->lng->txt("upload_files"));
991  $dnd_form_gui->addCommandButton("cancel", $this->lng->txt("cancel"));
992 
993  $dnd_form_gui->setTableWidth("100%");
994  $dnd_form_gui->setTarget($this->getTargetFrame("save"));
995  $dnd_form_gui->setTitle($this->lng->txt("upload_files_title"));
996  $dnd_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $this->lng->txt('obj_file'));
997 
998  $this->ctrl->setParameter($this, "new_type", "file");
999  $dnd_form_gui->setFormAction($this->ctrl->getFormAction($this, "uploadFiles"));
1000 
1001  return $dnd_form_gui;
1002  }
1003 
1007  public function uploadFiles()
1008  {
1009  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
1010 
1011  $response = new stdClass();
1012  $response->error = null;
1013  $response->debug = null;
1014 
1015  $files = $_FILES;
1016 
1017  // #14249 - race conditions because of concurrent uploads
1018  $after_creation_callback = (int)$_REQUEST["crtcb"];
1019  if($after_creation_callback)
1020  {
1021  $this->after_creation_callback_objects = array();
1022  unset($_REQUEST["crtcb"]);
1023  }
1024 
1025  // load form
1026  $dnd_form_gui = $this->initMultiUploadForm();
1027  if ($dnd_form_gui->checkInput())
1028  {
1029  try
1030  {
1031  if (!$this->checkPermissionBool("create", "", "file"))
1032  {
1033  $response->error = $this->lng->txt("permission_denied");
1034  }
1035  else
1036  {
1037  // handle the file
1038  $fileresult = $this->handleFileUpload($dnd_form_gui->getInput("upload_files"));
1039  if ($fileresult)
1040  $response = (object)array_merge((array)$response, (array)$fileresult);
1041  }
1042  }
1043  catch (Exception $ex)
1044  {
1045  $response->error = $ex->getMessage() . " ## " . $ex->getTraceAsString();
1046  }
1047  }
1048  else
1049  {
1050  $dnd_input = $dnd_form_gui->getItemByPostVar("upload_files");
1051  $response->error = $dnd_input->getAlert();
1052  }
1053 
1054  if($after_creation_callback &&
1055  sizeof($this->after_creation_callback_objects))
1056  {
1057  foreach($this->after_creation_callback_objects as $new_file_obj)
1058  {
1059  ilObject2GUI::handleAfterSaveCallback($new_file_obj, $after_creation_callback);
1060  }
1061  unset($this->after_creation_callback_objects);
1062  }
1063 
1064  // send response object (don't use 'application/json' as IE wants to download it!)
1065  header('Vary: Accept');
1066  header('Content-type: text/plain');
1067  echo ilJsonUtil::encode($response);
1068 
1069  // no further processing!
1070  exit;
1071  }
1072 
1079  protected function handleFileUpload($file_upload)
1080  {
1081  global $ilUser;
1082 
1083  // file upload params
1084  $filename = ilUtil::stripSlashes($file_upload["name"]);
1085  $type = ilUtil::stripSlashes($file_upload["type"]);
1086  $size = ilUtil::stripSlashes($file_upload["size"]);
1087  $temp_name = $file_upload["tmp_name"];
1088 
1089  // additional params
1090  $title = ilUtil::stripSlashes($file_upload["title"]);
1091  $description = ilUtil::stripSlashes($file_upload["description"]);
1092  $extract = ilUtil::stripSlashes($file_upload["extract"]);
1093  $keep_structure = ilUtil::stripSlashes($file_upload["keep_structure"]);
1094 
1095  // create answer object
1096  $response = new stdClass();
1097  $response->fileName = $filename;
1098  $response->fileSize = intval($size);
1099  $response->fileType = $type;
1100  $response->fileUnzipped = $extract;
1101  $response->error = null;
1102 
1103  // extract archive?
1104  if ($extract)
1105  {
1106  $zip_file = $filename;
1107  $adopt_structure = $keep_structure;
1108 
1109  include_once ("Services/Utilities/classes/class.ilFileUtils.php");
1110 
1111  // Create unzip-directory
1112  $newDir = ilUtil::ilTempnam();
1113  ilUtil::makeDir($newDir);
1114 
1115  // Check if permission is granted for creation of object, if necessary
1116  if($this->id_type != self::WORKSPACE_NODE_ID)
1117  {
1118  $type = ilObject::_lookupType((int)$this->parent_id, true);
1119  }
1120  else
1121  {
1122  $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
1123  }
1124 
1125  $tree = $access_handler = null;
1126  switch($type)
1127  {
1128  // workspace structure
1129  case 'wfld':
1130  case 'wsrt':
1131  $permission = $this->checkPermissionBool("create", "", "wfld");
1132  $containerType = "WorkspaceFolder";
1133  $tree = $this->tree;
1134  $access_handler = $this->getAccessHandler();
1135  break;
1136 
1137  // use categories as structure
1138  case 'cat':
1139  case 'root':
1140  $permission = $this->checkPermissionBool("create", "", "cat");
1141  $containerType = "Category";
1142  break;
1143 
1144  // use folders as structure (in courses)
1145  default:
1146  $permission = $this->checkPermissionBool("create", "", "fold");
1147  $containerType = "Folder";
1148  break;
1149  }
1150 
1151  try
1152  {
1153  // processZipFile (
1154  // Dir to unzip,
1155  // Path to uploaded file,
1156  // should a structure be created (+ permission check)?
1157  // ref_id of parent
1158  // object that contains files (folder or category)
1159  // should sendInfo be persistent?)
1161  $newDir,
1162  $temp_name,
1163  ($adopt_structure && $permission),
1164  $this->parent_id,
1165  $containerType,
1166  $tree,
1167  $access_handler);
1168  }
1169  catch (ilFileUtilsException $e)
1170  {
1171  $response->error = $e->getMessage();
1172  }
1173  catch (Exception $ex)
1174  {
1175  $response->error = $ex->getMessage();
1176  }
1177 
1178  ilUtil::delDir($newDir);
1179 
1180  // #15404
1181  if($this->id_type != self::WORKSPACE_NODE_ID)
1182  {
1183  foreach(ilFileUtils::getNewObjects() as $parent_ref_id => $objects)
1184  {
1185  if($parent_ref_id != $this->parent_id)
1186  {
1187  continue;
1188  }
1189 
1190  foreach($objects as $object)
1191  {
1192  $this->after_creation_callback_objects[] = $object;
1193  }
1194  }
1195  }
1196  }
1197  else
1198  {
1199  if (trim($title) == "")
1200  {
1201  $title = $filename;
1202  }
1203  else
1204  {
1205  // BEGIN WebDAV: Ensure that object title ends with the filename extension
1207  $titleExtension = ilObjFileAccess::_getFileExtension($title);
1208  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
1209  {
1210  $title .= '.'.$fileExtension;
1211  }
1212  // END WebDAV: Ensure that object title ends with the filename extension
1213  }
1214 
1215  // create and insert file in grp_tree
1216  include_once("./Modules/File/classes/class.ilObjFile.php");
1217  $fileObj = new ilObjFile();
1218  $fileObj->setTitle($title);
1219  $fileObj->setDescription($description);
1220  $fileObj->setFileName($filename);
1221 
1222  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1223  $fileObj->setFileType(ilMimeTypeUtil::getMimeType("", $filename, $type));
1224  $fileObj->setFileSize($size);
1225  $this->object_id = $fileObj->create();
1226 
1227  $this->putObjectInTree($fileObj, $this->parent_id);
1228 
1229  // see uploadFiles()
1230  if(is_array($this->after_creation_callback_objects))
1231  {
1232  $this->after_creation_callback_objects[] = $fileObj;
1233  }
1234 
1235  // upload file to filesystem
1236  $fileObj->createDirectory();
1237  $fileObj->raiseUploadError(false);
1238  $fileObj->getUploadFile($temp_name, $filename);
1239 
1240  $this->handleAutoRating($fileObj);
1241 
1242  // BEGIN ChangeEvent: Record write event.
1243  require_once('./Services/Tracking/classes/class.ilChangeEvent.php');
1244  ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
1245  // END ChangeEvent: Record write event.
1246  }
1247 
1248  return $response;
1249  }
1250 
1254  function deleteVersions()
1255  {
1256  global $ilTabs, $ilLocator;
1257 
1258  // get ids either from GET (if single item was clicked) or
1259  // from POST (if multiple items were selected)
1260  $version_ids = isset($_GET["hist_id"]) ? array($_GET["hist_id"]) : $_POST["hist_id"];
1261 
1262  if (count($version_ids) < 1)
1263  {
1264  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
1265  $this->ctrl->redirect($this, "versions");
1266  }
1267  else
1268  {
1269  $ilTabs->activateTab("id_versions");
1270 
1271  // check if all versions are selected
1272  $versionsToKeep = array_udiff($this->object->getVersions(), $version_ids, array($this, "compareHistoryIds"));
1273  if (count($versionsToKeep) < 1)
1274  {
1275  // set our message
1276  ilUtil::sendQuestion($this->lng->txt("file_confirm_delete_all_versions"));
1277 
1278  // show confirmation gui
1279  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1280  $conf_gui = new ilConfirmationGUI();
1281  $conf_gui->setFormAction($this->ctrl->getFormAction($this, "versions"));
1282  $conf_gui->setCancel($this->lng->txt("cancel"), "cancelDeleteFile");
1283  $conf_gui->setConfirm($this->lng->txt("confirm"), "confirmDeleteFile");
1284 
1285  $conf_gui->addItem("id[]", $this->ref_id, $this->object->getTitle(),
1286  ilObject::_getIcon($this->object->getId(), "small", $this->object->getType()),
1287  $this->lng->txt("icon")." ".$this->lng->txt("obj_".$this->object->getType()));
1288 
1289  $html = $conf_gui->getHTML();
1290  }
1291  else
1292  {
1293  include_once("./Modules/File/classes/class.ilFileVersionTableGUI.php");
1294 
1295  ilUtil::sendQuestion($this->lng->txt("file_confirm_delete_versions"));
1296  $versions = $this->object->getVersions($version_ids);
1297 
1298  $table = new ilFileVersionTableGUI($this, 'versions', true);
1299  $table->setMaxCount(sizeof($versions));
1300  $table->setData($versions);
1301 
1302  $html = $table->getHTML();
1303  }
1304 
1305  $this->tpl->setVariable('ADM_CONTENT', $html);
1306  }
1307  }
1308 
1313  {
1314  global $ilTabs;
1315 
1316  // has the user the rights to delete versions?
1317  if (!$this->checkPermissionBool("write"))
1318  {
1319  $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
1320  }
1321 
1322  // delete versions after confirmation
1323  if (count($_POST["hist_id"]) > 0)
1324  {
1325  $this->object->deleteVersions($_POST["hist_id"]);
1326  ilUtil::sendSuccess($this->lng->txt("file_versions_deleted"), true);
1327  }
1328 
1329  $this->ctrl->setParameter($this, "hist_id", "");
1330  $this->ctrl->redirect($this, "versions");
1331  }
1332 
1337  {
1338  $this->ctrl->redirect($this, "versions");
1339  }
1340 
1345  {
1346  // has the user the rights to delete the file?
1347  if (!$this->checkPermissionBool("write"))
1348  {
1349  $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
1350  }
1351 
1352  // delete this file object
1353  include_once("./Services/Repository/classes/class.ilRepUtilGUI.php");
1354  $ru = new ilRepUtilGUI($this);
1355  $ru->deleteObjects($this->parent_id, array($this->ref_id));
1356 
1357  // redirect to parent object
1358  $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $this->parent_id);
1359  $this->ctrl->redirectByClass("ilrepositorygui");
1360  }
1361 
1365  function cancelDeleteFile()
1366  {
1367  $this->ctrl->redirect($this, "versions");
1368  }
1369 
1377  function compareHistoryIds($v1, $v2)
1378  {
1379  if (is_array($v1))
1380  $v1 = (int)$v1["hist_entry_id"];
1381  else if (!is_int($v1))
1382  $v1 = (int)$v1;
1383 
1384  if (is_array($v2))
1385  $v2 = (int)$v2["hist_entry_id"];
1386  else if (!is_int($v2))
1387  $v2 = (int)$v2;
1388 
1389  return $v1 - $v2;
1390  }
1391 
1395  function rollbackVersion()
1396  {
1397  global $ilTabs;
1398 
1399  // has the user the rights to delete the file?
1400  if (!$this->checkPermissionBool("write"))
1401  {
1402  $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
1403  }
1404 
1405  // get ids either from GET (if single item was clicked) or
1406  // from POST (if multiple items were selected)
1407  $version_ids = isset($_GET["hist_id"]) ? array($_GET["hist_id"]) : $_POST["hist_id"];
1408 
1409  // more than one entry selected?
1410  if (count($version_ids) != 1)
1411  {
1412  ilUtil::sendInfo($this->lng->txt("file_rollback_select_exact_one"), true);
1413  $this->ctrl->redirect($this, "versions");
1414  }
1415 
1416  // rollback the version
1417  $new_version = $this->object->rollback($version_ids[0]);
1418 
1419  ilUtil::sendSuccess(sprintf($this->lng->txt("file_rollback_done"), $new_version["rollback_version"]), true);
1420  $this->ctrl->redirect($this, "versions");
1421  }
1422 
1423  protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
1424  {
1425  $lg = parent::initHeaderAction($a_sub_type, $a_sub_id);
1426  if(is_object($lg))
1427  {
1428  if($this->object->hasRating())
1429  {
1430  $lg->enableRating(true, null, false,
1431  array("ilcommonactiondispatchergui", "ilratinggui"));
1432  }
1433  }
1434  return $lg;
1435  }
1436 
1437 } // END class.ilObjFileGUI
1438 ?>