Skip to content

Commit

Permalink
Added itemtype creation
Browse files Browse the repository at this point in the history
re-organized installation and updates
Added Export/Import of pages
fixes #27
  • Loading branch information
tomolimo committed Jun 19, 2019
1 parent da27557 commit 5f2a28d
Show file tree
Hide file tree
Showing 35 changed files with 2,791 additions and 2,009 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Form Validation
GLPI plugin to provide form validations
This plugin gives the possibility to graphically set / unset mandatory fields on any GLPI form.
See : https://github.com/tomolimo/formvalidation/wiki



## Installation
- download the archive file
- 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/`.
- go to glpi plugins page to install and enable the newly installed plugin.

## Configuration
See wiki pages https://github.com/tomolimo/formvalidation/wiki

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

# Form Validation
GLPI plugin to provide form validations
This plugin gives the possibility to graphically set / unset mandatory fields on any GLPI form.
See : https://github.com/tomolimo/formvalidation/wiki



## Installation
- download the archive file
- 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/`.
- go to glpi plugins page to install and enable the newly installed plugin.

## Configuration
See wiki pages https://github.com/tomolimo/formvalidation/wiki

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

9 changes: 9 additions & 0 deletions ajax/existingFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
include ("../../../inc/includes.php");
$b = "0";
if (isset($_GET['filename']) && file_exists(GLPI_ROOT.$_GET['filename'])) {
$b = "1";
}
echo $b;


173 changes: 90 additions & 83 deletions ajax/getFormValidations.php
Original file line number Diff line number Diff line change
@@ -1,83 +1,90 @@
<?php
/*
* -------------------------------------------------------------------------
Form Validation plugin
Copyright (C) 2016 by Raynet SAS a company of A.Raymond Network.
http://www.araymond.com
-------------------------------------------------------------------------
LICENSE
This file is part of Form Validation plugin for GLPI.
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

$AJAX_INCLUDE = 1;
include ('../../../inc/includes.php');

// Send UTF8 Headers
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();

$config = PluginFormvalidationConfig::getInstance();

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

// from user session
$validations['config']['editmode']=$_SESSION['glpiformvalidationeditmode'];

$is_createitem = 0; // by default

$obj = getItemForItemtype( $_GET['itemtype'] );
if ($obj) {
if ($_GET['id'] > 0) {
$obj->getFromDB( $_GET['id'] );
$entity_restrict = 0; // by default if $obj doesn't have entities_id in table
if (isset($obj->fields['entities_id'])) {
$entity_restrict = $obj->fields['entities_id'];
}
} else {
$is_createitem = 1;
$entity_restrict = $_SESSION['glpiactive_entity'];
}

$query = "SELECT glpi_plugin_formvalidation_pages.*, glpi_plugin_formvalidation_itemtypes.itemtype FROM glpi_plugin_formvalidation_pages
JOIN glpi_plugin_formvalidation_itemtypes on glpi_plugin_formvalidation_itemtypes.id=glpi_plugin_formvalidation_pages.itemtypes_id
WHERE glpi_plugin_formvalidation_itemtypes.itemtype = '".$obj->getType()."' AND is_active=1 ".
getEntitiesRestrictRequest( 'AND', 'glpi_plugin_formvalidation_pages', '', $entity_restrict, true);

foreach ($DB->request( $query ) as $page) {
$validations['pages_id']=$page['id']; // normaly there is only one page
$validations['itemtype']=$page['itemtype']; // normaly there is only one page

$query = "SELECT * FROM glpi_plugin_formvalidation_forms WHERE is_createitem=$is_createitem AND pages_id = ".$page['id'];

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

$query = "SELECT * FROM glpi_plugin_formvalidation_fields WHERE forms_id = ".$form['id'];
foreach ($DB->request( $query ) as $field) {
$validations['forms'][$form['id']]['fields'][$field['id']] = Toolbox::stripslashes_deep( $field );
}
}
}
}
echo json_encode( $validations, JSON_HEX_APOS | JSON_HEX_QUOT );

<?php
/*
* -------------------------------------------------------------------------
Form Validation plugin
Copyright (C) 2016 by Raynet SAS a company of A.Raymond Network.
http://www.araymond.com
-------------------------------------------------------------------------
LICENSE
This file is part of Form Validation plugin for GLPI.
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

$AJAX_INCLUDE = 1;
include ('../../../inc/includes.php');

// Send UTF8 Headers
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();

$config = PluginFormvalidationConfig::getInstance();

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

// from user session
$validations['config']['editmode']=$_SESSION['glpiformvalidationeditmode'];

$is_createitem = 0; // by default

$obj = getItemForItemtype( $_GET['name'] );
if ($obj) {
if ($_GET['id'] > 0) {
$obj->getFromDB( $_GET['id'] );
$entity_restrict = 0; // by default if $obj doesn't have entities_id in table
if (isset($obj->fields['entities_id'])) {
$entity_restrict = $obj->fields['entities_id'];
}
} else {
$is_createitem = 1;
$entity_restrict = $_SESSION['glpiactive_entity'];
}

$query = $DB->request([
'SELECT' => ['glpi_plugin_formvalidation_pages.*','glpi_plugin_formvalidation_itemtypes.name'],
'FROM' => 'glpi_plugin_formvalidation_pages',
'INNER JOIN' => ['glpi_plugin_formvalidation_itemtypes' =>
['FKEY' =>
[
'glpi_plugin_formvalidation_pages' => 'itemtypes_id',
'glpi_plugin_formvalidation_itemtypes' => 'id'
]
]
],
['AND' => ['glpi_plugin_formvalidation_itemtypes.name'=>$obj->getType(), 'is_active' => 1, getEntitiesRestrictCriteria('glpi_plugin_formvalidation_pages', '', $entity_restrict, true)]]

]
);
foreach ($query as $page) {
$validations['pages_id']=$page['id']; // normaly there is only one page
//$validations['itemtype']=$page['itemtype']; // normaly there is only one page
$validations['itemtype']=$page['name']; // normaly there is only one page

foreach ($DB->request('glpi_plugin_formvalidation_forms', ['AND'=>['is_createitem' => $is_createitem, 'pages_id' => $page['id']]]) as $form) {
$validations['forms'][$form['id']]= Toolbox::stripslashes_deep( $form );
$validations['forms'][$form['id']]['fields'] = []; // needed in case this form has no fields
foreach ($DB->request('glpi_plugin_formvalidation_fields', ['forms_id' => $form['id']]) as $field) {
$validations['forms'][$form['id']]['fields'][$field['id']] = Toolbox::stripslashes_deep( $field );
}
}
}
}
echo json_encode( $validations, JSON_HEX_APOS | JSON_HEX_QUOT );

126 changes: 63 additions & 63 deletions ajax/getLocales.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
<?php
/*
* -------------------------------------------------------------------------
Form Validation plugin
Copyright (C) 2016 by Raynet SAS a company of A.Raymond Network.
http://www.araymond.com
-------------------------------------------------------------------------
LICENSE
This file is part of Form Validation plugin for GLPI.
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

$AJAX_INCLUDE = 1;
include ('../../../inc/includes.php');

// Send UTF8 Headers
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();

if (!isset($LANG['plugin_formvalidation'])) {
$dir = GLPI_ROOT . "/plugins/formvalidation/locales/";
// try to load en_GB default language
// to be sure that it will default to english if user's language
// can't be found
if (file_exists($dir . "en_GB.php")) {
include ($dir . "en_GB.php");
}
// and then try to load user's own language
if (file_exists($dir.$_SESSION["glpilanguage"].'.php')) {
include ($dir.$_SESSION["glpilanguage"].'.php');
}
}

// 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]")
];

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

echo json_encode( $localization, JSON_HEX_APOS | JSON_HEX_QUOT );

<?php
/*
* -------------------------------------------------------------------------
Form Validation plugin
Copyright (C) 2016 by Raynet SAS a company of A.Raymond Network.
http://www.araymond.com
-------------------------------------------------------------------------
LICENSE
This file is part of Form Validation plugin for GLPI.
This file is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

$AJAX_INCLUDE = 1;
include ('../../../inc/includes.php');

// Send UTF8 Headers
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();

if (!isset($LANG['plugin_formvalidation'])) {
$dir = GLPI_ROOT . "/plugins/formvalidation/locales/";
// try to load en_GB default language
// to be sure that it will default to english if user's language
// can't be found
if (file_exists($dir . "en_GB.php")) {
include ($dir . "en_GB.php");
}
// and then try to load user's own language
if (file_exists($dir.$_SESSION["glpilanguage"].'.php')) {
include ($dir.$_SESSION["glpilanguage"].'.php');
}
}

// 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]")
];

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

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

0 comments on commit 5f2a28d

Please sign in to comment.