ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_once("./Services/COPage/classes/class.ilPCFileList.php");
5 require_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;
161  $tpl = $this->tpl;
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");
173  $exp = new ilPCFileItemFileSelectorGUI(
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;
191  $tree = $this->tree;
193  $tpl = $this->tpl;
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  include_once("./Modules/File/classes/class.ilObjFile.php");
223 
224  $mode = ($_POST["file_ref_id"] != "")
225  ? "select_file"
226  : "create";
227  $form = $this->initEditForm($mode);
228  if (!$form->checkInput()) {
229  $form->setValuesByPost();
230  $this->insert($form);
231  return;
232  }
233 
234  // from personal workspace
235  if (substr($_POST["file_ref_id"], 0, 4) == "wsp_") {
236  $fileObj = new ilObjFile(substr($_POST["file_ref_id"], 4), false);
237  }
238  // upload
239  elseif ($_POST["file_ref_id"] == 0) {
240  $fileObj = new ilObjFile();
241  $fileObj->setType("file");
242  $fileObj->setTitle($_FILES["file"]["name"]);
243  $fileObj->setDescription("");
244  $fileObj->setFileName($_FILES["file"]["name"]);
245  $fileObj->setFileType($_FILES["file"]["type"]);
246  $fileObj->setFileSize($_FILES["file"]["size"]);
247  $fileObj->setMode("filelist");
248  $fileObj->create();
249  // upload file to filesystem
250  $fileObj->createDirectory();
251  $fileObj->raiseUploadError(false);
252  $fileObj->getUploadFile(
253  $_FILES["file"]["tmp_name"],
254  $_FILES["file"]["name"]
255  );
256  }
257  // from repository
258  else {
259  $fileObj = new ilObjFile($_POST["file_ref_id"]);
260  }
261  $_SESSION["il_text_lang_" . $_GET["ref_id"]] = $_POST["flst_language"];
262 
263  //echo "::".is_object($this->dom).":";
264  $this->content_obj = new ilPCFileList($this->getPage());
265  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
266  $this->content_obj->setListTitle(ilUtil::stripSlashes($_POST["flst_title"]), $_POST["flst_language"]);
267  $this->content_obj->appendItem(
268  $fileObj->getId(),
269  $fileObj->getFileName(),
270  $fileObj->getFileType()
271  );
272 
273  $this->updated = $this->pg_obj->update();
274  if ($this->updated === true) {
275  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
276  } else {
277  $this->insert();
278  }
279  }
280 
284  public function edit()
285  {
286  $this->setTabs(false);
287 
288  $form = $this->initEditForm();
289  $this->tpl->setContent($form->getHTML());
290  }
291 
297  public function initEditForm($a_mode = "edit")
298  {
299  $lng = $this->lng;
302 
303  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
304  $form = new ilPropertyFormGUI();
305 
306  if ($a_mode != "add_file") {
307  // title
308  $ti = new ilTextInputGUI($lng->txt("title"), "flst_title");
309  $ti->setMaxLength(80);
310  $ti->setSize(40);
311  $form->addItem($ti);
312 
313  // language
314  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
316  $si = new ilSelectInputGUI($lng->txt("language"), "flst_language");
317  $si->setOptions($lang);
318  $form->addItem($si);
319  }
320 
321  if (in_array($a_mode, array("create", "add_file"))) {
322  // file
323  $fi = new ilFileInputGUI($lng->txt("file"), "file");
324  $fi->setRequired(true);
325  $form->addItem($fi);
326  } elseif (in_array($a_mode, array("select_file"))) {
327  // file
328  $ne = new ilNonEditableValueGUI($lng->txt("file"), "");
329 
330  if (isset($_GET["file_ref_id"])) {
331  include_once("./Modules/File/classes/class.ilObjFile.php");
332  $file_obj = new ilObjFile((int) $_GET["file_ref_id"]);
333  if (is_object($file_obj)) {
334  // ref id as hidden input
335  $hi = new ilHiddenInputGUI("file_ref_id");
336  $hi->setValue((int) $_GET["file_ref_id"]);
337  $form->addItem($hi);
338 
339  $ne->setValue($file_obj->getTitle());
340  }
341  } elseif (isset($_GET["fl_wsp_id"])) {
342  // we need the object id for the instance
343  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
344  $tree = new ilWorkspaceTree($ilUser->getId());
345  $node = $tree->getNodeData((int) $_GET["fl_wsp_id"]);
346 
347  include_once("./Modules/File/classes/class.ilObjFile.php");
348  $file_obj = new ilObjFile($node["obj_id"], false);
349  if (is_object($file_obj)) {
350  // ref id as hidden input
351  $hi = new ilHiddenInputGUI("file_ref_id");
352  $hi->setValue("wsp_" . (int) $node["obj_id"]);
353  $form->addItem($hi);
354 
355  $ne->setValue($file_obj->getTitle());
356  }
357  $this->tpl->parseCurrentBlock();
358  }
359 
360  $form->addItem($ne);
361  }
362 
363 
364  switch ($a_mode) {
365  case "edit":
366  $ti->setValue($this->content_obj->getListTitle());
367  $si->setValue($this->content_obj->getLanguage());
368  $form->addCommandButton("saveProperties", $lng->txt("save"));
369  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
370  $form->setTitle($lng->txt("cont_edit_file_list_properties"));
371  break;
372 
373  case "create":
374  case "select_file":
375  if ($_SESSION["il_text_lang_" . $_GET["ref_id"]] != "") {
376  $s_lang = $_SESSION["il_text_lang_" . $_GET["ref_id"]];
377  } else {
378  $s_lang = $ilUser->getLanguage();
379  }
380  $si->setValue($s_lang);
381  $form->addCommandButton("create_flst", $lng->txt("save"));
382  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
383  $form->setTitle($lng->txt("cont_insert_file_list"));
384  break;
385 
386  case "add_file":
387  $form->addCommandButton("insertNewFileItem", $lng->txt("save"));
388  $form->addCommandButton("editFiles", $lng->txt("cancel"));
389  $form->setTitle($lng->txt("cont_insert_file_item"));
390  break;
391  }
392 
393  $form->setFormAction($ilCtrl->getFormAction($this));
394 
395  return $form;
396  }
397 
398 
402  public function saveProperties()
403  {
404  $this->content_obj->setListTitle(
405  ilUtil::stripSlashes($_POST["flst_title"]),
406  ilUtil::stripSlashes($_POST["flst_language"])
407  );
408  $this->updated = $this->pg_obj->update();
409  if ($this->updated === true) {
410  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
411  } else {
412  $this->pg_obj->addHierIDs();
413  $this->edit();
414  }
415  }
416 
420  public function editFiles()
421  {
422  $tpl = $this->tpl;
423  $ilToolbar = $this->toolbar;
425  $lng = $this->lng;
426 
427  $this->setTabs(false);
428 
429  $ilToolbar->addButton(
430  $lng->txt("cont_add_file"),
431  $ilCtrl->getLinkTarget($this, "addFileItem")
432  );
433 
434  include_once("./Services/COPage/classes/class.ilPCFileListTableGUI.php");
435  $table_gui = new ilPCFileListTableGUI($this, "editFiles", $this->content_obj);
436  $tpl->setContent($table_gui->getHTML());
437  }
438 
442  public function setTabs($a_create = true)
443  {
444  $ilTabs = $this->tabs;
446  $lng = $this->lng;
448 
449  if ($a_create) {
450  $cmd = "insert";
451 
452  $ilCtrl->setParameter($this, "subCmd", "insertNew");
453  $ilTabs->addSubTabTarget(
454  "cont_new_file",
455  $ilCtrl->getLinkTarget($this, $cmd),
456  $cmd
457  );
458 
459  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
460  $ilTabs->addSubTabTarget(
461  "cont_file_from_repository",
462  $ilCtrl->getLinkTarget($this, $cmd),
463  $cmd
464  );
465  $ilCtrl->setParameter($this, "subCmd", "");
466 
467  if (!$ilSetting->get("disable_personal_workspace") &&
468  !$ilSetting->get("disable_wsp_files")) {
469  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
470  $ilTabs->addSubTabTarget(
471  "cont_file_from_workspace",
472  $ilCtrl->getLinkTarget($this, $cmd),
473  $cmd
474  );
475  $ilCtrl->setParameter($this, "subCmd", "");
476  }
477  } else {
478  $ilTabs->setBackTarget(
479  $lng->txt("pg"),
480  $this->ctrl->getParentReturn($this)
481  );
482 
483  $ilTabs->addTarget(
484  "cont_ed_edit_files",
485  $ilCtrl->getLinkTarget($this, "editFiles"),
486  "editFiles",
487  get_class($this)
488  );
489 
490  $ilTabs->addTarget(
491  "cont_ed_edit_prop",
492  $ilCtrl->getLinkTarget($this, "edit"),
493  "edit",
494  get_class($this)
495  );
496  }
497  }
498 
503  public function addFileItem()
504  {
506 
507  $files = $this->content_obj->getFileList();
508 
509  if (count($files) >= 1) {
510  $ilCtrl->setParameterByClass(
511  "ilpcfileitemgui",
512  "hier_id",
513  $files[count($files) - 1]["hier_id"]
514  );
515  $ilCtrl->setParameterByClass(
516  "ilpcfileitemgui",
517  "pc_id",
518  $files[count($files) - 1]["pc_id"]
519  );
520  $ilCtrl->redirectByClass("ilpcfileitemgui", "newItemAfter");
521  } else {
522  $ilCtrl->redirect($this, "newFileItem");
523  }
524  }
525 
529  public function deleteFileItem()
530  {
532 
533  if (is_array($_POST["fid"])) {
534  $ids = array();
535  foreach ($_POST["fid"] as $k => $v) {
536  $ids[] = $k;
537  }
538  $this->content_obj->deleteFileItems($ids);
539  }
540  $this->updated = $this->pg_obj->update();
541  $ilCtrl->redirect($this, "editFiles");
542  }
543 
547  public function savePositions()
548  {
550 
551  if (is_array($_POST["position"])) {
552  $this->content_obj->savePositions($_POST["position"]);
553  }
554  $this->updated = $this->pg_obj->update();
555  $ilCtrl->redirect($this, "editFiles");
556  }
557 
561  public function savePositionsAndClasses()
562  {
564 
565  if (is_array($_POST["position"])) {
566  $this->content_obj->savePositions($_POST["position"]);
567  }
568  if (is_array($_POST["class"])) {
569  $this->content_obj->saveStyleClasses($_POST["class"]);
570  }
571  $this->updated = $this->pg_obj->update();
572  $ilCtrl->redirect($this, "editFiles");
573  }
574 
578  public function checkStyleSelection()
579  {
580  // check whether there is more than one style class
581  $chars = $this->getCharacteristics();
582 
583  $classes = $this->content_obj->getAllClasses();
584  if (count($chars) > 1) {
585  return true;
586  }
587  foreach ($classes as $class) {
588  if ($class != "" && $class != "FileListItem") {
589  return true;
590  }
591  }
592  return false;
593  }
594 
595  //
596  //
597  // New file item
598  //
599  //
600 
607  public function newFileItem()
608  {
609  $ilTabs = $this->tabs;
610 
611  if ($_GET["subCmd"] == "insertNew") {
612  $_SESSION["cont_file_insert"] = "insertNew";
613  }
614  if ($_GET["subCmd"] == "insertFromRepository") {
615  $_SESSION["cont_file_insert"] = "insertFromRepository";
616  }
617  if ($_GET["subCmd"] == "insertFromWorkspace") {
618  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
619  }
620  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
621  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
622  }
623 
624  switch ($_GET["subCmd"]) {
625  case "insertFromWorkspace":
626  $this->insertFromWorkspace("newFileItem");
627  break;
628 
629  case "insertFromRepository":
630  $this->insertFromRepository("newFileItem");
631  break;
632 
633  case "selectFile":
634  $this->insertNewFileItem($_GET["file_ref_id"]);
635  break;
636 
637  default:
638  $this->setItemTabs("newFileItem");
639  $ilTabs->setSubTabActive("cont_new_file");
640 
641  $this->displayValidationError();
642 
643  $form = $this->initEditForm("add_file");
644  $this->tpl->setContent($form->getHTML());
645  break;
646  }
647  }
648 
652  public function insertNewFileItem($a_file_ref_id = 0)
653  {
655 
656  // from personal workspace
657  if (isset($_GET["fl_wsp_id"])) {
658  // we need the object id for the instance
659  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
660  $tree = new ilWorkspaceTree($ilUser->getId());
661  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
662 
663  include_once("./Modules/File/classes/class.ilObjFile.php");
664  $file_obj = new ilObjFile($node["obj_id"], false);
665  }
666  // upload
667  elseif ($a_file_ref_id == 0) {
668  $file_obj = $this->createFileItem();
669  }
670  // from repository
671  else {
672  include_once("./Modules/File/classes/class.ilObjFile.php");
673  $file_obj = new ilObjFile($a_file_ref_id);
674  }
675  if (is_object($file_obj)) {
676  $this->content_obj->appendItem(
677  $file_obj->getId(),
678  $file_obj->getTitle(),
679  $file_obj->getFileType()
680  );
681  $this->updated = $this->pg_obj->update();
682  if ($this->updated === true) {
683  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
684  $this->ctrl->redirect($this, "editFiles");
685  }
686  }
687 
688  $_GET["subCmd"] = "-";
689  $this->newFileItem();
690  }
691 
695  public function createFileItem()
696  {
697  $lng = $this->lng;
698 
699  if ($_FILES["file"]["name"] == "") {
700  $_GET["subCmd"] = "-";
701  ilUtil::sendFailure($lng->txt("upload_error_file_not_found"));
702  return false;
703  }
704 
705  $form = $this->initEditForm();
706  // see #22541
707  // $form->checkInput();
708 
709  include_once("./Modules/File/classes/class.ilObjFile.php");
710  $fileObj = new ilObjFile();
711  $fileObj->setType("file");
712  $fileObj->setTitle($_FILES["file"]["name"]);
713  $fileObj->setDescription("");
714  $fileObj->setFileName($_FILES["file"]["name"]);
715  $fileObj->setFileType($_FILES["file"]["type"]);
716  $fileObj->setFileSize($_FILES["file"]["size"]);
717  $fileObj->setMode("filelist");
718  $fileObj->create();
719  $fileObj->raiseUploadError(false);
720  // upload file to filesystem
721  $fileObj->createDirectory();
722  $fileObj->getUploadFile(
723  $_FILES["file"]["tmp_name"],
724  $_FILES["file"]["name"]
725  );
726 
727  return $fileObj;
728  }
729 
730 
734  public function setItemTabs($a_cmd = "")
735  {
736  $ilTabs = $this->tabs;
739 
740  $ilTabs->addTarget(
741  "cont_back",
742  $this->ctrl->getParentReturn($this),
743  "",
744  ""
745  );
746 
747  if ($a_cmd != "") {
748  $ilCtrl->setParameter($this, "subCmd", "insertNew");
749  $ilTabs->addSubTabTarget(
750  "cont_new_file",
751  $ilCtrl->getLinkTarget($this, $a_cmd),
752  $a_cmd
753  );
754 
755  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
756  $ilTabs->addSubTabTarget(
757  "cont_file_from_repository",
758  $ilCtrl->getLinkTarget($this, $a_cmd),
759  $a_cmd
760  );
761  $ilCtrl->setParameter($this, "subCmd", "");
762 
763  if (!$ilSetting->get("disable_personal_workspace") &&
764  !$ilSetting->get("disable_wsp_files")) {
765  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
766  $ilTabs->addSubTabTarget(
767  "cont_file_from_workspace",
768  $ilCtrl->getLinkTarget($this, $a_cmd),
769  $a_cmd
770  );
771  $ilCtrl->setParameter($this, "subCmd", "");
772  }
773  }
774  }
775 }
$files
Definition: add-vimline.php:18
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
edit()
edit properties form
newFileItem()
New file item (called, if there is no file item in an existing)
insertFromWorkspace($a_cmd="insert")
Insert file from personal workspace.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
This class represents a property form user interface.
setTabs($a_create=true)
Set Tabs.
setItemTabs($a_cmd="")
output tabs
initEditForm($a_mode="edit")
Init edit form.
global $DIC
Definition: saml.php:7
createFileItem()
insert new file item
selectFile()
Select file.
$_GET["client_id"]
deleteFileItem()
Delete file items from list.
This class represents a file property in a property form.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
user()
Definition: user.php:4
Tree handler for personal workspace.
global $ilCtrl
Definition: ilias.php:18
setCharacteristics($a_chars)
Set Characteristics.
This class represents a hidden form property in a property form.
insert($a_form=null)
insert new file list form
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
executeCommand()
execute command
insertNewFileItem($a_file_ref_id=0)
insert new file item after another item
if(isset($_POST['submit'])) $form
Explorer for selecting a personal workspace item.
displayValidationError()
display validation errors
This class represents a text property in a property form.
$ilUser
Definition: imgupload.php:18
insertFromRepository($a_cmd="insert")
Insert file from repository.
setMaxLength($a_maxlength)
Set Max Length.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
getCharacteristics()
Get characteristics.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
settings()
Definition: settings.php:2
checkStyleSelection()
Checks whether style selection shoudl be available or not.
This class represents a non editable value in a property form.
Class ilPCListGUI.
global $ilSetting
Definition: privfeed.php:17
$ret
Definition: parser.php:6
Class ilPCFileList.
create()
create new file list in dom and update page in db
saveProperties()
save table properties in db and return to page edit screen
TableGUI class for file list.
savePositionsAndClasses()
Save positions of file items and style classes.
addFileItem()
Add file item.
$_POST["username"]
setRequired($a_required)
Set Required.
savePositions()
Save positions of file items.