ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  global $DIC;
127  $upload = $DIC->upload();
128  if ($upload->hasBeenProcessed() !== true) {
129  $upload->process();
130  }
131  $fileObj->getUploadFile(
132  $_FILES["file"]["tmp_name"],
133  $_FILES["file"]["name"]
134  );
135 
136  $this->file_object = $fileObj;
137  return true;
138  }
139 
140 
144  public function newItemAfter()
145  {
146  $ilTabs = $this->tabs;
147 
148  if ($_GET["subCmd"] == "insertNew") {
149  $_SESSION["cont_file_insert"] = "insertNew";
150  }
151  if ($_GET["subCmd"] == "insertFromRepository") {
152  $_SESSION["cont_file_insert"] = "insertFromRepository";
153  }
154  if ($_GET["subCmd"] == "insertFromWorkspace") {
155  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
156  }
157  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
158  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
159  }
160 
161  switch ($_GET["subCmd"]) {
162  case "insertFromWorkspace":
163  $this->insertFromWorkspace("newItemAfter");
164  break;
165 
166  case "insertFromRepository":
167  $this->insertFromRepository("newItemAfter");
168  break;
169 
170  case "selectFile":
171  $this->insertNewItemAfter($_GET["file_ref_id"]);
172  break;
173 
174  default:
175  $this->setTabs("newItemAfter");
176  $ilTabs->setSubTabActive("cont_new_file");
177 
178  $this->displayValidationError();
179  $form = $this->initAddFileForm(false);
180  $this->tpl->setContent($form->getHTML());
181 break;
182 
183  // new file list form
184  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
185  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
186  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
187 
188  $this->displayValidationError();
189 
190  // file
191  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
192 
193  $this->tpl->parseCurrentBlock();
194 
195  // operations
196  $this->tpl->setCurrentBlock("commands");
197  $this->tpl->setVariable("BTN_NAME", "insertNewItemAfter");
198  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
199  $this->tpl->parseCurrentBlock();
200  break;
201  }
202  }
203 
207  public function initAddFileForm($a_before = true)
208  {
209  $lng = $this->lng;
212 
213  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
214  $form = new ilPropertyFormGUI();
215 
216  // file
217  $fi = new ilFileInputGUI($lng->txt("file"), "file");
218  $fi->setRequired(true);
219  $form->addItem($fi);
220 
221  if ($a_before) {
222  $form->addCommandButton("insertNewItemBefore", $lng->txt("save"));
223  } else {
224  $form->addCommandButton("insertNewItemAfter", $lng->txt("save"));
225  }
226  $form->addCommandButton("cancelAddFile", $lng->txt("cancel"));
227 
228  $form->setTitle($lng->txt("cont_insert_file_item"));
229 
230  $form->setFormAction($ilCtrl->getFormAction($this));
231 
232  return $form;
233  }
234 
235 
239  public function insertFromRepository($a_cmd)
240  {
241  $ilTabs = $this->tabs;
243  $tpl = $this->tpl;
244 
245  $this->setTabs($a_cmd);
246  $ilTabs->setSubTabActive("cont_file_from_repository");
247  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
248 
249  include_once("./Services/COPage/classes/class.ilPCFileItemFileSelectorGUI.php");
250  $exp = new ilPCFileItemFileSelectorGUI(
251  $this,
252  $a_cmd,
253  $this,
254  $a_cmd,
255  "file_ref_id"
256  );
257  if (!$exp->handleCommand()) {
258  $tpl->setContent($exp->getHTML());
259  }
260  }
261 
265  public function insertFromWorkspace($a_cmd = "insert")
266  {
267  $ilTabs = $this->tabs;
268  $tree = $this->tree;
270  $tpl = $this->tpl;
272 
273  $this->setTabs($a_cmd);
274  $ilTabs->setSubTabActive("cont_file_from_workspace");
275 
276  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceExplorerGUI.php");
277  $exp = new ilWorkspaceExplorerGUI($this->user->getId(), $this, $a_cmd, $this, $a_cmd, "fl_wsp_id");
278  $ilCtrl->setParameter($this, "subCmd", "selectFile");
279  $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
280  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
281  $exp->setTypeWhiteList(array("wsrt", "wfld", "file"));
282  $exp->setSelectableTypes(array("file"));
283  if ($exp->handleCommand()) {
284  return;
285  }
286  $tpl->setContent($exp->getHTML());
287  }
288 
292  public function insertNewItemAfter($a_file_ref_id = 0)
293  {
295 
296  $res = true;
297  if (isset($_GET["fl_wsp_id"])) {
298  // we need the object id for the instance
299  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
300  $tree = new ilWorkspaceTree($ilUser->getId());
301  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
302 
303  include_once("./Modules/File/classes/class.ilObjFile.php");
304  $this->file_object = new ilObjFile($node["obj_id"], false);
305  } elseif ($a_file_ref_id == 0) {
306  $res = $this->newFileItem();
307  } else {
308  include_once("./Modules/File/classes/class.ilObjFile.php");
309  $this->file_object = new ilObjFile($a_file_ref_id);
310  }
311  if ($res) {
312  $this->content_obj->newItemAfter(
313  $this->file_object->getId(),
314  $this->file_object->getTitle(),
315  $this->file_object->getFileType()
316  );
317  $this->updated = $this->pg_obj->update();
318  if ($this->updated === true) {
319  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
320  }
321  }
322 
323  $_GET["subCmd"] = "-";
324  $this->newItemAfter();
325  }
326 
330  public function newItemBefore()
331  {
332  $ilTabs = $this->tabs;
333 
334  if ($_GET["subCmd"] == "insertNew") {
335  $_SESSION["cont_file_insert"] = "insertNew";
336  }
337  if ($_GET["subCmd"] == "insertFromRepository") {
338  $_SESSION["cont_file_insert"] = "insertFromRepository";
339  }
340  if ($_GET["subCmd"] == "insertFromWorkspace") {
341  $_SESSION["cont_file_insert"] = "insertFromWorkspace";
342  }
343  if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
344  $_GET["subCmd"] = $_SESSION["cont_file_insert"];
345  }
346 
347  switch ($_GET["subCmd"]) {
348  case "insertFromWorkspace":
349  $this->insertFromWorkspace("newItemBefore");
350  break;
351 
352  case "insertFromRepository":
353  $this->insertFromRepository("newItemBefore");
354  break;
355 
356  case "selectFile":
357  $this->insertNewItemBefore($_GET["file_ref_id"]);
358  break;
359 
360  default:
361  $this->setTabs("newItemBefore");
362  $ilTabs->setSubTabActive("cont_new_file");
363 
364  $this->displayValidationError();
365  $form = $this->initAddFileForm(true);
366  $this->tpl->setContent($form->getHTML());
367 break;
368 
369  // new file list form
370  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
371  $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
372  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
373 
374  $this->displayValidationError();
375 
376  // file
377  $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
378 
379  $this->tpl->parseCurrentBlock();
380 
381  // operations
382  $this->tpl->setCurrentBlock("commands");
383  $this->tpl->setVariable("BTN_NAME", "insertNewItemBefore");
384  $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
385  $this->tpl->parseCurrentBlock();
386  break;
387  }
388  }
389 
393  public function insertNewItemBefore($a_file_ref_id = 0)
394  {
396 
397  $res = true;
398  if (isset($_GET["fl_wsp_id"])) {
399  // we need the object id for the instance
400  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
401  $tree = new ilWorkspaceTree($ilUser->getId());
402  $node = $tree->getNodeData($_GET["fl_wsp_id"]);
403 
404  include_once("./Modules/File/classes/class.ilObjFile.php");
405  $this->file_object = new ilObjFile($node["obj_id"], false);
406  } elseif ($a_file_ref_id == 0) {
407  $res = $this->newFileItem();
408  } else {
409  include_once("./Modules/File/classes/class.ilObjFile.php");
410  $this->file_object = new ilObjFile($a_file_ref_id);
411  }
412  if ($res) {
413  $this->content_obj->newItemBefore(
414  $this->file_object->getId(),
415  $this->file_object->getTitle(),
416  $this->file_object->getFileType()
417  );
418  $this->updated = $this->pg_obj->update();
419  if ($this->updated === true) {
420  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
421  }
422  }
423 
424  $_GET["subCmd"] = "-";
425  $this->newItemBefore();
426  }
427 
431  public function deleteItem()
432  {
433  $this->content_obj->deleteItem();
434  $_SESSION["il_pg_error"] = $this->pg_obj->update();
435  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
436  }
437 
441  public function setTabs($a_cmd = "")
442  {
443  $ilTabs = $this->tabs;
446 
447  $ilTabs->addTarget(
448  "cont_back",
449  $this->ctrl->getParentReturn($this),
450  "",
451  ""
452  );
453 
454  if ($a_cmd != "") {
455  $ilCtrl->setParameter($this, "subCmd", "insertNew");
456  $ilTabs->addSubTabTarget(
457  "cont_new_file",
458  $ilCtrl->getLinkTarget($this, $a_cmd),
459  $a_cmd
460  );
461 
462  $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
463  $ilTabs->addSubTabTarget(
464  "cont_file_from_repository",
465  $ilCtrl->getLinkTarget($this, $a_cmd),
466  $a_cmd
467  );
468  $ilCtrl->setParameter($this, "subCmd", "");
469 
470  if (!$ilSetting->get("disable_personal_workspace") &&
471  !$ilSetting->get("disable_wsp_files")) {
472  $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
473  $ilTabs->addSubTabTarget(
474  "cont_file_from_workspace",
475  $ilCtrl->getLinkTarget($this, $a_cmd),
476  $a_cmd
477  );
478  $ilCtrl->setParameter($this, "subCmd", "");
479  }
480  }
481  }
482 
486  public function moveItemDown()
487  {
488  $this->content_obj->moveItemDown();
489  $_SESSION["il_pg_error"] = $this->pg_obj->update();
490  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
491  }
492 
496  public function moveItemUp()
497  {
498  $this->content_obj->moveItemUp();
499  $_SESSION["il_pg_error"] = $this->pg_obj->update();
500  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
501  }
502 
506  public function cancelAddFile()
507  {
508  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
509  }
510 }
deleteItem()
delete a list item
settings()
Definition: settings.php:2
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
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
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