Skip to content

Commit b7c92da

Browse files
committed
Merge branch 'release/2.8.6'
2 parents 276c492 + bf8d956 commit b7c92da

17 files changed

+190
-117
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
<a name="2.8.6"></a>
2+
## [2.8.6](https://github.com/pluginsglpi/formcreator/compare/v2.8.5...v2.8.6) (2019-11-07)
3+
4+
5+
### Bug Fixes
6+
7+
* **form:** deny access if form not enabled ([0290a97](https://github.com/pluginsglpi/formcreator/commit/0290a97))
8+
* **form:** don't access deleted forms ([6169412](https://github.com/pluginsglpi/formcreator/commit/6169412))
9+
* **formanswer:** bad sql ([023a60e](https://github.com/pluginsglpi/formcreator/commit/023a60e))
10+
* loading resources for anonymous forms ([58b7141](https://github.com/pluginsglpi/formcreator/commit/58b7141)), closes [#1535](https://github.com/pluginsglpi/formcreator/issues/1535)
11+
* **formanswer:** canViewItem with group ([4c22600](https://github.com/pluginsglpi/formcreator/commit/4c22600))
12+
* unexpected redirection while editing a ticket as post-only + service catalog ([63f3cee](https://github.com/pluginsglpi/formcreator/commit/63f3cee)), closes [#1557](https://github.com/pluginsglpi/formcreator/issues/1557)
13+
* **question_condition:** better performance ([0fc6aea](https://github.com/pluginsglpi/formcreator/commit/0fc6aea))
14+
* **targetticket,targetchange:** return value of save() method ([cbc2249](https://github.com/pluginsglpi/formcreator/commit/cbc2249))
15+
16+
17+
118
<a name="2.8.5"></a>
219
## [2.8.5](https://github.com/pluginsglpi/formcreator/compare/v2.8.4...v2.8.5) (2019-09-02)
320

ajax/showfields.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333

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

36-
$visibility = PluginFormcreatorFields::updateVisibility($_POST);
36+
try {
37+
$visibility = PluginFormcreatorFields::updateVisibility($_POST);
38+
} catch (Exception $e) {
39+
http_response_code(500);
40+
exit();
41+
}
3742
echo json_encode($visibility);
3843
exit();

front/formdisplay.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
&& is_numeric($_REQUEST['id'])) {
4848

4949
if ($form->getFromDB((int) $_REQUEST['id'])) {
50+
if ($form->fields['is_active'] == '0' || $form->fields['is_deleted'] != '0') {
51+
Html::displayNotFoundError();
52+
}
5053
if ($form->fields['access_rights'] != PluginFormcreatorForm::ACCESS_PUBLIC) {
5154
Session::checkLoginUser();
5255
if (!$form->checkEntity(true)) {

hook.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ function plugin_formcreator_getCondition($itemtype) {
111111
if (count($groups) < 1) {
112112
$condition .= ")";
113113
} else {
114-
$groups = implode(',', $groups);
115-
$condition .= " OR `$table`.`groups_id_validator` IN ($groups) )";
114+
$groupIDs = [];
115+
foreach ($groups as $group) {
116+
$groupIDs[] = $group['id'];
117+
}
118+
$groupIDs = implode(',', $groupIDs);
119+
$condition .= " OR `$table`.`groups_id_validator` IN ($groupIDs) )";
116120
}
117121
return $condition;
118122
}

inc/common.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static function prepareBooleanKeywords($keywords) {
165165
preg_match_all('/"(?:\\\\.|[^\\\\"])*"|\S+/', $keywords, $matches);
166166
$matches = $matches[0];
167167
foreach ($matches as &$keyword) {
168-
if (strpos($keyword, '"') === 0) {
168+
if (strpos($keyword, '"') !== 0) {
169169
// keyword does not begins with a double quote (assume it does not ends with this char)
170170
$keyword .= '*';
171171
}

inc/fields.class.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,27 @@ public static function printAllTabFieldsForJS() {
129129
*/
130130
public static function isVisible($id, $fields) {
131131
/**
132-
* Keep track of questions being evaluated to detect infinite loops
132+
* Keep track of questions results and computation status
133+
* null = is beinc computed
134+
* true or false = result of a previous evaluation
135+
* not set = not evaluated yet and not being evaluated
133136
*/
134137
static $evalQuestion = [];
135-
if (isset($evalQuestion[$id])) {
136-
// TODO : how to deal a infinite loop while evaluating visibility of question ?
137-
return true;
138+
if (!isset($evalQuestion[$id])) {
139+
$evalQuestion[$id] = null;
140+
} else if ($evalQuestion[$id] !== null) {
141+
return $evalQuestion[$id];
142+
} else {
143+
throw new Exception("Infinite loop in show conditions evaluation");
138144
}
139-
$evalQuestion[$id] = $id;
140145

141146
$question = new PluginFormcreatorQuestion();
142147
$question->getFromDB($id);
143148
$conditions = [];
144149

145150
// If the field is always shown
146151
if ($question->getField('show_rule') == 'always') {
147-
unset($evalQuestion[$id]);
152+
$evalQuestion[$id] = true;
148153
return true;
149154
}
150155

@@ -154,7 +159,7 @@ public static function isVisible($id, $fields) {
154159
$questionConditions = $question_condition->getConditionsFromQuestion($questionId);
155160
if (count($questionConditions) < 1) {
156161
// No condition defined, then always show the question
157-
unset($evalQuestion[$id]);
162+
$evalQuestion[$id] = true;
158163
return true;
159164
}
160165

@@ -294,15 +299,15 @@ public static function isVisible($id, $fields) {
294299
$return = ($return xor $lowPrecedenceReturnPart);
295300
}
296301

297-
unset($evalQuestion[$id]);
298-
299302
if ($question->fields['show_rule'] == 'hidden') {
300303
// If the field is hidden by default, show it if condition is true
301-
return $return;
304+
$evalQuestion[$id] = $return;
302305
} else {
303306
// else show it if condition is false
304-
return !$return;
307+
$evalQuestion[$id] = !$return;
305308
}
309+
310+
return $evalQuestion[$id];
306311
}
307312

308313
/**

inc/fields/datetimefield.class.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ public static function getJSFields() {
121121

122122
public function equals($value) {
123123
if ($this->value === '') {
124-
$answer = '0000-00-00 00:00';
124+
$answer = '0000-00-00 00:00:00';
125125
} else {
126126
$answer = $this->value;
127127
}
128-
$answerDatetime = DateTime::createFromFormat("Y-m-d H:i", $answer);
129-
$compareDatetime = DateTime::createFromFormat("Y-m-d H:i", $value);
128+
$answerDatetime = DateTime::createFromFormat("Y-m-d H:i:s", $answer);
129+
$compareDatetime = DateTime::createFromFormat("Y-m-d H:i:s", $value);
130130
return $answerDatetime == $compareDatetime;
131131
}
132132

@@ -136,12 +136,12 @@ public function notEquals($value) {
136136

137137
public function greaterThan($value) {
138138
if (empty($this->value)) {
139-
$answer = '0000-00-00 00:00';
139+
$answer = '0000-00-00 00:00:00';
140140
} else {
141141
$answer = $this->value;
142142
}
143-
$answerDatetime = DateTime::createFromFormat("Y-m-d H:i", $answer);
144-
$compareDatetime = DateTime::createFromFormat("Y-m-d H:i", $value);
143+
$answerDatetime = DateTime::createFromFormat("Y-m-d H:i:s", $answer);
144+
$compareDatetime = DateTime::createFromFormat("Y-m-d H:i:s", $value);
145145
return $answerDatetime > $compareDatetime;
146146
}
147147

@@ -156,7 +156,7 @@ public function parseAnswerValues($input, $nonDestructive = false) {
156156
}
157157

158158
if ($input[$key] != ''
159-
&& DateTime::createFromFormat("Y-m-d H:i", $input[$key]) === false) {
159+
&& DateTime::createFromFormat("Y-m-d H:i:s", $input[$key]) === false) {
160160
return false;
161161
}
162162

inc/formanswer.class.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ public function canViewItem() {
111111
return true;
112112
}
113113
} else {
114-
if (in_array($row['items_id'], $groups)) {
115-
return true;
114+
foreach ($groups as $group) {
115+
if ($group['id'] == $row['items_id']) {
116+
return true;
117+
}
116118
}
117119
}
118120
}
@@ -1081,7 +1083,7 @@ public function generateTarget() {
10811083
$targetObject = new $target['itemtype'];
10821084
$targetObject->getFromDB($target['items_id']);
10831085
$generatedTarget = $targetObject->save($this);
1084-
if ($generatedTarget === false) {
1086+
if ($generatedTarget === null) {
10851087
$success = false;
10861088
break;
10871089
}

inc/targetchange.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ public function prepareInputForUpdate($input) {
932932
*
933933
* @param PluginFormcreatorFormAnswer $formanswer Answers previously saved
934934
*
935-
* @return Change|false generated change
935+
* @return Change|null generated change
936936
*/
937937
public function save(PluginFormcreatorFormAnswer $formanswer) {
938938
global $DB;
@@ -1031,7 +1031,7 @@ public function save(PluginFormcreatorFormAnswer $formanswer) {
10311031

10321032
// Create the target change
10331033
if (!$changeID = $change->add($data)) {
1034-
return false;
1034+
return null;
10351035
}
10361036

10371037
// Add tag if presents

inc/targetticket.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ public function pre_deleteItem() {
10461046
*
10471047
* @param PluginFormcreatorFormAnswer $formanswer Answers previously saved
10481048
*
1049-
* @return Ticket|false Generated ticket if success, null otherwise
1049+
* @return Ticket|null Generated ticket if success, null otherwise
10501050
*/
10511051
public function save(PluginFormcreatorFormAnswer $formanswer) {
10521052
global $DB, $CFG_GLPI;

locales/it_IT.mo

1.94 KB
Binary file not shown.

0 commit comments

Comments
 (0)