ILIAS  Release_4_4_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_CLONE] = $this->fillCloneTemplate(null, "file");
206  }
207 
208  return $forms;
209  }
210 
214  public function initSingleUploadForm()
215  {
216  global $lng;
217 
218  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
219  $single_form_gui = new ilPropertyFormGUI();
220  $single_form_gui->setMultipart(true);
221 
222  // File Title
223  $in_title = new ilTextInputGUI($lng->txt("title"), "title");
224  $in_title->setInfo($this->lng->txt("if_no_title_then_filename"));
225  $in_title->setSize(min(40, ilObject::TITLE_LENGTH));
226  $in_title->setMaxLength(ilObject::TITLE_LENGTH);
227  $single_form_gui->addItem($in_title);
228 
229  // File Description
230  $in_descr = new ilTextAreaInputGUI($lng->txt("description"), "description");
231  $single_form_gui->addItem($in_descr);
232 
233  // File
234  $in_file = new ilFileInputGUI($lng->txt("file"), "upload_file");
235  $in_file->setRequired(true);
236  $single_form_gui->addItem($in_file);
237 
238  $single_form_gui->addCommandButton("save", $this->lng->txt($this->type."_add"));
239  $single_form_gui->addCommandButton("saveAndMeta", $this->lng->txt("file_add_and_metadata"));
240  $single_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
241 
242  $single_form_gui->setTableWidth("600px");
243  $single_form_gui->setTarget($this->getTargetFrame("save"));
244  $single_form_gui->setTitle($this->lng->txt($this->type."_new"));
245  $single_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.png'), $this->lng->txt('obj_file'));
246 
247  $this->ctrl->setParameter($this, "new_type", "file");
248 
249  $single_form_gui->setFormAction($this->ctrl->getFormAction($this, "save"));
250 
251  return $single_form_gui;
252  }
253 
259  function save()
260  {
261  global $objDefinition, $ilUser;
262 
263  if (!$this->checkPermissionBool("create", "", "file"))
264  {
265  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
266  }
267 
268  $single_form_gui = $this->initSingleUploadForm();
269 
270  if ($single_form_gui->checkInput())
271  {
272  $title = $single_form_gui->getInput("title");
273  $description = $single_form_gui->getInput("description");
274  $upload_file = $single_form_gui->getInput("upload_file");
275 
276  if (trim($title) == "")
277  {
278  $title = $upload_file["name"];
279  }
280  else
281  {
282  // BEGIN WebDAV: Ensure that object title ends with the filename extension
283  $fileExtension = ilObjFileAccess::_getFileExtension($upload_file["name"]);
284  $titleExtension = ilObjFileAccess::_getFileExtension($title);
285  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
286  {
287  $title .= '.'.$fileExtension;
288  }
289  // END WebDAV: Ensure that object title ends with the filename extension
290  }
291 
292  // create and insert file in grp_tree
293  include_once("./Modules/File/classes/class.ilObjFile.php");
294  $fileObj = new ilObjFile();
295  $fileObj->setTitle($title);
296  $fileObj->setDescription($description);
297  $fileObj->setFileName($upload_file["name"]);
298  //$fileObj->setFileType($upload_file["type"]);
299  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
300  $fileObj->setFileType(ilMimeTypeUtil::getMimeType(
301  "", $upload_file["name"], $upload_file["type"]));
302  $fileObj->setFileSize($upload_file["size"]);
303  $this->object_id = $fileObj->create();
304 
305  $this->putObjectInTree($fileObj, $this->parent_id);
306 
307  // upload file to filesystem
308  $fileObj->createDirectory();
309  $fileObj->getUploadFile($upload_file["tmp_name"],
310  $upload_file["name"]);
311 
312  $this->handleAutoRating($fileObj);
313 
314  // BEGIN ChangeEvent: Record write event.
315  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
316  ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
317  // END ChangeEvent: Record write event.
318 
319  ilUtil::sendSuccess($this->lng->txt("file_added"),true);
320 
321  if ($this->ctrl->getCmd() == "saveAndMeta")
322  {
323  $this->ctrl->setParameter($this, "new_type", "");
324  $target = $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilmdeditorgui"), "listSection", "", false, false);
325  ilUtil::redirect($target);
326  }
327  else
328  {
329  $this->ctrl->returnToParent($this);
330  }
331  }
332  else
333  {
334  $single_form_gui->setValuesByPost();
335  $this->tpl->setContent($single_form_gui->getHTML());
336  }
337  }
338 
344  function saveAndMeta()
345  {
346  $this->save();
347  }
348 
352  public function initZipUploadForm($a_mode = "create")
353  {
354  global $lng;
355 
356  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
357  $zip_form_gui = new ilPropertyFormGUI();
358  $zip_form_gui->setMultipart(true);
359 
360  // File
361  $in_file = new ilFileInputGUI($lng->txt("file"), "zip_file");
362  $in_file->setRequired(true);
363  $in_file->setSuffixes(array("zip"));
364  $zip_form_gui->addItem($in_file);
365 
366  // Take over structure
367  $in_str = new ilCheckboxInputGUI($this->lng->txt("take_over_structure"), "adopt_structure");
368  $in_str->setInfo($this->lng->txt("take_over_structure_info"));
369  $zip_form_gui->addItem($in_str);
370 
371  $zip_form_gui->addCommandButton("saveUnzip", $this->lng->txt($this->type."_add"));
372  $zip_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
373 
374  $zip_form_gui->setTableWidth("600px");
375  $zip_form_gui->setTarget($this->getTargetFrame("save"));
376  $zip_form_gui->setTitle($this->lng->txt("header_zip"));
377  $zip_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.png'), $this->lng->txt('obj_file'));
378 
379  $this->ctrl->setParameter($this, "new_type", "file");
380 
381  $zip_form_gui->setFormAction($this->ctrl->getFormAction($this, "saveUnzip"));
382 
383  return $zip_form_gui;
384  }
385 
391  function saveUnzip()
392  {
393  $zip_form_gui = $this->initZipUploadForm();
394 
395  if ($this->checkPermissionBool("create", "", "file"))
396  {
397  if ($zip_form_gui->checkInput())
398  {
399  $zip_file = $zip_form_gui->getInput("zip_file");
400  $adopt_structure = $zip_form_gui->getInput("adopt_structure");
401 
402  include_once ("Services/Utilities/classes/class.ilFileUtils.php");
403 
404  // Create unzip-directory
405  $newDir = ilUtil::ilTempnam();
406  ilUtil::makeDir($newDir);
407 
408  // Check if permission is granted for creation of object, if necessary
409  if($this->id_type != self::WORKSPACE_NODE_ID)
410  {
411 
412  $type = ilObject::_lookupType((int)$this->parent_id, true);
413  }
414  else
415  {
416  $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
417  }
418 
419  $tree = $access_handler = null;
420  switch($type)
421  {
422  // workspace structure
423  case 'wfld':
424  case 'wsrt':
425  $permission = $this->checkPermissionBool("create", "", "wfld");
426  $containerType = "WorkspaceFolder";
427  $tree = $this->tree;
428  $access_handler = $this->getAccessHandler();
429  break;
430 
431  // use categories as structure
432  case 'cat':
433  case 'root':
434  $permission = $this->checkPermissionBool("create", "", "cat");
435  $containerType = "Category";
436  break;
437 
438  // use folders as structure (in courses)
439  default:
440  $permission = $this->checkPermissionBool("create", "", "fold");
441  $containerType = "Folder";
442  break;
443  }
444  // processZipFile (
445  // Dir to unzip,
446  // Path to uploaded file,
447  // should a structure be created (+ permission check)?
448  // ref_id of parent
449  // object that contains files (folder or category)
450  // should sendInfo be persistent?)
451  try
452  {
453  $processDone = ilFileUtils::processZipFile( $newDir,
454  $zip_file["tmp_name"],
455  ($adopt_structure && $permission),
456  $this->parent_id,
457  $containerType,
458  $tree,
460  ilUtil::sendSuccess($this->lng->txt("file_added"),true);
461  }
462  catch (ilFileUtilsException $e)
463  {
464  ilUtil::sendFailure($e->getMessage(), true);
465  }
466 
467  ilUtil::delDir($newDir);
468  $this->ctrl->returnToParent($this);
469  }
470  else
471  {
472  $zip_form_gui->setValuesByPost();
473  $this->tpl->setContent($zip_form_gui->getHTML());
474  }
475  }
476  else
477  {
478  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
479  }
480  }
481 
487  function update()
488  {
489  global $ilTabs;
490 
491  $form = $this->initPropertiesForm();
492  if(!$form->checkInput())
493  {
494  $ilTabs->activateTab("settings");
495  $form->setValuesByPost();
496  $this->tpl->setContent($form->getHTML());
497  return false;
498  }
499 
500  $data = $form->getInput('file');
501 
502  // delete trailing '/' in filename
503  while (substr($data["name"],-1) == '/')
504  {
505  $data["name"] = substr($data["name"],0,-1);
506  }
507 
508  $filename = empty($data["name"]) ? $this->object->getFileName() : $data["name"];
509  $title = $form->getInput('title');
510  if(strlen(trim($title)) == 0)
511  {
512  $title = $filename;
513  }
514  else
515  {
516  $title = $this->object->checkFileExtension($filename,$title);
517  }
518  $this->object->setTitle($title);
519 
520  if (!empty($data["name"]))
521  {
522  switch($form->getInput('replace'))
523  {
524  case 1:
525  $this->object->deleteVersions();
526  $this->object->clearDataDirectory();
527  $this->object->replaceFile($data['tmp_name'],$data['name']);
528  break;
529  case 0:
530  $this->object->addFileVersion($data['tmp_name'],$data['name']);
531  break;
532  }
533  $this->object->setFileName($data['name']);
534  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
535  $this->object->setFileType(ilMimeTypeUtil::getMimeType(
536  "", $data["name"], $data["type"]));
537  $this->object->setFileSize($data['size']);
538  }
539 
540  $this->object->setDescription($form->getInput('description'));
541  $this->object->setRating($form->getInput('rating'));
542 
543  $this->update = $this->object->update();
544 
545  // BEGIN ChangeEvent: Record update event.
546  if (!empty($data["name"]))
547  {
548  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
549  global $ilUser;
550  ilChangeEvent::_recordWriteEvent($this->object->getId(), $ilUser->getId(), 'update');
551  ilChangeEvent::_catchupWriteEvents($this->object->getId(), $ilUser->getId());
552  }
553  // END ChangeEvent: Record update event.
554 
555  // Update ecs export settings
556  include_once 'Modules/File/classes/class.ilECSFileSettings.php';
557  $ecs = new ilECSFileSettings($this->object);
558  $ecs->handleSettingsUpdate();
559 
560  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
561  ilUtil::redirect($this->ctrl->getLinkTarget($this,'edit','',false,false));
562  }
563 
569  function edit()
570  {
571  global $ilTabs, $ilErr;
572 
573  if (!$this->checkPermissionBool("write"))
574  {
575  $ilErr->raiseError($this->lng->txt("msg_no_perm_write"));
576  }
577 
578  $ilTabs->activateTab("settings");
579 
580  $form = $this->initPropertiesForm();
581 
582  $val = array();
583  $val['title'] = $this->object->getTitle();
584  $val['description'] = $this->object->getLongDescription();
585  $val['rating'] = $this->object->hasRating();
586  $form->setValuesByArray($val);
587 
588  // Edit ecs export settings
589  include_once 'Modules/File/classes/class.ilECSFileSettings.php';
590  $ecs = new ilECSFileSettings($this->object);
591  $ecs->addSettingsToForm($form, 'file');
592 
593  $this->tpl->setContent($form->getHTML());
594  return true;
595  }
596 
602  protected function initPropertiesForm()
603  {
604  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
605 
606  $this->lng->loadLanguageModule('file');
607 
608  $form = new ilPropertyFormGUI();
609  $form->setFormAction($this->ctrl->getFormAction($this),'update');
610  $form->setTitle($this->lng->txt('file_edit'));
611  $form->addCommandButton('update',$this->lng->txt('save'));
612  $form->addCommandButton('cancel',$this->lng->txt('cancel'));
613 
614  $title = new ilTextInputGUI($this->lng->txt('title'),'title');
615  $title->setValue($this->object->getTitle());
616  $title->setInfo($this->lng->txt("if_no_title_then_filename"));
617  $form->addItem($title);
618 
619  $upload_possible = true;
620  if($this->id_type == self::WORKSPACE_NODE_ID)
621  {
622  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
623  $upload_possible = ilDiskQuotaHandler::isUploadPossible();
624  }
625 
626  if($upload_possible)
627  {
628  $file = new ilFileInputGUI($this->lng->txt('obj_file'),'file');
629  $file->setRequired(false);
630  // $file->enableFileNameSelection('title');
631  $form->addItem($file);
632 
633  $group = new ilRadioGroupInputGUI('','replace');
634  $group->setValue(0);
635 
636  $replace = new ilRadioOption($this->lng->txt('replace_file'),1);
637  $replace->setInfo($this->lng->txt('replace_file_info'));
638  $group->addOption($replace);
639 
640 
641  $keep = new ilRadioOption($this->lng->txt('file_new_version'),0);
642  $keep->setInfo($this->lng->txt('file_new_version_info'));
643  $group->addOption($keep);
644 
645  $file->addSubItem($group);
646  }
647  else
648  {
649  $file = new ilNonEditableValueGUI($this->lng->txt('obj_file'));
650  $file->setValue($this->lng->txt("personal_workspace_quota_exceeded_warning"));
651  $form->addItem($file);
652  }
653 
654  $desc = new ilTextAreaInputGUI($this->lng->txt('description'),'description');
655  $desc->setRows(3);
656  #$desc->setCols(40);
657  $form->addItem($desc);
658 
659  if($this->id_type == self::REPOSITORY_NODE_ID)
660  {
661  $this->lng->loadLanguageModule('rating');
662  $rate = new ilCheckboxInputGUI($this->lng->txt('rating_activate_rating'), 'rating');
663  $rate->setInfo($this->lng->txt('rating_activate_rating_info'));
664  $form->addItem($rate);
665  }
666 
667  return $form;
668  }
669 
670  function sendFile()
671  {
672  global $ilUser, $ilCtrl;
673 
674  if(ANONYMOUS_USER_ID == $ilUser->getId() && isset($_GET['transaction']) )
675  {
676  $this->object->sendFile($_GET["hist_id"]);
677  }
678 
679  if ($this->checkPermissionBool("read"))
680  {
681  // BEGIN ChangeEvent: Record read event.
682  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
683  global $ilUser;
684  // Record read event and catchup with write events
685  ilChangeEvent::_recordReadEvent($this->object->getType(), $this->object->getRefId(),
686  $this->object->getId(), $ilUser->getId());
687  // END ChangeEvent: Record read event.
688 
689  $this->object->sendFile($_GET["hist_id"]);
690  }
691  else
692  {
693  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
694  }
695  return true;
696  }
697 
698 
704  function versions()
705  {
706  global $ilTabs;
707 
708  $ilTabs->activateTab("id_versions");
709 
710  if (!$this->checkPermissionBool("write"))
711  {
712  $this->ilErr->raiseError($this->lng->txt("permission_denied"),$this->ilErr->MESSAGE);
713  }
714 
715  // get versions
716  $versions = $this->object->getVersions();
717 
718  // build versions table
719  require_once("Modules/File/classes/class.ilFileVersionTableGUI.php");
720  $table = new ilFileVersionTableGUI($this, "versions");
721  $table->setMaxCount(sizeof($versions));
722  $table->setData($versions);
723 
724  $this->tpl->setVariable("ADM_CONTENT", $table->getHTML());
725  }
726 
732  function infoScreen()
733  {
734  $this->ctrl->setCmd("showSummary");
735  $this->ctrl->setCmdClass("ilinfoscreengui");
736  $this->infoScreenForward();
737  }
738 
742  function infoScreenForward()
743  {
744  global $ilTabs, $ilErr;
745 
746  $ilTabs->activateTab("id_info");
747 
748  if (!$this->checkPermissionBool("visible"))
749  {
750  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
751  }
752 
753  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
754  $info = new ilInfoScreenGUI($this);
755 
756  if ($this->checkPermissionBool("read", "sendfile"))
757  {
758  // 9876
759  $this->lng->loadLanguageModule("file");
760 
761  // get permanent download link for repository
762  if ($this->id_type == self::REPOSITORY_NODE_ID)
763  $info->addButton($this->lng->txt("file_download"), ilObjFileAccess::_getPermanentDownloadLink($this->node_id), "", "top", true);
764  else
765  $info->addButton($this->lng->txt("file_download"), $this->ctrl->getLinkTarget($this, "sendfile"), "", "top", true);
766  }
767 
768  $info->enablePrivateNotes();
769 
770  if ($this->checkPermissionBool("read"))
771  {
772  $info->enableNews();
773  }
774 
775  // no news editing for files, just notifications
776  $info->enableNewsEditing(false);
777  if ($this->checkPermissionBool("write"))
778  {
779  $news_set = new ilSetting("news");
780  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
781 
782  if ($enable_internal_rss)
783  {
784  $info->setBlockProperty("news", "settings", true);
785  $info->setBlockProperty("news", "public_notifications_option", true);
786  }
787  }
788 
789 
790  // standard meta data
791  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
792 
793  $info->addSection($this->lng->txt("file_info"));
794  $info->addProperty($this->lng->txt("filename"),
795  $this->object->getFileName());
796  // BEGIN WebDAV Guess file type.
797  $info->addProperty($this->lng->txt("type"),
798  $this->object->guessFileType());
799  // END WebDAV Guess file type.
800  $info->addProperty($this->lng->txt("size"),
801  ilFormat::formatSize(ilObjFile::_lookupFileSize($this->object->getId()),'long'));
802  $info->addProperty($this->lng->txt("version"),
803  $this->object->getVersion());
804 
805  // using getVersions function instead of ilHistory direct
806  $uploader = $this->object->getVersions();
807  $uploader = array_shift($uploader);
808  $uploader = $uploader["user_id"];
809 
810  $this->lng->loadLanguageModule("file");
811  include_once "Services/User/classes/class.ilUserUtil.php";
812  $info->addProperty($this->lng->txt("file_uploaded_by"), ilUserUtil::getNamePresentation($uploader));
813 
814  // download link added in repository
815  if ($this->id_type == self::REPOSITORY_NODE_ID && $this->checkPermissionBool("read", "sendfile"))
816  {
817  $tpl = new ilTemplate("tpl.download_link.html", true, true, "Modules/File");
818  $tpl->setVariable("LINK", ilObjFileAccess::_getPermanentDownloadLink($this->node_id));
819  $info->addProperty($this->lng->txt("download_link"), $tpl->get());
820  }
821 
822  if($this->id_type == self::WORKSPACE_NODE_ID)
823  {
824  $info->addProperty($this->lng->txt("perma_link"), $this->getPermanentLinkWidget());
825  }
826 
827  // display previews
828  include_once("./Services/Preview/classes/class.ilPreview.php");
829  if (!$this->ctrl->isAsynch() &&
830  ilPreview::hasPreview($this->object->getId(), $this->object->getType()) &&
831  $this->checkPermissionBool("read"))
832  {
833  include_once("./Services/Preview/classes/class.ilPreviewGUI.php");
834 
835  // get context for access checks later on
836  $context;
837  switch ($this->id_type)
838  {
839  case self::WORKSPACE_NODE_ID:
840  case self::WORKSPACE_OBJECT_ID:
842  break;
843 
844  default:
846  break;
847  }
848 
849  $preview = new ilPreviewGUI($this->node_id, $context, $this->object->getId(), $this->access_handler);
850  $info->addProperty($this->lng->txt("preview"), $preview->getInlineHTML());
851  }
852 
853  // forward the command
854  // $this->ctrl->setCmd("showSummary");
855  // $this->ctrl->setCmdClass("ilinfoscreengui");
856  $this->ctrl->forwardCommand($info);
857  }
858 
859 
860  // get tabs
861  function setTabs()
862  {
863  global $ilTabs, $lng, $ilHelp;
864 
865  $ilHelp->setScreenIdComponent("file");
866 
867  $this->ctrl->setParameter($this,"ref_id",$this->node_id);
868 
869  if ($this->checkPermissionBool("visible"))
870  {
871  $ilTabs->addTab("id_info",
872  $lng->txt("info_short"),
873  $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilinfoscreengui"), "showSummary"));
874  }
875 
876  if ($this->checkPermissionBool("write"))
877  {
878  $ilTabs->addTab("settings",
879  $lng->txt("edit"),
880  $this->ctrl->getLinkTarget($this, "edit"));
881  }
882 
883  if ($this->checkPermissionBool("write"))
884  {
885  $ilTabs->addTab("id_versions",
886  $lng->txt("versions"),
887  $this->ctrl->getLinkTarget($this, "versions"));
888  }
889 
890  // meta data
891  if ($this->checkPermissionBool("write"))
892  {
893  $ilTabs->addTab("id_meta",
894  $lng->txt("meta_data"),
895  $this->ctrl->getLinkTargetByClass(array('ilobjfilegui','ilmdeditorgui'),'listSection'));
896  }
897 
898  // export
899  if ($this->checkPermissionBool("write"))
900  {
901  $ilTabs->addTab("export",
902  $lng->txt("export"),
903  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
904  }
905 
906  // will add permission tab if needed
907  parent::setTabs();
908  }
909 
910  function _goto($a_target, $a_additional = null)
911  {
912  global $ilErr, $lng, $ilAccess;
913 
914  if($a_additional && substr($a_additional, -3) == "wsp")
915  {
916  $_GET["baseClass"] = "ilsharedresourceGUI";
917  $_GET["wsp_id"] = $a_target;
918  include("ilias.php");
919  exit;
920  }
921 
922  // added support for direct download goto links
923  if($a_additional && substr($a_additional, -8) == "download")
924  {
925  ilObjectGUI::_gotoRepositoryNode($a_target, "sendfile");
926  }
927 
928  // static method, no workspace support yet
929 
930  if ($ilAccess->checkAccess("visible", "", $a_target))
931  {
932  ilObjectGUI::_gotoRepositoryNode($a_target, "infoScreen");
933  }
934  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
935  {
936  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
939  }
940 
941  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
942  }
943 
947  function addLocatorItems()
948  {
949  global $ilLocator;
950 
951  if (is_object($this->object))
952  {
953  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
954  }
955  }
956 
962  public function initMultiUploadForm()
963  {
964  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
965  $dnd_form_gui = new ilPropertyFormGUI();
966  $dnd_form_gui->setMultipart(true);
967  $dnd_form_gui->setHideLabels();
968 
969  // file input
970  include_once("Services/Form/classes/class.ilDragDropFileInputGUI.php");
971  $dnd_input = new ilDragDropFileInputGUI($this->lng->txt("files"), "upload_files");
972  $dnd_input->setArchiveSuffixes(array("zip"));
973  $dnd_input->setCommandButtonNames("uploadFiles", "cancel");
974  $dnd_form_gui->addItem($dnd_input);
975 
976  // add commands
977  $dnd_form_gui->addCommandButton("uploadFiles", $this->lng->txt("upload_files"));
978  $dnd_form_gui->addCommandButton("cancel", $this->lng->txt("cancel"));
979 
980  $dnd_form_gui->setTableWidth("100%");
981  $dnd_form_gui->setTarget($this->getTargetFrame("save"));
982  $dnd_form_gui->setTitle($this->lng->txt("upload_files_title"));
983  $dnd_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $this->lng->txt('obj_file'));
984 
985  $this->ctrl->setParameter($this, "new_type", "file");
986  $dnd_form_gui->setFormAction($this->ctrl->getFormAction($this, "uploadFiles"));
987 
988  return $dnd_form_gui;
989  }
990 
994  public function uploadFiles()
995  {
996  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
997 
998  $response = new stdClass();
999  $response->error = null;
1000  $response->debug = null;
1001 
1002  $files = $_FILES;
1003 
1004  // load form
1005  $dnd_form_gui = $this->initMultiUploadForm();
1006  if ($dnd_form_gui->checkInput())
1007  {
1008  try
1009  {
1010  if (!$this->checkPermissionBool("create", "", "file"))
1011  {
1012  $response->error = $this->lng->txt("permission_denied");
1013  }
1014  else
1015  {
1016  // handle the file
1017  $fileresult = $this->handleFileUpload($dnd_form_gui->getInput("upload_files"));
1018  if ($fileresult)
1019  $response = (object)array_merge((array)$response, (array)$fileresult);
1020  }
1021  }
1022  catch (Exception $ex)
1023  {
1024  $response->error = $ex->getMessage() . " ## " . $ex->getTraceAsString();
1025  }
1026  }
1027  else
1028  {
1029  $dnd_input = $dnd_form_gui->getItemByPostVar("upload_files");
1030  $response->error = $dnd_input->getAlert();
1031  }
1032 
1033  // send response object (don't use 'application/json' as IE wants to download it!)
1034  header('Vary: Accept');
1035  header('Content-type: text/plain');
1036  echo ilJsonUtil::encode($response);
1037 
1038  // no further processing!
1039  exit;
1040  }
1041 
1048  protected function handleFileUpload($file_upload)
1049  {
1050  global $ilUser;
1051 
1052  // file upload params
1053  $filename = ilUtil::stripSlashes($file_upload["name"]);
1054  $type = ilUtil::stripSlashes($file_upload["type"]);
1055  $size = ilUtil::stripSlashes($file_upload["size"]);
1056  $temp_name = $file_upload["tmp_name"];
1057 
1058  // additional params
1059  $title = ilUtil::stripSlashes($file_upload["title"]);
1060  $description = ilUtil::stripSlashes($file_upload["description"]);
1061  $extract = ilUtil::stripSlashes($file_upload["extract"]);
1062  $keep_structure = ilUtil::stripSlashes($file_upload["keep_structure"]);
1063 
1064  // create answer object
1065  $response = new stdClass();
1066  $response->fileName = $filename;
1067  $response->fileSize = intval($size);
1068  $response->fileType = $type;
1069  $response->fileUnzipped = $extract;
1070  $response->error = null;
1071 
1072  // extract archive?
1073  if ($extract)
1074  {
1075  $zip_file = $filename;
1076  $adopt_structure = $keep_structure;
1077 
1078  include_once ("Services/Utilities/classes/class.ilFileUtils.php");
1079 
1080  // Create unzip-directory
1081  $newDir = ilUtil::ilTempnam();
1082  ilUtil::makeDir($newDir);
1083 
1084  // Check if permission is granted for creation of object, if necessary
1085  if($this->id_type != self::WORKSPACE_NODE_ID)
1086  {
1087  $type = ilObject::_lookupType((int)$this->parent_id, true);
1088  }
1089  else
1090  {
1091  $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
1092  }
1093 
1094  $tree = $access_handler = null;
1095  switch($type)
1096  {
1097  // workspace structure
1098  case 'wfld':
1099  case 'wsrt':
1100  $permission = $this->checkPermissionBool("create", "", "wfld");
1101  $containerType = "WorkspaceFolder";
1102  $tree = $this->tree;
1103  $access_handler = $this->getAccessHandler();
1104  break;
1105 
1106  // use categories as structure
1107  case 'cat':
1108  case 'root':
1109  $permission = $this->checkPermissionBool("create", "", "cat");
1110  $containerType = "Category";
1111  break;
1112 
1113  // use folders as structure (in courses)
1114  default:
1115  $permission = $this->checkPermissionBool("create", "", "fold");
1116  $containerType = "Folder";
1117  break;
1118  }
1119 
1120  try
1121  {
1122  // processZipFile (
1123  // Dir to unzip,
1124  // Path to uploaded file,
1125  // should a structure be created (+ permission check)?
1126  // ref_id of parent
1127  // object that contains files (folder or category)
1128  // should sendInfo be persistent?)
1130  $newDir,
1131  $temp_name,
1132  ($adopt_structure && $permission),
1133  $this->parent_id,
1134  $containerType,
1135  $tree,
1136  $access_handler);
1137  }
1138  catch (ilFileUtilsException $e)
1139  {
1140  $response->error = $e->getMessage();
1141  }
1142  catch (Exception $ex)
1143  {
1144  $response->error = $ex->getMessage();
1145  }
1146 
1147  ilUtil::delDir($newDir);
1148  }
1149  else
1150  {
1151  if (trim($title) == "")
1152  {
1153  $title = $filename;
1154  }
1155  else
1156  {
1157  // BEGIN WebDAV: Ensure that object title ends with the filename extension
1159  $titleExtension = ilObjFileAccess::_getFileExtension($title);
1160  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
1161  {
1162  $title .= '.'.$fileExtension;
1163  }
1164  // END WebDAV: Ensure that object title ends with the filename extension
1165  }
1166 
1167  // create and insert file in grp_tree
1168  include_once("./Modules/File/classes/class.ilObjFile.php");
1169  $fileObj = new ilObjFile();
1170  $fileObj->setTitle($title);
1171  $fileObj->setDescription($description);
1172  $fileObj->setFileName($filename);
1173 
1174  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
1175  $fileObj->setFileType(ilMimeTypeUtil::getMimeType("", $filename, $type));
1176  $fileObj->setFileSize($size);
1177  $this->object_id = $fileObj->create();
1178 
1179  $this->putObjectInTree($fileObj, $this->parent_id);
1180 
1181  // upload file to filesystem
1182  $fileObj->createDirectory();
1183  $fileObj->raiseUploadError(false);
1184  $fileObj->getUploadFile($temp_name, $filename);
1185 
1186  $this->handleAutoRating($fileObj);
1187 
1188  // BEGIN ChangeEvent: Record write event.
1189  require_once('./Services/Tracking/classes/class.ilChangeEvent.php');
1190  ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
1191  // END ChangeEvent: Record write event.
1192  }
1193 
1194  return $response;
1195  }
1196 
1200  function deleteVersions()
1201  {
1202  global $ilTabs, $ilLocator;
1203 
1204  // get ids either from GET (if single item was clicked) or
1205  // from POST (if multiple items were selected)
1206  $version_ids = isset($_GET["hist_id"]) ? array($_GET["hist_id"]) : $_POST["hist_id"];
1207 
1208  if (count($version_ids) < 1)
1209  {
1210  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
1211  $this->ctrl->redirect($this, "versions");
1212  }
1213  else
1214  {
1215  $ilTabs->activateTab("id_versions");
1216 
1217  // check if all versions are selected
1218  $versionsToKeep = array_udiff($this->object->getVersions(), $version_ids, array($this, "compareHistoryIds"));
1219  if (count($versionsToKeep) < 1)
1220  {
1221  // set our message
1222  ilUtil::sendQuestion($this->lng->txt("file_confirm_delete_all_versions"));
1223 
1224  // show confirmation gui
1225  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1226  $conf_gui = new ilConfirmationGUI();
1227  $conf_gui->setFormAction($this->ctrl->getFormAction($this, "versions"));
1228  $conf_gui->setCancel($this->lng->txt("cancel"), "cancelDeleteFile");
1229  $conf_gui->setConfirm($this->lng->txt("confirm"), "confirmDeleteFile");
1230 
1231  $conf_gui->addItem("id[]", $this->ref_id, $this->object->getTitle(),
1232  ilObject::_getIcon($this->object->getId(), "small", $this->object->getType()),
1233  $this->lng->txt("icon")." ".$this->lng->txt("obj_".$this->object->getType()));
1234 
1235  $html = $conf_gui->getHTML();
1236  }
1237  else
1238  {
1239  include_once("./Modules/File/classes/class.ilFileVersionTableGUI.php");
1240 
1241  ilUtil::sendQuestion($this->lng->txt("file_confirm_delete_versions"));
1242  $versions = $this->object->getVersions($version_ids);
1243 
1244  $table = new ilFileVersionTableGUI($this, 'versions', true);
1245  $table->setMaxCount(sizeof($versions));
1246  $table->setData($versions);
1247 
1248  $html = $table->getHTML();
1249  }
1250 
1251  $this->tpl->setVariable('ADM_CONTENT', $html);
1252  }
1253  }
1254 
1259  {
1260  global $ilTabs;
1261 
1262  // has the user the rights to delete versions?
1263  if (!$this->checkPermissionBool("write"))
1264  {
1265  $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
1266  }
1267 
1268  // delete versions after confirmation
1269  if (count($_POST["hist_id"]) > 0)
1270  {
1271  $this->object->deleteVersions($_POST["hist_id"]);
1272  ilUtil::sendSuccess($this->lng->txt("file_versions_deleted"), true);
1273  }
1274 
1275  $this->ctrl->setParameter($this, "hist_id", "");
1276  $this->ctrl->redirect($this, "versions");
1277  }
1278 
1283  {
1284  $this->ctrl->redirect($this, "versions");
1285  }
1286 
1291  {
1292  // has the user the rights to delete the file?
1293  if (!$this->checkPermissionBool("write"))
1294  {
1295  $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
1296  }
1297 
1298  // delete this file object
1299  include_once("./Services/Repository/classes/class.ilRepUtilGUI.php");
1300  $ru = new ilRepUtilGUI($this);
1301  $ru->deleteObjects($this->parent_id, array($this->ref_id));
1302 
1303  // redirect to parent object
1304  $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $this->parent_id);
1305  $this->ctrl->redirectByClass("ilrepositorygui");
1306  }
1307 
1311  function cancelDeleteFile()
1312  {
1313  $this->ctrl->redirect($this, "versions");
1314  }
1315 
1323  function compareHistoryIds($v1, $v2)
1324  {
1325  if (is_array($v1))
1326  $v1 = (int)$v1["hist_entry_id"];
1327  else if (!is_int($v1))
1328  $v1 = (int)$v1;
1329 
1330  if (is_array($v2))
1331  $v2 = (int)$v2["hist_entry_id"];
1332  else if (!is_int($v2))
1333  $v2 = (int)$v2;
1334 
1335  return $v1 - $v2;
1336  }
1337 
1341  function rollbackVersion()
1342  {
1343  global $ilTabs;
1344 
1345  // has the user the rights to delete the file?
1346  if (!$this->checkPermissionBool("write"))
1347  {
1348  $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
1349  }
1350 
1351  // get ids either from GET (if single item was clicked) or
1352  // from POST (if multiple items were selected)
1353  $version_ids = isset($_GET["hist_id"]) ? array($_GET["hist_id"]) : $_POST["hist_id"];
1354 
1355  // more than one entry selected?
1356  if (count($version_ids) != 1)
1357  {
1358  ilUtil::sendInfo($this->lng->txt("file_rollback_select_exact_one"), true);
1359  $this->ctrl->redirect($this, "versions");
1360  }
1361 
1362  // rollback the version
1363  $new_version = $this->object->rollback($version_ids[0]);
1364 
1365  ilUtil::sendSuccess(sprintf($this->lng->txt("file_rollback_done"), $new_version["rollback_version"]), true);
1366  $this->ctrl->redirect($this, "versions");
1367  }
1368 
1369  protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
1370  {
1371  $lg = parent::initHeaderAction($a_sub_type, $a_sub_id);
1372  if(is_object($lg))
1373  {
1374  if($this->object->hasRating())
1375  {
1376  $lg->enableRating(true, null, false,
1377  array("ilcommonactiondispatchergui", "ilratinggui"));
1378  }
1379  }
1380  return $lg;
1381  }
1382 
1383 } // END class.ilObjFileGUI
1384 ?>