ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
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["file"]["name"] == "")
77 {
78 $_GET["subCmd"] = "-";
79 ilUtil::sendFailure($lng->txt("upload_error_file_not_found"));
80 return false;
81 }
82
83 $form = $this->initAddFileForm();
84 $form->checkInput();
85
86 include_once("./Modules/File/classes/class.ilObjFile.php");
87 $fileObj = new ilObjFile();
88 $fileObj->setType("file");
89 $fileObj->setTitle($_FILES["file"]["name"]);
90 $fileObj->setDescription("");
91 $fileObj->setFileName($_FILES["file"]["name"]);
92 $fileObj->setFileType($_FILES["file"]["type"]);
93 $fileObj->setFileSize($_FILES["file"]["size"]);
94 $fileObj->setMode("filelist");
95 $fileObj->create();
96 $fileObj->raiseUploadError(false);
97 // upload file to filesystem
98 $fileObj->createDirectory();
99 $fileObj->getUploadFile($_FILES["file"]["tmp_name"],
100 $_FILES["file"]["name"]);
101
102 $this->file_object =& $fileObj;
103 return true;
104 }
105
106
110 function newItemAfter()
111 {
112 global $ilTabs;
113
114 if ($_GET["subCmd"] == "insertNew")
115 {
116 $_SESSION["cont_file_insert"] = "insertNew";
117 }
118 if ($_GET["subCmd"] == "insertFromRepository")
119 {
120 $_SESSION["cont_file_insert"] = "insertFromRepository";
121 }
122 if ($_GET["subCmd"] == "insertFromWorkspace")
123 {
124 $_SESSION["cont_file_insert"] = "insertFromWorkspace";
125 }
126 if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
127 {
128 $_GET["subCmd"] = $_SESSION["cont_file_insert"];
129 }
130
131 switch ($_GET["subCmd"])
132 {
133 case "insertFromWorkspace":
134 $this->insertFromWorkspace("newItemAfter");
135 break;
136
137 case "insertFromRepository":
138 $this->insertFromRepository("newItemAfter");
139 break;
140
141 case "selectFile":
142 $this->insertNewItemAfter($_GET["file_ref_id"]);
143 break;
144
145 default:
146 $this->setTabs("newItemAfter");
147 $ilTabs->setSubTabActive("cont_new_file");
148
149 $this->displayValidationError();
150 $form = $this->initAddFileForm(false);
151 $this->tpl->setContent($form->getHTML());
152break;
153
154 // new file list form
155 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
156 $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
157 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
158
159 $this->displayValidationError();
160
161 // file
162 $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
163
164 $this->tpl->parseCurrentBlock();
165
166 // operations
167 $this->tpl->setCurrentBlock("commands");
168 $this->tpl->setVariable("BTN_NAME", "insertNewItemAfter");
169 $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
170 $this->tpl->parseCurrentBlock();
171 break;
172 }
173 }
174
178 public function initAddFileForm($a_before = true)
179 {
180 global $lng, $ilCtrl, $ilUser;
181
182 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
183 $form = new ilPropertyFormGUI();
184
185 // file
186 $fi = new ilFileInputGUI($lng->txt("file"), "file");
187 $fi->setRequired(true);
188 $form->addItem($fi);
189
190 if ($a_before)
191 {
192 $form->addCommandButton("insertNewItemBefore", $lng->txt("save"));
193 }
194 else
195 {
196 $form->addCommandButton("insertNewItemAfter", $lng->txt("save"));
197 }
198 $form->addCommandButton("cancelAddFile", $lng->txt("cancel"));
199
200 $form->setTitle($lng->txt("cont_insert_file_item"));
201
202 $form->setFormAction($ilCtrl->getFormAction($this));
203
204 return $form;
205 }
206
207
211 function insertFromRepository($a_cmd)
212 {
213 global $ilTabs, $tree, $ilCtrl, $tpl;
214
215 $this->setTabs($a_cmd);
216 $ilTabs->setSubTabActive("cont_file_from_repository");
217
218 include_once "./Services/COPage/classes/class.ilFileSelectorGUI.php";
219
220 $exp = new ilFileSelectorGUI($this->ctrl->getLinkTarget($this, $a_cmd),
221 "ilpcfileitemgui");
222
223 if ($_GET["expand"] == "")
224 {
225 $expanded = $tree->readRootId();
226 }
227 else
228 {
229 $expanded = $_GET["expand"];
230 }
231 $exp->setExpand($expanded);
232
233 $exp->setTargetGet("sel_id");
234 //$this->ctrl->setParameter($this, "target_type", $a_type);
235 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
236 $exp->setParamsGet($this->ctrl->getParameterArray($this, $a_cmd));
237
238 // filter
239 $exp->setFiltered(true);
240 $exp->setFilterMode(IL_FM_POSITIVE);
241 $exp->addFilter("root");
242 $exp->addFilter("cat");
243 $exp->addFilter("grp");
244 $exp->addFilter("fold");
245 $exp->addFilter("crs");
246 $exp->addFilter("file");
247
248 $sel_types = array('file');
249
250 $exp->setOutput(0);
251
252 $tpl->setContent($exp->getOutput());
253 }
254
258 function insertFromWorkspace($a_cmd = "insert")
259 {
260 global $ilTabs, $tree, $ilCtrl, $tpl, $ilUser;
261
262 $this->setTabs($a_cmd);
263 $ilTabs->setSubTabActive("cont_file_from_workspace");
264
265 // get ws tree
266 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
267 $tree = new ilWorkspaceTree($ilUser->getId());
268
269 // get access handler
270 include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
271 $acc_handler = new ilWorkspaceAccessHandler($tree);
272
273 // get es explorer
274 include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceExplorer.php");
276 'filelist_wspexpand', $tree, $acc_handler);
277 $exp->setTargetGet('fl_wsp_id');
278 $exp->setFiltered(false);
279 $exp->removeAllFormItemTypes();
280
281 // select link
282 $exp->setTypeClickable("file");
283 $ilCtrl->setParameter($this, "subCmd", "selectFile");
284 $exp->setCustomLinkTarget($ilCtrl->getLinkTarget($this, $a_cmd));
285
286 // filter
287 $exp->setFiltered(true);
288 $exp->setFilterMode(IL_FM_POSITIVE);
289 $exp->addFilter("wsrt");
290 $exp->addFilter("wfld");
291 $exp->addFilter("file");
292
293 // expand link
294 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
295 $exp->setParamsGet($ilCtrl->getParameterArray($this, $a_cmd));
296
297 if($_GET['filelist_wspexpand'] == '')
298 {
299 $expanded = $tree->readRootId();
300 }
301 else
302 {
303 $expanded = $_GET['filelist_wspexpand'];
304 }
305 $exp->setExpand($expanded);
306 $exp->setOutput(0);
307
308 $tpl->setContent($exp->getOutput());
309 }
310
314 function insertNewItemAfter($a_file_ref_id = 0)
315 {
316 global $ilUser;
317
318 $res = true;
319 if(isset($_GET["fl_wsp_id"]))
320 {
321 // we need the object id for the instance
322 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
323 $tree = new ilWorkspaceTree($ilUser->getId());
324 $node = $tree->getNodeData($_GET["fl_wsp_id"]);
325
326 include_once("./Modules/File/classes/class.ilObjFile.php");
327 $this->file_object = new ilObjFile($node["obj_id"], false);
328 }
329 else if ($a_file_ref_id == 0)
330 {
331 $res = $this->newFileItem();
332 }
333 else
334 {
335 include_once("./Modules/File/classes/class.ilObjFile.php");
336 $this->file_object = new ilObjFile($a_file_ref_id);
337 }
338 if ($res)
339 {
340 $this->content_obj->newItemAfter($this->file_object->getId(),
341 $this->file_object->getTitle(), $this->file_object->getFileType());
342 $this->updated = $this->pg_obj->update();
343 if ($this->updated === true)
344 {
345 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
346 }
347 }
348
349 $_GET["subCmd"] = "-";
350 $this->newItemAfter();
351 }
352
356 function newItemBefore()
357 {
358 global $ilTabs;
359
360 if ($_GET["subCmd"] == "insertNew")
361 {
362 $_SESSION["cont_file_insert"] = "insertNew";
363 }
364 if ($_GET["subCmd"] == "insertFromRepository")
365 {
366 $_SESSION["cont_file_insert"] = "insertFromRepository";
367 }
368 if ($_GET["subCmd"] == "insertFromWorkspace")
369 {
370 $_SESSION["cont_file_insert"] = "insertFromWorkspace";
371 }
372 if (($_GET["subCmd"] == "") && $_SESSION["cont_file_insert"] != "")
373 {
374 $_GET["subCmd"] = $_SESSION["cont_file_insert"];
375 }
376
377 switch ($_GET["subCmd"])
378 {
379 case "insertFromWorkspace":
380 $this->insertFromWorkspace("newItemBefore");
381 break;
382
383 case "insertFromRepository":
384 $this->insertFromRepository("newItemBefore");
385 break;
386
387 case "selectFile":
388 $this->insertNewItemBefore($_GET["file_ref_id"]);
389 break;
390
391 default:
392 $this->setTabs("newItemBefore");
393 $ilTabs->setSubTabActive("cont_new_file");
394
395 $this->displayValidationError();
396 $form = $this->initAddFileForm(true);
397 $this->tpl->setContent($form->getHTML());
398break;
399
400 // new file list form
401 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.file_item_edit.html", "Services/COPage");
402 $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_insert_file_item"));
403 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
404
405 $this->displayValidationError();
406
407 // file
408 $this->tpl->setVariable("TXT_FILE", $this->lng->txt("file"));
409
410 $this->tpl->parseCurrentBlock();
411
412 // operations
413 $this->tpl->setCurrentBlock("commands");
414 $this->tpl->setVariable("BTN_NAME", "insertNewItemBefore");
415 $this->tpl->setVariable("BTN_TEXT", $this->lng->txt("save"));
416 $this->tpl->parseCurrentBlock();
417 break;
418 }
419
420 }
421
425 function insertNewItemBefore($a_file_ref_id = 0)
426 {
427 global $ilUser;
428
429 $res = true;
430 if(isset($_GET["fl_wsp_id"]))
431 {
432 // we need the object id for the instance
433 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
434 $tree = new ilWorkspaceTree($ilUser->getId());
435 $node = $tree->getNodeData($_GET["fl_wsp_id"]);
436
437 include_once("./Modules/File/classes/class.ilObjFile.php");
438 $this->file_object = new ilObjFile($node["obj_id"], false);
439 }
440 else if ($a_file_ref_id == 0)
441 {
442 $res = $this->newFileItem();
443 }
444 else
445 {
446 include_once("./Modules/File/classes/class.ilObjFile.php");
447 $this->file_object = new ilObjFile($a_file_ref_id);
448 }
449 if ($res)
450 {
451 $this->content_obj->newItemBefore($this->file_object->getId(),
452 $this->file_object->getTitle(), $this->file_object->getFileType());
453 $this->updated = $this->pg_obj->update();
454 if ($this->updated === true)
455 {
456 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
457 }
458 }
459
460 $_GET["subCmd"] = "-";
461 $this->newItemBefore();
462 }
463
467 function deleteItem()
468 {
469 $this->content_obj->deleteItem();
470 $_SESSION["il_pg_error"] = $this->pg_obj->update();
471 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
472 }
473
477 function setTabs($a_cmd = "")
478 {
479 global $ilTabs, $ilCtrl, $ilSetting;
480
481 $ilTabs->addTarget("cont_back",
482 $this->ctrl->getParentReturn($this), "",
483 "");
484
485 if ($a_cmd != "")
486 {
487 $ilCtrl->setParameter($this, "subCmd", "insertNew");
488 $ilTabs->addSubTabTarget("cont_new_file",
489 $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
490
491 $ilCtrl->setParameter($this, "subCmd", "insertFromRepository");
492 $ilTabs->addSubTabTarget("cont_file_from_repository",
493 $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
494 $ilCtrl->setParameter($this, "subCmd", "");
495
496 if(!$ilSetting->get("disable_personal_workspace") &&
497 !$ilSetting->get("disable_wsp_files"))
498 {
499 $ilCtrl->setParameter($this, "subCmd", "insertFromWorkspace");
500 $ilTabs->addSubTabTarget("cont_file_from_workspace",
501 $ilCtrl->getLinkTarget($this, $a_cmd), $a_cmd);
502 $ilCtrl->setParameter($this, "subCmd", "");
503 }
504 }
505 }
506
510 function moveItemDown()
511 {
512 $this->content_obj->moveItemDown();
513 $_SESSION["il_pg_error"] = $this->pg_obj->update();
514 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
515 }
516
520 function moveItemUp()
521 {
522 $this->content_obj->moveItemUp();
523 $_SESSION["il_pg_error"] = $this->pg_obj->update();
524 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
525 }
526
530 function cancelAddFile()
531 {
532 $this->ctrl->returnToParent($this, "jump".$this->hier_id);
533 }
534}
535?>
$_GET["client_id"]
$_SESSION["AccountId"]
const IL_FM_POSITIVE
This class represents a file property in a property form.
Select file for being added into file lists.
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
& executeCommand()
execute command
newItemBefore()
insert new list item before current one
insertFromRepository($a_cmd)
Insert file from repository.
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
ilPCFileItemGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
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.
Access handler for personal workspace.
Tree handler for personal workspace.
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15