ILIAS  Release_4_2_x_branch Revision 61807
 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["Fobject"]["name"]["file"] == "")
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["Fobject"]["name"]["file"]);
86  $fileObj->setDescription("");
87  $fileObj->setFileName($_FILES["Fobject"]["name"]["file"]);
88  $fileObj->setFileType($_FILES["Fobject"]["type"]["file"]);
89  $fileObj->setFileSize($_FILES["Fobject"]["size"]["file"]);
90  $fileObj->setMode("filelist");
91  $fileObj->create();
92  $fileObj->raiseUploadError(false);
93  // upload file to filesystem
94  $fileObj->createDirectory();
95  $fileObj->getUploadFile($_FILES["Fobject"]["tmp_name"]["file"],
96  $_FILES["Fobject"]["name"]["file"]);
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  // new file list form
146  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
147  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
148  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
149 
150  $this->displayValidationError();
151 
152  // file
153  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
154 
155  $this->tpl->parseCurrentBlock();
156 
157  // operations
158  $this->tpl->setCurrentBlock("commands");
159  $this->tpl->setVariable("BTN_NAME", "insertNewItemAfter");
160  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
161  $this->tpl->parseCurrentBlock();
162  break;
163  }
164  }
165 
169  function insertFromRepository($a_cmd)
170  {
171  global $ilTabs, $tree, $ilCtrl, $tpl;
172 
173  $this->setTabs($a_cmd);
174  $ilTabs->setSubTabActive("cont_file_from_repository");
175 
176  include_once "./Services/COPage/classes/class.ilFileSelectorGUI.php";
177 
178  $exp = new ilFileSelectorGUI($this->ctrl->getLinkTarget($this, $a_cmd),
179  "ilpcfileitemgui");
180 
181  if ($_GET["expand"] == "")
182  {
183  $expanded = $tree->readRootId();
184  }
185  else
186  {
187  $expanded = $_GET["expand"];
188  }
189  $exp->setExpand($expanded);
190 
191  $exp->setTargetGet("sel_id");
192  //$this->ctrl->setParameter($this, "target_type", $a_type);
193  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
194  $exp->setParamsGet($this->ctrl->getParameterArray($this, $a_cmd));
195 
196  // filter
197  $exp->setFiltered(true);
198  $exp->setFilterMode(IL_FM_POSITIVE);
199  $exp->addFilter("root");
200  $exp->addFilter("cat");
201  $exp->addFilter("grp");
202  $exp->addFilter("fold");
203  $exp->addFilter("crs");
204  $exp->addFilter("file");
205 
206  $sel_types = array('file');
207 
208  $exp->setOutput(0);
209 
210  $tpl->setContent($exp->getOutput());
211  }
212 
216  function insertFromWorkspace($a_cmd = "insert")
217  {
218  global $ilTabs, $tree, $ilCtrl, $tpl, $ilUser;
219 
220  $this->setTabs($a_cmd);
221  $ilTabs->setSubTabActive("cont_file_from_workspace");
222 
223  // get ws tree
224  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
225  $tree = new ilWorkspaceTree($ilUser->getId());
226 
227  // get access handler
228  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
229  $acc_handler = new ilWorkspaceAccessHandler($tree);
230 
231  // get es explorer
232  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceExplorer.php");
234  'filelist_wspexpand', $tree, $acc_handler);
235  $exp->setTargetGet('fl_wsp_id');
236  $exp->setFiltered(false);
237  $exp->removeAllFormItemTypes();
238 
239  // select link
240  $exp->setTypeClickable("file");
241  $ilCtrl->setParameter($this, "subCmd", "selectFile");
242  $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
243 
244  // filter
245  $exp->setFiltered(true);
246  $exp->setFilterMode(IL_FM_POSITIVE);
247  $exp->addFilter("wsrt");
248  $exp->addFilter("wfld");
249  $exp->addFilter("file");
250 
251  // expand link
252  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
253  $exp->setParamsGet($ilCtrl->getParameterArray($this, $a_cmd));
254 
255  if($_GET['filelist_wspexpand'] == '')
256  {
257  $expanded = $tree->readRootId();
258  }
259  else
260  {
261  $expanded = $_GET['filelist_wspexpand'];
262  }
263  $exp->setExpand($expanded);
264  $exp->setOutput(0);
265 
266  $tpl->setContent($exp->getOutput());
267  }
268 
272  function insertNewItemAfter($a_file_ref_id = 0)
273  {
274  global $ilUser;
275 
276  $res = true;
277  if(isset($_GET["fl_wsp_id"]))
278  {
279  // we need the object id for the instance
280  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
281  $tree = new ilWorkspaceTree($ilUser->getId());
282  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
283 
284  include_once("./Modules/File/classes/class.ilObjFile.php");
285  $this->file_object = new ilObjFile($node["obj_id"], false);
286  }
287  else if ($a_file_ref_id == 0)
288  {
289  $res = $this->newFileItem();
290  }
291  else
292  {
293  include_once("./Modules/File/classes/class.ilObjFile.php");
294  $this->file_object = new ilObjFile($a_file_ref_id);
295  }
296  if ($res)
297  {
298  $this->content_obj->newItemAfter($this->file_object->getId(),
299  $this->file_object->getTitle(), $this->file_object->getFileType());
300  $this->updated = $this->pg_obj->update();
301  if ($this->updated === true)
302  {
303  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
304  }
305  }
306 
307  $_GET["subCmd"] = "-";
308  $this->newItemAfter();
309  }
310 
314  function newItemBefore()
315  {
316  global $ilTabs;
317 
318  if ($_GET["subCmd"] == "insertNew")
319  {
320  $_SESSION["cont_file_insert"] = "insertNew";
321  }
322  if ($_GET["subCmd"] == "insertFromRepository")
323  {
324  $_SESSION["cont_file_insert"] = "insertFromRepository";
325  }
326  if ($_GET["subCmd"] == "insertFromWorkspace")
327  {
328  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
329  }
330  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
331  {
332  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
333  }
334 
335  switch ($_GET["subCmd"])
336  {
337  case "insertFromWorkspace":
338  $this->insertFromWorkspace("newItemBefore");
339  break;
340 
341  case "insertFromRepository":
342  $this->insertFromRepository("newItemBefore");
343  break;
344 
345  case "selectFile":
346  $this->insertNewItemBefore($_GET["file_ref_id"]);
347  break;
348 
349  default:
350  $this->setTabs("newItemBefore");
351  $ilTabs->setSubTabActive("cont_new_file");
352 
353  // new file list form
354  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
355  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
356  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
357 
358  $this->displayValidationError();
359 
360  // file
361  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
362 
363  $this->tpl->parseCurrentBlock();
364 
365  // operations
366  $this->tpl->setCurrentBlock("commands");
367  $this->tpl->setVariable("BTN_NAME", "insertNewItemBefore");
368  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
369  $this->tpl->parseCurrentBlock();
370  break;
371  }
372 
373  }
374 
378  function insertNewItemBefore($a_file_ref_id = 0)
379  {
380  global $ilUser;
381 
382  $res = true;
383  if(isset($_GET["fl_wsp_id"]))
384  {
385  // we need the object id for the instance
386  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
387  $tree = new ilWorkspaceTree($ilUser->getId());
388  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
389 
390  include_once("./Modules/File/classes/class.ilObjFile.php");
391  $this->file_object = new ilObjFile($node["obj_id"], false);
392  }
393  else if ($a_file_ref_id == 0)
394  {
395  $res = $this->newFileItem();
396  }
397  else
398  {
399  include_once("./Modules/File/classes/class.ilObjFile.php");
400  $this->file_object = new ilObjFile($a_file_ref_id);
401  }
402  if ($res)
403  {
404  $this->content_obj->newItemBefore($this->file_object->getId(),
405  $this->file_object->getTitle(), $this->file_object->getFileType());
406  $this->updated = $this->pg_obj->update();
407  if ($this->updated === true)
408  {
409  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
410  }
411  }
412 
413  $_GET["subCmd"] = "-";
414  $this->newItemBefore();
415  }
416 
420  function deleteItem()
421  {
422  $this->content_obj->deleteItem();
423  $_SESSION["il_pg_error"] = $this->pg_obj->update();
424  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
425  }
426 
430  function setTabs($a_cmd = "")
431  {
432  global $ilTabs, $ilCtrl, $ilSetting;
433 
434  $ilTabs->addTarget("cont_back",
435  $this->ctrl->getParentReturn($this), "",
436  "");
437 
438  if ($a_cmd != "")
439  {
440  $ilCtrl->setParameter($this, "subCmd", "insertNew");
441  $ilTabs->addSubTabTarget("cont_new_file",
442  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
443 
444  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
445  $ilTabs->addSubTabTarget("cont_file_from_repository",
446  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
447  $ilCtrl->setParameter($this, "subCmd", "");
448 
449  if(!$ilSetting->get("disable_personal_workspace") &&
450  !$ilSetting->get("disable_wsp_files"))
451  {
452  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
453  $ilTabs->addSubTabTarget("cont_file_from_workspace",
454  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
455  $ilCtrl->setParameter($this, "subCmd", "");
456  }
457  }
458  }
459 
463  function moveItemDown()
464  {
465  $this->content_obj->moveItemDown();
466  $_SESSION["il_pg_error"] = $this->pg_obj->update();
467  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
468  }
469 
473  function moveItemUp()
474  {
475  $this->content_obj->moveItemUp();
476  $_SESSION["il_pg_error"] = $this->pg_obj->update();
477  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
478  }
479 
480 
481 }
482 ?>