diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index c09b1ba..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,10 +0,0 @@ -on: [push, pull_request] -name: Main -jobs: - php-cs-fixer: - name: PHP-CS-Fixer - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: PHP-CS-Fixer - uses: docker://oskarstark/php-cs-fixer-ga diff --git a/.github/workflows/php-lint.yml b/.github/workflows/php-lint.yml deleted file mode 100644 index 3abbc65..0000000 --- a/.github/workflows/php-lint.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: PHP Linting -on: pull_request -jobs: - phplint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: michaelw90/PHP-Lint@master diff --git a/README.md b/README.md index ca791cd..f7670ec 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,6 @@ This plugin allows you to manage the rooms and the elements that are included in. A room is not the same as a location that already exists in GLPI because it can not contain items nor be loaned (which a room can be). -GLPI 9.5.1 compatibility added and tested. Translation fixed (gettext domain). -I also added a basic hungarian translation :) - Installation ------------ diff --git a/front/room.form.php b/front/room.form.php index fa31944..043318f 100644 --- a/front/room.form.php +++ b/front/room.form.php @@ -26,68 +26,56 @@ $newID = $room->add($_POST); Html::back(); -} else { - if (isset($_POST['delete'])) { // Supression d'une salle - $room->check($_POST['id'], DELETE); - - $room->delete($_POST); - Html::redirect($CFG_GLPI['root_doc'] . '/plugins/room/index.php'); - } else { - if (isset($_POST['purge'])) { // Purge de la salle - $room->check($_POST['id'], PURGE); - - $room->delete($_POST, 1); - Html::redirect($CFG_GLPI['root_doc'] . '/plugins/room/index.php'); - } else { - if (isset($_POST['restore'])) { // Restauration de la salle - $room->check($_POST['id'], PURGE); - - $room->restore($_POST); - Html::redirect($CFG_GLPI['root_doc'] . '/plugins/room/index.php'); - } else { - if (isset($_POST['update'])) { // Modification d'une salle - $room->check($_POST['id'], UPDATE); - - $room->update($_POST); - Html::back(); - } else { - if (isset($_POST['additem'])) { // Ajout de la liaison à un ordinateur - $room->check($_POST['room_id'], UPDATE); // Ça devrait pas être rooms_id? - - if ($_POST['room_id'] > 0 && $_POST['computers_id'] > 0) { - $room->plugin_room_AddDevice($_POST['room_id'], $_POST['computers_id']); - } - Html::back(); - } else { - if (isset($_POST['deleteitem'])) { // Suppression de la liaison à un ordinateur - $room->check($_POST['room_id'], UPDATE); - - if (count($_POST['item'])) { - foreach ($_POST['item'] as $key => $val) { - $room->plugin_room_DeleteDevice($key); - } - } - Html::back(); - } else { // Logiquement on passe ici pour visualiser une salle - $room->check($_GET['id'], READ); - - // test l'onglet de départ a afficher à l'ouverture de la fiche - if (!isset($_SESSION['glpi_tab'])) { - $_SESSION['glpi_tab'] = 1; - } - if (isset($_GET['tab'])) { - $_SESSION['glpi_tab'] = $_GET['tab']; - } - - Html::header(__('Room Management', 'room'), '', 'assets', 'pluginroommenu'); - - $room->display($_GET); - - Html::footer(); - } - } - } - } +} else if (isset($_POST['delete'])) { // Supression d'une salle + $room->check($_POST['id'], DELETE); + + $room->delete($_POST); + Html::redirect($CFG_GLPI['root_doc'] . '/plugins/room/index.php'); +} else if (isset($_POST['purge'])) { // Purge de la salle + $room->check($_POST['id'], PURGE); + + $room->delete($_POST, 1); + Html::redirect($CFG_GLPI['root_doc'] . '/plugins/room/index.php'); +} else if (isset($_POST['restore'])) { // Restauration de la salle + $room->check($_POST['id'], PURGE); + + $room->restore($_POST); + Html::redirect($CFG_GLPI['root_doc'] . '/plugins/room/index.php'); +} else if (isset($_POST['update'])) { // Modification d'une salle + $room->check($_POST['id'], UPDATE); + + $room->update($_POST); + Html::back(); +} else if (isset($_POST['additem'])) { // Ajout de la liaison à un ordinateur + $room->check($_POST['room_id'], UPDATE); // Ça devrait pas être rooms_id? + + if ($_POST['room_id'] > 0 && $_POST['computers_id'] > 0) { + $room->plugin_room_AddDevice($_POST['room_id'], $_POST['computers_id']); + } + Html::back(); +} else if (isset($_POST['deleteitem'])) { // Suppression de la liaison à un ordinateur + $room->check($_POST['room_id'], UPDATE); + + if (count($_POST['item'])) { + foreach ($_POST['item'] as $key => $val) { + $room->plugin_room_DeleteDevice($key); } } + Html::back(); +} else { // Logiquement on passe ici pour visualiser une salle + $room->check($_GET['id'], READ); + + // test l'onglet de départ a afficher à l'ouverture de la fiche + if (!isset($_SESSION['glpi_tab'])) { + $_SESSION['glpi_tab'] = 1; + } + if (isset($_GET['tab'])) { + $_SESSION['glpi_tab'] = $_GET['tab']; + } + + Html::header(__('Room Management', 'room'), '', 'assets', 'pluginroommenu'); + + $room->display($_GET); + + Html::footer(); } diff --git a/hook.php b/hook.php index d0ab39c..180b412 100644 --- a/hook.php +++ b/hook.php @@ -10,36 +10,36 @@ function plugin_room_install() if (!$DB->tableExists('glpi_plugin_room_rooms')) { $query = <<<'EOS' CREATE TABLE `glpi_plugin_room_rooms` ( - `id` int(11) NOT NULL auto_increment, - `name` varchar(255) collate utf8_unicode_ci default NULL, - `entities_id` int(11) NOT NULL default 0, - `locations_id` int(11) NOT NULL default 0, + `id` int unsigned NOT NULL auto_increment, + `name` varchar(255) collate utf8mb4_unicode_ci default NULL, + `entities_id` int unsigned NOT NULL default 0, + `locations_id` int unsigned NOT NULL default 0, `is_recursive` smallint(6) NOT NULL default 0, `is_deleted` smallint(6) NOT NULL default 0, - `type` int(11) NOT NULL default 0, - `date_mod` datetime default NULL, + `type` int unsigned NOT NULL default 0, + `date_mod` timestamp NULL default NULL, `size` smallint(6) NOT NULL default 0, `count_linked` smallint(6) NOT NULL default 0, - `buy` datetime default NULL, - `access` int(11) NOT NULL default 0, + `buy` timestamp NULL default NULL, + `access` int unsigned NOT NULL default 0, `printer` smallint(6) NOT NULL default 0, `videoprojector` smallint(6) NOT NULL default 0, `wifi` smallint(6) NOT NULL default 0, - `comment` text collate utf8_unicode_ci, - `opening` varchar(255) collate utf8_unicode_ci default NULL, - `limits` varchar(255) collate utf8_unicode_ci default NULL, - `text1` varchar(255) collate utf8_unicode_ci default NULL, - `text2` varchar(255) collate utf8_unicode_ci default NULL, - `dropdown1` int(11) NOT NULL default 0, - `dropdown2` int(11) NOT NULL default 0, - `tech_num` int(11) NOT NULL default 0, - `users_id` int(11) NOT NULL default 0, + `comment` text collate utf8mb4_unicode_ci, + `opening` varchar(255) collate utf8mb4_unicode_ci default NULL, + `limits` varchar(255) collate utf8mb4_unicode_ci default NULL, + `text1` varchar(255) collate utf8mb4_unicode_ci default NULL, + `text2` varchar(255) collate utf8mb4_unicode_ci default NULL, + `dropdown1` int unsigned NOT NULL default 0, + `dropdown2` int unsigned NOT NULL default 0, + `tech_num` int unsigned NOT NULL default 0, + `users_id` int unsigned NOT NULL default 0, `is_template` smallint(6) NOT NULL default 0, # not used / for reservation search engine `location` smallint(6) NOT NULL default 0, # not used / for reservation search engine `state` smallint(6) NOT NULL default 0, # not used / for reservation search engine - `manufacturers_id` smallint(6) NOT NULL default 0, # not used / for reservation search engine - `groups_id` smallint(6) NOT NULL default 0, # not used / for reservation search engine - `groups_id_tech` int(11) NOT NULL default 0 COMMENT "Group in charge of the hardware. RELATION to glpi_groups (id)", + `manufacturers_id` int unsigned NOT NULL default 0, # not used / for reservation search engine + `groups_id` int unsigned NOT NULL default 0, # not used / for reservation search engine + `groups_id_tech` int unsigned NOT NULL default 0 COMMENT "Group in charge of the hardware. RELATION to glpi_groups (id)", PRIMARY KEY (`id`), KEY `entities_id` (`entities_id`), KEY `is_deleted` (`is_deleted`), @@ -50,7 +50,7 @@ function plugin_room_install() KEY `dropdown2` (`dropdown2`), KEY `tech_num` (`tech_num`), KEY `users_id` (`users_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC EOS; $DB->query($query) || die('error adding glpi_plugin_room table ' . __('Error during the database update', 'room') . $DB->error()); } @@ -59,13 +59,13 @@ function plugin_room_install() if (!$DB->TableExists('glpi_plugin_room_rooms_computers')) { $query = <<<'EOS' CREATE TABLE `glpi_plugin_room_rooms_computers` ( - `id` int(11) NOT NULL auto_increment, - `computers_id` int(11) NOT NULL, - `rooms_id` int(11) NOT NULL, + `id` int unsigned NOT NULL auto_increment, + `computers_id` int unsigned NOT NULL, + `rooms_id` int unsigned NOT NULL, PRIMARY KEY (`id`), UNIQUE `computers_id` (`computers_id`), KEY `rooms_id` (`rooms_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; EOS; $DB->query($query) || die('error adding glpi_plugin_room_rooms_computers table ' . __('Error during the database update', 'room') . $DB->error()); } @@ -74,12 +74,12 @@ function plugin_room_install() if (!$DB->TableExists('glpi_plugin_room_roomtypes')) { $query = <<<'EOS' CREATE TABLE `glpi_plugin_room_roomtypes` ( - `id` int(11) NOT NULL auto_increment, - `name` varchar(255) collate utf8_unicode_ci default NULL, - `comment` text collate utf8_unicode_ci, + `id` int unsigned NOT NULL auto_increment, + `name` varchar(255) collate utf8mb4_unicode_ci default NULL, + `comment` text collate utf8mb4_unicode_ci, PRIMARY KEY (`id`), KEY `name` (`name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; EOS; $DB->query($query) || die('error adding glpi_plugin_room_roomtypes table ' . __('Error during the database update', 'room') . $DB->error()); } @@ -88,12 +88,12 @@ function plugin_room_install() if (!$DB->TableExists('glpi_plugin_room_roomaccessconds')) { $query = <<<'EOS' CREATE TABLE `glpi_plugin_room_roomaccessconds` ( - `id` int(11) NOT NULL auto_increment, - `name` varchar(255) collate utf8_unicode_ci default NULL, - `comment` text collate utf8_unicode_ci, + `id` int unsigned NOT NULL auto_increment, + `name` varchar(255) collate utf8mb4_unicode_ci default NULL, + `comment` text collate utf8mb4_unicode_ci, PRIMARY KEY (`id`), KEY `name` (`name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; EOS; $DB->query($query) || die('error adding glpi_plugin_room_roomaccessconds table ' . __('Error during the database update', 'room') . $DB->error()); } @@ -102,12 +102,12 @@ function plugin_room_install() if (!$DB->TableExists('glpi_plugin_room_dropdown1s')) { $query = <<<'EOS' CREATE TABLE `glpi_plugin_room_dropdown1s` ( - `id` int(11) NOT NULL auto_increment, - `name` varchar(255) collate utf8_unicode_ci default NULL, - `comment` text collate utf8_unicode_ci, + `id` int unsigned NOT NULL auto_increment, + `name` varchar(255) collate utf8mb4_unicode_ci default NULL, + `comment` text collate utf8mb4_unicode_ci, PRIMARY KEY (`id`), KEY `name` (`name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; EOS; $DB->query($query) || die('error adding glpi_plugin_room_roomspecificities table ' . __('Error during the database update', 'room') . $DB->error()); } @@ -121,6 +121,7 @@ function plugin_room_uninstall() { global $DB; + // Drop plugin tables $tables = [ 'glpi_plugin_room_rooms_computers', 'glpi_plugin_room_roomtypes', @@ -133,6 +134,11 @@ function plugin_room_uninstall() $DB->query("DROP TABLE IF EXISTS `$table`;"); } + // Delete reservations + $DB->query('DELETE FROM `glpi_reservations` WHERE `reservationitems_id` in + (SELECT id FROM `glpi_reservationitems` WHERE `itemtype` = "PluginRoomRoom");'); + + // Delete logs, items and other things from glpi tables $tables_glpi = [ 'glpi_displaypreferences', 'glpi_documents_items', @@ -143,7 +149,7 @@ function plugin_room_uninstall() ]; foreach ($tables_glpi as $table_glpi) { - $DB->query('DELETE FROM `$table_glpi` WHERE `itemtype` = "PluginRoomRoom";'); + $DB->query("DELETE FROM `$table_glpi` WHERE `itemtype` = 'PluginRoomRoom';"); } return true; @@ -293,10 +299,10 @@ function plugin_room_getAddSearchOptions($itemtype) function plugin_room_addSelect($type, $ID, $num) { - global $SEARCH_OPTION; + $searchopt = &Search::getOptions($type); - $table = $SEARCH_OPTION[$type][$ID]['table']; - $field = $SEARCH_OPTION[$type][$ID]['field']; + $table = $searchopt[$ID]['table']; + $field = $searchopt[$ID]['field']; // Example of standard Select clause but use it ONLY for specific Select // No need of the function if you do not have specific cases @@ -358,7 +364,8 @@ function plugin_room_MassiveActionsProcess($data) function plugin_room_AssignToTicket($types) { - if (in_array('PluginRoomRoom', $_SESSION['glpiactiveprofile']['helpdesk_item_type'])) { + if (isset($_SESSION['glpiactiveprofile']['helpdesk_item_type']) + && in_array('PluginRoomRoom', $_SESSION['glpiactiveprofile']['helpdesk_item_type'])) { $types['PluginRoomRoom'] = __('Room Management', 'room'); } return $types; diff --git a/inc/profile.class.php b/inc/profile.class.php index 61c817c..e7a7326 100755 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -129,9 +129,10 @@ public function showForm($profiles_id = 0, $openform = true, $closeform = true) _sx('button', 'Save'), [ 'name' => 'update', + 'class' => 'btn btn-primary', ] ); - echo '\n'; + echo "\n"; Html::closeForm(); } echo ''; diff --git a/inc/room.class.php b/inc/room.class.php index 52a24b2..ca7cafb 100644 --- a/inc/room.class.php +++ b/inc/room.class.php @@ -2,12 +2,20 @@ class PluginRoomRoom extends CommonDBTM { + use Glpi\Features\Clonable; + public $dohistory = true; public static $rightname = 'plugin_room'; protected $usenotepad = true; + public function getCloneRelations() :array { + return [ + Document_Item::class, + ]; + } + public static function getTypeName($nb = 0) { return _n('Room', 'Rooms', $nb, 'room'); @@ -247,14 +255,14 @@ public function defineTabs($options = []) $ong = []; $this->addDefaultFormTab($ong); - if (Session::haveRight('reservation', READ)) { - // Affiche "Réservations" - $this->addStandardTab('Reservation', $ong, $options); - } $this->addStandardTab('Ticket', $ong, $options); $this->addStandardTab('Item_Problem', $ong, $options); $this->addStandardTab('Document_Item', $ong, $options); $this->addStandardTab('Notepad', $ong, $options); + if (Session::haveRight('reservation', READ)) { + // Affiche "Réservations" + $this->addStandardTab('Reservation', $ong, $options); + } $this->addStandardTab('Log', $ong, $options); return $ong; @@ -263,7 +271,7 @@ public function defineTabs($options = []) // Cette fonction affiche le formulaire de l'objet (en création ou en édition/consultation) // Cette fonction est appelée par /front/room.form.php // showForm(ID de l'objet,tableau pour les options) - public function showForm($ID, $options = []) + public function showForm($ID, array $options = []) { global $CFG_GLPI; @@ -301,7 +309,7 @@ public function showForm($ID, $options = []) // Nom de la salle echo '