ILIAS  eassessment Revision 61809
 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"] == "") && $_SESSION["cont_file_insert"] != "")
69  {
70  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
71  }
72 
73  switch ($_GET["subCmd"])
74  {
75  case "insertFromRepository":
76  $this->insertFromRepository();
77  break;
78 
79  case "selectFile":
80  $this->selectFile();
81  break;
82 
83  default:
84  $this->setTabs();
85  $ilTabs->setSubTabActive("cont_new_file");
86 
87  // new file list form
88  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_list_new.html", "Services/COPage");
89 
90  $this->tpl->setCurrentBlock("new_file");
91  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
92  $this->tpl->parseCurrentBlock();
93 
94  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_list"));
95  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
96 
97  $this->displayValidationError();
98 
99  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
100  {
101  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
102  }
103  else
104  {
105  $s_lang = $ilUser->getLanguage();
106  }
107 
108 
109  // title
110  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
111  $this->tpl->setVariable("INPUT_TITLE", "flst_title");
112 
113  // language
114  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
115  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
117  $select_lang = ilUtil::formSelect ($s_lang, "flst_language",$lang,false,true);
118  $this->tpl->setVariable("SELECT_LANGUAGE", $select_lang);
119 
120 
121  $this->tpl->parseCurrentBlock();
122 
123  // operations
124  $this->tpl->setCurrentBlock("commands");
125  $this->tpl->setVariable("BTN_NAME", "create_flst");
126  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
127  $this->tpl->setVariable("BTN_CANCEL", "cancelCreate");
128  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
129  $this->tpl->parseCurrentBlock();
130  break;
131  }
132 
133  }
134 
138  function selectFile()
139  {
140  global $ilTabs, $ilUser;
141 
142  $this->setTabs();
143  $ilTabs->setSubTabActive("cont_file_from_repository");
144 
145  // new file list form
146  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_list_new.html", "Services/COPage");
147 
148  $this->tpl->setCurrentBlock("rep_file");
149  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
150  include_once("./Modules/File/classes/class.ilObjFile.php");
151  $file_obj = new ilObjFile($_GET["file_ref_id"]);
152  if (is_object($file_obj))
153  {
154  $this->tpl->setVariable("TXT_FILE_TITLE", $file_obj->getTitle());
155  $this->tpl->setVariable("FILE_REF_ID", $file_obj->getRefId());
156  }
157  $this->tpl->parseCurrentBlock();
158 
159  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_list"));
160  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
161 
162  $this->displayValidationError();
163 
164  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
165  {
166  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
167  }
168  else
169  {
170  $s_lang = $ilUser->getLanguage();
171  }
172 
173  // select fields for number of columns
174  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
175  $this->tpl->setVariable("INPUT_TITLE", "flst_title");
176 
177  // language
178  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
179  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
181  $select_lang = ilUtil::formSelect ($s_lang, "flst_language",$lang,false,true);
182  $this->tpl->setVariable("SELECT_LANGUAGE", $select_lang);
183 
184 // $this->tpl->parseCurrentBlock();
185 
186  // operations
187  $this->tpl->setCurrentBlock("commands");
188  $this->tpl->setVariable("BTN_NAME", "create_flst");
189  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
190  $this->tpl->setVariable("BTN_CANCEL", "cancelCreate");
191  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
192  $this->tpl->parseCurrentBlock();
193  }
194 
198  function insertFromRepository($a_cmd = "insert")
199  {
200  global $ilTabs, $tree, $ilCtrl, $tpl;
201 
202  if ($a_cmd == "insert")
203  {
204  $this->setTabs();
205  }
206  else
207  {
208  $this->setItemTabs($a_cmd);
209  }
210 
211  $ilTabs->setSubTabActive("cont_file_from_repository");
212 
213  include_once "./Services/COPage/classes/class.ilFileSelectorGUI.php";
214 
215  $exp = new ilFileSelectorGUI($this->ctrl->getLinkTarget($this, $a_cmd));
216 
217  if ($_GET["expand"] == "")
218  {
219  $expanded = $tree->readRootId();
220  }
221  else
222  {
223  $expanded = $_GET["expand"];
224  }
225  $exp->setExpand($expanded);
226 
227  $exp->setTargetGet("sel_id");
228  //$this->ctrl->setParameter($this, "target_type", $a_type);
229  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
230  $exp->setParamsGet($this->ctrl->getParameterArray($this, $a_cmd));
231 
232  // filter
233  $exp->setFiltered(true);
234  $exp->setFilterMode(IL_FM_POSITIVE);
235  $exp->addFilter("root");
236  $exp->addFilter("cat");
237  $exp->addFilter("grp");
238  $exp->addFilter("fold");
239  $exp->addFilter("crs");
240  $exp->addFilter("file");
241 
242  $sel_types = array('file');
243 
244  $exp->setOutput(0);
245 
246  $tpl->setContent($exp->getOutput());
247  }
248 
249 
253  function create()
254  {
255  include_once("./Modules/File/classes/class.ilObjFile.php");
256 
257  if ($_POST["file_ref_id"] == 0)
258  {
259  $fileObj = new ilObjFile();
260  $fileObj->setType("file");
261  $fileObj->setTitle($_FILES["Fobject"]["name"]["file"]);
262  $fileObj->setDescription("");
263  $fileObj->setFileName($_FILES["Fobject"]["name"]["file"]);
264  $fileObj->setFileType($_FILES["Fobject"]["type"]["file"]);
265  $fileObj->setFileSize($_FILES["Fobject"]["size"]["file"]);
266  $fileObj->setMode("filelist");
267  $fileObj->create();
268  // upload file to filesystem
269  $fileObj->createDirectory();
270  $fileObj->raiseUploadError(false);
271  $fileObj->getUploadFile($_FILES["Fobject"]["tmp_name"]["file"],
272  $_FILES["Fobject"]["name"]["file"]);
273  }
274  else
275  {
276  $fileObj = new ilObjFile($_POST["file_ref_id"]);
277  }
278  $_SESSION["il_text_lang_".$_GET["ref_id"]] = $_POST["flst_language"];
279 
280 //echo "::".is_object($this->dom).":";
281  $this->content_obj = new ilPCFileList($this->dom);
282  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
283  $this->content_obj->setListTitle(ilUtil::stripSlashes($_POST["flst_title"]), $_POST["flst_language"]);
284  $this->content_obj->appendItem($fileObj->getId(), $fileObj->getFileName(),
285  $fileObj->getFileType());
286 
287  $this->updated = $this->pg_obj->update();
288  if ($this->updated === true)
289  {
290  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
291  }
292  else
293  {
294  $this->insert();
295  }
296  }
297 
301  function edit()
302  {
303  $this->setTabs(false);
304 
305  // add paragraph edit template
306  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_list_edit.html", "Services/COPage");
307  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_edit_file_list_properties"));
308  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
309 
310  $this->displayValidationError();
311 
312  // select fields for number of columns
313  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
314  $this->tpl->setVariable("INPUT_TITLE", "flst_title");
315 
316  // todo: this doesnt work if title contains " quotes
317  // ... addslashes doesnt work
318  $this->tpl->setVariable("VALUE_TITLE", $this->content_obj->getListTitle());
319 
320  // language
321  $this->tpl->setVariable("TXT_LANGUAGE", $this->lng->txt("language"));
322  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
324  $select_lang = ilUtil::formSelect ($this->content_obj->getLanguage(),"flst_language",$lang,false,true);
325  $this->tpl->setVariable("SELECT_LANGUAGE", $select_lang);
326 
327 
328 // $this->tpl->parseCurrentBlock();
329 
330  // operations
331  $this->tpl->setCurrentBlock("commands");
332  $this->tpl->setVariable("BTN_NAME", "saveProperties");
333  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
334  $this->tpl->setVariable("BTN_CANCEL", "cancelUpdate");
335  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
336  $this->tpl->parseCurrentBlock();
337 
338  }
339 
340 
344  function saveProperties()
345  {
346  $this->content_obj->setListTitle(ilUtil::stripSlashes($_POST["flst_title"]),
347  $_POST["flst_language"]);
348  $this->updated = $this->pg_obj->update();
349  if ($this->updated === true)
350  {
351  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
352  }
353  else
354  {
355  $this->pg_obj->addHierIDs();
356  $this->edit();
357  }
358  }
359 
363  function editFiles()
364  {
365  global $tpl;
366 
367  $this->setTabs(false);
368  include_once("./Services/COPage/classes/class.ilPCFileListTableGUI.php");
369  $table_gui = new ilPCFileListTableGUI($this, "editFiles", $this->content_obj);
370  $tpl->setContent($table_gui->getHTML());
371  }
372 
376  function setTabs($a_create = true)
377  {
378  global $ilTabs, $ilCtrl, $lng;
379 
380  if ($a_create)
381  {
382  $cmd = "insert";
383 
384  $ilCtrl->setParameter($this, "subCmd", "insertNew");
385  $ilTabs->addSubTabTarget("cont_new_file",
386  $ilCtrl->getLinkTarget($this, $cmd), $cmd);
387 
388  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
389  $ilTabs->addSubTabTarget("cont_file_from_repository",
390  $ilCtrl->getLinkTarget($this, $cmd), $cmd);
391  $ilCtrl->setParameter($this, "subCmd", "");
392  }
393  else
394  {
395  $ilTabs->setBackTarget($lng->txt("pg"),
396  $this->ctrl->getParentReturn($this));
397 
398  $ilTabs->addTarget("cont_ed_edit_prop",
399  $ilCtrl->getLinkTarget($this, "edit"), "edit",
400  get_class($this));
401 
402  $ilTabs->addTarget("cont_ed_edit_files",
403  $ilCtrl->getLinkTarget($this, "editFiles"), "editFiles",
404  get_class($this));
405  }
406  }
407 
412  function addFileItem()
413  {
414  global $ilCtrl;
415 
416  $files = $this->content_obj->getFileList();
417 
418  if (count($files) >= 1)
419  {
420  $ilCtrl->setParameterByClass("ilpcfileitemgui", "hier_id",
421  $files[count($files) - 1]["hier_id"]);
422  $ilCtrl->setParameterByClass("ilpcfileitemgui", "pc_id",
423  $files[count($files) - 1]["pc_id"]);
424  $ilCtrl->redirectByClass("ilpcfileitemgui", "newItemAfter");
425  }
426  else
427  {
428  $ilCtrl->redirect($this, "newFileItem");
429  }
430  }
431 
435  function deleteFileItem()
436  {
437  global $ilCtrl;
438 
439  if (is_array($_POST["fid"]))
440  {
441  $ids = array();
442  foreach($_POST["fid"] as $k => $v)
443  {
444  $ids[] = $k;
445  }
446  $this->content_obj->deleteFileItems($ids);
447  }
448  $this->updated = $this->pg_obj->update();
449  $ilCtrl->redirect($this, "editFiles");
450  }
451 
455  function savePositions()
456  {
457  global $ilCtrl;
458 
459  if (is_array($_POST["position"]))
460  {
461  $this->content_obj->savePositions($_POST["position"]);
462  }
463  $this->updated = $this->pg_obj->update();
464  $ilCtrl->redirect($this, "editFiles");
465  }
466 
471  {
472  global $ilCtrl;
473 
474  if (is_array($_POST["position"]))
475  {
476  $this->content_obj->savePositions($_POST["position"]);
477  }
478  if (is_array($_POST["class"]))
479  {
480  $this->content_obj->saveStyleClasses($_POST["class"]);
481  }
482  $this->updated = $this->pg_obj->update();
483  $ilCtrl->redirect($this, "editFiles");
484  }
485 
490  {
491  // check whether there is more than one style class
492  $chars = $this->getCharacteristics();
493 
494  $classes = $this->content_obj->getAllClasses();
495  if (count($chars) > 1)
496  {
497  return true;
498  }
499  foreach ($classes as $class)
500  {
501  if ($class != "" && $class != "FileListItem")
502  {
503  return true;
504  }
505  }
506  return false;
507  }
508 
509  //
510  //
511  // New file item
512  //
513  //
514 
521  function newFileItem()
522  {
523  global $ilTabs;
524 
525  if ($_GET["subCmd"] == "insertNew")
526  {
527  $_SESSION["cont_file_insert"] = "insertNew";
528  }
529  if ($_GET["subCmd"] == "insertFromRepository")
530  {
531  $_SESSION["cont_file_insert"] = "insertFromRepository";
532  }
533  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
534  {
535  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
536  }
537 
538  switch ($_GET["subCmd"])
539  {
540  case "insertFromRepository":
541  $this->insertFromRepository("newFileItem");
542  break;
543 
544  case "selectFile":
545  $this->insertNewFileItem($_GET["file_ref_id"]);
546  break;
547 
548  default:
549  $this->setItemTabs("newFileItem");
550  $ilTabs->setSubTabActive("cont_new_file");
551 
552  // new file list form
553  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
554  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
555  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
556 
557  $this->displayValidationError();
558 
559  // file
560  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
561 
562  $this->tpl->parseCurrentBlock();
563 
564  // operations
565  $this->tpl->setCurrentBlock("commands");
566  $this->tpl->setVariable("BTN_NAME", "insertNewFileItem");
567  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
568  $this->tpl->parseCurrentBlock();
569  break;
570  }
571  }
572 
576  function insertNewFileItem($a_file_ref_id = 0)
577  {
578  if ($a_file_ref_id == 0)
579  {
580  $file_obj = $this->createFileItem();
581  }
582  else
583  {
584  include_once("./Modules/File/classes/class.ilObjFile.php");
585  $file_obj = new ilObjFile($a_file_ref_id);
586  }
587  if (is_object($file_obj))
588  {
589  $this->content_obj->appendItem($file_obj->getId(),
590  $file_obj->getTitle(), $file_obj->getFileType());
591  $this->updated = $this->pg_obj->update();
592  if ($this->updated === true)
593  {
594  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
595  }
596  }
597 
598  $_GET["subCmd"] = "-";
599  $this->newFileItem();
600  }
601 
605  function createFileItem()
606  {
607  global $lng;
608 
609  if ($_FILES["Fobject"]["name"]["file"] == "")
610  {
611  $_GET["subCmd"] = "-";
612  ilUtil::sendFailure($lng->txt("upload_error_file_not_found"));
613  return false;
614  }
615  include_once("./Modules/File/classes/class.ilObjFile.php");
616  $fileObj = new ilObjFile();
617  $fileObj->setType("file");
618  $fileObj->setTitle($_FILES["Fobject"]["name"]["file"]);
619  $fileObj->setDescription("");
620  $fileObj->setFileName($_FILES["Fobject"]["name"]["file"]);
621  $fileObj->setFileType($_FILES["Fobject"]["type"]["file"]);
622  $fileObj->setFileSize($_FILES["Fobject"]["size"]["file"]);
623  $fileObj->setMode("filelist");
624  $fileObj->create();
625  $fileObj->raiseUploadError(false);
626  // upload file to filesystem
627  $fileObj->createDirectory();
628  $fileObj->getUploadFile($_FILES["Fobject"]["tmp_name"]["file"],
629  $_FILES["Fobject"]["name"]["file"]);
630 
631  return $fileObj;
632  }
633 
634 
638  function setItemTabs($a_cmd = "")
639  {
640  global $ilTabs, $ilCtrl;
641 
642  $ilTabs->addTarget("cont_back",
643  $this->ctrl->getParentReturn($this), "",
644  "");
645 
646  if ($a_cmd != "")
647  {
648  $ilCtrl->setParameter($this, "subCmd", "insertNew");
649  $ilTabs->addSubTabTarget("cont_new_file",
650  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
651 
652  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
653  $ilTabs->addSubTabTarget("cont_file_from_repository",
654  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
655  $ilCtrl->setParameter($this, "subCmd", "");
656  }
657  }
658 
659 
660 }
661 ?>