Skip to content

Commit

Permalink
fix(targetchange): rendering with rich text
Browse files Browse the repository at this point in the history
Signed-off-by: btry <tbugier@teclib.com>
  • Loading branch information
btry committed Nov 2, 2018
1 parent bccec57 commit a86f6da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions inc/form_answer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,14 +1061,16 @@ public function getForm() {
*
* @return String Full form questions and answers to be print
*/
public function getFullForm() {
public function getFullForm($disableRichText = false) {
global $CFG_GLPI, $DB;

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

if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) {
if ($disableRichText === false
&& (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']))
{
$output .= '<h1>' . __('Form data', 'formcreator') . '</h1>';
} else {
$output .= __('Form data', 'formcreator') . $eol;
Expand Down Expand Up @@ -1109,7 +1111,9 @@ public function getFullForm() {

// Get and display current section if needed
if ($last_section != $question_line['section_name']) {
if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) {
if ($disableRichText === false
&& (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']))
{
$output .= '<h2>' . Toolbox::addslashes_deep($question_line['section_name']) . '</h2>';
} else {
$output .= $eol . Toolbox::addslashes_deep($question_line['section_name']) . $eol;
Expand All @@ -1130,7 +1134,9 @@ public function getFullForm() {

if ($question_line['fieldtype'] != 'description') {
$question_no++;
if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) {
if ($disableRichText === false
&& (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']))
{
$output .= '<div>';
$output .= '<b>' . $question_no . ') ##question_' . $question_line['id'] . '## : </b>';
$output .= '##answer_' . $question_line['id'] . '##';
Expand Down
3 changes: 2 additions & 1 deletion inc/targetchange.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -987,12 +987,13 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
}
if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) {
// replace HTML P tags with DIV tags
$data[$changeField] = str_replace(['<p>', '</p>'], ['<div>', '</div>'], $data[$changeField]);
$data[$changeField] = str_replace('\r\n', "\r\n", $data[$changeField]);
}

$data[$changeField] = $this->parseTags($data[$changeField], $formanswer);

// This target does not supports rich text
$data[$changeField] = str_replace('<br>', '\r\n', $data[$changeField]);
$data[$changeField] = strip_tags($data[$changeField], '<p>');
$data[$changeField] = str_replace('<p>', '', $data[$changeField]);
$data[$changeField] = str_replace('</p>', '\r\n', $data[$changeField]);
Expand Down

0 comments on commit a86f6da

Please sign in to comment.