ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules 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.4.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  if(strpos($i, ':') !== false)
283  {
284  $iarr = explode(":", $i);
285  $filename = $iarr[1];
286  }
287  else
288  {
289  $filename = $i;
290  }
291  $cgui->addItem("file[]", $i, $filename);
292  }
293 
294  $tpl->setContent($cgui->getHTML());
295  }
296  }
297 
301  function delete()
302  {
303  global $ilCtrl;
304 
305  foreach($_POST["file"] as $file)
306  {
307  $file = explode(":", $file);
308 
309  $file[1] = basename($file[1]);
310 
311  include_once("./Services/Export/classes/class.ilExport.php");
312  $export_dir = ilExport::_getExportDirectory($this->obj->getId(),
313  str_replace("..", "", $file[0]), $this->obj->getType());
314 
315  $exp_file = $export_dir."/".str_replace("..", "", $file[1]);
316  $exp_dir = $export_dir."/".substr($file[1], 0, strlen($file[1]) - 4);
317  if (@is_file($exp_file))
318  {
319  unlink($exp_file);
320  }
321  if (@is_dir($exp_dir))
322  {
323  ilUtil::delDir($exp_dir);
324  }
325 
326  // delete entry in database
327  include_once './Services/Export/classes/class.ilExportFileInfo.php';
328  $info = new ilExportFileInfo($this->obj->getId(),$file[0],$file[1]);
329  $info->delete();
330  }
331  $ilCtrl->redirect($this, "listExportFiles");
332  }
333 
337  function download()
338  {
339  global $ilCtrl, $lng;
340 
341  if(!isset($_POST["file"]))
342  {
343  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
344  $ilCtrl->redirect($this, "listExportFiles");
345  }
346 
347  if (count($_POST["file"]) > 1)
348  {
349  ilUtil::sendFailure($lng->txt("exp_select_max_one_item"), true);
350  $ilCtrl->redirect($this, "listExportFiles");
351  }
352 
353  $file = explode(":", $_POST["file"][0]);
354  include_once("./Services/Export/classes/class.ilExport.php");
355  $export_dir = ilExport::_getExportDirectory($this->obj->getId(),
356  str_replace("..", "", $file[0]), $this->obj->getType());
357 
358  $file[1] = basename($file[1]);
359 
360  ilUtil::deliverFile($export_dir."/".$file[1],
361  $file[1]);
362  }
363 
371  {
372  global $ilCtrl;
373 
374  $cmd = substr($ilCtrl->getCmd(), 6);
375  foreach ($this->getCustomMultiCommands() as $c)
376  {
377  if ($c["func"] == $cmd)
378  {
379  $c["obj"]->$c["func"]($_POST["file"]);
380  }
381  }
382  }
383 
388  protected function showItemSelection()
389  {
390  global $tpl;
391 
392  $tpl->addJavaScript('./Services/CopyWizard/js/ilContainer.js');
393  $tpl->setVariable('BODY_ATTRIBUTES','onload="ilDisableChilds(\'cmd\');"');
394 
395  include_once './Services/Export/classes/class.ilExportSelectionTableGUI.php';
396  $table = new ilExportSelectionTableGUI($this,'listExportFiles');
397  $table->parseContainer($this->getParentGUI()->object->getRefId());
398  $this->tpl->setContent($table->getHTML());
399  }
400 
405  protected function saveItemSelection()
406  {
407  global $tree,$objDefinition, $ilAccess, $ilCtrl,$lng;
408 
409  include_once './Services/Export/classes/class.ilExportOptions.php';
411  $eo->addOption(ilExportOptions::KEY_ROOT,0,0,$this->obj->getId());
412 
413  $items_selected = false;
414  foreach($tree->getSubTree($root = $tree->getNodeData($this->getParentGUI()->object->getRefId())) as $node)
415  {
416  if($node['type'] == 'rolf')
417  {
418  continue;
419  }
420  if($node['ref_id'] == $this->getParentGUI()->object->getRefId())
421  {
422  $eo->addOption(
424  $node['ref_id'],
425  $node['obj_id'],
427  );
428  continue;
429  }
430  // no export available or no access
431  if(!$objDefinition->allowExport($node['type']) or !$ilAccess->checkAccess('write','',$node['ref_id']))
432  {
433 
434  $eo->addOption(
436  $node['ref_id'],
437  $node['obj_id'],
439  );
440  continue;
441  }
442 
443  $mode = isset($_POST['cp_options'][$node['ref_id']]['type']) ?
444  $_POST['cp_options'][$node['ref_id']]['type'] :
446  $eo->addOption(
448  $node['ref_id'],
449  $node['obj_id'],
450  $mode
451  );
452  if($mode != ilExportOptions::EXPORT_OMIT)
453  {
454  $items_selected = true;
455  }
456  }
457 
458  include_once("./Services/Export/classes/class.ilExport.php");
459  if($items_selected)
460  {
461  // TODO: move this to background soap
462  $eo->read();
463  $exp = new ilExport();
464  foreach($eo->getSubitemsForCreation($this->obj->getRefId()) as $ref_id)
465  {
466  $obj_id = ilObject::_lookupObjId($ref_id);
467  $type = ilObject::_lookupType($obj_id);
468  $exp->exportObject($type,$obj_id,'4.1.0');
469  }
470  // Fixme: there is a naming conflict between the container settings xml and the container subitem xml.
471  sleep(1);
472  // Export container
473  include_once './Services/Export/classes/class.ilExportContainer.php';
474  $cexp = new ilExportContainer($eo);
475  $cexp->exportObject($this->obj->getType(),$this->obj->getId(),'4.1.0');
476  }
477  else
478  {
479  $exp = new ilExport();
480  $exp->exportObject($this->obj->getType(),$this->obj->getId(), "4.1.0");
481  }
482 
483  // Delete export options
484  $eo->delete();
485 
486  ilUtil::sendSuccess($lng->txt('export_created'),true);
487  $ilCtrl->redirect($this, "listExportFiles");
488  }
489 }
490 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
print $file
$_POST['username']
Definition: cron.php:12
download()
Download file.
showItemSelection()
Show container item selection table.
This class represents a selection list property in a property form.
$cmd
Definition: sahs_server.php:35
handleCustomMultiCommand()
Handle custom multi command.
addCustomColumn($a_txt, $a_obj, $a_func)
Add custom column.
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.
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.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
delete()
Delete one export entry.
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.
static _lookupType($a_id, $a_reference=false)
lookup object type
getFormats()
Get formats.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$filename
Definition: buildRTE.php:89
listExportFiles()
List export files.
getCustomMultiCommands()
Get custom multi commands.
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:40
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.
__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
getParentGUI()
get parent gui
Confirmation screen class.
createExportFile()
Create export file.