Skip to content

Commit 07a922a

Browse files
committed
Clean & add informations
1 parent 401676b commit 07a922a

12 files changed

Lines changed: 354 additions & 365 deletions

ajax/showentitygroups.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@
3131
* -------------------------------------------------------------------------
3232
*/
3333

34-
//include('../../../inc/includes.php');
35-
//header("Content-Type: text/html; charset=UTF-8");
36-
//Html::header_nocache();
37-
38-
//Session::checkLoginUser();
39-
4034
if (strpos($_SERVER['PHP_SELF'], "showentitygroups.php")) {
4135
include('../../../inc/includes.php');
4236
header("Content-Type: text/html; charset=UTF-8");

ajax/showentitymandatorygroup.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* -------------------------------------------------------------------------
5+
* Metademands plugin for GLPI
6+
* -------------------------------------------------------------------------
7+
*
8+
* LICENSE
9+
*
10+
* This file is part of Metademands.
11+
*
12+
* Metademands is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation; either version 2 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* Metademands is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with Metademands. If not, see <http://www.gnu.org/licenses/>.
24+
* -------------------------------------------------------------------------
25+
* @copyright Copyright (C) 2013-2022 by Metademands plugin team.
26+
* @copyright 2015-2022 Teclib' and contributors.
27+
* @copyright 2003-2014 by the INDEPNET Development Team.
28+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
29+
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
30+
* @link https://github.com/pluginsGLPI/Metademands
31+
* -------------------------------------------------------------------------
32+
*/
33+
34+
if (strpos($_SERVER['PHP_SELF'], "showentitymandatorygroup.php")) {
35+
include('../../../inc/includes.php');
36+
header("Content-Type: text/html; charset=UTF-8");
37+
Html::header_nocache();
38+
} elseif (!defined('GLPI_ROOT')) {
39+
die("Sorry. You can't access this file directly");
40+
}
41+
42+
if (isset($_POST['entity_selection'])) {
43+
$entitites_id = $_POST['entity_selection'];
44+
45+
$params['entity_choice'] = $entitites_id;
46+
$getEntitiesRights = PluginTransferticketentityEntity::checkEntityRight($params);
47+
48+
if ($getEntitiesRights['allow_entity_only_transfer'] == 1) {
49+
echo "<span class='text-danger'>";
50+
echo " *";
51+
echo "</span>";
52+
}
53+
}
54+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* -------------------------------------------------------------------------
5+
* Metademands plugin for GLPI
6+
* -------------------------------------------------------------------------
7+
*
8+
* LICENSE
9+
*
10+
* This file is part of Metademands.
11+
*
12+
* Metademands is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation; either version 2 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* Metademands is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with Metademands. If not, see <http://www.gnu.org/licenses/>.
24+
* -------------------------------------------------------------------------
25+
* @copyright Copyright (C) 2013-2022 by Metademands plugin team.
26+
* @copyright 2015-2022 Teclib' and contributors.
27+
* @copyright 2003-2014 by the INDEPNET Development Team.
28+
* @licence https://www.gnu.org/licenses/gpl-3.0.html
29+
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
30+
* @link https://github.com/pluginsGLPI/Metademands
31+
* -------------------------------------------------------------------------
32+
*/
33+
34+
if (strpos($_SERVER['PHP_SELF'], "showentitymandatoryjustification.php")) {
35+
include('../../../inc/includes.php');
36+
header("Content-Type: text/html; charset=UTF-8");
37+
Html::header_nocache();
38+
} elseif (!defined('GLPI_ROOT')) {
39+
die("Sorry. You can't access this file directly");
40+
}
41+
42+
if (isset($_POST['entity_selection'])) {
43+
$entitites_id = $_POST['entity_selection'];
44+
45+
$params['entity_choice'] = $entitites_id;
46+
$getEntitiesRights = PluginTransferticketentityEntity::checkEntityRight($params);
47+
48+
if ($getEntitiesRights['justification_transfer'] == 1) {
49+
echo "<span class='text-danger'>";
50+
echo " *";
51+
echo "</span>";
52+
}
53+
}
54+

front/entity.form.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,26 @@
4444
if ($_POST['allow_transfer'] == 0) {
4545
$config->delete(['id' => $_POST['id']]);
4646
} else {
47-
$config->update($_POST);
48-
}
4947

48+
$params['entity_choice'] = $_POST['entities_id'];
49+
$checkMandatoryCategory = PluginTransferticketentityTicket::checkMandatoryCategory($params);
50+
51+
if ($checkMandatoryCategory
52+
&& $_POST['keep_category'] == 0
53+
&& $_POST['itilcategories_id'] == 0) {
54+
55+
Session::addMessageAfterRedirect(
56+
__(
57+
"The category is mandatory in the ticket template assigned to the entity",
58+
'transferticketentity'
59+
),
60+
true,
61+
ERROR
62+
);
63+
} else {
64+
$config->update($_POST);
65+
}
66+
}
5067
}
5168
Html::back();
5269
}

front/ticket.form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@
4242
true,
4343
ERROR
4444
);
45-
Html::back();
4645
}
4746
}
47+
Html::back();

inc/entity.class.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ public function showFormMcv($item)
153153

154154
$availableCategories = self::availableCategories();
155155

156+
$params['entity_choice'] = $item->getID();
157+
$checkMandatoryCategory = PluginTransferticketentityTicket::checkMandatoryCategory($params);
158+
156159
if (empty($checkRights->fields)) {
157160
$checkRights->fields['allow_entity_only_transfer'] = 0;
158161
$checkRights->fields['justification_transfer'] = 0;
@@ -235,6 +238,14 @@ public function showFormMcv($item)
235238
['value' => $checkRights->fields['itilcategories_id'],
236239
'class' => 'itilcategories_id']
237240
);
241+
242+
if($checkMandatoryCategory) {
243+
echo "<br><br><div class='alert alert-warning'>";
244+
echo "<p>" .
245+
__("The category is mandatory in the ticket template assigned to the entity", "transferticketentity")
246+
. "</p>";
247+
echo "</div>";
248+
}
238249
echo "</td>";
239250
echo "</tr>";
240251
echo "</tbody>";
@@ -250,6 +261,7 @@ public function showFormMcv($item)
250261
echo "</div>\n";
251262
Html::closeForm();
252263
}
264+
253265
}
254266

255267
public static function getEntitiesRights()
@@ -276,4 +288,27 @@ public static function getEntitiesRights()
276288

277289
return $array;
278290
}
291+
292+
293+
/**
294+
* Get selected entity rights
295+
*
296+
* @return array
297+
*/
298+
public static function checkEntityRight($params)
299+
{
300+
$array = [];
301+
$entity_config = new self();
302+
$entities = $entity_config->find(['entities_id' => $params['entity_choice']]);
303+
304+
foreach ($entities as $data) {
305+
$array['allow_entity_only_transfer'] = $data['allow_entity_only_transfer'];
306+
$array['justification_transfer'] = $data['justification_transfer'];
307+
$array['allow_transfer'] = $data['allow_transfer'];
308+
$array['keep_category'] = $data['keep_category'];
309+
$array['itilcategories_id'] = $data['itilcategories_id'];
310+
}
311+
312+
return $array;
313+
}
279314
}

0 commit comments

Comments
 (0)