ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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'];
152 $objDefinition = $DIC["objDefinition"];
153
154 // this should work (at least) for repository objects
155 if (method_exists($this->obj, 'getRefId') and $this->obj->getRefId()) {
156 if (!$ilAccess->checkAccess('write', '', $this->obj->getRefId())) {
157 $ilErr->raiseError($lng->txt('permission_denied'), $ilErr->WARNING);
158 }
159
160 // check export activation of container
161 $exp_limit = new ilExportLimitation();
162 if ($objDefinition->isContainer(ilObject::_lookupType($this->obj->getRefId(), true)) &&
163 $exp_limit->getLimitationMode() == ilExportLimitation::SET_EXPORT_DISABLED) {
164 ilUtil::sendFailure($lng->txt("exp_error_disabled"));
165 return;
166 }
167 }
168
169 $cmd = $ilCtrl->getCmd("listExportFiles");
170
171 switch ($cmd) {
172 case "listExportFiles":
173 $this->$cmd();
174 break;
175
176 default:
177 if (substr($cmd, 0, 7) == "create_") {
178 $this->createExportFile();
179 } elseif (substr($cmd, 0, 6) == "multi_") { // custom multi command
181 } else {
182 $this->$cmd();
183 }
184 break;
185 }
186 }
187
194 public function listExportFiles()
195 {
196 global $DIC;
197
198 $tpl = $DIC['tpl'];
199 $ilToolbar = $DIC['ilToolbar'];
200 $ilCtrl = $DIC['ilCtrl'];
201 $lng = $DIC['lng'];
202
203 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
204 $button = ilSubmitButton::getInstance();
205
206 // creation buttons
207 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
208 if (count($this->getFormats()) > 1) {
209 // type selection
210 foreach ($this->getFormats() as $f) {
211 $options[$f["key"]] = $f["txt"];
212 }
213 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
214 $si = new ilSelectInputGUI($lng->txt("type"), "format");
215 $si->setOptions($options);
216 $ilToolbar->addInputItem($si, true);
217
218 $button->setCaption("exp_create_file");
219 $button->setCommand("createExportFile");
220 } else {
221 $format = $this->getFormats();
222 $format = $format[0];
223
224 $button->setCaption($lng->txt("exp_create_file") . " (" . $format["txt"] . ")", false);
225 $button->setCommand("create_" . $format["key"]);
226 }
227
228 $ilToolbar->addButtonInstance($button);
229
230 $table = $this->buildExportTableGUI();
231 $table->setSelectAllCheckbox("file");
232 foreach ($this->getCustomColumns() as $c) {
233 $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
234 }
235 foreach ($this->getCustomMultiCommands() as $c) {
236 $table->addCustomMultiCommand($c["txt"], "multi_" . $c["func"]);
237 }
238 $tpl->setContent($table->getHTML());
239 }
240
247 public function createExportFile()
248 {
249 global $DIC;
250
251 $ilCtrl = $DIC['ilCtrl'];
252 $lng = $DIC['lng'];
253
254 if ($ilCtrl->getCmd() == "createExportFile") {
256 } else {
257 $format = substr($ilCtrl->getCmd(), 7);
258 }
259 foreach ($this->getFormats() as $f) {
260 if ($f["key"] == $format) {
261 if (is_object($f["call_obj"])) {
262 $f["call_obj"]->{$f["call_func"]}();
263 } elseif ($this->getParentGUI() instanceof ilContainerGUI) {
264 return $this->showItemSelection();
265 } elseif ($format == "xml") { // standard procedure
266 include_once("./Services/Export/classes/class.ilExport.php");
267 $exp = new ilExport();
268 $exp->exportObject($this->obj->getType(), $this->obj->getId());
269 }
270 }
271 }
272
273 ilUtil::sendSuccess($lng->txt("exp_file_created"), true);
274 $ilCtrl->redirect($this, "listExportFiles");
275 }
276
280 public function confirmDeletion()
281 {
282 global $DIC;
283
284 $ilCtrl = $DIC['ilCtrl'];
285 $tpl = $DIC['tpl'];
286 $lng = $DIC['lng'];
287
288 if (!is_array($_POST["file"]) || count($_POST["file"]) == 0) {
289 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
290 $ilCtrl->redirect($this, "listExportFiles");
291 } else {
292 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
293 $cgui = new ilConfirmationGUI();
294 $cgui->setFormAction($ilCtrl->getFormAction($this));
295 $cgui->setHeaderText($lng->txt("exp_really_delete"));
296 $cgui->setCancel($lng->txt("cancel"), "listExportFiles");
297 $cgui->setConfirm($lng->txt("delete"), "delete");
298
299 foreach ($_POST["file"] as $i) {
300 if (strpos($i, ':') !== false) {
301 $iarr = explode(":", $i);
302 $filename = $iarr[1];
303 } else {
304 $filename = $i;
305 }
306 $cgui->addItem("file[]", $i, $filename);
307 }
308
309 $tpl->setContent($cgui->getHTML());
310 }
311 }
312
316 public function delete()
317 {
318 global $DIC;
319
320 $ilCtrl = $DIC['ilCtrl'];
321
322 foreach ($_POST["file"] as $file) {
323 $file = explode(":", $file);
324
325 $file[1] = basename($file[1]);
326
327 include_once("./Services/Export/classes/class.ilExport.php");
328 $export_dir = ilExport::_getExportDirectory(
329 $this->obj->getId(),
330 str_replace("..", "", $file[0]),
331 $this->obj->getType()
332 );
333
334 $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]);
335 $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4);
336 if (@is_file($exp_file)) {
337 unlink($exp_file);
338 }
339 if (@is_dir($exp_dir)) {
340 ilUtil::delDir($exp_dir);
341 }
342
343 // delete entry in database
344 include_once './Services/Export/classes/class.ilExportFileInfo.php';
345 $info = new ilExportFileInfo($this->obj->getId(), $file[0], $file[1]);
346 $info->delete();
347 }
348 $ilCtrl->redirect($this, "listExportFiles");
349 }
350
354 public function download()
355 {
356 global $DIC;
357
358 $ilCtrl = $DIC['ilCtrl'];
359 $lng = $DIC['lng'];
360
361 if (!isset($_GET["file"]) ||
362 is_array($_GET["file"])) {
363 $ilCtrl->redirect($this, "listExportFiles");
364 }
365
366 $file = explode(":", trim($_GET["file"]));
367 include_once("./Services/Export/classes/class.ilExport.php");
368 $export_dir = ilExport::_getExportDirectory(
369 $this->obj->getId(),
370 str_replace("..", "", $file[0]),
371 $this->obj->getType()
372 );
373
374 $file[1] = basename($file[1]);
375
377 $export_dir . "/" . $file[1],
378 $file[1]
379 );
380 }
381
388 public function handleCustomMultiCommand()
389 {
390 global $DIC;
391
392 $ilCtrl = $DIC['ilCtrl'];
393
394 $cmd = substr($ilCtrl->getCmd(), 6);
395 foreach ($this->getCustomMultiCommands() as $c) {
396 if ($c["func"] == $cmd) {
397 $c["obj"]->{$c["func"]}($_POST["file"]);
398 }
399 }
400 }
401
406 protected function showItemSelection()
407 {
408 global $DIC;
409
410 $tpl = $DIC['tpl'];
411
412 $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
413 $tpl->setVariable('BODY_ATTRIBUTES', 'onload="ilDisableChilds(\'cmd\');"');
414
415 include_once './Services/Export/classes/class.ilExportSelectionTableGUI.php';
416 $table = new ilExportSelectionTableGUI($this, 'listExportFiles');
417 $table->parseContainer($this->getParentGUI()->object->getRefId());
418 $this->tpl->setContent($table->getHTML());
419 }
420
425 protected function saveItemSelection()
426 {
427 global $DIC;
428
429 $tree = $DIC['tree'];
430 $objDefinition = $DIC['objDefinition'];
431 $ilAccess = $DIC['ilAccess'];
432 $ilCtrl = $DIC['ilCtrl'];
433 $lng = $DIC['lng'];
434
435 include_once './Services/Export/classes/class.ilExportOptions.php';
437 $eo->addOption(ilExportOptions::KEY_ROOT, 0, 0, $this->obj->getId());
438
439 // check export limitation
440 $exp_limit = new ilExportLimitation();
441 try {
442 $exp_limit->checkLimitation(
443 $this->getParentGUI()->object->getRefId(),
444 $_POST['cp_options']
445 );
446 } catch (Exception $e) {
447 ilUtil::sendFailure($e->getMessage());
448 $this->showItemSelection();
449 return;
450 }
451
452 $items_selected = false;
453 foreach ($tree->getSubTree($root = $tree->getNodeData($this->getParentGUI()->object->getRefId())) as $node) {
454 if ($node['type'] == 'rolf') {
455 continue;
456 }
457 if ($node['ref_id'] == $this->getParentGUI()->object->getRefId()) {
458 $eo->addOption(
460 $node['ref_id'],
461 $node['obj_id'],
463 );
464 continue;
465 }
466 // no export available or no access
467 if (!$objDefinition->allowExport($node['type']) or !$ilAccess->checkAccess('write', '', $node['ref_id'])) {
468 $eo->addOption(
470 $node['ref_id'],
471 $node['obj_id'],
473 );
474 continue;
475 }
476
477 $mode = isset($_POST['cp_options'][$node['ref_id']]['type']) ?
478 $_POST['cp_options'][$node['ref_id']]['type'] :
480 $eo->addOption(
482 $node['ref_id'],
483 $node['obj_id'],
484 $mode
485 );
486 if ($mode != ilExportOptions::EXPORT_OMIT) {
487 $items_selected = true;
488 }
489 }
490
491 include_once("./Services/Export/classes/class.ilExport.php");
492 if ($items_selected) {
493 // TODO: move this to background soap
494 $eo->read();
495 $exp = new ilExport();
496 foreach ($eo->getSubitemsForCreation($this->obj->getRefId()) as $ref_id) {
497 $obj_id = ilObject::_lookupObjId($ref_id);
498 $type = ilObject::_lookupType($obj_id);
499 $exp->exportObject($type, $obj_id);
500 }
501 // Fixme: there is a naming conflict between the container settings xml and the container subitem xml.
502 sleep(1);
503 // Export container
504 include_once './Services/Export/classes/class.ilExportContainer.php';
505 $cexp = new ilExportContainer($eo);
506 $cexp->exportObject($this->obj->getType(), $this->obj->getId());
507 } else {
508 $exp = new ilExport();
509 $exp->exportObject($this->obj->getType(), $this->obj->getId());
510 }
511
512 // Delete export options
513 $eo->delete();
514
515 ilUtil::sendSuccess($lng->txt('export_created'), true);
516 $ilCtrl->redirect($this, "listExportFiles");
517 }
518}
$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
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.
Export limitation checker.
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 sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
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.
global $ilCtrl
Definition: ilias.php:18
$format
Definition: metadata.php:218
$i
Definition: metadata.php:24
$type
$ilErr
Definition: raiseError.php:18
$lng
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$DIC
Definition: xapitoken.php:46