Skip to content

Commit 278c628

Browse files
committed
fix(target): fix HTML issues in generated tickets
1 parent d563c3f commit 278c628

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

inc/form_answer.class.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ public function saveAnswers($data) {
757757
* @return null|string
758758
*/
759759
private function transformAnswerValue(PluginFormcreatorQuestion $question, $value = null) {
760+
global $CFG_GLPI;
761+
760762
// unset the answer value
761763
$answer_value = null;
762764
$form = $question->getForm();
@@ -766,15 +768,23 @@ private function transformAnswerValue(PluginFormcreatorQuestion $question, $valu
766768
if (isset($value)) {
767769
// If the answer is set, check if it is an array (then implode id).
768770
if ($value !== null) {
769-
$answer_value = $value;
770-
if (is_array(json_decode($answer_value, JSON_UNESCAPED_UNICODE))) {
771-
$answer_value = json_decode($answer_value);
772-
foreach ($answer_value as $key => $value) {
773-
$answer_value[$key] = $value;
771+
if ($question->getField('fieldtype') != 'textarea') {
772+
$answer_value = $value;
773+
if (is_array(json_decode($answer_value, JSON_UNESCAPED_UNICODE))) {
774+
$answer_value = json_decode($answer_value);
775+
foreach ($answer_value as $key => $value) {
776+
$answer_value[$key] = $value;
777+
}
778+
$answer_value = json_encode($answer_value, JSON_UNESCAPED_UNICODE);
779+
} else {
780+
$answer_value = str_replace('\\r\\n', '\n', $answer_value);
774781
}
775-
$answer_value = json_encode($answer_value, JSON_UNESCAPED_UNICODE);
776782
} else {
777-
$answer_value = str_replace('\\r\\n', '\n', $answer_value);
783+
if ($CFG_GLPI['use_rich_text']) {
784+
$answer_value = html_entity_decode($value);
785+
} else {
786+
$answer_value = $value;
787+
}
778788
}
779789
} else {
780790
$answer_value = '';

inc/targetchange.class.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ public function prepareInputForUpdate($input) {
891891
* @return Change|null generated change
892892
*/
893893
public function save(PluginFormcreatorForm_Answer $formanswer) {
894-
global $DB;
894+
global $DB, $CFG_GLPI;
895895

896896
// Prepare actors structures for creation of the ticket
897897
$this->requesters = [
@@ -963,6 +963,11 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
963963
}
964964
if (strpos($data[$changeField], '##FULLFORM##') !== false) {
965965
$data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data[$changeField]);
966+
} else {
967+
if ($CFG_GLPI['use_rich_text']) {
968+
// replace HTML P tags with DIV tags
969+
$data['content'] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data['content']);
970+
}
966971
}
967972
$data[$changeField] = addslashes($this->parseTags($data[$changeField], $formanswer));
968973
}

inc/targetticket.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,11 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
10751075
$data['content'] = $this->fields['comment'];
10761076
if (strpos($data['content'], '##FULLFORM##') !== false) {
10771077
$data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']);
1078+
} else {
1079+
if ($CFG_GLPI['use_rich_text']) {
1080+
// replace HTML P tags with DIV tags
1081+
$data['content'] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data['content']);
1082+
}
10781083
}
10791084
$data['content'] = addslashes($this->parseTags($data['content'], $formanswer));
10801085
if ($CFG_GLPI['use_rich_text']) {

0 commit comments

Comments
 (0)