ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCFileItemGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Services/COPage/classes/class.ilPCListItem.php");
25 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26 
38 {
39 
44  function ilPCFileItemGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
45  {
46  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
47  }
48 
52  function &executeCommand()
53  {
54  // get next class that processes or forwards current command
55  $next_class = $this->ctrl->getNextClass($this);
56 
57  // get current command
58  $cmd = $this->ctrl->getCmd();
59  switch($next_class)
60  {
61  default:
62  $ret =& $this->$cmd();
63  break;
64  }
65 
66  return $ret;
67  }
68 
72  function newFileItem()
73  {
74  global $lng;
75 
76  if ($_FILES["file"]["name"] == "")
77  {
78  $_GET["subCmd"] = "-";
79  ilUtil::sendFailure($lng->txt("upload_error_file_not_found"));
80  return false;
81  }
82  include_once("./Modules/File/classes/class.ilObjFile.php");
83  $fileObj = new ilObjFile();
84  $fileObj->setType("file");
85  $fileObj->setTitle($_FILES["file"]["name"]);
86  $fileObj->setDescription("");
87  $fileObj->setFileName($_FILES["file"]["name"]);
88  $fileObj->setFileType($_FILES["file"]["type"]);
89  $fileObj->setFileSize($_FILES["file"]["size"]);
90  $fileObj->setMode("filelist");
91  $fileObj->create();
92  $fileObj->raiseUploadError(false);
93  // upload file to filesystem
94  $fileObj->createDirectory();
95  $fileObj->getUploadFile($_FILES["file"]["tmp_name"],
96  $_FILES["file"]["name"]);
97 
98  $this->file_object =& $fileObj;
99  return true;
100  }
101 
102 
106  function newItemAfter()
107  {
108  global $ilTabs;
109 
110  if ($_GET["subCmd"] == "insertNew")
111  {
112  $_SESSION["cont_file_insert"] = "insertNew";
113  }
114  if ($_GET["subCmd"] == "insertFromRepository")
115  {
116  $_SESSION["cont_file_insert"] = "insertFromRepository";
117  }
118  if ($_GET["subCmd"] == "insertFromWorkspace")
119  {
120  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
121  }
122  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
123  {
124  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
125  }
126 
127  switch ($_GET["subCmd"])
128  {
129  case "insertFromWorkspace":
130  $this->insertFromWorkspace("newItemAfter");
131  break;
132 
133  case "insertFromRepository":
134  $this->insertFromRepository("newItemAfter");
135  break;
136 
137  case "selectFile":
138  $this->insertNewItemAfter($_GET["file_ref_id"]);
139  break;
140 
141  default:
142  $this->setTabs("newItemAfter");
143  $ilTabs->setSubTabActive("cont_new_file");
144 
145  $this->displayValidationError();
146  $form = $this->initAddFileForm(false);
147  $this->tpl->setContent($form->getHTML());
148 break;
149 
150  // new file list form
151  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
152  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
153  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
154 
155  $this->displayValidationError();
156 
157  // file
158  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
159 
160  $this->tpl->parseCurrentBlock();
161 
162  // operations
163  $this->tpl->setCurrentBlock("commands");
164  $this->tpl->setVariable("BTN_NAME", "insertNewItemAfter");
165  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
166  $this->tpl->parseCurrentBlock();
167  break;
168  }
169  }
170 
174  public function initAddFileForm($a_before = true)
175  {
176  global $lng, $ilCtrl, $ilUser;
177 
178  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
179  $form = new ilPropertyFormGUI();
180 
181  // file
182  $fi = new ilFileInputGUI($lng->txt("file"), "file");
183  $fi->setRequired(true);
184  $form->addItem($fi);
185 
186  if ($a_before)
187  {
188  $form->addCommandButton("insertNewItemBefore", $lng->txt("save"));
189  }
190  else
191  {
192  $form->addCommandButton("insertNewItemAfter", $lng->txt("save"));
193  }
194  $form->addCommandButton("cancelAddFile", $lng->txt("cancel"));
195 
196  $form->setTitle($lng->txt("cont_insert_file_item"));
197 
198  $form->setFormAction($ilCtrl->getFormAction($this));
199 
200  return $form;
201  }
202 
203 
207  function insertFromRepository($a_cmd)
208  {
209  global $ilTabs, $tree, $ilCtrl, $tpl;
210 
211  $this->setTabs($a_cmd);
212  $ilTabs->setSubTabActive("cont_file_from_repository");
213 
214  include_once "./Services/COPage/classes/class.ilFileSelectorGUI.php";
215 
216  $exp = new ilFileSelectorGUI($this->ctrl->getLinkTarget($this, $a_cmd),
217  "ilpcfileitemgui");
218 
219  if ($_GET["expand"] == "")
220  {
221  $expanded = $tree->readRootId();
222  }
223  else
224  {
225  $expanded = $_GET["expand"];
226  }
227  $exp->setExpand($expanded);
228 
229  $exp->setTargetGet("sel_id");
230  //$this->ctrl->setParameter($this, "target_type", $a_type);
231  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
232  $exp->setParamsGet($this->ctrl->getParameterArray($this, $a_cmd));
233 
234  // filter
235  $exp->setFiltered(true);
236  $exp->setFilterMode(IL_FM_POSITIVE);
237  $exp->addFilter("root");
238  $exp->addFilter("cat");
239  $exp->addFilter("grp");
240  $exp->addFilter("fold");
241  $exp->addFilter("crs");
242  $exp->addFilter("file");
243 
244  $sel_types = array('file');
245 
246  $exp->setOutput(0);
247 
248  $tpl->setContent($exp->getOutput());
249  }
250 
254  function insertFromWorkspace($a_cmd = "insert")
255  {
256  global $ilTabs, $tree, $ilCtrl, $tpl, $ilUser;
257 
258  $this->setTabs($a_cmd);
259  $ilTabs->setSubTabActive("cont_file_from_workspace");
260 
261  // get ws tree
262  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
263  $tree = new ilWorkspaceTree($ilUser->getId());
264 
265  // get access handler
266  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
267  $acc_handler = new ilWorkspaceAccessHandler($tree);
268 
269  // get es explorer
270  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceExplorer.php");
272  'filelist_wspexpand', $tree, $acc_handler);
273  $exp->setTargetGet('fl_wsp_id');
274  $exp->setFiltered(false);
275  $exp->removeAllFormItemTypes();
276 
277  // select link
278  $exp->setTypeClickable("file");
279  $ilCtrl->setParameter($this, "subCmd", "selectFile");
280  $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
281 
282  // filter
283  $exp->setFiltered(true);
284  $exp->setFilterMode(IL_FM_POSITIVE);
285  $exp->addFilter("wsrt");
286  $exp->addFilter("wfld");
287  $exp->addFilter("file");
288 
289  // expand link
290  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
291  $exp->setParamsGet($ilCtrl->getParameterArray($this, $a_cmd));
292 
293  if($_GET['filelist_wspexpand'] == '')
294  {
295  $expanded = $tree->readRootId();
296  }
297  else
298  {
299  $expanded = $_GET['filelist_wspexpand'];
300  }
301  $exp->setExpand($expanded);
302  $exp->setOutput(0);
303 
304  $tpl->setContent($exp->getOutput());
305  }
306 
310  function insertNewItemAfter($a_file_ref_id = 0)
311  {
312  global $ilUser;
313 
314  $res = true;
315  if(isset($_GET["fl_wsp_id"]))
316  {
317  // we need the object id for the instance
318  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
319  $tree = new ilWorkspaceTree($ilUser->getId());
320  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
321 
322  include_once("./Modules/File/classes/class.ilObjFile.php");
323  $this->file_object = new ilObjFile($node["obj_id"], false);
324  }
325  else if ($a_file_ref_id == 0)
326  {
327  $res = $this->newFileItem();
328  }
329  else
330  {
331  include_once("./Modules/File/classes/class.ilObjFile.php");
332  $this->file_object = new ilObjFile($a_file_ref_id);
333  }
334  if ($res)
335  {
336  $this->content_obj->newItemAfter($this->file_object->getId(),
337  $this->file_object->getTitle(), $this->file_object->getFileType());
338  $this->updated = $this->pg_obj->update();
339  if ($this->updated === true)
340  {
341  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
342  }
343  }
344 
345  $_GET["subCmd"] = "-";
346  $this->newItemAfter();
347  }
348 
352  function newItemBefore()
353  {
354  global $ilTabs;
355 
356  if ($_GET["subCmd"] == "insertNew")
357  {
358  $_SESSION["cont_file_insert"] = "insertNew";
359  }
360  if ($_GET["subCmd"] == "insertFromRepository")
361  {
362  $_SESSION["cont_file_insert"] = "insertFromRepository";
363  }
364  if ($_GET["subCmd"] == "insertFromWorkspace")
365  {
366  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
367  }
368  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
369  {
370  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
371  }
372 
373  switch ($_GET["subCmd"])
374  {
375  case "insertFromWorkspace":
376  $this->insertFromWorkspace("newItemBefore");
377  break;
378 
379  case "insertFromRepository":
380  $this->insertFromRepository("newItemBefore");
381  break;
382 
383  case "selectFile":
384  $this->insertNewItemBefore($_GET["file_ref_id"]);
385  break;
386 
387  default:
388  $this->setTabs("newItemBefore");
389  $ilTabs->setSubTabActive("cont_new_file");
390 
391  $this->displayValidationError();
392  $form = $this->initAddFileForm(true);
393  $this->tpl->setContent($form->getHTML());
394 break;
395 
396  // new file list form
397  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
398  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
399  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
400 
401  $this->displayValidationError();
402 
403  // file
404  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
405 
406  $this->tpl->parseCurrentBlock();
407 
408  // operations
409  $this->tpl->setCurrentBlock("commands");
410  $this->tpl->setVariable("BTN_NAME", "insertNewItemBefore");
411  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
412  $this->tpl->parseCurrentBlock();
413  break;
414  }
415 
416  }
417 
421  function insertNewItemBefore($a_file_ref_id = 0)
422  {
423  global $ilUser;
424 
425  $res = true;
426  if(isset($_GET["fl_wsp_id"]))
427  {
428  // we need the object id for the instance
429  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
430  $tree = new ilWorkspaceTree($ilUser->getId());
431  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
432 
433  include_once("./Modules/File/classes/class.ilObjFile.php");
434  $this->file_object = new ilObjFile($node["obj_id"], false);
435  }
436  else if ($a_file_ref_id == 0)
437  {
438  $res = $this->newFileItem();
439  }
440  else
441  {
442  include_once("./Modules/File/classes/class.ilObjFile.php");
443  $this->file_object = new ilObjFile($a_file_ref_id);
444  }
445  if ($res)
446  {
447  $this->content_obj->newItemBefore($this->file_object->getId(),
448  $this->file_object->getTitle(), $this->file_object->getFileType());
449  $this->updated = $this->pg_obj->update();
450  if ($this->updated === true)
451  {
452  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
453  }
454  }
455 
456  $_GET["subCmd"] = "-";
457  $this->newItemBefore();
458  }
459 
463  function deleteItem()
464  {
465  $this->content_obj->deleteItem();
466  $_SESSION["il_pg_error"] = $this->pg_obj->update();
467  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
468  }
469 
473  function setTabs($a_cmd = "")
474  {
475  global $ilTabs, $ilCtrl, $ilSetting;
476 
477  $ilTabs->addTarget("cont_back",
478  $this->ctrl->getParentReturn($this), "",
479  "");
480 
481  if ($a_cmd != "")
482  {
483  $ilCtrl->setParameter($this, "subCmd", "insertNew");
484  $ilTabs->addSubTabTarget("cont_new_file",
485  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
486 
487  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
488  $ilTabs->addSubTabTarget("cont_file_from_repository",
489  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
490  $ilCtrl->setParameter($this, "subCmd", "");
491 
492  if(!$ilSetting->get("disable_personal_workspace") &&
493  !$ilSetting->get("disable_wsp_files"))
494  {
495  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
496  $ilTabs->addSubTabTarget("cont_file_from_workspace",
497  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
498  $ilCtrl->setParameter($this, "subCmd", "");
499  }
500  }
501  }
502 
506  function moveItemDown()
507  {
508  $this->content_obj->moveItemDown();
509  $_SESSION["il_pg_error"] = $this->pg_obj->update();
510  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
511  }
512 
516  function moveItemUp()
517  {
518  $this->content_obj->moveItemUp();
519  $_SESSION["il_pg_error"] = $this->pg_obj->update();
520  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
521  }
522 
526  function cancelAddFile()
527  {
528  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
529  }
530 }
531 ?>