From 40e061a14af8557b317d44d5db0231e60d10da55 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Mon, 1 Sep 2014 20:59:13 +0000
Subject: [PATCH] Maintain user input on error

Make the error message clear
---
 include/ajax.tickets.php                       | 17 ++++++++++++++---
 include/staff/templates/ticket-status.tmpl.php |  2 +-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php
index 9ce2a85fa..3d93e9a9c 100644
--- a/include/ajax.tickets.php
+++ b/include/ajax.tickets.php
@@ -901,9 +901,9 @@ class TicketsAjaxAPI extends AjaxController {
             }
         }
 
+        $count = count($_REQUEST['tids']);
         if (!$errors) {
             $i = 0;
-            $count = count($_REQUEST['tids']);
             $comments = $_REQUEST['comments'];
             foreach ($_REQUEST['tids'] as $tid) {
                 if (($ticket=Ticket::lookup($tid))
@@ -914,8 +914,8 @@ class TicketsAjaxAPI extends AjaxController {
             }
 
             if (!$i)
-                $errors['err'] = sprintf(__('Unable to set status for %s'),
-                        _N('selected ticket', 'selected tickets', $count));
+                $errors['err'] = sprintf(__('Unable to change status for %s'),
+                        _N('the selected ticket', 'any of the selected tickets', $count));
             else {
                 // Assume success
                 if ($i==$count) {
@@ -936,6 +936,17 @@ class TicketsAjaxAPI extends AjaxController {
             }
         }
 
+        $info['title'] = sprintf('%s %s',
+                TicketStateField::getVerb($state),
+                 __('Tickets'));
+
+        if ($count)
+            $info['title'] .= sprintf(' &mdash; %d %s',
+                    $count, __('selected'));
+
+
+        $info['status_id'] = $_REQUEST['status_id'];
+        $info['comments'] = Format::htmlchars($_REQUEST['comments']);
         $info['errors'] = $errors;
         return self::_setStatus($state, $info);
     }
diff --git a/include/staff/templates/ticket-status.tmpl.php b/include/staff/templates/ticket-status.tmpl.php
index 8646a05cf..7f7dc7d64 100644
--- a/include/staff/templates/ticket-status.tmpl.php
+++ b/include/staff/templates/ticket-status.tmpl.php
@@ -86,7 +86,7 @@ $action = $info['action'] ?: ('#tickets/status/'. $state);
                             cols="50" rows="3" wrap="soft" style="width:100%"
                             class="richtext ifhtml no-bar"
                             placeholder="<?php echo $placeholder; ?>"><?php
-                            echo $info['notes']; ?></textarea>
+                            echo $info['comments']; ?></textarea>
                     </td>
                 </tr>
             </tbody>
-- 
GitLab