ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
12{
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 public function __construct($parent_gui)
48 {
49 global $DIC;
50 $tpl = $DIC['tpl'];
51 $ilCtrl = $DIC['ilCtrl'];
52 $ilToolbar = $DIC['ilToolbar'];
53 $lng = $DIC['lng'];
54 $ilAccess = $DIC['ilAccess'];
55 $log = $DIC['log'];
56 $this->tpl = $tpl;
57 $this->ctrl = $ilCtrl;
58 $this->parent_gui = $parent_gui;
59 $this->parent_object = $parent_gui->object;
60 $this->tabs_gui = $this->parent_gui->tabs_gui;
61 $this->toolbar = $ilToolbar;
62 $this->lng = $lng;
63 $this->ilLog = $log;
64 $this->ilAccess = $ilAccess;
65 $this->lng->loadLanguageModule('user');
66 if (!$this->ilAccess->checkaccess('write', '', $this->parent_gui->object->getRefId())) {
67 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
68 }
69 }
70
71
75 public function executeCommand()
76 {
77 $cmd = $this->ctrl->getCmd();
78
79 $this->tabs_gui->clearTargets();
80 $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTargetByClass('ilOrgUnitSimpleImportGUI', 'chooseImport'));
81
82 switch ($cmd) {
83 case 'userImportScreen':
84 $this->userImportScreen();
85 break;
86 case 'startImport':
87 $this->startImport();
88 break;
89 }
90
91 return true;
92 }
93
94
95 public function userImportScreen()
96 {
97 $form = $this->initForm();
98 $this->tpl->setContent($form->getHTML());
99 }
100
101
105 protected function testImport()
106 {
107 return false;
108 $importer = new ilOrgUnitSimpleUserImport();
109 $string = '<Assignment action=\'add\'>
110 <User id_type=\'ilias_login\'>root</User>
111 <OrgUnit id_type=\'external_id\'>imported_001</OrgUnit>
112 <Role>superior</Role>
113 </Assignment>';
114
115 $xml = new SimpleXMLElement($string);
116 $importer->simpleUserImportElement($xml);
117 ilUtil::sendInfo('<pre>' . print_r($importer->getErrors(), 1) . '</pre>');
118 }
119
120
121 protected function initForm()
122 {
123 $form = new ilPropertyFormGUI();
124 $input = new ilFileInputGUI($this->lng->txt('import_xml_file'), 'import_file');
125 $input->setRequired(true);
126 $form->addItem($input);
127 $form->setFormAction($this->ctrl->getFormAction($this));
128 $form->addCommandButton('startImport', $this->lng->txt('import'));
129
130 return $form;
131 }
132
133
134 public function startImport()
135 {
136 $form = $this->initForm();
137 if (!$form->checkInput()) {
138 $this->tpl->setContent($form->getHTML());
139 } else {
140 $file = $form->getInput('import_file');
141 $importer = new ilOrgUnitSimpleUserImport();
142 try {
143 $importer->simpleUserImport($file['tmp_name']);
144 } catch (Exception $e) {
145 $this->ilLog->write($e->getMessage() . ' - ' . $e->getTraceAsString());
146 ilUtil::sendFailure($this->lng->txt('import_failed'), true);
147 $this->ctrl->redirect($this, 'render');
148 }
149 $this->displayImportResults($importer);
150 }
151 }
152
153
157 public function displayImportResults($importer)
158 {
159 if (!$importer->hasErrors() and !$importer->hasWarnings()) {
160 $stats = $importer->getStats();
161 ilUtil::sendSuccess(sprintf($this->lng->txt('user_import_successful'), $stats['created'], $stats['removed']), true);
162 }
163 if ($importer->hasWarnings()) {
164 $msg = $this->lng->txt('import_terminated_with_warnings') . '<br>';
165 foreach ($importer->getWarnings() as $warning) {
166 $msg .= '-' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
167 }
168 ilUtil::sendInfo($msg, true);
169 }
170 if ($importer->hasErrors()) {
171 $msg = $this->lng->txt('import_terminated_with_errors') . '<br>';
172 foreach ($importer->getErrors() as $warning) {
173 $msg .= '- ' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
174 }
175 ilUtil::sendFailure($msg, true);
176 }
177 }
178}
sprintf('%.4f', $callTime)
$warning
Definition: X509warning.php:13
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
This class represents a file property in a property form.
logging
Definition: class.ilLog.php:19
write($a_msg, $a_log_level=null)
logging
Class ilOrgUnitSimpleUserImportGUI.
testImport()
@description FSX Can be deleted; Just for a single Test of a UserImport
Class ilOrgUnitSimpleUserImport.
This class represents a property form user interface.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
$xml
Definition: metadata.php:240
$stats
if(isset($_POST['submit'])) $form
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC
Definition: saml.php:7