ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPCFileListGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("./Services/COPage/classes/class.ilPCFileList.php");
5require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
6
18{
22 protected $user;
23
27 protected $tabs;
28
32 protected $tree;
33
37 protected $toolbar;
38
42 protected $settings;
43
44
49 public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
50 {
51 global $DIC;
52
53 $this->user = $DIC->user();
54 $this->tabs = $DIC->tabs();
55 $this->ctrl = $DIC->ctrl();
56 $this->tpl = $DIC["tpl"];
57 $this->tree = $DIC->repositoryTree();
58 $this->lng = $DIC->language();
59 $this->toolbar = $DIC->toolbar();
60 $this->settings = $DIC->settings();
61 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
62 $this->setCharacteristics(array("FileListItem" => $this->lng->txt("cont_FileListItem")));
63 }
64
68 public function executeCommand()
69 {
70 // get next class that processes or forwards current command
71 $next_class = $this->ctrl->getNextClass($this);
72
73 $this->getCharacteristicsOfCurrentStyle("flist_li"); // scorm-2004
74
75 // get current command
76 $cmd = $this->ctrl->getCmd();
77
78 switch ($next_class) {
79 default:
80 $ret = $this->$cmd();
81 break;
82 }
83
84 return $ret;
85 }
86
90 public function insert($a_form = null)
91 {
93 $ilTabs = $this->tabs;
94
95 if ($_GET["subCmd"] == "insertNew") {
96 $_SESSION["cont_file_insert"] = "insertNew";
97 }
98 if ($_GET["subCmd"] == "insertFromRepository") {
99 $_SESSION["cont_file_insert"] = "insertFromRepository";
100 }
101 if ($_GET["subCmd"] == "insertFromWorkspace") {
102 $_SESSION["cont_file_insert"] = "insertFromWorkspace";
103 }
104 if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
105 $_GET["subCmd"] = $_SESSION["cont_file_insert"];
106 }
107
108 switch ($_GET["subCmd"]) {
109 case "insertFromWorkspace":
110 $this->insertFromWorkspace();
111 break;
112
113 case "insertFromRepository":
114 $this->insertFromRepository();
115 break;
116
117 case "selectFile":
118 $this->selectFile();
119 break;
120
121 default:
122 $this->setTabs();
123 $ilTabs->setSubTabActive("cont_new_file");
124
125 $this->displayValidationError();
126
127 if ($a_form != null) {
128 $form = $a_form;
129 } else {
130 $form = $this->initEditForm("create");
131 }
132 $this->tpl->setContent($form->getHTML());
133 break;
134 }
135 }
136
140 public function selectFile()
141 {
142 $ilTabs = $this->tabs;
144
145 $this->setTabs();
146 $ilTabs->setSubTabActive("cont_file_from_repository");
147
148 $this->displayValidationError();
149 $form = $this->initEditForm("select_file");
150
151 $this->tpl->setContent($form->getHTML());
152 }
153
157 public function insertFromRepository($a_cmd = "insert")
158 {
159 $ilTabs = $this->tabs;
162
163 if ($a_cmd == "insert") {
164 $this->setTabs();
165 } else {
166 $this->setItemTabs($a_cmd);
167 }
168
169 $ilTabs->setSubTabActive("cont_file_from_repository");
170 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
171
172 include_once("./Services/COPage/classes/class.ilPCFileItemFileSelectorGUI.php");
174 $this,
175 $a_cmd,
176 $this,
177 $a_cmd,
178 "file_ref_id"
179 );
180 if (!$exp->handleCommand()) {
181 $tpl->setContent($exp->getHTML());
182 }
183 }
184
188 public function insertFromWorkspace($a_cmd = "insert")
189 {
190 $ilTabs = $this->tabs;
195
196 if ($a_cmd == "insert") {
197 $this->setTabs();
198 } else {
199 $this->setItemTabs($a_cmd);
200 }
201
202 $ilTabs->setSubTabActive("cont_file_from_workspace");
203
204 include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceExplorerGUI.php");
205 $exp = new ilWorkspaceExplorerGUI($ilUser->getId(), $this, $a_cmd, $this, $a_cmd, "fl_wsp_id");
206 $ilCtrl->setParameter($this, "subCmd", "selectFile");
207 $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
208 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
209 $exp->setTypeWhiteList(array("wsrt", "wfld", "file"));
210 $exp->setSelectableTypes(array("file"));
211 if ($exp->handleCommand()) {
212 return;
213 }
214 $tpl->setContent($exp->getHTML());
215 }
216
220 public function create()
221 {
222 global $DIC;
223
224 include_once("./Modules/File/classes/class.ilObjFile.php");
225
226 $mode = ($_POST["file_ref_id"] != "")
227 ? "select_file"
228 : "create";
229 $form = $this->initEditForm($mode);
230 if (!$form->checkInput()) {
231 $form->setValuesByPost();
232 $this->insert($form);
233 return;
234 }
235
236 // from personal workspace
237 if (substr($_POST["file_ref_id"], 0, 4) == "wsp_") {
238 $fileObj = new ilObjFile(substr($_POST["file_ref_id"], 4), false);
239 }
240 // upload
241 elseif ($_POST["file_ref_id"] == 0) {
242 $fileObj = new ilObjFile();
243 $fileObj->setType("file");
244 $fileObj->setTitle($_FILES["file"]["name"]);
245 $fileObj->setDescription("");
246 $fileObj->setFileName($_FILES["file"]["name"]);
247 $fileObj->setFileType($_FILES["file"]["type"]);
248 $fileObj->setFileSize($_FILES["file"]["size"]);
249 $fileObj->setMode("filelist");
250 $fileObj->create();
251 // upload file to filesystem
252 $fileObj->createDirectory();
253 $fileObj->raiseUploadError(false);
254
255 $upload = $DIC->upload();
256 if ($upload->hasBeenProcessed() !== true) {
257 $upload->process();
258 }
259
260 $fileObj->getUploadFile(
261 $_FILES["file"]["tmp_name"],
262 $_FILES["file"]["name"]
263 );
264 }
265 // from repository
266 else {
267 $fileObj = new ilObjFile($_POST["file_ref_id"]);
268 }
269 $_SESSION["il_text_lang_" . $_GET["ref_id"]] = $_POST["flst_language"];
270
271 //echo "::".is_object($this->dom).":";
272 $this->content_obj = new ilPCFileList($this->getPage());
273 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
274 $this->content_obj->setListTitle(ilUtil::stripSlashes($_POST["flst_title"]), $_POST["flst_language"]);
275 $this->content_obj->appendItem(
276 $fileObj->getId(),
277 $fileObj->getFileName(),
278 $fileObj->getFileType()
279 );
280
281 $this->updated = $this->pg_obj->update();
282 if ($this->updated === true) {
283 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
284 } else {
285 $this->insert();
286 }
287 }
288
292 public function edit()
293 {
294 $this->setTabs(false);
295
296 $form = $this->initEditForm();
297 $this->tpl->setContent($form->getHTML());
298 }
299
305 public function initEditForm($a_mode = "edit")
306 {
310
311 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
312 $form = new ilPropertyFormGUI();
313
314 if ($a_mode != "add_file") {
315 // title
316 $ti = new ilTextInputGUI($lng->txt("title"), "flst_title");
317 $ti->setMaxLength(80);
318 $ti->setSize(40);
319 $form->addItem($ti);
320
321 // language
322 require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
324 $si = new ilSelectInputGUI($lng->txt("language"), "flst_language");
325 $si->setOptions($lang);
326 $form->addItem($si);
327 }
328
329 if (in_array($a_mode, array("create", "add_file"))) {
330 // file
331 $fi = new ilFileInputGUI($lng->txt("file"), "file");
332 $fi->setRequired(true);
333 $form->addItem($fi);
334 } elseif (in_array($a_mode, array("select_file"))) {
335 // file
336 $ne = new ilNonEditableValueGUI($lng->txt("file"), "");
337
338 if (isset($_GET["file_ref_id"])) {
339 include_once("./Modules/File/classes/class.ilObjFile.php");
340 $file_obj = new ilObjFile((int) $_GET["file_ref_id"]);
341 if (is_object($file_obj)) {
342 // ref id as hidden input
343 $hi = new ilHiddenInputGUI("file_ref_id");
344 $hi->setValue((int) $_GET["file_ref_id"]);
345 $form->addItem($hi);
346
347 $ne->setValue($file_obj->getTitle());
348 }
349 } elseif (isset($_GET["fl_wsp_id"])) {
350 // we need the object id for the instance
351 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
352 $tree = new ilWorkspaceTree($ilUser->getId());
353 $node = $tree->getNodeData((int) $_GET["fl_wsp_id"]);
354
355 include_once("./Modules/File/classes/class.ilObjFile.php");
356 $file_obj = new ilObjFile($node["obj_id"], false);
357 if (is_object($file_obj)) {
358 // ref id as hidden input
359 $hi = new ilHiddenInputGUI("file_ref_id");
360 $hi->setValue("wsp_" . (int) $node["obj_id"]);
361 $form->addItem($hi);
362
363 $ne->setValue($file_obj->getTitle());
364 }
365 $this->tpl->parseCurrentBlock();
366 }
367
368 $form->addItem($ne);
369 }
370
371
372 switch ($a_mode) {
373 case "edit":
374 $ti->setValue($this->content_obj->getListTitle());
375 $si->setValue($this->content_obj->getLanguage());
376 $form->addCommandButton("saveProperties", $lng->txt("save"));
377 $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
378 $form->setTitle($lng->txt("cont_edit_file_list_properties"));
379 break;
380
381 case "create":
382 case "select_file":
383 if ($_SESSION["il_text_lang_" . $_GET["ref_id"]] != "") {
384 $s_lang = $_SESSION["il_text_lang_" . $_GET["ref_id"]];
385 } else {
386 $s_lang = $ilUser->getLanguage();
387 }
388 $si->setValue($s_lang);
389 $form->addCommandButton("create_flst", $lng->txt("save"));
390 $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
391 $form->setTitle($lng->txt("cont_insert_file_list"));
392 break;
393
394 case "add_file":
395 $form->addCommandButton("insertNewFileItem", $lng->txt("save"));
396 $form->addCommandButton("editFiles", $lng->txt("cancel"));
397 $form->setTitle($lng->txt("cont_insert_file_item"));
398 break;
399 }
400
401 $form->setFormAction($ilCtrl->getFormAction($this));
402
403 return $form;
404 }
405
406
410 public function saveProperties()
411 {
412 $this->content_obj->setListTitle(
413 ilUtil::stripSlashes($_POST["flst_title"]),
414 ilUtil::stripSlashes($_POST["flst_language"])
415 );
416 $this->updated = $this->pg_obj->update();
417 if ($this->updated === true) {
418 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
419 } else {
420 $this->pg_obj->addHierIDs();
421 $this->edit();
422 }
423 }
424
428 public function editFiles()
429 {
431 $ilToolbar = $this->toolbar;
434
435 $this->setTabs(false);
436
437 $ilToolbar->addButton(
438 $lng->txt("cont_add_file"),
439 $ilCtrl->getLinkTarget($this, "addFileItem")
440 );
441
442 include_once("./Services/COPage/classes/class.ilPCFileListTableGUI.php");
443 $table_gui = new ilPCFileListTableGUI($this, "editFiles", $this->content_obj);
444 $tpl->setContent($table_gui->getHTML());
445 }
446
450 public function setTabs($a_create = true)
451 {
452 $ilTabs = $this->tabs;
456
457 if ($a_create) {
458 $cmd = "insert";
459
460 $ilCtrl->setParameter($this, "subCmd", "insertNew");
461 $ilTabs->addSubTabTarget(
462 "cont_new_file",
463 $ilCtrl->getLinkTarget($this, $cmd),
464 $cmd
465 );
466
467 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
468 $ilTabs->addSubTabTarget(
469 "cont_file_from_repository",
470 $ilCtrl->getLinkTarget($this, $cmd),
471 $cmd
472 );
473 $ilCtrl->setParameter($this, "subCmd", "");
474
475 if (!$ilSetting->get("disable_personal_workspace") &&
476 !$ilSetting->get("disable_wsp_files")) {
477 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
478 $ilTabs->addSubTabTarget(
479 "cont_file_from_workspace",
480 $ilCtrl->getLinkTarget($this, $cmd),
481 $cmd
482 );
483 $ilCtrl->setParameter($this, "subCmd", "");
484 }
485 } else {
486 $ilTabs->setBackTarget(
487 $lng->txt("pg"),
488 $this->ctrl->getParentReturn($this)
489 );
490
491 $ilTabs->addTarget(
492 "cont_ed_edit_files",
493 $ilCtrl->getLinkTarget($this, "editFiles"),
494 "editFiles",
495 get_class($this)
496 );
497
498 $ilTabs->addTarget(
499 "cont_ed_edit_prop",
500 $ilCtrl->getLinkTarget($this, "edit"),
501 "edit",
502 get_class($this)
503 );
504 }
505 }
506
511 public function addFileItem()
512 {
514
515 $files = $this->content_obj->getFileList();
516
517 if (count($files) >= 1) {
518 $ilCtrl->setParameterByClass(
519 "ilpcfileitemgui",
520 "hier_id",
521 $files[count($files) - 1]["hier_id"]
522 );
523 $ilCtrl->setParameterByClass(
524 "ilpcfileitemgui",
525 "pc_id",
526 $files[count($files) - 1]["pc_id"]
527 );
528 $ilCtrl->redirectByClass("ilpcfileitemgui", "newItemAfter");
529 } else {
530 $ilCtrl->redirect($this, "newFileItem");
531 }
532 }
533
537 public function deleteFileItem()
538 {
540
541 if (is_array($_POST["fid"])) {
542 $ids = array();
543 foreach ($_POST["fid"] as $k => $v) {
544 $ids[] = $k;
545 }
546 $this->content_obj->deleteFileItems($ids);
547 }
548 $this->updated = $this->pg_obj->update();
549 $ilCtrl->redirect($this, "editFiles");
550 }
551
555 public function savePositions()
556 {
558
559 if (is_array($_POST["position"])) {
560 $this->content_obj->savePositions($_POST["position"]);
561 }
562 $this->updated = $this->pg_obj->update();
563 $ilCtrl->redirect($this, "editFiles");
564 }
565
569 public function savePositionsAndClasses()
570 {
572
573 if (is_array($_POST["position"])) {
574 $this->content_obj->savePositions($_POST["position"]);
575 }
576 if (is_array($_POST["class"])) {
577 $this->content_obj->saveStyleClasses($_POST["class"]);
578 }
579 $this->updated = $this->pg_obj->update();
580 $ilCtrl->redirect($this, "editFiles");
581 }
582
586 public function checkStyleSelection()
587 {
588 // check whether there is more than one style class
589 $chars = $this->getCharacteristics();
590
591 $classes = $this->content_obj->getAllClasses();
592 if (count($chars) > 1) {
593 return true;
594 }
595 foreach ($classes as $class) {
596 if ($class != "" && $class != "FileListItem") {
597 return true;
598 }
599 }
600 return false;
601 }
602
603 //
604 //
605 // New file item
606 //
607 //
608
615 public function newFileItem()
616 {
617 $ilTabs = $this->tabs;
618
619 if ($_GET["subCmd"] == "insertNew") {
620 $_SESSION["cont_file_insert"] = "insertNew";
621 }
622 if ($_GET["subCmd"] == "insertFromRepository") {
623 $_SESSION["cont_file_insert"] = "insertFromRepository";
624 }
625 if ($_GET["subCmd"] == "insertFromWorkspace") {
626 $_SESSION["cont_file_insert"] = "insertFromWorkspace";
627 }
628 if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
629 $_GET["subCmd"] = $_SESSION["cont_file_insert"];
630 }
631
632 switch ($_GET["subCmd"]) {
633 case "insertFromWorkspace":
634 $this->insertFromWorkspace("newFileItem");
635 break;
636
637 case "insertFromRepository":
638 $this->insertFromRepository("newFileItem");
639 break;
640
641 case "selectFile":
642 $this->insertNewFileItem($_GET["file_ref_id"]);
643 break;
644
645 default:
646 $this->setItemTabs("newFileItem");
647 $ilTabs->setSubTabActive("cont_new_file");
648
649 $this->displayValidationError();
650
651 $form = $this->initEditForm("add_file");
652 $this->tpl->setContent($form->getHTML());
653 break;
654 }
655 }
656
660 public function insertNewFileItem($a_file_ref_id = 0)
661 {
663
664 // from personal workspace
665 if (isset($_GET["fl_wsp_id"])) {
666 // we need the object id for the instance
667 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
668 $tree = new ilWorkspaceTree($ilUser->getId());
669 $node = $tree->getNodeData($_GET["fl_wsp_id"]);
670
671 include_once("./Modules/File/classes/class.ilObjFile.php");
672 $file_obj = new ilObjFile($node["obj_id"], false);
673 }
674 // upload
675 elseif ($a_file_ref_id == 0) {
676 $file_obj = $this->createFileItem();
677 }
678 // from repository
679 else {
680 include_once("./Modules/File/classes/class.ilObjFile.php");
681 $file_obj = new ilObjFile($a_file_ref_id);
682 }
683 if (is_object($file_obj)) {
684 $this->content_obj->appendItem(
685 $file_obj->getId(),
686 $file_obj->getTitle(),
687 $file_obj->getFileType()
688 );
689 $this->updated = $this->pg_obj->update();
690 if ($this->updated === true) {
691 //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
692 $this->ctrl->redirect($this, "editFiles");
693 }
694 }
695
696 $_GET["subCmd"] = "-";
697 $this->newFileItem();
698 }
699
703 public function createFileItem()
704 {
705 global $DIC;
706
708
709 if ($_FILES["file"]["name"] == "") {
710 $_GET["subCmd"] = "-";
711 ilUtil::sendFailure($lng->txt("upload_error_file_not_found"));
712 return false;
713 }
714
715 $form = $this->initEditForm();
716 // see #22541
717 // $form->checkInput();
718
719 include_once("./Modules/File/classes/class.ilObjFile.php");
720 $fileObj = new ilObjFile();
721 $fileObj->setType("file");
722 $fileObj->setTitle($_FILES["file"]["name"]);
723 $fileObj->setDescription("");
724 $fileObj->setVersion(0);
725 $fileObj->setMaxVersion(0);
726 $fileObj->setFileName($_FILES["file"]["name"]);
727 $fileObj->setFileType($_FILES["file"]["type"]);
728 $fileObj->setFileSize($_FILES["file"]["size"]);
729 $fileObj->setMode("filelist");
730 $fileObj->create();
731 $fileObj->createDirectory();
732 $fileObj->raiseUploadError(false);
733 $fileObj->getUploadFile($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);
734 // upload file to filesystem
735
736 return $fileObj;
737 }
738
739
743 public function setItemTabs($a_cmd = "")
744 {
745 $ilTabs = $this->tabs;
748
749 $ilTabs->addTarget(
750 "cont_back",
751 $this->ctrl->getParentReturn($this),
752 "",
753 ""
754 );
755
756 if ($a_cmd != "") {
757 $ilCtrl->setParameter($this, "subCmd", "insertNew");
758 $ilTabs->addSubTabTarget(
759 "cont_new_file",
760 $ilCtrl->getLinkTarget($this, $a_cmd),
761 $a_cmd
762 );
763
764 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
765 $ilTabs->addSubTabTarget(
766 "cont_file_from_repository",
767 $ilCtrl->getLinkTarget($this, $a_cmd),
768 $a_cmd
769 );
770 $ilCtrl->setParameter($this, "subCmd", "");
771
772 if (!$ilSetting->get("disable_personal_workspace") &&
773 !$ilSetting->get("disable_wsp_files")) {
774 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
775 $ilTabs->addSubTabTarget(
776 "cont_file_from_workspace",
777 $ilCtrl->getLinkTarget($this, $a_cmd),
778 $a_cmd
779 );
780 $ilCtrl->setParameter($this, "subCmd", "");
781 }
782 }
783 }
784}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a file property in a property form.
This class represents a hidden form property in a property form.
This class represents a non editable value in a property form.
Class ilObjFile.
Class ilPCListGUI.
insertFromRepository($a_cmd="insert")
Insert file from repository.
executeCommand()
execute command
insert($a_form=null)
insert new file list form
setTabs($a_create=true)
Set Tabs.
addFileItem()
Add file item.
insertFromWorkspace($a_cmd="insert")
Insert file from personal workspace.
newFileItem()
New file item (called, if there is no file item in an existing)
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
setItemTabs($a_cmd="")
output tabs
initEditForm($a_mode="edit")
Init edit form.
savePositions()
Save positions of file items.
savePositionsAndClasses()
Save positions of file items and style classes.
checkStyleSelection()
Checks whether style selection shoudl be available or not.
saveProperties()
save table properties in db and return to page edit screen
edit()
edit properties form
create()
create new file list in dom and update page in db
deleteFileItem()
Delete file items from list.
createFileItem()
insert new file item
insertNewFileItem($a_file_ref_id=0)
insert new file item after another item
TableGUI class for file list.
Class ilPCFileList.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
displayValidationError()
display validation errors
getCharacteristics()
Get characteristics.
setCharacteristics($a_chars)
Set Characteristics.
This class represents a property form user interface.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Explorer for selecting a personal workspace item.
Tree handler for personal workspace.
global $ilCtrl
Definition: ilias.php:18
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
$files
Definition: metarefresh.php:49
$ret
Definition: parser.php:6
global $ilSetting
Definition: privfeed.php:17
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18