Skip to content

Commit 8caf70a

Browse files
committed
GLPI 9.5 compatibility
Added Export (via massive actions) and Import features Set version to 1.0.3
1 parent 3af694e commit 8caf70a

33 files changed

+7181
-1575
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 and 9.4
17+
Tested with 0.85, 0.90, 9.1, 9.2, 9.3, 9.4 and 9.5
1818

ajax/getFormValidations.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
$is_createitem = 0; // by default
4646

47-
$obj = getItemForItemtype( $_GET['name'] );
47+
$obj = getItemForItemtype( $_GET['itemtype'] );
4848
if ($obj && method_exists($obj, 'getType')) {
4949
if ($_GET['id'] > 0) {
5050
$obj->getFromDB( $_GET['id'] );

ajax/getLocales.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,10 @@
5050
}
5151

5252
// 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-
];
53+
$localization = [];
5854

5955
// add plugin own language strings to $localization
6056
$localization['plugin_formvalidation'] = $LANG['plugin_formvalidation'];
6157

62-
echo json_encode( $localization, JSON_HEX_APOS | JSON_HEX_QUOT );
58+
echo json_encode($localization, JSON_HEX_APOS | JSON_HEX_QUOT);
6359

formvalidation.xml

+8-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
<author>Olivier Moron </author>
2525
</authors>
2626
<versions>
27-
<version>
28-
<num>0.6.8</num>
29-
<compatibility>9.4</compatibility>
30-
</version>
27+
<version>
28+
<num>1.0.3</num>
29+
<compatibility>9.5</compatibility>
30+
</version>
31+
<version>
32+
<num>0.6.8</num>
33+
<compatibility>9.4</compatibility>
34+
</version>
3135
<version>
3236
<num>0.5.1</num>
3337
<compatibility>9.3</compatibility>

front/config.form.php

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?php
2-
3-
include ("../../../inc/includes.php");
4-
// No autoload when plugin is not activated
5-
//require_once('../inc/config.class.php');
6-
7-
$config = new PluginFormvalidationConfig();
8-
if (isset($_REQUEST["update"])) {
9-
$config->check($_REQUEST['id'], UPDATE);
10-
$config->update($_REQUEST);
11-
12-
Html::back();
13-
}
14-
Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=".
15-
urlencode('PluginFormvalidationConfig$1'));
2+
3+
include ("../../../inc/includes.php");
4+
5+
$config = new PluginFormvalidationConfig();
6+
if (isset($_REQUEST["update"])) {
7+
$config->check($_REQUEST['id'], UPDATE);
8+
$config->update($_REQUEST);
9+
10+
Html::back();
11+
}
12+
Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=".
13+
urlencode('PluginFormvalidationConfig$1'));

front/form.form.php

-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
$form->check($_POST["id"], PURGE);
4949
$form->delete($_POST, 1);
5050

51-
//Event::log($_POST["id"], "change", 4, "maintain",
52-
// //TRANS: %s is the user login
53-
// sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
5451
$form->redirectToList();
5552

5653
} else if (isset($_POST["update"])) {
@@ -59,9 +56,6 @@
5956
$_POST["formula"] = Html::entity_decode_deep( $_POST["formula"] );
6057

6158
$form->update($_POST);
62-
//Event::log($_POST["id"], "change", 4, "maintain",
63-
// //TRANS: %s is the user login
64-
// sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
6559

6660
Html::back();
6761

front/form.php

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Html::header(__('Form Validations', 'formvalidation'), $_SERVER['PHP_SELF'], "config", "PluginFormvalidationMenu", "formvalidationform");
66

77
if (Session::haveRight('config', READ) || Session::haveRight("config", UPDATE)) {
8-
//$process=new PluginFormvalidationForm();
98

109
Search::show('PluginFormvalidationForm');
1110

front/formvalidation.backup.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
switch ($action) {
2020
case 'export':
2121
if (isset($_GET['filename'])) {
22-
$file = "../../../files/_tmp/".$_GET['filename'];
22+
$file = GLPI_TMP_DIR."/".$_GET['filename'];
2323
if (file_exists($file)) {
2424
header('Content-type: application/json');
25-
header('Content-Disposition: attachment; filename="'.basename($file).'"');
25+
header('Content-Disposition: attachment; filename="'.$_GET['filename'].'"');
2626
readfile($file);
2727
}
2828
}

front/itemtype.form.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22
include ('../../../inc/includes.php');
33

4-
$dropdown = new PluginFormvalidationItemtype();
5-
include (GLPI_ROOT . "/front/dropdown.common.form.php");
4+
$dropdown = new PluginFormvalidationItemtype();
5+
include (GLPI_ROOT . "/front/dropdown.common.form.php");

front/itemtype.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
include ('../../../inc/includes.php');
4-
5-
$dropdown = new PluginFormvalidationItemtype();
3+
include ('../../../inc/includes.php');
4+
5+
$dropdown = new PluginFormvalidationItemtype();
66
include (GLPI_ROOT . "/front/dropdown.common.php");

front/page.form.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
} else if (isset($_POST["purge"])) {
5858
$page->check($_POST["id"], PURGE);
59-
$page->delete($_POST, 1);
59+
$page->delete($_POST, true);
6060

6161
$page->redirectToList();
6262

front/page.php

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Html::header(__('Form Validations', 'formvalidation'), $_SERVER['PHP_SELF'], "config", "PluginFormvalidationMenu", "formvalidationpage");
66

77
if (Session::haveRight('config', READ) || Session::haveRight("config", UPDATE)) {
8-
//$process=new PluginFormvalidationPage();
98
PluginFormvalidationPage::titleBackup();
109
Search::show('PluginFormvalidationPage');
1110

hook.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
* @return boolean
3232
*/
3333
function plugin_formvalidation_install() {
34-
global $DB, $CFG_GLPI;
35-
$dbu = new DbUtils();
34+
global $DB;
3635
if (!$DB->tableExists("glpi_plugin_formvalidation_configs")) {
3736
// new installation
3837
include_once(GLPI_ROOT."/plugins/formvalidation/install/install.php");

inc/config.class.php

+41-42
Original file line numberDiff line numberDiff line change
@@ -48,50 +48,49 @@ static function getInstance() {
4848

4949

5050

51-
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
52-
global $LANG;
53-
54-
if ($item->getType()=='Config') {
55-
return "Formvalidation";
56-
}
57-
return '';
58-
}
59-
60-
61-
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
62-
63-
if ($item->getType()=='Config') {
64-
self::showConfigForm($item);
65-
}
66-
return true;
51+
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
52+
53+
if ($item->getType()=='Config') {
54+
return "Formvalidation";
55+
}
56+
return '';
57+
}
58+
59+
60+
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
61+
62+
if ($item->getType()=='Config') {
63+
self::showConfigForm($item);
64+
}
65+
return true;
6766
}
6867

69-
static function showConfigForm($item) {
70-
global $LANG, $DB;
71-
72-
$config = self::getInstance();
73-
74-
$config->showFormHeader();
75-
76-
echo "<tr class='tab_bg_1'>";
77-
echo "<td colspan=2>".__("css mandatory","formvalidation")."</td><td colspan=2>";
78-
echo "<input type='text' name='css_mandatory' value='".$config->fields['css_mandatory']."'>";
79-
echo "</td></tr>\n";
80-
81-
echo "<tr class='tab_bg_1'>";
82-
echo "<td colspan=2>".__("css error","formvalidation")."</td><td colspan=2>";
83-
echo "<input type='text' name='css_error' value='".$config->fields['css_error']."'>";
84-
echo "</td></tr>\n";
85-
86-
if(!extension_loaded('v8js')) {
87-
echo "<tr class='tab_bg_1'>";
88-
echo "<td colspan=2>".__("nodejs path for massive action validation","formvalidation")."</td><td colspan=2>";
89-
echo "<input type='text' name='js_path' value='".$config->fields['js_path']."'>";
90-
echo "</td></tr>\n";
91-
}
92-
$config->showFormButtons(['candel'=>false]);
93-
94-
return false;
68+
static function showConfigForm($item) {
69+
global $DB;
70+
71+
$config = self::getInstance();
72+
73+
$config->showFormHeader();
74+
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+
}
91+
$config->showFormButtons(['candel'=>false]);
92+
93+
return false;
9594
}
9695
}
9796

inc/field.class.php

+14-43
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ static function canPurge() {
3030
* @return string translation
3131
*/
3232
static function getTypeName($nb = 0) {
33-
global $LANG;
3433

3534
if ($nb>1) {
3635
return __('Fields', 'formvalidation');
@@ -43,7 +42,6 @@ static function getTypeName($nb = 0) {
4342
* @return array of search options
4443
*/
4544
function rawSearchOptions() {
46-
global $LANG;
4745

4846
$tab = [];
4947

@@ -111,11 +109,7 @@ function rawSearchOptions() {
111109
return $tab;
112110
}
113111

114-
/**
115-
* @since version 0.85
116-
*
117-
* @see CommonGLPI::getTabNameForItem()
118-
**/
112+
119113
/**
120114
* Summary of getTabNameForItem
121115
* @param CommonGLPI $item
@@ -172,18 +166,14 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
172166
* @param mixed $ids
173167
* @param mixed $crit
174168
* @param mixed $tree
175-
* @return mixed
169+
* @return
176170
*/
177171
static function getDataForForm(PluginFormvalidationForm $form, &$members, &$ids, $crit = '', $tree = 0) {
178172
global $DB;
179173

180-
$entityrestrict = 0;
181-
182-
$restrict = "='".$form->getID()."'";
183-
184174
$res = $DB->request([
185-
'SELECT DISTINCT' => 'glpi_plugin_formvalidation_fields.id',
186-
'FIELDS' => [
175+
'SELECT' => [
176+
'glpi_plugin_formvalidation_fields.id',
187177
'glpi_plugin_formvalidation_fields.id AS linkID',
188178
'glpi_plugin_formvalidation_fields.name',
189179
'glpi_plugin_formvalidation_fields.css_selector_value',
@@ -193,31 +183,14 @@ static function getDataForForm(PluginFormvalidationForm $form, &$members, &$ids,
193183
'glpi_plugin_formvalidation_fields.show_mandatory_if',
194184
'glpi_plugin_formvalidation_fields.forms_id'
195185
],
196-
'FROM' => 'glpi_plugin_formvalidation_fields',
197-
'WHERE' => [
186+
'DISTINCT' => true,
187+
'FROM' => 'glpi_plugin_formvalidation_fields',
188+
'WHERE' => [
198189
'glpi_plugin_formvalidation_fields.forms_id' => $form->getID()
199190
],
200-
'ORDER' => 'glpi_plugin_formvalidation_fields.id'
191+
'ORDER' => 'glpi_plugin_formvalidation_fields.id'
201192
]);
202-
//// All group members
203-
//$query = "SELECT DISTINCT `glpi_plugin_formvalidation_fields`.`id`,
204-
// `glpi_plugin_formvalidation_fields`.`id` AS linkID,
205-
// `glpi_plugin_formvalidation_fields`.`name`,
206-
// `glpi_plugin_formvalidation_fields`.`css_selector_value`,
207-
// `glpi_plugin_formvalidation_fields`.`formula`,
208-
// `glpi_plugin_formvalidation_fields`.`is_active`,
209-
// `glpi_plugin_formvalidation_fields`.`show_mandatory`,
210-
// `glpi_plugin_formvalidation_fields`.`show_mandatory_if`,
211-
// `glpi_plugin_formvalidation_fields`.`forms_id`
212-
// FROM `glpi_plugin_formvalidation_fields`
213-
// WHERE `glpi_plugin_formvalidation_fields`.`forms_id` $restrict
214-
// ORDER BY `glpi_plugin_formvalidation_fields`.`id`";
215-
216-
//$result = $DB->query($query);
217-
218-
//if ($DB->numrows($result) > 0) {
219-
// while ($data=$DB->fetch_assoc($result)) {
220-
foreach($res as $data) {
193+
foreach ($res as $data) {
221194
// Add to display list, according to criterion
222195
if (empty($crit) || $data[$crit]) {
223196
$members[] = $data;
@@ -227,9 +200,7 @@ static function getDataForForm(PluginFormvalidationForm $form, &$members, &$ids,
227200
$ids[] = $data['id'];
228201
}
229202
}
230-
//}
231203

232-
return $entityrestrict;
233204
}
234205

235206
/**
@@ -240,15 +211,15 @@ static function getDataForForm(PluginFormvalidationForm $form, &$members, &$ids,
240211
/**
241212
* Summary of showForForm
242213
* @param PluginFormvalidationForm $form
243-
* @return boolean
214+
* @return
244215
*/
245216
static function showForForm(PluginFormvalidationForm $form) {
246-
global $DB, $LANG, $CFG_GLPI;
217+
global $DB, $CFG_GLPI;
247218

248219
$ID = $form->getID();
249220
if (!PluginFormvalidationField::canView()
250221
|| !$form->can($ID, READ)) {
251-
return false;
222+
return;
252223
}
253224

254225
// Have right to manage members
@@ -259,7 +230,7 @@ static function showForForm(PluginFormvalidationForm $form) {
259230
$ids = [];
260231

261232
// Retrieve member list
262-
$entityrestrict = self::getDataForForm($form, $used, $ids);
233+
self::getDataForForm($form, $used, $ids);
263234

264235
$number = count($used);
265236

@@ -373,7 +344,7 @@ function defineTabs($options = []) {
373344
* @param mixed $options
374345
*/
375346
function showForm ($ID, $options = ['candel'=>false]) {
376-
global $DB, $CFG_GLPI, $LANG;
347+
global $DB, $CFG_GLPI;
377348

378349
if ($ID > 0) {
379350
$this->check($ID, READ);

0 commit comments

Comments
 (0)