ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 */
3require_once("class.ilOrgUnitSimpleImport.php");
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 function __construct($parent_gui) {
46 global $tpl, $ilCtrl, $ilTabs, $ilToolbar, $lng, $ilAccess, $ilLog;
47 $this->tpl = $tpl;
48 $this->ctrl = $ilCtrl;
49 $this->parent_gui = $parent_gui;
50 $this->parent_object = $parent_gui->object;
51 $this->tabs_gui = $this->parent_gui->tabs_gui;
52 $this->toolbar = $ilToolbar;
53 $this->lng = $lng;
54 $this->ilAccess = $ilAccess;
55 $this->lng->loadLanguageModule('user');
56 $this->ilLog = $ilLog;
57 if (! $this->ilAccess->checkaccess("write", "", $this->parent_gui->object->getRefId())) {
58 ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
59 }
60 }
61
65 public function executeCommand()
66 {
67 $cmd = $this->ctrl->getCmd();
68
69 switch ($cmd) {
70 case 'importScreen':
71 $this->importScreen();
72 break;
73 case 'startImport':
74 $this->startImport();
75 break;
76 }
77 return true;
78 }
79
80 public function importScreen() {
81 $form = $this->initForm("startImport");
82 $this->tpl->setContent($form->getHTML());
83 }
84
85
86 protected function initForm($submit_action) {
87 $form = new ilPropertyFormGUI();
88 $input = new ilFileInputGUI($this->lng->txt("import_xml_file"), "import_file");
89 $input->setRequired(true);
90 $input->setSuffixes(array('zip', 'xml'));
91 $form->addItem($input);
92 $form->setFormAction($this->ctrl->getFormAction($this));
93 $form->addCommandButton($submit_action, $this->lng->txt("import"));
94
95 return $form;
96 }
97
98
99 public function startImport() {
100 $form = $this->initForm("startImport");
101 if (! $form->checkInput()) {
102 $this->tpl->setContent($form->getHTML());
103 } else {
104 $file = $form->getInput("import_file");
105 $importer = new ilOrgUnitSimpleImport();
106 try {
107 $file_path = $file["tmp_name"];
108 $file_type = pathinfo($file["name"], PATHINFO_EXTENSION);
109 $file_name = pathinfo($file["name"], PATHINFO_FILENAME);
110
111 if($file_type == "zip") {
112 $extract_path = $file_path.'_extracted/';
113 $extracted_file = $extract_path.$file_name.'/manifest.xml';
114
115 $zip = new ZipArchive();
116 $res = $zip->open($file_path);
117 if ($res === true) {
118 $zip->extractTo($extract_path);
119 $zip->close();
120
121 if(file_exists($extracted_file)) {
122 $file_path = $extracted_file;
123 }
124 }
125 }
126
127 $importer->simpleImport($file_path);
128 } catch (Exception $e) {
129 $this->ilLog->write($e->getMessage() . " - " . $e->getTraceAsString());
130 ilUtil::sendFailure($this->lng->txt("import_failed"), true);
131 $this->ctrl->redirect($this, "render");
132 }
133 $this->displayImportResults($importer);
134 }
135 }
136
140 public function displayImportResults($importer) {
141 if (! $importer->hasErrors() && ! $importer->hasWarnings()) {
142 $stats = $importer->getStats();
143 ilUtil::sendSuccess(sprintf($this->lng->txt("import_successful"), $stats["created"], $stats["updated"], $stats["deleted"]), true);
144 }
145 if ($importer->hasWarnings()) {
146 $msg = $this->lng->txt("import_terminated_with_warnings") . " <br/>";
147 foreach ($importer->getWarnings() as $warning) {
148 $msg .= "-" . $this->lng->txt($warning["lang_var"]) . " (Import ID: " . $warning["import_id"] . ")<br />";
149 }
150 ilUtil::sendInfo($msg, true);
151 }
152 if ($importer->hasErrors()) {
153 $msg = $this->lng->txt("import_terminated_with_errors") . "<br/>";
154 foreach ($importer->getErrors() as $warning) {
155 $msg .= "- " . $this->lng->txt($warning["lang_var"]) . " (Import ID: " . $warning["import_id"] . ")<br />";
156 }
157 ilUtil::sendFailure($msg, true);
158 }
159 }
160
161
162}
163?>
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 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
$cmd
Definition: sahs_server.php:35