Skip to content

Commit

Permalink
fix(target): fix HTML issues in generated tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Dec 15, 2017
1 parent d563c3f commit 278c628
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
24 changes: 17 additions & 7 deletions inc/form_answer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ public function saveAnswers($data) {
* @return null|string
*/
private function transformAnswerValue(PluginFormcreatorQuestion $question, $value = null) {
global $CFG_GLPI;

// unset the answer value
$answer_value = null;
$form = $question->getForm();
Expand All @@ -766,15 +768,23 @@ private function transformAnswerValue(PluginFormcreatorQuestion $question, $valu
if (isset($value)) {
// If the answer is set, check if it is an array (then implode id).
if ($value !== null) {
$answer_value = $value;
if (is_array(json_decode($answer_value, JSON_UNESCAPED_UNICODE))) {
$answer_value = json_decode($answer_value);
foreach ($answer_value as $key => $value) {
$answer_value[$key] = $value;
if ($question->getField('fieldtype') != 'textarea') {
$answer_value = $value;
if (is_array(json_decode($answer_value, JSON_UNESCAPED_UNICODE))) {
$answer_value = json_decode($answer_value);
foreach ($answer_value as $key => $value) {
$answer_value[$key] = $value;
}
$answer_value = json_encode($answer_value, JSON_UNESCAPED_UNICODE);
} else {
$answer_value = str_replace('\\r\\n', '\n', $answer_value);
}
$answer_value = json_encode($answer_value, JSON_UNESCAPED_UNICODE);
} else {
$answer_value = str_replace('\\r\\n', '\n', $answer_value);
if ($CFG_GLPI['use_rich_text']) {
$answer_value = html_entity_decode($value);
} else {
$answer_value = $value;
}
}
} else {
$answer_value = '';
Expand Down
7 changes: 6 additions & 1 deletion inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ public function prepareInputForUpdate($input) {
* @return Change|null generated change
*/
public function save(PluginFormcreatorForm_Answer $formanswer) {
global $DB;
global $DB, $CFG_GLPI;

// Prepare actors structures for creation of the ticket
$this->requesters = [
Expand Down Expand Up @@ -963,6 +963,11 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
}
if (strpos($data[$changeField], '##FULLFORM##') !== false) {
$data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data[$changeField]);
} else {
if ($CFG_GLPI['use_rich_text']) {
// replace HTML P tags with DIV tags
$data['content'] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data['content']);
}
}
$data[$changeField] = addslashes($this->parseTags($data[$changeField], $formanswer));
}
Expand Down
5 changes: 5 additions & 0 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,11 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
$data['content'] = $this->fields['comment'];
if (strpos($data['content'], '##FULLFORM##') !== false) {
$data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']);
} else {
if ($CFG_GLPI['use_rich_text']) {
// replace HTML P tags with DIV tags
$data['content'] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data['content']);
}
}
$data['content'] = addslashes($this->parseTags($data['content'], $formanswer));
if ($CFG_GLPI['use_rich_text']) {
Expand Down

0 comments on commit 278c628

Please sign in to comment.