Skip to content

Commit 71f0789

Browse files
committed
Version 0.4.4 for GLPI 9.2
1 parent 86583c9 commit 71f0789

18 files changed

+291
-245
lines changed

ajax/getFormValidations.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
$config = PluginFormvalidationConfig::getInstance();
3939

40-
$validations = array( 'config' => $config->fields, 'pages_id' => 0, 'forms' => array( ) ); // by default
40+
$validations = [ 'config' => $config->fields, 'pages_id' => 0, 'forms' => [ ] ]; // by default
4141

4242
// from user session
4343
$validations['config']['editmode']=$_SESSION['glpiformvalidationeditmode'];
@@ -70,7 +70,7 @@
7070

7171
foreach ($DB->request( $query ) as $form) {
7272
$validations['forms'][$form['id']]= Toolbox::stripslashes_deep( $form );
73-
$validations['forms'][$form['id']]['fields'] = array(); // needed in case this form has no fields
73+
$validations['forms'][$form['id']]['fields'] = []; // needed in case this form has no fields
7474

7575
$query = "SELECT * FROM glpi_plugin_formvalidation_fields WHERE forms_id = ".$form['id'];
7676
foreach ($DB->request( $query ) as $field) {

ajax/getLocales.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
}
5151

5252
// JSON encode all strings that are needed in formvalidation.js
53-
$localization = array(
53+
$localization = [
5454
// 'job' => array( 44 => "LANG['job'][44]" ),
5555
// 'common' => array( 17 => "LANG['common'][17]",
5656
// 36 => "LANG['common'][36]")
57-
);
57+
];
5858

5959
// add plugin own language strings to $localization
6060
$localization['plugin_formvalidation'] = $LANG['plugin_formvalidation'];

ajax/setUnsetField.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
// extract default form name from form_css_selector
5757
$name = '';
5858
$action = '';
59-
$matches = array();
59+
$matches = [];
6060
$regex = "/form(\\[name=\\\"(?'name'\\w*)\\\"])?\\[action=\\\"(?'action'[\\w\\/\\.]*)\\\"]/";
6161
if (preg_match( $regex, str_replace("\\", "", html_entity_decode($_REQUEST['form_css_selector'])), $matches )) {
6262
if (isset($matches['name'] )) {
@@ -81,12 +81,12 @@
8181

8282
if ($DB->query( $query )) {
8383
$_REQUEST['fieldindex'] = $DB->insert_id();
84-
$ret = array( 'forms' => array( ) ); // by default
84+
$ret = [ 'forms' => [ ] ]; // by default
8585
$query = "SELECT * FROM glpi_plugin_formvalidation_forms WHERE id = ".$_REQUEST['formindex'];
8686
foreach ($DB->request( $query ) as $form) {
8787
$ret['forms_id'] = $form['id'];
8888
$ret['forms'][$form['id']]=Toolbox::stripslashes_deep( $form );
89-
$ret['forms'][$form['id']]['fields'] = array(); // needed in case this form has no fields
89+
$ret['forms'][$form['id']]['fields'] = []; // needed in case this form has no fields
9090
$query = "SELECT * FROM glpi_plugin_formvalidation_fields WHERE id = ".$_REQUEST['fieldindex'];
9191
foreach ($DB->request( $query ) as $field) {
9292
$ret['fields_id']=$field['id'];

css/formvalidation.css

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.fv-alert { z-index: 2000 !important ;}
2+
.fv-editmodeinfo { z-index: 10000 !important ;}

formvalidation.xml

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
<description>
88
<short>
99
<cs><![CDATA[Poskytuje ověřování formuláře při vyplňování přímo v prohlížeči.]]></cs>
10+
<fr><![CDATA[Permet la validation des formulaires pendant la saisie directement dans le navigateur.]]></fr>
1011
<en><![CDATA[Provides form validation during input directly in browser.]]></en>
11-
<fr><![CDATA[Permet la validation des formulaires pendant la saisie directement dans le navigateur.]]></fr>
1212
</short>
1313
<long>
1414
<cs><![CDATA[Poskytuje grafické rozhraní pro výběr kolonek, jehož obsah je třeba ověřovat.]]></cs>
15-
<en><![CDATA[Provides a graphical interface to select fields that need to be validated.]]></en>
1615
<fr><![CDATA[Fournit une interface graphique permettant de selectionner les champs qui seront à valider.]]></fr>
16+
<en><![CDATA[Provides a graphical interface to select fields that need to be validated.]]></en>
1717
</long>
1818
</description>
1919
<homepage>https://github.com/tomolimo/formvalidation</homepage>
2020
<download>https://github.com/tomolimo/formvalidation/releases</download>
2121
<issues>https://github.com/tomolimo/formvalidation/issues</issues>
2222
<readme>https://github.com/tomolimo/formvalidation/wiki</readme>
2323
<authors>
24-
<author>Olivier Moron</author>
24+
<author>Olivier Moron </author>
2525
</authors>
2626
<versions>
2727
<version>
28-
<num>0.2.3</num>
28+
<num>0.4.4</num>
2929
<compatibility>9.2</compatibility>
3030
</version>
3131
<version>
@@ -54,17 +54,17 @@
5454
<tag>Ověřování</tag>
5555
<tag>Ověřování formuláře</tag>
5656
</cs>
57-
<en>
58-
<tag>Helpdesk</tag>
59-
<tag>Form</tag>
60-
<tag>Validation</tag>
61-
<tag>Form Validation</tag>
62-
</en>
6357
<fr>
6458
<tag>Helpdesk</tag>
6559
<tag>Formulaire</tag>
6660
<tag>Validation</tag>
6761
<tag>Validation Formulaire</tag>
6862
</fr>
63+
<en>
64+
<tag>Helpdesk</tag>
65+
<tag>Form</tag>
66+
<tag>Validation</tag>
67+
<tag>Form Validation</tag>
68+
</en>
6969
</tags>
7070
</root>

front/field.form.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
if (!isset( $_POST['id'] )) {
5656
// then we have an array of input to update
5757
foreach ($_POST as $key => $val) {
58-
$match = array();
58+
$match = [];
5959
if (preg_match( "/^formula_(\\d+)$/", $key, $match )) {
6060
$ID = $match[1];
6161
$field->check($ID, UPDATE);
@@ -64,7 +64,7 @@
6464
$formula = ($formula===''?'NULL':$formula);
6565

6666
$_POST["show_mandatory_if_$ID"] = Html::entity_decode_deep( $_POST["show_mandatory_if_$ID"] );
67-
$post = array( 'id' => $ID, 'formula' => $formula, 'is_active' => $_POST["is_active_$ID"], 'show_mandatory' => $_POST["show_mandatory_$ID"], 'show_mandatory_if' => $_POST["show_mandatory_if_$ID"] );
67+
$post = [ 'id' => $ID, 'formula' => $formula, 'is_active' => $_POST["is_active_$ID"], 'show_mandatory' => $_POST["show_mandatory_$ID"], 'show_mandatory_if' => $_POST["show_mandatory_if_$ID"] ];
6868
$field->update($post);
6969
}
7070
}

hook.php

+22-38
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,37 @@
2626
--------------------------------------------------------------------------
2727
*/
2828

29-
if (!function_exists('arTableExists')) {
30-
function arTableExists($table) {
31-
global $DB;
32-
if (method_exists( $DB, 'tableExists')) {
33-
return $DB->tableExists($table);
34-
} else {
35-
return TableExists($table);
36-
}
37-
}
38-
}
39-
40-
if (!function_exists('arFieldExists')) {
41-
function arFieldExists($table, $field, $usecache = true) {
42-
global $DB;
43-
if (method_exists( $DB, 'fieldExists')) {
44-
return $DB->fieldExists($table, $field, $usecache);
45-
} else {
46-
return FieldExists($table, $field, $usecache);
47-
}
48-
}
49-
}
50-
5129
/**
5230
* Summary of plugin_formvalidation_install
5331
* @return boolean
5432
*/
5533
function plugin_formvalidation_install() {
5634
global $DB;
35+
$dbu = new DbUtils();
5736

58-
if (!arTableExists("glpi_plugin_formvalidation_configs")) {
59-
$query = "CREATE TABLE `glpi_plugin_formvalidation_configs` (
37+
if (!$DB->tableExists("glpi_plugin_formvalidation_configs")) {
38+
$query = "CREATE TABLE `glpi_plugin_formvalidation_configs` (
6039
`id` INT(11) NOT NULL AUTO_INCREMENT,
6140
`css_mandatory` VARCHAR(200) NOT NULL DEFAULT '{\"background-color\":\"lightgrey\", \"font-weight\":\"bold\"}',
62-
`css_error` VARCHAR(200) NOT NULL DEFAULT '{\"background-color\": \"red\"}',
41+
`css_error` VARCHAR(200) NOT NULL DEFAULT '{\"background-color\": \"red\"}',
6342
PRIMARY KEY (`id`)
6443
)
6544
ENGINE=InnoDB
6645
;
6746
";
6847

69-
$DB->query($query) or die("Error creating glpi_plugin_formvalidation_configs " . $DB->error());
70-
71-
$query = "INSERT INTO `glpi_plugin_formvalidation_configs` (`id`) VALUES (1);";
72-
$DB->query($query) or die("Error inserting default config into glpi_plugin_formvalidation_configs " . $DB->error());
48+
$DB->query($query) or die("Error creating glpi_plugin_formvalidation_configs " . $DB->error());
49+
$DB->insertOrDie(
50+
'glpi_plugin_formvalidation_configs', [
51+
'id' => '1',
52+
],
53+
"Error inserting default config into glpi_plugin_formvalidation_configs "
54+
);
55+
// $query = "INSERT INTO `glpi_plugin_formvalidation_configs` (`id`) VALUES (1);";
56+
// $DB->query($query) or die("Error inserting default config into glpi_plugin_formvalidation_configs " . $DB->error());
7357
}
7458

75-
if (!arTableExists("glpi_plugin_formvalidation_itemtypes")) {
59+
if (!$DB->tableExists("glpi_plugin_formvalidation_itemtypes")) {
7660
$query = "CREATE TABLE `glpi_plugin_formvalidation_itemtypes` (
7761
`id` INT(11) NOT NULL AUTO_INCREMENT,
7862
`name` VARCHAR(255) NOT NULL,
@@ -123,7 +107,7 @@ function plugin_formvalidation_install() {
123107

124108
}
125109

126-
if (!arTableExists("glpi_plugin_formvalidation_pages")) {
110+
if (!$DB->tableExists("glpi_plugin_formvalidation_pages")) {
127111
$query = "CREATE TABLE `glpi_plugin_formvalidation_pages` (
128112
`id` INT(11) NOT NULL AUTO_INCREMENT,
129113
`name` VARCHAR(200) NULL DEFAULT NULL,
@@ -153,7 +137,7 @@ function plugin_formvalidation_install() {
153137
$DB->query($query) or die("Error inserting default pages into glpi_plugin_formvalidation_pages " . $DB->error());
154138

155139
} else {
156-
if (!arFieldExists('glpi_plugin_formvalidation_pages', 'itemtypes_id')) {
140+
if (!$DB->fieldExists('glpi_plugin_formvalidation_pages', 'itemtypes_id')) {
157141
$query = "ALTER TABLE `glpi_plugin_formvalidation_pages`
158142
ADD COLUMN `itemtypes_id` INT(11) NOT NULL DEFAULT '0' AFTER `itemtype`,
159143
ADD INDEX `itemtypes_id` (`itemtypes_id`);
@@ -162,7 +146,7 @@ function plugin_formvalidation_install() {
162146
}
163147

164148
// check if migration is neccessary
165-
$pages = getAllDatasFromTable('glpi_plugin_formvalidation_pages', 'itemtypes_id = 0');
149+
$pages = $dbu->getAllDataFromTable('glpi_plugin_formvalidation_pages', ['itemtypes_id' => '0']);
166150
if (count($pages)) {
167151
// migration of itemtype into itemtypes_id
168152
$query = "UPDATE glpi_plugin_formvalidation_pages AS gpfp, glpi_plugin_formvalidation_itemtypes AS gpfi
@@ -171,15 +155,15 @@ function plugin_formvalidation_install() {
171155
$DB->query($query) or die("Error migrating itemtype into itemtypes_id field in glpi_plugin_formvalidation_pages " . $DB->error());
172156

173157
// check if all pages have been migrated
174-
$pages = getAllDatasFromTable('glpi_plugin_formvalidation_pages', 'itemtypes_id = 0');
158+
$pages = $dbu->getAllDataFromTable('glpi_plugin_formvalidation_pages', ['itemtypes_id' => '0']);
175159
if (count($pages)) {
176160
die("Error some itemtype can't be migrated into itemtypes_id field from glpi_plugin_formvalidation_pages, </br>
177161
please check the list of itemtype in glpi_plugin_formvalidation_pages and in glpi_plugin_formvalidation_itemtypes,</br>
178162
fix the issue and restart install of the plugin.");
179163
}
180164
}
181165

182-
if (arFieldExists('glpi_plugin_formvalidation_pages', 'itemtype') && !count($pages)) {
166+
if ($DB->fieldExists('glpi_plugin_formvalidation_pages', 'itemtype') && !count($pages)) {
183167
// delete itemtype field after migration is done
184168
$query = "ALTER TABLE `glpi_plugin_formvalidation_pages`
185169
DROP COLUMN `itemtype`,
@@ -195,7 +179,7 @@ function plugin_formvalidation_install() {
195179
}
196180
}
197181

198-
if (!arTableExists("glpi_plugin_formvalidation_forms")) {
182+
if (!$DB->tableExists("glpi_plugin_formvalidation_forms")) {
199183
$query = "CREATE TABLE `glpi_plugin_formvalidation_forms` (
200184
`id` INT(11) NOT NULL AUTO_INCREMENT,
201185
`name` VARCHAR(200) NULL DEFAULT NULL,
@@ -230,15 +214,15 @@ function plugin_formvalidation_install() {
230214
$DB->query($query) or die("Error inserting default data into glpi_plugin_formvalidation_forms " . $DB->error());
231215

232216
} else {
233-
if (!arFieldExists('glpi_plugin_formvalidation_forms', 'use_for_massiveaction')) {
217+
if (!$DB->fieldExists('glpi_plugin_formvalidation_forms', 'use_for_massiveaction')) {
234218
$query = "ALTER TABLE `glpi_plugin_formvalidation_forms`
235219
ADD COLUMN `use_for_massiveaction` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_active`;
236220
";
237221
$DB->query($query) or die("Error inserting use_for_massiveaction field into glpi_plugin_formvalidation_forms " . $DB->error());
238222
}
239223
}
240224

241-
if (!arTableExists("glpi_plugin_formvalidation_fields")) {
225+
if (!$DB->tableExists("glpi_plugin_formvalidation_fields")) {
242226
$query = "CREATE TABLE `glpi_plugin_formvalidation_fields` (
243227
`id` INT(11) NOT NULL AUTO_INCREMENT,
244228
`name` VARCHAR(200) NULL DEFAULT NULL,

inc/config.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class PluginFormvalidationConfig extends CommonDBTM {
3030

31-
static private $_instance = NULL;
31+
static private $_instance = null;
3232

3333
/**
3434
* Singleton for the unique config record

0 commit comments

Comments
 (0)