ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  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 
49  protected function getParentGUI()
50  {
51  return $this->parent_gui;
52  }
53 
59  function addFormat($a_key, $a_txt = "", $a_call_obj = null, $a_call_func = "")
60  {
61  global $lng;
62 
63  if ($a_txt == "")
64  {
65  $a_txt = $lng->txt("exp_".$a_key);
66  }
67  $this->formats[] = array("key" => $a_key, "txt" => $a_txt,
68  "call_obj" => $a_call_obj, "call_func" => $a_call_func);
69  }
70 
76  function getFormats()
77  {
78  return $this->formats;
79  }
80 
87  function addCustomColumn($a_txt, $a_obj, $a_func)
88  {
89  $this->custom_columns[] = array("txt" => $a_txt,
90  "obj" => $a_obj,
91  "func" => $a_func);
92  }
93 
100  function addCustomMultiCommand($a_txt, $a_obj, $a_func)
101  {
102  $this->custom_multi_commands[] = array("txt" => $a_txt,
103  "obj" => $a_obj,
104  "func" => $a_func);
105  }
106 
111  {
113  }
114 
121  function getCustomColumns()
122  {
123  return $this->custom_columns;
124  }
125 
132  function executeCommand()
133  {
134  global $ilCtrl, $ilAccess, $ilErr, $lng;
135 
136  // this should work (at least) for repository objects
137  if(method_exists($this->obj, 'getRefId') and $this->obj->getRefId())
138  {
139  if(!$ilAccess->checkAccess('write','',$this->obj->getRefId()))
140  {
141  $ilErr->raiseError($lng->txt('permission_denied'),$ilErr->WARNING);
142  }
143  }
144 
145  $cmd = $ilCtrl->getCmd("listExportFiles");
146 
147  switch ($cmd)
148  {
149  case "listExportFiles":
150  $this->$cmd();
151  break;
152 
153  default:
154  if (substr($cmd, 0, 7) == "create_")
155  {
156  $this->createExportFile();
157  }
158  else if (substr($cmd, 0, 6) == "multi_") // custom multi command
159  {
160  $this->handleCustomMultiCommand();
161  }
162  else
163  {
164  $this->$cmd();
165  }
166  break;
167  }
168  }
169 
176  function listExportFiles()
177  {
178  global $tpl, $ilToolbar, $ilCtrl, $lng;
179 
180  // creation buttons
181  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
182  if (count($this->getFormats()) > 1)
183  {
184  // type selection
185  foreach ($this->getFormats() as $f)
186  {
187  $options[$f["key"]] = $f["txt"];
188  }
189  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
190  $si = new ilSelectInputGUI($lng->txt("type"), "format");
191  $si->setOptions($options);
192  $ilToolbar->addInputItem($si, true);
193  $ilToolbar->addFormButton($lng->txt("exp_create_file"), "createExportFile");
194  }
195  else
196  {
197  $format = $this->getFormats();
198  $format = $format[0];
199  $ilToolbar->addFormButton($lng->txt("exp_create_file")." (".$format["txt"].")", "create_".$format["key"]);
200  }
201 
202  include_once("./Services/Export/classes/class.ilExportTableGUI.php");
203  $table = new ilExportTableGUI($this, "listExportFiles", $this->obj);
204  $table->setSelectAllCheckbox("file");
205  foreach ($this->getCustomColumns() as $c)
206  {
207  $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
208  }
209  foreach ($this->getCustomMultiCommands() as $c)
210  {
211  $table->addCustomMultiCommand($c["txt"], "multi_".$c["func"]);
212  }
213  $tpl->setContent($table->getHTML());
214  }
215 
222  function createExportFile()
223  {
224  global $ilCtrl, $lng;
225 
226  if ($ilCtrl->getCmd() == "createExportFile")
227  {
228  $format = ilUtil::stripSlashes($_POST["format"]);
229  }
230  else
231  {
232  $format = substr($ilCtrl->getCmd(), 7);
233  }
234  foreach ($this->getFormats() as $f)
235  {
236  if ($f["key"] == $format)
237  {
238  if (is_object($f["call_obj"]))
239  {
240  $f["call_obj"]->$f["call_func"]();
241  }
242  elseif($this->getParentGUI() instanceof ilContainerGUI)
243  {
244  return $this->showItemSelection();
245  }
246  else if ($format == "xml") // standard procedure
247  {
248  include_once("./Services/Export/classes/class.ilExport.php");
249  $exp = new ilExport();
250  $exp->exportObject($this->obj->getType(),$this->obj->getId(), "4.3.0");
251  }
252  }
253  }
254 
255  ilUtil::sendSuccess($lng->txt("exp_file_created"), true);
256  $ilCtrl->redirect($this, "listExportFiles");
257  }
258 
262  function confirmDeletion()
263  {
264  global $ilCtrl, $tpl, $lng;
265 
266  if (!is_array($_POST["file"]) || count($_POST["file"]) == 0)
267  {
268  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
269  $ilCtrl->redirect($this, "listExportFiles");
270  }
271  else
272  {
273  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
274  $cgui = new ilConfirmationGUI();
275  $cgui->setFormAction($ilCtrl->getFormAction($this));
276  $cgui->setHeaderText($lng->txt("exp_really_delete"));
277  $cgui->setCancel($lng->txt("cancel"), "listExportFiles");
278  $cgui->setConfirm($lng->txt("delete"), "delete");
279 
280  foreach ($_POST["file"] as $i)
281  {
282  $iarr = explode(":", $i);
283  $cgui->addItem("file[]", $i, $iarr[1]);
284  }
285 
286  $tpl->setContent($cgui->getHTML());
287  }
288  }
289 
293  function delete()
294  {
295  global $ilCtrl;
296 
297  foreach($_POST["file"] as $file)
298  {
299  $file = explode(":", $file);
300 
301  $file[1] = basename($file[1]);
302 
303  include_once("./Services/Export/classes/class.ilExport.php");
304  $export_dir = ilExport::_getExportDirectory($this->obj->getId(),
305  str_replace("..", "", $file[0]), $this->obj->getType());
306 
307  $exp_file = $export_dir."/".str_replace("..", "", $file[1]);
308  $exp_dir = $export_dir."/".substr($file[1], 0, strlen($file[1]) - 4);
309  if (@is_file($exp_file))
310  {
311  unlink($exp_file);
312  }
313  if (@is_dir($exp_dir))
314  {
315  ilUtil::delDir($exp_dir);
316  }
317 
318  // delete entry in database
319  include_once './Services/Export/classes/class.ilExportFileInfo.php';
320  $info = new ilExportFileInfo($this->obj->getId(),$file[0],$file[1]);
321  $info->delete();
322  }
323  $ilCtrl->redirect($this, "listExportFiles");
324  }
325 
329  function download()
330  {
331  global $ilCtrl, $lng;
332 
333  if(!isset($_POST["file"]))
334  {
335  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
336  $ilCtrl->redirect($this, "listExportFiles");
337  }
338 
339  if (count($_POST["file"]) > 1)
340  {
341  ilUtil::sendFailure($lng->txt("exp_select_max_one_item"), true);
342  $ilCtrl->redirect($this, "listExportFiles");
343  }
344 
345  $file = explode(":", $_POST["file"][0]);
346  include_once("./Services/Export/classes/class.ilExport.php");
347  $export_dir = ilExport::_getExportDirectory($this->obj->getId(),
348  str_replace("..", "", $file[0]), $this->obj->getType());
349 
350  $file[1] = basename($file[1]);
351 
352  ilUtil::deliverFile($export_dir."/".$file[1],
353  $file[1]);
354  }
355 
363  {
364  global $ilCtrl;
365 
366  $cmd = substr($ilCtrl->getCmd(), 6);
367  foreach ($this->getCustomMultiCommands() as $c)
368  {
369  if ($c["func"] == $cmd)
370  {
371  $c["obj"]->$c["func"]($_POST["file"]);
372  }
373  }
374  }
375 
380  protected function showItemSelection()
381  {
382  global $tpl;
383 
384  $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
385  $tpl->setVariable('BODY_ATTRIBUTES','onload="ilDisableChilds(\'cmd\');"');
386 
387  include_once './Services/Export/classes/class.ilExportSelectionTableGUI.php';
388  $table = new ilExportSelectionTableGUI($this,'listExportFiles');
389  $table->parseContainer($this->getParentGUI()->object->getRefId());
390  $this->tpl->setContent($table->getHTML());
391  }
392 
397  protected function saveItemSelection()
398  {
399  global $tree,$objDefinition, $ilAccess, $ilCtrl,$lng;
400 
401  include_once './Services/Export/classes/class.ilExportOptions.php';
403  $eo->addOption(ilExportOptions::KEY_ROOT,0,0,$this->obj->getId());
404 
405  $items_selected = false;
406  foreach($tree->getSubTree($root = $tree->getNodeData($this->getParentGUI()->object->getRefId())) as $node)
407  {
408  if($node['type'] == 'rolf')
409  {
410  continue;
411  }
412  if($node['ref_id'] == $this->getParentGUI()->object->getRefId())
413  {
414  $eo->addOption(
416  $node['ref_id'],
417  $node['obj_id'],
419  );
420  continue;
421  }
422  // no export available or no access
423  if(!$objDefinition->allowExport($node['type']) or !$ilAccess->checkAccess('write','',$node['ref_id']))
424  {
425 
426  $eo->addOption(
428  $node['ref_id'],
429  $node['obj_id'],
431  );
432  continue;
433  }
434 
435  $mode = isset($_POST['cp_options'][$node['ref_id']]['type']) ?
436  $_POST['cp_options'][$node['ref_id']]['type'] :
438  $eo->addOption(
440  $node['ref_id'],
441  $node['obj_id'],
442  $mode
443  );
444  if($mode != ilExportOptions::EXPORT_OMIT)
445  {
446  $items_selected = true;
447  }
448  }
449 
450  include_once("./Services/Export/classes/class.ilExport.php");
451  if($items_selected)
452  {
453  // TODO: move this to background soap
454  $eo->read();
455  $exp = new ilExport();
456  foreach($eo->getSubitemsForCreation($this->obj->getRefId()) as $ref_id)
457  {
458  $obj_id = ilObject::_lookupObjId($ref_id);
459  $type = ilObject::_lookupType($obj_id);
460  $exp->exportObject($type,$obj_id,'4.1.0');
461  }
462  // Fixme: there is a naming conflict between the container settings xml and the container subitem xml.
463  sleep(1);
464  // Export container
465  include_once './Services/Export/classes/class.ilExportContainer.php';
466  $cexp = new ilExportContainer($eo);
467  $cexp->exportObject($this->obj->getType(),$this->obj->getId(),'4.1.0');
468  }
469  else
470  {
471  $exp = new ilExport();
472  $exp->exportObject($this->obj->getType(),$this->obj->getId(), "4.1.0");
473  }
474 
475  // Delete export options
476  $eo->delete();
477 
478  ilUtil::sendSuccess($lng->txt('export_created'),true);
479  $ilCtrl->redirect($this, "listExportFiles");
480  }
481 }
482 ?>