ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $DIC;
49 $tpl = $DIC['tpl'];
50 $ilCtrl = $DIC['ilCtrl'];
51 $ilToolbar = $DIC['ilToolbar'];
52 $lng = $DIC['lng'];
53 $ilAccess = $DIC['ilAccess'];
54 $log = $DIC['log'];
55 $this->tpl = $tpl;
56 $this->ctrl = $ilCtrl;
57 $this->parent_gui = $parent_gui;
58 $this->parent_object = $parent_gui->object;
59 $this->tabs_gui = $this->parent_gui->tabs_gui;
60 $this->toolbar = $ilToolbar;
61 $this->lng = $lng;
62 $this->ilLog = $log;
63 $this->ilAccess = $ilAccess;
64 $this->lng->loadLanguageModule('user');
65 if (!$this->ilAccess->checkaccess('write', '', $this->parent_gui->object->getRefId())) {
66 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
67 }
68 }
69
70
74 public function executeCommand() {
75 $cmd = $this->ctrl->getCmd();
76
77 $this->tabs_gui->clearTargets();
78 $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTargetByClass('ilOrgUnitSimpleImportGUI','chooseImport'));
79
80 switch ($cmd) {
81 case 'userImportScreen':
82 $this->userImportScreen();
83 break;
84 case 'startImport':
85 $this->startImport();
86 break;
87 }
88
89 return true;
90 }
91
92
93 public function userImportScreen() {
94 $form = $this->initForm();
95 $this->tpl->setContent($form->getHTML());
96 }
97
98
102 protected function testImport() {
103 return false;
104 $importer = new ilOrgUnitSimpleUserImport();
105 $string = '<Assignment action=\'add\'>
106 <User id_type=\'ilias_login\'>root</User>
107 <OrgUnit id_type=\'external_id\'>imported_001</OrgUnit>
108 <Role>superior</Role>
109 </Assignment>';
110
111 $xml = new SimpleXMLElement($string);
112 $importer->simpleUserImportElement($xml);
113 ilUtil::sendInfo('<pre>' . print_r($importer->getErrors(), 1) . '</pre>');
114 }
115
116
117 protected function initForm() {
118 $form = new ilPropertyFormGUI();
119 $input = new ilFileInputGUI($this->lng->txt('import_xml_file'), 'import_file');
120 $input->setRequired(true);
121 $form->addItem($input);
122 $form->setFormAction($this->ctrl->getFormAction($this));
123 $form->addCommandButton('startImport', $this->lng->txt('import'));
124
125 return $form;
126 }
127
128
129 public function startImport() {
130 $form = $this->initForm();
131 if (!$form->checkInput()) {
132 $this->tpl->setContent($form->getHTML());
133 } else {
134 $file = $form->getInput('import_file');
135 $importer = new ilOrgUnitSimpleUserImport();
136 try {
137 $importer->simpleUserImport($file['tmp_name']);
138 } catch (Exception $e) {
139 $this->ilLog->write($e->getMessage() . ' - ' . $e->getTraceAsString());
140 ilUtil::sendFailure($this->lng->txt('import_failed'), true);
141 $this->ctrl->redirect($this, 'render');
142 }
143 $this->displayImportResults($importer);
144 }
145 }
146
147
151 public function displayImportResults($importer) {
152 if (!$importer->hasErrors() AND !$importer->hasWarnings()) {
153 $stats = $importer->getStats();
154 ilUtil::sendSuccess(sprintf($this->lng->txt('user_import_successful'), $stats['created'], $stats['removed']), true);
155 }
156 if ($importer->hasWarnings()) {
157 $msg = $this->lng->txt('import_terminated_with_warnings') . '<br>';
158 foreach ($importer->getWarnings() as $warning) {
159 $msg .= '-' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
160 }
161 ilUtil::sendInfo($msg, true);
162 }
163 if ($importer->hasErrors()) {
164 $msg = $this->lng->txt('import_terminated_with_errors') . '<br>';
165 foreach ($importer->getErrors() as $warning) {
166 $msg .= '- ' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
167 }
168 ilUtil::sendFailure($msg, true);
169 }
170 }
171}
172
173?>
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
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
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$cmd
Definition: sahs_server.php:35
global $DIC