ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilOrgUnitSimpleImportGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
10{
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 public function __construct($parent_gui)
46 {
47 global $DIC;
48 $tpl = $DIC['tpl'];
49 $ilCtrl = $DIC['ilCtrl'];
50 $ilTabs = $DIC['ilTabs'];
51 $ilToolbar = $DIC['ilToolbar'];
52 $lng = $DIC['lng'];
53 $ilAccess = $DIC['ilAccess'];
54 $ilLog = $DIC['ilLog'];
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->ilAccess = $ilAccess;
63 $this->lng->loadLanguageModule('user');
64 $this->ilLog = $ilLog;
65 if (!$this->ilAccess->checkaccess("write", "", $this->parent_gui->object->getRefId())) {
66 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
67 }
68 }
69
73 public function executeCommand()
74 {
75 $cmd = $this->ctrl->getCmd();
76
77 switch ($cmd) {
78 case 'chooseImport':
79 $this->chooseImport();
80 break;
81 case 'importScreen':
82 $this->tabs_gui->clearTargets();
83 $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, 'chooseImport'));
84 $this->importScreen();
85 break;
86 case 'startImport':
87 $this->tabs_gui->clearTargets();
88 $this->tabs_gui->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTarget($this, 'chooseImport'));
89 $this->startImport();
90 break;
91 }
92 return true;
93 }
94
95 public function chooseImport()
96 {
97 if (!$this->ilAccess->checkAccess("write", "", $_GET["ref_id"]) or !$this->parent_object->getRefId() == ilObjOrgUnit::getRootOrgRefId()) {
98 ilUtil::sendFailure($this->lng->txt("msg_no_perm_edit"));
99 $this->ctrl->redirectByClass('ilinfoscreengui', '');
100 }
101
102 $this->tabs_gui->setTabActive('view_content');
103 $this->tabs_gui->removeSubTab("page_editor");
104 $this->tabs_gui->removeSubTab("ordering"); // Mantis 0014728
105
106 if ($this->ilAccess->checkAccess("write", "", $_GET["ref_id"]) and $this->parent_object->getRefId() == ilObjOrgUnit::getRootOrgRefId()) {
107 $this->toolbar->addButton($this->lng->txt("simple_import"), $this->ctrl->getLinkTargetByClass("ilOrgUnitSimpleImportGUI", "importScreen"));
108 $this->toolbar->addButton($this->lng->txt("simple_user_import"), $this->ctrl->getLinkTargetByClass("ilOrgUnitSimpleUserImportGUI", "userImportScreen"));
109 }
110 }
111
112 public function importScreen()
113 {
114 $form = $this->initForm("startImport");
115 $this->tpl->setContent($form->getHTML());
116 }
117
118
119 protected function initForm($submit_action)
120 {
121 $form = new ilPropertyFormGUI();
122 $input = new ilFileInputGUI($this->lng->txt("import_xml_file"), "import_file");
123 $input->setRequired(true);
124 $input->setSuffixes(array('zip', 'xml'));
125 $form->addItem($input);
126 $form->setFormAction($this->ctrl->getFormAction($this));
127 $form->addCommandButton($submit_action, $this->lng->txt("import"));
128
129 return $form;
130 }
131
132
133 public function startImport()
134 {
135 $form = $this->initForm("startImport");
136 if (!$form->checkInput()) {
137 $this->tpl->setContent($form->getHTML());
138 } else {
139 $file = $form->getInput("import_file");
140 $importer = new ilOrgUnitSimpleImport();
141 try {
142 $file_path = $file["tmp_name"];
143 $file_type = pathinfo($file["name"], PATHINFO_EXTENSION);
144 $file_name = pathinfo($file["name"], PATHINFO_FILENAME);
145
146 if ($file_type == "zip") {
147 $extract_path = $file_path . '_extracted/';
148 $extracted_file = $extract_path . $file_name . '/manifest.xml';
149
150 $zip = new ZipArchive();
151 $res = $zip->open($file_path);
152 if ($res === true) {
153 $zip->extractTo($extract_path);
154 $zip->close();
155
156 if (file_exists($extracted_file)) {
157 $file_path = $extracted_file;
158 }
159 }
160 }
161
162 $importer->simpleImport($file_path);
163 } catch (Exception $e) {
164 $this->ilLog->write($e->getMessage() . " - " . $e->getTraceAsString());
165 ilUtil::sendFailure($this->lng->txt("import_failed"), true);
166 $this->ctrl->redirect($this, "render");
167 }
168 $this->displayImportResults($importer);
169 }
170 }
171
175 public function displayImportResults($importer)
176 {
177 if (!$importer->hasErrors() && !$importer->hasWarnings()) {
178 $stats = $importer->getStats();
179 ilUtil::sendSuccess(sprintf($this->lng->txt("import_successful"), $stats["created"], $stats["updated"], $stats["deleted"]), true);
180 }
181 if ($importer->hasWarnings()) {
182 $msg = $this->lng->txt("import_terminated_with_warnings") . " <br/>";
183 foreach ($importer->getWarnings() as $warning) {
184 $msg .= "-" . $this->lng->txt($warning["lang_var"]) . " (Import ID: " . $warning["import_id"] . ")<br />";
185 }
186 ilUtil::sendInfo($msg, true);
187 }
188 if ($importer->hasErrors()) {
189 $msg = $this->lng->txt("import_terminated_with_errors") . "<br/>";
190 foreach ($importer->getErrors() as $warning) {
191 $msg .= "- " . $this->lng->txt($warning["lang_var"]) . " (Import ID: " . $warning["import_id"] . ")<br />";
192 }
193 ilUtil::sendFailure($msg, true);
194 }
195 }
196}
sprintf('%.4f', $callTime)
$warning
Definition: X509warning.php:13
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
checkAccess($a_permission, $a_cmd, $a_ref_id, $a_type="", $a_obj_id="", $a_tree_id="")
check access for an object (provide $a_type and $a_obj_id if available for better performance)
This class represents a file property in a property form.
logging
Definition: class.ilLog.php:19
write($a_msg, $a_log_level=null)
logging
static getRootOrgRefId()
Class ilOrgUnitSimpleImportGUI.
Class ilOrgUnitSimpleImport.
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
$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
foreach($_POST as $key=> $value) $res