Skip to content

Commit d723a47

Browse files
committed
fix(targetticket,targetchange): ticket and change rendering without rich text mode
fix #847
1 parent e41a86d commit d723a47

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

inc/form_answer.class.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ public function generateTarget() {
956956
$targetObject = new $target['itemtype'];
957957
$targetObject->getFromDB($target['items_id']);
958958
$generatedTarget = $targetObject->save($this);
959-
if ($generatedTarget === null) {
959+
if ($generatedTarget === false) {
960960
$success = false;
961961
break;
962962
}
@@ -1011,13 +1011,14 @@ public function getFullForm() {
10111011

10121012
$question_no = 0;
10131013
$output = '';
1014+
$eol = '\r\n';
10141015

10151016
if ($CFG_GLPI['use_rich_text']) {
10161017
$output .= '<h1>' . __('Form data', 'formcreator') . '</h1>';
10171018
} else {
1018-
$output .= __('Form data', 'formcreator') . PHP_EOL;
1019+
$output .= __('Form data', 'formcreator') . $eol;
10191020
$output .= '=================';
1020-
$output .= PHP_EOL . PHP_EOL;
1021+
$output .= $eol . $eol;
10211022
}
10221023

10231024
// retrieve answers
@@ -1044,9 +1045,9 @@ public function getFullForm() {
10441045
if ($CFG_GLPI['use_rich_text']) {
10451046
$output .= '<h2>'.$question_line['section_name'].'</h2>';
10461047
} else {
1047-
$output .= PHP_EOL.$question_line['section_name'].PHP_EOL;
1048+
$output .= $eol . $question_line['section_name'] . $eol;
10481049
$output .= '---------------------------------';
1049-
$output .= PHP_EOL;
1050+
$output .= $eol;
10501051
}
10511052
$last_section = $question_line['section_name'];
10521053
}
@@ -1069,7 +1070,7 @@ public function getFullForm() {
10691070
$output .= '</div>';
10701071
} else {
10711072
$output .= $question_no . ') ##question_' . $question_line['id'] . '## : ';
1072-
$output .= '##answer_' . $question_line['id'] . '##' . PHP_EOL . PHP_EOL;
1073+
$output .= '##answer_' . $question_line['id'] . '##' . $eol . $eol;
10731074
}
10741075
}
10751076
}

inc/targetbase.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer,
767767
}
768768

769769
if ($question_line['fieldtype'] !== 'file') {
770-
$content = str_replace('##question_' . $id . '##', $name, $content);
771-
$content = str_replace('##answer_' . $id . '##', $value, $content);
770+
$content = str_replace('##question_' . $id . '##', addslashes($name), $content);
771+
$content = str_replace('##answer_' . $id . '##', addslashes($value), $content);
772772
} else {
773773
if (strpos($content, '##answer_' . $id . '##') !== false) {
774774
$content = str_replace('##question_' . $id . '##', $name, $content);

inc/targetchange.class.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ public function prepareInputForUpdate($input) {
888888
*
889889
* @param PluginFormcreatorForm_Answer $formanswer Answers previously saved
890890
*
891-
* @return Change|null generated change
891+
* @return Change|false generated change
892892
*/
893893
public function save(PluginFormcreatorForm_Answer $formanswer) {
894894
global $DB, $CFG_GLPI;
@@ -961,6 +961,8 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
961961
} else {
962962
$data[$changeField] = $this->fields['comment'];
963963
}
964+
$data[$changeField] = addslashes($data[$changeField]);
965+
$data[$changeField] = str_replace("\r\n", '\r\n', $data[$changeField]);
964966
if (strpos($data[$changeField], '##FULLFORM##') !== false) {
965967
$data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data[$changeField]);
966968
} else {
@@ -969,7 +971,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
969971
$data['content'] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data['content']);
970972
}
971973
}
972-
$data[$changeField] = addslashes($this->parseTags($data[$changeField], $formanswer));
974+
$data[$changeField] = $this->parseTags($data[$changeField], $formanswer);
973975
}
974976

975977
$data['_users_id_recipient'] = $_SESSION['glpiID'];
@@ -1071,9 +1073,20 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
10711073

10721074
// Define due date
10731075
if ($this->fields['due_date_question'] !== null) {
1074-
$found = $answer->find('plugin_formcreator_formanwers_id = '.$formanswer->fields['id'].
1075-
' AND plugin_formcreator_questions_id = '.$this->fields['due_date_question']);
1076-
$date = array_shift($found);
1076+
$request = [
1077+
'FROM' => $answer::getTable(),
1078+
'WHERE' => [
1079+
'AND' => [
1080+
$formanswer::getForeignKeyField() => $formanswer->fields['id'],
1081+
PluginFormcreatorQuestion::getForeignKeyField() => $this->fields['due_date_question'],
1082+
],
1083+
],
1084+
];
1085+
$iterator = $DB->request($request);
1086+
if ($iterator->count() > 0) {
1087+
$iterator->rewind();
1088+
$date = $iterator->current();
1089+
}
10771090
} else {
10781091
$date = null;
10791092
}

inc/targetticket.class.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ public function pre_deleteItem() {
979979
*
980980
* @param PluginFormcreatorForm_Answer $formanswer Answers previously saved
981981
*
982-
* @return Ticket|null Generated ticket if success, null otherwise
982+
* @return Ticket|false Generated ticket if success, null otherwise
983983
*/
984984
public function save(PluginFormcreatorForm_Answer $formanswer) {
985985
global $DB, $CFG_GLPI;
@@ -1072,7 +1072,8 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
10721072
$data['name'] = $this->fields['name'];
10731073
$data['name'] = addslashes($this->parseTags($data['name'], $formanswer));
10741074

1075-
$data['content'] = $this->fields['comment'];
1075+
$data['content'] = addslashes($this->fields['comment']);
1076+
$data['content'] = str_replace("\r\n", '\r\n', $data['content']);
10761077
if (strpos($data['content'], '##FULLFORM##') !== false) {
10771078
$data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']);
10781079
} else {
@@ -1081,7 +1082,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
10811082
$data['content'] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data['content']);
10821083
}
10831084
}
1084-
$data['content'] = addslashes($this->parseTags($data['content'], $formanswer));
1085+
$data['content'] = $this->parseTags($data['content'], $formanswer);
10851086
if ($CFG_GLPI['use_rich_text']) {
10861087
$data['content'] = htmlentities($data['content']);
10871088
}

0 commit comments

Comments
 (0)