ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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');
4 
13 
17  protected $tabs_gui;
21  protected $toolbar;
25  protected $ctrl;
29  protected $tpl;
33  protected $parent_object;
37  protected $lng;
41  protected $ilAccess;
42 
43 
47  function __construct($parent_gui) {
48  global $tpl, $ilCtrl, $ilToolbar, $lng, $ilAccess, $log;
49  $this->tpl = $tpl;
50  $this->ctrl = $ilCtrl;
51  $this->parent_gui = $parent_gui;
52  $this->parent_object = $parent_gui->object;
53  $this->tabs_gui = $this->parent_gui->tabs_gui;
54  $this->toolbar = $ilToolbar;
55  $this->lng = $lng;
56  $this->ilLog = $log;
57  $this->ilAccess = $ilAccess;
58  $this->lng->loadLanguageModule('user');
59  if (!$this->ilAccess->checkaccess('write', '', $this->parent_gui->object->getRefId())) {
60  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
61  }
62  }
63 
64 
68  public function executeCommand() {
69  $cmd = $this->ctrl->getCmd();
70 
71  $this->tabs_gui->clearTargets();
72  $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTargetByClass('ilOrgUnitSimpleImportGUI','chooseImport'));
73 
74  switch ($cmd) {
75  case 'userImportScreen':
76  $this->userImportScreen();
77  break;
78  case 'startImport':
79  $this->startImport();
80  break;
81  }
82 
83  return true;
84  }
85 
86 
87  public function userImportScreen() {
88  $form = $this->initForm();
89  $this->tpl->setContent($form->getHTML());
90  }
91 
92 
96  protected function testImport() {
97  return false;
98  $importer = new ilOrgUnitSimpleUserImport();
99  $string = '<Assignment action=\'add\'>
100  <User id_type=\'ilias_login\'>root</User>
101  <OrgUnit id_type=\'external_id\'>imported_001</OrgUnit>
102  <Role>superior</Role>
103  </Assignment>';
104 
105  $xml = new SimpleXMLElement($string);
106  $importer->simpleUserImportElement($xml);
107  ilUtil::sendInfo('<pre>' . print_r($importer->getErrors(), 1) . '</pre>');
108  }
109 
110 
111  protected function initForm() {
112  $form = new ilPropertyFormGUI();
113  $input = new ilFileInputGUI($this->lng->txt('import_xml_file'), 'import_file');
114  $input->setRequired(true);
115  $form->addItem($input);
116  $form->setFormAction($this->ctrl->getFormAction($this));
117  $form->addCommandButton('startImport', $this->lng->txt('import'));
118 
119  return $form;
120  }
121 
122 
123  public function startImport() {
124  $form = $this->initForm();
125  if (!$form->checkInput()) {
126  $this->tpl->setContent($form->getHTML());
127  } else {
128  $file = $form->getInput('import_file');
129  $importer = new ilOrgUnitSimpleUserImport();
130  try {
131  $importer->simpleUserImport($file['tmp_name']);
132  } catch (Exception $e) {
133  $this->ilLog->write($e->getMessage() . ' - ' . $e->getTraceAsString());
134  ilUtil::sendFailure($this->lng->txt('import_failed'), true);
135  $this->ctrl->redirect($this, 'render');
136  }
137  $this->displayImportResults($importer);
138  }
139  }
140 
141 
145  public function displayImportResults($importer) {
146  if (!$importer->hasErrors() AND !$importer->hasWarnings()) {
147  $stats = $importer->getStats();
148  ilUtil::sendSuccess(sprintf($this->lng->txt('user_import_successful'), $stats['created'], $stats['removed']), true);
149  }
150  if ($importer->hasWarnings()) {
151  $msg = $this->lng->txt('import_terminated_with_warnings') . '<br>';
152  foreach ($importer->getWarnings() as $warning) {
153  $msg .= '-' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
154  }
155  ilUtil::sendInfo($msg, true);
156  }
157  if ($importer->hasErrors()) {
158  $msg = $this->lng->txt('import_terminated_with_errors') . '<br>';
159  foreach ($importer->getErrors() as $warning) {
160  $msg .= '- ' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
161  }
162  ilUtil::sendFailure($msg, true);
163  }
164  }
165 }
166 
167 ?>
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.
write($a_msg, $a_log_level=NULL)
logging
testImport()
FSX Can be deleted; Just for a single Test of a UserImport
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilOrgUnitSimpleUserImportGUI.
setRequired($a_required)
Set Required.