ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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();
19 
20  private $parent_gui = null;
21 
28  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  {
35  $this->obj = $a_parent_gui->object;
36  }
37  else
38  {
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  function addFormat($a_key, $a_txt = "", $a_call_obj = null, $a_call_func = "")
70  {
71  global $lng;
72 
73  if ($a_txt == "")
74  {
75  $a_txt = $lng->txt("exp_".$a_key);
76  }
77  $this->formats[] = array("key" => $a_key, "txt" => $a_txt,
78  "call_obj" => $a_call_obj, "call_func" => $a_call_func);
79  }
80 
86  function getFormats()
87  {
88  return $this->formats;
89  }
90 
97  function addCustomColumn($a_txt, $a_obj, $a_func)
98  {
99  $this->custom_columns[] = array("txt" => $a_txt,
100  "obj" => $a_obj,
101  "func" => $a_func);
102  }
103 
110  function addCustomMultiCommand($a_txt, $a_obj, $a_func)
111  {
112  $this->custom_multi_commands[] = array("txt" => $a_txt,
113  "obj" => $a_obj,
114  "func" => $a_func);
115  }
116 
121  {
123  }
124 
131  function getCustomColumns()
132  {
133  return $this->custom_columns;
134  }
135 
142  function executeCommand()
143  {
144  global $ilCtrl, $ilAccess, $ilErr, $lng;
145 
146  // this should work (at least) for repository objects
147  if(method_exists($this->obj, 'getRefId') and $this->obj->getRefId())
148  {
149  if(!$ilAccess->checkAccess('write','',$this->obj->getRefId()))
150  {
151  $ilErr->raiseError($lng->txt('permission_denied'),$ilErr->WARNING);
152  }
153  }
154 
155  $cmd = $ilCtrl->getCmd("listExportFiles");
156 
157  switch ($cmd)
158  {
159  case "listExportFiles":
160  $this->$cmd();
161  break;
162 
163  default:
164  if (substr($cmd, 0, 7) == "create_")
165  {
166  $this->createExportFile();
167  }
168  else if (substr($cmd, 0, 6) == "multi_") // custom multi command
169  {
170  $this->handleCustomMultiCommand();
171  }
172  else
173  {
174  $this->$cmd();
175  }
176  break;
177  }
178  }
179 
186  function listExportFiles()
187  {
188  global $tpl, $ilToolbar, $ilCtrl, $lng;
189 
190  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
191  $button = ilSubmitButton::getInstance();
192 
193  // creation buttons
194  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
195  if (count($this->getFormats()) > 1)
196  {
197  // type selection
198  foreach ($this->getFormats() as $f)
199  {
200  $options[$f["key"]] = $f["txt"];
201  }
202  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
203  $si = new ilSelectInputGUI($lng->txt("type"), "format");
204  $si->setOptions($options);
205  $ilToolbar->addInputItem($si, true);
206 
207  $button->setCaption("exp_create_file");
208  $button->setCommand("createExportFile");
209  }
210  else
211  {
212  $format = $this->getFormats();
213  $format = $format[0];
214 
215  $button->setCaption($lng->txt("exp_create_file")." (".$format["txt"].")", false);
216  $button->setCommand("create_".$format["key"]);
217  }
218 
219  $ilToolbar->addButtonInstance($button);
220 
221  $table = $this->buildExportTableGUI();
222  $table->setSelectAllCheckbox("file");
223  foreach ($this->getCustomColumns() as $c)
224  {
225  $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
226  }
227  foreach ($this->getCustomMultiCommands() as $c)
228  {
229  $table->addCustomMultiCommand($c["txt"], "multi_".$c["func"]);
230  }
231  $tpl->setContent($table->getHTML());
232  }
233 
240  function createExportFile()
241  {
242  global $ilCtrl, $lng;
243 
244  if ($ilCtrl->getCmd() == "createExportFile")
245  {
246  $format = ilUtil::stripSlashes($_POST["format"]);
247  }
248  else
249  {
250  $format = substr($ilCtrl->getCmd(), 7);
251  }
252  foreach ($this->getFormats() as $f)
253  {
254  if ($f["key"] == $format)
255  {
256  if (is_object($f["call_obj"]))
257  {
258  $f["call_obj"]->{$f["call_func"]}();
259  }
260  elseif($this->getParentGUI() instanceof ilContainerGUI)
261  {
262  return $this->showItemSelection();
263  }
264  else if ($format == "xml") // standard procedure
265  {
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  function confirmDeletion()
281  {
282  global $ilCtrl, $tpl, $lng;
283 
284  if (!is_array($_POST["file"]) || count($_POST["file"]) == 0)
285  {
286  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
287  $ilCtrl->redirect($this, "listExportFiles");
288  }
289  else
290  {
291  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
292  $cgui = new ilConfirmationGUI();
293  $cgui->setFormAction($ilCtrl->getFormAction($this));
294  $cgui->setHeaderText($lng->txt("exp_really_delete"));
295  $cgui->setCancel($lng->txt("cancel"), "listExportFiles");
296  $cgui->setConfirm($lng->txt("delete"), "delete");
297 
298  foreach ($_POST["file"] as $i)
299  {
300  if(strpos($i, ':') !== false)
301  {
302  $iarr = explode(":", $i);
303  $filename = $iarr[1];
304  }
305  else
306  {
307  $filename = $i;
308  }
309  $cgui->addItem("file[]", $i, $filename);
310  }
311 
312  $tpl->setContent($cgui->getHTML());
313  }
314  }
315 
319  function delete()
320  {
321  global $ilCtrl;
322 
323  foreach($_POST["file"] as $file)
324  {
325  $file = explode(":", $file);
326 
327  $file[1] = basename($file[1]);
328 
329  include_once("./Services/Export/classes/class.ilExport.php");
330  $export_dir = ilExport::_getExportDirectory($this->obj->getId(),
331  str_replace("..", "", $file[0]), $this->obj->getType());
332 
333  $exp_file = $export_dir."/".str_replace("..", "", $file[1]);
334  $exp_dir = $export_dir."/".substr($file[1], 0, strlen($file[1]) - 4);
335  if (@is_file($exp_file))
336  {
337  unlink($exp_file);
338  }
339  if (@is_dir($exp_dir))
340  {
341  ilUtil::delDir($exp_dir);
342  }
343 
344  // delete entry in database
345  include_once './Services/Export/classes/class.ilExportFileInfo.php';
346  $info = new ilExportFileInfo($this->obj->getId(),$file[0],$file[1]);
347  $info->delete();
348  }
349  $ilCtrl->redirect($this, "listExportFiles");
350  }
351 
355  public function download()
356  {
357  global $ilCtrl, $lng;
358 
359  if(!isset($_GET["file"]) ||
360  is_array($_GET["file"]))
361  {
362  $ilCtrl->redirect($this, "listExportFiles");
363  }
364 
365  $file = explode(":", trim($_GET["file"]));
366  include_once("./Services/Export/classes/class.ilExport.php");
367  $export_dir = ilExport::_getExportDirectory($this->obj->getId(),
368  str_replace("..", "", $file[0]), $this->obj->getType());
369 
370  $file[1] = basename($file[1]);
371 
372  ilUtil::deliverFile($export_dir."/".$file[1],
373  $file[1]);
374  }
375 
383  {
384  global $ilCtrl;
385 
386  $cmd = substr($ilCtrl->getCmd(), 6);
387  foreach ($this->getCustomMultiCommands() as $c)
388  {
389  if ($c["func"] == $cmd)
390  {
391  $c["obj"]->{$c["func"]}($_POST["file"]);
392  }
393  }
394  }
395 
400  protected function showItemSelection()
401  {
402  global $tpl;
403 
404  $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
405  $tpl->setVariable('BODY_ATTRIBUTES','onload="ilDisableChilds(\'cmd\');"');
406 
407  include_once './Services/Export/classes/class.ilExportSelectionTableGUI.php';
408  $table = new ilExportSelectionTableGUI($this,'listExportFiles');
409  $table->parseContainer($this->getParentGUI()->object->getRefId());
410  $this->tpl->setContent($table->getHTML());
411  }
412 
417  protected function saveItemSelection()
418  {
419  global $tree,$objDefinition, $ilAccess, $ilCtrl,$lng;
420 
421  include_once './Services/Export/classes/class.ilExportOptions.php';
423  $eo->addOption(ilExportOptions::KEY_ROOT,0,0,$this->obj->getId());
424 
425  $items_selected = false;
426  foreach($tree->getSubTree($root = $tree->getNodeData($this->getParentGUI()->object->getRefId())) as $node)
427  {
428  if($node['type'] == 'rolf')
429  {
430  continue;
431  }
432  if($node['ref_id'] == $this->getParentGUI()->object->getRefId())
433  {
434  $eo->addOption(
436  $node['ref_id'],
437  $node['obj_id'],
439  );
440  continue;
441  }
442  // no export available or no access
443  if(!$objDefinition->allowExport($node['type']) or !$ilAccess->checkAccess('write','',$node['ref_id']))
444  {
445 
446  $eo->addOption(
448  $node['ref_id'],
449  $node['obj_id'],
451  );
452  continue;
453  }
454 
455  $mode = isset($_POST['cp_options'][$node['ref_id']]['type']) ?
456  $_POST['cp_options'][$node['ref_id']]['type'] :
458  $eo->addOption(
460  $node['ref_id'],
461  $node['obj_id'],
462  $mode
463  );
464  if($mode != ilExportOptions::EXPORT_OMIT)
465  {
466  $items_selected = true;
467  }
468  }
469 
470  include_once("./Services/Export/classes/class.ilExport.php");
471  if($items_selected)
472  {
473  // TODO: move this to background soap
474  $eo->read();
475  $exp = new ilExport();
476  foreach($eo->getSubitemsForCreation($this->obj->getRefId()) as $ref_id)
477  {
478  $obj_id = ilObject::_lookupObjId($ref_id);
479  $type = ilObject::_lookupType($obj_id);
480  $exp->exportObject($type,$obj_id);
481  }
482  // Fixme: there is a naming conflict between the container settings xml and the container subitem xml.
483  sleep(1);
484  // Export container
485  include_once './Services/Export/classes/class.ilExportContainer.php';
486  $cexp = new ilExportContainer($eo);
487  $cexp->exportObject($this->obj->getType(),$this->obj->getId());
488  }
489  else
490  {
491  $exp = new ilExport();
492  $exp->exportObject($this->obj->getType(),$this->obj->getId());
493  }
494 
495  // Delete export options
496  $eo->delete();
497 
498  ilUtil::sendSuccess($lng->txt('export_created'),true);
499  $ilCtrl->redirect($this, "listExportFiles");
500  }
501 }
502 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
global $ilErr
Definition: raiseError.php:16
download()
Download file.
showItemSelection()
Show container item selection table.
This class represents a selection list property in a property form.
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
handleCustomMultiCommand()
Handle custom multi command.
addCustomColumn($a_txt, $a_obj, $a_func)
Add custom column.
global $tpl
Definition: ilias.php:8
addFormat($a_key, $a_txt="", $a_call_obj=null, $a_call_func="")
Add formats.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getCustomColumns()
Get custom columns.
Export User Interface Class.
static newInstance($a_export_id)
Create new instance.
addCustomMultiCommand($a_txt, $a_obj, $a_func)
Add custom multi command.
$info
Definition: example_052.php:80
saveItemSelection()
Save selection of subitems.
if(!is_array($argv)) $options
static _lookupObjId($a_id)
Stores information of creation date and versions of export files
executeCommand()
Execute command.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
getFormats()
Get formats.
Set cell number formats
listExportFiles()
List export files.
getCustomMultiCommands()
Get custom multi commands.
$ref_id
Definition: sahs_server.php:39
Create new PHPExcel object
obj_idprivate
global $lng
Definition: privfeed.php:17
confirmDeletion()
Confirm file deletion.
Class ilContainerGUI.
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
__construct($a_parent_gui, $a_main_obj=null)
Constuctor.
static allocateExportId()
Allocate a new export id.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$_POST["username"]
getParentGUI()
get parent gui
Confirmation screen class.
createExportFile()
Create export file.