ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
19 
24  function ilPCFileListGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
25  {
26  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
27  $this->setCharacteristics(array("FileListItem" => $this->lng->txt("cont_FileListItem")));
28  }
29 
33  function &executeCommand()
34  {
35  // get next class that processes or forwards current command
36  $next_class = $this->ctrl->getNextClass($this);
37 
38  $this->getCharacteristicsOfCurrentStyle("flist_li"); // scorm-2004
39 
40  // get current command
41  $cmd = $this->ctrl->getCmd();
42 
43  switch($next_class)
44  {
45  default:
46  $ret =& $this->$cmd();
47  break;
48  }
49 
50  return $ret;
51  }
52 
56  function insert()
57  {
58  global $ilUser, $ilTabs;
59 
60  if ($_GET["subCmd"] == "insertNew")
61  {
62  $_SESSION["cont_file_insert"] = "insertNew";
63  }
64  if ($_GET["subCmd"] == "insertFromRepository")
65  {
66  $_SESSION["cont_file_insert"] = "insertFromRepository";
67  }
68  if ($_GET["subCmd"] == "insertFromWorkspace")
69  {
70  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
71  }
72  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
73  {
74  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
75  }
76 
77  switch ($_GET["subCmd"])
78  {
79  case "insertFromWorkspace":
80  $this->insertFromWorkspace();
81  break;
82 
83  case "insertFromRepository":
84  $this->insertFromRepository();
85  break;
86 
87  case "selectFile":
88  $this->selectFile();
89  break;
90 
91  default:
92  $this->setTabs();
93  $ilTabs->setSubTabActive("cont_new_file");
94 
95  $this->displayValidationError();
96 
97  $form = $this->initEditForm("create");
98  $this->tpl->setContent($form->getHTML());
99  break;
100  }
101 
102  }
103 
107  function selectFile()
108  {
109  global $ilTabs, $ilUser;
110 
111  $this->setTabs();
112  $ilTabs->setSubTabActive("cont_file_from_repository");
113 
114  $this->displayValidationError();
115  $form = $this->initEditForm("select_file");
116 
117  $this->tpl->setContent($form->getHTML());
118  }
119 
123  function insertFromRepository($a_cmd = "insert")
124  {
125  global $ilTabs, $tree, $ilCtrl, $tpl;
126 
127  if ($a_cmd == "insert")
128  {
129  $this->setTabs();
130  }
131  else
132  {
133  $this->setItemTabs($a_cmd);
134  }
135 
136  $ilTabs->setSubTabActive("cont_file_from_repository");
137 
138  include_once "./Services/COPage/classes/class.ilFileSelectorGUI.php";
139 
140  $exp = new ilFileSelectorGUI($this->ctrl->getLinkTarget($this, $a_cmd));
141 
142  if ($_GET["expand"] == "")
143  {
144  $expanded = $tree->readRootId();
145  }
146  else
147  {
148  $expanded = $_GET["expand"];
149  }
150  $exp->setExpand($expanded);
151 
152  $exp->setTargetGet("sel_id");
153  //$this->ctrl->setParameter($this, "target_type", $a_type);
154  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
155  $exp->setParamsGet($this->ctrl->getParameterArray($this, $a_cmd));
156 
157  // filter
158  $exp->setFiltered(true);
159  $exp->setFilterMode(IL_FM_POSITIVE);
160  $exp->addFilter("root");
161  $exp->addFilter("cat");
162  $exp->addFilter("grp");
163  $exp->addFilter("fold");
164  $exp->addFilter("crs");
165  $exp->addFilter("file");
166 
167  $sel_types = array('file');
168 
169  $exp->setOutput(0);
170 
171  $tpl->setContent($exp->getOutput());
172  }
173 
177  function insertFromWorkspace($a_cmd = "insert")
178  {
179  global $ilTabs, $tree, $ilCtrl, $tpl, $ilUser;
180 
181  if ($a_cmd == "insert")
182  {
183  $this->setTabs();
184  }
185  else
186  {
187  $this->setItemTabs($a_cmd);
188  }
189 
190  $ilTabs->setSubTabActive("cont_file_from_workspace");
191 
192  // get ws tree
193  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
194  $tree = new ilWorkspaceTree($ilUser->getId());
195 
196  // get access handler
197  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
198  $acc_handler = new ilWorkspaceAccessHandler($tree);
199 
200  // get es explorer
201  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceExplorer.php");
203  'filelist_wspexpand', $tree, $acc_handler);
204  $exp->setTargetGet('fl_wsp_id');
205  $exp->setFiltered(false);
206  $exp->removeAllFormItemTypes();
207 
208  // select link
209  $exp->setTypeClickable("file");
210  $ilCtrl->setParameter($this, "subCmd", "selectFile");
211  $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
212 
213  // filter
214  $exp->setFiltered(true);
215  $exp->setFilterMode(IL_FM_POSITIVE);
216  $exp->addFilter("wsrt");
217  $exp->addFilter("wfld");
218  $exp->addFilter("file");
219 
220  // expand link
221  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
222  $exp->setParamsGet($ilCtrl->getParameterArray($this, $a_cmd));
223 
224  if($_GET['filelist_wspexpand'] == '')
225  {
226  $expanded = $tree->readRootId();
227  }
228  else
229  {
230  $expanded = $_GET['filelist_wspexpand'];
231  }
232  $exp->setExpand($expanded);
233  $exp->setOutput(0);
234 
235  $tpl->setContent($exp->getOutput());
236  }
237 
241  function create()
242  {
243  include_once("./Modules/File/classes/class.ilObjFile.php");
244 
245  // from personal workspace
246  if(substr($_POST["file_ref_id"], 0, 4) == "wsp_")
247  {
248  $fileObj = new ilObjFile(substr($_POST["file_ref_id"], 4), false);
249  }
250  // upload
251  else if ($_POST["file_ref_id"] == 0)
252  {
253  $fileObj = new ilObjFile();
254  $fileObj->setType("file");
255  $fileObj->setTitle($_FILES["file"]["name"]);
256  $fileObj->setDescription("");
257  $fileObj->setFileName($_FILES["file"]["name"]);
258  $fileObj->setFileType($_FILES["file"]["type"]);
259  $fileObj->setFileSize($_FILES["file"]["size"]);
260  $fileObj->setMode("filelist");
261  $fileObj->create();
262  // upload file to filesystem
263  $fileObj->createDirectory();
264  $fileObj->raiseUploadError(false);
265  $fileObj->getUploadFile($_FILES["file"]["tmp_name"],
266  $_FILES["file"]["name"]);
267  }
268  // from repository
269  else
270  {
271  $fileObj = new ilObjFile($_POST["file_ref_id"]);
272  }
273  $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["flst_language"];
274 
275 //echo "::".is_object($this->dom).":";
276  $this->content_obj = new ilPCFileList($this->dom);
277  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
278  $this->content_obj->setListTitle(ilUtil::stripSlashes($_POST["flst_title"]), $_POST["flst_language"]);
279  $this->content_obj->appendItem($fileObj->getId(), $fileObj->getFileName(),
280  $fileObj->getFileType());
281 
282  $this->updated = $this->pg_obj->update();
283  if ($this->updated === true)
284  {
285  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
286  }
287  else
288  {
289  $this->insert();
290  }
291  }
292 
296  function edit()
297  {
298  $this->setTabs(false);
299 
300  $form = $this->initEditForm();
301  $this->tpl->setContent($form->getHTML());
302  }
303 
309  public function initEditForm($a_mode = "edit")
310  {
311  global $lng, $ilCtrl, $ilUser;
312 
313  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
314  $form = new ilPropertyFormGUI();
315 
316  if ($a_mode != "add_file")
317  {
318  // title
319  $ti = new ilTextInputGUI($lng->txt("title"), "flst_title");
320  $ti->setMaxLength(80);
321  $ti->setSize(40);
322  $form->addItem($ti);
323 
324  // language
325  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
327  $si = new ilSelectInputGUI($lng->txt("language"), "flst_language");
328  $si->setOptions($lang);
329  $form->addItem($si);
330  }
331 
332  if (in_array($a_mode, array("create", "add_file")))
333  {
334  // file
335  $fi = new ilFileInputGUI($lng->txt("file"), "file");
336  $fi->setRequired(true);
337  $form->addItem($fi);
338  }
339  else if (in_array($a_mode, array("select_file")))
340  {
341  // file
342  $ne = new ilNonEditableValueGUI($lng->txt("file"), "");
343 
344  if(isset($_GET["file_ref_id"]))
345  {
346  include_once("./Modules/File/classes/class.ilObjFile.php");
347  $file_obj = new ilObjFile((int) $_GET["file_ref_id"]);
348  if (is_object($file_obj))
349  {
350  // ref id as hidden input
351  $hi = new ilHiddenInputGUI("file_ref_id");
352  $hi->setValue((int) $_GET["file_ref_id"]);
353  $form->addItem($hi);
354 
355  $ne->setValue($file_obj->getTitle());
356  }
357  }
358  else if(isset($_GET["fl_wsp_id"]))
359  {
360  // we need the object id for the instance
361  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
362  $tree = new ilWorkspaceTree($ilUser->getId());
363  $node = $tree->getNodeData((int) $_GET["fl_wsp_id"]);
364 
365  include_once("./Modules/File/classes/class.ilObjFile.php");
366  $file_obj = new ilObjFile($node["obj_id"], false);
367  if (is_object($file_obj))
368  {
369  // ref id as hidden input
370  $hi = new ilHiddenInputGUI("file_ref_id");
371  $hi->setValue("wsp_".(int) $node["obj_id"]);
372  $form->addItem($hi);
373 
374  $ne->setValue($file_obj->getTitle());
375  }
376  $this->tpl->parseCurrentBlock();
377  }
378 
379  $form->addItem($ne);
380  }
381 
382 
383  switch ($a_mode)
384  {
385  case "edit";
386  $ti->setValue($this->content_obj->getListTitle());
387  $si->setValue($this->content_obj->getLanguage());
388  $form->addCommandButton("saveProperties", $lng->txt("save"));
389  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
390  $form->setTitle($lng->txt("cont_edit_file_list_properties"));
391  break;
392 
393  case "create":
394  case "select_file":
395  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
396  {
397  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
398  }
399  else
400  {
401  $s_lang = $ilUser->getLanguage();
402  }
403  $si->setValue($s_lang);
404  $form->addCommandButton("create_flst", $lng->txt("save"));
405  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
406  $form->setTitle($lng->txt("cont_insert_file_list"));
407  break;
408 
409  case "add_file":
410  $form->addCommandButton("insertNewFileItem", $lng->txt("save"));
411  $form->addCommandButton("editFiles", $lng->txt("cancel"));
412  $form->setTitle($lng->txt("cont_insert_file_item"));
413  break;
414  }
415 
416  $form->setFormAction($ilCtrl->getFormAction($this));
417 
418  return $form;
419  }
420 
421 
425  function saveProperties()
426  {
427  $this->content_obj->setListTitle(ilUtil::stripSlashes($_POST["flst_title"]),
428  ilUtil::stripSlashes($_POST["flst_language"]));
429  $this->updated = $this->pg_obj->update();
430  if ($this->updated === true)
431  {
432  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
433  }
434  else
435  {
436  $this->pg_obj->addHierIDs();
437  $this->edit();
438  }
439  }
440 
444  function editFiles()
445  {
446  global $tpl, $ilToolbar, $ilCtrl, $lng;
447 
448  $this->setTabs(false);
449 
450  $ilToolbar->addButton($lng->txt("cont_add_file"),
451  $ilCtrl->getLinkTarget($this, "addFileItem"));
452 
453  include_once("./Services/COPage/classes/class.ilPCFileListTableGUI.php");
454  $table_gui = new ilPCFileListTableGUI($this, "editFiles", $this->content_obj);
455  $tpl->setContent($table_gui->getHTML());
456  }
457 
461  function setTabs($a_create = true)
462  {
463  global $ilTabs, $ilCtrl, $lng, $ilSetting;
464 
465  if ($a_create)
466  {
467  $cmd = "insert";
468 
469  $ilCtrl->setParameter($this, "subCmd", "insertNew");
470  $ilTabs->addSubTabTarget("cont_new_file",
471  $ilCtrl->getLinkTarget($this, $cmd), $cmd);
472 
473  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
474  $ilTabs->addSubTabTarget("cont_file_from_repository",
475  $ilCtrl->getLinkTarget($this, $cmd), $cmd);
476  $ilCtrl->setParameter($this, "subCmd", "");
477 
478  if(!$ilSetting->get("disable_personal_workspace") &&
479  !$ilSetting->get("disable_wsp_files"))
480  {
481  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
482  $ilTabs->addSubTabTarget("cont_file_from_workspace",
483  $ilCtrl->getLinkTarget($this, $cmd), $cmd);
484  $ilCtrl->setParameter($this, "subCmd", "");
485  }
486  }
487  else
488  {
489  $ilTabs->setBackTarget($lng->txt("pg"),
490  $this->ctrl->getParentReturn($this));
491 
492  $ilTabs->addTarget("cont_ed_edit_files",
493  $ilCtrl->getLinkTarget($this, "editFiles"), "editFiles",
494  get_class($this));
495 
496  $ilTabs->addTarget("cont_ed_edit_prop",
497  $ilCtrl->getLinkTarget($this, "edit"), "edit",
498  get_class($this));
499 
500  }
501  }
502 
507  function addFileItem()
508  {
509  global $ilCtrl;
510 
511  $files = $this->content_obj->getFileList();
512 
513  if (count($files) >= 1)
514  {
515  $ilCtrl->setParameterByClass("ilpcfileitemgui", "hier_id",
516  $files[count($files) - 1]["hier_id"]);
517  $ilCtrl->setParameterByClass("ilpcfileitemgui", "pc_id",
518  $files[count($files) - 1]["pc_id"]);
519  $ilCtrl->redirectByClass("ilpcfileitemgui", "newItemAfter");
520  }
521  else
522  {
523  $ilCtrl->redirect($this, "newFileItem");
524  }
525  }
526 
530  function deleteFileItem()
531  {
532  global $ilCtrl;
533 
534  if (is_array($_POST["fid"]))
535  {
536  $ids = array();
537  foreach($_POST["fid"] as $k => $v)
538  {
539  $ids[] = $k;
540  }
541  $this->content_obj->deleteFileItems($ids);
542  }
543  $this->updated = $this->pg_obj->update();
544  $ilCtrl->redirect($this, "editFiles");
545  }
546 
550  function savePositions()
551  {
552  global $ilCtrl;
553 
554  if (is_array($_POST["position"]))
555  {
556  $this->content_obj->savePositions($_POST["position"]);
557  }
558  $this->updated = $this->pg_obj->update();
559  $ilCtrl->redirect($this, "editFiles");
560  }
561 
566  {
567  global $ilCtrl;
568 
569  if (is_array($_POST["position"]))
570  {
571  $this->content_obj->savePositions($_POST["position"]);
572  }
573  if (is_array($_POST["class"]))
574  {
575  $this->content_obj->saveStyleClasses($_POST["class"]);
576  }
577  $this->updated = $this->pg_obj->update();
578  $ilCtrl->redirect($this, "editFiles");
579  }
580 
585  {
586  // check whether there is more than one style class
587  $chars = $this->getCharacteristics();
588 
589  $classes = $this->content_obj->getAllClasses();
590  if (count($chars) > 1)
591  {
592  return true;
593  }
594  foreach ($classes as $class)
595  {
596  if ($class != "" && $class != "FileListItem")
597  {
598  return true;
599  }
600  }
601  return false;
602  }
603 
604  //
605  //
606  // New file item
607  //
608  //
609 
616  function newFileItem()
617  {
618  global $ilTabs;
619 
620  if ($_GET["subCmd"] == "insertNew")
621  {
622  $_SESSION["cont_file_insert"] = "insertNew";
623  }
624  if ($_GET["subCmd"] == "insertFromRepository")
625  {
626  $_SESSION["cont_file_insert"] = "insertFromRepository";
627  }
628  if ($_GET["subCmd"] == "insertFromWorkspace")
629  {
630  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
631  }
632  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
633  {
634  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
635  }
636 
637  switch ($_GET["subCmd"])
638  {
639  case "insertFromWorkspace":
640  $this->insertFromWorkspace("newFileItem");
641  break;
642 
643  case "insertFromRepository":
644  $this->insertFromRepository("newFileItem");
645  break;
646 
647  case "selectFile":
648  $this->insertNewFileItem($_GET["file_ref_id"]);
649  break;
650 
651  default:
652  $this->setItemTabs("newFileItem");
653  $ilTabs->setSubTabActive("cont_new_file");
654 
655  $this->displayValidationError();
656 
657  $form = $this->initEditForm("add_file");
658  $this->tpl->setContent($form->getHTML());
659  break;
660  }
661  }
662 
666  function insertNewFileItem($a_file_ref_id = 0)
667  {
668  global $ilUser;
669 
670  // from personal workspace
671  if(isset($_GET["fl_wsp_id"]))
672  {
673  // we need the object id for the instance
674  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
675  $tree = new ilWorkspaceTree($ilUser->getId());
676  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
677 
678  include_once("./Modules/File/classes/class.ilObjFile.php");
679  $file_obj = new ilObjFile($node["obj_id"], false);
680  }
681  // upload
682  else if ($a_file_ref_id == 0)
683  {
684  $file_obj = $this->createFileItem();
685  }
686  // from repository
687  else
688  {
689  include_once("./Modules/File/classes/class.ilObjFile.php");
690  $file_obj = new ilObjFile($a_file_ref_id);
691  }
692  if (is_object($file_obj))
693  {
694  $this->content_obj->appendItem($file_obj->getId(),
695  $file_obj->getTitle(), $file_obj->getFileType());
696  $this->updated = $this->pg_obj->update();
697  if ($this->updated === true)
698  {
699  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
700  $this->ctrl->redirect($this, "editFiles");
701  }
702  }
703 
704  $_GET["subCmd"] = "-";
705  $this->newFileItem();
706  }
707 
711  function createFileItem()
712  {
713  global $lng;
714 
715  if ($_FILES["file"]["name"] == "")
716  {
717  $_GET["subCmd"] = "-";
718  ilUtil::sendFailure($lng->txt("upload_error_file_not_found"));
719  return false;
720  }
721  include_once("./Modules/File/classes/class.ilObjFile.php");
722  $fileObj = new ilObjFile();
723  $fileObj->setType("file");
724  $fileObj->setTitle($_FILES["file"]["name"]);
725  $fileObj->setDescription("");
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->raiseUploadError(false);
732  // upload file to filesystem
733  $fileObj->createDirectory();
734  $fileObj->getUploadFile($_FILES["file"]["tmp_name"],
735  $_FILES["file"]["name"]);
736 
737  return $fileObj;
738  }
739 
740 
744  function setItemTabs($a_cmd = "")
745  {
746  global $ilTabs, $ilCtrl, $ilSetting;
747 
748  $ilTabs->addTarget("cont_back",
749  $this->ctrl->getParentReturn($this), "",
750  "");
751 
752  if ($a_cmd != "")
753  {
754  $ilCtrl->setParameter($this, "subCmd", "insertNew");
755  $ilTabs->addSubTabTarget("cont_new_file",
756  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
757 
758  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
759  $ilTabs->addSubTabTarget("cont_file_from_repository",
760  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
761  $ilCtrl->setParameter($this, "subCmd", "");
762 
763  if(!$ilSetting->get("disable_personal_workspace") &&
764  !$ilSetting->get("disable_wsp_files"))
765  {
766  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
767  $ilTabs->addSubTabTarget("cont_file_from_workspace",
768  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
769  $ilCtrl->setParameter($this, "subCmd", "");
770  }
771  }
772  }
773 
774 
775 }
776 ?>