ILIAS  release_4-4 Revision
class.ilOrgUnitSimpleUserImportGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once("class.ilOrgUnitSimpleUserImport.php");
11 
15  protected $tabs_gui;
19  protected $toolbar;
23  protected $ctrl;
27  protected $tpl;
31  protected $parent_object;
35  protected $lng;
39  protected $ilAccess;
40 
41 
45  function __construct($parent_gui) {
46  global $tpl, $ilCtrl, $ilTabs, $ilToolbar, $lng, $ilAccess;
47  $this->tpl = $tpl;
48  $this->ctrl = $ilCtrl;
49  $this->parent_gui = $parent_gui;
50  $this->parent_object = $parent_gui->object;
51  $this->tabs_gui = $this->parent_gui->tabs_gui;
52  $this->toolbar = $ilToolbar;
53  $this->lng = $lng;
54  $this->ilAccess = $ilAccess;
55  $this->lng->loadLanguageModule('user');
56  if (! $this->ilAccess->checkaccess("write", "", $this->parent_gui->object->getRefId())) {
57  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
58  }
59  }
60 
64  public function executeCommand()
65  {
66  $cmd = $this->ctrl->getCmd();
67 
68  switch ($cmd) {
69  case 'userImportScreen':
70  $this->userImportScreen();
71  break;
72  case 'startImport':
73  $this->startImport();
74  break;
75  }
76  return true;
77  }
78 
79  public function userImportScreen() {
80  $form = $this->initForm();
81  $this->tpl->setContent($form->getHTML());
82  }
83 
84 
85  protected function initForm() {
86  $form = new ilPropertyFormGUI();
87  $input = new ilFileInputGUI($this->lng->txt("import_xml_file"), "import_file");
88  $input->setRequired(true);
89  $form->addItem($input);
90  $form->setFormAction($this->ctrl->getFormAction($this));
91  $form->addCommandButton("startImport", $this->lng->txt("import"));
92 
93  return $form;
94  }
95 
96  public function startImport() {
97  $form = $this->initForm();
98  if (! $form->checkInput()) {
99  $this->tpl->setContent($form->getHTML());
100  } else {
101  $file = $form->getInput("import_file");
102  $importer = new ilOrgUnitSimpleUserImport();
103  try {
104  $importer->simpleUserImport($file["tmp_name"]);
105  } catch (Exception $e) {
106  $this->ilLog->wirte($e->getMessage() . " - " . $e->getTraceAsString());
107  ilUtil::sendFailure($lng->txt("import_failed"), true);
108  $this->ctrl->redirect($this, "render");
109  }
110  $this->displayImportResults($importer);
111  }
112  }
113 
117  public function displayImportResults($importer) {
118  if (! $importer->hasErrors() && ! $importer->hasWarnings()) {
119  $stats = $importer->getStats();
120  ilUtil::sendSuccess(sprintf($this->lng->txt("user_import_successful"), $stats["created"], $stats["removed"]), true);
121  }
122  if ($importer->hasWarnings()) {
123  $msg = $this->lng->txt("import_terminated_with_warnings") . "<br>";
124  foreach ($importer->getWarnings() as $warning) {
125  $msg .= "-" . $this->lng->txt($warning["lang_var"]) . " (Import ID: " . $warning["import_id"] . ")<br>";
126  }
127  ilUtil::sendInfo($msg, true);
128  }
129  if ($importer->hasErrors()) {
130  $msg = $this->lng->txt("import_terminated_with_errors") . "<br>";
131  foreach ($importer->getErrors() as $warning) {
132  $msg .= "- " . $this->lng->txt($warning["lang_var"]) . " (Import ID: " . $warning["import_id"] . ")<br>";
133  }
134  ilUtil::sendFailure($msg, true);
135  }
136  }
137 }
138 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
print $file
This class represents a property form user interface.
This class represents a file property in a property form.
Class ilOrgUnitSimpleUserImport.
$cmd
Definition: sahs_server.php:35
logging
Definition: class.ilLog.php:18
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilOrgUnitSimpleUserImportGUI.
setRequired($a_required)
Set Required.