From 8ec2b843bac961721805fa0356ba1ae77d449ca0 Mon Sep 17 00:00:00 2001 From: C-Duv <1466273+C-Duv@users.noreply.github.com> Date: Fri, 9 Feb 2018 02:31:03 +0100 Subject: [PATCH 1/6] Deletes old database migration code Over the time, the plugin used various database schemas. Migration code was made so that database from various plugin version could be upgraded to the latest schema. With old GLPI version support drop in v3.1.1, most of theses codes are useless. This commit drops theses codes. Issue: #30 --- hook.php | 242 +++--------------------------------------- inc/profile.class.php | 34 ------ 2 files changed, 13 insertions(+), 263 deletions(-) diff --git a/hook.php b/hook.php index 58cdca1..77c125a 100644 --- a/hook.php +++ b/hook.php @@ -38,10 +38,7 @@ function plugin_room_install() { include_once (GLPI_ROOT . "/plugins/room/inc/profile.class.php"); - $install = false; - $upgradeFrom2 = false; - $upgradeFrom3Beta = false; - + // Table for room assets if (! $DB->tableExists('glpi_plugin_room_rooms')) { $query = "CREATE TABLE `glpi_plugin_room_rooms` ( `id` int(11) NOT NULL auto_increment, @@ -86,123 +83,22 @@ function plugin_room_install() { KEY `users_id` (`users_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;"; $DB->query($query) or die("error adding glpi_plugin_room table " . __('Error during the database update') . $DB->error()); - } elseif (!FieldExists('glpi_plugin_room_rooms', 'groups_id_tech')) { // Mise à jour entre 3.0.4 et 3.1.0; la table existe, mais il manque "groups_id_tech" - $query = "ALTER TABLE `glpi_plugin_room_rooms` - ADD COLUMN `groups_id_tech` INT NOT NULL DEFAULT '0' COMMENT 'Group in charge of the hardware. RELATION to glpi_groups (id)' AFTER `groups_id`;"; - $result = $DB->query($query) or die('Error when adding `glpi_plugin_room_rooms`.`groups_id_tech` field. ' . __('Error during the database update') . $DB->error()); - } elseif (FieldExists('glpi_plugin_room_rooms', 'FK_users')) { // mise à jour depuis 3.0.0 Beta; la table existe, mais avec les mauvais noms de champs - $upgradeFrom3Beta = true; - $query = "alter TABLE `glpi_plugin_room_rooms` - change FK_users users_id int(11) not null default 0, - change FK_glpi_enterprise id_manufacturers smallint(11) not null default 0, - change FK_groups id_groups smallint(11) not null default 0, - change comments comment text collate utf8_unicode_ci;"; - $result = $DB->query($query) or die("error renaming glpi_plugin_room fields from Beta version " . __('Error during the database update') . $DB->error()); - if ($result) { - $query = "ALTER TABLE `glpi_plugin_room_rooms` DROP INDEX `FK_users` , - ADD KEY `users_id` ( `users_id` );"; - $result = $DB->query($query) or die("error renaming glpi_plugin_room fields from Beta version " . __('Error during the database update') . $DB->error()); - } - $query = "ALTER TABLE `glpi_plugin_room_rooms` - ADD COLUMN `groups_id_tech` INT NOT NULL DEFAULT '0' COMMENT 'Group in charge of the hardware. RELATION to glpi_groups (id)' AFTER `groups_id`;"; - $result = $DB->query($query) or die('Error when adding `glpi_plugin_room_rooms`.`groups_id_tech` field. ' . __('Error during the database update') . $DB->error()); - - } - if ($DB->TableExists('glpi_plugin_room')) { // il existe une table correspondant à l'ancienne nomenclature; voir à transférer les enregistrement contenus dans celle-ci. - if (! $upgradeFrom3Beta) // Sauf si on vient de la version beta; on présume que l'usager aura transféré manuellement ses informations. -{ - $upgradeFrom2 = true; - $query = "SELECT COUNT(*) FROM glpi_plugin_room"; - $result = $DB->query($query); - if ($result) { // insertion des enregistrements de l'ancienne à la nouvelle table, pour peu qu'existent le entities_id et FK_users concernés - $query = "INSERT INTO glpi_plugin_room_rooms(id, name, entities_id, is_recursive, is_deleted, `type`, date_mod, size, count_linked, buy, access, printer, videoprojector, wifi, comment, opening, limits, text1, text2, dropdown1, dropdown2, tech_num, users_id, is_template, location, state, manufacturers_id, groups_id) - SELECT ID, name, FK_entities, recursive, deleted, `type`, date_mod, size, count_linked, buy, access, printer, videoprojector, wifi, comments, opening, limits, text1, text2, dropdown1, dropdown2, tech_num, FK_users, is_template, location, state, FK_glpi_enterprise, FK_groups - FROM glpi_plugin_room r WHERE - ((EXISTS(SELECT * FROM glpi_users u where u.id = r.FK_users) OR r.FK_users = 0) AND - (EXISTS(SELECT * FROM glpi_entities e where e.id = r.FK_entities) OR r.FK_entities = 0));"; - $result = 0; - $result = $DB->query($query) or die("error copying glpi_plugin_room records into new table " . __('Error during the database update') . $DB->error()); - if ($result) { - $query = "DROP TABLE glpi_plugin_room;"; - $result = $DB->query($query); - } - } else { - $query = "DROP TABLE glpi_plugin_room;"; - $result = $DB->query($query); - } - } else { - $query = "DROP TABLE glpi_plugin_room;"; - $result = $DB->query($query); - } - } else { - $install = true; - } - if ($upgradeFrom2 || $install) { // Si on arrive d'une version standard ou que c'est une installation vanille - if (! $DB->TableExists('glpi_plugin_room_rooms_computers')) { - $query = "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, - PRIMARY KEY (`id`), - UNIQUE `computers_id` (`computers_id`), - KEY `rooms_id` (`rooms_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; - $result = $DB->query($query) or die("error adding glpi_plugin_room_rooms_computers table " . __('Error during the database update') . $DB->error()); - if ($result) { - if ($DB->TableExists('glpi_plugin_room_computer')) { - $result = 0; - $query = "SELECT COUNT(*) FROM glpi_plugin_room_computer"; - $result = $DB->query($query); - - if ($result) { - $query = "INSERT INTO glpi_plugin_room_rooms_computers(id, rooms_id, computers_id) - SELECT ID, FK_rooms, FK_computers - FROM glpi_plugin_room_computer ;"; - $result = 0; - $result = $DB->query($query) or die("error copying glpi_plugin_room_computer records into new table " . __('Error during the database update') . $DB->error()); - if ($result) { - $query = "DROP TABLE glpi_plugin_room_computer;"; - $result = $DB->query($query); - } - } else { - $query = "DROP TABLE glpi_plugin_room_computer;"; - $result = $DB->query($query); - } - } - } - } - } elseif ($upgradeFrom3Beta) { - $query = "rename table `glpi_plugin_room_computer` to `glpi_plugin_room_rooms_computers`;"; - $result = $DB->query($query) or die("error renaming glpi_plugin_room_computer table from BETA version " . __('Error during the database update') . $DB->error()); - if ($result) { - $query = "alter TABLE `glpi_plugin_room_rooms_computers` - change FK_rooms rooms_id int(11) not null , - change FK_computers id_computers int(11) not null, - DROP INDEX `FK_rooms` , - ADD KEY `rooms_id` ( `rooms_id` ), - DROP INDEX `FK_computers` , - ADD UNIQUE `id_computers` ( `id_computers` );"; - $result = $DB->query($query) or die("error renaming glpi_plugin_room_rooms_computers fields from Beta version " . __('Error during the database update') . $DB->error()); - } } - if (! $DB->TableExists('glpi_plugin_room_profiles')) { - $query = "CREATE TABLE `glpi_plugin_room_profiles` ( + // Table to link Rooms to Computers + if (! $DB->TableExists('glpi_plugin_room_rooms_computers')) { + $query = "CREATE TABLE `glpi_plugin_room_rooms_computers` ( `id` int(11) NOT NULL auto_increment, - `profiles_id` int(11) NOT NULL default '0' COMMENT 'RELATION to glpi_profiles (id)', - `room` char(1) collate utf8_unicode_ci default NULL, + `computers_id` int(11) NOT NULL, + `rooms_id` int(11) NOT NULL, PRIMARY KEY (`id`), - KEY `profiles_id` (`profiles_id`) + UNIQUE `computers_id` (`computers_id`), + KEY `rooms_id` (`rooms_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; - $DB->query($query) or die("error adding glpi_plugin_room_profiles table " . __('Error during the database update') . $DB->error()); - // je pense qu'il faut aussi ici faire des insertions dans glpi_displaypreferences - // (Edit PMD) ainsi que dans glpi_bookmark, glpi_doc_device -> glpi_documents_items et glpi_logs -> glpi_history - } elseif (FieldExists('glpi_plugin_room_profiles', 'FK_profiles')) { - $query = "UPDATE `glpi_plugin_room_profiles` - CHANGE `FK_profiles` `profiles_id`, `ID` `id`"; - $DB->query($query) or die("error updating table glpi_plugin_room_computer" . __('Error during the database update') . $DB->error()); + $DB->query($query) or die("error adding glpi_plugin_room_rooms_computers table " . __('Error during the database update') . $DB->error()); } + // Table for Room types if (! $DB->TableExists('glpi_plugin_room_roomtypes')) { $query = "CREATE TABLE `glpi_plugin_room_roomtypes` ( `id` int(11) NOT NULL auto_increment, @@ -213,23 +109,8 @@ function plugin_room_install() { ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die("error adding glpi_plugin_room_roomtypes table " . __('Error during the database update') . $DB->error()); } - if ($DB->TableExists('glpi_dropdown_plugin_room_type') && ! $upgradeFrom3Beta) { // il existe une table correspondant à l'ancienne nomenclature; - // voir à transférer les enregistrement contenus dans celle-ci. - // Sauf si on arrive de la version beta - $query = "SELECT COUNT(*) FROM glpi_dropdown_plugin_room_type"; - $result = $DB->query($query); - if ($result) { // insertion des enregistrements de l'ancienne à la nouvelle table, pour peu qu'existent le entities_id et FK_users concernés - $query = "INSERT INTO glpi_plugin_room_roomtypes(id, name, comment) - SELECT id, name, comments - FROM glpi_dropdown_plugin_room_type ;"; - $result = 0; - $result = $DB->query($query) or die("error copying glpi_dropdown_plugin_room_type records into new table " . __('Error during the database update') . $DB->error()); - if ($result) { - $query = "DROP TABLE glpi_dropdown_plugin_room_type;"; - $result = $DB->query($query); - } - } - } + + // Table for access conditions if (! $DB->TableExists('glpi_plugin_room_roomaccessconds')) { $query = "CREATE TABLE `glpi_plugin_room_roomaccessconds` ( `id` int(11) NOT NULL auto_increment, @@ -239,22 +120,9 @@ function plugin_room_install() { KEY `name` (`name`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $DB->query($query) or die("error adding glpi_plugin_room_roomaccessconds table " . __('Error during the database update') . $DB->error()); - if ($DB->TableExists('glpi_dropdown_plugin_room_access')) { - $query = "SELECT COUNT(*) FROM glpi_dropdown_plugin_room_access"; - $result = $DB->query($query); - if ($result) { - $query = "INSERT INTO glpi_plugin_room_roomaccessconds (id, name, comment) - SELECT id, name, comments FROM glpi_dropdown_plugin_room_access"; - $result = 0; - $result = $DB->query($query) or die("error copying glpi_dropdown_plugin_room_access records into new table " . __('Error during the database update') . $DB->error()); - if ($result) { - $query = "DROP TABLE glpi_dropdown_plugin_room_access;"; - $result = $DB->query($query); - } - } - } } + // Table for dropdowns if (! $DB->TableExists('glpi_plugin_room_dropdown1s')) { $query = "CREATE TABLE `glpi_plugin_room_dropdown1s` ( `id` int(11) NOT NULL auto_increment, @@ -266,91 +134,7 @@ function plugin_room_install() { $DB->query($query) or die("error adding glpi_plugin_room_roomspecificities table " . __('Error during the database update') . $DB->error()); } - if ($DB->TableExists('glpi_dropdown_plugin_room_dropdown1') && ! $upgradeFrom3Beta) { - $query = "SELECT COUNT(*) FROM glpi_dropdown_plugin_room_dropdown1"; - $result = $DB->query($query); - if ($result) { - $query = "INSERT INTO glpi_plugin_room_dropdown1s (id, name, comment) - SELECT id, name, comments FROM glpi_dropdown_plugin_room_dropdown1"; - $result = 0; - $result = $DB->query($query) or die("error copying glpi_dropdown_plugin_room_dropdown1 records into new table " . __('Error during the database update') . $DB->error()); - if ($result) { - $query = "DROP TABLE glpi_dropdown_plugin_room_dropdown1;"; - $result = $DB->query($query); - } - } else { - $query = "DROP TABLE glpi_dropdown_plugin_room_dropdown1;"; - $result = $DB->query($query); - } - } - - if ($DB->TableExists('glpi_dropdown_plugin_room_dropdown2') && ! $upgradeFrom3Beta) { - $query = "SELECT * FROM glpi_dropdown_plugin_room_dropdown2"; - $result = $DB->query($query); - if ($result) { - $idOffset = 0; - $query = "SELECT MAX(id) FROM glpi_plugin_room_dropdown1s"; - $result = 0; - $result = $DB->query($query) or die("error copying glpi_dropdown_plugin_room_dropdown2 records into new table " . __('Error during the database update') . $DB->error()); - if ($result) { // Il existait des valeurs dans la table glpi_dropdown_plugin_room_dropdown1 qui ont été transférées dams glpi_plugin_room_roomspecificities - // On doit décaler les valeurs de glpi_dropdown_plugin_room_dropdown2. - $row = $DB->fetch_array($result); - if ($row[0]) { - $idOffset = $row[0]; - } - } - $query = "INSERT INTO glpi_plugin_room_dropdown1s (id, name, comment) - SELECT (ID + " . $idOffset . "), name, comments FROM glpi_dropdown_plugin_room_dropdown2"; - $result = 0; - $result = $DB->query($query) or die("error copying glpi_dropdown_plugin_room_dropdown2 records into new table " . __('Error during the database update') . $DB->error()); - if ($result) { - if ($idOffset > 0) { - // Nous avons décalé les id des spécificités de la table glpi_dropdown_plugin_room_dropdown2; on doit modifier les enregistrements de la table glpi_plugin_room_rooms en conséquence. - $result = 0; - $query = "UPDATE glpi_plugin_room_rooms - SET `dropdown2` = (`dropdown2` + " . $idOffset . ") - WHERE `dropdown2` > 0;"; - $result = $DB->query($query) or die("error updating dropdown2 values to new ids. " . __('Error during the database update') . $DB->error()); - } - $query = "DROP TABLE glpi_dropdown_plugin_room_dropdown2;"; - $result = $DB->query($query); - } - } else { - $query = "DROP TABLE glpi_dropdown_plugin_room_dropdown2;"; - $result = $DB->query($query); - } - } - - if ($upgradeFrom2 || $upgradeFrom3Beta) { - $query = "UPDATE `glpi_reservationitems` - SET itemtype = 'PluginRoomRoom' - WHERE itemtype = '1050';"; - $result = $DB->query($query) or die("error updating glpi_reservationitems records for prior room reservations " . __('Error during the database update') . $DB->error()); - $query = "UPDATE `glpi_displaypreferences` - SET itemtype = 'PluginRoomRoom' - WHERE itemtype = '1050';"; - $result = $DB->query($query) or die("error updating glpi_displaypreferences records for prior room display preferences " . __('Error during the database update') . $DB->error()); - $query = "UPDATE `glpi_logs` - SET itemtype = 'PluginRoomRoom' - WHERE itemtype = '1050';"; - $result = $DB->query($query) or die("error updating glpi_logs records for prior room modifications history " . __('Error during the database update') . $DB->error()); - $query = "UPDATE `glpi_documents_items` - SET itemtype = 'PluginRoomRoom' - WHERE itemtype = '1050';"; - $result = $DB->query($query) or die("error updating glpi_document_items records for prior room documents" . __('Error during the database update') . $DB->error()); - $query = "UPDATE `glpi_bookmarks` - SET itemtype = 'PluginRoomRoom' - WHERE itemtype = '1050';"; - $result = $DB->query($query) or die("error updating glpi_bookmarks records for prior room bookmarks" . __('Error during the database update') . $DB->error()); - $query = "UPDATE `glpi_bookmarks_users` - SET itemtype = 'PluginRoomRoom' - WHERE itemtype = '1050';"; - $result = $DB->query($query) or die("error updating glpi_document_items records for prior room private bookmarks" . __('Error during the database update') . $DB->error()); - } - PluginRoomProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); - $migration = new Migration('3.0.4'); - $migration->dropTable('glpi_plugin_room_profiles'); return true; } diff --git a/inc/profile.class.php b/inc/profile.class.php index 1218cab..362ead8 100755 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -174,36 +174,6 @@ static function translateARight($old_right) { } } - /** - * - * @since 0.85 - * Migration rights from old system to the new one for one profile - * @param $profiles_id the profile ID - */ - static function migrateOneProfile($profiles_id) { - global $DB; - // Cannot launch migration if there's nothing to migrate... - if (! $DB->TableExists('glpi_plugin_room_profiles')) { - return true; - } - - foreach ($DB->request('glpi_plugin_room_profiles', "`profiles_id`='$profiles_id'") as $profile_data) { - - $matching = array( - 'room' => 'plugin_room' - ); - $current_rights = ProfileRight::getProfileRights($profiles_id, array_values($matching)); - foreach ($matching as $old => $new) { - if (! isset($current_rights[$old])) { - $query = "UPDATE `glpi_profilerights` - SET `rights`='" . self::translateARight($profile_data[$old]) . "' - WHERE `name`='$new' AND `profiles_id`='$profiles_id'"; - $DB->query($query); - } - } - } - } - /** * Initialize profiles, and migrate it necessary */ @@ -220,10 +190,6 @@ static function initProfile() { } } - // Migration old rights in new ones - foreach ($DB->request("SELECT `id` FROM `glpi_profiles`") as $prof) { - self::migrateOneProfile($prof['id']); - } foreach ($DB->request("SELECT * FROM `glpi_profilerights` WHERE `profiles_id`='" . $_SESSION['glpiactiveprofile']['id'] . "' From 74044dd313d6b5a8938940102f87734378fb8215 Mon Sep 17 00:00:00 2001 From: C-Duv <1466273+C-Duv@users.noreply.github.com> Date: Sat, 25 Aug 2018 12:51:13 +0200 Subject: [PATCH 2/6] Deletes backward GLPI compatibility code Over the time, the GLPI core API changed and the plugin was somehow compatible with previous versions. With old GLPI version support drop in v3.1.1, theses codes are useless. This commit drops a part relative to "notepad" feature. Issue: #30 --- inc/room.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/room.class.php b/inc/room.class.php index 46837e9..46c1464 100644 --- a/inc/room.class.php +++ b/inc/room.class.php @@ -39,8 +39,7 @@ class PluginRoomRoom extends CommonDBTM { static $rightname = "plugin_room"; - protected $usenotepadrights = true; // GLPI < v0.90 - protected $usenotepad = true; // GLPI >= v0.90 + protected $usenotepad = true; static function getTypeName($nb = 0) { global $LANG; From 82beb88c3106b2a789e8f6ed4fca1ac2237504be Mon Sep 17 00:00:00 2001 From: C-Duv <1466273+C-Duv@users.noreply.github.com> Date: Sun, 2 Sep 2018 16:14:55 +0200 Subject: [PATCH 3/6] Apply PHP coding standard PSR-1, PSR-2 and PSR-12 Until now the code was conforming to PSR-1, PSR-2 and GLPI's Coding standards. Because GLPI's Coding standards is not a common standard, I am dropping it in favor of more wide-spread one: code will now respect PSR-1, PSR-2 and PSR-12. The main change is the indentation: GLPI wants a 3-space indentation but I am changing to a 4-space indentation. I also applied some of Symfony coding standards (but not all). Conformation to theses rules can be checked with PHP Coding Standards Fixer (http://cs.sensiolabs.org) using the provided ".php_cs.dist" file. Some SQL queries were moved into PHP Heredoc and Nowdoc with some SQL formatting to avoid reaching the 120 characters soft limit on line length. Issue: #32 --- .gitignore | 1 + .php_cs.dist | 130 ++++ README.md | 27 +- ajax/profile_tabs.php | 43 +- ajax/room.tabs.php | 67 +- front/dropdown1.form.php | 34 +- front/dropdown1.php | 34 +- front/profile.form.php | 39 +- front/room.form.php | 195 +++--- front/room.php | 41 +- front/roomaccesscond.form.php | 34 +- front/roomaccesscond.php | 34 +- front/roomtype.form.php | 34 +- front/roomtype.php | 34 +- hook.php | 600 ++++++++-------- inc/dropdown1.class.php | 51 +- inc/menu.class.php | 55 +- inc/profile.class.php | 409 +++++------ inc/room.class.php | 1208 +++++++++++++++++---------------- inc/room_computer.class.php | 54 +- inc/roomaccesscond.class.php | 52 +- inc/roomtype.class.php | 51 +- index.php | 41 +- locales/de_DE.php | 79 +-- locales/en_GB.php | 79 +-- locales/fr_FR.php | 79 +-- locales/it_IT.php | 79 +-- locales/pt_PT.php | 79 +-- setup.php | 128 ++-- 29 files changed, 1644 insertions(+), 2147 deletions(-) create mode 100644 .gitignore create mode 100644 .php_cs.dist diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b3d4649 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.php_cs \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..1012c07 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,130 @@ +in(__DIR__) +; + +$config = PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ + '@PSR1' => true, // Apply PSR-1 + '@PSR2' => true, // Apply PSR-2 + + 'align_multiline_comment' => true, // Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one. + 'array_indentation' => true, // Each element of an array must be indented exactly once. + 'array_syntax' => ['syntax' => 'short'], // PHP arrays should be declared using the configured syntax. + 'backtick_to_shell_exec' => true, // Converts backtick operators to shell_exec calls. + 'binary_operator_spaces' => ['default' => 'single_space'], // Binary operators should be surrounded by space as configured. + 'blank_line_after_opening_tag' => true, // Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line. + 'cast_spaces' => true, // A single space or none should be between cast and variable. + 'class_attributes_separation' => true, // Class, trait and interface elements must be separated with one blank line. + 'class_keyword_remove' => true, // Converts ::class keywords to FQCN strings. + 'combine_consecutive_issets' => true, // Converts ::class keywords to FQCN strings. + 'combine_consecutive_unsets' => true, // Calling unset on multiple items should be done in one call. + 'compact_nullable_typehint' => true, // Remove extra spaces in a nullable typehint. + 'concat_space' => ['spacing' => 'one'], // Concatenation should be spaced according configuration. + 'declare_equal_normalize' => ['space' => 'single'], // Equal sign in declare statement should be surrounded by spaces or not following configuration. + 'dir_constant' => true, // Replaces dirname(__FILE__) expression with equivalent __DIR__ constant. + 'ereg_to_preg' => true, // Replace deprecated ereg regular expression functions with preg. + 'explicit_indirect_variable' => true, // Add curly braces to indirect variables to make them clear to understand. Requires PHP >= 7.0. + 'fully_qualified_strict_types' => true, // Transforms imported FQCN parameters and return types in function arguments to short version. + 'function_typehint_space' => true, // Add missing space between function's argument and its typehint. + 'include' => true, // Include/Require and file path should be divided with a single space. File path should not be placed under brackets. + 'increment_style' => ['style' => 'pre'], // Pre- or post-increment and decrement operators should be used if possible. + 'line_ending' => true, // All PHP files must use same line ending. + 'list_syntax' => ['syntax' => 'short'], // List (array destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1. + 'logical_operators' => true, // Use && and || logical operators instead of and and or. + 'lowercase_cast' => true, // Cast should be written in lower case. + 'lowercase_static_reference' => true, // Class static references self, static and parent MUST be in lower case. + 'magic_constant_casing' => true, // Magic constants should be referred to using the correct casing. + 'mb_str_functions' => true, // Replace non multibyte-safe functions with corresponding mb function. + 'modernize_types_casting' => true, // Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator. + 'multiline_comment_opening_closing' => true, // DocBlocks must start with two asterisks, multiline comments must start with a single asterisk, after the opening slash. Both must end with a single asterisk before the closing slash. + 'multiline_whitespace_before_semicolons' => true, // Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new li ne for chained calls. + 'native_function_casing' => true, // Function defined by PHP should be called using the correct casing. + 'new_with_braces' => true, // All instances created with new keyword must be followed by braces. + 'no_alias_functions' => true, // Master functions shall be used instead of aliases. + 'no_alternative_syntax' => true, // Replace control structure alternative syntax to use braces. + 'no_blank_lines_after_class_opening' => true, // There should be no empty lines after class opening brace. + 'no_empty_comment' => true, // There should not be any empty comments. + 'no_empty_phpdoc' => true, // There should not be empty PHPDoc blocks. + 'no_empty_statement' => true, // Remove useless semicolon statements. + 'no_extra_blank_lines' => ['tokens' => [ // Removes extra blank lines and/or blank lines following configuration. + 'break', + 'case', + 'continue', + 'curly_brace_block', + 'default', + 'extra', + 'parenthesis_brace_block', + 'return', + 'square_brace_block', + 'switch', + 'throw', + 'use', + 'useTrait', + 'use_trait', + ]], + 'no_homoglyph_names' => true, // Replace accidental usage of homoglyphs (non ascii characters) in names. + 'no_leading_import_slash' => true, // Remove leading slashes in use clauses. + 'no_leading_namespace_whitespace' => true, // The namespace declaration line shouldn't contain leading whitespace. + 'no_mixed_echo_print' => ['use' => 'echo'], // Either language construct print or echo should be used. + 'no_multiline_whitespace_around_double_arrow' => true, // Operator => should not be surrounded by multi-line whitespaces. + 'no_null_property_initialization' => true, // Properties MUST not be explicitly initialized with null. + 'no_php4_constructor' => true, // Convert PHP4-style constructors to __construct. + 'no_short_bool_cast' => true, // Short cast bool using double exclamation mark should not be used. + 'no_short_echo_tag' => true, // Replace short-echo true, // Single-line whitespace before closing semicolon are prohibited. + 'no_spaces_around_offset' => true, // There MUST NOT be spaces around offset braces. + 'no_trailing_comma_in_singleline_array' => true, // PHP single-line arrays should not have trailing comma. + 'no_unneeded_control_parentheses' => true, // Removes unneeded parentheses around control statements. + 'no_unneeded_curly_braces' => true, // Removes unneeded curly braces that are superfluous and aren't part of a control structure's body. + 'no_unneeded_final_method' => true, // A final class must not have final methods. + 'no_unreachable_default_argument_value' => true, // In function arguments there must not be arguments with default values before non-default ones. + 'no_unused_imports' => true, // Unused use statements must be removed. + 'no_useless_return' => true, // There should not be an empty return statement at the end of a function. + 'no_whitespace_before_comma_in_array' => true, // In array declaration, there MUST NOT be a whitespace before each comma. + 'no_whitespace_in_blank_line' => true, // Remove trailing whitespace at the end of blank lines. + 'non_printable_character' => true, // Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other invisible unicode symbols. + 'normalize_index_brace' => true, // Array index should always be written by using square braces. + 'object_operator_without_whitespace' => true, // There should not be space before or after object T_OBJECT_OPERATOR ->. + + 'phpdoc_add_missing_param_annotation' => true, // Phpdoc should contain @param for all params. + 'phpdoc_align' => ['align' => 'left'], // All items of the given phpdoc tags must be either left-aligned or (by default) aligned vertically. + 'phpdoc_indent' => true, // Docblocks should have the same indentation as the documented subject. + 'phpdoc_scalar' => true, // Scalar types should always be written in the same form. int not integer, bool not boolean, float not real or double. + 'phpdoc_separation' => true, // Annotations in phpdocs should be grouped together so that annotations of the same type immediately follow each oth er, and annotations of a different type are separated by a single blank line. + 'phpdoc_single_line_var_spacing' => true, // Single line @var PHPDoc should have proper spacing. + 'phpdoc_to_comment' => true, // Docblocks should only be used on structural elements. + 'phpdoc_types' => true, // The correct case must be used for standard PHP types in PHPDoc. + 'phpdoc_var_without_name' => true, // @var and @type annotations should not contain the variable name. + + 'pow_to_exponentiation' => true, // Converts pow to the ** operator. + 'random_api_migration' => true, // Replaces rand, srand, getrandmax functions calls with their mt_* analogs. + 'return_assignment' => true, // Local, dynamic and directly referenced variables should not be assigned and directly returned by a function or method. + 'return_type_declaration' => true, // There should be one or no space before colon, and one space after it in return type declarations, according to configuration. + 'self_accessor' => true, // Inside class or interface element self should be preferred to the class name itself. + 'semicolon_after_instruction' => true, // Instructions must be terminated with a semicolon. + 'set_type_to_cast' => true, // Cast shall be used, not settype. + 'short_scalar_cast' => true, // Cast (boolean) and (integer) should be written as (bool) and (int), (double) and (real) as (float). + 'single_blank_line_before_namespace' => true, // There should be exactly one blank line before a namespace declaration. + 'single_line_comment_style' => true, // Single-line comments and multi-line comments with only one line of actual content should use the // syntax . + 'single_quote' => true, // Convert double quotes to single quotes for simple strings. + 'space_after_semicolon' => true, // Fix whitespace after a semicolon. + 'standardize_increment' => true, // Increment and decrement operators should be used if possible. + 'standardize_not_equals' => true, // Replace all <> with !=. + 'string_line_ending' => true, // All multi-line strings must use correct line ending. + 'ternary_operator_spaces' => true, // Standardize spaces around ternary operator. + 'trailing_comma_in_multiline_array' => true, // PHP multi-line arrays should have a trailing comma. + 'trim_array_spaces' => true, // Arrays should be formatted like function/method arguments, without leading or trailing single line space. + 'unary_operator_spaces' => true, // Unary operators should be placed adjacent to their operands. + 'whitespace_after_comma_in_array' => true, // In array declaration, there MUST be a whitespace after each comma. + + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ) +; + +return $config; diff --git a/README.md b/README.md index 8277fab..f0242c3 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,32 @@ Contributing Please follow the following rules for contributing: -* Respect [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/) - and [GLPI's Coding standards](http://glpi-developer-documentation.readthedocs.io/en/master/codingstandards.html) - (giving priority to the latest). +* Respect [PSR-1](http://www.php-fig.org/psr/psr-1/) and [PSR-2](http://www.php-fig.org/psr/psr-2/). * Open an issue for each bug/feature so it can be discussed. * Follow [development guidelines](http://glpi-developer-documentation.readthedocs.io/en/master/plugins/guidelines.html). * Refer to [GitFlow](http://git-flow.readthedocs.io) process for branching. * Work on a new branch on your own fork. * Open a PR for merging. It will be reviewed by a developer. + +### Coding standards + +Respect of coding standard is checked by [*PHP Coding Standards Fixer*](http://cs.sensiolabs.org). +The `.php_cs.dist` file contains the standards to conform to. + +Command to list all PHP files with standard issues: + +```Shell +php php-cs-fixer-v2.phar fix --config .php_cs.dist --dry-run. +``` + +Same command but includes detail of actual lines with standard issues: + +```Shell +php php-cs-fixer-v2.phar fix --config .php_cs.dist --dry-run --diff . +``` + +Command to fix thoses issues: + +```Shell +php php-cs-fixer-v2.phar fix --config .php_cs.dist . +``` diff --git a/ajax/profile_tabs.php b/ajax/profile_tabs.php index b6d2869..bfc275e 100644 --- a/ajax/profile_tabs.php +++ b/ajax/profile_tabs.php @@ -1,45 +1,12 @@ showrelationsForm($_POST["ID"]); - -?> +if ($_POST['interface'] == 'room') { + $prof->showrelationsForm($_POST['ID']); +} diff --git a/ajax/room.tabs.php b/ajax/room.tabs.php index 25767a3..689986a 100644 --- a/ajax/room.tabs.php +++ b/ajax/room.tabs.php @@ -1,60 +1,29 @@ 0 && $Room->can($_POST["id"], READ)) { - switch ($_REQUEST['glpi_tab']) { - case - 1: // Onglet Tous - $Room->showComputers($_POST['target'], $_POST["id"]); - Reservation::showForItem($Room); - break; - default: // Logiquement Onglet Principal - if ($_POST["id"]) { - if (! CommonGLPI::displayStandardTab($Room, $_POST["id"], $_REQUEST['glpi_tab'])) { - $Room->showComputers($_POST['target'], $_POST["id"]); +if ($_POST['id'] > 0 && $Room->can($_POST['id'], READ)) { + switch ($_REQUEST['glpi_tab']) { + case -1: // Onglet Tous + $Room->showComputers($_POST['target'], $_POST['id']); + Reservation::showForItem($Room); + break; + default: // Logiquement Onglet Principal + if ($_POST['id']) { + if (!CommonGLPI::displayStandardTab($Room, $_POST['id'], $_REQUEST['glpi_tab'])) { + $Room->showComputers($_POST['target'], $_POST['id']); + } } - } - break; - } + break; + } } -?> \ No newline at end of file diff --git a/front/dropdown1.form.php b/front/dropdown1.form.php index c5a31db..f59e7e8 100644 --- a/front/dropdown1.form.php +++ b/front/dropdown1.form.php @@ -1,38 +1,6 @@ \ No newline at end of file +include GLPI_ROOT . '/front/dropdown.common.form.php'; diff --git a/front/dropdown1.php b/front/dropdown1.php index c5a31db..f59e7e8 100644 --- a/front/dropdown1.php +++ b/front/dropdown1.php @@ -1,38 +1,6 @@ \ No newline at end of file +include GLPI_ROOT . '/front/dropdown.common.form.php'; diff --git a/front/profile.form.php b/front/profile.form.php index de87930..9e773a4 100755 --- a/front/profile.form.php +++ b/front/profile.form.php @@ -1,46 +1,13 @@ update($_POST); - Html::back(); + $prof->update($_POST); + Html::back(); } - -?> \ No newline at end of file diff --git a/front/room.form.php b/front/room.form.php index 9bb7fcb..3138305 100644 --- a/front/room.form.php +++ b/front/room.form.php @@ -1,124 +1,93 @@ check(- 1, CREATE, $_POST); - - $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); +if (isset($_POST['add'])) { // Ajout d'une salle + $room->check(-1, CREATE, $_POST); + + $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 { // 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($LANG['plugin_room'][0], '', "assets", "pluginroommenu"); - - $room->display($_GET); - - Html::footer(); - } -?> \ No newline at end of file + 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($LANG['plugin_room'][0], '', 'assets', 'pluginroommenu'); + + $room->display($_GET); + + Html::footer(); + } + } + } + } + } + } +} diff --git a/front/room.php b/front/room.php index f935679..b24c84b 100644 --- a/front/room.php +++ b/front/room.php @@ -1,48 +1,15 @@ diff --git a/front/roomaccesscond.form.php b/front/roomaccesscond.form.php index 35d3b5f..6970049 100644 --- a/front/roomaccesscond.form.php +++ b/front/roomaccesscond.form.php @@ -1,38 +1,6 @@ \ No newline at end of file +include GLPI_ROOT . '/front/dropdown.common.form.php'; diff --git a/front/roomaccesscond.php b/front/roomaccesscond.php index 35d3b5f..6970049 100644 --- a/front/roomaccesscond.php +++ b/front/roomaccesscond.php @@ -1,38 +1,6 @@ \ No newline at end of file +include GLPI_ROOT . '/front/dropdown.common.form.php'; diff --git a/front/roomtype.form.php b/front/roomtype.form.php index 771eba5..3dba5d5 100644 --- a/front/roomtype.form.php +++ b/front/roomtype.form.php @@ -1,38 +1,6 @@ \ No newline at end of file +include GLPI_ROOT . '/front/dropdown.common.form.php'; diff --git a/front/roomtype.php b/front/roomtype.php index 771eba5..3dba5d5 100644 --- a/front/roomtype.php +++ b/front/roomtype.php @@ -1,38 +1,6 @@ \ No newline at end of file +include GLPI_ROOT . '/front/dropdown.common.form.php'; diff --git a/hook.php b/hook.php index 77c125a..4909090 100644 --- a/hook.php +++ b/hook.php @@ -1,77 +1,46 @@ tableExists('glpi_plugin_room_rooms')) { - $query = "CREATE TABLE `glpi_plugin_room_rooms` ( +function plugin_room_install() +{ + global $DB, $LANG; + + include_once GLPI_ROOT . '/plugins/room/inc/profile.class.php'; + + // Table for room assets + 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', - `is_recursive` smallint(6) NOT NULL default '0', - `is_deleted` smallint(6) NOT NULL default '0', - `type` int(11) NOT NULL default '0', + `entities_id` int(11) NOT NULL default 0, + `locations_id` int(11) 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, - `size` smallint(6) NOT NULL default '0', - `count_linked` smallint(6) NOT NULL default '0', + `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', - `printer` smallint(6) NOT NULL default '0', - `videoprojector` smallint(6) NOT NULL default '0', - `wifi` smallint(6) NOT NULL default '0', + `access` int(11) 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', - `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)', - PRIMARY KEY (`id`), + `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, + `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)", + PRIMARY KEY (`id`), KEY `entities_id` (`entities_id`), KEY `is_deleted` (`is_deleted`), KEY `type` (`type`), @@ -81,294 +50,325 @@ 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 ;"; - $DB->query($query) or die("error adding glpi_plugin_room table " . __('Error during the database update') . $DB->error()); - } - - // Table to link Rooms to Computers - if (! $DB->TableExists('glpi_plugin_room_rooms_computers')) { - $query = "CREATE TABLE `glpi_plugin_room_rooms_computers` ( + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +EOS; + $DB->query($query) || die('error adding glpi_plugin_room table ' . __('Error during the database update') . $DB->error()); + } + + // Table to link Rooms to Computers + 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, - PRIMARY KEY (`id`), + PRIMARY KEY (`id`), UNIQUE `computers_id` (`computers_id`), KEY `rooms_id` (`rooms_id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; - $DB->query($query) or die("error adding glpi_plugin_room_rooms_computers table " . __('Error during the database update') . $DB->error()); - } - - // Table for Room types - if (! $DB->TableExists('glpi_plugin_room_roomtypes')) { - $query = "CREATE TABLE `glpi_plugin_room_roomtypes` ( + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +EOS; + $DB->query($query) || die('error adding glpi_plugin_room_rooms_computers table ' . __('Error during the database update') . $DB->error()); + } + + // Table for Room types + 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, - PRIMARY KEY (`id`), + PRIMARY KEY (`id`), KEY `name` (`name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; - $DB->query($query) or die("error adding glpi_plugin_room_roomtypes table " . __('Error during the database update') . $DB->error()); - } - - // Table for access conditions - if (! $DB->TableExists('glpi_plugin_room_roomaccessconds')) { - $query = "CREATE TABLE `glpi_plugin_room_roomaccessconds` ( + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +EOS; + $DB->query($query) || die('error adding glpi_plugin_room_roomtypes table ' . __('Error during the database update') . $DB->error()); + } + + // Table for access conditions + 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, - PRIMARY KEY (`id`), + PRIMARY KEY (`id`), KEY `name` (`name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; - $DB->query($query) or die("error adding glpi_plugin_room_roomaccessconds table " . __('Error during the database update') . $DB->error()); - } - - // Table for dropdowns - if (! $DB->TableExists('glpi_plugin_room_dropdown1s')) { - $query = "CREATE TABLE `glpi_plugin_room_dropdown1s` ( + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +EOS; + $DB->query($query) || die('error adding glpi_plugin_room_roomaccessconds table ' . __('Error during the database update') . $DB->error()); + } + + // Table for dropdowns + 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, - PRIMARY KEY (`id`), + PRIMARY KEY (`id`), KEY `name` (`name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; - $DB->query($query) or die("error adding glpi_plugin_room_roomspecificities table " . __('Error during the database update') . $DB->error()); - } + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +EOS; + $DB->query($query) || die('error adding glpi_plugin_room_roomspecificities table ' . __('Error during the database update') . $DB->error()); + } - PluginRoomProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); + PluginRoomProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']); - return true; + return true; } -function plugin_room_uninstall() { - global $DB; - - $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_rooms_computers`'; - $DB->query($query); - $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_roomtypes`'; - $DB->query($query); - $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_roomaccessconds`'; - $DB->query($query); - $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_dropdown1s`'; - $DB->query($query); - $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_rooms`'; - $DB->query($query); - - $tables_glpi = array( - "glpi_displaypreferences", - "glpi_documents_items", - "glpi_logs", - 'glpi_items_tickets', - 'glpi_reservationitems', - 'glpi_savedsearches', - ); - - foreach ($tables_glpi as $table_glpi) - $DB->query("DELETE FROM `$table_glpi` WHERE `itemtype` = 'PluginRoomRoom';"); - - return true; +function plugin_room_uninstall() +{ + global $DB; + + $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_rooms_computers`'; + $DB->query($query); + $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_roomtypes`'; + $DB->query($query); + $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_roomaccessconds`'; + $DB->query($query); + $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_dropdown1s`'; + $DB->query($query); + $query = 'DROP TABLE IF EXISTS `glpi_plugin_room_rooms`'; + $DB->query($query); + + $tables_glpi = [ + 'glpi_displaypreferences', + 'glpi_documents_items', + 'glpi_logs', + 'glpi_items_tickets', + 'glpi_reservationitems', + 'glpi_savedsearches', + ]; + + foreach ($tables_glpi as $table_glpi) { + $DB->query('DELETE FROM `$table_glpi` WHERE `itemtype` = "PluginRoomRoom";'); + } + + return true; } // Define dropdown relations -function plugin_room_getDatabaseRelations() { - $plugin = new Plugin(); - - if ($plugin->isActivated("room")) { - return array( - "glpi_plugin_room_roomtypes" => array( - "glpi_plugin_room_rooms" => "type" - ), - "glpi_plugin_room_roomaccessconds" => array( - "glpi_plugin_room_rooms" => "access" - ), - "glpi_plugin_room_dropdown1s" => array( - "glpi_plugin_room_rooms" => array( - "dropdown1", - "dropdown2" - ) - ), - "glpi_plugin_room_rooms" => array( - "glpi_plugin_room_rooms_computers" => "rooms_id" - ), - "glpi_computers" => array( - "glpi_plugin_room_rooms_computers" => "computers_id" - ), - "glpi_entities" => array( - "glpi_plugin_room_rooms" => "entities_id" - ), - "glpi_locations" => array( - "glpi_plugin_room_rooms" => "locations_id" - ), - "glpi_profiles" => array( - "glpi_plugin_room_profiles" => "profiles_id" - ), - "glpi_users" => array( - "glpi_plugin_room_rooms" => array( - 'users_id', - 'tech_num' - ) - ) - ); - } else - return array(); +function plugin_room_getDatabaseRelations() +{ + $plugin = new Plugin(); + + if ($plugin->isActivated('room')) { + return [ + 'glpi_plugin_room_roomtypes' => [ + 'glpi_plugin_room_rooms' => 'type', + ], + 'glpi_plugin_room_roomaccessconds' => [ + 'glpi_plugin_room_rooms' => 'access', + ], + 'glpi_plugin_room_dropdown1s' => [ + 'glpi_plugin_room_rooms' => [ + 'dropdown1', + 'dropdown2', + ], + ], + 'glpi_plugin_room_rooms' => [ + 'glpi_plugin_room_rooms_computers' => 'rooms_id', + ], + 'glpi_computers' => [ + 'glpi_plugin_room_rooms_computers' => 'computers_id', + ], + 'glpi_entities' => [ + 'glpi_plugin_room_rooms' => 'entities_id', + ], + 'glpi_locations' => [ + 'glpi_plugin_room_rooms' => 'locations_id', + ], + 'glpi_profiles' => [ + 'glpi_plugin_room_profiles' => 'profiles_id', + ], + 'glpi_users' => [ + 'glpi_plugin_room_rooms' => [ + 'users_id', + 'tech_num', + ], + ], + ]; + } else { + return []; + } } // Define Dropdown tables to be manage in GLPI : // Definit les tables qui sont gérables via les intitulés -function plugin_room_getDropdown() { - global $LANG; - - $plugin = new Plugin(); - - if ($plugin->isActivated("room")) - return array( - 'PluginRoomRoomType' => $LANG['plugin_room'][9], - 'PluginRoomRoomAccessCond' => $LANG['plugin_room'][5], - 'PluginRoomDropdown1' => $LANG['plugin_room']['dropdown'][2] - ); - else - return array(); +function plugin_room_getDropdown() +{ + global $LANG; + + $plugin = new Plugin(); + + if ($plugin->isActivated('room')) { + return [ + 'PluginRoomRoomType' => $LANG['plugin_room'][9], + 'PluginRoomRoomAccessCond' => $LANG['plugin_room'][5], + 'PluginRoomDropdown1' => $LANG['plugin_room']['dropdown'][2], + ]; + } else { + return []; + } } -function plugin_room_addLeftJoin($type, $ref_table, $new_table, $linkfield, &$already_link_tables) { - - // Example of standard LEFT JOIN clause but use it ONLY for specific LEFT JOIN - // No need of the function if you do not have specific cases - - switch ($new_table) { - case "glpi_computers": - $out = " LEFT JOIN glpi_plugin_room_rooms_computers ON (glpi_plugin_room_rooms.id = glpi_plugin_room_rooms_computers.rooms_id) "; - $out .= " LEFT JOIN glpi_computers ON (glpi_computers.id = glpi_plugin_room_rooms_computers.computers_id) "; - return $out; - break; - case "glpi_plugin_room_rooms": // From computers - $out = " LEFT JOIN glpi_plugin_room_rooms_computers ON (glpi_computers.id = glpi_plugin_room_rooms_computers.computers_id) "; - $out .= " LEFT JOIN glpi_plugin_room_rooms ON (glpi_plugin_room_rooms.id = glpi_plugin_room_rooms_computers.rooms_id) "; - return $out; - break; - case "glpi_plugin_room_roomtypes": // From computers - $out = Search::addLeftJoin($type, $ref_table, $already_link_tables, "glpi_plugin_room_rooms", $linkfield); - $out .= " LEFT JOIN glpi_plugin_room_roomtypes ON (glpi_plugin_room_roomtypes.id = glpi_plugin_room_rooms.type) "; - return $out; - break; - } - return ""; +function plugin_room_addLeftJoin($type, $ref_table, $new_table, $linkfield, &$already_link_tables) +{ + // Example of standard LEFT JOIN clause but use it ONLY for specific LEFT JOIN + // No need of the function if you do not have specific cases + + switch ($new_table) { + case 'glpi_computers': + $out = <<<'EOS' + LEFT JOIN glpi_plugin_room_rooms_computers + ON (glpi_plugin_room_rooms.id = glpi_plugin_room_rooms_computers.rooms_id) +EOS; + $out .= <<<'EOS' + LEFT JOIN glpi_computers + ON (glpi_computers.id = glpi_plugin_room_rooms_computers.computers_id) +EOS; + return $out; + break; + case 'glpi_plugin_room_rooms': // From computers + $out = <<<'EOS' + LEFT JOIN glpi_plugin_room_rooms_computers + ON (glpi_computers.id = glpi_plugin_room_rooms_computers.computers_id) +EOS; + $out .= <<<'EOS' + LEFT JOIN glpi_plugin_room_rooms + ON (glpi_plugin_room_rooms.id = glpi_plugin_room_rooms_computers.rooms_id) +EOS; + return $out; + break; + case 'glpi_plugin_room_roomtypes': // From computers + $out = Search::addLeftJoin($type, $ref_table, $already_link_tables, 'glpi_plugin_room_rooms', $linkfield); + $out .= <<<'EOS' + LEFT JOIN glpi_plugin_room_roomtypes + ON (glpi_plugin_room_roomtypes.id = glpi_plugin_room_rooms.type) +EOS; + return $out; + break; + } + return ''; } -function plugin_room_forceGroupBy($type) { - return true; - switch ($type) { - case 'PluginRoomRoom': - // Force add GROUP BY IN REQUEST - return true; - break; - } - return false; +function plugin_room_forceGroupBy($type) +{ + return true; + switch ($type) { + case 'PluginRoomRoom': + // Force add GROUP BY IN REQUEST + return true; + break; + } + return false; } // Define search option for types of the plugins -function plugin_room_getAddSearchOptions($itemtype) { - global $LANG; - $sopt = array(); - if ($itemtype == "Computer") { - if (PluginRoomRoom::canView()) { - $sopt[1050]['table'] = 'glpi_plugin_room_rooms'; - $sopt[1050]['field'] = 'name'; - $sopt[1050]['linkfield'] = ''; - $sopt[1050]['name'] = $LANG['plugin_room'][0] . " - " . __('Name'); - $sopt[1050]['forcegroupby'] = true; - $sopt[1050]['datatype'] = 'itemlink'; - $sopt[1050]['itemlink_type'] = 'PluginRoomRoom'; - - $sopt[1051]['table'] = 'glpi_plugin_room_roomtypes'; - $sopt[1051]['field'] = 'name'; - $sopt[1051]['linkfield'] = ''; - $sopt[1051]['name'] = $LANG['plugin_room'][0] . " - " . $LANG['plugin_room'][9]; - $sopt[1050]['forcegroupby'] = true; - } - } - return $sopt; +function plugin_room_getAddSearchOptions($itemtype) +{ + global $LANG; + $sopt = []; + if ($itemtype == 'Computer') { + if (PluginRoomRoom::canView()) { + $sopt[1050]['table'] = 'glpi_plugin_room_rooms'; + $sopt[1050]['field'] = 'name'; + $sopt[1050]['linkfield'] = ''; + $sopt[1050]['name'] = $LANG['plugin_room'][0] . ' - ' . __('Name'); + $sopt[1050]['forcegroupby'] = true; + $sopt[1050]['datatype'] = 'itemlink'; + $sopt[1050]['itemlink_type'] = 'PluginRoomRoom'; + + $sopt[1051]['table'] = 'glpi_plugin_room_roomtypes'; + $sopt[1051]['field'] = 'name'; + $sopt[1051]['linkfield'] = ''; + $sopt[1051]['name'] = $LANG['plugin_room'][0] . ' - ' . $LANG['plugin_room'][9]; + $sopt[1050]['forcegroupby'] = true; + } + } + return $sopt; } // Aucune idee de ce que cela fait // peut-etre ajouter un critère de recherche ? -function plugin_room_addSelect($type, $ID, $num) { - global $SEARCH_OPTION; - - $table = $SEARCH_OPTION[$type][$ID]["table"]; - $field = $SEARCH_OPTION[$type][$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 - switch ($table . "." . $field) { - case "glpi_computers.count": - return " COUNT( glpi_computers.ID) AS ITEM_$num, "; - break; - } - return ""; +function plugin_room_addSelect($type, $ID, $num) +{ + global $SEARCH_OPTION; + + $table = $SEARCH_OPTION[$type][$ID]['table']; + $field = $SEARCH_OPTION[$type][$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 + switch ($table . '.' . $field) { + case 'glpi_computers.count': + return ' COUNT( glpi_computers.ID) AS ITEM_$num, '; + break; + } + return ''; } // Define actions : -function plugin_room_MassiveActions($type) { - global $LANG; - switch ($type) { - case 'Computer': - return array( - "plugin_room_addComputer" => $LANG['plugin_room'][17] - ); - break; - - } - return array(); +function plugin_room_MassiveActions($type) +{ + global $LANG; + switch ($type) { + case 'Computer': + return [ + 'plugin_room_addComputer' => $LANG['plugin_room'][17], + ]; + break; + } + return []; } // How to display specific actions ? -function plugin_room_MassiveActionsDisplay($options = array()) { - global $LANG; - - $PluginRoomRoom = new PluginRoomRoom(); - switch ($options['itemtype']) { - - case 'Computer': - switch ($options['action']) { - case "plugin_room_addComputer": - Dropdown::show("PluginRoomRoom"); - echo " "; - break; - } - break; - } - return ""; +function plugin_room_MassiveActionsDisplay($options = []) +{ + global $LANG; + + $PluginRoomRoom = new PluginRoomRoom(); + switch ($options['itemtype']) { + case 'Computer': + switch ($options['action']) { + case 'plugin_room_addComputer': + Dropdown::show('PluginRoomRoom'); + echo ' '; + break; + } + break; + } + return ''; } // How to process specific actions ? -function plugin_room_MassiveActionsProcess($data) { - global $LANG; - - $PluginRoomRoom = new PluginRoomRoom(); - - switch ($data['action']) { - case 'plugin_room_addComputer': - if ($data['itemtype'] == 'Computer' && $data['plugin_room_rooms_id'] > 0) { - foreach ($data['item'] as $key => $val) { - if ($val == 1) { - $PluginRoomRoom->plugin_room_AddDevice($data['plugin_room_rooms_id'], $key); - - } +function plugin_room_MassiveActionsProcess($data) +{ + global $LANG; + + $PluginRoomRoom = new PluginRoomRoom(); + + switch ($data['action']) { + case 'plugin_room_addComputer': + if ($data['itemtype'] == 'Computer' && $data['plugin_room_rooms_id'] > 0) { + foreach ($data['item'] as $key => $val) { + if ($val == 1) { + $PluginRoomRoom->plugin_room_AddDevice($data['plugin_room_rooms_id'], $key); + } + } } - } - break; - - } + break; + } } -function plugin_room_AssignToTicket($types) { - global $LANG; +function plugin_room_AssignToTicket($types) +{ + global $LANG; - if (in_array('PluginRoomRoom', $_SESSION['glpiactiveprofile']['helpdesk_item_type'])) { - $types['PluginRoomRoom'] = $LANG['plugin_room'][0]; - } - return $types; + if (in_array('PluginRoomRoom', $_SESSION['glpiactiveprofile']['helpdesk_item_type'])) { + $types['PluginRoomRoom'] = $LANG['plugin_room'][0]; + } + return $types; } - -?> diff --git a/inc/dropdown1.class.php b/inc/dropdown1.class.php index b89a6b4..00ffa6c 100644 --- a/inc/dropdown1.class.php +++ b/inc/dropdown1.class.php @@ -1,49 +1,18 @@ \ No newline at end of file diff --git a/inc/menu.class.php b/inc/menu.class.php index ee45a61..7a8e525 100644 --- a/inc/menu.class.php +++ b/inc/menu.class.php @@ -1,59 +1,32 @@ . - * -------------------------------------------------------------------------- - * - * -------------------------------------------------------------------------- - * MOSTLY* inspired by "inc/profile.class.php" from "certificates" plugin - * -------------------------------------------------------------------------- - */ - -if (! defined('GLPI_ROOT')) { - die("Sorry. You can't access directly to this file"); + +if (!defined('GLPI_ROOT')) { + die('Sorry. You can\'t access directly to this file'); } -class PluginRoomProfile extends CommonDBTM { - - static $rightname = "profile"; - - function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - - if ($item->getType() == 'Profile') { - return PluginRoomRoom::getTypeName(2); - } - return ''; - } - - static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - global $CFG_GLPI; - - if ($item->getType() == 'Profile') { - $ID = $item->getID(); - $prof = new self(); - - self::addDefaultProfileInfos($ID, array( - 'plugin_room' => 0 - )); - $prof->showForm($ID); - } - return true; - } - - static function createFirstAccess($ID) { - self::addDefaultProfileInfos($ID, array( - 'plugin_room' => ALLSTANDARDRIGHT | READNOTE | UPDATENOTE - ), true); - } - - /** - * - * @param $profile - * - */ - static function addDefaultProfileInfos($profiles_id, $rights, $drop_existing = false) { - global $DB; - - $profileRight = new ProfileRight(); - foreach ($rights as $right => $value) { - if (countElementsInTable('glpi_profilerights', "`profiles_id`='$profiles_id' AND `name`='$right'") && $drop_existing) { - $profileRight->deleteByCriteria(array( - 'profiles_id' => $profiles_id, - 'name' => $right - )); - } - if (! countElementsInTable('glpi_profilerights', "`profiles_id`='$profiles_id' AND `name`='$right'")) { - $myright['profiles_id'] = $profiles_id; - $myright['name'] = $right; - $myright['rights'] = $value; - $profileRight->add($myright); - - // Add right to the current session - $_SESSION['glpiactiveprofile'][$right] = $value; - } - } - } - - /** - * Show profile form - * - * @param $items_id integer id of the profile - * @param $target value url of target - * - * @return nothing - * - */ - function showForm($profiles_id = 0, $openform = TRUE, $closeform = TRUE) { - - echo "
"; - if (($canedit = Session::haveRightsOr(self::$rightname, array( - CREATE, - UPDATE, - PURGE - ))) && $openform) { - $profile = new Profile(); - echo "
"; - } - - $profile = new Profile(); - $profile->getFromDB($profiles_id); - if ($profile->getField('interface') == 'central') { - $rights = $this->getAllRights(); - $profile->displayRightsChoiceMatrix($rights, array( - 'canedit' => $canedit, - 'default_class' => 'tab_bg_2', - 'title' => __('General') - )); - } - - if ($canedit && $closeform) { - echo "
"; - echo Html::hidden('id', array( - 'value' => $profiles_id - )); - echo Html::submit(_sx('button', 'Save'), array( - 'name' => 'update' - )); - echo "
\n"; - Html::closeForm(); - } - echo "
"; - } - - static function getAllRights($all = false) { - global $LANG; - $rights = array( - array( - 'itemtype' => 'PluginRoomRoom', - 'label' => $LANG['plugin_room'][0], - 'field' => 'plugin_room' - ) - ); - return $rights; - } - - /** - * Init profiles - */ - - static function translateARight($old_right) { - switch ($old_right) { - case '': - return 0; - case 'r': - return READ; - case 'w': - return ALLSTANDARDRIGHT + READNOTE + UPDATENOTE; - case '0': - case '1': - return $old_right; - - default: - return 0; - } - } - - /** - * Initialize profiles, and migrate it necessary - */ - static function initProfile() { - global $DB; - $profile = new self(); - - // Add new rights in glpi_profilerights table - foreach ($profile->getAllRights(true) as $data) { - if (countElementsInTable("glpi_profilerights", "`name` = '" . $data['field'] . "'") == 0) { - ProfileRight::addProfileRights(array( - $data['field'] - )); - } - } - - foreach ($DB->request("SELECT * - FROM `glpi_profilerights` - WHERE `profiles_id`='" . $_SESSION['glpiactiveprofile']['id'] . "' - AND `name` LIKE '%plugin_room%'") as $prof) { - $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; - } - } - - static function removeRightsFromSession() { - foreach (self::getAllRights(true) as $right) { - if (isset($_SESSION['glpiactiveprofile'][$right['field']])) { - unset($_SESSION['glpiactiveprofile'][$right['field']]); - } - } - } +class PluginRoomProfile extends CommonDBTM +{ + public static $rightname = 'profile'; + + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) + { + if ($item->getType() == 'Profile') { + return PluginRoomRoom::getTypeName(2); + } + return ''; + } + + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) + { + global $CFG_GLPI; + + if ($item->getType() == 'Profile') { + $ID = $item->getID(); + $prof = new self(); + + self::addDefaultProfileInfos($ID, [ + 'plugin_room' => 0, + ]); + $prof->showForm($ID); + } + return true; + } + + public static function createFirstAccess($ID) + { + self::addDefaultProfileInfos( + $ID, + [ + 'plugin_room' => ALLSTANDARDRIGHT | READNOTE | UPDATENOTE, + ], + true + ); + } + + /** + * @param int $profiles_id + * @param array $rights + * @param bool $drop_existing + * + * @return void + */ + public static function addDefaultProfileInfos($profiles_id, $rights, $drop_existing = false) + { + global $DB; + + $profileRight = new ProfileRight(); + foreach ($rights as $right => $value) { + $count_conditions = '`profiles_id` = ' . $profiles_id . ' AND `name` = "' . $right . '"'; + if (countElementsInTable('glpi_profilerights', $count_conditions) && $drop_existing) { + $profileRight->deleteByCriteria([ + 'profiles_id' => $profiles_id, + 'name' => $right, + ]); + } + if (!countElementsInTable('glpi_profilerights', $count_conditions)) { + $myright['profiles_id'] = $profiles_id; + $myright['name'] = $right; + $myright['rights'] = $value; + $profileRight->add($myright); + + // Add right to the current session + $_SESSION['glpiactiveprofile'][$right] = $value; + } + } + } + + /** + * Show profile form + * + * @param int $profiles_id + * @param bool $openform + * @param bool $closeform + * + * @return void + */ + public function showForm($profiles_id = 0, $openform = true, $closeform = true) + { + echo '
'; + if ( + ( + $canedit = Session::haveRightsOr( + self::$rightname, + [ + CREATE, + UPDATE, + PURGE, + ] + ) + ) + && $openform + ) { + $profile = new Profile(); + echo ''; + } + + $profile = new Profile(); + $profile->getFromDB($profiles_id); + if ($profile->getField('interface') == 'central') { + $rights = $this->getAllRights(); + $profile->displayRightsChoiceMatrix( + $rights, + [ + 'canedit' => $canedit, + 'default_class' => 'tab_bg_2', + 'title' => __('General'), + ] + ); + } + + if ($canedit && $closeform) { + echo '
'; + echo Html::hidden( + 'id', + [ + 'value' => $profiles_id, + ] + ); + echo Html::submit( + _sx('button', 'Save'), + [ + 'name' => 'update', + ] + ); + echo '
\n'; + Html::closeForm(); + } + echo '
'; + } + + public static function getAllRights($all = false) + { + global $LANG; + $rights = [ + [ + 'itemtype' => 'PluginRoomRoom', + 'label' => $LANG['plugin_room'][0], + 'field' => 'plugin_room', + ], + ]; + return $rights; + } + + /** + * Init profiles + * + * @param string $old_right + */ + public static function translateARight($old_right) + { + switch ($old_right) { + case '': + return 0; + case 'r': + return READ; + case 'w': + return ALLSTANDARDRIGHT + READNOTE + UPDATENOTE; + case '0': + case '1': + return $old_right; + default: + return 0; + } + } + + /** + * Initialize profiles, and migrate it necessary + */ + public static function initProfile() + { + global $DB; + $profile = new self(); + + // Add new rights in glpi_profilerights table + foreach ($profile->getAllRights(true) as $data) { + if (countElementsInTable('glpi_profilerights', '`name` = "' . $data['field'] . '"') == 0) { + ProfileRight::addProfileRights([ + $data['field'], + ]); + } + } + + foreach ($DB->request('SELECT * + FROM `glpi_profilerights` + WHERE `profiles_id` ' . $_SESSION['glpiactiveprofile']['id'] . ' + AND `name` LIKE "%plugin_room%"') as $prof) { + $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; + } + } + + public static function removeRightsFromSession() + { + foreach (self::getAllRights(true) as $right) { + if (isset($_SESSION['glpiactiveprofile'][$right['field']])) { + unset($_SESSION['glpiactiveprofile'][$right['field']]); + } + } + } } diff --git a/inc/room.class.php b/inc/room.class.php index 46c1464..43ee25c 100644 --- a/inc/room.class.php +++ b/inc/room.class.php @@ -1,582 +1,638 @@ getTable(); - $tab[1]['field'] = 'name'; - $tab[1]['linkfield'] = 'name'; - $tab[1]['name'] = __('Name'); - $tab[1]['datatype'] = 'itemlink'; - $tab[1]['itemlink_type'] = $this->getType(); - - $tab[2]['table'] = 'glpi_plugin_room_roomtypes'; - $tab[2]['field'] = 'name'; - $tab[2]['linkfield'] = 'type'; - $tab[2]['name'] = __('Type'); - - $tab[26]['table'] = 'glpi_groups'; - $tab[26]['field'] = 'completename'; - $tab[26]['linkfield'] = 'groups_id_tech'; - $tab[26]['name'] = __('Group in charge of the hardware'); - $tab[26]['condition'] = '`is_assign`'; - $tab[26]['datatype'] = 'dropdown'; - - $tab[24]['table'] = 'glpi_users'; - $tab[24]['field'] = 'name'; - $tab[24]['linkfield'] = 'tech_num'; - $tab[24]['name'] = __('Technician in charge of the hardware'); - - $tab[25]['table'] = 'glpi_users'; - $tab[25]['field'] = 'name'; - $tab[25]['linkfield'] = 'users_id'; - $tab[25]['name'] = __('Alternate username'); - - $tab[3]['table'] = $this->getTable(); - $tab[3]['field'] = 'comment'; - $tab[3]['linkfield'] = 'comment'; - $tab[3]['name'] = __('Comments'); - - $tab += Location::getSearchOptionsToAdd(); - - $tab[5]['table'] = $this->getTable(); - $tab[5]['field'] = 'size'; - $tab[5]['linkfield'] = 'size'; - $tab[5]['name'] = $LANG['plugin_room'][4]; - - $tab[6]['table'] = 'glpi_plugin_room_roomaccessconds'; - $tab[6]['field'] = 'name'; - $tab[6]['linkfield'] = 'access'; - $tab[6]['name'] = $LANG['plugin_room'][5]; - - $tab[7]['table'] = $this->getTable(); - $tab[7]['field'] = 'buy'; - $tab[7]['linkfield'] = 'buy'; - $tab[7]['name'] = __('Date of purchase'); - - $tab[8]['table'] = $this->getTable(); - $tab[8]['field'] = 'printer'; - $tab[8]['linkfield'] = 'printer'; - $tab[8]['name'] = $LANG['plugin_room'][6]; - - $tab[9]['table'] = $this->getTable(); - $tab[9]['field'] = 'videoprojector'; - $tab[9]['linkfield'] = 'videoprojector'; - $tab[9]['name'] = $LANG['plugin_room'][7]; - - $tab[10]['table'] = $this->getTable(); - $tab[10]['field'] = 'wifi'; - $tab[10]['linkfield'] = 'wifi'; - $tab[10]['name'] = $LANG['plugin_room'][8]; - - $tab[11]['table'] = $this->getTable(); - $tab[11]['field'] = 'comment'; - $tab[11]['linkfield'] = ''; - $tab[11]['name'] = __('Comments'); - - $tab[13]['table'] = $this->getTable(); - $tab[13]['field'] = 'opening'; - $tab[13]['linkfield'] = ''; - $tab[13]['name'] = $LANG['plugin_room'][11]; - - $tab[12]['table'] = $this->getTable(); - $tab[12]['field'] = 'limits'; - $tab[12]['linkfield'] = ''; - $tab[12]['name'] = $LANG['plugin_room'][12]; - - $tab[16]['table'] = $this->getTable(); - $tab[16]['field'] = 'text1'; - $tab[16]['linkfield'] = ''; - $tab[16]['name'] = $LANG['plugin_room'][13]; - - $tab[17]['table'] = $this->getTable(); - $tab[17]['field'] = 'text2'; - $tab[17]['linkfield'] = ''; - $tab[17]['name'] = $LANG['plugin_room'][14]; - - $tab[18]['table'] = 'glpi_plugin_room_dropdown1s'; - $tab[18]['field'] = 'name'; - $tab[18]['linkfield'] = 'dropdown1'; - $tab[18]['name'] = $LANG['plugin_room'][15]; - - $tab[19]['table'] = 'glpi_plugin_room_dropdown1s'; - $tab[19]['field'] = 'name'; - $tab[19]['linkfield'] = 'dropdown2'; - $tab[19]['name'] = $LANG['plugin_room'][16]; - - $tab[30]['table'] = $this->getTable(); - $tab[30]['field'] = 'id'; - $tab[30]['linkfield'] = ''; - $tab[30]['name'] = __('ID'); - - $tab[31]['table'] = $this->getTable(); - $tab[31]['field'] = 'name'; - $tab[31]['linkfield'] = ''; - $tab[31]['name'] = __('Computers'); - $tab[31]['forcegroupby'] = true; - $tab[31]['datatype'] = 'itemlink'; - $tab[31]['itemlink_type'] = $this->getType(); - - $tab[32]['table'] = $this->getTable(); - $tab[32]['field'] = 'count_linked'; - $tab[32]['linkfield'] = ''; - $tab[32]['name'] = $LANG['plugin_room'][18]; - $tab[32]['meta'] = 1; - - $tab[80]['table'] = 'glpi_entities'; - $tab[80]['field'] = 'completename'; - $tab[80]['linkfield'] = 'entities_id'; - $tab[80]['name'] = __('Entity'); - return $tab; - } - - // Cette fonction définie les onglets à afficher sur la fiche de l'objet - // Cette fonction retourne un tableau [id de l'onglet->titre onglet] - function defineTabs($options = array()) { - $ong = array(); - - $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); - $this->addStandardTab('Log', $ong, $options); - - return $ong; - } - - // 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) - function showForm($ID, $options = array()) { - global $CFG_GLPI, $LANG; - - if (! self::canView()) - return false; - - if (! $this->canView()) - return false; - - // Si la salle éxiste - if ($ID > 0) { - $this->check($ID, READ); - } else { // C'est une nouvelle salle - $this->check(- 1, CREATE); - $this->getEmpty(); - } - - // entete du formulaire avec affichage du type d'objet, de l'entite et de la recursivite - // au niveau affichage la première ligne du tableau - $this->showFormHeader($options); - - // Composition du formulaire de l'objet salle - // seconde ligne du tableau - echo ""; - if ($ID > 0) { // La salle éxiste déjà - // affichage de la derniere modif - echo "" . __('Last update') . ": " . Html::convDateTime($this->fields["date_mod"]) . ""; - } else { // C'est une nouvelle salle - echo " "; - } - echo ""; - - // Reste du tableau - // Nom de la salle - echo "" . __('Name') . ": "; - echo ""; - Html::autocompletionTextField($this, 'name'); - echo ""; - echo "" . __('Location') . ": "; - echo ""; - Dropdown::show('Location', array( - 'value' => $this->fields["locations_id"], - 'entity' => $this->fields["entities_id"] - )); - echo ""; - - // Dropdown du type - echo "" . __('Type') . ": "; - echo ""; - Dropdown::show('PluginRoomRoomType', array( - 'name' => "type", - 'value' => $this->fields["type"] - )); - echo ""; - - // Dropdown des Conditions d'accès - echo "" . $LANG['plugin_room'][5] . ": "; - echo ""; - Dropdown::show('PluginRoomRoomAccessCond', array( - 'name' => "access", - 'value' => $this->fields["access"] - )); - echo ""; - - // Dropdown de l'usager - echo "" . __('Alternate username') . ": "; - echo ""; - User::Dropdown(array( - 'name' => "users_id", - 'value' => $this->fields["users_id"], - 'entity' => $this->fields["entities_id"], - 'right' => 'all' - )); - echo ""; - - // Dropdown du Responsable technique - echo "" . __('Technician in charge of the hardware') . ": "; - echo ""; - User::Dropdown(array( - 'name' => "tech_num", - 'value' => $this->fields["tech_num"], - 'entity' => $this->fields["entities_id"], - 'right' => 'interface' - )); - echo ""; - - // Nombres de place - echo "" . $LANG['plugin_room'][4] . ": "; - echo ""; - Dropdown::showNumber("size", - [ - 'value' => $this->fields["size"], - 'min' => 0, - 'max' => 500, - ] - ); - echo ""; - - // Dropdown du Groupe responsable technique - echo '' . __('Group in charge of the hardware') . ''; - Group::dropdown([ - 'name' => 'groups_id_tech', - 'value' => $this->fields['groups_id_tech'], - 'entity' => $this->fields['entities_id'], - 'condition' => '`is_assign`' - ]); - echo ''; - - // Date d'achat - echo "" . __('Date of purchase') . ": "; - echo ""; - Html::showDateField("buy", - [ - 'value' => $this->fields["buy"], - 'maybeempty' => true, - 'canedit' => true, - ] - ); - echo ""; - - // Moyen d'impression - echo "" . $LANG['plugin_room'][6] . ": "; - echo ""; - Dropdown::showYesNo("printer", $this->fields["printer"]); - echo ""; - - // Videoprojecteur - echo "" . $LANG['plugin_room'][7] . ": "; - echo ""; - Dropdown::showYesNo("videoprojector", $this->fields["videoprojector"]); - echo ""; - - // wifi - echo "" . $LANG['plugin_room'][8] . ": "; - echo ""; - Dropdown::showYesNo("wifi", $this->fields["wifi"]); - echo ""; - - // Spécificité 1 - echo "" . $LANG['plugin_room'][13] . ": "; - echo ""; - Html::autocompletionTextField($this, 'text1'); - echo ""; - - // Spécificité 3 - echo "" . $LANG['plugin_room'][15] . ": "; - echo ""; - Dropdown::show("PluginRoomDropdown1", array( - 'name' => "dropdown1", - 'value' => $this->fields["dropdown1"] - )); - echo ""; - - // Spécificité 2 - echo "" . $LANG['plugin_room'][14] . ": "; - echo ""; - Html::autocompletionTextField($this, 'text2'); - echo ""; - - // Spécificité 4 - echo "" . $LANG['plugin_room'][16] . ": "; - echo ""; - Dropdown::show("PluginRoomDropdown1", array( - 'name' => "dropdown2", - 'value' => $this->fields["dropdown2"] - )); - echo ""; - - // Horaires d'ouverture - echo "" . $LANG['plugin_room'][11] . ": "; - echo ""; - Html::autocompletionTextField($this, 'opening'); - echo ""; - - // limitations - echo "" . $LANG['plugin_room'][12] . ": "; - echo ""; - Html::autocompletionTextField($this, 'limits'); - echo ""; - - // Commentaires - echo ""; - echo ""; - echo __('Comments') . ":"; - echo ""; - echo ""; - echo ""; - - // Affichage des boutons - $this->showFormButtons($options); - - return true; - - } - - // cette fonction doit servir à remplir la rubrique ordinateur de la fiche room - function showComputers($target, $room_id) { - global $CFG_GLPI, $LANG, $DB; - - if (! self::canView()) - return false; - - if ($this->getFromDB($room_id)) { - $canedit = $this->can($room_id, UPDATE); - - $query = "SELECT glpi_computers.*, glpi_plugin_room_rooms_computers.id AS idd, glpi_entities.id AS entity " . " FROM glpi_plugin_room_rooms_computers, glpi_computers " . " LEFT JOIN glpi_entities ON (glpi_entities.id=glpi_computers.entities_id) " . " WHERE glpi_computers.id = glpi_plugin_room_rooms_computers.computers_id AND glpi_plugin_room_rooms_computers.rooms_id = '$room_id' "; - - $query .= " ORDER BY glpi_entities.completename, glpi_computers.name"; - - echo ""; - - echo "

"; - echo ""; - if ($canedit) { - echo ""; - } - echo ""; - echo ""; - echo ""; - - if ($result_linked = $DB->query($query)) { - if ($DB->numrows($result_linked)) { - while ($data = $DB->fetch_assoc($result_linked)) { - $ID = ""; - - if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { - $ID = " (" . $data["id"] . ")"; - } - $name = "" . $data["name"] . "$ID"; - - echo ""; - - if ($canedit) { - echo ""; - } - - echo ""; - echo ""; - - echo ""; - } +class PluginRoomRoom extends CommonDBTM +{ + public $dohistory = true; + + public static $rightname = 'plugin_room'; + + protected $usenotepad = true; + + public static function getTypeName($nb = 0) + { + global $LANG; + + return $LANG['plugin_room'][0]; + } + + public function prepareInputForUpdate($input) + { + // Backup initial values + if (isset($input['buy']) && empty($input['buy'])) { + $input['buy'] = 'NULL'; + } + + return $input; + } + + public function prepareInputForAdd($input) + { + // Backup initial values + if (isset($input['buy']) && empty($input['buy'])) { + unset($input['buy']); + } + + return $input; + } + + // Cette fonction propose des critères de filtrage pour la page des salles + public function getSearchOptions() + { + global $LANG; + + $tab = []; + + $tab['common'] = $LANG['plugin_room'][0]; + + $tab[1]['table'] = $this->getTable(); + $tab[1]['field'] = 'name'; + $tab[1]['linkfield'] = 'name'; + $tab[1]['name'] = __('Name'); + $tab[1]['datatype'] = 'itemlink'; + $tab[1]['itemlink_type'] = $this->getType(); + + $tab[2]['table'] = 'glpi_plugin_room_roomtypes'; + $tab[2]['field'] = 'name'; + $tab[2]['linkfield'] = 'type'; + $tab[2]['name'] = __('Type'); + + $tab[26]['table'] = 'glpi_groups'; + $tab[26]['field'] = 'completename'; + $tab[26]['linkfield'] = 'groups_id_tech'; + $tab[26]['name'] = __('Group in charge of the hardware'); + $tab[26]['condition'] = '`is_assign`'; + $tab[26]['datatype'] = 'dropdown'; + + $tab[24]['table'] = 'glpi_users'; + $tab[24]['field'] = 'name'; + $tab[24]['linkfield'] = 'tech_num'; + $tab[24]['name'] = __('Technician in charge of the hardware'); + + $tab[25]['table'] = 'glpi_users'; + $tab[25]['field'] = 'name'; + $tab[25]['linkfield'] = 'users_id'; + $tab[25]['name'] = __('Alternate username'); + + $tab[3]['table'] = $this->getTable(); + $tab[3]['field'] = 'comment'; + $tab[3]['linkfield'] = 'comment'; + $tab[3]['name'] = __('Comments'); + + $tab += Location::getSearchOptionsToAdd(); + + $tab[5]['table'] = $this->getTable(); + $tab[5]['field'] = 'size'; + $tab[5]['linkfield'] = 'size'; + $tab[5]['name'] = $LANG['plugin_room'][4]; + + $tab[6]['table'] = 'glpi_plugin_room_roomaccessconds'; + $tab[6]['field'] = 'name'; + $tab[6]['linkfield'] = 'access'; + $tab[6]['name'] = $LANG['plugin_room'][5]; + + $tab[7]['table'] = $this->getTable(); + $tab[7]['field'] = 'buy'; + $tab[7]['linkfield'] = 'buy'; + $tab[7]['name'] = __('Date of purchase'); + + $tab[8]['table'] = $this->getTable(); + $tab[8]['field'] = 'printer'; + $tab[8]['linkfield'] = 'printer'; + $tab[8]['name'] = $LANG['plugin_room'][6]; + + $tab[9]['table'] = $this->getTable(); + $tab[9]['field'] = 'videoprojector'; + $tab[9]['linkfield'] = 'videoprojector'; + $tab[9]['name'] = $LANG['plugin_room'][7]; + + $tab[10]['table'] = $this->getTable(); + $tab[10]['field'] = 'wifi'; + $tab[10]['linkfield'] = 'wifi'; + $tab[10]['name'] = $LANG['plugin_room'][8]; + + $tab[11]['table'] = $this->getTable(); + $tab[11]['field'] = 'comment'; + $tab[11]['linkfield'] = ''; + $tab[11]['name'] = __('Comments'); + + $tab[13]['table'] = $this->getTable(); + $tab[13]['field'] = 'opening'; + $tab[13]['linkfield'] = ''; + $tab[13]['name'] = $LANG['plugin_room'][11]; + + $tab[12]['table'] = $this->getTable(); + $tab[12]['field'] = 'limits'; + $tab[12]['linkfield'] = ''; + $tab[12]['name'] = $LANG['plugin_room'][12]; + + $tab[16]['table'] = $this->getTable(); + $tab[16]['field'] = 'text1'; + $tab[16]['linkfield'] = ''; + $tab[16]['name'] = $LANG['plugin_room'][13]; + + $tab[17]['table'] = $this->getTable(); + $tab[17]['field'] = 'text2'; + $tab[17]['linkfield'] = ''; + $tab[17]['name'] = $LANG['plugin_room'][14]; + + $tab[18]['table'] = 'glpi_plugin_room_dropdown1s'; + $tab[18]['field'] = 'name'; + $tab[18]['linkfield'] = 'dropdown1'; + $tab[18]['name'] = $LANG['plugin_room'][15]; + + $tab[19]['table'] = 'glpi_plugin_room_dropdown1s'; + $tab[19]['field'] = 'name'; + $tab[19]['linkfield'] = 'dropdown2'; + $tab[19]['name'] = $LANG['plugin_room'][16]; + + $tab[30]['table'] = $this->getTable(); + $tab[30]['field'] = 'id'; + $tab[30]['linkfield'] = ''; + $tab[30]['name'] = __('ID'); + + $tab[31]['table'] = $this->getTable(); + $tab[31]['field'] = 'name'; + $tab[31]['linkfield'] = ''; + $tab[31]['name'] = __('Computers'); + $tab[31]['forcegroupby'] = true; + $tab[31]['datatype'] = 'itemlink'; + $tab[31]['itemlink_type'] = $this->getType(); + + $tab[32]['table'] = $this->getTable(); + $tab[32]['field'] = 'count_linked'; + $tab[32]['linkfield'] = ''; + $tab[32]['name'] = $LANG['plugin_room'][18]; + $tab[32]['meta'] = 1; + + $tab[80]['table'] = 'glpi_entities'; + $tab[80]['field'] = 'completename'; + $tab[80]['linkfield'] = 'entities_id'; + $tab[80]['name'] = __('Entity'); + return $tab; + } + + // Cette fonction définie les onglets à afficher sur la fiche de l'objet + // Cette fonction retourne un tableau [id de l'onglet->titre onglet] + 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); + $this->addStandardTab('Log', $ong, $options); + + return $ong; + } + + // 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 = []) + { + global $CFG_GLPI, $LANG; + + if (!self::canView()) { + return false; + } + + if (!$this->canView()) { + return false; + } + + // Si la salle éxiste + if ($ID > 0) { + $this->check($ID, READ); + } else { // C'est une nouvelle salle + $this->check(-1, CREATE); + $this->getEmpty(); + } + + // entete du formulaire avec affichage du type d'objet, de l'entite et de la recursivite + // au niveau affichage la première ligne du tableau + $this->showFormHeader($options); + + // Composition du formulaire de l'objet salle + // seconde ligne du tableau + echo ''; + if ($ID > 0) { // La salle éxiste déjà : affichage de la derniere modif + echo ''; + } else { // C'est une nouvelle salle + echo ''; + } + echo ''; + + // Reste du tableau + // Nom de la salle + echo ''; + echo ''; + echo ''; + echo ''; + + // Dropdown du type + echo ''; + echo ''; + + // Dropdown des Conditions d'accès + echo ''; + echo ''; + + // Dropdown de l'usager + echo ''; + echo ''; + + // Dropdown du Responsable technique + echo ''; + echo ''; + + // Nombres de place + echo ''; + echo ''; + + // Dropdown du Groupe responsable technique + echo ''; + + // Date d'achat + echo ''; + echo ''; + + // Moyen d'impression + echo ''; + echo ''; + + // Videoprojecteur + echo ''; + echo ''; + + // wifi + echo ''; + echo ''; + + // Spécificité 1 + echo ''; + echo ''; + + // Spécificité 3 + echo ''; + echo ''; + + // Spécificité 2 + echo ''; + echo ''; + + // Spécificité 4 + echo ''; + echo ''; + + // Horaires d'ouverture + echo ''; + echo ''; + + // limitations + echo ''; + echo ''; + + // Commentaires + echo ''; + echo ''; + echo ''; + echo ''; + + // Affichage des boutons + $this->showFormButtons($options); + + return true; + } + + // cette fonction doit servir à remplir la rubrique ordinateur de la fiche room + public function showComputers($target, $room_id) + { + global $CFG_GLPI, $LANG, $DB; + + if (!self::canView()) { + return false; + } + + if ($this->getFromDB($room_id)) { + $canedit = $this->can($room_id, UPDATE); + + $query = <<'; + + echo '

" . __('Associated items') . ":
 " . __('Name') . "" . __('Select the desired entity') . "
"; - $sel = ""; - if (isset($_GET["select"]) && $_GET["select"] == "all") - $sel = "checked"; - echo ""; - echo "" . $name . "" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "
' . __('Last update') . ': ' . Html::convDateTime($this->fields['date_mod']) . ' 
' . __('Name') . ': '; + Html::autocompletionTextField($this, 'name'); + echo '' . __('Location') . ': '; + Dropdown::show( + 'Location', + [ + 'value' => $this->fields['locations_id'], + 'entity' => $this->fields['entities_id'], + ] + ); + echo '
' . __('Type') . ': '; + Dropdown::show( + 'PluginRoomRoomType', + [ + 'name' => 'type', + 'value' => $this->fields['type'], + ] + ); + echo '' . $LANG['plugin_room'][5] . ': '; + Dropdown::show( + 'PluginRoomRoomAccessCond', + [ + 'name' => 'access', + 'value' => $this->fields['access'], + ] + ); + echo '
' . __('Alternate username') . ': '; + User::Dropdown([ + 'name' => 'users_id', + 'value' => $this->fields['users_id'], + 'entity' => $this->fields['entities_id'], + 'right' => 'all', + ]); + echo '' . __('Technician in charge of the hardware') . ': '; + User::Dropdown([ + 'name' => 'tech_num', + 'value' => $this->fields['tech_num'], + 'entity' => $this->fields['entities_id'], + 'right' => 'interface', + ]); + echo '
' . $LANG['plugin_room'][4] . ': '; + Dropdown::showNumber( + 'size', + [ + 'value' => $this->fields['size'], + 'min' => 0, + 'max' => 500, + ] + ); + echo '' . __('Group in charge of the hardware') . ''; + Group::dropdown([ + 'name' => 'groups_id_tech', + 'value' => $this->fields['groups_id_tech'], + 'entity' => $this->fields['entities_id'], + 'condition' => '`is_assign`', + ]); + echo '
' . __('Date of purchase') . ': '; + Html::showDateField( + 'buy', + [ + 'value' => $this->fields['buy'], + 'maybeempty' => true, + 'canedit' => true, + ] + ); + echo '' . $LANG['plugin_room'][6] . ': '; + Dropdown::showYesNo('printer', $this->fields['printer']); + echo '
' . $LANG['plugin_room'][7] . ': '; + Dropdown::showYesNo('videoprojector', $this->fields['videoprojector']); + echo '' . $LANG['plugin_room'][8] . ': '; + Dropdown::showYesNo('wifi', $this->fields['wifi']); + echo '
' . $LANG['plugin_room'][13] . ': '; + Html::autocompletionTextField($this, 'text1'); + echo '' . $LANG['plugin_room'][15] . ': '; + Dropdown::show( + 'PluginRoomDropdown1', + [ + 'name' => 'dropdown1', + 'value' => $this->fields['dropdown1'], + ] + ); + echo '
' . $LANG['plugin_room'][14] . ': '; + Html::autocompletionTextField($this, 'text2'); + echo '' . $LANG['plugin_room'][16] . ': '; + Dropdown::show( + 'PluginRoomDropdown1', + [ + 'name' => 'dropdown2', + 'value' => $this->fields['dropdown2'], + ] + ); + echo '
' . $LANG['plugin_room'][11] . ': '; + Html::autocompletionTextField($this, 'opening'); + echo '
' . $LANG['plugin_room'][12] . ': '; + Html::autocompletionTextField($this, 'limits'); + echo '
'; + echo __('Comments') . ':'; + echo ''; + echo '
'; + echo ''; + if ($canedit) { + echo ''; } - } - - if ($canedit) { - echo ""; - echo ""; - echo "
' . __('Associated items') . ':
 
"; - - echo ""; - Dropdown::show("Computer"); - echo ""; - echo ""; - echo "
"; - - echo "
"; - echo ""; - echo ""; - - echo ""; - echo "
" . __('Check All') . "/" . __('Uncheck All') . ""; - echo ""; - echo ""; - echo "
"; - - } else { - - echo ""; - } - - Html::closeForm(); - } - - } - - // cette fonction sert à remplir la rubrique room de l'onglet ajouté à la fiche ordinateur - function plugin_room_showComputerRoom($itemtype, $ID, $withtemplate = '') { - global $DB, $LANG, $CFG_GLPI; - - $item = new $itemtype(); - $canread = $item->can($ID, READ); - $canedit = $item->can($ID, UPDATE); - - $Room = new self(); - - if ($ID > 0) { - $query = "SELECT `glpi_plugin_room_rooms`.*, u.`id` as resp_id, CONCAT(u.`firstname` , ' ', u.`realname`) as resp " . "FROM `glpi_plugin_room_rooms_computers` " . " LEFT JOIN `glpi_plugin_room_rooms` ON (`glpi_plugin_room_rooms`.`id` = `glpi_plugin_room_rooms_computers`.`rooms_id`) " . " LEFT JOIN `glpi_users` as u on u.`id` = `glpi_plugin_room_rooms`.`tech_num` " . "WHERE `computers_id` = '$ID' "; - $result = $DB->query($query); - $number = $DB->numrows($result); - if (Session::isMultiEntitiesMode()) { - $colsup = 1; - } else { - $colsup = 0; - } - echo "
"; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } else { - echo $data['name']; - } - echo ""; + echo ''; + echo ''; + echo ''; + + if ($result_linked = $DB->query($query)) { + if ($DB->numrows($result_linked)) { + while ($data = $DB->fetch_assoc($result_linked)) { + $ID = ''; + + if ($_SESSION['glpiis_ids_visible'] || empty($data['name'])) { + $ID = ' (' . $data['id'] . ')'; + } + $name = + '' + . $data['name'] . $ID . ''; + + echo ''; + + if ($canedit) { + echo ''; + } + + echo + '' + . $name + . ''; + echo + ''; + + echo ''; + } + } } - } - echo "
" . $LANG['plugin_room'][20] . "
" . $LANG['plugin_room'][19] . "" . $LANG['plugin_room'][10] . "
"; - if ($result = $DB->query($query)) { - if ($DB->numrows($result) > 0) { - $data = $DB->fetch_assoc($result); - - if (self::canView()) { - echo "" . $data['name'] . ""; - echo "" . $data['resp'] . "' . __('Name') . '' . __('Select the desired entity') . '
'; + $sel = ''; + if (isset($_GET['select']) && $_GET['select'] == 'all') { + $sel = 'checked'; + } + echo ''; + echo '' + . Dropdown::getDropdownName('glpi_entities', $data['entity']) + . '
"; - } - - } - - function plugin_room_AddDevice($room_id, $computer_id) { - global $DB; - if ($room_id > 0 && $computer_id > 0) { - $query = "SELECT ID FROM glpi_plugin_room_rooms_computers WHERE computers_id='$computer_id'"; - if ($result = $DB->query($query)) { - if ($DB->numrows($result) == 0) { - $query = "INSERT INTO glpi_plugin_room_rooms_computers (rooms_id, computers_id) VALUES ('$room_id','$computer_id');"; - $result = $DB->query($query); - $this->plugin_room_updateCountDevices($room_id); + + if ($canedit) { + echo ''; + + echo ''; + Dropdown::show('Computer'); + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; + + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + echo '
' + . '' + . __('Check All') . ''; + echo '/' + . '' + . __('Uncheck All') . ''; + echo ''; + echo ''; + echo '
'; + } else { + echo ''; + } + + Html::closeForm(); + } + } + + // cette fonction sert à remplir la rubrique room de l'onglet ajouté à la fiche ordinateur + public function plugin_room_showComputerRoom($itemtype, $ID, $withtemplate = '') + { + global $DB, $LANG, $CFG_GLPI; + + $item = new $itemtype(); + $canread = $item->can($ID, READ); + $canedit = $item->can($ID, UPDATE); + + $Room = new self(); + + if ($ID > 0) { + $query = <<query($query); + $number = $DB->numrows($result); + if (Session::isMultiEntitiesMode()) { + $colsup = 1; + } else { + $colsup = 0; + } + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } else { + echo $data['name']; + } + echo ''; + } + } + echo '
' . $LANG['plugin_room'][20] . '
' . $LANG['plugin_room'][19] . '' . $LANG['plugin_room'][10] . '
'; + if ($result = $DB->query($query)) { + if ($DB->numrows($result) > 0) { + $data = $DB->fetch_assoc($result); + + if (self::canView()) { + echo '' + . $data['name'] . ''; + echo '' + . '' + . $data['resp'] . '
'; + } + } + + public function plugin_room_AddDevice($room_id, $computer_id) + { + global $DB; + if ($room_id > 0 && $computer_id > 0) { + $query = 'SELECT ID FROM glpi_plugin_room_rooms_computers WHERE computers_id = ' . $computer_id; + if ($result = $DB->query($query)) { + if ($DB->numrows($result) == 0) { + $query = <<query($query); + $this->plugin_room_updateCountDevices($room_id); + } } - } - } - } - - function plugin_room_DeleteDevice($ID) { - global $DB; - $query = "SELECT rooms_id FROM glpi_plugin_room_rooms_computers WHERE ID='$ID'"; - if ($result = $DB->query($query)) { - $IDroom = $DB->result($result, 0, 0); - $query = "DELETE FROM glpi_plugin_room_rooms_computers WHERE ID= '$ID';"; - $result = $DB->query($query); - $this->plugin_room_updateCountDevices($IDroom); - } - } - - function plugin_room_updateCountDevices($ID) { - global $DB; - $query = "SELECT count(ID) FROM glpi_plugin_room_rooms_computers WHERE rooms_id='$ID'"; - if ($result = $DB->query($query)) { - $query2 = "UPDATE glpi_plugin_room_rooms SET count_linked='" . $DB->result($result, 0, 0) . "' WHERE ID='$ID'"; - $DB->query($query2); - } - } + } + } + + public function plugin_room_DeleteDevice($ID) + { + global $DB; + $query = 'SELECT rooms_id FROM glpi_plugin_room_rooms_computers WHERE ID = ' . $ID; + if ($result = $DB->query($query)) { + $IDroom = $DB->result($result, 0, 0); + $query = 'DELETE FROM glpi_plugin_room_rooms_computers WHERE ID = ' . $ID; + $result = $DB->query($query); + $this->plugin_room_updateCountDevices($IDroom); + } + } + + public function plugin_room_updateCountDevices($ID) + { + global $DB; + $query = 'SELECT count(ID) FROM glpi_plugin_room_rooms_computers WHERE rooms_id = ' . $ID; + if ($result = $DB->query($query)) { + $query2 = <<result($result, 0, 0)} + WHERE ID = {$ID} +EOS; + $DB->query($query2); + } + } } -?> \ No newline at end of file diff --git a/inc/room_computer.class.php b/inc/room_computer.class.php index 4d9340f..be9dd56 100644 --- a/inc/room_computer.class.php +++ b/inc/room_computer.class.php @@ -1,52 +1,20 @@ . - * -------------------------------------------------------------------------- - */ -// ---------------------------------------------------------------------- -// Original Author of file: Julien Dombre -// Purpose of file: -// ---------------------------------------------------------------------- - -if (! defined('GLPI_ROOT')) { - die("Sorry. You can't access directly to this file"); +if (!defined('GLPI_ROOT')) { + die('Sorry. You can\'t access directly to this file'); } // / Group_User class - Relation between Group and User -class PluginRoomRoom_Computer extends CommonDBRelation { - - // From CommonDBRelation - public static $itemtype_1 = 'PluginRoomRoom'; +class PluginRoomRoom_Computer extends CommonDBRelation +{ + // From CommonDBRelation + public static $itemtype_1 = 'PluginRoomRoom'; - public static $items_id_1 = 'rooms_id'; + public static $items_id_1 = 'rooms_id'; - public static $itemtype_2 = 'Computer'; + public static $itemtype_2 = 'Computer'; - public static $items_id_2 = 'computers_id'; + public static $items_id_2 = 'computers_id'; - public $checks_and_logs_only_for_itemtype1 = true; - -} \ No newline at end of file + public $checks_and_logs_only_for_itemtype1 = true; +} diff --git a/inc/roomaccesscond.class.php b/inc/roomaccesscond.class.php index 5244dbc..d897607 100755 --- a/inc/roomaccesscond.class.php +++ b/inc/roomaccesscond.class.php @@ -1,50 +1,18 @@ \ No newline at end of file diff --git a/inc/roomtype.class.php b/inc/roomtype.class.php index 1012993..eac838d 100644 --- a/inc/roomtype.class.php +++ b/inc/roomtype.class.php @@ -1,49 +1,18 @@ \ No newline at end of file diff --git a/index.php b/index.php index fa45a7c..95c5fc7 100644 --- a/index.php +++ b/index.php @@ -1,48 +1,15 @@ diff --git a/locales/de_DE.php b/locales/de_DE.php index 1e22749..a878808 100644 --- a/locales/de_DE.php +++ b/locales/de_DE.php @@ -1,58 +1,29 @@ +$LANG['plugin_room']['dropdown'][0] = 'Art des Raumes'; +$LANG['plugin_room']['dropdown'][2] = 'Room specificities'; diff --git a/locales/en_GB.php b/locales/en_GB.php index fa0317b..dbe9b09 100644 --- a/locales/en_GB.php +++ b/locales/en_GB.php @@ -1,58 +1,29 @@ \ No newline at end of file +$LANG['plugin_room']['dropdown'][0] = 'Room type'; +$LANG['plugin_room']['dropdown'][2] = 'Room specificities'; diff --git a/locales/fr_FR.php b/locales/fr_FR.php index c82205a..b11f716 100644 --- a/locales/fr_FR.php +++ b/locales/fr_FR.php @@ -1,58 +1,29 @@ \ No newline at end of file +$LANG['plugin_room']['dropdown'][0] = 'Type de Salle'; +$LANG['plugin_room']['dropdown'][2] = 'Spécificités de salle'; diff --git a/locales/it_IT.php b/locales/it_IT.php index 0e67941..95eee86 100644 --- a/locales/it_IT.php +++ b/locales/it_IT.php @@ -1,58 +1,29 @@ \ No newline at end of file +$LANG['plugin_room']['dropdown'][0] = 'Tipologia di Locale'; +$LANG['plugin_room']['dropdown'][2] = 'Caratteristica di Locale'; diff --git a/locales/pt_PT.php b/locales/pt_PT.php index 01e7bf6..75444ff 100644 --- a/locales/pt_PT.php +++ b/locales/pt_PT.php @@ -1,58 +1,29 @@ +$LANG['plugin_room']['dropdown'][0] = 'Tipo de Salas'; +$LANG['plugin_room']['dropdown'][2] = 'Especificações da Sala'; diff --git a/setup.php b/setup.php index 32f1609..61876c7 100644 --- a/setup.php +++ b/setup.php @@ -1,99 +1,71 @@ true, - 'ticket_types' => true, - 'linkgroup_tech_types' => true, - )); + // Déclaration d'un nouvel objet d'inventaire Room + Plugin::registerClass('PluginRoomRoom', [ + 'reservation_types' => true, + 'ticket_types' => true, + 'linkgroup_tech_types' => true, + ]); - Plugin::registerClass('PluginRoomProfile', array( - 'addtabon' => 'Profile' - )); + Plugin::registerClass('PluginRoomProfile', [ + 'addtabon' => 'Profile', + ]); - if (Session::getLoginUserID()) { - $PLUGIN_HOOKS['menu_toadd']['room'] = array( - 'assets' => 'PluginRoomMenu' - ); - } + if (Session::getLoginUserID()) { + $PLUGIN_HOOKS['menu_toadd']['room'] = [ + 'assets' => 'PluginRoomMenu', + ]; + } } // Get the name and the version of the plugin - Needed -function plugin_version_room() { - global $LANG; - - return array( - 'name' => $LANG['plugin_room'][0], - 'version' => PLUGIN_ROOM_VERSION, - 'license' => 'GPLv2+', - 'author' => 'Julien Dombre / Modif bogucool, Pascal Marier-Dionne et Claude Duvergier', - 'homepage' => 'https://github.com/pluginsGLPI/room', - 'minGlpiVersion' => '9.2' - ); +function plugin_version_room() +{ + global $LANG; + return [ + 'name' => $LANG['plugin_room'][0], + 'version' => PLUGIN_ROOM_VERSION, + 'license' => 'GPLv2+', + 'author' => 'Julien Dombre / Modif bogucool, Pascal Marier-Dionne et Claude Duvergier', + 'homepage' => 'https://github.com/pluginsGLPI/room', + 'minGlpiVersion' => '9.2', + ]; } // Optional : check prerequisites before install : may print errors or add to message after redirect -function plugin_room_check_prerequisites() { - if (version_compare(GLPI_VERSION, '9.2', '>=') && version_compare(GLPI_VERSION, '9.3', '<')) { - return true; - } else { - _e('This plugin requires GLPI >= 9.2 && < 9.3', 'room'); - return false; - } +function plugin_room_check_prerequisites() +{ + if (version_compare(GLPI_VERSION, '9.2', '>=') && version_compare(GLPI_VERSION, '9.3', '<')) { + return true; + } else { + _e('This plugin requires GLPI >= 9.2 && < 9.3', 'room'); + return false; + } } -// Incertain de ce que devrais vérifier cette méthode; je n'y touche donc pas / unsure as to what this function should check for; i wont modify it -function plugin_room_check_config() { - return true; +// Incertain de ce que devrais vérifier cette méthode; je n'y touche donc pas +// unsure as to what this function should check for; i wont modify it +function plugin_room_check_config() +{ + return true; } -?> From 576b9e0c8a697758d597a8f5aebf91a6fc1c23b5 Mon Sep 17 00:00:00 2001 From: C-Duv <1466273+C-Duv@users.noreply.github.com> Date: Thu, 11 Oct 2018 01:59:52 +0200 Subject: [PATCH 4/6] Makes compatible with GLPI 9.3 search engine With GLPI v9.3 (and v9.3.1), changes were made in the GLPI API, some methods where deprecated/renamed (eg. CommonDBTM::getSearchOptions(), Location::getSearchOptionsToAdd()), other changed their expectations about arguments (eg. countElementsInTable()). This commit makes the code complies with theses changes. Issue: #31 --- inc/profile.class.php | 4 +- inc/room.class.php | 327 ++++++++++++++++++++++++++---------------- setup.php | 4 +- 3 files changed, 204 insertions(+), 131 deletions(-) diff --git a/inc/profile.class.php b/inc/profile.class.php index f90de36..5ac2765 100755 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -56,7 +56,7 @@ public static function addDefaultProfileInfos($profiles_id, $rights, $drop_exist $profileRight = new ProfileRight(); foreach ($rights as $right => $value) { - $count_conditions = '`profiles_id` = ' . $profiles_id . ' AND `name` = "' . $right . '"'; + $count_conditions = ['WHERE' => '`profiles_id` = ' . $profiles_id . ' AND `name` = "' . $right . '"']; if (countElementsInTable('glpi_profilerights', $count_conditions) && $drop_existing) { $profileRight->deleteByCriteria([ 'profiles_id' => $profiles_id, @@ -183,7 +183,7 @@ public static function initProfile() // Add new rights in glpi_profilerights table foreach ($profile->getAllRights(true) as $data) { - if (countElementsInTable('glpi_profilerights', '`name` = "' . $data['field'] . '"') == 0) { + if (countElementsInTable('glpi_profilerights', ['WHERE' => '`name` = "' . $data['field'] . '"']) == 0) { ProfileRight::addProfileRights([ $data['field'], ]); diff --git a/inc/room.class.php b/inc/room.class.php index 43ee25c..c1b2944 100644 --- a/inc/room.class.php +++ b/inc/room.class.php @@ -36,138 +36,211 @@ public function prepareInputForAdd($input) } // Cette fonction propose des critères de filtrage pour la page des salles - public function getSearchOptions() + public function rawSearchOptions() { global $LANG; $tab = []; - $tab['common'] = $LANG['plugin_room'][0]; - - $tab[1]['table'] = $this->getTable(); - $tab[1]['field'] = 'name'; - $tab[1]['linkfield'] = 'name'; - $tab[1]['name'] = __('Name'); - $tab[1]['datatype'] = 'itemlink'; - $tab[1]['itemlink_type'] = $this->getType(); - - $tab[2]['table'] = 'glpi_plugin_room_roomtypes'; - $tab[2]['field'] = 'name'; - $tab[2]['linkfield'] = 'type'; - $tab[2]['name'] = __('Type'); - - $tab[26]['table'] = 'glpi_groups'; - $tab[26]['field'] = 'completename'; - $tab[26]['linkfield'] = 'groups_id_tech'; - $tab[26]['name'] = __('Group in charge of the hardware'); - $tab[26]['condition'] = '`is_assign`'; - $tab[26]['datatype'] = 'dropdown'; - - $tab[24]['table'] = 'glpi_users'; - $tab[24]['field'] = 'name'; - $tab[24]['linkfield'] = 'tech_num'; - $tab[24]['name'] = __('Technician in charge of the hardware'); - - $tab[25]['table'] = 'glpi_users'; - $tab[25]['field'] = 'name'; - $tab[25]['linkfield'] = 'users_id'; - $tab[25]['name'] = __('Alternate username'); - - $tab[3]['table'] = $this->getTable(); - $tab[3]['field'] = 'comment'; - $tab[3]['linkfield'] = 'comment'; - $tab[3]['name'] = __('Comments'); - - $tab += Location::getSearchOptionsToAdd(); - - $tab[5]['table'] = $this->getTable(); - $tab[5]['field'] = 'size'; - $tab[5]['linkfield'] = 'size'; - $tab[5]['name'] = $LANG['plugin_room'][4]; - - $tab[6]['table'] = 'glpi_plugin_room_roomaccessconds'; - $tab[6]['field'] = 'name'; - $tab[6]['linkfield'] = 'access'; - $tab[6]['name'] = $LANG['plugin_room'][5]; - - $tab[7]['table'] = $this->getTable(); - $tab[7]['field'] = 'buy'; - $tab[7]['linkfield'] = 'buy'; - $tab[7]['name'] = __('Date of purchase'); - - $tab[8]['table'] = $this->getTable(); - $tab[8]['field'] = 'printer'; - $tab[8]['linkfield'] = 'printer'; - $tab[8]['name'] = $LANG['plugin_room'][6]; - - $tab[9]['table'] = $this->getTable(); - $tab[9]['field'] = 'videoprojector'; - $tab[9]['linkfield'] = 'videoprojector'; - $tab[9]['name'] = $LANG['plugin_room'][7]; - - $tab[10]['table'] = $this->getTable(); - $tab[10]['field'] = 'wifi'; - $tab[10]['linkfield'] = 'wifi'; - $tab[10]['name'] = $LANG['plugin_room'][8]; - - $tab[11]['table'] = $this->getTable(); - $tab[11]['field'] = 'comment'; - $tab[11]['linkfield'] = ''; - $tab[11]['name'] = __('Comments'); - - $tab[13]['table'] = $this->getTable(); - $tab[13]['field'] = 'opening'; - $tab[13]['linkfield'] = ''; - $tab[13]['name'] = $LANG['plugin_room'][11]; - - $tab[12]['table'] = $this->getTable(); - $tab[12]['field'] = 'limits'; - $tab[12]['linkfield'] = ''; - $tab[12]['name'] = $LANG['plugin_room'][12]; - - $tab[16]['table'] = $this->getTable(); - $tab[16]['field'] = 'text1'; - $tab[16]['linkfield'] = ''; - $tab[16]['name'] = $LANG['plugin_room'][13]; - - $tab[17]['table'] = $this->getTable(); - $tab[17]['field'] = 'text2'; - $tab[17]['linkfield'] = ''; - $tab[17]['name'] = $LANG['plugin_room'][14]; - - $tab[18]['table'] = 'glpi_plugin_room_dropdown1s'; - $tab[18]['field'] = 'name'; - $tab[18]['linkfield'] = 'dropdown1'; - $tab[18]['name'] = $LANG['plugin_room'][15]; - - $tab[19]['table'] = 'glpi_plugin_room_dropdown1s'; - $tab[19]['field'] = 'name'; - $tab[19]['linkfield'] = 'dropdown2'; - $tab[19]['name'] = $LANG['plugin_room'][16]; - - $tab[30]['table'] = $this->getTable(); - $tab[30]['field'] = 'id'; - $tab[30]['linkfield'] = ''; - $tab[30]['name'] = __('ID'); - - $tab[31]['table'] = $this->getTable(); - $tab[31]['field'] = 'name'; - $tab[31]['linkfield'] = ''; - $tab[31]['name'] = __('Computers'); - $tab[31]['forcegroupby'] = true; - $tab[31]['datatype'] = 'itemlink'; - $tab[31]['itemlink_type'] = $this->getType(); - - $tab[32]['table'] = $this->getTable(); - $tab[32]['field'] = 'count_linked'; - $tab[32]['linkfield'] = ''; - $tab[32]['name'] = $LANG['plugin_room'][18]; - $tab[32]['meta'] = 1; - - $tab[80]['table'] = 'glpi_entities'; - $tab[80]['field'] = 'completename'; - $tab[80]['linkfield'] = 'entities_id'; - $tab[80]['name'] = __('Entity'); + $tab[] = [ + 'id' => 'common', + 'name' => $LANG['plugin_room'][0], + ]; + + $tab[] = [ + 'id' => '1', + 'table' => $this->getTable(), + 'field' => 'name', + 'linkfield' => 'name', + 'name' => __('Name'), + 'datatype' => 'itemlink', + 'itemlink_type' => $this->getType(), + ]; + + $tab[] = [ + 'id' => '2', + 'table' => 'glpi_plugin_room_roomtypes', + 'field' => 'name', + 'linkfield' => 'type', + 'name' => __('Type'), + ]; + + $tab[] = [ + 'id' => '26', + 'table' => 'glpi_groups', + 'field' => 'completename', + 'linkfield' => 'groups_id_tech', + 'name' => __('Group in charge of the hardware'), + 'condition' => '`is_assign`', + 'datatype' => 'dropdown', + ]; + + $tab[] = [ + 'id' => '24', + 'table' => 'glpi_users', + 'field' => 'name', + 'linkfield' => 'tech_num', + 'name' => __('Technician in charge of the hardware'), + ]; + + $tab[] = [ + 'id' => '25', + 'table' => 'glpi_users', + 'field' => 'name', + 'linkfield' => 'users_id', + 'name' => __('Alternate username'), + ]; + + $tab[] = [ + 'id' => '3', + 'table' => $this->getTable(), + 'field' => 'comment', + 'linkfield' => 'comment', + 'name' => __('Comments'), + ]; + + $tab += Location::rawSearchOptionsToAdd(); + + $tab[] = [ + 'id' => '5', + 'table' => $this->getTable(), + 'field' => 'size', + 'linkfield' => 'size', + 'name' => $LANG['plugin_room'][4], + ]; + + $tab[] = [ + 'id' => '6', + 'table' => 'glpi_plugin_room_roomaccessconds', + 'field' => 'name', + 'linkfield' => 'access', + 'name' => $LANG['plugin_room'][5], + ]; + + $tab[] = [ + 'id' => '7', + 'table' => $this->getTable(), + 'field' => 'buy', + 'linkfield' => 'buy', + 'name' => __('Date of purchase'), + ]; + + $tab[] = [ + 'id' => '8', + 'table' => $this->getTable(), + 'field' => 'printer', + 'linkfield' => 'printer', + 'name' => $LANG['plugin_room'][6], + ]; + + $tab[] = [ + 'id' => '9', + 'table' => $this->getTable(), + 'field' => 'videoprojector', + 'linkfield' => 'videoprojector', + 'name' => $LANG['plugin_room'][7], + ]; + + $tab[] = [ + 'id' => '10', + 'table' => $this->getTable(), + 'field' => 'wifi', + 'linkfield' => 'wifi', + 'name' => $LANG['plugin_room'][8], + ]; + + $tab[] = [ + 'id' => '11', + 'table' => $this->getTable(), + 'field' => 'comment', + 'linkfield' => '', + 'name' => __('Comments'), + ]; + + $tab[] = [ + 'id' => '13', + 'table' => $this->getTable(), + 'field' => 'opening', + 'linkfield' => '', + 'name' => $LANG['plugin_room'][11], + ]; + + $tab[] = [ + 'id' => '12', + 'table' => $this->getTable(), + 'field' => 'limits', + 'linkfield' => '', + 'name' => $LANG['plugin_room'][12], + ]; + + $tab[] = [ + 'id' => '16', + 'table' => $this->getTable(), + 'field' => 'text1', + 'linkfield' => '', + 'name' => $LANG['plugin_room'][13], + ]; + + $tab[] = [ + 'id' => '17', + 'table' => $this->getTable(), + 'field' => 'text2', + 'linkfield' => '', + 'name' => $LANG['plugin_room'][14], + ]; + + $tab[] = [ + 'id' => '18', + 'table' => 'glpi_plugin_room_dropdown1s', + 'field' => 'name', + 'linkfield' => 'dropdown1', + 'name' => $LANG['plugin_room'][15], + ]; + + $tab[] = [ + 'id' => '19', + 'table' => 'glpi_plugin_room_dropdown1s', + 'field' => 'name', + 'linkfield' => 'dropdown2', + 'name' => $LANG['plugin_room'][16], + ]; + + $tab[] = [ + 'id' => '30', + 'table' => $this->getTable(), + 'field' => 'id', + 'linkfield' => '', + 'name' => __('ID'), + ]; + + $tab[] = [ + 'id' => '31', + 'table' => $this->getTable(), + 'field' => 'name', + 'linkfield' => '', + 'name' => __('Computers'), + 'forcegroupby' => true, + 'datatype' => 'itemlink', + 'itemlink_type' => $this->getType(), + ]; + + $tab[] = [ + 'id' => '32', + 'table' => $this->getTable(), + 'field' => 'count_linked', + 'linkfield' => '', + 'name' => $LANG['plugin_room'][18], + 'meta' => 1, + ]; + + $tab[] = [ + 'id' => '80', + 'table' => 'glpi_entities', + 'field' => 'completename', + 'linkfield' => 'entities_id', + 'name' => __('Entity'), + ]; + return $tab; } diff --git a/setup.php b/setup.php index 61876c7..471ed29 100644 --- a/setup.php +++ b/setup.php @@ -55,10 +55,10 @@ function plugin_version_room() // Optional : check prerequisites before install : may print errors or add to message after redirect function plugin_room_check_prerequisites() { - if (version_compare(GLPI_VERSION, '9.2', '>=') && version_compare(GLPI_VERSION, '9.3', '<')) { + if (version_compare(GLPI_VERSION, '9.3.1', '>=') && version_compare(GLPI_VERSION, '9.4', '<')) { return true; } else { - _e('This plugin requires GLPI >= 9.2 && < 9.3', 'room'); + _e('This plugin requires GLPI >= 9.3.1 && < 9.4', 'room'); return false; } } From 096d010058f4b5d9ba00c804a3e1fd3fecd8a0df Mon Sep 17 00:00:00 2001 From: C-Duv <1466273+C-Duv@users.noreply.github.com> Date: Sun, 21 Apr 2019 16:40:12 +0200 Subject: [PATCH 5/6] Fixes an SQL query (missing "=" operator) In 82beb88c an bug was introduced which breaks an SQL query: a "=" operator was inadvertently removed). This commit fixes this (thanks Stoatwblr) Issue: #35 --- inc/profile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/profile.class.php b/inc/profile.class.php index 5ac2765..4ec1f31 100755 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -192,7 +192,7 @@ public static function initProfile() foreach ($DB->request('SELECT * FROM `glpi_profilerights` - WHERE `profiles_id` ' . $_SESSION['glpiactiveprofile']['id'] . ' + WHERE `profiles_id` = ' . $_SESSION['glpiactiveprofile']['id'] . ' AND `name` LIKE "%plugin_room%"') as $prof) { $_SESSION['glpiactiveprofile'][$prof['name']] = $prof['rights']; } From 8748766c160210c9554fe885a741c469c92fd570 Mon Sep 17 00:00:00 2001 From: C-Duv <1466273+C-Duv@users.noreply.github.com> Date: Sun, 21 Apr 2019 16:54:08 +0200 Subject: [PATCH 6/6] Changes version number to 3.1.2 Also updates XML plugin file to declare this 3.1.2 version is only compatible with GLPI v9.3.1. --- room.xml | 4 ++++ setup.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/room.xml b/room.xml index b2bdacc..1117b94 100644 --- a/room.xml +++ b/room.xml @@ -69,6 +69,10 @@ 3.1.1 9.2 + + 3.1.2 + 9.3.1 + de_DE diff --git a/setup.php b/setup.php index 471ed29..f7cef65 100644 --- a/setup.php +++ b/setup.php @@ -1,6 +1,6 @@