Skip to content

Commit

Permalink
GLPI 9.5 compatibility
Browse files Browse the repository at this point in the history
Added Export (via massive actions) and Import features
Set version to 1.0.3
  • Loading branch information
tomolimo committed Mar 11, 2021
1 parent 3af694e commit 8caf70a
Show file tree
Hide file tree
Showing 33 changed files with 7,181 additions and 1,575 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ See : https://github.com/tomolimo/formvalidation/wiki
See wiki pages https://github.com/tomolimo/formvalidation/wiki

## GLPI compatibility:
Tested with 0.85, 0.90, 9.1, 9.2, 9.3 and 9.4
Tested with 0.85, 0.90, 9.1, 9.2, 9.3, 9.4 and 9.5

2 changes: 1 addition & 1 deletion ajax/getFormValidations.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

$is_createitem = 0; // by default

$obj = getItemForItemtype( $_GET['name'] );
$obj = getItemForItemtype( $_GET['itemtype'] );
if ($obj && method_exists($obj, 'getType')) {
if ($_GET['id'] > 0) {
$obj->getFromDB( $_GET['id'] );
Expand Down
8 changes: 2 additions & 6 deletions ajax/getLocales.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@
}

// JSON encode all strings that are needed in formvalidation.js
$localization = [
// 'job' => array( 44 => "LANG['job'][44]" ),
// 'common' => array( 17 => "LANG['common'][17]",
// 36 => "LANG['common'][36]")
];
$localization = [];

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

echo json_encode( $localization, JSON_HEX_APOS | JSON_HEX_QUOT );
echo json_encode($localization, JSON_HEX_APOS | JSON_HEX_QUOT);

12 changes: 8 additions & 4 deletions formvalidation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
<author>Olivier Moron </author>
</authors>
<versions>
<version>
<num>0.6.8</num>
<compatibility>9.4</compatibility>
</version>
<version>
<num>1.0.3</num>
<compatibility>9.5</compatibility>
</version>
<version>
<num>0.6.8</num>
<compatibility>9.4</compatibility>
</version>
<version>
<num>0.5.1</num>
<compatibility>9.3</compatibility>
Expand Down
26 changes: 12 additions & 14 deletions front/config.form.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php

include ("../../../inc/includes.php");
// No autoload when plugin is not activated
//require_once('../inc/config.class.php');

$config = new PluginFormvalidationConfig();
if (isset($_REQUEST["update"])) {
$config->check($_REQUEST['id'], UPDATE);
$config->update($_REQUEST);

Html::back();
}
Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=".
urlencode('PluginFormvalidationConfig$1'));

include ("../../../inc/includes.php");

$config = new PluginFormvalidationConfig();
if (isset($_REQUEST["update"])) {
$config->check($_REQUEST['id'], UPDATE);
$config->update($_REQUEST);

Html::back();
}
Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=".
urlencode('PluginFormvalidationConfig$1'));
6 changes: 0 additions & 6 deletions front/form.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
$form->check($_POST["id"], PURGE);
$form->delete($_POST, 1);

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

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

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

Html::back();

Expand Down
1 change: 0 additions & 1 deletion front/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Html::header(__('Form Validations', 'formvalidation'), $_SERVER['PHP_SELF'], "config", "PluginFormvalidationMenu", "formvalidationform");

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

Search::show('PluginFormvalidationForm');

Expand Down
4 changes: 2 additions & 2 deletions front/formvalidation.backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
switch ($action) {
case 'export':
if (isset($_GET['filename'])) {
$file = "../../../files/_tmp/".$_GET['filename'];
$file = GLPI_TMP_DIR."/".$_GET['filename'];
if (file_exists($file)) {
header('Content-type: application/json');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Disposition: attachment; filename="'.$_GET['filename'].'"');
readfile($file);
}
}
Expand Down
4 changes: 2 additions & 2 deletions front/itemtype.form.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include ('../../../inc/includes.php');

$dropdown = new PluginFormvalidationItemtype();
include (GLPI_ROOT . "/front/dropdown.common.form.php");
$dropdown = new PluginFormvalidationItemtype();
include (GLPI_ROOT . "/front/dropdown.common.form.php");
6 changes: 3 additions & 3 deletions front/itemtype.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

include ('../../../inc/includes.php');

$dropdown = new PluginFormvalidationItemtype();
include ('../../../inc/includes.php');

$dropdown = new PluginFormvalidationItemtype();
include (GLPI_ROOT . "/front/dropdown.common.php");
2 changes: 1 addition & 1 deletion front/page.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

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

$page->redirectToList();

Expand Down
1 change: 0 additions & 1 deletion front/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Html::header(__('Form Validations', 'formvalidation'), $_SERVER['PHP_SELF'], "config", "PluginFormvalidationMenu", "formvalidationpage");

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

Expand Down
3 changes: 1 addition & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
* @return boolean
*/
function plugin_formvalidation_install() {
global $DB, $CFG_GLPI;
$dbu = new DbUtils();
global $DB;
if (!$DB->tableExists("glpi_plugin_formvalidation_configs")) {
// new installation
include_once(GLPI_ROOT."/plugins/formvalidation/install/install.php");
Expand Down
83 changes: 41 additions & 42 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,49 @@ static function getInstance() {



function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
global $LANG;

if ($item->getType()=='Config') {
return "Formvalidation";
}
return '';
}


static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {

if ($item->getType()=='Config') {
self::showConfigForm($item);
}
return true;
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {

if ($item->getType()=='Config') {
return "Formvalidation";
}
return '';
}


static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {

if ($item->getType()=='Config') {
self::showConfigForm($item);
}
return true;
}

static function showConfigForm($item) {
global $LANG, $DB;

$config = self::getInstance();

$config->showFormHeader();

echo "<tr class='tab_bg_1'>";
echo "<td colspan=2>".__("css mandatory","formvalidation")."</td><td colspan=2>";
echo "<input type='text' name='css_mandatory' value='".$config->fields['css_mandatory']."'>";
echo "</td></tr>\n";

echo "<tr class='tab_bg_1'>";
echo "<td colspan=2>".__("css error","formvalidation")."</td><td colspan=2>";
echo "<input type='text' name='css_error' value='".$config->fields['css_error']."'>";
echo "</td></tr>\n";

if(!extension_loaded('v8js')) {
echo "<tr class='tab_bg_1'>";
echo "<td colspan=2>".__("nodejs path for massive action validation","formvalidation")."</td><td colspan=2>";
echo "<input type='text' name='js_path' value='".$config->fields['js_path']."'>";
echo "</td></tr>\n";
}
$config->showFormButtons(['candel'=>false]);

return false;
static function showConfigForm($item) {
global $DB;

$config = self::getInstance();

$config->showFormHeader();

echo "<tr class='tab_bg_1'>";
echo "<td colspan=2>".__("css mandatory", "formvalidation")."</td><td colspan=2>";
echo "<input type='text' name='css_mandatory' value='".$config->fields['css_mandatory']."'>";
echo "</td></tr>\n";

echo "<tr class='tab_bg_1'>";
echo "<td colspan=2>".__("css error", "formvalidation")."</td><td colspan=2>";
echo "<input type='text' name='css_error' value='".$config->fields['css_error']."'>";
echo "</td></tr>\n";

if (!extension_loaded('v8js')) {
echo "<tr class='tab_bg_1'>";
echo "<td colspan=2>".__("nodejs path for massive action validation", "formvalidation")."</td><td colspan=2>";
echo "<input type='text' name='js_path' value='".$config->fields['js_path']."'>";
echo "</td></tr>\n";
}
$config->showFormButtons(['candel'=>false]);

return false;
}
}

57 changes: 14 additions & 43 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ static function canPurge() {
* @return string translation
*/
static function getTypeName($nb = 0) {
global $LANG;

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

$tab = [];

Expand Down Expand Up @@ -111,11 +109,7 @@ function rawSearchOptions() {
return $tab;
}

/**
* @since version 0.85
*
* @see CommonGLPI::getTabNameForItem()
**/

/**
* Summary of getTabNameForItem
* @param CommonGLPI $item
Expand Down Expand Up @@ -172,18 +166,14 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
* @param mixed $ids
* @param mixed $crit
* @param mixed $tree
* @return mixed
* @return
*/
static function getDataForForm(PluginFormvalidationForm $form, &$members, &$ids, $crit = '', $tree = 0) {
global $DB;

$entityrestrict = 0;

$restrict = "='".$form->getID()."'";

$res = $DB->request([
'SELECT DISTINCT' => 'glpi_plugin_formvalidation_fields.id',
'FIELDS' => [
'SELECT' => [
'glpi_plugin_formvalidation_fields.id',
'glpi_plugin_formvalidation_fields.id AS linkID',
'glpi_plugin_formvalidation_fields.name',
'glpi_plugin_formvalidation_fields.css_selector_value',
Expand All @@ -193,31 +183,14 @@ static function getDataForForm(PluginFormvalidationForm $form, &$members, &$ids,
'glpi_plugin_formvalidation_fields.show_mandatory_if',
'glpi_plugin_formvalidation_fields.forms_id'
],
'FROM' => 'glpi_plugin_formvalidation_fields',
'WHERE' => [
'DISTINCT' => true,
'FROM' => 'glpi_plugin_formvalidation_fields',
'WHERE' => [
'glpi_plugin_formvalidation_fields.forms_id' => $form->getID()
],
'ORDER' => 'glpi_plugin_formvalidation_fields.id'
'ORDER' => 'glpi_plugin_formvalidation_fields.id'
]);
//// All group members
//$query = "SELECT DISTINCT `glpi_plugin_formvalidation_fields`.`id`,
// `glpi_plugin_formvalidation_fields`.`id` AS linkID,
// `glpi_plugin_formvalidation_fields`.`name`,
// `glpi_plugin_formvalidation_fields`.`css_selector_value`,
// `glpi_plugin_formvalidation_fields`.`formula`,
// `glpi_plugin_formvalidation_fields`.`is_active`,
// `glpi_plugin_formvalidation_fields`.`show_mandatory`,
// `glpi_plugin_formvalidation_fields`.`show_mandatory_if`,
// `glpi_plugin_formvalidation_fields`.`forms_id`
// FROM `glpi_plugin_formvalidation_fields`
// WHERE `glpi_plugin_formvalidation_fields`.`forms_id` $restrict
// ORDER BY `glpi_plugin_formvalidation_fields`.`id`";

//$result = $DB->query($query);

//if ($DB->numrows($result) > 0) {
// while ($data=$DB->fetch_assoc($result)) {
foreach($res as $data) {
foreach ($res as $data) {
// Add to display list, according to criterion
if (empty($crit) || $data[$crit]) {
$members[] = $data;
Expand All @@ -227,9 +200,7 @@ static function getDataForForm(PluginFormvalidationForm $form, &$members, &$ids,
$ids[] = $data['id'];
}
}
//}

return $entityrestrict;
}

/**
Expand All @@ -240,15 +211,15 @@ static function getDataForForm(PluginFormvalidationForm $form, &$members, &$ids,
/**
* Summary of showForForm
* @param PluginFormvalidationForm $form
* @return boolean
* @return
*/
static function showForForm(PluginFormvalidationForm $form) {
global $DB, $LANG, $CFG_GLPI;
global $DB, $CFG_GLPI;

$ID = $form->getID();
if (!PluginFormvalidationField::canView()
|| !$form->can($ID, READ)) {
return false;
return;
}

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

// Retrieve member list
$entityrestrict = self::getDataForForm($form, $used, $ids);
self::getDataForForm($form, $used, $ids);

$number = count($used);

Expand Down Expand Up @@ -373,7 +344,7 @@ function defineTabs($options = []) {
* @param mixed $options
*/
function showForm ($ID, $options = ['candel'=>false]) {
global $DB, $CFG_GLPI, $LANG;
global $DB, $CFG_GLPI;

if ($ID > 0) {
$this->check($ID, READ);
Expand Down
Loading

0 comments on commit 8caf70a

Please sign in to comment.