Skip to content

Commit 2ae9d2f

Browse files
committed
GLPI 9.4
Version 0.6.3
1 parent 0d19bb2 commit 2ae9d2f

35 files changed

+2927
-2048
lines changed

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# Form Validation
2-
GLPI plugin to provide form validations
3-
This plugin gives the possibility to graphically set / unset mandatory fields on any GLPI form.
4-
See : https://github.com/tomolimo/formvalidation/wiki
5-
6-
7-
8-
## Installation
9-
- download the archive file
10-
- copy content of archive into your `glpi/plugins/` folder, beware that the plugin folder must be `formvalidation`. So you should have a directory like: `glpi/plugins/formvalidation/`.
11-
- go to glpi plugins page to install and enable the newly installed plugin.
12-
13-
## Configuration
14-
See wiki pages https://github.com/tomolimo/formvalidation/wiki
15-
16-
## GLPI compatibility:
17-
Tested with 0.85, 0.90, 9.1, 9.2 and 9.3
18-
1+
# Form Validation
2+
GLPI plugin to provide form validations
3+
This plugin gives the possibility to graphically set / unset mandatory fields on any GLPI form.
4+
See : https://github.com/tomolimo/formvalidation/wiki
5+
6+
7+
8+
## Installation
9+
- download the archive file
10+
- copy content of archive into your `glpi/plugins/` folder, beware that the plugin folder must be `formvalidation`. So you should have a directory like: `glpi/plugins/formvalidation/`.
11+
- go to glpi plugins page to install and enable the newly installed plugin.
12+
13+
## Configuration
14+
See wiki pages https://github.com/tomolimo/formvalidation/wiki
15+
16+
## GLPI compatibility:
17+
Tested with 0.85, 0.90, 9.1, 9.2, 9.3 and 9.4
18+

ajax/existingFile.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
include ("../../../inc/includes.php");
3+
$b = "0";
4+
if (isset($_GET['filename']) && file_exists(GLPI_ROOT.$_GET['filename'])) {
5+
$b = "1";
6+
}
7+
echo $b;
8+
9+

ajax/getFormValidations.php

+90-83
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,90 @@
1-
<?php
2-
/*
3-
* -------------------------------------------------------------------------
4-
Form Validation plugin
5-
Copyright (C) 2016 by Raynet SAS a company of A.Raymond Network.
6-
7-
http://www.araymond.com
8-
-------------------------------------------------------------------------
9-
10-
LICENSE
11-
12-
This file is part of Form Validation plugin for GLPI.
13-
14-
This file is free software; you can redistribute it and/or modify
15-
it under the terms of the GNU General Public License as published by
16-
the Free Software Foundation; either version 2 of the License, or
17-
(at your option) any later version.
18-
19-
GLPI is distributed in the hope that it will be useful,
20-
but WITHOUT ANY WARRANTY; without even the implied warranty of
21-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22-
GNU General Public License for more details.
23-
24-
You should have received a copy of the GNU General Public License
25-
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
26-
--------------------------------------------------------------------------
27-
*/
28-
29-
$AJAX_INCLUDE = 1;
30-
include ('../../../inc/includes.php');
31-
32-
// Send UTF8 Headers
33-
header("Content-Type: text/html; charset=UTF-8");
34-
Html::header_nocache();
35-
36-
Session::checkLoginUser();
37-
38-
$config = PluginFormvalidationConfig::getInstance();
39-
40-
$validations = [ 'config' => $config->fields, 'pages_id' => 0, 'forms' => [ ] ]; // by default
41-
42-
// from user session
43-
$validations['config']['editmode']=$_SESSION['glpiformvalidationeditmode'];
44-
45-
$is_createitem = 0; // by default
46-
47-
$obj = getItemForItemtype( $_GET['itemtype'] );
48-
if ($obj) {
49-
if ($_GET['id'] > 0) {
50-
$obj->getFromDB( $_GET['id'] );
51-
$entity_restrict = 0; // by default if $obj doesn't have entities_id in table
52-
if (isset($obj->fields['entities_id'])) {
53-
$entity_restrict = $obj->fields['entities_id'];
54-
}
55-
} else {
56-
$is_createitem = 1;
57-
$entity_restrict = $_SESSION['glpiactive_entity'];
58-
}
59-
60-
$query = "SELECT glpi_plugin_formvalidation_pages.*, glpi_plugin_formvalidation_itemtypes.itemtype FROM glpi_plugin_formvalidation_pages
61-
JOIN glpi_plugin_formvalidation_itemtypes on glpi_plugin_formvalidation_itemtypes.id=glpi_plugin_formvalidation_pages.itemtypes_id
62-
WHERE glpi_plugin_formvalidation_itemtypes.itemtype = '".$obj->getType()."' AND is_active=1 ".
63-
getEntitiesRestrictRequest( 'AND', 'glpi_plugin_formvalidation_pages', '', $entity_restrict, true);
64-
65-
foreach ($DB->request( $query ) as $page) {
66-
$validations['pages_id']=$page['id']; // normaly there is only one page
67-
$validations['itemtype']=$page['itemtype']; // normaly there is only one page
68-
69-
$query = "SELECT * FROM glpi_plugin_formvalidation_forms WHERE is_createitem=$is_createitem AND pages_id = ".$page['id'];
70-
71-
foreach ($DB->request( $query ) as $form) {
72-
$validations['forms'][$form['id']]= Toolbox::stripslashes_deep( $form );
73-
$validations['forms'][$form['id']]['fields'] = []; // needed in case this form has no fields
74-
75-
$query = "SELECT * FROM glpi_plugin_formvalidation_fields WHERE forms_id = ".$form['id'];
76-
foreach ($DB->request( $query ) as $field) {
77-
$validations['forms'][$form['id']]['fields'][$field['id']] = Toolbox::stripslashes_deep( $field );
78-
}
79-
}
80-
}
81-
}
82-
echo json_encode( $validations, JSON_HEX_APOS | JSON_HEX_QUOT );
83-
1+
<?php
2+
/*
3+
* -------------------------------------------------------------------------
4+
Form Validation plugin
5+
Copyright (C) 2016 by Raynet SAS a company of A.Raymond Network.
6+
7+
http://www.araymond.com
8+
-------------------------------------------------------------------------
9+
10+
LICENSE
11+
12+
This file is part of Form Validation plugin for GLPI.
13+
14+
This file is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation; either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
GLPI is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
26+
--------------------------------------------------------------------------
27+
*/
28+
29+
$AJAX_INCLUDE = 1;
30+
include ('../../../inc/includes.php');
31+
32+
// Send UTF8 Headers
33+
header("Content-Type: text/html; charset=UTF-8");
34+
Html::header_nocache();
35+
36+
Session::checkLoginUser();
37+
38+
$config = PluginFormvalidationConfig::getInstance();
39+
40+
$validations = [ 'config' => $config->fields, 'pages_id' => 0, 'forms' => [ ] ]; // by default
41+
42+
// from user session
43+
$validations['config']['editmode']=$_SESSION['glpiformvalidationeditmode'];
44+
45+
$is_createitem = 0; // by default
46+
47+
$obj = getItemForItemtype( $_GET['name'] );
48+
if ($obj) {
49+
if ($_GET['id'] > 0) {
50+
$obj->getFromDB( $_GET['id'] );
51+
$entity_restrict = 0; // by default if $obj doesn't have entities_id in table
52+
if (isset($obj->fields['entities_id'])) {
53+
$entity_restrict = $obj->fields['entities_id'];
54+
}
55+
} else {
56+
$is_createitem = 1;
57+
$entity_restrict = $_SESSION['glpiactive_entity'];
58+
}
59+
60+
$query = $DB->request([
61+
'SELECT' => ['glpi_plugin_formvalidation_pages.*','glpi_plugin_formvalidation_itemtypes.name'],
62+
'FROM' => 'glpi_plugin_formvalidation_pages',
63+
'INNER JOIN' => ['glpi_plugin_formvalidation_itemtypes' =>
64+
['FKEY' =>
65+
[
66+
'glpi_plugin_formvalidation_pages' => 'itemtypes_id',
67+
'glpi_plugin_formvalidation_itemtypes' => 'id'
68+
]
69+
]
70+
],
71+
['AND' => ['glpi_plugin_formvalidation_itemtypes.name'=>$obj->getType(), 'is_active' => 1, getEntitiesRestrictCriteria('glpi_plugin_formvalidation_pages', '', $entity_restrict, true)]]
72+
73+
]
74+
);
75+
foreach ($query as $page) {
76+
$validations['pages_id']=$page['id']; // normaly there is only one page
77+
//$validations['itemtype']=$page['itemtype']; // normaly there is only one page
78+
$validations['itemtype']=$page['name']; // normaly there is only one page
79+
80+
foreach ($DB->request('glpi_plugin_formvalidation_forms', ['AND'=>['is_createitem' => $is_createitem, 'pages_id' => $page['id']]]) as $form) {
81+
$validations['forms'][$form['id']]= Toolbox::stripslashes_deep( $form );
82+
$validations['forms'][$form['id']]['fields'] = []; // needed in case this form has no fields
83+
foreach ($DB->request('glpi_plugin_formvalidation_fields', ['forms_id' => $form['id']]) as $field) {
84+
$validations['forms'][$form['id']]['fields'][$field['id']] = Toolbox::stripslashes_deep( $field );
85+
}
86+
}
87+
}
88+
}
89+
echo json_encode( $validations, JSON_HEX_APOS | JSON_HEX_QUOT );
90+

ajax/getLocales.php

+63-63
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
<?php
2-
/*
3-
* -------------------------------------------------------------------------
4-
Form Validation plugin
5-
Copyright (C) 2016 by Raynet SAS a company of A.Raymond Network.
6-
7-
http://www.araymond.com
8-
-------------------------------------------------------------------------
9-
10-
LICENSE
11-
12-
This file is part of Form Validation plugin for GLPI.
13-
14-
This file is free software; you can redistribute it and/or modify
15-
it under the terms of the GNU General Public License as published by
16-
the Free Software Foundation; either version 2 of the License, or
17-
(at your option) any later version.
18-
19-
GLPI is distributed in the hope that it will be useful,
20-
but WITHOUT ANY WARRANTY; without even the implied warranty of
21-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22-
GNU General Public License for more details.
23-
24-
You should have received a copy of the GNU General Public License
25-
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
26-
--------------------------------------------------------------------------
27-
*/
28-
29-
$AJAX_INCLUDE = 1;
30-
include ('../../../inc/includes.php');
31-
32-
// Send UTF8 Headers
33-
header("Content-Type: text/html; charset=UTF-8");
34-
Html::header_nocache();
35-
36-
Session::checkLoginUser();
37-
38-
if (!isset($LANG['plugin_formvalidation'])) {
39-
$dir = GLPI_ROOT . "/plugins/formvalidation/locales/";
40-
// try to load en_GB default language
41-
// to be sure that it will default to english if user's language
42-
// can't be found
43-
if (file_exists($dir . "en_GB.php")) {
44-
include ($dir . "en_GB.php");
45-
}
46-
// and then try to load user's own language
47-
if (file_exists($dir.$_SESSION["glpilanguage"].'.php')) {
48-
include ($dir.$_SESSION["glpilanguage"].'.php');
49-
}
50-
}
51-
52-
// JSON encode all strings that are needed in formvalidation.js
53-
$localization = [
54-
// 'job' => array( 44 => "LANG['job'][44]" ),
55-
// 'common' => array( 17 => "LANG['common'][17]",
56-
// 36 => "LANG['common'][36]")
57-
];
58-
59-
// add plugin own language strings to $localization
60-
$localization['plugin_formvalidation'] = $LANG['plugin_formvalidation'];
61-
62-
echo json_encode( $localization, JSON_HEX_APOS | JSON_HEX_QUOT );
63-
1+
<?php
2+
/*
3+
* -------------------------------------------------------------------------
4+
Form Validation plugin
5+
Copyright (C) 2016 by Raynet SAS a company of A.Raymond Network.
6+
7+
http://www.araymond.com
8+
-------------------------------------------------------------------------
9+
10+
LICENSE
11+
12+
This file is part of Form Validation plugin for GLPI.
13+
14+
This file is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation; either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
GLPI is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
26+
--------------------------------------------------------------------------
27+
*/
28+
29+
$AJAX_INCLUDE = 1;
30+
include ('../../../inc/includes.php');
31+
32+
// Send UTF8 Headers
33+
header("Content-Type: text/html; charset=UTF-8");
34+
Html::header_nocache();
35+
36+
Session::checkLoginUser();
37+
38+
if (!isset($LANG['plugin_formvalidation'])) {
39+
$dir = GLPI_ROOT . "/plugins/formvalidation/locales/";
40+
// try to load en_GB default language
41+
// to be sure that it will default to english if user's language
42+
// can't be found
43+
if (file_exists($dir . "en_GB.php")) {
44+
include ($dir . "en_GB.php");
45+
}
46+
// and then try to load user's own language
47+
if (file_exists($dir.$_SESSION["glpilanguage"].'.php')) {
48+
include ($dir.$_SESSION["glpilanguage"].'.php');
49+
}
50+
}
51+
52+
// JSON encode all strings that are needed in formvalidation.js
53+
$localization = [
54+
// 'job' => array( 44 => "LANG['job'][44]" ),
55+
// 'common' => array( 17 => "LANG['common'][17]",
56+
// 36 => "LANG['common'][36]")
57+
];
58+
59+
// add plugin own language strings to $localization
60+
$localization['plugin_formvalidation'] = $LANG['plugin_formvalidation'];
61+
62+
echo json_encode( $localization, JSON_HEX_APOS | JSON_HEX_QUOT );
63+

0 commit comments

Comments
 (0)