ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
5
20{
21 use ilObjFileSecureString;
22 const CMD_EDIT = "edit";
23 const CMD_VERSIONS = "versions";
27 public $object;
28 public $lng;
29 protected $log = null;
30 protected $obj_service;
31
32
40 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
41 {
42 global $DIC;
43 $this->lng = $DIC->language();
44 $this->log = ilLoggerFactory::getLogger('file');
45 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
46 $this->obj_service = $DIC->object();
47 $this->lng->loadLanguageModule("file");
48 }
49
50
51 public function getType()
52 {
53 return "file";
54 }
55
56
57 public function executeCommand()
58 {
59 global $DIC;
60 $ilNavigationHistory = $DIC['ilNavigationHistory'];
61 $ilCtrl = $DIC['ilCtrl'];
62 $ilUser = $DIC['ilUser'];
63 $ilTabs = $DIC['ilTabs'];
64 $ilAccess = $DIC['ilAccess'];
65 $ilErr = $DIC['ilErr'];
66
67 $next_class = $this->ctrl->getNextClass($this);
68 $cmd = $this->ctrl->getCmd();
69
70 if ($this->id_type == self::WORKSPACE_NODE_ID) {
72 }
73
74 if (!$this->getCreationMode()) {
75 if ($this->id_type == self::REPOSITORY_NODE_ID
76 && $this->checkPermissionBool("read")
77 ) {
78 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->node_id);
79 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "infoScreen");
80 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
81
82 // add entry to navigation history
83 $ilNavigationHistory->addItem(
84 $this->node_id,
85 $link,
86 "file"
87 );
88 }
89 }
90
91 $this->prepareOutput();
92
93 switch ($next_class) {
94 case "ilinfoscreengui":
95 $this->infoScreenForward(); // forwards command
96 break;
97
98 case 'ilobjectmetadatagui':
99 if (!$this->checkPermissionBool("write")) {
100 $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->WARNING);
101 }
102
103 $ilTabs->activateTab("id_meta");
104
105 $md_gui = new ilObjectMetaDataGUI($this->object);
106
107 // todo: make this work
108 // $md_gui->addMDObserver($this->object,'MDUpdateListener','Technical');
109
110 $this->ctrl->forwardCommand($md_gui);
111 break;
112
113 // repository permissions
114 case 'ilpermissiongui':
115 $ilTabs->activateTab("id_permissions");
116 $perm_gui = new ilPermissionGUI($this);
117 $ret = $this->ctrl->forwardCommand($perm_gui);
118 break;
119
120 case "ilexportgui":
121 $ilTabs->activateTab("export");
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 $cp = new ilObjectCopyGUI($this);
129 $cp->setType('file');
130 $this->ctrl->forwardCommand($cp);
131 break;
132
133 // personal workspace permissions
134 case "ilworkspaceaccessgui":
135 $ilTabs->activateTab("id_permissions");
136 $wspacc = new ilWorkspaceAccessGUI($this->node_id, $this->getAccessHandler());
137 $this->ctrl->forwardCommand($wspacc);
138 break;
139
140 case "ilcommonactiondispatchergui":
142 $this->ctrl->forwardCommand($gui);
143 break;
144
145 case "illearningprogressgui":
146 $ilTabs->activateTab('learning_progress');
147 $new_gui = new ilLearningProgressGUI(
149 $this->object->getRefId(),
150 $_GET['user_id'] ? $_GET['user_id'] : $ilUser->getId()
151 );
152 $this->ctrl->forwardCommand($new_gui);
153 $this->tabs_gui->setTabActive('learning_progress');
154 break;
155 case strtolower(ilFileVersionsGUI::class):
156 $this->tabs_gui->activateTab("id_versions");
157
158 if (!$this->checkPermissionBool("write")) {
159 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
160 }
161 $this->ctrl->forwardCommand(new ilFileVersionsGUI($this->object));
162 break;
163 default:
164 // in personal workspace use object2gui
165 if ($this->id_type == self::WORKSPACE_NODE_ID) {
166 $this->addHeaderAction();
167
168 // coming from goto we need default command
169 if (empty($cmd)) {
170 $ilCtrl->setCmd("infoScreen");
171 }
172 $ilTabs->clearTargets();
173
174 return parent::executeCommand();
175 }
176
177 if (empty($cmd)) {
178 $cmd = "infoScreen";
179 }
180
181 $this->$cmd();
182 break;
183 }
184
185 $this->addHeaderAction();
186 }
187
188
192 protected function initCreationForms($a_new_type)
193 {
194 $forms = array();
195
196 if ($this->id_type == self::WORKSPACE_NODE_ID) {
198 ilUtil::sendFailure($this->lng->txt("personal_resources_quota_exceeded_warning"), true);
199 $this->ctrl->redirect($this, "cancel");
200 }
201 }
202
203 // use drag-and-drop upload if configured
205 $forms[] = $this->initMultiUploadForm();
206 } else {
207 $forms[] = $this->initSingleUploadForm();
208 $forms[] = $this->initZipUploadForm();
209 }
210
211 // repository only
212 if ($this->id_type != self::WORKSPACE_NODE_ID) {
213 $forms[self::CFORM_IMPORT] = $this->initImportForm('file');
214 $forms[self::CFORM_CLONE] = $this->fillCloneTemplate(null, "file");
215 }
216
217 return $forms;
218 }
219
220
224 public function initSingleUploadForm()
225 {
226 global $DIC;
227 $lng = $DIC['lng'];
228
229 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
230 $single_form_gui = new ilPropertyFormGUI();
231 $single_form_gui->setMultipart(true);
232
233 // File Title
234 $in_title = new ilTextInputGUI($lng->txt("title"), "title");
235 $in_title->setInfo($this->lng->txt("if_no_title_then_filename"));
236 $in_title->setSize(min(40, ilObject::TITLE_LENGTH));
237 $in_title->setMaxLength(ilObject::TITLE_LENGTH);
238 $single_form_gui->addItem($in_title);
239
240 // File Description
241 $in_descr = new ilTextAreaInputGUI($lng->txt("description"), "description");
242 $single_form_gui->addItem($in_descr);
243
244 // File
245 $in_file = new ilFileInputGUI($lng->txt("file"), "upload_file");
246 $in_file->setRequired(true);
247 $single_form_gui->addItem($in_file);
248
249 $single_form_gui->addCommandButton("save", $this->lng->txt($this->type . "_add"));
250 $single_form_gui->addCommandButton("saveAndMeta", $this->lng->txt("file_add_and_metadata"));
251 $single_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
252
253 $single_form_gui->setTableWidth("600px");
254 $single_form_gui->setTarget($this->getTargetFrame("save"));
255 $single_form_gui->setTitle($this->lng->txt($this->type . "_new"));
256 $single_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.svg'), $this->lng->txt('obj_file'));
257
258 $this->ctrl->setParameter($this, "new_type", "file");
259
260 $single_form_gui->setFormAction($this->ctrl->getFormAction($this, "save"));
261
262 return $single_form_gui;
263 }
264
265
271 public function save()
272 {
273 global $DIC;
274 $ilUser = $DIC->user();
275
276 if (!$this->checkPermissionBool("create", "", "file")) {
277 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
278 }
279
280 $single_form_gui = $this->initSingleUploadForm();
281
282 if ($single_form_gui->checkInput()) {
283 $title = $single_form_gui->getInput("title");
284 $description = $single_form_gui->getInput("description");
285 $upload_file = $single_form_gui->getInput("upload_file");
286
287 if (trim($title) == "") {
288 $title = $upload_file["name"];
289 } else {
290 // BEGIN WebDAV: Ensure that object title ends with the filename extension
291 $fileExtension = ilObjFileAccess::_getFileExtension($upload_file["name"]);
292 $titleExtension = ilObjFileAccess::_getFileExtension($title);
293 if ($titleExtension != $fileExtension && strlen($fileExtension) > 0) {
294 $title .= '.' . $fileExtension;
295 }
296 // END WebDAV: Ensure that object title ends with the filename extension
297 }
298
299 // create and insert file in grp_tree
300
301 $fileObj = new ilObjFile();
302 $fileObj->setTitle($title);
303 $fileObj->setDescription($description);
304 $fileObj->setFileName($upload_file["name"]);
305
306 $fileObj->setFileType(ilMimeTypeUtil::getMimeType(
307 "",
308 $upload_file["name"],
309 $upload_file["type"]
310 ));
311 $fileObj->setFileSize($upload_file["size"]);
312 $this->object_id = $fileObj->create();
313
314 $this->putObjectInTree($fileObj, $this->parent_id);
315
316 // upload file to filesystem
317 $fileObj->createDirectory();
318 if ($result = $fileObj->getUploadFile($upload_file["tmp_name"], $upload_file["name"])) {
319 $fileObj->setFileName($result->getName());
320 }
321
322 $this->handleAutoRating($fileObj);
323
324 // BEGIN ChangeEvent: Record write event.
325 ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
326 // END ChangeEvent: Record write event.
327
328 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
329
330 if ($this->ctrl->getCmd() == "saveAndMeta") {
331 $this->ctrl->setParameter($this, "new_type", "");
332 $target = $this->ctrl->getLinkTargetByClass(array("ilobjectmetadatagui", "ilmdeditorgui"), "listSection", "", false, false);
333 ilUtil::redirect($target);
334 } else {
335 $this->ctrl->returnToParent($this);
336 }
337 } else {
338 $single_form_gui->setValuesByPost();
339 $this->tpl->setContent($single_form_gui->getHTML());
340 }
341 }
342
343
349 public function saveAndMeta()
350 {
351 $this->save();
352 }
353
354
358 public function initZipUploadForm($a_mode = "create")
359 {
360 global $DIC;
361 $lng = $DIC['lng'];
362
363 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
364 $zip_form_gui = new ilPropertyFormGUI();
365 $zip_form_gui->setMultipart(true);
366
367 // File
368 $in_file = new ilFileInputGUI($lng->txt("file"), "zip_file");
369 $in_file->setRequired(true);
370 $in_file->setSuffixes(array("zip"));
371 $zip_form_gui->addItem($in_file);
372
373 // Take over structure
374 $in_str = new ilCheckboxInputGUI($this->lng->txt("take_over_structure"), "adopt_structure");
375 $in_str->setInfo($this->lng->txt("take_over_structure_info"));
376 $zip_form_gui->addItem($in_str);
377
378 $zip_form_gui->addCommandButton("saveUnzip", $this->lng->txt($this->type . "_add"));
379 $zip_form_gui->addCommandButton("cancel", $lng->txt("cancel"));
380
381 $zip_form_gui->setTableWidth("600px");
382 $zip_form_gui->setTarget($this->getTargetFrame("save"));
383 $zip_form_gui->setTitle($this->lng->txt("header_zip"));
384 $zip_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.svg'), $this->lng->txt('obj_file'));
385
386 $this->ctrl->setParameter($this, "new_type", "file");
387
388 $zip_form_gui->setFormAction($this->ctrl->getFormAction($this, "saveUnzip"));
389
390 return $zip_form_gui;
391 }
392
393
399 public function saveUnzip()
400 {
401 $zip_form_gui = $this->initZipUploadForm();
402
403 if ($this->checkPermissionBool("create", "", "file")) {
404 if ($zip_form_gui->checkInput()) {
405 $zip_file = $zip_form_gui->getInput("zip_file");
406 $adopt_structure = $zip_form_gui->getInput("adopt_structure");
407
408 include_once("Services/Utilities/classes/class.ilFileUtils.php");
409
410 // Create unzip-directory
411 $newDir = ilUtil::ilTempnam();
412 ilUtil::makeDir($newDir);
413
414 // Check if permission is granted for creation of object, if necessary
415 if ($this->id_type != self::WORKSPACE_NODE_ID) {
416 $type = ilObject::_lookupType((int) $this->parent_id, true);
417 } else {
418 $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
419 }
420
421 $tree = $access_handler = null;
422 switch ($type) {
423 // workspace structure
424 case 'wfld':
425 case 'wsrt':
426 $permission = $this->checkPermissionBool("create", "", "wfld");
427 $containerType = "WorkspaceFolder";
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 $processDone = ilFileUtils::processZipFile(
454 $newDir,
455 $zip_file["tmp_name"],
456 ($adopt_structure && $permission),
457 $this->parent_id,
458 $containerType,
459 $tree,
461 );
462 ilUtil::sendSuccess($this->lng->txt("file_added"), true);
463 } catch (ilFileUtilsException $e) {
464 ilUtil::sendFailure($e->getMessage(), true);
465 }
466
467 ilUtil::delDir($newDir);
468 $this->ctrl->returnToParent($this);
469 } else {
470 $zip_form_gui->setValuesByPost();
471 $this->tpl->setContent($zip_form_gui->getHTML());
472 }
473 } else {
474 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
475 }
476 }
477
478
484 public function update()
485 {
486 global $DIC;
487 $ilTabs = $DIC['ilTabs'];
488
489 $form = $this->initPropertiesForm();
490 if (!$form->checkInput()) {
491 $ilTabs->activateTab("settings");
492 $form->setValuesByPost();
493 $this->tpl->setContent($form->getHTML());
494
495 return false;
496 }
497
498 $title = $form->getInput('title');
499 // bugfix mantis 26045:
500 $filename = empty($data["name"]) ? $this->object->getFileName() : $data["name"];
501 if (strlen(trim($title)) == 0) {
502 $title = $filename;
503 } else {
504 $title = $this->object->checkFileExtension($filename, $title);
505 }
506 $this->object->setTitle($title);
507 $this->object->setDescription($form->getInput('description'));
508 $this->object->setRating($form->getInput('rating'));
509
510 $this->update = $this->object->update();
511 $this->obj_service->commonSettings()->legacyForm($form, $this->object)->saveTileImage();
512
513 // BEGIN ChangeEvent: Record update event.
514 if (!empty($data["name"])) {
515 global $DIC;
516 $ilUser = $DIC['ilUser'];
517 ilChangeEvent::_recordWriteEvent($this->object->getId(), $ilUser->getId(), 'update');
518 ilChangeEvent::_catchupWriteEvents($this->object->getId(), $ilUser->getId());
519 }
520 // END ChangeEvent: Record update event.
521
522 // Update ecs export settings
523 $ecs = new ilECSFileSettings($this->object);
524 $ecs->handleSettingsUpdate();
525
526 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
527 ilUtil::redirect($this->ctrl->getLinkTarget($this, self::CMD_EDIT, '', false, false));
528 }
529
530
536 public function edit()
537 {
538 global $DIC;
539 $ilTabs = $DIC['ilTabs'];
540 $ilErr = $DIC['ilErr'];
541
542 if (!$this->checkPermissionBool("write")) {
543 $ilErr->raiseError($this->lng->txt("msg_no_perm_write"));
544 }
545
546 $ilTabs->activateTab("settings");
547
548 $form = $this->initPropertiesForm(self::CMD_EDIT);
549
550 $val = array();
551 $val['title'] = $this->object->getTitle();
552 $val['description'] = $this->object->getLongDescription();
553 $val['rating'] = $this->object->hasRating();
554 $form->setValuesByArray($val);
555
556 // Edit ecs export settings
557 include_once 'Modules/File/classes/class.ilECSFileSettings.php';
558 $ecs = new ilECSFileSettings($this->object);
559 $ecs->addSettingsToForm($form, 'file');
560
561 $this->tpl->setContent($form->getHTML());
562
563 return true;
564 }
565
566
573 protected function initPropertiesForm($mode = "create")
574 {
575 $form = new ilPropertyFormGUI();
576 $form->setFormAction($this->ctrl->getFormAction($this, 'update'));
577
578 $form->setTitle($this->lng->txt('file_edit'));
579 $form->addCommandButton('update', $this->lng->txt('save'));
580 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
581
582 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
583 $title->setValue($this->object->getTitle());
584 $title->setInfo($this->lng->txt("if_no_title_then_filename"));
585 $form->addItem($title);
586
587 if ($mode === 'create') {
588 $upload_possible = true;
589 if ($this->id_type == self::WORKSPACE_NODE_ID) {
590 $upload_possible = ilDiskQuotaHandler::isUploadPossible();
591 }
592
593 if ($upload_possible) {
595 'cancel',
596 $this->lng->txt('obj_file'),
597 'file'
598 );
599 $file->setRequired(false);
600 $form->addItem($file);
601
602 $group = new ilRadioGroupInputGUI('', 'replace');
603 $group->setValue(0);
604
605 $replace = new ilRadioOption($this->lng->txt('replace_file'), 1);
606 $replace->setInfo($this->lng->txt('replace_file_info'));
607 $group->addOption($replace);
608
609 $keep = new ilRadioOption($this->lng->txt('file_new_version'), 0);
610 $keep->setInfo($this->lng->txt('file_new_version_info'));
611 $group->addOption($keep);
612
613 $file->addSubItem($group);
614 } elseif ($mode == 'create') {
615 $file = new ilNonEditableValueGUI($this->lng->txt('obj_file'));
616 $file->setValue($this->lng->txt("personal_resources_quota_exceeded_warning"));
617 $form->addItem($file);
618 }
619 } else {
620 $o = new ilNonEditableValueGUI($this->lng->txt('upload_info'));
621 $o->setValue($this->lng->txt('upload_info_desc'));
622 $form->addItem($o);
623 }
624 $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'description');
625 $desc->setRows(3);
626 $form->addItem($desc);
627
628 if ($this->id_type == self::REPOSITORY_NODE_ID) {
629 $this->lng->loadLanguageModule('rating');
630 $rate = new ilCheckboxInputGUI($this->lng->txt('rating_activate_rating'), 'rating');
631 $rate->setInfo($this->lng->txt('rating_activate_rating_info'));
632 $form->addItem($rate);
633 }
634
635 $presentationHeader = new ilFormSectionHeaderGUI();
636 $presentationHeader->setTitle($this->lng->txt('settings_presentation_header'));
637 $form->addItem($presentationHeader);
638 $this->obj_service->commonSettings()->legacyForm($form, $this->object)->addTileImage();
639
640 return $form;
641 }
642
643
644 public function sendFile()
645 {
646 global $DIC;
647
648 try {
649 if (ANONYMOUS_USER_ID == $DIC->user()->getId() && isset($_GET['transaction'])) {
650 $a_hist_entry_id = isset($_GET["hist_id"]) ? $_GET["hist_id"] : null;
651 $this->object->sendFile($a_hist_entry_id);
652 }
653
654 if ($this->checkPermissionBool("read")) {
655 // BEGIN ChangeEvent: Record read event.
656 require_once('Services/Tracking/classes/class.ilChangeEvent.php');
657
658 // Record read event and catchup with write events
660 $this->object->getType(),
661 $this->object->getRefId(),
662 $this->object->getId(),
663 $DIC->user()->getId()
664 );
665 // END ChangeEvent: Record read event.
666
667 require_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
668 ilLPStatusWrapper::_updateStatus($this->object->getId(), $DIC->user()->getId());
669
670 $a_hist_entry_id = isset($_GET["hist_id"]) ? $_GET["hist_id"] : null;
671 $this->object->sendFile($a_hist_entry_id);
672 } else {
673 $this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
674 }
675 } catch (\ILIAS\Filesystem\Exception\FileNotFoundException $e) {
676 $this->ilErr->raiseError($e->getMessage(), $this->ilErr->MESSAGE);
677 }
678
679 return true;
680 }
681
682
686 public function versions()
687 {
688 $this->ctrl->redirectByClass(ilFileVersionsGUI::class);
689 }
690
691
697 public function infoScreen()
698 {
699 $this->ctrl->setCmd("showSummary");
700 $this->ctrl->setCmdClass("ilinfoscreengui");
701 $this->infoScreenForward();
702 }
703
704
708 public function infoScreenForward()
709 {
710 global $DIC;
711 $ilTabs = $DIC['ilTabs'];
712 $ilErr = $DIC['ilErr'];
713 $ilToolbar = $DIC['ilToolbar'];
714
715 $ilTabs->activateTab("id_info");
716
717 if (!$this->checkPermissionBool("visible") && !$this->checkPermissionBool("read")) {
718 $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
719 }
720
721 include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
722 $info = new ilInfoScreenGUI($this);
723
724 if ($this->checkPermissionBool("read", "sendfile")) {
725 // #14378
726 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
727 $button = ilLinkButton::getInstance();
728 $button->setCaption("file_download");
729 $button->setPrimary(true);
730
731 // get permanent download link for repository
732 if ($this->id_type == self::REPOSITORY_NODE_ID) {
733 $button->setUrl(ilObjFileAccess::_getPermanentDownloadLink($this->node_id));
734 } else {
735 $button->setUrl($this->ctrl->getLinkTarget($this, "sendfile"));
736 }
737
738 $ilToolbar->addButtonInstance($button);
739 }
740
741 $info->enablePrivateNotes();
742
743 if ($this->checkPermissionBool("read")) {
744 $info->enableNews();
745 }
746
747 // no news editing for files, just notifications
748 $info->enableNewsEditing(false);
749 if ($this->checkPermissionBool("write")) {
750 $news_set = new ilSetting("news");
751 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
752
753 if ($enable_internal_rss) {
754 $info->setBlockProperty("news", "settings", true);
755 $info->setBlockProperty("news", "public_notifications_option", true);
756 }
757 }
758
759 // standard meta data
760 $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
761
762 // File Info
763 $info->addSection($this->lng->txt("file_info"));
764 $info->addProperty($this->lng->txt("filename"), $this->secure($this->object->getFileName()));
765 $info->addProperty($this->lng->txt("type"), $this->object->guessFileType());
766
767 $info->addProperty($this->lng->txt("size"), ilUtil::formatSize(ilObjFile::_lookupFileSize($this->object->getId()), 'long'));
768 $info->addProperty($this->lng->txt("version"), $this->object->getVersion());
769
770 if ($this->object->getPageCount() > 0) {
771 $info->addProperty($this->lng->txt("page_count"), $this->object->getPageCount());
772 }
773
774 // using getVersions function instead of ilHistory direct
775 $uploader = $this->object->getVersions();
776 $uploader = array_shift($uploader);
777 $uploader = $uploader["user_id"];
778
779 include_once "Services/User/classes/class.ilUserUtil.php";
780 $info->addProperty($this->lng->txt("file_uploaded_by"), ilUserUtil::getNamePresentation($uploader));
781
782 // download link added in repository
783 if ($this->id_type == self::REPOSITORY_NODE_ID && $this->checkPermissionBool("read", "sendfile")) {
784 $tpl = new ilTemplate("tpl.download_link.html", true, true, "Modules/File");
785 $tpl->setVariable("LINK", ilObjFileAccess::_getPermanentDownloadLink($this->node_id));
786 $info->addProperty($this->lng->txt("download_link"), $tpl->get());
787 }
788
789 if ($this->id_type == self::WORKSPACE_NODE_ID) {
790 $info->addProperty($this->lng->txt("perma_link"), $this->getPermanentLinkWidget());
791 }
792
793 // display previews
794 include_once("./Services/Preview/classes/class.ilPreview.php");
795 if (!$this->ctrl->isAsynch()
796 && ilPreview::hasPreview($this->object->getId(), $this->object->getType())
797 && $this->checkPermissionBool("read")
798 ) {
799 include_once("./Services/Preview/classes/class.ilPreviewGUI.php");
800
801 // get context for access checks later on
802 $context;
803 switch ($this->id_type) {
807 break;
808
809 default:
811 break;
812 }
813
814 $preview = new ilPreviewGUI($this->node_id, $context, $this->object->getId(), $this->access_handler);
815 $info->addProperty($this->lng->txt("preview"), $preview->getInlineHTML());
816 }
817
818 // forward the command
819 // $this->ctrl->setCmd("showSummary");
820 // $this->ctrl->setCmdClass("ilinfoscreengui");
821 $this->ctrl->forwardCommand($info);
822 }
823
824
825 // get tabs
826 public function setTabs()
827 {
828 global $DIC;
829 $ilTabs = $DIC['ilTabs'];
830 $lng = $DIC['lng'];
831 $ilHelp = $DIC['ilHelp'];
832
833 $ilHelp->setScreenIdComponent("file");
834
835 $this->ctrl->setParameter($this, "ref_id", $this->node_id);
836
837 if ($this->checkPermissionBool("write")) {
838 $ilTabs->addTab(
839 "id_versions",
840 $lng->txt(self::CMD_VERSIONS),
841 $this->ctrl->getLinkTargetByClass(ilFileVersionsGUI::class, ilFileVersionsGUI::CMD_DEFAULT)
842 );
843 }
844
845 if ($this->checkPermissionBool("visible") || $this->checkPermissionBool("read")) {
846 $ilTabs->addTab(
847 "id_info",
848 $lng->txt("info_short"),
849 $this->ctrl->getLinkTargetByClass(array("ilobjfilegui", "ilinfoscreengui"), "showSummary")
850 );
851 }
852
853 if ($this->checkPermissionBool("write")) {
854 $ilTabs->addTab(
855 "settings",
856 $lng->txt("settings"),
857 $this->ctrl->getLinkTarget($this, self::CMD_EDIT)
858 );
859 }
860
861 if (ilLearningProgressAccess::checkAccess($this->object->getRefId())) {
862 $ilTabs->addTab(
863 'learning_progress',
864 $lng->txt('learning_progress'),
865 $this->ctrl->getLinkTargetByClass(array(__CLASS__, 'illearningprogressgui'), '')
866 );
867 }
868
869 // meta data
870 if ($this->checkPermissionBool("write")) {
871 $mdgui = new ilObjectMetaDataGUI($this->object);
872 $mdtab = $mdgui->getTab();
873 if ($mdtab) {
874 $ilTabs->addTab(
875 "id_meta",
876 $lng->txt("meta_data"),
877 $mdtab
878 );
879 }
880 }
881
882 // export
883 if ($this->checkPermissionBool("write")) {
884 $ilTabs->addTab(
885 "export",
886 $lng->txt("export"),
887 $this->ctrl->getLinkTargetByClass("ilexportgui", "")
888 );
889 }
890
891 // will add permission tab if needed
892 parent::setTabs();
893 }
894
895
896 public static function _goto($a_target, $a_additional = null)
897 {
898 global $DIC;
899 $ilErr = $DIC['ilErr'];
900 $lng = $DIC['lng'];
901 $ilAccess = $DIC['ilAccess'];
902
903 if ($a_additional && substr($a_additional, -3) == "wsp") {
904 $_GET["baseClass"] = "ilsharedresourceGUI";
905 $_GET["wsp_id"] = $a_target;
906 include("ilias.php");
907 exit;
908 }
909
910 // added support for direct download goto links
911 if ($a_additional && substr($a_additional, -8) == "download") {
912 ilObjectGUI::_gotoRepositoryNode($a_target, "sendfile");
913 }
914
915 // static method, no workspace support yet
916
917 if ($ilAccess->checkAccess("visible", "", $a_target)
918 || $ilAccess->checkAccess("read", "", $a_target)
919 ) {
920 ilObjectGUI::_gotoRepositoryNode($a_target, "infoScreen");
921 } else {
922 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
923 ilUtil::sendFailure(sprintf(
924 $lng->txt("msg_no_perm_read_item"),
926 ), true);
928 }
929 }
930
931 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
932 }
933
934
938 public function addLocatorItems()
939 {
940 global $DIC;
941 $ilLocator = $DIC['ilLocator'];
942
943 if (is_object($this->object)) {
944 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $this->node_id);
945 }
946 }
947
948
954 public function initMultiUploadForm()
955 {
956 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
957 $dnd_form_gui = new ilPropertyFormGUI();
958 $dnd_form_gui->setMultipart(true);
959 $dnd_form_gui->setHideLabels();
960
961 // file input
962 include_once("Services/Form/classes/class.ilDragDropFileInputGUI.php");
963 $dnd_input = new ilDragDropFileInputGUI($this->lng->txt("files"), "upload_files");
964 $dnd_input->setArchiveSuffixes(array("zip"));
965 $dnd_input->setCommandButtonNames("uploadFiles", "cancel");
966 $dnd_form_gui->addItem($dnd_input);
967
968 // add commands
969 $dnd_form_gui->addCommandButton("uploadFiles", $this->lng->txt("upload_files"));
970 $dnd_form_gui->addCommandButton("cancel", $this->lng->txt("cancel"));
971
972 $dnd_form_gui->setTableWidth("100%");
973 $dnd_form_gui->setTarget($this->getTargetFrame("save"));
974 $dnd_form_gui->setTitle($this->lng->txt("upload_files_title"));
975 $dnd_form_gui->setTitleIcon(ilUtil::getImagePath('icon_file.gif'), $this->lng->txt('obj_file'));
976
977 $this->ctrl->setParameter($this, "new_type", "file");
978 $dnd_form_gui->setFormAction($this->ctrl->getFormAction($this, "uploadFiles"));
979
980 return $dnd_form_gui;
981 }
982
983
987 public function uploadFiles()
988 {
989 global $DIC;
990
991 include_once("./Services/JSON/classes/class.ilJsonUtil.php");
992
993 $response = new stdClass();
994 $response->error = null;
995 $response->debug = null;
996
997 $files = $_FILES;
998
999 // #14249 - race conditions because of concurrent uploads
1000 $after_creation_callback = (int) $_REQUEST["crtcb"];
1001 if ($after_creation_callback) {
1002 $this->after_creation_callback_objects = array();
1003 unset($_REQUEST["crtcb"]);
1004 }
1005
1006 // load form
1007 $dnd_form_gui = $this->initMultiUploadForm();
1008 if ($dnd_form_gui->checkInput()) {
1009 try {
1010 if (!$this->checkPermissionBool("create", "", "file")) {
1011 $response->error = $this->lng->txt("permission_denied");
1012 } else {
1013 // handle the file
1014 $inp = $dnd_form_gui->getInput("upload_files");
1015 $this->log->debug("ilObjFileGUI::uploadFiles " . print_r($_POST, true));
1016 $this->log->debug("ilObjFileGUI::uploadFiles " . print_r($_FILES, true));
1017 $fileresult = $this->handleFileUpload($inp);
1018 if ($fileresult) {
1019 $response = (object) array_merge((array) $response, (array) $fileresult);
1020 }
1021 }
1022 } catch (Exception $ex) {
1023 $response->error = $this->lng->txt('general_upload_error_occured');
1024 }
1025 } else {
1026 $dnd_input = $dnd_form_gui->getItemByPostVar("upload_files");
1027 $response->error = $dnd_input->getAlert();
1028 }
1029
1030 if ($after_creation_callback
1031 && sizeof($this->after_creation_callback_objects)
1032 ) {
1033 foreach ($this->after_creation_callback_objects as $new_file_obj) {
1034 ilObject2GUI::handleAfterSaveCallback($new_file_obj, $after_creation_callback);
1035 }
1036 unset($this->after_creation_callback_objects);
1037 }
1038
1039 // send response object (don't use 'application/json' as IE wants to download it!)
1040 header('Vary: Accept');
1041 header('Content-type: text/plain');
1042
1043 if ($DIC->upload()->hasBeenProcessed()) {
1044 foreach ($DIC->upload()->getResults() as $result) {
1045 if (!ilFileUtils::hasValidExtension($result->getName()) && $result->getStatus()->getCode() == ProcessingStatus::OK) {
1047 $this->lng->txt('file_upload_info_file_with_critical_extension'),
1048 true
1049 );
1050 }
1051 }
1052 }
1053 echo json_encode($response);
1054 // no further processing!
1055 exit;
1056 }
1057
1058
1066 protected function handleFileUpload($file_upload)
1067 {
1068 global $DIC;
1069 $ilUser = $DIC['ilUser'];
1070
1071 if ($DIC->upload()->hasBeenProcessed() !== true) {
1072 if (PATH_TO_GHOSTSCRIPT !== "") {
1073 $DIC->upload()->register(new ilCountPDFPagesPreProcessors());
1074 }
1075 }
1076
1077 $DIC->upload()->process();
1081 $item = reset($DIC->upload()->getResults());
1082
1083 // file upload params
1084
1085 $file_upload['name'] = $item->getName();
1086
1087 $filename = ilUtil::stripSlashes($item->getName());
1088 $type = ilUtil::stripSlashes($item->getMimeType());
1089 $size = ilUtil::stripSlashes($item->getSize());
1090 $temp_name = $item->getPath(); // currently used
1091
1092 // additional params
1093 $title = ilUtil::stripSlashes($file_upload["title"]);
1094 $description = ilUtil::stripSlashes($file_upload["description"]);
1095 $extract = ilUtil::stripSlashes($file_upload["extract"]);
1096 $keep_structure = ilUtil::stripSlashes($file_upload["keep_structure"]);
1097
1098 // create answer object
1099 $response = new stdClass();
1100 $response->fileName = $filename;
1101 $response->fileSize = intval($size);
1102 $response->fileType = $type;
1103 $response->fileUnzipped = $extract;
1104 $response->error = null;
1105
1106 // extract archive?
1107 if ($extract) {
1108 $zip_file = $filename;
1109 $adopt_structure = $keep_structure;
1110
1111 include_once("Services/Utilities/classes/class.ilFileUtils.php");
1112
1113 // Create unzip-directory
1114 $newDir = ilUtil::ilTempnam();
1115 ilUtil::makeDir($newDir);
1116
1117 // Check if permission is granted for creation of object, if necessary
1118 if ($this->id_type != self::WORKSPACE_NODE_ID) {
1119 $type = ilObject::_lookupType((int) $this->parent_id, true);
1120 } else {
1121 $type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
1122 }
1123
1124 $tree = $access_handler = null;
1125 switch ($type) {
1126 // workspace structure
1127 case 'wfld':
1128 case 'wsrt':
1129 $permission = $this->checkPermissionBool("create", "", "wfld");
1130 $containerType = "WorkspaceFolder";
1133 break;
1134
1135 // use categories as structure
1136 case 'cat':
1137 case 'root':
1138 $permission = $this->checkPermissionBool("create", "", "cat");
1139 $containerType = "Category";
1140 break;
1141
1142 // use folders as structure (in courses)
1143 default:
1144 $permission = $this->checkPermissionBool("create", "", "fold");
1145 $containerType = "Folder";
1146 break;
1147 }
1148
1149 try {
1150 // processZipFile (
1151 // Dir to unzip,
1152 // Path to uploaded file,
1153 // should a structure be created (+ permission check)?
1154 // ref_id of parent
1155 // object that contains files (folder or category)
1156 // should sendInfo be persistent?)
1158 $newDir,
1159 $temp_name,
1160 ($adopt_structure && $permission),
1161 $this->parent_id,
1162 $containerType,
1163 $tree,
1165 );
1166 } catch (ilFileUtilsException $e) {
1167 $response->error = $e->getMessage();
1168 } catch (Exception $ex) {
1169 $response->error = $this->lng->txt('general_upload_error_occured');
1170 }
1171
1172 ilUtil::delDir($newDir);
1173
1174 // #15404
1175 if ($this->id_type != self::WORKSPACE_NODE_ID) {
1176 foreach (ilFileUtils::getNewObjects() as $parent_ref_id => $objects) {
1177 if ($parent_ref_id != $this->parent_id) {
1178 continue;
1179 }
1180
1181 foreach ($objects as $object) {
1182 $this->after_creation_callback_objects[] = $object;
1183 }
1184 }
1185 }
1186 } else {
1187 // create and insert file in grp_tree
1188 $fileObj = new ilObjFile();
1189 // bugfix mantis 0026043
1190 if (strlen(trim($title)) == 0) {
1191 $title = $filename;
1192 } else {
1193 $title = $fileObj->checkFileExtension($filename, $title);
1194 }
1195 $fileObj->setTitle($title);
1196 $fileObj->setDescription($description);
1197 $fileObj->setFileName($filename);
1198 $fileObj->setFileType($type);
1199 $fileObj->setFileSize($size);
1200 $this->object_id = $fileObj->create();
1201 $this->putObjectInTree($fileObj, $this->parent_id);
1202
1203 // see uploadFiles()
1204 if (is_array($this->after_creation_callback_objects)) {
1205 $this->after_creation_callback_objects[] = $fileObj;
1206 }
1207
1208 // upload file to filesystem
1209 $fileObj->createDirectory();
1210 $fileObj->raiseUploadError(true);
1211
1212 $result = $fileObj->getUploadFile($temp_name, $filename);
1213
1214 if ($result) {
1215 //if no title for the file was set use the filename as title
1216 if (empty($fileObj->getTitle())) {
1217 $fileObj->setTitle($filename);
1218 }
1219 $fileObj->setFileName($filename);
1220 }
1221 $fileObj->update();
1222 $this->handleAutoRating($fileObj);
1223
1224 ilChangeEvent::_recordWriteEvent($fileObj->getId(), $ilUser->getId(), 'create');
1225 }
1226
1227 return $response;
1228 }
1229
1230
1231 protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
1232 {
1233 $lg = parent::initHeaderAction($a_sub_type, $a_sub_id);
1234 if (is_object($lg)) {
1235 if ($this->object->hasRating()) {
1236 $lg->enableRating(
1237 true,
1238 null,
1239 false,
1240 array("ilcommonactiondispatchergui", "ilratinggui")
1241 );
1242 }
1243 }
1244
1245 return $lg;
1246 }
1247}
$result
$size
Definition: RandomTest.php:84
$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.
This class represents a section header in a property form.
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 ...
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:29
Class FlySystemFileAccessTest.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
$ret
Definition: parser.php:6
$type
$response
$preview
$ilUser
Definition: imgupload.php:18
$context
Definition: webdav.php:26
$DIC
Definition: xapitoken.php:46