ILIAS  Release_4_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["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"] == "") && $_SESSION["cont_file_insert"] != "")
119  {
120  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
121  }
122 
123  switch ($_GET["subCmd"])
124  {
125  case "insertFromRepository":
126  $this->insertFromRepository("newItemAfter");
127  break;
128 
129  case "selectFile":
130  $this->insertNewItemAfter($_GET["file_ref_id"]);
131  break;
132 
133  default:
134  $this->setTabs("newItemAfter");
135  $ilTabs->setSubTabActive("cont_new_file");
136 
137  // new file list form
138  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
139  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
140  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
141 
142  $this->displayValidationError();
143 
144  // file
145  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
146 
147  $this->tpl->parseCurrentBlock();
148 
149  // operations
150  $this->tpl->setCurrentBlock("commands");
151  $this->tpl->setVariable("BTN_NAME", "insertNewItemAfter");
152  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
153  $this->tpl->parseCurrentBlock();
154  break;
155  }
156  }
157 
161  function insertFromRepository($a_cmd)
162  {
163  global $ilTabs, $tree, $ilCtrl, $tpl;
164 
165  $this->setTabs($a_cmd);
166  $ilTabs->setSubTabActive("cont_file_from_repository");
167 
168  include_once "./Services/COPage/classes/class.ilFileSelectorGUI.php";
169 
170  $exp = new ilFileSelectorGUI($this->ctrl->getLinkTarget($this, $a_cmd),
171  "ilpcfileitemgui");
172 
173  if ($_GET["expand"] == "")
174  {
175  $expanded = $tree->readRootId();
176  }
177  else
178  {
179  $expanded = $_GET["expand"];
180  }
181  $exp->setExpand($expanded);
182 
183  $exp->setTargetGet("sel_id");
184  //$this->ctrl->setParameter($this, "target_type", $a_type);
185  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
186  $exp->setParamsGet($this->ctrl->getParameterArray($this, $a_cmd));
187 
188  // filter
189  $exp->setFiltered(true);
190  $exp->setFilterMode(IL_FM_POSITIVE);
191  $exp->addFilter("root");
192  $exp->addFilter("cat");
193  $exp->addFilter("grp");
194  $exp->addFilter("fold");
195  $exp->addFilter("crs");
196  $exp->addFilter("file");
197 
198  $sel_types = array('file');
199 
200  $exp->setOutput(0);
201 
202  $tpl->setContent($exp->getOutput());
203  }
204 
208  function insertNewItemAfter($a_file_ref_id = 0)
209  {
210  $res = true;
211  if ($a_file_ref_id == 0)
212  {
213  $res = $this->newFileItem();
214  }
215  else
216  {
217  include_once("./Modules/File/classes/class.ilObjFile.php");
218  $this->file_object = new ilObjFile($a_file_ref_id);
219  }
220  if ($res)
221  {
222  $this->content_obj->newItemAfter($this->file_object->getId(),
223  $this->file_object->getTitle(), $this->file_object->getFileType());
224  $this->updated = $this->pg_obj->update();
225  if ($this->updated === true)
226  {
227  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
228  }
229  }
230 
231  $_GET["subCmd"] = "-";
232  $this->newItemAfter();
233  }
234 
238  function newItemBefore()
239  {
240  global $ilTabs;
241 
242  if ($_GET["subCmd"] == "insertNew")
243  {
244  $_SESSION["cont_file_insert"] = "insertNew";
245  }
246  if ($_GET["subCmd"] == "insertFromRepository")
247  {
248  $_SESSION["cont_file_insert"] = "insertFromRepository";
249  }
250  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
251  {
252  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
253  }
254 
255  switch ($_GET["subCmd"])
256  {
257  case "insertFromRepository":
258  $this->insertFromRepository("newItemBefore");
259  break;
260 
261  case "selectFile":
262  $this->insertNewItemBefore($_GET["file_ref_id"]);
263  break;
264 
265  default:
266  $this->setTabs("newItemBefore");
267  $ilTabs->setSubTabActive("cont_new_file");
268 
269  // new file list form
270  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
271  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
272  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
273 
274  $this->displayValidationError();
275 
276  // file
277  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
278 
279  $this->tpl->parseCurrentBlock();
280 
281  // operations
282  $this->tpl->setCurrentBlock("commands");
283  $this->tpl->setVariable("BTN_NAME", "insertNewItemBefore");
284  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
285  $this->tpl->parseCurrentBlock();
286  break;
287  }
288 
289  }
290 
294  function insertNewItemBefore($a_file_ref_id = 0)
295  {
296  $res = true;
297  if ($a_file_ref_id == 0)
298  {
299  $res = $this->newFileItem();
300  }
301  else
302  {
303  include_once("./Modules/File/classes/class.ilObjFile.php");
304  $this->file_object = new ilObjFile($a_file_ref_id);
305  }
306  if ($res)
307  {
308  $this->content_obj->newItemBefore($this->file_object->getId(),
309  $this->file_object->getTitle(), $this->file_object->getFileType());
310  $this->updated = $this->pg_obj->update();
311  if ($this->updated === true)
312  {
313  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
314  }
315  }
316 
317  $_GET["subCmd"] = "-";
318  $this->newItemBefore();
319  }
320 
324  function deleteItem()
325  {
326  $this->content_obj->deleteItem();
327  $_SESSION["il_pg_error"] = $this->pg_obj->update();
328  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
329  }
330 
334  function setTabs($a_cmd = "")
335  {
336  global $ilTabs, $ilCtrl;
337 
338  $ilTabs->addTarget("cont_back",
339  $this->ctrl->getParentReturn($this), "",
340  "");
341 
342  if ($a_cmd != "")
343  {
344  $ilCtrl->setParameter($this, "subCmd", "insertNew");
345  $ilTabs->addSubTabTarget("cont_new_file",
346  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
347 
348  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
349  $ilTabs->addSubTabTarget("cont_file_from_repository",
350  $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
351  $ilCtrl->setParameter($this, "subCmd", "");
352  }
353  }
354 
358  function moveItemDown()
359  {
360  $this->content_obj->moveItemDown();
361  $_SESSION["il_pg_error"] = $this->pg_obj->update();
362  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
363  }
364 
368  function moveItemUp()
369  {
370  $this->content_obj->moveItemUp();
371  $_SESSION["il_pg_error"] = $this->pg_obj->update();
372  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
373  }
374 
375 
376 }
377 ?>