ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExportGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
15{
16 protected $formats = array();
17 protected $custom_columns = array();
18 protected $custom_multi_commands = array();
19
20 private $parent_gui = null;
21
28 public function __construct($a_parent_gui, $a_main_obj = null)
29 {
30 global $DIC;
31
32 $lng = $DIC['lng'];
33 $tpl = $DIC['tpl'];
34
35 $this->parent_gui = $a_parent_gui;
36 if ($a_main_obj == null) {
37 $this->obj = $a_parent_gui->object;
38 } else {
39 $this->obj = $a_main_obj;
40 }
41 $lng->loadLanguageModule("exp");
42 $this->tpl = $tpl;
43 }
44
48 protected function buildExportTableGUI()
49 {
50 include_once("./Services/Export/classes/class.ilExportTableGUI.php");
51 $table = new ilExportTableGUI($this, "listExportFiles", $this->obj);
52 return $table;
53 }
54
59 protected function getParentGUI()
60 {
61 return $this->parent_gui;
62 }
63
69 public function addFormat($a_key, $a_txt = "", $a_call_obj = null, $a_call_func = "")
70 {
71 global $DIC;
72
73 $lng = $DIC['lng'];
74
75 if ($a_txt == "") {
76 $a_txt = $lng->txt("exp_" . $a_key);
77 }
78 $this->formats[] = array("key" => $a_key, "txt" => $a_txt,
79 "call_obj" => $a_call_obj, "call_func" => $a_call_func);
80 }
81
87 public function getFormats()
88 {
89 return $this->formats;
90 }
91
98 public function addCustomColumn($a_txt, $a_obj, $a_func)
99 {
100 $this->custom_columns[] = array("txt" => $a_txt,
101 "obj" => $a_obj,
102 "func" => $a_func);
103 }
104
111 public function addCustomMultiCommand($a_txt, $a_obj, $a_func)
112 {
113 $this->custom_multi_commands[] = array("txt" => $a_txt,
114 "obj" => $a_obj,
115 "func" => $a_func);
116 }
117
121 public function getCustomMultiCommands()
122 {
124 }
125
132 public function getCustomColumns()
133 {
135 }
136
143 public function executeCommand()
144 {
145 global $DIC;
146
147 $ilCtrl = $DIC['ilCtrl'];
148 $ilAccess = $DIC['ilAccess'];
149 $ilErr = $DIC['ilErr'];
150 $lng = $DIC['lng'];
151
152 // this should work (at least) for repository objects
153 if (method_exists($this->obj, 'getRefId') and $this->obj->getRefId()) {
154 if (!$ilAccess->checkAccess('write', '', $this->obj->getRefId())) {
155 $ilErr->raiseError($lng->txt('permission_denied'), $ilErr->WARNING);
156 }
157 }
158
159 $cmd = $ilCtrl->getCmd("listExportFiles");
160
161 switch ($cmd) {
162 case "listExportFiles":
163 $this->$cmd();
164 break;
165
166 default:
167 if (substr($cmd, 0, 7) == "create_") {
168 $this->createExportFile();
169 } elseif (substr($cmd, 0, 6) == "multi_") { // custom multi command
171 } else {
172 $this->$cmd();
173 }
174 break;
175 }
176 }
177
184 public function listExportFiles()
185 {
186 global $DIC;
187
188 $tpl = $DIC['tpl'];
189 $ilToolbar = $DIC['ilToolbar'];
190 $ilCtrl = $DIC['ilCtrl'];
191 $lng = $DIC['lng'];
192
193 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
194 $button = ilSubmitButton::getInstance();
195
196 // creation buttons
197 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
198 if (count($this->getFormats()) > 1) {
199 // type selection
200 foreach ($this->getFormats() as $f) {
201 $options[$f["key"]] = $f["txt"];
202 }
203 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
204 $si = new ilSelectInputGUI($lng->txt("type"), "format");
205 $si->setOptions($options);
206 $ilToolbar->addInputItem($si, true);
207
208 $button->setCaption("exp_create_file");
209 $button->setCommand("createExportFile");
210 } else {
211 $format = $this->getFormats();
212 $format = $format[0];
213
214 $button->setCaption($lng->txt("exp_create_file") . " (" . $format["txt"] . ")", false);
215 $button->setCommand("create_" . $format["key"]);
216 }
217
218 $ilToolbar->addButtonInstance($button);
219
220 $table = $this->buildExportTableGUI();
221 $table->setSelectAllCheckbox("file");
222 foreach ($this->getCustomColumns() as $c) {
223 $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
224 }
225 foreach ($this->getCustomMultiCommands() as $c) {
226 $table->addCustomMultiCommand($c["txt"], "multi_" . $c["func"]);
227 }
228 $tpl->setContent($table->getHTML());
229 }
230
237 public function createExportFile()
238 {
239 global $DIC;
240
241 $ilCtrl = $DIC['ilCtrl'];
242 $lng = $DIC['lng'];
243
244 if ($ilCtrl->getCmd() == "createExportFile") {
246 } else {
247 $format = substr($ilCtrl->getCmd(), 7);
248 }
249 foreach ($this->getFormats() as $f) {
250 if ($f["key"] == $format) {
251 if (is_object($f["call_obj"])) {
252 $f["call_obj"]->{$f["call_func"]}();
253 } elseif ($this->getParentGUI() instanceof ilContainerGUI) {
254 return $this->showItemSelection();
255 } elseif ($format == "xml") { // standard procedure
256 include_once("./Services/Export/classes/class.ilExport.php");
257 $exp = new ilExport();
258 $exp->exportObject($this->obj->getType(), $this->obj->getId());
259 }
260 }
261 }
262
263 ilUtil::sendSuccess($lng->txt("exp_file_created"), true);
264 $ilCtrl->redirect($this, "listExportFiles");
265 }
266
270 public function confirmDeletion()
271 {
272 global $DIC;
273
274 $ilCtrl = $DIC['ilCtrl'];
275 $tpl = $DIC['tpl'];
276 $lng = $DIC['lng'];
277
278 if (!is_array($_POST["file"]) || count($_POST["file"]) == 0) {
279 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
280 $ilCtrl->redirect($this, "listExportFiles");
281 } else {
282 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
283 $cgui = new ilConfirmationGUI();
284 $cgui->setFormAction($ilCtrl->getFormAction($this));
285 $cgui->setHeaderText($lng->txt("exp_really_delete"));
286 $cgui->setCancel($lng->txt("cancel"), "listExportFiles");
287 $cgui->setConfirm($lng->txt("delete"), "delete");
288
289 foreach ($_POST["file"] as $i) {
290 if (strpos($i, ':') !== false) {
291 $iarr = explode(":", $i);
292 $filename = $iarr[1];
293 } else {
294 $filename = $i;
295 }
296 $cgui->addItem("file[]", $i, $filename);
297 }
298
299 $tpl->setContent($cgui->getHTML());
300 }
301 }
302
306 public function delete()
307 {
308 global $DIC;
309
310 $ilCtrl = $DIC['ilCtrl'];
311
312 foreach ($_POST["file"] as $file) {
313 $file = explode(":", $file);
314
315 $file[1] = basename($file[1]);
316
317 include_once("./Services/Export/classes/class.ilExport.php");
318 $export_dir = ilExport::_getExportDirectory(
319 $this->obj->getId(),
320 str_replace("..", "", $file[0]),
321 $this->obj->getType()
322 );
323
324 $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]);
325 $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4);
326 if (@is_file($exp_file)) {
327 unlink($exp_file);
328 }
329 if (@is_dir($exp_dir)) {
330 ilUtil::delDir($exp_dir);
331 }
332
333 // delete entry in database
334 include_once './Services/Export/classes/class.ilExportFileInfo.php';
335 $info = new ilExportFileInfo($this->obj->getId(), $file[0], $file[1]);
336 $info->delete();
337 }
338 $ilCtrl->redirect($this, "listExportFiles");
339 }
340
344 public function download()
345 {
346 global $DIC;
347
348 $ilCtrl = $DIC['ilCtrl'];
349 $lng = $DIC['lng'];
350
351 if (!isset($_GET["file"]) ||
352 is_array($_GET["file"])) {
353 $ilCtrl->redirect($this, "listExportFiles");
354 }
355
356 $file = explode(":", trim($_GET["file"]));
357 include_once("./Services/Export/classes/class.ilExport.php");
358 $export_dir = ilExport::_getExportDirectory(
359 $this->obj->getId(),
360 str_replace("..", "", $file[0]),
361 $this->obj->getType()
362 );
363
364 $file[1] = basename($file[1]);
365
367 $export_dir . "/" . $file[1],
368 $file[1]
369 );
370 }
371
378 public function handleCustomMultiCommand()
379 {
380 global $DIC;
381
382 $ilCtrl = $DIC['ilCtrl'];
383
384 $cmd = substr($ilCtrl->getCmd(), 6);
385 foreach ($this->getCustomMultiCommands() as $c) {
386 if ($c["func"] == $cmd) {
387 $c["obj"]->{$c["func"]}($_POST["file"]);
388 }
389 }
390 }
391
396 protected function showItemSelection()
397 {
398 global $DIC;
399
400 $tpl = $DIC['tpl'];
401
402 $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
403 $tpl->setVariable('BODY_ATTRIBUTES', 'onload="ilDisableChilds(\'cmd\');"');
404
405 include_once './Services/Export/classes/class.ilExportSelectionTableGUI.php';
406 $table = new ilExportSelectionTableGUI($this, 'listExportFiles');
407 $table->parseContainer($this->getParentGUI()->object->getRefId());
408 $this->tpl->setContent($table->getHTML());
409 }
410
415 protected function saveItemSelection()
416 {
417 global $DIC;
418
419 $tree = $DIC['tree'];
420 $objDefinition = $DIC['objDefinition'];
421 $ilAccess = $DIC['ilAccess'];
422 $ilCtrl = $DIC['ilCtrl'];
423 $lng = $DIC['lng'];
424
425 include_once './Services/Export/classes/class.ilExportOptions.php';
427 $eo->addOption(ilExportOptions::KEY_ROOT, 0, 0, $this->obj->getId());
428
429 $items_selected = false;
430 foreach ($tree->getSubTree($root = $tree->getNodeData($this->getParentGUI()->object->getRefId())) as $node) {
431 if ($node['type'] == 'rolf') {
432 continue;
433 }
434 if ($node['ref_id'] == $this->getParentGUI()->object->getRefId()) {
435 $eo->addOption(
437 $node['ref_id'],
438 $node['obj_id'],
440 );
441 continue;
442 }
443 // no export available or no access
444 if (!$objDefinition->allowExport($node['type']) or !$ilAccess->checkAccess('write', '', $node['ref_id'])) {
445 $eo->addOption(
447 $node['ref_id'],
448 $node['obj_id'],
450 );
451 continue;
452 }
453
454 $mode = isset($_POST['cp_options'][$node['ref_id']]['type']) ?
455 $_POST['cp_options'][$node['ref_id']]['type'] :
457 $eo->addOption(
459 $node['ref_id'],
460 $node['obj_id'],
461 $mode
462 );
463 if ($mode != ilExportOptions::EXPORT_OMIT) {
464 $items_selected = true;
465 }
466 }
467
468 include_once("./Services/Export/classes/class.ilExport.php");
469 if ($items_selected) {
470 // TODO: move this to background soap
471 $eo->read();
472 $exp = new ilExport();
473 foreach ($eo->getSubitemsForCreation($this->obj->getRefId()) as $ref_id) {
474 $obj_id = ilObject::_lookupObjId($ref_id);
475 $type = ilObject::_lookupType($obj_id);
476 $exp->exportObject($type, $obj_id);
477 }
478 // Fixme: there is a naming conflict between the container settings xml and the container subitem xml.
479 sleep(1);
480 // Export container
481 include_once './Services/Export/classes/class.ilExportContainer.php';
482 $cexp = new ilExportContainer($eo);
483 $cexp->exportObject($this->obj->getType(), $this->obj->getId());
484 } else {
485 $exp = new ilExport();
486 $exp->exportObject($this->obj->getType(), $this->obj->getId());
487 }
488
489 // Delete export options
490 $eo->delete();
491
492 ilUtil::sendSuccess($lng->txt('export_created'), true);
493 $ilCtrl->redirect($this, "listExportFiles");
494 }
495}
$tpl
Definition: ilias.php:10
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
Class ilContainerGUI.
@classDescription Stores information of creation date and versions of export files
Export User Interface Class.
addFormat($a_key, $a_txt="", $a_call_obj=null, $a_call_func="")
Add formats.
saveItemSelection()
Save selection of subitems.
getParentGUI()
get parent gui
executeCommand()
Execute command.
createExportFile()
Create export file.
getCustomColumns()
Get custom columns.
confirmDeletion()
Confirm file deletion.
__construct($a_parent_gui, $a_main_obj=null)
Constuctor.
getFormats()
Get formats.
getCustomMultiCommands()
Get custom multi commands.
showItemSelection()
Show container item selection table.
download()
Download file.
handleCustomMultiCommand()
Handle custom multi command.
listExportFiles()
List export files.
addCustomColumn($a_txt, $a_obj, $a_func)
Add custom column.
addCustomMultiCommand($a_txt, $a_obj, $a_func)
Add custom multi command.
static newInstance($a_export_id)
Create new instance.
static allocateExportId()
Allocate a new export id.
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a selection list property in a property form.
static getInstance()
Factory.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$i
Definition: disco.tpl.php:19
global $ilCtrl
Definition: ilias.php:18
$format
Definition: metadata.php:141
$info
Definition: index.php:5
$type
if(empty($password)) $table
Definition: pwgen.php:24
$ilErr
Definition: raiseError.php:18
$root
Definition: sabredav.php:45
global $DIC
Definition: saml.php:7
$lng