ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
42  protected $tabs;
43 
47  protected $user;
48 
52  protected $tree;
53 
57  protected $settings;
58 
59 
64  public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
65  {
66  global $DIC;
67 
68  $this->lng = $DIC->language();
69  $this->tabs = $DIC->tabs();
70  $this->ctrl = $DIC->ctrl();
71  $this->user = $DIC->user();
72  $this->tpl = $DIC["tpl"];
73  $this->tree = $DIC->repositoryTree();
74  $this->settings = $DIC->settings();
75  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
76  }
77 
81  public function executeCommand()
82  {
83  // get next class that processes or forwards current command
84  $next_class = $this->ctrl->getNextClass($this);
85 
86  // get current command
87  $cmd = $this->ctrl->getCmd();
88  switch ($next_class) {
89  default:
90  $ret = $this->$cmd();
91  break;
92  }
93 
94  return $ret;
95  }
96 
100  public function newFileItem()
101  {
102  $lng = $this->lng;
103 
104  if ($_FILES["file"]["name"] == "") {
105  $_GET["subCmd"] = "-";
106  ilUtil::sendFailure($lng->txt("upload_error_file_not_found"));
107  return false;
108  }
109 
110  $form = $this->initAddFileForm();
111  $form->checkInput();
112 
113  include_once("./Modules/File/classes/class.ilObjFile.php");
114  $fileObj = new ilObjFile();
115  $fileObj->setType("file");
116  $fileObj->setTitle($_FILES["file"]["name"]);
117  $fileObj->setDescription("");
118  $fileObj->setFileName($_FILES["file"]["name"]);
119  $fileObj->setFileType($_FILES["file"]["type"]);
120  $fileObj->setFileSize($_FILES["file"]["size"]);
121  $fileObj->setMode("filelist");
122  $fileObj->create();
123  $fileObj->raiseUploadError(false);
124  // upload file to filesystem
125  $fileObj->createDirectory();
126  $fileObj->getUploadFile(
127  $_FILES["file"]["tmp_name"],
128  $_FILES["file"]["name"]
129  );
130 
131  $this->file_object = $fileObj;
132  return true;
133  }
134 
135 
139  public function newItemAfter()
140  {
141  $ilTabs = $this->tabs;
142 
143  if ($_GET["subCmd"] == "insertNew") {
144  $_SESSION["cont_file_insert"] = "insertNew";
145  }
146  if ($_GET["subCmd"] == "insertFromRepository") {
147  $_SESSION["cont_file_insert"] = "insertFromRepository";
148  }
149  if ($_GET["subCmd"] == "insertFromWorkspace") {
150  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
151  }
152  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
153  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
154  }
155 
156  switch ($_GET["subCmd"]) {
157  case "insertFromWorkspace":
158  $this->insertFromWorkspace("newItemAfter");
159  break;
160 
161  case "insertFromRepository":
162  $this->insertFromRepository("newItemAfter");
163  break;
164 
165  case "selectFile":
166  $this->insertNewItemAfter($_GET["file_ref_id"]);
167  break;
168 
169  default:
170  $this->setTabs("newItemAfter");
171  $ilTabs->setSubTabActive("cont_new_file");
172 
173  $this->displayValidationError();
174  $form = $this->initAddFileForm(false);
175  $this->tpl->setContent($form->getHTML());
176 break;
177 
178  // new file list form
179  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
180  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
181  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
182 
183  $this->displayValidationError();
184 
185  // file
186  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
187 
188  $this->tpl->parseCurrentBlock();
189 
190  // operations
191  $this->tpl->setCurrentBlock("commands");
192  $this->tpl->setVariable("BTN_NAME", "insertNewItemAfter");
193  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
194  $this->tpl->parseCurrentBlock();
195  break;
196  }
197  }
198 
202  public function initAddFileForm($a_before = true)
203  {
204  $lng = $this->lng;
207 
208  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
209  $form = new ilPropertyFormGUI();
210 
211  // file
212  $fi = new ilFileInputGUI($lng->txt("file"), "file");
213  $fi->setRequired(true);
214  $form->addItem($fi);
215 
216  if ($a_before) {
217  $form->addCommandButton("insertNewItemBefore", $lng->txt("save"));
218  } else {
219  $form->addCommandButton("insertNewItemAfter", $lng->txt("save"));
220  }
221  $form->addCommandButton("cancelAddFile", $lng->txt("cancel"));
222 
223  $form->setTitle($lng->txt("cont_insert_file_item"));
224 
225  $form->setFormAction($ilCtrl->getFormAction($this));
226 
227  return $form;
228  }
229 
230 
234  public function insertFromRepository($a_cmd)
235  {
236  $ilTabs = $this->tabs;
238  $tpl = $this->tpl;
239 
240  $this->setTabs($a_cmd);
241  $ilTabs->setSubTabActive("cont_file_from_repository");
242  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
243 
244  include_once("./Services/COPage/classes/class.ilPCFileItemFileSelectorGUI.php");
245  $exp = new ilPCFileItemFileSelectorGUI(
246  $this,
247  $a_cmd,
248  $this,
249  $a_cmd,
250  "file_ref_id"
251  );
252  if (!$exp->handleCommand()) {
253  $tpl->setContent($exp->getHTML());
254  }
255  }
256 
260  public function insertFromWorkspace($a_cmd = "insert")
261  {
262  $ilTabs = $this->tabs;
263  $tree = $this->tree;
265  $tpl = $this->tpl;
267 
268  $this->setTabs($a_cmd);
269  $ilTabs->setSubTabActive("cont_file_from_workspace");
270 
271  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceExplorerGUI.php");
272  $exp = new ilWorkspaceExplorerGUI($this->user->getId(), $this, $a_cmd, $this, $a_cmd, "fl_wsp_id");
273  $ilCtrl->setParameter($this, "subCmd", "selectFile");
274  $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
275  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
276  $exp->setTypeWhiteList(array("wsrt", "wfld", "file"));
277  $exp->setSelectableTypes(array("file"));
278  if ($exp->handleCommand()) {
279  return;
280  }
281  $tpl->setContent($exp->getHTML());
282  }
283 
287  public function insertNewItemAfter($a_file_ref_id = 0)
288  {
290 
291  $res = true;
292  if (isset($_GET["fl_wsp_id"])) {
293  // we need the object id for the instance
294  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
295  $tree = new ilWorkspaceTree($ilUser->getId());
296  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
297 
298  include_once("./Modules/File/classes/class.ilObjFile.php");
299  $this->file_object = new ilObjFile($node["obj_id"], false);
300  } elseif ($a_file_ref_id == 0) {
301  $res = $this->newFileItem();
302  } else {
303  include_once("./Modules/File/classes/class.ilObjFile.php");
304  $this->file_object = new ilObjFile($a_file_ref_id);
305  }
306  if ($res) {
307  $this->content_obj->newItemAfter(
308  $this->file_object->getId(),
309  $this->file_object->getTitle(),
310  $this->file_object->getFileType()
311  );
312  $this->updated = $this->pg_obj->update();
313  if ($this->updated === true) {
314  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
315  }
316  }
317 
318  $_GET["subCmd"] = "-";
319  $this->newItemAfter();
320  }
321 
325  public function newItemBefore()
326  {
327  $ilTabs = $this->tabs;
328 
329  if ($_GET["subCmd"] == "insertNew") {
330  $_SESSION["cont_file_insert"] = "insertNew";
331  }
332  if ($_GET["subCmd"] == "insertFromRepository") {
333  $_SESSION["cont_file_insert"] = "insertFromRepository";
334  }
335  if ($_GET["subCmd"] == "insertFromWorkspace") {
336  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
337  }
338  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
339  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
340  }
341 
342  switch ($_GET["subCmd"]) {
343  case "insertFromWorkspace":
344  $this->insertFromWorkspace("newItemBefore");
345  break;
346 
347  case "insertFromRepository":
348  $this->insertFromRepository("newItemBefore");
349  break;
350 
351  case "selectFile":
352  $this->insertNewItemBefore($_GET["file_ref_id"]);
353  break;
354 
355  default:
356  $this->setTabs("newItemBefore");
357  $ilTabs->setSubTabActive("cont_new_file");
358 
359  $this->displayValidationError();
360  $form = $this->initAddFileForm(true);
361  $this->tpl->setContent($form->getHTML());
362 break;
363 
364  // new file list form
365  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
366  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
367  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
368 
369  $this->displayValidationError();
370 
371  // file
372  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
373 
374  $this->tpl->parseCurrentBlock();
375 
376  // operations
377  $this->tpl->setCurrentBlock("commands");
378  $this->tpl->setVariable("BTN_NAME", "insertNewItemBefore");
379  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
380  $this->tpl->parseCurrentBlock();
381  break;
382  }
383  }
384 
388  public function insertNewItemBefore($a_file_ref_id = 0)
389  {
391 
392  $res = true;
393  if (isset($_GET["fl_wsp_id"])) {
394  // we need the object id for the instance
395  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
396  $tree = new ilWorkspaceTree($ilUser->getId());
397  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
398 
399  include_once("./Modules/File/classes/class.ilObjFile.php");
400  $this->file_object = new ilObjFile($node["obj_id"], false);
401  } elseif ($a_file_ref_id == 0) {
402  $res = $this->newFileItem();
403  } else {
404  include_once("./Modules/File/classes/class.ilObjFile.php");
405  $this->file_object = new ilObjFile($a_file_ref_id);
406  }
407  if ($res) {
408  $this->content_obj->newItemBefore(
409  $this->file_object->getId(),
410  $this->file_object->getTitle(),
411  $this->file_object->getFileType()
412  );
413  $this->updated = $this->pg_obj->update();
414  if ($this->updated === true) {
415  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
416  }
417  }
418 
419  $_GET["subCmd"] = "-";
420  $this->newItemBefore();
421  }
422 
426  public function deleteItem()
427  {
428  $this->content_obj->deleteItem();
429  $_SESSION["il_pg_error"] = $this->pg_obj->update();
430  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
431  }
432 
436  public function setTabs($a_cmd = "")
437  {
438  $ilTabs = $this->tabs;
441 
442  $ilTabs->addTarget(
443  "cont_back",
444  $this->ctrl->getParentReturn($this),
445  "",
446  ""
447  );
448 
449  if ($a_cmd != "") {
450  $ilCtrl->setParameter($this, "subCmd", "insertNew");
451  $ilTabs->addSubTabTarget(
452  "cont_new_file",
453  $ilCtrl->getLinkTarget($this, $a_cmd),
454  $a_cmd
455  );
456 
457  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
458  $ilTabs->addSubTabTarget(
459  "cont_file_from_repository",
460  $ilCtrl->getLinkTarget($this, $a_cmd),
461  $a_cmd
462  );
463  $ilCtrl->setParameter($this, "subCmd", "");
464 
465  if (!$ilSetting->get("disable_personal_workspace") &&
466  !$ilSetting->get("disable_wsp_files")) {
467  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
468  $ilTabs->addSubTabTarget(
469  "cont_file_from_workspace",
470  $ilCtrl->getLinkTarget($this, $a_cmd),
471  $a_cmd
472  );
473  $ilCtrl->setParameter($this, "subCmd", "");
474  }
475  }
476  }
477 
481  public function moveItemDown()
482  {
483  $this->content_obj->moveItemDown();
484  $_SESSION["il_pg_error"] = $this->pg_obj->update();
485  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
486  }
487 
491  public function moveItemUp()
492  {
493  $this->content_obj->moveItemUp();
494  $_SESSION["il_pg_error"] = $this->pg_obj->update();
495  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
496  }
497 
501  public function cancelAddFile()
502  {
503  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
504  }
505 }
deleteItem()
delete a list item
initAddFileForm($a_before=true)
Init add file form.
moveItemUp()
move list item up
$_SESSION["AccountId"]
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
This class represents a file property in a property form.
insertFromWorkspace($a_cmd="insert")
Insert file from personal workspace.
newItemBefore()
insert new list item before current one
Class ilPCFileItemGUI.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
user()
Definition: user.php:4
Tree handler for personal workspace.
setTabs($a_cmd="")
output tabs
global $ilCtrl
Definition: ilias.php:18
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
foreach($_POST as $key=> $value) $res
if(isset($_POST['submit'])) $form
insertFromRepository($a_cmd)
Insert file from repository.
moveItemDown()
move list item down
Explorer for selecting a personal workspace item.
displayValidationError()
display validation errors
$ilUser
Definition: imgupload.php:18
newFileItem()
insert new file item
cancelAddFile()
Cancel adding a file.
insertNewItemAfter($a_file_ref_id=0)
insert new file item after another item
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
settings()
Definition: settings.php:2
global $ilSetting
Definition: privfeed.php:17
newItemAfter()
insert new list item after current one
insertNewItemBefore($a_file_ref_id=0)
insert new list item before current one
$ret
Definition: parser.php:6
setRequired($a_required)
Set Required.
executeCommand()
execute command