Skip to content

Commit

Permalink
fix(targetticket,targetchange): ticket and change rendering without r…
Browse files Browse the repository at this point in the history
…ich text mode

fix pluginsGLPI#847
  • Loading branch information
btry committed Dec 26, 2017
1 parent d086006 commit 226c965
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
13 changes: 7 additions & 6 deletions inc/form_answer.class.php
Expand Up @@ -907,7 +907,7 @@ public function generateTarget() {
$targetObject = new $target['itemtype'];
$targetObject->getFromDB($target['items_id']);
$generatedTarget = $targetObject->save($this);
if ($generatedTarget === null) {
if ($generatedTarget === false) {
$success = false;
break;
}
Expand Down Expand Up @@ -962,13 +962,14 @@ public function getFullForm() {

$question_no = 0;
$output = '';
$eol = '\r\n';

if ($CFG_GLPI['use_rich_text']) {
$output .= '<h1>' . __('Form data', 'formcreator') . '</h1>';
} else {
$output .= __('Form data', 'formcreator') . PHP_EOL;
$output .= __('Form data', 'formcreator') . $eol;
$output .= '=================';
$output .= PHP_EOL . PHP_EOL;
$output .= $eol . $eol;
}

// retrieve answers
Expand All @@ -995,9 +996,9 @@ public function getFullForm() {
if ($CFG_GLPI['use_rich_text']) {
$output .= '<h2>'.$question_line['section_name'].'</h2>';
} else {
$output .= PHP_EOL.$question_line['section_name'].PHP_EOL;
$output .= $eol . $question_line['section_name'] . $eol;
$output .= '---------------------------------';
$output .= PHP_EOL;
$output .= $eol;
}
$last_section = $question_line['section_name'];
}
Expand All @@ -1020,7 +1021,7 @@ public function getFullForm() {
$output .= '</div>';
} else {
$output .= $question_no . ') ##question_' . $question_line['id'] . '## : ';
$output .= '##answer_' . $question_line['id'] . '##' . PHP_EOL . PHP_EOL;
$output .= '##answer_' . $question_line['id'] . '##' . $eol . $eol;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions inc/targetbase.class.php
Expand Up @@ -767,8 +767,8 @@ protected function parseTags($content, PluginFormcreatorForm_Answer $formanswer,
}

if ($question_line['fieldtype'] !== 'file') {
$content = str_replace('##question_' . $id . '##', $name, $content);
$content = str_replace('##answer_' . $id . '##', $value, $content);
$content = str_replace('##question_' . $id . '##', addslashes($name), $content);
$content = str_replace('##answer_' . $id . '##', addslashes($value), $content);
} else {
if (strpos($content, '##answer_' . $id . '##') !== false) {
$content = str_replace('##question_' . $id . '##', $name, $content);
Expand Down
23 changes: 18 additions & 5 deletions inc/targetchange.class.php
Expand Up @@ -888,7 +888,7 @@ public function prepareInputForUpdate($input) {
*
* @param PluginFormcreatorForm_Answer $formanswer Answers previously saved
*
* @return Change|null generated change
* @return Change|false generated change
*/
public function save(PluginFormcreatorForm_Answer $formanswer) {
global $DB, $CFG_GLPI;
Expand Down Expand Up @@ -961,6 +961,8 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
} else {
$data[$changeField] = $this->fields['comment'];
}
$data[$changeField] = addslashes($data[$changeField]);
$data[$changeField] = str_replace("\r\n", '\r\n', $data[$changeField]);
if (strpos($data[$changeField], '##FULLFORM##') !== false) {
$data[$changeField] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data[$changeField]);
} else {
Expand All @@ -969,7 +971,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
$data['content'] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data['content']);
}
}
$data[$changeField] = addslashes($this->parseTags($data[$changeField], $formanswer));
$data[$changeField] = $this->parseTags($data[$changeField], $formanswer);
}

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

// Define due date
if ($this->fields['due_date_question'] !== null) {
$found = $answer->find('plugin_formcreator_formanwers_id = '.$formanswer->fields['id'].
' AND plugin_formcreator_questions_id = '.$this->fields['due_date_question']);
$date = array_shift($found);
$request = [
'FROM' => $answer::getTable(),
'WHERE' => [
'AND' => [
$formanswer::getForeignKeyField() => $formanswer->fields['id'],
PluginFormcreatorQuestion::getForeignKeyField() => $this->fields['due_date_question'],
],
],
];
$iterator = $DB->request($request);
if ($iterator->count() > 0) {
$iterator->rewind();
$date = $iterator->current();
}
} else {
$date = null;
}
Expand Down
7 changes: 4 additions & 3 deletions inc/targetticket.class.php
Expand Up @@ -979,7 +979,7 @@ public function pre_deleteItem() {
*
* @param PluginFormcreatorForm_Answer $formanswer Answers previously saved
*
* @return Ticket|null Generated ticket if success, null otherwise
* @return Ticket|false Generated ticket if success, null otherwise
*/
public function save(PluginFormcreatorForm_Answer $formanswer) {
global $DB, $CFG_GLPI;
Expand Down Expand Up @@ -1072,7 +1072,8 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
$data['name'] = $this->fields['name'];
$data['name'] = addslashes($this->parseTags($data['name'], $formanswer));

$data['content'] = $this->fields['comment'];
$data['content'] = addslashes($this->fields['comment']);
$data['content'] = str_replace("\r\n", '\r\n', $data['content']);
if (strpos($data['content'], '##FULLFORM##') !== false) {
$data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']);
} else {
Expand All @@ -1081,7 +1082,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
$data['content'] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data['content']);
}
}
$data['content'] = addslashes($this->parseTags($data['content'], $formanswer));
$data['content'] = $this->parseTags($data['content'], $formanswer);
if ($CFG_GLPI['use_rich_text']) {
$data['content'] = htmlentities($data['content']);
}
Expand Down

0 comments on commit 226c965

Please sign in to comment.