Skip to content

Commit b8497fa

Browse files
committed
fix: improve quote escaping
fix show / hide of fields under conditions Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 5c01a4e commit b8497fa

File tree

6 files changed

+34
-28
lines changed

6 files changed

+34
-28
lines changed

inc/fields.class.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ public static function isVisible($id, $fields) {
183183
}
184184

185185
// TODO: find the best behavior if the question does not exists
186-
$conditionQuestion = new PluginFormcreatorQuestion();
187-
$conditionQuestion->getFromDB($condition['field']);
188186
$conditionField = $fields[$condition['field']];
189187

190188
switch ($condition['operator']) {

inc/fields/checkboxesfield.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function displayField($canEdit = true) {
6060
'name' => htmlentities($fieldName, ENT_QUOTES) . '[]',
6161
'value' => htmlentities($value, ENT_QUOTES),
6262
'zero_on_empty' => false,
63-
'checked' => in_array($value, $this->value)
63+
'checked' => in_array($value, $this->value)
6464
]);
6565
echo '<label for="' . $domId . '_' . $i . '">';
6666
echo '&nbsp;' . $value;
@@ -124,7 +124,7 @@ public function parseAnswerValues($input) {
124124
}
125125
}
126126

127-
$this->value = $input[$key];
127+
$this->value = Toolbox::stripslashes_deep($input[$key]);
128128
return true;
129129
}
130130

@@ -208,7 +208,7 @@ public function getValueForTargetText($richText) {
208208

209209
foreach ($this->value as $input) {
210210
if (in_array($input, $values)) {
211-
$value[] = Toolbox::addslashes_deep($input);
211+
$value[] = $input;
212212
}
213213
}
214214

inc/fields/radiosfield.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function displayField($canEdit = true) {
5959
echo '<input type="radio" class="form-control"
6060
name="' . $fieldName . '"
6161
id="' . $domId . '_' . $i . '"
62-
value="' . addslashes($value) . '"' . $checked . ' /> ';
62+
value="' . $value . '"' . $checked . ' /> ';
6363
echo '<label for="' . $domId . '_' . $i . '">';
6464
echo $value;
6565
echo '</label>';
@@ -117,7 +117,7 @@ public function parseAnswerValues($input) {
117117
return true;
118118
}
119119

120-
$this->value = $input[$key];
120+
$this->value = Toolbox::stripslashes_deep($input[$key]);
121121
return true;
122122
}
123123

@@ -149,7 +149,7 @@ public function serializeValue() {
149149
return '';
150150
}
151151

152-
return $this->value;
152+
return Toolbox::addslashes_deep($this->value);
153153
}
154154

155155
public function deserializeValue($value) {
@@ -167,7 +167,7 @@ public function getValueForDesign() {
167167
}
168168

169169
public function getValueForTargetText($richText) {
170-
return Toolbox::addslashes_deep($this->value);
170+
return $this->value;
171171
}
172172

173173
public function getDocumentsForTarget() {

inc/fields/textfield.class.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function serializeValue() {
6161
return '';
6262
}
6363

64-
return $this->value;
64+
return Toolbox::addslashes_deep($this->value);
6565
}
6666

6767
public function deserializeValue($value) {
@@ -188,8 +188,9 @@ public function parseAnswerValues($input) {
188188
return false;
189189
}
190190

191-
$this->value = str_replace('\r\n', "\r\n", $input[$key]);
192-
return true;
191+
$this->value = str_replace('\r\n', "\r\n", $input[$key]);
192+
$this->value = Toolbox::stripslashes_deep($this->value);
193+
return true;
193194
}
194195

195196
public function getEmptyParameters() {
@@ -218,15 +219,15 @@ public function getEmptyParameters() {
218219
}
219220

220221
public function equals($value) {
221-
return $this->value == $value;
222+
return Toolbox::stripslashes_deep($this->value) == $value;
222223
}
223224

224225
public function notEquals($value) {
225226
return !$this->equals($value);
226227
}
227228

228229
public function greaterThan($value) {
229-
return $this->value > $value;
230+
return Toolbox::stripslashes_deep($this->value) > $value;
230231
}
231232

232233
public function lessThan($value) {

inc/formanswer.class.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ public function showForm($ID, $options = []) {
551551
$last_section = '';
552552
$questionsCount = $questions->count();
553553
$fields = [];
554-
while ($question_line = $questions->next()) {
554+
foreach ($questions as $question_line) {
555555
$question = new PluginFormcreatorQuestion();
556556
$question->getFromDB($question_line['id']);
557557
$fields[$question_line['id']] = PluginFormcreatorFields::getFieldInstance(
@@ -560,27 +560,28 @@ public function showForm($ID, $options = []) {
560560
);
561561
$fields[$question_line['id']]->deserializeValue($question_line['answer']);
562562
}
563-
$questions->rewind();
564-
while ($question_line = $questions->current()) {
563+
foreach ($questions as $question_line) {
565564
// Get and display current section if needed
566565
if ($last_section != $question_line['section_name']) {
567566
echo '<h2>'.$question_line['section_name'].'</h2>';
568567
$last_section = $question_line['section_name'];
569568
}
570569

571-
if ($canEdit
572-
|| ($question_line['fieldtype'] != "description"
573-
&& $question_line['fieldtype'] != "hidden")
574-
) {
575-
// if (PluginFormcreatorFields::isVisible($question_line['id'], $fields)) {
576-
// }
570+
if ($canEdit) {
577571
$fields[$question_line['id']]->show($canEdit);
572+
} else {
573+
if (($question_line['fieldtype'] != "description" && $question_line['fieldtype'] != "hidden")) {
574+
if (PluginFormcreatorFields::isVisible($question_line['id'], $fields)) {
575+
$fields[$question_line['id']]->show($canEdit);
576+
}
577+
}
578578
}
579-
$questions->next();
580579
}
581-
echo Html::scriptBlock('$(function() {
582-
formcreatorShowFields($("form[name=\'form\']"));
583-
})');
580+
if ($canEdit) {
581+
echo Html::scriptBlock('$(function() {
582+
formcreatorShowFields($("form[name=\'form\']"));
583+
})');
584+
}
584585

585586
//add requester info
586587
echo '<div class="form-group">';

inc/question_condition.class.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ public function export($remove_uuid = false) {
157157
return $condition;
158158
}
159159

160+
/**
161+
* get show / hide conditions for a question
162+
*
163+
* @param int $questionId
164+
* @return array
165+
*/
160166
public function getConditionsFromQuestion($questionId) {
161167
global $DB;
162168

@@ -271,4 +277,4 @@ public function getConditionHtml($form_id, $questionId = 0, $isFirst = false) {
271277

272278
return $html;
273279
}
274-
}
280+
}

0 commit comments

Comments
 (0)