-
Notifications
You must be signed in to change notification settings - Fork 125
/
hiddenfield.class.php
129 lines (111 loc) · 3.75 KB
/
hiddenfield.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator 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.
*
* Formcreator 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 Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @author Thierry Bugier
* @author Jérémy Moreau
* @copyright Copyright © 2011 - 2018 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/
class PluginFormcreatorHiddenField extends PluginFormcreatorField
{
public function isPrerequisites() {
return true;
}
public function show($canEdit = true) {
$id = $this->fields['id'];
$rand = mt_rand();
$fieldName = 'formcreator_field_' . $id;
$domId = $fieldName . '_' . $rand;
$defaultValue = Html::cleanInputText($this->fields['default_values']);
echo '<input type="hidden" class="form-control"
name="' . $fieldName . '"
id="' . $domId . '"
value="' . $defaultValue . '" />' . PHP_EOL;
}
public function serializeValue() {
return $this->value;
}
public function deserializeValue($value) {
$this->value = $value;
}
public function getValueForDesign() {
return $this->value;
}
public function isValid() {
return true;
}
public static function getName() {
return _n('Hidden field', 'Hidden fields', 1);
}
public function getValueForTargetText() {
return str_replace("\n", '\r\n', Toolbox::addslashes_deep($this->value));
}
public function getDocumentsForTarget() {
return [];;
}
public static function getPrefs() {
return [
'required' => 0,
'default_values' => 1,
'values' => 0,
'range' => 0,
'show_empty' => 0,
'regex' => 0,
'show_type' => 0,
'dropdown_value' => 0,
'glpi_objects' => 0,
'ldap_values' => 0,
];
}
public function parseAnswerValues($input) {
$key = 'formcreator_field_' . $this->fields['id'];
if (!is_string($input[$key])) {
return false;
}
$this->value = $input[$key];
return true;
}
public static function getJSFields() {
$prefs = self::getPrefs();
return "tab_fields_fields['hidden'] = 'showFields(" . implode(', ', $prefs) . ");';";
}
public function equals($value) {
return $this->value == $value;
}
public function notEquals($value) {
return !$this->equals($value);
}
public function greaterThan($value) {
return $this->value > $value;
}
public function lessThan($value) {
return !$this->greaterThan($value) && !$this->equals($value);
}
public function isAnonymousFormCompatible() {
return true;
}
}