ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
18{
19 const CMD_EDIT = "edit";
20 const CMD_VERSIONS = "versions";
24 public $object;
25 protected $log = null;
26
27
35 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
36 {
37 $this->log = ilLoggerFactory::getLogger('file');
38 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
39 $this->lng->loadLanguageModule('file');
40 }
41
42
43 public function getType()
44 {
45 return "file";
46 }
47
48
49 public function executeCommand()
50 {
51 global $DIC;
52 $ilNavigationHistory = $DIC['ilNavigationHistory'];
53 $ilCtrl = $DIC['ilCtrl'];
54 $ilUser = $DIC['ilUser'];
55 $ilTabs = $DIC['ilTabs'];
56 $ilAccess = $DIC['ilAccess'];
57 $ilErr = $DIC['ilErr'];
58
59 $next_class = $this->ctrl->getNextClass($this);
60 $cmd = $this->ctrl->getCmd();
61
62 if ($this->id_type == self::WORKSPACE_NODE_ID) {
64 }
65
66 if (!$this->getCreationMode()) {
67 if ($this->id_type == self::REPOSITORY_NODE_ID
68 && $this->checkPermissionBool("read")
69 ) {
70 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->node_id);
71 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "infoScreen");
72 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
73
74 // add entry to navigation history
75 $ilNavigationHistory->addItem(
76 $this->node_id,
77 $link,
78 "file"
79 );
80 }
81 }
82
83 $this->prepareOutput();
84
85 switch ($next_class) {
86 case "ilinfoscreengui":
87 $this->infoScreenForward(); // forwards command
88 break;
89
90 case 'ilobjectmetadatagui':
91 if (!$this->checkPermissionBool("write")) {
92 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->WARNING);
93 }
94
95 $ilTabs->activateTab("id_meta");
96
97 $md_gui = new ilObjectMetaDataGUI($this->object);
98
99 // todo: make this work
100 // $md_gui->addMDObserver($this->object,'MDUpdateListener','Technical');
101
102 $this->ctrl->forwardCommand($md_gui);
103 break;
104
105 // repository permissions
106 case 'ilpermissiongui':
107 $ilTabs->activateTab("id_permissions");
108 $perm_gui = new ilPermissionGUI($this);
109 $ret = $this->ctrl->forwardCommand($perm_gui);
110 break;
111
112 case "ilexportgui":
113 $ilTabs->activateTab("export");
114 $exp_gui = new ilExportGUI($this);
115 $exp_gui->addFormat("xml");
116 $ret = $this->ctrl->forwardCommand($exp_gui);
117 break;
118
119 case 'ilobjectcopygui':
120 $cp = new ilObjectCopyGUI($this);
121 $cp->setType('file');
122 $this->ctrl->forwardCommand($cp);
123 break;
124
125 // personal workspace permissions
126 case "ilworkspaceaccessgui":
127 $ilTabs->activateTab("id_permissions");
128 $wspacc = new ilWorkspaceAccessGUI($this->node_id, $this->getAccessHandler());
129 $this->ctrl->forwardCommand($wspacc);
130 break;
131
132 case "ilcommonactiondispatchergui":
134 $this->ctrl->forwardCommand($gui);
135 break;
136
137 case "illearningprogressgui":
138 $ilTabs->activateTab('learning_progress');
139 $new_gui = new ilLearningProgressGUI(
141 $this->object->getRefId(),
142 $_GET['user_id'] ? $_GET['user_id'] : $ilUser->getId()
143 );
144 $this->ctrl->forwardCommand($new_gui);
145 $this->tabs_gui->setTabActive('learning_progress');
146 break;
147 case strtolower(ilFileVersionsGUI::class):
148 $this->tabs_gui->activateTab("id_versions");
149
150 if (!$this->checkPermissionBool("write")) {
151 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
152 }
153 $this->ctrl->forwardCommand(new ilFileVersionsGUI($this->object));
154 break;
155
156 default:
157 // in personal workspace use object2gui
158 if ($this->id_type == self::WORKSPACE_NODE_ID) {
159 $this->addHeaderAction();
160
161 // coming from goto we need default command
162 if (empty($cmd)) {
163 $ilCtrl->setCmd("infoScreen");
164 }
165 $ilTabs->clearTargets();
166
167 return parent::executeCommand();
168 }
169
170 if (empty($cmd)) {
171 $cmd = "infoScreen";
172 }
173
174 $this->$cmd();
175 break;
176 }
177
178 $this->addHeaderAction();
179 }
180
181
185 protected function initCreationForms($a_new_type)
186 {
187 $forms = array();
188
189 if ($this->id_type == self::WORKSPACE_NODE_ID) {
191 ilUtil::sendFailure($this->lng->txt("personal_workspace_quota_exceeded_warning"), true);
192 $this->ctrl->redirect($this, "cancel");
193 }
194 }
195
196 // use drag-and-drop upload if configured
198 $forms[] = $this->initMultiUploadForm();
199 } else {
200 $forms[] = $this->initSingleUploadForm();
201 $forms[] = $this->initZipUploadForm();
202 }
203
204 // repository only
205 if ($this->id_type != self::WORKSPACE_NODE_ID) {
206 $forms[self::CFORM_IMPORT] = $this->initImportForm('file');
207 $forms[self::CFORM_CLONE] = $this->fillCloneTemplate(null, "file");
208 }
209
210 return $forms;
211 }
212
213
217 public function initSingleUploadForm()
218 {
219 global $DIC;
220 $lng = $DIC['lng'];
221
222 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
223 $single_form_gui = new ilPropertyFormGUI();
224 $single_form_gui->setMultipart(true);
225
226 // File Title
227 $in_title = new ilTextInputGUI($lng->txt("title"), "title");
228 $in_title->setInfo($this->lng->txt("if_no_title_then_filename"));
229 $in_title->setSize(min(40, ilObject::TITLE_LENGTH));
230 $in_title->setMaxLength(ilObject::TITLE_LENGTH);
231 $single_form_gui->addItem($in_title);
232
233 // File Description
234 $in_descr = new ilTextAreaInputGUI($lng->txt("description"), "description");
235 $single_form_gui->addItem($in_descr);
236
237 // File
238 $in_file = new ilFileInputGUI($lng->txt("file"), "upload_file");
239 $in_file->setRequired(true);
240 $single_form_gui->addItem($in_file);
241
242 $single_form_gui->addCommandButton("save", $this->lng->txt($this->type . "_add"));
243 $single_form_gui->addCommandButton("saveAndMeta", $this->lng->txt("file_add_and_metadata"));
244 $single_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
245
246 $single_form_gui->setTableWidth("600px");
247 $single_form_gui->setTarget($this->getTargetFrame("save"));
248 $single_form_gui->setTitle($this->lng->txt($this->type . "_new"));
249 $single_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.svg'), $this->lng->txt('obj_file'));
250
251 $this->ctrl->setParameter($this, "new_type", "file");
252
253 $single_form_gui->setFormAction($this->ctrl->getFormAction($this, "save"));
254
255 return $single_form_gui;
256 }
257
258
264 public function save()
265 {
266 global $DIC;
267 $ilUser = $DIC->user();
268
269 if (!$this->checkPermissionBool("create", "", "file")) {
270 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
271 }
272
273 $single_form_gui = $this->initSingleUploadForm();
274
275 if ($single_form_gui->checkInput()) {
276 $title = $single_form_gui->getInput("title");
277 $description = $single_form_gui->getInput("description");
278 $upload_file = $single_form_gui->getInput("upload_file");
279
280 if (trim($title) == "") {
281 $title = $upload_file["name"];
282 } else {
283 // BEGIN WebDAV: Ensure that object title ends with the filename extension
284 $fileExtension = ilObjFileAccess::_getFileExtension($upload_file["name"]);
286 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) {
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
294 $fileObj = new ilObjFile();
295 $fileObj->setTitle($title);
296 $fileObj->setDescription($description);
297 $fileObj->setFileName($upload_file["name"]);
298
299 $fileObj->setFileType(ilMimeTypeUtil::getMimeType(
300 "",
301 $upload_file["name"],
302 $upload_file["type"]
303 ));
304 $fileObj->setFileSize($upload_file["size"]);
305 $this->object_id = $fileObj->create();
306
307 $this->putObjectInTree($fileObj, $this->parent_id);
308
309 // upload file to filesystem
310 $fileObj->createDirectory();
311 if ($result = $fileObj->getUploadFile($upload_file["tmp_name"], $upload_file["name"])) {
312 $fileObj->setFileName($result->getName());
313 }
314
315 $this->handleAutoRating($fileObj);
316
317 // BEGIN ChangeEvent: Record write event.
318 ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
319 // END ChangeEvent: Record write event.
320
321 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
322
323 if ($this->ctrl->getCmd() == "saveAndMeta") {
324 $this->ctrl->setParameter($this, "new_type", "");
325 $target = $this->ctrl->getLinkTargetByClass(array("ilobjectmetadatagui", "ilmdeditorgui"), "listSection", "", false, false);
327 } else {
328 $this->ctrl->returnToParent($this);
329 }
330 } else {
331 $single_form_gui->setValuesByPost();
332 $this->tpl->setContent($single_form_gui->getHTML());
333 }
334 }
335
336
342 public function saveAndMeta()
343 {
344 $this->save();
345 }
346
347
351 public function initZipUploadForm($a_mode = "create")
352 {
353 global $DIC;
354 $lng = $DIC['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.svg'), $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
386
392 public function saveUnzip()
393 {
394 $zip_form_gui = $this->initZipUploadForm();
395
396 if ($this->checkPermissionBool("create", "", "file")) {
397 if ($zip_form_gui->checkInput()) {
398 $zip_file = $zip_form_gui->getInput("zip_file");
399 $adopt_structure = $zip_form_gui->getInput("adopt_structure");
400
401 include_once("Services/Utilities/classes/class.ilFileUtils.php");
402
403 // Create unzip-directory
404 $newDir = ilUtil::ilTempnam();
405 ilUtil::makeDir($newDir);
406
407 // Check if permission is granted for creation of object, if necessary
408 if ($this->id_type != self::WORKSPACE_NODE_ID) {
409 $type = ilObject::_lookupType((int) $this->parent_id, true);
410 } else {
411 $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
412 }
413
414 $tree = $access_handler = null;
415 switch ($type) {
416 // workspace structure
417 case 'wfld':
418 case 'wsrt':
419 $permission = $this->checkPermissionBool("create", "", "wfld");
420 $containerType = "WorkspaceFolder";
423 break;
424
425 // use categories as structure
426 case 'cat':
427 case 'root':
428 $permission = $this->checkPermissionBool("create", "", "cat");
429 $containerType = "Category";
430 break;
431
432 // use folders as structure (in courses)
433 default:
434 $permission = $this->checkPermissionBool("create", "", "fold");
435 $containerType = "Folder";
436 break;
437 }
438 // processZipFile (
439 // Dir to unzip,
440 // Path to uploaded file,
441 // should a structure be created (+ permission check)?
442 // ref_id of parent
443 // object that contains files (folder or category)
444 // should sendInfo be persistent?)
445 try {
446 $processDone = ilFileUtils::processZipFile(
447 $newDir,
448 $zip_file["tmp_name"],
449 ($adopt_structure && $permission),
450 $this->parent_id,
451 $containerType,
452 $tree,
454 );
455 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
456 } catch (ilFileUtilsException $e) {
457 ilUtil::sendFailure($e->getMessage(), true);
458 }
459
460 ilUtil::delDir($newDir);
461 $this->ctrl->returnToParent($this);
462 } else {
463 $zip_form_gui->setValuesByPost();
464 $this->tpl->setContent($zip_form_gui->getHTML());
465 }
466 } else {
467 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
468 }
469 }
470
471
477 public function update()
478 {
479 global $DIC;
480 $ilTabs = $DIC['ilTabs'];
481
482 $form = $this->initPropertiesForm(self::CMD_EDIT);
483 if (!$form->checkInput()) {
484 $ilTabs->activateTab("settings");
485 $form->setValuesByPost();
486 $this->tpl->setContent($form->getHTML());
487
488 return false;
489 }
490
491 $title = $form->getInput('title');
492 // bugfix mantis 26045:
493 $filename = empty($data["name"]) ? $this->object->getFileName() : $data["name"];
494 if (strlen(trim($title)) == 0) {
496 } else {
497 $title = $this->object->checkFileExtension($filename, $title);
498 }
499 $this->object->setTitle($title);
500 $this->object->setDescription($form->getInput('description'));
501 $this->object->setRating($form->getInput('rating'));
502
503 $this->update = $this->object->update();
504
505 // BEGIN ChangeEvent: Record update event.
506 if (!empty($data["name"])) {
507 global $DIC;
508 $ilUser = $DIC['ilUser'];
509 ilChangeEvent::_recordWriteEvent($this->object->getId(), $ilUser->getId(), 'update');
510 ilChangeEvent::_catchupWriteEvents($this->object->getId(), $ilUser->getId());
511 }
512 // END ChangeEvent: Record update event.
513
514 // Update ecs export settings
515 $ecs = new ilECSFileSettings($this->object);
516 $ecs->handleSettingsUpdate();
517
518 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
519 ilUtil::redirect($this->ctrl->getLinkTarget($this, self::CMD_EDIT, '', false, false));
520 }
521
522
528 public function edit()
529 {
530 global $DIC;
531 $ilTabs = $DIC['ilTabs'];
532 $ilErr = $DIC['ilErr'];
533
534 if (!$this->checkPermissionBool("write")) {
535 $ilErr->raiseError($this->lng->txt("msg_no_perm_write"));
536 }
537
538 $ilTabs->activateTab("settings");
539
540 $form = $this->initPropertiesForm(self::CMD_EDIT);
541
542 $val = array();
543 $val['title'] = $this->object->getTitle();
544 $val['description'] = $this->object->getLongDescription();
545 $val['rating'] = $this->object->hasRating();
546 $form->setValuesByArray($val);
547
548 // Edit ecs export settings
549 include_once 'Modules/File/classes/class.ilECSFileSettings.php';
550 $ecs = new ilECSFileSettings($this->object);
551 $ecs->addSettingsToForm($form, 'file');
552
553 $this->tpl->setContent($form->getHTML());
554
555 return true;
556 }
557
558
565 protected function initPropertiesForm($mode = "create")
566 {
567 $form = new ilPropertyFormGUI();
568 $form->setFormAction($this->ctrl->getFormAction($this, 'update'));
569 $form->setTitle($this->lng->txt('file_edit'));
570 $form->addCommandButton('update', $this->lng->txt('save'));
571 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
572
573 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
574 $title->setValue($this->object->getTitle());
575 $title->setInfo($this->lng->txt("if_no_title_then_filename"));
576 $form->addItem($title);
577
578 if ($mode === 'create') {
579 $upload_possible = true;
580 if ($this->id_type == self::WORKSPACE_NODE_ID) {
581 $upload_possible = ilDiskQuotaHandler::isUploadPossible();
582 }
583
584 if ($upload_possible) {
586 'cancel',
587 $this->lng->txt('obj_file'),
588 'file'
589 );
590 $file->setRequired(false);
591 $form->addItem($file);
592
593 $group = new ilRadioGroupInputGUI('', 'replace');
594 $group->setValue(0);
595
596 $replace = new ilRadioOption($this->lng->txt('replace_file'), 1);
597 $replace->setInfo($this->lng->txt('replace_file_info'));
598 $group->addOption($replace);
599
600 $keep = new ilRadioOption($this->lng->txt('file_new_version'), 0);
601 $keep->setInfo($this->lng->txt('file_new_version_info'));
602 $group->addOption($keep);
603
604 $file->addSubItem($group);
605 } elseif ($mode == 'create') {
606 $file = new ilNonEditableValueGUI($this->lng->txt('obj_file'));
607 $file->setValue($this->lng->txt("personal_workspace_quota_exceeded_warning"));
608 $form->addItem($file);
609 }
610 } else {
611 $o = new ilNonEditableValueGUI($this->lng->txt('upload_info'));
612 $o->setValue($this->lng->txt('upload_info_desc'));
613 $form->addItem($o);
614 }
615 $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
616 $desc->setRows(3);
617 $form->addItem($desc);
618
619 if ($this->id_type == self::REPOSITORY_NODE_ID) {
620 $this->lng->loadLanguageModule('rating');
621 $rate = new ilCheckboxInputGUI($this->lng->txt('rating_activate_rating'), 'rating');
622 $rate->setInfo($this->lng->txt('rating_activate_rating_info'));
623 $form->addItem($rate);
624 }
625
626 return $form;
627 }
628
629
630 public function sendFile()
631 {
632 global $DIC;
633
634 try {
635 if (ANONYMOUS_USER_ID == $DIC->user()->getId() && isset($_GET['transaction'])) {
636 $a_hist_entry_id = isset($_GET["hist_id"]) ? $_GET["hist_id"] : null;
637 $this->object->sendFile($a_hist_entry_id);
638 }
639
640 if ($this->checkPermissionBool("read")) {
641 // BEGIN ChangeEvent: Record read event.
642 require_once('Services/Tracking/classes/class.ilChangeEvent.php');
643
644 // Record read event and catchup with write events
646 $this->object->getType(),
647 $this->object->getRefId(),
648 $this->object->getId(),
649 $DIC->user()->getId()
650 );
651 // END ChangeEvent: Record read event.
652
653 require_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
654 ilLPStatusWrapper::_updateStatus($this->object->getId(), $DIC->user()->getId());
655
656 $a_hist_entry_id = isset($_GET["hist_id"]) ? $_GET["hist_id"] : null;
657 $this->object->sendFile($a_hist_entry_id);
658 } else {
659 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
660 }
661 } catch (\ILIAS\Filesystem\Exception\FileNotFoundException $e) {
662 $this->ilErr->raiseError($e->getMessage(), $this->ilErr->MESSAGE);
663 }
664
665 return true;
666 }
667
668
672 public function versions()
673 {
674 $this->ctrl->redirectByClass(ilFileVersionsGUI::class);
675 }
676
677
683 public function infoScreen()
684 {
685 $this->ctrl->setCmd("showSummary");
686 $this->ctrl->setCmdClass("ilinfoscreengui");
687 $this->infoScreenForward();
688 }
689
690
694 public function infoScreenForward()
695 {
696 global $DIC;
697 $ilTabs = $DIC['ilTabs'];
698 $ilErr = $DIC['ilErr'];
699 $ilToolbar = $DIC['ilToolbar'];
700
701 $ilTabs->activateTab("id_info");
702
703 if (!$this->checkPermissionBool("visible") && !$this->checkPermissionBool("read")) {
704 $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
705 }
706
707 include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
708 $info = new ilInfoScreenGUI($this);
709
710 if ($this->checkPermissionBool("read", "sendfile")) {
711 // #14378
712 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
713 $button = ilLinkButton::getInstance();
714 $button->setCaption("file_download");
715 $button->setPrimary(true);
716
717 // get permanent download link for repository
718 if ($this->id_type == self::REPOSITORY_NODE_ID) {
719 $button->setUrl(ilObjFileAccess::_getPermanentDownloadLink($this->node_id));
720 } else {
721 $button->setUrl($this->ctrl->getLinkTarget($this, "sendfile"));
722 }
723
724 $ilToolbar->addButtonInstance($button);
725 }
726
727 $info->enablePrivateNotes();
728
729 if ($this->checkPermissionBool("read")) {
730 $info->enableNews();
731 }
732
733 // no news editing for files, just notifications
734 $info->enableNewsEditing(false);
735 if ($this->checkPermissionBool("write")) {
736 $news_set = new ilSetting("news");
737 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
738
739 if ($enable_internal_rss) {
740 $info->setBlockProperty("news", "settings", true);
741 $info->setBlockProperty("news", "public_notifications_option", true);
742 }
743 }
744
745 // standard meta data
746 $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
747
748 // File Info
749 $info->addSection($this->lng->txt("file_info"));
750 $info->addProperty($this->lng->txt("filename"), $this->object->getFileName());
751 $info->addProperty($this->lng->txt("type"), $this->object->guessFileType());
752
753 $info->addProperty($this->lng->txt("size"), ilUtil::formatSize(ilObjFile::_lookupFileSize($this->object->getId()), 'long'));
754 $info->addProperty($this->lng->txt("version"), $this->object->getVersion());
755
756 if ($this->object->getPageCount() > 0) {
757 $info->addProperty($this->lng->txt("page_count"), $this->object->getPageCount());
758 }
759
760 // using getVersions function instead of ilHistory direct
761 $uploader = $this->object->getVersions();
762 $uploader = array_shift($uploader);
763 $uploader = $uploader["user_id"];
764
765 include_once "Services/User/classes/class.ilUserUtil.php";
766 $info->addProperty($this->lng->txt("file_uploaded_by"), ilUserUtil::getNamePresentation($uploader));
767
768 // download link added in repository
769 if ($this->id_type == self::REPOSITORY_NODE_ID && $this->checkPermissionBool("read", "sendfile")) {
770 $tpl = new ilTemplate("tpl.download_link.html", true, true, "Modules/File");
771 $tpl->setVariable("LINK", ilObjFileAccess::_getPermanentDownloadLink($this->node_id));
772 $info->addProperty($this->lng->txt("download_link"), $tpl->get());
773 }
774
775 if ($this->id_type == self::WORKSPACE_NODE_ID) {
776 $info->addProperty($this->lng->txt("perma_link"), $this->getPermanentLinkWidget());
777 }
778
779 // display previews
780 include_once("./Services/Preview/classes/class.ilPreview.php");
781 if (!$this->ctrl->isAsynch()
782 && ilPreview::hasPreview($this->object->getId(), $this->object->getType())
783 && $this->checkPermissionBool("read")
784 ) {
785 include_once("./Services/Preview/classes/class.ilPreviewGUI.php");
786
787 // get context for access checks later on
788 $context;
789 switch ($this->id_type) {
793 break;
794
795 default:
797 break;
798 }
799
800 $preview = new ilPreviewGUI($this->node_id, $context, $this->object->getId(), $this->access_handler);
801 $info->addProperty($this->lng->txt("preview"), $preview->getInlineHTML());
802 }
803
804 // forward the command
805 // $this->ctrl->setCmd("showSummary");
806 // $this->ctrl->setCmdClass("ilinfoscreengui");
807 $this->ctrl->forwardCommand($info);
808 }
809
810
811 // get tabs
812 public function setTabs()
813 {
814 global $DIC;
815 $ilTabs = $DIC['ilTabs'];
816 $lng = $DIC['lng'];
817 $ilHelp = $DIC['ilHelp'];
818
819 $ilHelp->setScreenIdComponent("file");
820
821 $this->ctrl->setParameter($this, "ref_id", $this->node_id);
822
823 if ($this->checkPermissionBool("write")) {
824 $ilTabs->addTab(
825 "id_versions",
826 $lng->txt(self::CMD_VERSIONS),
827 $this->ctrl->getLinkTargetByClass(ilFileVersionsGUI::class, ilFileVersionsGUI::CMD_DEFAULT)
828 );
829 }
830
831 if ($this->checkPermissionBool("visible") || $this->checkPermissionBool("read")) {
832 $ilTabs->addTab(
833 "id_info",
834 $lng->txt("info_short"),
835 $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilinfoscreengui"), "showSummary")
836 );
837 }
838
839 if ($this->checkPermissionBool("write")) {
840 $ilTabs->addTab(
841 "settings",
842 $lng->txt("settings"),
843 $this->ctrl->getLinkTarget($this, self::CMD_EDIT)
844 );
845 }
846
847 if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
848 $ilTabs->addTab(
849 'learning_progress',
850 $lng->txt('learning_progress'),
851 $this->ctrl->getLinkTargetByClass(array(__CLASS__, 'illearningprogressgui'), '')
852 );
853 }
854
855 // meta data
856 if ($this->checkPermissionBool("write")) {
857 $mdgui = new ilObjectMetaDataGUI($this->object);
858 $mdtab = $mdgui->getTab();
859 if ($mdtab) {
860 $ilTabs->addTab(
861 "id_meta",
862 $lng->txt("meta_data"),
863 $mdtab
864 );
865 }
866 }
867
868 // export
869 if ($this->checkPermissionBool("write")) {
870 $ilTabs->addTab(
871 "export",
872 $lng->txt("export"),
873 $this->ctrl->getLinkTargetByClass("ilexportgui", "")
874 );
875 }
876
877 // will add permission tab if needed
878 parent::setTabs();
879 }
880
881
882 public static function _goto($a_target, $a_additional = null)
883 {
884 global $DIC;
885 $ilErr = $DIC['ilErr'];
886 $lng = $DIC['lng'];
887 $ilAccess = $DIC['ilAccess'];
888
889 if ($a_additional && substr($a_additional, -3) == "wsp") {
890 $_GET["baseClass"] = "ilsharedresourceGUI";
891 $_GET["wsp_id"] = $a_target;
892 include("ilias.php");
893 exit;
894 }
895
896 // added support for direct download goto links
897 if ($a_additional && substr($a_additional, -8) == "download") {
898 ilObjectGUI::_gotoRepositoryNode($a_target, "sendfile");
899 }
900
901 // static method, no workspace support yet
902
903 if ($ilAccess->checkAccess("visible", "", $a_target)
904 || $ilAccess->checkAccess("read", "", $a_target)
905 ) {
906 ilObjectGUI::_gotoRepositoryNode($a_target, "infoScreen");
907 } else {
908 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
909 ilUtil::sendFailure(sprintf(
910 $lng->txt("msg_no_perm_read_item"),
912 ), true);
914 }
915 }
916
917 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
918 }
919
920
924 public function addLocatorItems()
925 {
926 global $DIC;
927 $ilLocator = $DIC['ilLocator'];
928
929 if (is_object($this->object)) {
930 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
931 }
932 }
933
934
940 public function initMultiUploadForm()
941 {
942 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
943 $dnd_form_gui = new ilPropertyFormGUI();
944 $dnd_form_gui->setMultipart(true);
945 $dnd_form_gui->setHideLabels();
946
947 // file input
948 include_once("Services/Form/classes/class.ilDragDropFileInputGUI.php");
949 $dnd_input = new ilDragDropFileInputGUI($this->lng->txt("files"), "upload_files");
950 $dnd_input->setArchiveSuffixes(array("zip"));
951 $dnd_input->setCommandButtonNames("uploadFiles", "cancel");
952 $dnd_form_gui->addItem($dnd_input);
953
954 // add commands
955 $dnd_form_gui->addCommandButton("uploadFiles", $this->lng->txt("upload_files"));
956 $dnd_form_gui->addCommandButton("cancel", $this->lng->txt("cancel"));
957
958 $dnd_form_gui->setTableWidth("100%");
959 $dnd_form_gui->setTarget($this->getTargetFrame("save"));
960 $dnd_form_gui->setTitle($this->lng->txt("upload_files_title"));
961 $dnd_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $this->lng->txt('obj_file'));
962
963 $this->ctrl->setParameter($this, "new_type", "file");
964 $dnd_form_gui->setFormAction($this->ctrl->getFormAction($this, "uploadFiles"));
965
966 return $dnd_form_gui;
967 }
968
969
973 public function uploadFiles()
974 {
975 global $DIC;
976
977 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
978
979 $response = new stdClass();
980 $response->error = null;
981 $response->debug = null;
982
983 $files = $_FILES;
984
985 // #14249 - race conditions because of concurrent uploads
986 $after_creation_callback = (int) $_REQUEST["crtcb"];
987 if ($after_creation_callback) {
988 $this->after_creation_callback_objects = array();
989 unset($_REQUEST["crtcb"]);
990 }
991
992 // load form
993 $dnd_form_gui = $this->initMultiUploadForm();
994 if ($dnd_form_gui->checkInput()) {
995 try {
996 if (!$this->checkPermissionBool("create", "", "file")) {
997 $response->error = $this->lng->txt("permission_denied");
998 } else {
999 // handle the file
1000 $inp = $dnd_form_gui->getInput("upload_files");
1001 $this->log->debug("ilObjFileGUI::uploadFiles " . print_r($_POST, true));
1002 $this->log->debug("ilObjFileGUI::uploadFiles " . print_r($_FILES, true));
1003 $fileresult = $this->handleFileUpload($inp);
1004 if ($fileresult) {
1005 $response = (object) array_merge((array) $response, (array) $fileresult);
1006 }
1007 }
1008 } catch (Exception $ex) {
1009 $response->error = $this->lng->txt('general_upload_error_occured');
1010 }
1011 } else {
1012 $dnd_input = $dnd_form_gui->getItemByPostVar("upload_files");
1013 $response->error = $dnd_input->getAlert();
1014 }
1015
1016 if ($after_creation_callback
1017 && sizeof($this->after_creation_callback_objects)
1018 ) {
1019 foreach ($this->after_creation_callback_objects as $new_file_obj) {
1020 ilObject2GUI::handleAfterSaveCallback($new_file_obj, $after_creation_callback);
1021 }
1022 unset($this->after_creation_callback_objects);
1023 }
1024
1025 // send response object (don't use 'application/json' as IE wants to download it!)
1026 header('Vary: Accept');
1027 header('Content-type: text/plain');
1028
1029 if ($DIC->upload()->hasBeenProcessed()) {
1030 foreach ($DIC->upload()->getResults() as $result) {
1031 if (!ilFileUtils::hasValidExtension($result->getName())) {
1033 $this->lng->txt('file_upload_info_file_with_critical_extension'),
1034 true
1035 );
1036 }
1037 }
1038 }
1039 echo json_encode($response);
1040 // no further processing!
1041 exit;
1042 }
1043
1044
1052 protected function handleFileUpload($file_upload)
1053 {
1054 global $DIC;
1055 $ilUser = $DIC['ilUser'];
1056
1057 if ($DIC->upload()->hasBeenProcessed() !== true) {
1058 if (PATH_TO_GHOSTSCRIPT !== "") {
1059 $DIC->upload()->register(new ilCountPDFPagesPreProcessors());
1060 }
1061 }
1062
1063 $DIC->upload()->process();
1067 $item = reset($DIC->upload()->getResults());
1068
1069 // file upload params
1070
1071 $file_upload['name'] = $item->getName();
1072
1073 $filename = ilUtil::stripSlashes($item->getName());
1074 $type = ilUtil::stripSlashes($item->getMimeType());
1075 $size = ilUtil::stripSlashes($item->getSize());
1076 $temp_name = $item->getPath(); // currently used
1077
1078 // additional params
1079 $title = ilUtil::stripSlashes($file_upload["title"]);
1080 $description = ilUtil::stripSlashes($file_upload["description"]);
1081 $extract = ilUtil::stripSlashes($file_upload["extract"]);
1082 $keep_structure = ilUtil::stripSlashes($file_upload["keep_structure"]);
1083
1084 // create answer object
1085 $response = new stdClass();
1086 $response->fileName = $filename;
1087 $response->fileSize = intval($size);
1088 $response->fileType = $type;
1089 $response->fileUnzipped = $extract;
1090 $response->error = null;
1091
1092 // extract archive?
1093 if ($extract) {
1094 $zip_file = $filename;
1095 $adopt_structure = $keep_structure;
1096
1097 include_once("Services/Utilities/classes/class.ilFileUtils.php");
1098
1099 // Create unzip-directory
1100 $newDir = ilUtil::ilTempnam();
1101 ilUtil::makeDir($newDir);
1102
1103 // Check if permission is granted for creation of object, if necessary
1104 if ($this->id_type != self::WORKSPACE_NODE_ID) {
1105 $type = ilObject::_lookupType((int) $this->parent_id, true);
1106 } else {
1107 $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
1108 }
1109
1110 $tree = $access_handler = null;
1111 switch ($type) {
1112 // workspace structure
1113 case 'wfld':
1114 case 'wsrt':
1115 $permission = $this->checkPermissionBool("create", "", "wfld");
1116 $containerType = "WorkspaceFolder";
1119 break;
1120
1121 // use categories as structure
1122 case 'cat':
1123 case 'root':
1124 $permission = $this->checkPermissionBool("create", "", "cat");
1125 $containerType = "Category";
1126 break;
1127
1128 // use folders as structure (in courses)
1129 default:
1130 $permission = $this->checkPermissionBool("create", "", "fold");
1131 $containerType = "Folder";
1132 break;
1133 }
1134
1135 try {
1136 // processZipFile (
1137 // Dir to unzip,
1138 // Path to uploaded file,
1139 // should a structure be created (+ permission check)?
1140 // ref_id of parent
1141 // object that contains files (folder or category)
1142 // should sendInfo be persistent?)
1144 $newDir,
1145 $temp_name,
1146 ($adopt_structure && $permission),
1147 $this->parent_id,
1148 $containerType,
1149 $tree,
1151 );
1152 } catch (ilFileUtilsException $e) {
1153 $response->error = $e->getMessage();
1154 } catch (Exception $ex) {
1155 $response->error = $this->lng->txt('general_upload_error_occured');
1156 }
1157
1158 ilUtil::delDir($newDir);
1159
1160 // #15404
1161 if ($this->id_type != self::WORKSPACE_NODE_ID) {
1162 foreach (ilFileUtils::getNewObjects() as $parent_ref_id => $objects) {
1163 if ($parent_ref_id != $this->parent_id) {
1164 continue;
1165 }
1166
1167 foreach ($objects as $object) {
1168 $this->after_creation_callback_objects[] = $object;
1169 }
1170 }
1171 }
1172 } else {
1173 // create and insert file in grp_tree
1174 $fileObj = new ilObjFile();
1175 // bugfix mantis 0026043
1176 if (strlen(trim($title)) == 0) {
1177 $title = $filename;
1178 } else {
1179 $title = $fileObj->checkFileExtension($filename, $title);
1180 }
1181 $fileObj->setTitle($title);
1182 $fileObj->setDescription($description);
1183 $fileObj->setFileName($filename);
1184 $fileObj->setFileType($type);
1185 $fileObj->setFileSize($size);
1186 $this->object_id = $fileObj->create();
1187 $this->putObjectInTree($fileObj, $this->parent_id);
1188
1189 // see uploadFiles()
1190 if (is_array($this->after_creation_callback_objects)) {
1191 $this->after_creation_callback_objects[] = $fileObj;
1192 }
1193
1194 // upload file to filesystem
1195 $fileObj->createDirectory();
1196 $fileObj->raiseUploadError(true);
1197
1198 $result = $fileObj->getUploadFile($temp_name, $filename);
1199
1200 if ($result) {
1201 //if no title for the file was set use the filename as title
1202 if (empty($fileObj->getTitle())) {
1203 $fileObj->setTitle($filename);
1204 }
1205 $fileObj->setFileName($filename);
1206 }
1207 $fileObj->update();
1208 $this->handleAutoRating($fileObj);
1209
1210 ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
1211 }
1212
1213 return $response;
1214 }
1215
1216
1217 protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
1218 {
1219 $lg = parent::initHeaderAction($a_sub_type, $a_sub_id);
1220 if (is_object($lg)) {
1221 if ($this->object->hasRating()) {
1222 $lg->enableRating(
1223 true,
1224 null,
1225 false,
1226 array("ilcommonactiondispatchergui", "ilratinggui")
1227 );
1228 }
1229 }
1230
1231 return $lg;
1232 }
1233}
$result
$size
Definition: RandomTest.php:84
exit
Definition: backend.php:16
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static _recordReadEvent( $a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents=true, $a_ext_rc=false, $a_ext_time=false)
Records a read event and catches up with write events.
static _catchupWriteEvents($obj_id, $usr_id, $timestamp=null)
Catches up with all write events which occured before the specified timestamp.
static _recordWriteEvent($obj_id, $usr_id, $action, $parent_obj_id=null)
Records a write event.
This class represents a checkbox property in a property form.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Class ilCountPDFPagesPreProcessors.
static isUploadPossible($a_additional_size=null)
This class represents a file input property where multiple files can be dopped in a property form.
Class ilECSFileSettings.
Export User Interface Class.
This class represents a file property in a property form.
static setPersonalWorkspaceQuotaCheck($a_value)
Class ilFileStandardDropzoneInputGUI.
static isDragAndDropUploadEnabled()
Gets whether drag and drop file upload is enabled.
Class to report exception.
static hasValidExtension($a_filename)
static processZipFile($a_directory, $a_file, $structure, $ref_id=null, $containerType=null, $tree=null, $access_handler=null)
unzips in given directory and processes uploaded zip for use as single files
static getNewObjects()
Class ilFileVersionsGUI.
Class ilInfoScreenGUI.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static checkAccess($a_ref_id, $a_allow_only_read=true)
check access to learning progress
Class ilObjUserTrackingGUI.
static getInstance()
Factory.
static getLogger($a_component_id)
Get component logger.
static getMimeType($a_file='', $a_filename='', $a_mime='')
This class represents a non editable value in a property form.
static _getFileExtension($a_file_name)
Gets the file extension of the specified file name.
static _getPermanentDownloadLink($ref_id)
Gets the permanent download link for the file.
GUI class for file objects.
update()
updates object entry in object_data
uploadFiles()
Called after a file was uploaded.
initCreationForms($a_new_type)
saveAndMeta()
save object
infoScreen()
this one is called from the info button in the repository not very nice to set cmdClass/Cmd manually,...
executeCommand()
execute command
getType()
Functions that must be overwritten.
initHeaderAction($a_sub_type=null, $a_sub_id=null)
Add header action menu.
initSingleUploadForm()
FORM: Init single upload form.
initMultiUploadForm()
Initializes the upload form for multiple files.
saveUnzip()
saveUnzip object
initPropertiesForm($mode="create")
static _goto($a_target, $a_additional=null)
infoScreenForward()
show information screen
edit()
edit object
save()
save object
addLocatorItems()
Functions to be overwritten.
initZipUploadForm($a_mode="create")
FORM: Init zip upload form.
setTabs()
create tabs (repository/workspace switch)
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
Constructor.
Class ilObjFile.
static _lookupFileSize($a_id)
Lookups the file size of the file in bytes.
New implementation of ilObjectGUI.
handleAutoRating(ilObject $a_new_obj)
fillCloneTemplate($a_tpl_varname, $a_type)
Fill object clone template This method can be called from any object GUI class that wants to offer ob...
getAccessHandler()
Get access handler.
prepareOutput($a_show_subobjects=true)
prepare output
getTargetFrame($a_cmd, $a_target_frame="")
get target frame for command (command is method name without "Object", e.g.
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_node_id=null)
Check permission.
static handleAfterSaveCallback(ilObject $a_obj, $a_callback_ref_id)
After creation callback.
getCreationMode()
get creation mode
putObjectInTree(ilObject $a_obj, $a_parent_node_id=null)
Add object to tree at given position.
GUI class for the workflow of copying objects.
initImportForm($a_new_type)
Init object import form.
static _gotoRepositoryNode($a_ref_id, $a_cmd="frameset")
Goto repository root.
static _gotoRepositoryRoot($a_raise_error=false)
Goto repository root.
addHeaderAction()
Add header action menu.
Class ilObjectMetaDataGUI.
static _lookupObjId($a_id)
const TITLE_LENGTH
max length of object title
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static hasPreview($a_obj_id, $a_type="")
Determines whether the object with the specified reference id has a preview.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static formatSize($size, $a_mode='short', $a_lng=null)
Returns the specified file size value in a human friendly form.
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
$lg
Definition: example_018.php:62
global $ilCtrl
Definition: ilias.php:18
$info
Definition: index.php:5
$target
Definition: test.php:19
$files
Definition: metarefresh.php:49
Class FlySystemFileAccessTest.
Class BaseForm.
$ret
Definition: parser.php:6
$type
$response
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$preview
$ilUser
Definition: imgupload.php:18
$context
Definition: webdav.php:25