Skip to content

Commit 602b17f

Browse files
committed
nouvelle vue de configuration des customs categories (resolve #75)
correction de bug #76 meilleure gestion de la date du formulaire : resolve #70 lint du code
2 parents db7d49d + a8e5ca5 commit 602b17f

21 files changed

+3405
-3175
lines changed

.phpcs.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<file>.</file>
4+
<exclude-pattern>/.git/</exclude-pattern>
5+
<exclude-pattern type="relative">^config/</exclude-pattern>
6+
<exclude-pattern type="relative">^files/</exclude-pattern>
7+
<exclude-pattern type="relative">^lib/</exclude-pattern>
8+
<exclude-pattern type="relative">^marketplace/</exclude-pattern>
9+
<exclude-pattern type="relative">^node_modules/</exclude-pattern>
10+
<exclude-pattern type="relative">^plugins/</exclude-pattern>
11+
<exclude-pattern type="relative">^tests/config/</exclude-pattern>
12+
<exclude-pattern type="relative">^tests/files/</exclude-pattern>
13+
<exclude-pattern type="relative">^vendor/</exclude-pattern>
14+
15+
<arg name="warning-severity" value="0" />
16+
<arg value="p" />
17+
<ini name="memory_limit" value="512M" />
18+
<arg name="colors" />
19+
<arg name="extensions" value="php" />
20+
21+
<rule ref="PSR12">
22+
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
23+
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
24+
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
25+
</rule>
26+
27+
<rule ref="Generic.Arrays.ArrayIndent"></rule>
28+
</ruleset>

RoboFile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This is project's console commands configuration for Robo task runner.
45
*

apirest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
define('GLPI_ROOT', __DIR__.'/../../');
3+
define('GLPI_ROOT', __DIR__ . '/../../');
44
define('DO_NOT_CHECK_HTTP_REFERER', 1);
55
ini_set('session.use_cookies', 0);
66

7-
include (GLPI_ROOT . '/inc/autoload.function.php');
7+
include(GLPI_ROOT . '/inc/autoload.function.php');
88
include 'inc/api.php';
99

10-
$api = new PluginReservationApi;
10+
$api = new PluginReservationApi();
1111
$api->call();

composer.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
"minimum-stability": "dev",
33
"prefer-stable": true,
44
"require-dev": {
5-
"glpi-project/coding-standard": "^0.7.0"
5+
"glpi-project/coding-standard": "^0.7.0",
6+
"phpstan/extension-installer": "^1.2",
7+
"php-parallel-lint/php-parallel-lint": "^1.3",
8+
"phpstan/phpstan": "^1.10",
9+
"phpstan/phpstan-deprecation-rules": "^1.1"
610
},
711
"require": {
812
"glpi-project/tools": "^0.1.4"
13+
},
14+
"scripts": {
15+
"cs": "phpcs -d memory_limit=512M --cache -p --extensions=php --ignore=\"/.git/,^$(pwd)/(config|files|lib|marketplace|node_modules|plugins|tests/config|vendor)/\" ./",
16+
"lint": "parallel-lint --exclude vendor ."
17+
},
18+
"config": {
19+
"allow-plugins": {
20+
"phpstan/extension-installer": true
21+
}
922
}
1023
}

css/views.css

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,30 @@ color: black;
3232
cursor: default;
3333
}
3434
.categoryClose {
35-
/* position:absolute;
36-
margin:0;
37-
padding:5px; */
3835
color:red;
39-
/* top:0;
40-
right:0; */
36+
font: bold 11px Arial;
4137
cursor: pointer;
42-
width: 15px;
43-
text-align: center;
44-
vertical-align: middle;
38+
text-decoration: none;
39+
background-color: #EEEEEE;
40+
4541
}
4642

43+
.categoryConfig {
44+
font: bold 11px Arial;
45+
cursor: pointer;
46+
text-decoration: none;
47+
background-color: #EEEEEE;
48+
}
49+
50+
.listCustomCategories {
51+
border: 1px solid;
52+
}
53+
54+
table.listCustomCategories td {
55+
border: 1px solid;
56+
}
57+
58+
4759

4860
.dropper {
4961
position:relative;

front/config.form.php

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
// Définition de la variable GLPI_ROOT obligatoire pour l'instanciation des class
34
define('GLPI_ROOT', getAbsolutePath());
45
// // Récupération du fichier includes de GLPI, permet l'accès au cœur
@@ -8,61 +9,70 @@
89

910
$plugin = new Plugin();
1011
if ($plugin->isActivated("reservation")) {
11-
$PluginReservationConfig = new PluginReservationConfig();
12-
Session::checkRightsOr("config", [CREATE, UPDATE, DELETE]);
12+
$PluginReservationConfig = new PluginReservationConfig();
13+
Session::checkRightsOr("config", [CREATE, UPDATE, DELETE]);
1314

14-
if (isset($_POST["mode_auto"])) {
15-
$PluginReservationConfig->setMailAutomaticAction($_POST["mode_auto"]);
16-
$PluginReservationConfig->setConfigurationValue("mode_auto", $_POST["mode_auto"]);
17-
}
18-
if (isset($_POST["extension_time"])) {
19-
$PluginReservationConfig->setConfigurationValue("extension_time", $_POST["extension_time"]);
20-
}
21-
if (isset($_POST["conflict_action"])) {
22-
$PluginReservationConfig->setConfigurationValue("conflict_action", $_POST["conflict_action"]);
23-
}
24-
if (isset($_POST["checkin"])) {
25-
$PluginReservationConfig->setConfigurationValue("checkin", $_POST["checkin"]);
26-
$PluginReservationConfig->setConfigurationValue("checkin_timeout", $_POST["checkin_timeout"]);
27-
$PluginReservationConfig->setConfigurationValue("checkin_action", $_POST["checkin_action"]);
28-
$PluginReservationConfig->setConfigurationValue("auto_checkin", $_POST["auto_checkin"]);
29-
$PluginReservationConfig->setConfigurationValue("auto_checkin_time", $_POST["auto_checkin_time"]);
30-
}
31-
if (isset($_POST["custom_categories"])) {
32-
$PluginReservationConfig->setConfigurationValue("custom_categories", $_POST["custom_categories"]);
33-
}
34-
if (isset($_POST["use_items_types"])) {
35-
$PluginReservationConfig->setConfigurationValue("use_items_types", $_POST["use_items_types"]);
36-
}
37-
if (isset($_POST['configCategoriesForm'])) {
38-
$PluginReservationCategory = new PluginReservationCategory();
39-
$PluginReservationCategory->applyCategoriesConfig($_POST);
40-
}
15+
if (isset($_POST["mode_auto"])) {
16+
$PluginReservationConfig->setMailAutomaticAction($_POST["mode_auto"]);
17+
$PluginReservationConfig->setConfigurationValue("mode_auto", $_POST["mode_auto"]);
18+
}
19+
if (isset($_POST["extension_time"])) {
20+
$PluginReservationConfig->setConfigurationValue("extension_time", $_POST["extension_time"]);
21+
}
22+
if (isset($_POST["conflict_action"])) {
23+
$PluginReservationConfig->setConfigurationValue("conflict_action", $_POST["conflict_action"]);
24+
}
25+
if (isset($_POST["checkin"])) {
26+
$PluginReservationConfig->setConfigurationValue("checkin", $_POST["checkin"]);
27+
$PluginReservationConfig->setConfigurationValue("checkin_timeout", $_POST["checkin_timeout"]);
28+
$PluginReservationConfig->setConfigurationValue("checkin_action", $_POST["checkin_action"]);
29+
$PluginReservationConfig->setConfigurationValue("auto_checkin", $_POST["auto_checkin"]);
30+
$PluginReservationConfig->setConfigurationValue("auto_checkin_time", $_POST["auto_checkin_time"]);
31+
}
32+
if (isset($_POST["custom_categories"])) {
33+
$PluginReservationConfig->setConfigurationValue("custom_categories", $_POST["custom_categories"]);
34+
}
35+
if (isset($_POST["use_items_types"])) {
36+
$PluginReservationConfig->setConfigurationValue("use_items_types", $_POST["use_items_types"]);
37+
}
38+
if (isset($_POST['configCategoriesForm'])) {
39+
$PluginReservationCategory = new PluginReservationCategory();
40+
$PluginReservationCategory->applyCategoriesConfig($_POST);
41+
}
42+
if (isset($_POST['configCategoryItems'])) {
43+
$PluginReservationCategory = new PluginReservationCategory();
44+
$PluginReservationCategory->applyCategoryItem($_POST);
45+
}
4146

42-
foreach ($toolTipConfig as $config) {
43-
if (isset($_POST[$config])) {
44-
$PluginReservationConfig->setConfigurationValue($config, $_POST[$config]);
45-
}
46-
}
47+
foreach ($toolTipConfig as $config) {
48+
if (isset($_POST[$config])) {
49+
$PluginReservationConfig->setConfigurationValue($config, $_POST[$config]);
50+
}
51+
}
4752

48-
foreach ($tabConfig as $config) {
49-
if (isset($_POST[$config])) {
50-
$PluginReservationConfig->setConfigurationValue($config, $_POST[$config]);
51-
}
52-
}
53+
foreach ($tabConfig as $config) {
54+
if (isset($_POST[$config])) {
55+
$PluginReservationConfig->setConfigurationValue($config, $_POST[$config]);
56+
}
57+
}
5358

54-
Html::header(PluginReservationReservation::getTypeName(2), '', "plugins", "Reservation");
55-
$PluginReservationConfig->showForm(1);
56-
Html::footer();
59+
Html::header(PluginReservationReservation::getTypeName(2), '', "plugins", "Reservation");
60+
if (isset($_POST['configCategorySubmit'])) {
61+
$PluginReservationConfig->showForm(2, [$_POST['configCategorySubmit']]);
62+
} else {
63+
$PluginReservationConfig->showForm(1);
64+
}
5765

66+
Html::footer();
5867
} else {
59-
Html::header(__('Setup'), '', "config", "plugins");
60-
echo "<div class='center'><br><br>" .
61-
"<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt='warning'><br><br>";
62-
echo "<b>" . __('Please activate the plugin', 'reservation') . "</b></div>";
63-
Html::footer();
68+
Html::header(__('Setup'), '', "config", "plugins");
69+
echo "<div class='center'><br><br>" .
70+
"<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt='warning'><br><br>";
71+
echo "<b>" . __('Please activate the plugin', 'reservation') . "</b></div>";
72+
Html::footer();
6473
}
6574

66-
function getAbsolutePath() {
67-
return realpath("../../..") . "/";
75+
function getAbsolutePath()
76+
{
77+
return realpath("../../..") . "/";
6878
}

front/menu.form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
if (!defined('GLPI_ROOT')) {
44
die("Sorry. You can't access directly to this file");
5-
}
5+
}
66
// // Définition de la variable GLPI_ROOT obligatoire pour l'instanciation des class
77
// define('GLPI_ROOT', getAbsolutePath());
88
// // Récupération du fichier includes de GLPI, permet l'accès au cœur

front/menu.php

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
include '../../../inc/includes.php';
88

99
if (Session::getCurrentInterface() == "helpdesk") {
10-
Html::helpHeader(__('Simplified interface'), $_SERVER['PHP_SELF'], $_SESSION["glpiname"]);
10+
Html::helpHeader(__('Simplified interface'), $_SERVER['PHP_SELF'], $_SESSION["glpiname"]);
1111
} else {
12-
Html::header(PluginReservationMenu::getTypeName(2), $_SERVER['PHP_SELF'], "plugins", "pluginreservationmenu", "reservation");
12+
Html::header(PluginReservationMenu::getTypeName(2), $_SERVER['PHP_SELF'], "plugins", "pluginreservationmenu", "reservation");
1313
}
1414

1515
// Check if plugin is activated...
1616
$plugin = new Plugin();
1717
if (!$plugin->isInstalled('reservation') || !$plugin->isActivated('reservation')) {
18-
Html::displayNotFoundError();
18+
Html::displayNotFoundError();
1919
}
2020

2121
Session::checkRightsOr("reservation", [CREATE, UPDATE, DELETE]);
@@ -38,56 +38,59 @@
3838

3939
$form_dates["begin"] = date("Y-m-d H:i:s", $begin_time);
4040
if ($planning_end_date > date("Y-m-d H:i:s", time())) {
41-
$form_dates['end'] = $planning_end_date;
41+
$form_dates['end'] = $planning_end_date;
4242
} else {
43-
$form_dates['end'] = date("Y-m-d H:i:s", mktime(23, 59, 00, $month, $day, $year));
43+
$form_dates['end'] = date("Y-m-d H:i:s", mktime(23, 59, 00, $month, $day, $year));
4444
}
4545

4646
if (isset($_POST['date_begin'])) {
47-
$form_dates["begin"] = $_POST['date_begin'];
47+
$form_dates["begin"] = $_POST['date_begin'];
4848
}
4949
if (isset($_GET['date_begin'])) {
50-
$form_dates["begin"] = $_GET['date_begin'];
50+
$form_dates["begin"] = $_GET['date_begin'];
5151
}
5252
if (isset($_POST['date_end'])) {
53-
$form_dates["end"] = $_POST['date_end'];
53+
$form_dates["end"] = $_POST['date_end'];
5454
}
5555
if (isset($_GET['date_end'])) {
56-
$form_dates["end"] = $_GET['date_end'];
56+
$form_dates["end"] = $_GET['date_end'];
5757
}
5858
if (isset($_POST['nextday']) || isset($_GET['nextday'])) {
59-
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
60-
$day = date("d", strtotime($form_dates["begin"]) + DAY_TIMESTAMP);
61-
$month = date("m", strtotime($form_dates["begin"]) + DAY_TIMESTAMP);
62-
$year = date("Y", strtotime($form_dates["begin"]) + DAY_TIMESTAMP);
59+
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
60+
$day = date("d", strtotime($form_dates["begin"]) + DAY_TIMESTAMP);
61+
$month = date("m", strtotime($form_dates["begin"]) + DAY_TIMESTAMP);
62+
$year = date("Y", strtotime($form_dates["begin"]) + DAY_TIMESTAMP);
6363

64-
$form_dates["begin"] = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 00, $month, $day, $year));
65-
$form_dates["end"] = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 00, $month, $day, $year));
64+
$form_dates["begin"] = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 00, $month, $day, $year));
65+
$form_dates["end"] = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 00, $month, $day, $year));
6666
}
6767
if (isset($_POST['previousday']) || isset($_GET['previousday'])) {
68-
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
69-
$day = date("d", strtotime($form_dates["begin"]) - DAY_TIMESTAMP);
70-
$month = date("m", strtotime($form_dates["begin"]) - DAY_TIMESTAMP);
71-
$year = date("Y", strtotime($form_dates["begin"]) - DAY_TIMESTAMP);
68+
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
69+
$day = date("d", strtotime($form_dates["begin"]) - DAY_TIMESTAMP);
70+
$month = date("m", strtotime($form_dates["begin"]) - DAY_TIMESTAMP);
71+
$year = date("Y", strtotime($form_dates["begin"]) - DAY_TIMESTAMP);
7272

73-
$form_dates["begin"] = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 00, $month, $day, $year));
74-
$form_dates["end"] = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 00, $month, $day, $year));
73+
$form_dates["begin"] = date("Y-m-d H:i:s", mktime($planning_begin_time[0], $planning_begin_time[1], 00, $month, $day, $year));
74+
$form_dates["end"] = date("Y-m-d H:i:s", mktime($planning_end_time[0], $planning_end_time[1], 00, $month, $day, $year));
7575
}
7676
if (isset($_GET['reset'])) {
77-
unset($_SESSION['glpi_plugin_reservation_form_dates']);
77+
unset($_SESSION['glpi_plugin_reservation_form_dates']);
7878
}
7979
if (isset($_POST['add_item_to_reservation'])) {
80-
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
81-
$current_reservation = $_POST['add_item_to_reservation'];
82-
$item_to_add = $_POST['add_item'];
83-
PluginReservationReservation::addItemToResa($item_to_add, $current_reservation);
84-
80+
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
81+
$current_reservation = $_POST['add_item_to_reservation'];
82+
$item_to_add = $_POST['add_item'];
83+
PluginReservationReservation::addItemToResa($item_to_add, $current_reservation);
8584
}
8685
if (isset($_POST['switch_item_to_reservation'])) {
87-
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
88-
$current_reservation = $_POST['switch_item_to_reservation'];
89-
$item_to_switch = $_POST['switch_item'];
90-
PluginReservationReservation::switchItemToResa($item_to_switch, $current_reservation);
86+
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
87+
$current_reservation = $_POST['switch_item_to_reservation'];
88+
$item_to_switch = $_POST['switch_item'];
89+
PluginReservationReservation::switchItemToResa($item_to_switch, $current_reservation);
90+
}
91+
if (isset($_SESSION['glpi_plugin_reservation_change_in_progress'])) {
92+
$form_dates = $_SESSION['glpi_plugin_reservation_form_dates'];
93+
unset($_SESSION['glpi_plugin_reservation_change_in_progress']);
9194
}
9295

9396
$_SESSION['glpi_plugin_reservation_form_dates'] = $form_dates;
@@ -97,7 +100,7 @@
97100
$menu->display($_POST);
98101

99102
if ($_SESSION["glpiactiveprofile"]["interface"] == "central") {
100-
Html::footer();
103+
Html::footer();
101104
} else {
102-
Html::helpFooter();
105+
Html::helpFooter();
103106
}

0 commit comments

Comments
 (0)