-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathclientinjection.form.php
More file actions
106 lines (98 loc) · 4.13 KB
/
clientinjection.form.php
File metadata and controls
106 lines (98 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* -------------------------------------------------------------------------
* DataInjection plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of DataInjection.
*
* DataInjection is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* DataInjection is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DataInjection. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2007-2023 by DataInjection plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/datainjection
* -------------------------------------------------------------------------
*/
Session::checkRight("plugin_datainjection_use", READ);
Html::header(
__('Data injection', 'datainjection'),
$_SERVER["PHP_SELF"],
"tools",
"plugindatainjectionmenu",
"client",
);
if (isset($_SESSION['datainjection']['go'])) {
$model = unserialize($_SESSION['datainjection']['currentmodel']);
PluginDatainjectionClientInjection::showInjectionForm($model, $_SESSION['glpiactive_entity']);
} elseif (isset($_POST['upload'])) {
$model = new PluginDatainjectionModel();
$model->can($_POST['id'], READ);
$_SESSION['datainjection']['infos'] = ($_POST['info'] ?? []);
//If additional informations provided : check if mandatory infos are present
if (!$model->checkMandatoryFields($_SESSION['datainjection']['infos'])) {
Session::addMessageAfterRedirect(
__s('One mandatory field is not filled', 'datainjection'),
true,
ERROR,
true,
);
} elseif (
isset($_FILES['filename']['name'])
&& $_FILES['filename']['name']
&& $_FILES['filename']['tmp_name']
&& !$_FILES['filename']['error']
&& $_FILES['filename']['size']
) {
//Read file using automatic encoding detection, and do not delete file once readed
$options = [
'file_encoding' => $_POST['file_encoding'],
'mode' => PluginDatainjectionModel::PROCESS,
'delete_file' => false,
];
$response = $model->processUploadedFile($options);
$model->cleanData();
if ($response) {
//File uploaded successfully and matches the given model : switch to the import tab
$_SESSION['datainjection']['file_name'] = $_FILES['filename']['name'];
$_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_PROCESS;
//Store model in session for injection
$_SESSION['datainjection']['currentmodel'] = serialize($model);
$_SESSION['datainjection']['go'] = true;
} else {
//Got back to the file upload page
$_SESSION['datainjection']['step'] = PluginDatainjectionClientInjection::STEP_UPLOAD;
}
} else {
Session::addMessageAfterRedirect(
__s('The file could not be found (Maybe it exceeds the maximum size allowed)', 'datainjection'),
true,
ERROR,
true,
);
}
Html::back();
} elseif (isset($_POST['finish']) || isset($_POST['cancel'])) {
PluginDatainjectionSession::removeParams();
Html::redirect(Toolbox::getItemTypeFormURL('PluginDatainjectionClientInjection'));
} else {
if (isset($_GET['id'])) { // Allow link to a model
PluginDatainjectionSession::setParam('models_id', $_GET['id']);
}
$clientInjection = new PluginDatainjectionClientInjection();
$clientInjection->title();
$clientInjection->showForm(0);
}
Html::footer();