ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $lng,$tpl;
31
32 $this->parent_gui = $a_parent_gui;
33 if ($a_main_obj == null) {
34 $this->obj = $a_parent_gui->object;
35 } else {
36 $this->obj = $a_main_obj;
37 }
38 $lng->loadLanguageModule("exp");
39 $this->tpl = $tpl;
40 }
41
45 protected function buildExportTableGUI()
46 {
47 include_once("./Services/Export/classes/class.ilExportTableGUI.php");
48 $table = new ilExportTableGUI($this, "listExportFiles", $this->obj);
49 return $table;
50 }
51
56 protected function getParentGUI()
57 {
58 return $this->parent_gui;
59 }
60
66 public function addFormat($a_key, $a_txt = "", $a_call_obj = null, $a_call_func = "")
67 {
68 global $lng;
69
70 if ($a_txt == "") {
71 $a_txt = $lng->txt("exp_" . $a_key);
72 }
73 $this->formats[] = array("key" => $a_key, "txt" => $a_txt,
74 "call_obj" => $a_call_obj, "call_func" => $a_call_func);
75 }
76
82 public function getFormats()
83 {
84 return $this->formats;
85 }
86
93 public function addCustomColumn($a_txt, $a_obj, $a_func)
94 {
95 $this->custom_columns[] = array("txt" => $a_txt,
96 "obj" => $a_obj,
97 "func" => $a_func);
98 }
99
106 public function addCustomMultiCommand($a_txt, $a_obj, $a_func)
107 {
108 $this->custom_multi_commands[] = array("txt" => $a_txt,
109 "obj" => $a_obj,
110 "func" => $a_func);
111 }
112
116 public function getCustomMultiCommands()
117 {
119 }
120
127 public function getCustomColumns()
128 {
130 }
131
138 public function executeCommand()
139 {
140 global $ilCtrl, $ilAccess, $ilErr, $lng;
141
142 // this should work (at least) for repository objects
143 if (method_exists($this->obj, 'getRefId') and $this->obj->getRefId()) {
144 if (!$ilAccess->checkAccess('write', '', $this->obj->getRefId())) {
145 $ilErr->raiseError($lng->txt('permission_denied'), $ilErr->WARNING);
146 }
147 }
148
149 $cmd = $ilCtrl->getCmd("listExportFiles");
150
151 switch ($cmd) {
152 case "listExportFiles":
153 $this->$cmd();
154 break;
155
156 default:
157 if (substr($cmd, 0, 7) == "create_") {
158 $this->createExportFile();
159 } elseif (substr($cmd, 0, 6) == "multi_") { // custom multi command
161 } else {
162 $this->$cmd();
163 }
164 break;
165 }
166 }
167
174 public function listExportFiles()
175 {
176 global $tpl, $ilToolbar, $ilCtrl, $lng;
177
178 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
179 $button = ilSubmitButton::getInstance();
180
181 // creation buttons
182 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
183 if (count($this->getFormats()) > 1) {
184 // type selection
185 foreach ($this->getFormats() as $f) {
186 $options[$f["key"]] = $f["txt"];
187 }
188 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
189 $si = new ilSelectInputGUI($lng->txt("type"), "format");
190 $si->setOptions($options);
191 $ilToolbar->addInputItem($si, true);
192
193 $button->setCaption("exp_create_file");
194 $button->setCommand("createExportFile");
195 } else {
196 $format = $this->getFormats();
197 $format = $format[0];
198
199 $button->setCaption($lng->txt("exp_create_file") . " (" . $format["txt"] . ")", false);
200 $button->setCommand("create_" . $format["key"]);
201 }
202
203 $ilToolbar->addButtonInstance($button);
204
205 $table = $this->buildExportTableGUI();
206 $table->setSelectAllCheckbox("file");
207 foreach ($this->getCustomColumns() as $c) {
208 $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
209 }
210 foreach ($this->getCustomMultiCommands() as $c) {
211 $table->addCustomMultiCommand($c["txt"], "multi_" . $c["func"]);
212 }
213 $tpl->setContent($table->getHTML());
214 }
215
222 public function createExportFile()
223 {
224 global $ilCtrl, $lng;
225
226 if ($ilCtrl->getCmd() == "createExportFile") {
228 } else {
229 $format = substr($ilCtrl->getCmd(), 7);
230 }
231 foreach ($this->getFormats() as $f) {
232 if ($f["key"] == $format) {
233 if (is_object($f["call_obj"])) {
234 $f["call_obj"]->{$f["call_func"]}();
235 } elseif ($this->getParentGUI() instanceof ilContainerGUI) {
236 return $this->showItemSelection();
237 } elseif ($format == "xml") { // standard procedure
238 include_once("./Services/Export/classes/class.ilExport.php");
239 $exp = new ilExport();
240 $exp->exportObject($this->obj->getType(), $this->obj->getId());
241 }
242 }
243 }
244
245 ilUtil::sendSuccess($lng->txt("exp_file_created"), true);
246 $ilCtrl->redirect($this, "listExportFiles");
247 }
248
252 public function confirmDeletion()
253 {
254 global $ilCtrl, $tpl, $lng;
255
256 if (!is_array($_POST["file"]) || count($_POST["file"]) == 0) {
257 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
258 $ilCtrl->redirect($this, "listExportFiles");
259 } else {
260 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
261 $cgui = new ilConfirmationGUI();
262 $cgui->setFormAction($ilCtrl->getFormAction($this));
263 $cgui->setHeaderText($lng->txt("exp_really_delete"));
264 $cgui->setCancel($lng->txt("cancel"), "listExportFiles");
265 $cgui->setConfirm($lng->txt("delete"), "delete");
266
267 foreach ($_POST["file"] as $i) {
268 if (strpos($i, ':') !== false) {
269 $iarr = explode(":", $i);
270 $filename = $iarr[1];
271 } else {
272 $filename = $i;
273 }
274 $cgui->addItem("file[]", $i, $filename);
275 }
276
277 $tpl->setContent($cgui->getHTML());
278 }
279 }
280
284 public function delete()
285 {
286 global $ilCtrl;
287
288 foreach ($_POST["file"] as $file) {
289 $file = explode(":", $file);
290
291 $file[1] = basename($file[1]);
292
293 include_once("./Services/Export/classes/class.ilExport.php");
294 $export_dir = ilExport::_getExportDirectory(
295 $this->obj->getId(),
296 str_replace("..", "", $file[0]),
297 $this->obj->getType()
298 );
299
300 $exp_file = $export_dir . "/" . str_replace("..", "", $file[1]);
301 $exp_dir = $export_dir . "/" . substr($file[1], 0, strlen($file[1]) - 4);
302 if (@is_file($exp_file)) {
303 unlink($exp_file);
304 }
305 if (@is_dir($exp_dir)) {
306 ilUtil::delDir($exp_dir);
307 }
308
309 // delete entry in database
310 include_once './Services/Export/classes/class.ilExportFileInfo.php';
311 $info = new ilExportFileInfo($this->obj->getId(), $file[0], $file[1]);
312 $info->delete();
313 }
314 $ilCtrl->redirect($this, "listExportFiles");
315 }
316
320 public function download()
321 {
322 global $ilCtrl, $lng;
323
324 if (!isset($_GET["file"]) ||
325 is_array($_GET["file"])) {
326 $ilCtrl->redirect($this, "listExportFiles");
327 }
328
329 $file = explode(":", trim($_GET["file"]));
330 include_once("./Services/Export/classes/class.ilExport.php");
331 $export_dir = ilExport::_getExportDirectory(
332 $this->obj->getId(),
333 str_replace("..", "", $file[0]),
334 $this->obj->getType()
335 );
336
337 $file[1] = basename($file[1]);
338
340 $export_dir . "/" . $file[1],
341 $file[1]
342 );
343 }
344
351 public function handleCustomMultiCommand()
352 {
353 global $ilCtrl;
354
355 $cmd = substr($ilCtrl->getCmd(), 6);
356 foreach ($this->getCustomMultiCommands() as $c) {
357 if ($c["func"] == $cmd) {
358 $c["obj"]->{$c["func"]}($_POST["file"]);
359 }
360 }
361 }
362
367 protected function showItemSelection()
368 {
369 global $tpl;
370
371 $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
372 $tpl->setVariable('BODY_ATTRIBUTES', 'onload="ilDisableChilds(\'cmd\');"');
373
374 include_once './Services/Export/classes/class.ilExportSelectionTableGUI.php';
375 $table = new ilExportSelectionTableGUI($this, 'listExportFiles');
376 $table->parseContainer($this->getParentGUI()->object->getRefId());
377 $this->tpl->setContent($table->getHTML());
378 }
379
384 protected function saveItemSelection()
385 {
386 global $tree,$objDefinition, $ilAccess, $ilCtrl,$lng;
387
388 include_once './Services/Export/classes/class.ilExportOptions.php';
390 $eo->addOption(ilExportOptions::KEY_ROOT, 0, 0, $this->obj->getId());
391
392 $items_selected = false;
393 foreach ($tree->getSubTree($root = $tree->getNodeData($this->getParentGUI()->object->getRefId())) as $node) {
394 if ($node['type'] == 'rolf') {
395 continue;
396 }
397 if ($node['ref_id'] == $this->getParentGUI()->object->getRefId()) {
398 $eo->addOption(
400 $node['ref_id'],
401 $node['obj_id'],
403 );
404 continue;
405 }
406 // no export available or no access
407 if (!$objDefinition->allowExport($node['type']) or !$ilAccess->checkAccess('write', '', $node['ref_id'])) {
408 $eo->addOption(
410 $node['ref_id'],
411 $node['obj_id'],
413 );
414 continue;
415 }
416
417 $mode = isset($_POST['cp_options'][$node['ref_id']]['type']) ?
418 $_POST['cp_options'][$node['ref_id']]['type'] :
420 $eo->addOption(
422 $node['ref_id'],
423 $node['obj_id'],
424 $mode
425 );
426 if ($mode != ilExportOptions::EXPORT_OMIT) {
427 $items_selected = true;
428 }
429 }
430
431 include_once("./Services/Export/classes/class.ilExport.php");
432 if ($items_selected) {
433 // TODO: move this to background soap
434 $eo->read();
435 $exp = new ilExport();
436 foreach ($eo->getSubitemsForCreation($this->obj->getRefId()) as $ref_id) {
437 $obj_id = ilObject::_lookupObjId($ref_id);
438 $type = ilObject::_lookupType($obj_id);
439 $exp->exportObject($type, $obj_id);
440 }
441 // Fixme: there is a naming conflict between the container settings xml and the container subitem xml.
442 sleep(1);
443 // Export container
444 include_once './Services/Export/classes/class.ilExportContainer.php';
445 $cexp = new ilExportContainer($eo);
446 $cexp->exportObject($this->obj->getType(), $this->obj->getId());
447 } else {
448 $exp = new ilExport();
449 $exp->exportObject($this->obj->getType(), $this->obj->getId());
450 }
451
452 // Delete export options
453 $eo->delete();
454
455 ilUtil::sendSuccess($lng->txt('export_created'), true);
456 $ilCtrl->redirect($this, "listExportFiles");
457 }
458}
$tpl
Definition: ilias.php:10
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_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 sendSuccess($a_info="", $a_keep=false)
Send Success 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.
$i
Definition: disco.tpl.php:19
global $ilCtrl
Definition: ilias.php:18
$format
Definition: metadata.php:141
$info
Definition: index.php:5
global $lng
Definition: privfeed.php:17
$type
if(empty($password)) $table
Definition: pwgen.php:24
global $ilErr
Definition: raiseError.php:16
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file