From c89a737a52e29dcf9b8460c1eda6a9dabcb0e98a Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Thu, 21 May 2015 21:05:55 +0000
Subject: [PATCH] Move Rich Text setting to System Settings page.

The setting is no longer ticket thread specific. Disabling html is now
system wide setting for disable-able textarea widgets as well as email
correspondence.
---
 include/ajax.config.php                            | 4 ++--
 include/ajax.kbase.php                             | 2 +-
 include/ajax.tickets.php                           | 4 ++--
 include/class.config.php                           | 4 ++--
 include/class.forms.php                            | 2 +-
 include/class.mailer.php                           | 2 +-
 include/class.mailfetch.php                        | 2 +-
 include/class.mailparse.php                        | 2 +-
 include/class.thread.php                           | 4 ++--
 include/class.ticket.php                           | 6 +++---
 include/client/view.inc.php                        | 2 +-
 include/i18n/en_US/help/tips/settings.system.yaml  | 6 ++++++
 include/i18n/en_US/help/tips/settings.ticket.yaml  | 6 ------
 include/staff/settings-system.inc.php              | 9 +++++++++
 include/staff/settings-tickets.inc.php             | 9 ---------
 include/staff/templates/task-delete.tmpl.php       | 2 +-
 include/staff/templates/task-status.tmpl.php       | 2 +-
 include/staff/templates/thread-entry-edit.tmpl.php | 2 +-
 include/staff/templates/ticket-status.tmpl.php     | 2 +-
 include/staff/ticket-open.inc.php                  | 4 ++--
 include/staff/ticket-view.inc.php                  | 8 ++++----
 21 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/include/ajax.config.php b/include/ajax.config.php
index c259b6028..239a7f5a4 100644
--- a/include/ajax.config.php
+++ b/include/ajax.config.php
@@ -39,7 +39,7 @@ class ConfigAjaxAPI extends AjaxController {
 
         $config=array(
               'lock_time'       => ($cfg->getLockTime()*3600),
-              'html_thread'     => (bool) $cfg->isHtmlThreadEnabled(),
+              'html_thread'     => (bool) $cfg->isRichTextEnabled(),
               'date_format'     => $cfg->getDateFormat(true),
               'lang'            => $lang,
               'short_lang'      => $sl,
@@ -66,7 +66,7 @@ class ConfigAjaxAPI extends AjaxController {
         }
 
         $config=array(
-            'html_thread'     => (bool) $cfg->isHtmlThreadEnabled(),
+            'html_thread'     => (bool) $cfg->isRichTextEnabled(),
             'lang'            => $lang,
             'short_lang'      => $sl,
             'has_rtl'         => $rtl,
diff --git a/include/ajax.kbase.php b/include/ajax.kbase.php
index 3909fd831..30575ac22 100644
--- a/include/ajax.kbase.php
+++ b/include/ajax.kbase.php
@@ -26,7 +26,7 @@ class KbaseAjaxAPI extends AjaxController {
         if(!$id || !($canned=Canned::lookup($id)) || !$canned->isEnabled())
             Http::response(404, 'No such premade reply');
 
-        if (!$cfg->isHtmlThreadEnabled())
+        if (!$cfg->isRichTextEnabled())
             $format .= '.plain';
 
         return $canned->getFormattedResponse($format);
diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php
index 1e95dde3e..1fb4d5bc5 100644
--- a/include/ajax.tickets.php
+++ b/include/ajax.tickets.php
@@ -340,7 +340,7 @@ class TicketsAjaxAPI extends AjaxController {
             $response = "<br/><blockquote>{$response->asVar()}</blockquote><br/>";
 
             //  Return text if html thread is not enabled
-            if (!$cfg->isHtmlThreadEnabled())
+            if (!$cfg->isRichTextEnabled())
                 $response = Format::html2text($response, 90);
             else
                 $response = Format::viewableImages($response);
@@ -349,7 +349,7 @@ class TicketsAjaxAPI extends AjaxController {
             return Format::json_encode(array('response' => $response));
         }
 
-        if (!$cfg->isHtmlThreadEnabled())
+        if (!$cfg->isRichTextEnabled())
             $format.='.plain';
 
         $varReplacer = function (&$var) use($ticket) {
diff --git a/include/class.config.php b/include/class.config.php
index bbcea4eeb..73b6fc23c 100644
--- a/include/class.config.php
+++ b/include/class.config.php
@@ -365,7 +365,7 @@ class OsticketConfig extends Config {
         return $this->get('passwd_reset_period');
     }
 
-    function isHtmlThreadEnabled() {
+    function isRichTextEnabled() {
         return $this->get('enable_html_thread');
     }
 
@@ -1073,6 +1073,7 @@ class OsticketConfig extends Config {
             'system_language'=>$vars['system_language'],
             'secondary_langs'=>$secondary_langs,
             'max_file_size' => $vars['max_file_size'],
+            'enable_html_thread' => isset($vars['enable_html_thread']) ? 1 : 0,
         ));
     }
 
@@ -1150,7 +1151,6 @@ class OsticketConfig extends Config {
             'show_answered_tickets'=>isset($vars['show_answered_tickets'])?0:1,
             'show_related_tickets'=>isset($vars['show_related_tickets'])?1:0,
             'hide_staff_name'=>isset($vars['hide_staff_name'])?1:0,
-            'enable_html_thread'=>isset($vars['enable_html_thread'])?1:0,
             'allow_client_updates'=>isset($vars['allow_client_updates'])?1:0,
         ));
     }
diff --git a/include/class.forms.php b/include/class.forms.php
index be6c35e5b..c6b5d6810 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -2989,7 +2989,7 @@ class ThreadEntryWidget extends Widget {
         ?>: <span class="error">*</span></span><br/>
         <textarea style="width:100%;" name="<?php echo $this->field->get('name'); ?>"
             placeholder="<?php echo Format::htmlchars($this->field->get('hint')); ?>"
-            class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+            class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                 ?> draft draft-delete" <?php echo $attrs; ?>
             cols="21" rows="8" style="width:80%;"><?php echo
             $draft ?: Format::htmlchars($this->value); ?></textarea>
diff --git a/include/class.mailer.php b/include/class.mailer.php
index 83f097050..cedb308d7 100644
--- a/include/class.mailer.php
+++ b/include/class.mailer.php
@@ -417,7 +417,7 @@ class Mailer {
             $isHtml = false;
         }
 
-        if ($isHtml && $cfg && $cfg->isHtmlThreadEnabled()) {
+        if ($isHtml && $cfg && $cfg->isRichTextEnabled()) {
             // Pick a domain compatible with pear Mail_Mime
             $matches = array();
             if (preg_match('#(@[0-9a-zA-Z\-\.]+)#', $this->getFromAddress(), $matches)) {
diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
index 8a8839a9e..d1ad8fbec 100644
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -579,7 +579,7 @@ class MailFetcher {
     function getBody($mid) {
         global $cfg;
 
-        if ($cfg->isHtmlThreadEnabled()) {
+        if ($cfg->isRichTextEnabled()) {
             if ($html=$this->getPart($mid, 'text/html', $this->charset))
                 $body = new HtmlThreadEntryBody($html);
             elseif ($text=$this->getPart($mid, 'text/plain', $this->charset))
diff --git a/include/class.mailparse.php b/include/class.mailparse.php
index 6564a4a22..083e3b26c 100644
--- a/include/class.mailparse.php
+++ b/include/class.mailparse.php
@@ -303,7 +303,7 @@ class Mail_Parse {
     function getBody(){
         global $cfg;
 
-        if ($cfg && $cfg->isHtmlThreadEnabled()) {
+        if ($cfg && $cfg->isRichTextEnabled()) {
             if ($html=$this->getPart($this->struct,'text/html'))
                 $body = new HtmlThreadEntryBody($html);
             elseif ($text=$this->getPart($this->struct,'text/plain'))
diff --git a/include/class.thread.php b/include/class.thread.php
index 75d5a14a3..bce158999 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -612,7 +612,7 @@ implements TemplateVariable {
         global $cfg;
 
         if (!$body instanceof ThreadEntryBody) {
-            if ($cfg->isHtmlThreadEnabled())
+            if ($cfg->isRichTextEnabled())
                 $body = new HtmlThreadEntryBody($body);
             else
                 $body = new TextThreadEntryBody($body);
@@ -1221,7 +1221,7 @@ implements TemplateVariable {
 
 
         if (!$vars['body'] instanceof ThreadEntryBody) {
-            if ($cfg->isHtmlThreadEnabled())
+            if ($cfg->isRichTextEnabled())
                 $vars['body'] = new HtmlThreadEntryBody($vars['body']);
             else
                 $vars['body'] = new TextThreadEntryBody($vars['body']);
diff --git a/include/class.ticket.php b/include/class.ticket.php
index cde27c478..d571a845d 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -2282,7 +2282,7 @@ implements RestrictedAccess, Threadable, TemplateVariable {
         foreach ($canned->attachments->getAll() as $file)
             $files[] = $file['id'];
 
-        if ($cfg->isHtmlThreadEnabled())
+        if ($cfg->isRichTextEnabled())
             $response = new HtmlThreadEntryBody(
                     $this->replaceVars($canned->getHtml()));
         else
@@ -3413,7 +3413,7 @@ implements RestrictedAccess, Threadable, TemplateVariable {
 
         // Not assigned...save optional note if any
         if (!$vars['assignId'] && $vars['note']) {
-            if (!$cfg->isHtmlThreadEnabled()) {
+            if (!$cfg->isRichTextEnabled()) {
                 $vars['note'] = new TextThreadBody($vars['note']);
             }
             $ticket->logNote(_S('New Ticket'), $vars['note'], $thisstaff, false);
@@ -3438,7 +3438,7 @@ implements RestrictedAccess, Threadable, TemplateVariable {
 
             $message = (string) $ticket->getLastMessage();
             if($response) {
-                $message .= ($cfg->isHtmlThreadEnabled()) ? "<br><br>" : "\n\n";
+                $message .= ($cfg->isRichTextEnabled()) ? "<br><br>" : "\n\n";
                 $message .= $response->getBody();
             }
 
diff --git a/include/client/view.inc.php b/include/client/view.inc.php
index 4f96855d7..2aead70b0 100644
--- a/include/client/view.inc.php
+++ b/include/client/view.inc.php
@@ -197,7 +197,7 @@ if (!$ticket->isClosed() || $ticket->isReopenable()) { ?>
         <font class="error">*&nbsp;<?php echo $errors['message']; ?></font>
         </p>
         <textarea name="message" id="message" cols="50" rows="9" wrap="soft"
-            class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+            class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                 ?> draft" <?php
 list($draft, $attrs) = Draft::getDraftAndDataAttrs('ticket.client', $ticket->getId(), $info['message']);
 echo $attrs; ?>><?php echo $draft ?: $info['message'];
diff --git a/include/i18n/en_US/help/tips/settings.system.yaml b/include/i18n/en_US/help/tips/settings.system.yaml
index 8e88d0e29..96d1a5e46 100644
--- a/include/i18n/en_US/help/tips/settings.system.yaml
+++ b/include/i18n/en_US/help/tips/settings.system.yaml
@@ -77,6 +77,12 @@ default_name_formatting:
       - title: Supported Email Template Variables
         href: http://osticket.com/wiki/Email_templates
 
+enable_richtext:
+    title: Enable Rich Text
+    content: >
+        If enabled, this will permit the use of rich text formatting between
+        Clients and Agents.
+
 # Date and time options
 date_time_options:
     title: Date &amp; Time Options
diff --git a/include/i18n/en_US/help/tips/settings.ticket.yaml b/include/i18n/en_US/help/tips/settings.ticket.yaml
index 87d25e036..d6fac581e 100644
--- a/include/i18n/en_US/help/tips/settings.ticket.yaml
+++ b/include/i18n/en_US/help/tips/settings.ticket.yaml
@@ -122,12 +122,6 @@ staff_identity_masking:
         If enabled, this will hide the Agent’s name from the Client during any
         communication.
 
-enable_html_ticket_thread:
-    title: Enable HTML Ticket Thread
-    content: >
-        If enabled, this will permit the use of rich text formatting between
-        Clients and Agents.
-
 ticket_attachment_settings:
     title: Ticket Thread Attachments
     content: >
diff --git a/include/staff/settings-system.inc.php b/include/staff/settings-system.inc.php
index 4dd7742f3..65a087d55 100644
--- a/include/staff/settings-system.inc.php
+++ b/include/staff/settings-system.inc.php
@@ -120,6 +120,15 @@ $gmtime = Misc::gmtime();
                 <i class="help-tip icon-question-sign" href="#default_name_formatting"></i>
             </td>
         </tr>
+        <tr>
+            <td><?php echo __('Enable Rich Text'); ?>:</td>
+            <td>
+                <input type="checkbox" name="enable_html_thread" <?php
+                echo $config['enable_html_thread']?'checked="checked"':''; ?>>
+                <?php echo __('Enable html in thread entries and email correspondence.'); ?>
+                <i class="help-tip icon-question-sign" href="#enable_richtext"></i>
+            </td>
+        </tr>
         <tr>
             <th colspan="2">
                 <em><b><?php echo __('Date and Time Options'); ?></b>&nbsp;
diff --git a/include/staff/settings-tickets.inc.php b/include/staff/settings-tickets.inc.php
index a357b20d0..d3e1bb8f1 100644
--- a/include/staff/settings-tickets.inc.php
+++ b/include/staff/settings-tickets.inc.php
@@ -203,15 +203,6 @@ if(!($maxfileuploads=ini_get('max_file_uploads')))
                 <i class="help-tip icon-question-sign" href="#staff_identity_masking"></i>
             </td>
         </tr>
-        <tr>
-            <td><?php echo __('Enable HTML Ticket Thread'); ?>:</td>
-            <td>
-                <input type="checkbox" name="enable_html_thread" <?php
-                echo $config['enable_html_thread']?'checked="checked"':''; ?>>
-                <?php echo __('Enable rich text in ticket thread and autoresponse emails.'); ?>
-                <i class="help-tip icon-question-sign" href="#enable_html_ticket_thread"></i>
-            </td>
-        </tr>
         <tr>
             <th colspan="2">
                 <em><b><?php echo __('Attachments');?></b>:  <?php echo __('Size and maximum uploads setting mainly apply to web tickets.');?></em>
diff --git a/include/staff/templates/task-delete.tmpl.php b/include/staff/templates/task-delete.tmpl.php
index eea44e19c..77cd9df4e 100644
--- a/include/staff/templates/task-delete.tmpl.php
+++ b/include/staff/templates/task-delete.tmpl.php
@@ -47,7 +47,7 @@ $action = $info[':action'] ?: ('#tasks/mass/delete');
                 ?>
                 <textarea name="comments" id="comments"
                     cols="50" rows="3" wrap="soft" style="width:100%"
-                    class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                    class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                     ?> no-bar"
                     placeholder="<?php echo $placeholder; ?>"><?php
                     echo $info['comments']; ?></textarea>
diff --git a/include/staff/templates/task-status.tmpl.php b/include/staff/templates/task-status.tmpl.php
index d741aaafc..8aba2d100 100644
--- a/include/staff/templates/task-status.tmpl.php
+++ b/include/staff/templates/task-status.tmpl.php
@@ -76,7 +76,7 @@ $action = $info[':action'] ?: ('#tasks/mass/'. $action);
                         ?>
                         <textarea name="comments" id="comments"
                             cols="50" rows="3" wrap="soft" style="width:100%"
-                            class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                            class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                             ?> no-bar"
                             placeholder="<?php echo $placeholder; ?>"><?php
                             echo $info['comments']; ?></textarea>
diff --git a/include/staff/templates/thread-entry-edit.tmpl.php b/include/staff/templates/thread-entry-edit.tmpl.php
index 24e63230e..bab5e4eb6 100644
--- a/include/staff/templates/thread-entry-edit.tmpl.php
+++ b/include/staff/templates/thread-entry-edit.tmpl.php
@@ -31,7 +31,7 @@
 <?php } ?>
     name="body"
     class="large <?php
-        if ($cfg->isHtmlThreadEnabled() && $this->entry->format == 'html')
+        if ($cfg->isRichTextEnabled() && $this->entry->format == 'html')
             echo 'richtext';
     ?>"><?php echo Format::viewableImages($this->entry->body);
 ?></textarea>
diff --git a/include/staff/templates/ticket-status.tmpl.php b/include/staff/templates/ticket-status.tmpl.php
index 458c6010c..5da0e6619 100644
--- a/include/staff/templates/ticket-status.tmpl.php
+++ b/include/staff/templates/ticket-status.tmpl.php
@@ -84,7 +84,7 @@ $action = $info['action'] ?: ('#tickets/status/'. $state);
                         ?>
                         <textarea name="comments" id="comments"
                             cols="50" rows="3" wrap="soft" style="width:100%"
-                            class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                            class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                             ?> no-bar"
                             placeholder="<?php echo $placeholder; ?>"><?php
                             echo $info['comments']; ?></textarea>
diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php
index 80f4829e2..65d4e37a0 100644
--- a/include/staff/ticket-open.inc.php
+++ b/include/staff/ticket-open.inc.php
@@ -306,7 +306,7 @@ if ($_POST)
                 if ($thisstaff->getDefaultSignatureType() == 'mine')
                     $signature = $thisstaff->getSignature(); ?>
                 <textarea
-                    class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                    class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                         ?> draft draft-delete" data-signature="<?php
                         echo Format::htmlchars(Format::viewableImages($signature)); ?>"
                     data-signature-field="signature" data-dept-field="deptId"
@@ -378,7 +378,7 @@ print $response_form->getField('attachments')->render();
         <tr>
             <td colspan=2>
                 <textarea
-                    class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                    class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                         ?> draft draft-delete"
                     placeholder="<?php echo __('Optional internal note (recommended on assignment)'); ?>"
                     name="note" cols="21" rows="6" style="width:80%;" <?php
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 74407ea19..60043bd38 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -576,7 +576,7 @@ $tcount = $ticket->getThreadEntries($types)->count();
                         'Start writing your response here. Use canned responses from the drop-down above'
                         ); ?>"
                         rows="9" wrap="soft"
-                        class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                        class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                             ?> draft draft-delete" <?php
     list($draft, $attrs) = Draft::getDraftAndDataAttrs('ticket.response', $ticket->getId(), $info['response']);
     echo $attrs; ?>><?php echo $draft ?: $info['response'];
@@ -691,7 +691,7 @@ $tcount = $ticket->getThreadEntries($types)->count();
                     <textarea name="note" id="internal_note" cols="80"
                         placeholder="<?php echo __('Note details'); ?>"
                         rows="9" wrap="soft"
-                        class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                        class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                             ?> draft draft-delete" <?php
     list($draft, $attrs) = Draft::getDraftAndDataAttrs('ticket.note', $ticket->getId(), $info['note']);
     echo $attrs; ?>><?php echo $draft ?: $info['note'];
@@ -786,7 +786,7 @@ $tcount = $ticket->getThreadEntries($types)->count();
                 <td>
                     <textarea name="transfer_comments" id="transfer_comments"
                         placeholder="<?php echo __('Enter reasons for the transfer'); ?>"
-                        class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                        class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                             ?> no-bar" cols="80" rows="7" wrap="soft"><?php
                         echo $info['transfer_comments']; ?></textarea>
                     <span class="error"><?php echo $errors['transfer_comments']; ?></span>
@@ -887,7 +887,7 @@ $tcount = $ticket->getThreadEntries($types)->count();
                     <textarea name="assign_comments" id="assign_comments"
                         cols="80" rows="7" wrap="soft"
                         placeholder="<?php echo __('Enter reasons for the assignment or instructions for assignee'); ?>"
-                        class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext';
+                        class="<?php if ($cfg->isRichTextEnabled()) echo 'richtext';
                             ?> no-bar"><?php echo $info['assign_comments']; ?></textarea>
                     <span class="error"><?php echo $errors['assign_comments']; ?></span><br>
                 </td>
-- 
GitLab