ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 */
3require_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 switch ($cmd) {
72 case 'userImportScreen':
73 $this->userImportScreen();
74 break;
75 case 'startImport':
76 $this->startImport();
77 break;
78 }
79
80 return true;
81 }
82
83
84 public function userImportScreen() {
85 $form = $this->initForm();
86 $this->tpl->setContent($form->getHTML());
87 }
88
89
93 protected function testImport() {
94 return false;
95 $importer = new ilOrgUnitSimpleUserImport();
96 $string = '<Assignment action=\'add\'>
97 <User id_type=\'ilias_login\'>root</User>
98 <OrgUnit id_type=\'external_id\'>imported_001</OrgUnit>
99 <Role>superior</Role>
100 </Assignment>';
101
102 $xml = new SimpleXMLElement($string);
103 $importer->simpleUserImportElement($xml);
104 ilUtil::sendInfo('<pre>' . print_r($importer->getErrors(), 1) . '</pre>');
105 }
106
107
108 protected function initForm() {
109 $form = new ilPropertyFormGUI();
110 $input = new ilFileInputGUI($this->lng->txt('import_xml_file'), 'import_file');
111 $input->setRequired(true);
112 $form->addItem($input);
113 $form->setFormAction($this->ctrl->getFormAction($this));
114 $form->addCommandButton('startImport', $this->lng->txt('import'));
115
116 return $form;
117 }
118
119
120 public function startImport() {
121 $form = $this->initForm();
122 if (!$form->checkInput()) {
123 $this->tpl->setContent($form->getHTML());
124 } else {
125 $file = $form->getInput('import_file');
126 $importer = new ilOrgUnitSimpleUserImport();
127 try {
128 $importer->simpleUserImport($file['tmp_name']);
129 } catch (Exception $e) {
130 $this->ilLog->write($e->getMessage() . ' - ' . $e->getTraceAsString());
131 ilUtil::sendFailure($this->lng->txt('import_failed'), true);
132 $this->ctrl->redirect($this, 'render');
133 }
134 $this->displayImportResults($importer);
135 }
136 }
137
138
142 public function displayImportResults($importer) {
143 if (!$importer->hasErrors() AND !$importer->hasWarnings()) {
144 $stats = $importer->getStats();
145 ilUtil::sendSuccess(sprintf($this->lng->txt('user_import_successful'), $stats['created'], $stats['removed']), true);
146 }
147 if ($importer->hasWarnings()) {
148 $msg = $this->lng->txt('import_terminated_with_warnings') . '<br>';
149 foreach ($importer->getWarnings() as $warning) {
150 $msg .= '-' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
151 }
152 ilUtil::sendInfo($msg, true);
153 }
154 if ($importer->hasErrors()) {
155 $msg = $this->lng->txt('import_terminated_with_errors') . '<br>';
156 foreach ($importer->getErrors() as $warning) {
157 $msg .= '- ' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
158 }
159 ilUtil::sendFailure($msg, true);
160 }
161 }
162}
163
164?>
print $file
This class represents a file property in a property form.
logging
Definition: class.ilLog.php:19
write($a_msg, $a_log_level=NULL)
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
$cmd
Definition: sahs_server.php:35