|
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 | + |
0 commit comments