ILIAS  release_7 Revision v7.30-3-g800a261c036
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
24require_once("./Services/COPage/classes/class.ilPCListItem.php");
25require_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 {
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 // upload file to filesystem
124 $fileObj->createDirectory();
125 global $DIC;
126 $upload = $DIC->upload();
127 if ($upload->hasBeenProcessed() !== true) {
128 $upload->process();
129 }
130 $fileObj->getUploadFile(
131 $_FILES["file"]["tmp_name"],
132 $_FILES["file"]["name"]
133 );
134
135 $this->file_object = $fileObj;
136 return true;
137 }
138
139
143 public function newItemAfter()
144 {
145 $ilTabs = $this->tabs;
146
147 if ($_GET["subCmd"] == "insertNew") {
148 $_SESSION["cont_file_insert"] = "insertNew";
149 }
150 if ($_GET["subCmd"] == "insertFromRepository") {
151 $_SESSION["cont_file_insert"] = "insertFromRepository";
152 }
153 if ($_GET["subCmd"] == "insertFromWorkspace") {
154 $_SESSION["cont_file_insert"] = "insertFromWorkspace";
155 }
156 if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
157 $_GET["subCmd"] = $_SESSION["cont_file_insert"];
158 }
159
160 switch ($_GET["subCmd"]) {
161 case "insertFromWorkspace":
162 $this->insertFromWorkspace("newItemAfter");
163 break;
164
165 case "insertFromRepository":
166 $this->insertFromRepository("newItemAfter");
167 break;
168
169 case "selectFile":
170 $this->insertNewItemAfter($_GET["file_ref_id"]);
171 break;
172
173 default:
174 $this->setTabs("newItemAfter");
175 $ilTabs->setSubTabActive("cont_new_file");
176
177 $this->displayValidationError();
178 $form = $this->initAddFileForm(false);
179 $this->tpl->setContent($form->getHTML());
180break;
181
182 // new file list form
183 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
184 $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
185 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
186
187 $this->displayValidationError();
188
189 // file
190 $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
191
192 $this->tpl->parseCurrentBlock();
193
194 // operations
195 $this->tpl->setCurrentBlock("commands");
196 $this->tpl->setVariable("BTN_NAME", "insertNewItemAfter");
197 $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
198 $this->tpl->parseCurrentBlock();
199 break;
200 }
201 }
202
206 public function initAddFileForm($a_before = true)
207 {
209 $ilCtrl = $this->ctrl;
211
212 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
213 $form = new ilPropertyFormGUI();
214
215 // file
216 $fi = new ilFileInputGUI($lng->txt("file"), "file");
217 $fi->setRequired(true);
218 $form->addItem($fi);
219
220 if ($a_before) {
221 $form->addCommandButton("insertNewItemBefore", $lng->txt("save"));
222 } else {
223 $form->addCommandButton("insertNewItemAfter", $lng->txt("save"));
224 }
225 $form->addCommandButton("cancelAddFile", $lng->txt("cancel"));
226
227 $form->setTitle($lng->txt("cont_insert_file_item"));
228
229 $form->setFormAction($ilCtrl->getFormAction($this));
230
231 return $form;
232 }
233
234
238 public function insertFromRepository($a_cmd)
239 {
240 $ilTabs = $this->tabs;
241 $ilCtrl = $this->ctrl;
243
244 $this->setTabs($a_cmd);
245 $ilTabs->setSubTabActive("cont_file_from_repository");
246 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
247
248 include_once("./Services/COPage/classes/class.ilPCFileItemFileSelectorGUI.php");
250 $this,
251 $a_cmd,
252 $this,
253 $a_cmd,
254 "file_ref_id"
255 );
256 if (!$exp->handleCommand()) {
257 $tpl->setContent($exp->getHTML());
258 }
259 }
260
264 public function insertFromWorkspace($a_cmd = "insert")
265 {
266 $ilTabs = $this->tabs;
268 $ilCtrl = $this->ctrl;
271
272 $this->setTabs($a_cmd);
273 $ilTabs->setSubTabActive("cont_file_from_workspace");
274
275 include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceExplorerGUI.php");
276 $exp = new ilWorkspaceExplorerGUI($this->user->getId(), $this, $a_cmd, $this, $a_cmd, "fl_wsp_id");
277 $ilCtrl->setParameter($this, "subCmd", "selectFile");
278 $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
279 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
280 $exp->setTypeWhiteList(array("wsrt", "wfld", "file"));
281 $exp->setSelectableTypes(array("file"));
282 if ($exp->handleCommand()) {
283 return;
284 }
285 $tpl->setContent($exp->getHTML());
286 }
287
291 public function insertNewItemAfter($a_file_ref_id = 0)
292 {
294
295 $res = true;
296 if (isset($_GET["fl_wsp_id"])) {
297 // we need the object id for the instance
298 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
299 $tree = new ilWorkspaceTree($ilUser->getId());
300 $node = $tree->getNodeData($_GET["fl_wsp_id"]);
301
302 include_once("./Modules/File/classes/class.ilObjFile.php");
303 $this->file_object = new ilObjFile($node["obj_id"], false);
304 } elseif ($a_file_ref_id == 0) {
305 $res = $this->newFileItem();
306 } else {
307 include_once("./Modules/File/classes/class.ilObjFile.php");
308 $this->file_object = new ilObjFile($a_file_ref_id);
309 }
310 if ($res) {
311 $this->content_obj->newItemAfter(
312 $this->file_object->getId(),
313 $this->file_object->getTitle(),
314 $this->file_object->getFileType()
315 );
316 $this->updated = $this->pg_obj->update();
317 if ($this->updated === true) {
318 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
319 }
320 }
321
322 $_GET["subCmd"] = "-";
323 $this->newItemAfter();
324 }
325
329 public function newItemBefore()
330 {
331 $ilTabs = $this->tabs;
332
333 if ($_GET["subCmd"] == "insertNew") {
334 $_SESSION["cont_file_insert"] = "insertNew";
335 }
336 if ($_GET["subCmd"] == "insertFromRepository") {
337 $_SESSION["cont_file_insert"] = "insertFromRepository";
338 }
339 if ($_GET["subCmd"] == "insertFromWorkspace") {
340 $_SESSION["cont_file_insert"] = "insertFromWorkspace";
341 }
342 if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "") {
343 $_GET["subCmd"] = $_SESSION["cont_file_insert"];
344 }
345
346 switch ($_GET["subCmd"]) {
347 case "insertFromWorkspace":
348 $this->insertFromWorkspace("newItemBefore");
349 break;
350
351 case "insertFromRepository":
352 $this->insertFromRepository("newItemBefore");
353 break;
354
355 case "selectFile":
356 $this->insertNewItemBefore($_GET["file_ref_id"]);
357 break;
358
359 default:
360 $this->setTabs("newItemBefore");
361 $ilTabs->setSubTabActive("cont_new_file");
362
363 $this->displayValidationError();
364 $form = $this->initAddFileForm(true);
365 $this->tpl->setContent($form->getHTML());
366break;
367
368 // new file list form
369 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
370 $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
371 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
372
373 $this->displayValidationError();
374
375 // file
376 $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
377
378 $this->tpl->parseCurrentBlock();
379
380 // operations
381 $this->tpl->setCurrentBlock("commands");
382 $this->tpl->setVariable("BTN_NAME", "insertNewItemBefore");
383 $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
384 $this->tpl->parseCurrentBlock();
385 break;
386 }
387 }
388
392 public function insertNewItemBefore($a_file_ref_id = 0)
393 {
395
396 $res = true;
397 if (isset($_GET["fl_wsp_id"])) {
398 // we need the object id for the instance
399 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
400 $tree = new ilWorkspaceTree($ilUser->getId());
401 $node = $tree->getNodeData($_GET["fl_wsp_id"]);
402
403 include_once("./Modules/File/classes/class.ilObjFile.php");
404 $this->file_object = new ilObjFile($node["obj_id"], false);
405 } elseif ($a_file_ref_id == 0) {
406 $res = $this->newFileItem();
407 } else {
408 include_once("./Modules/File/classes/class.ilObjFile.php");
409 $this->file_object = new ilObjFile($a_file_ref_id);
410 }
411 if ($res) {
412 $this->content_obj->newItemBefore(
413 $this->file_object->getId(),
414 $this->file_object->getTitle(),
415 $this->file_object->getFileType()
416 );
417 $this->updated = $this->pg_obj->update();
418 if ($this->updated === true) {
419 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
420 }
421 }
422
423 $_GET["subCmd"] = "-";
424 $this->newItemBefore();
425 }
426
430 public function deleteItem()
431 {
432 $this->content_obj->deleteItem();
433 $_SESSION["il_pg_error"] = $this->pg_obj->update();
434 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
435 }
436
440 public function setTabs($a_cmd = "")
441 {
442 $ilTabs = $this->tabs;
443 $ilCtrl = $this->ctrl;
445
446 $ilTabs->addTarget(
447 "cont_back",
448 $this->ctrl->getParentReturn($this),
449 "",
450 ""
451 );
452
453 if ($a_cmd != "") {
454 $ilCtrl->setParameter($this, "subCmd", "insertNew");
455 $ilTabs->addSubTabTarget(
456 "cont_new_file",
457 $ilCtrl->getLinkTarget($this, $a_cmd),
458 $a_cmd
459 );
460
461 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
462 $ilTabs->addSubTabTarget(
463 "cont_file_from_repository",
464 $ilCtrl->getLinkTarget($this, $a_cmd),
465 $a_cmd
466 );
467 $ilCtrl->setParameter($this, "subCmd", "");
468
469 if (!$ilSetting->get("disable_personal_workspace") &&
470 !$ilSetting->get("disable_wsp_files")) {
471 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
472 $ilTabs->addSubTabTarget(
473 "cont_file_from_workspace",
474 $ilCtrl->getLinkTarget($this, $a_cmd),
475 $a_cmd
476 );
477 $ilCtrl->setParameter($this, "subCmd", "");
478 }
479 }
480 }
481
485 public function moveItemDown()
486 {
487 $this->content_obj->moveItemDown();
488 $_SESSION["il_pg_error"] = $this->pg_obj->update();
489 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
490 }
491
495 public function moveItemUp()
496 {
497 $this->content_obj->moveItemUp();
498 $_SESSION["il_pg_error"] = $this->pg_obj->update();
499 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
500 }
501
505 public function cancelAddFile()
506 {
507 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
508 }
509}
user()
Definition: user.php:4
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a file property in a property form.
Class ilObjFile.
Class ilPCFileItemGUI.
cancelAddFile()
Cancel adding a file.
initAddFileForm($a_before=true)
Init add file form.
insertNewItemAfter($a_file_ref_id=0)
insert new file item after another item
newItemBefore()
insert new list item before current one
insertFromRepository($a_cmd)
Insert file from repository.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
executeCommand()
execute command
insertNewItemBefore($a_file_ref_id=0)
insert new list item before current one
insertFromWorkspace($a_cmd="insert")
Insert file from personal workspace.
newItemAfter()
insert new list item after current one
moveItemDown()
move list item down
newFileItem()
insert new file item
setTabs($a_cmd="")
output tabs
deleteItem()
delete a list item
moveItemUp()
move list item up
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
displayValidationError()
display validation errors
This class represents a property form user interface.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Explorer for selecting a personal workspace item.
Tree handler for personal workspace.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
global $ilSetting
Definition: privfeed.php:17
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2