Skip to content

Commit 4f29bf9

Browse files
committed
For GLPI 10.0
1 parent e644a03 commit 4f29bf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+16627
-6875
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ See : https://github.com/tomolimo/formvalidation/wiki
1414
See wiki pages https://github.com/tomolimo/formvalidation/wiki
1515

1616
## GLPI compatibility:
17-
Tested with 0.85, 0.90, 9.1, 9.2, 9.3, 9.4 and 9.5
17+
Tested with 0.85, 0.90, 9.1, 9.2, 9.3, 9.4, 9.5 and 10.0
1818

ajax/getFormValidations.php

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

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

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

4242
// from user session
4343
$validations['config']['editmode']=$_SESSION['glpiformvalidationeditmode'];
@@ -63,7 +63,7 @@
6363
'INNER JOIN' => ['glpi_plugin_formvalidation_itemtypes' =>
6464
['FKEY' =>
6565
[
66-
'glpi_plugin_formvalidation_pages' => 'itemtypes_id',
66+
'glpi_plugin_formvalidation_pages' => 'plugin_formvalidation_itemtypes_id',
6767
'glpi_plugin_formvalidation_itemtypes' => 'id'
6868
]
6969
]
@@ -73,18 +73,17 @@
7373
]
7474
);
7575
foreach ($query as $page) {
76-
$validations['pages_id']=$page['id']; // normaly there is only one page
76+
$validations['plugin_formvalidation_pages_id']=$page['id']; // normaly there is only one page
7777
//$validations['itemtype']=$page['itemtype']; // normaly there is only one page
7878
$validations['itemtype']=$page['name']; // normaly there is only one page
7979

80-
foreach ($DB->request('glpi_plugin_formvalidation_forms', ['AND'=>['is_createitem' => $is_createitem, 'pages_id' => $page['id']]]) as $form) {
80+
foreach ($DB->request('glpi_plugin_formvalidation_forms', ['AND'=>['is_createitem' => $is_createitem, 'plugin_formvalidation_pages_id' => $page['id']]]) as $form) {
8181
$validations['forms'][$form['id']]= Toolbox::stripslashes_deep( $form );
8282
$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) {
83+
foreach ($DB->request('glpi_plugin_formvalidation_fields', ['plugin_formvalidation_forms_id' => $form['id']]) as $field) {
8484
$validations['forms'][$form['id']]['fields'][$field['id']] = Toolbox::stripslashes_deep( $field );
8585
}
8686
}
8787
}
8888
}
89-
echo json_encode( $validations, JSON_HEX_APOS | JSON_HEX_QUOT );
90-
89+
echo json_encode( $validations, JSON_HEX_APOS | JSON_HEX_QUOT );

ajax/setUnsetField.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,19 @@
6060
$name = '';
6161
$action = '';
6262
$matches = [];
63-
$regex = "/form(\\[name=\\\"(?'name'\\w*)\\\"])?\\[action=\\\"(?'action'[\\w\\/\\.]*)\\\"]/";
63+
$regex = '/form(?>(?>\[name="(?\'name\'\w*)?"])|(?>\[id="(?\'id\'[\w-]*)?"]))+\[action\^{0,1}="(?\'action\'[\w\/\.]*)"]/ui';
6464
if (preg_match( $regex, str_replace("\\", "", html_entity_decode($_REQUEST['form_css_selector'])), $matches )) {
65-
if (isset($matches['name'] )) {
65+
if (isset($matches['name']) && $matches['name'] != '') {
6666
$name = $matches['name'];
67+
} else if (isset($matches['id'])) {
68+
$name = $matches['id'];
6769
}
6870
$action = $matches['action'];
6971
}
7072
if ($form->add(
7173
[
7274
'name' => $DB->escape("$name($action)"),
73-
'pages_id' => $_REQUEST['pages_id'],
75+
'plugin_formvalidation_pages_id' => $_REQUEST['plugin_formvalidation_pages_id'],
7476
'css_selector' => $DB->escape(html_entity_decode($_REQUEST['form_css_selector'])),
7577
'is_active' => 1,
7678
'is_createitem' => $_REQUEST['is_createitem']
@@ -84,7 +86,7 @@
8486
if ($fields->add(
8587
[
8688
'name' => $_REQUEST['name'],
87-
'forms_id' => $_REQUEST['formindex'],
89+
'plugin_formvalidation_forms_id' => $_REQUEST['formindex'],
8890
'css_selector_value' => $DB->escape(html_entity_decode( $_REQUEST['css_selector_value'])),
8991
'css_selector_errorsign' => $DB->escape(html_entity_decode( $_REQUEST['css_selector_errorsign'])),
9092
'css_selector_mandatorysign' => $DB->escape(html_entity_decode( $_REQUEST['css_selector_mandatorysign'])),

formvalidation.xml

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
</authors>
2626
<versions>
2727
<version>
28-
<num>1.0.15</num>
29-
<compatibility>9.5</compatibility>
28+
<num>2.0.1</num>
29+
<compatibility>10.0</compatibility>
3030
</version>
3131
<version>
32+
<num>1.0.15</num>
33+
<compatibility>9.5</compatibility>
34+
</version> <version>
3235
<num>0.6.8</num>
3336
<compatibility>9.4</compatibility>
3437
</version>

inc/config.class.php

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
use Glpi\Application\View\TemplateRenderer;
23
/*
34
* -------------------------------------------------------------------------
45
Form Validation plugin
@@ -67,27 +68,16 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
6768

6869
static function showConfigForm($item) {
6970
global $DB;
70-
7171
$config = self::getInstance();
72-
7372
$config->showFormHeader();
7473

75-
echo "<tr class='tab_bg_1'>";
76-
echo "<td colspan=2>".__("css mandatory", "formvalidation")."</td><td colspan=2>";
77-
echo "<input type='text' name='css_mandatory' value='".$config->fields['css_mandatory']."'>";
78-
echo "</td></tr>\n";
79-
80-
echo "<tr class='tab_bg_1'>";
81-
echo "<td colspan=2>".__("css error", "formvalidation")."</td><td colspan=2>";
82-
echo "<input type='text' name='css_error' value='".$config->fields['css_error']."'>";
83-
echo "</td></tr>\n";
84-
85-
if (!extension_loaded('v8js')) {
86-
echo "<tr class='tab_bg_1'>";
87-
echo "<td colspan=2>".__("nodejs path for massive action validation", "formvalidation")."</td><td colspan=2>";
88-
echo "<input type='text' name='js_path' value='".$config->fields['js_path']."'>";
89-
echo "</td></tr>\n";
90-
}
74+
$extLoaded = extension_loaded('v8js');
75+
$html = TemplateRenderer::getInstance()->render('@formvalidation/config_form.html.twig', [
76+
'data' => $config->fields,
77+
'extLoaded' => $extLoaded,
78+
]);
79+
80+
echo $html;
9181
$config->showFormButtons(['candel'=>false]);
9282

9383
return false;

0 commit comments

Comments
 (0)