ILIAS  eassessment Revision 61809
 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)
29  {
30  global $lng,$tpl;
31 
32  $this->parent_gui = $a_parent_gui;
33  $this->obj = $a_parent_gui->object;
34  $lng->loadLanguageModule("exp");
35  $this->tpl = $tpl;
36  }
37 
42  protected function getParentGUI()
43  {
44  return $this->parent_gui;
45  }
46 
52  function addFormat($a_key, $a_txt = "", $a_call_obj = null, $a_call_func = "")
53  {
54  global $lng;
55 
56  if ($a_txt == "")
57  {
58  $a_txt = $lng->txt("exp_".$a_key);
59  }
60  $this->formats[] = array("key" => $a_key, "txt" => $a_txt,
61  "call_obj" => $a_call_obj, "call_func" => $a_call_func);
62  }
63 
69  function getFormats()
70  {
71  return $this->formats;
72  }
73 
80  function addCustomColumn($a_txt, $a_obj, $a_func)
81  {
82  $this->custom_columns[] = array("txt" => $a_txt,
83  "obj" => $a_obj,
84  "func" => $a_func);
85  }
86 
93  function addCustomMultiCommand($a_txt, $a_obj, $a_func)
94  {
95  $this->custom_multi_commands[] = array("txt" => $a_txt,
96  "obj" => $a_obj,
97  "func" => $a_func);
98  }
99 
104  {
106  }
107 
114  function getCustomColumns()
115  {
116  return $this->custom_columns;
117  }
118 
125  function executeCommand()
126  {
127  global $ilCtrl;
128 
129  $cmd = $ilCtrl->getCmd("listExportFiles");
130 
131  switch ($cmd)
132  {
133  case "listExportFiles":
134  $this->$cmd();
135  break;
136 
137  default:
138  if (substr($cmd, 0, 7) == "create_")
139  {
140  $this->createExportFile();
141  }
142  else if (substr($cmd, 0, 6) == "multi_") // custom multi command
143  {
144  $this->handleCustomMultiCommand();
145  }
146  else
147  {
148  $this->$cmd();
149  }
150  break;
151  }
152  }
153 
160  function listExportFiles()
161  {
162  global $tpl, $ilToolbar, $ilCtrl, $lng;
163 
164  // creation buttons
165  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
166  if (count($this->getFormats()) > 1)
167  {
168  // type selection
169  foreach ($this->getFormats() as $f)
170  {
171  $options[$f["key"]] = $f["txt"];
172  }
173  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
174  $si = new ilSelectInputGUI($lng->txt("type"), "format");
175  $si->setOptions($options);
176  $ilToolbar->addInputItem($si, true);
177  $ilToolbar->addFormButton($lng->txt("exp_create_file"), "createExportFile");
178  }
179  else
180  {
181  $format = $this->getFormats();
182  $format = $format[0];
183  $ilToolbar->addFormButton($lng->txt("exp_create_file")." (".$format["txt"].")", "create_".$format["key"]);
184  }
185 
186  include_once("./Services/Export/classes/class.ilExportTableGUI.php");
187  $table = new ilExportTableGUI($this, "listExportFiles", $this->obj);
188  $table->setSelectAllCheckbox("file");
189  foreach ($this->getCustomColumns() as $c)
190  {
191  $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
192  }
193  foreach ($this->getCustomMultiCommands() as $c)
194  {
195  $table->addCustomMultiCommand($c["txt"], "multi_".$c["func"]);
196  }
197  $tpl->setContent($table->getHTML());
198 
199  }
200 
207  function createExportFile()
208  {
209  global $ilCtrl;
210 
211  if ($ilCtrl->getCmd() == "createExportFile")
212  {
213  $format = ilUtil::stripSlashes($_POST["format"]);
214  }
215  else
216  {
217  $format = substr($ilCtrl->getCmd(), 7);
218  }
219  foreach ($this->getFormats() as $f)
220  {
221  if ($f["key"] == $format)
222  {
223  if (is_object($f["call_obj"]))
224  {
225  $f["call_obj"]->$f["call_func"]();
226  }
227  elseif($this->getParentGUI() instanceof ilContainerGUI)
228  {
229  return $this->showItemSelection();
230  }
231  else if ($format == "xml") // standard procedure
232  {
233  include_once("./Services/Export/classes/class.ilExport.php");
234  $exp = new ilExport();
235  $exp->exportObject($this->obj->getType(),$this->obj->getId(), "4.1.0");
236  }
237  }
238  }
239  $ilCtrl->redirect($this, "listExportFiles");
240  }
241 
245  function confirmDeletion()
246  {
247  global $ilCtrl, $tpl, $lng;
248 
249  if (!is_array($_POST["file"]) || count($_POST["file"]) == 0)
250  {
251  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
252  $ilCtrl->redirect($this, "listExportFiles");
253  }
254  else
255  {
256  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
257  $cgui = new ilConfirmationGUI();
258  $cgui->setFormAction($ilCtrl->getFormAction($this));
259  $cgui->setHeaderText($lng->txt("exp_really_delete"));
260  $cgui->setCancel($lng->txt("cancel"), "listExportFiles");
261  $cgui->setConfirm($lng->txt("delete"), "delete");
262 
263  foreach ($_POST["file"] as $i)
264  {
265  $iarr = explode(":", $i);
266  $cgui->addItem("file[]", $i, $iarr[1]);
267  }
268 
269  $tpl->setContent($cgui->getHTML());
270  }
271  }
272 
276  function delete()
277  {
278  global $ilCtrl;
279 
280  foreach($_POST["file"] as $file)
281  {
282  $file = explode(":", $file);
283 
284  include_once("./Services/Export/classes/class.ilExport.php");
285  $export_dir = ilExport::_getExportDirectory($this->obj->getId(),
286  str_replace("..", "", $file[0]), $this->obj->getType());
287 
288  $exp_file = $export_dir."/".str_replace("..", "", $file[1]);
289  $exp_dir = $export_dir."/".substr($file[1], 0, strlen($file[1]) - 4);
290  if (@is_file($exp_file))
291  {
292  unlink($exp_file);
293  }
294  if (@is_dir($exp_dir))
295  {
296  ilUtil::delDir($exp_dir);
297  }
298 
299  // delete entry in database
300  include_once './Services/Export/classes/class.ilExportFileInfo.php';
301  $info = new ilExportFileInfo($this->obj->getId(),$file[0],$file[1]);
302  $info->delete();
303  }
304  $ilCtrl->redirect($this, "listExportFiles");
305  }
306 
310  function download()
311  {
312  global $ilCtrl, $lng;
313 
314  if(!isset($_POST["file"]))
315  {
316  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
317  $ilCtrl->redirect($this, "listExportFiles");
318  }
319 
320  if (count($_POST["file"]) > 1)
321  {
322  ilUtil::sendFailure($lng->txt("exp_select_max_one_item"), true);
323  $ilCtrl->redirect($this, "listExportFiles");
324  }
325 
326  $file = explode(":", $_POST["file"][0]);
327  include_once("./Services/Export/classes/class.ilExport.php");
328  $export_dir = ilExport::_getExportDirectory($this->obj->getId(),
329  str_replace("..", "", $file[0]), $this->obj->getType());
330  ilUtil::deliverFile($export_dir."/".$file[1],
331  $file[1]);
332  }
333 
341  {
342  global $ilCtrl;
343 
344  $cmd = substr($ilCtrl->getCmd(), 6);
345  foreach ($this->getCustomMultiCommands() as $c)
346  {
347  if ($c["func"] == $cmd)
348  {
349  $c["obj"]->$c["func"]($_POST["file"]);
350  }
351  }
352  }
353 
358  protected function showItemSelection()
359  {
360  global $tpl;
361 
362  $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
363  $tpl->setVariable('BODY_ATTRIBUTES','onload="ilDisableChilds(\'cmd\');"');
364 
365  include_once './Services/Export/classes/class.ilExportSelectionTableGUI.php';
366  $table = new ilExportSelectionTableGUI($this,'listExportFiles');
367  $table->parseContainer($this->getParentGUI()->object->getRefId());
368  $this->tpl->setContent($table->getHTML());
369  }
370 
375  protected function saveItemSelection()
376  {
377  global $tree,$objDefinition, $ilAccess, $ilCtrl,$lng;
378 
379  include_once './Services/Export/classes/class.ilExportOptions.php';
381  $eo->addOption(ilExportOptions::KEY_ROOT,0,0,$this->obj->getId());
382 
383  $items_selected = false;
384  foreach($tree->getSubTree($root = $tree->getNodeData($this->getParentGUI()->object->getRefId())) as $node)
385  {
386  if($node['type'] == 'rolf')
387  {
388  continue;
389  }
390  if($node['ref_id'] == $this->getParentGUI()->object->getRefId())
391  {
392  $eo->addOption(
394  $node['ref_id'],
395  $node['obj_id'],
397  );
398  continue;
399  }
400  // no export available or no access
401  if(!$objDefinition->allowExport($node['type']) or !$ilAccess->checkAccess('write','',$node['ref_id']))
402  {
403 
404  $eo->addOption(
406  $node['ref_id'],
407  $node['obj_id'],
409  );
410  continue;
411  }
412 
413  $mode = isset($_POST['cp_options'][$node['ref_id']]['type']) ?
414  $_POST['cp_options'][$node['ref_id']]['type'] :
416  $eo->addOption(
418  $node['ref_id'],
419  $node['obj_id'],
420  $mode
421  );
422  if($mode != ilExportOptions::EXPORT_OMIT)
423  {
424  $items_selected = true;
425  }
426  }
427 
428  include_once("./Services/Export/classes/class.ilExport.php");
429  if($items_selected)
430  {
431  // TODO: move this to background soap
432  $eo->read();
433  $exp = new ilExport();
434  foreach($eo->getSubitemsForCreation($this->obj->getRefId()) as $ref_id)
435  {
436  $obj_id = ilObject::_lookupObjId($ref_id);
437  $type = ilObject::_lookupType($obj_id);
438  $exp->exportObject($type,$obj_id,'4.1.0');
439  }
440  // Fixme: there is a naming conflict between the container settings xml and the container subitem xml.
441  sleep(1);
442  // Export container
443  include_once './Services/Export/classes/class.ilExportContainer.php';
444  $cexp = new ilExportContainer($eo);
445  $cexp->exportObject($this->obj->getType(),$this->obj->getId(),'4.1.0');
446  }
447  else
448  {
449  $exp = new ilExport();
450  $exp->exportObject($this->obj->getType(),$this->obj->getId(), "4.1.0");
451  }
452 
453  // Delete export options
454  $eo->delete();
455 
456  ilUtil::sendSuccess($lng->txt('export_created'),true);
457  $ilCtrl->redirect($this, "listExportFiles");
458  }
459 }
460 ?>