From 49b9658f5ed133fec43a4416432f210e0a117f01 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 21 Aug 2015 08:55:23 -0500
Subject: [PATCH] tickets: Use post-redirect-get when posting and editing

---
 include/staff/tickets.inc.php |  2 +-
 scp/tickets.php               | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php
index 2742d39a7..5adab6cec 100644
--- a/include/staff/tickets.inc.php
+++ b/include/staff/tickets.inc.php
@@ -587,7 +587,7 @@ $(function() {
             +'?count='+count
             +'&_uid='+new Date().getTime();
             $.dialog(url, [201], function (xhr) {
-                $.pjax.reload('#pjax-container');
+                $.pjax({url: 'tickets.php', container: '#pjax-container'});
              });
         }
         return false;
diff --git a/scp/tickets.php b/scp/tickets.php
index e4c1fc103..b8fc7ae44 100644
--- a/scp/tickets.php
+++ b/scp/tickets.php
@@ -25,6 +25,7 @@ require_once(INCLUDE_DIR.'class.export.php');       // For paper sizes
 
 $page='';
 $ticket = $user = null; //clean start.
+$redirect = false;
 //LOCKDOWN...See if the id provided is actually valid and if the user has access.
 if($_REQUEST['id']) {
     if(!($ticket=Ticket::lookup($_REQUEST['id'])))
@@ -131,6 +132,7 @@ if($_POST && !$errors):
 
                 // Go back to the ticket listing page on reply
                 $ticket = null;
+                $redirect = 'tickets.php';
 
             } elseif(!$errors['err']) {
                 $errors['err']=__('Unable to post the reply. Correct the errors below and try again!');
@@ -173,6 +175,7 @@ if($_POST && !$errors):
                     Draft::deleteForNamespace('ticket.note.'.$ticket->getId(),
                         $thisstaff->getId());
 
+                 $redirect = 'tickets.php';
             } else {
 
                 if(!$errors['err'])
@@ -187,6 +190,7 @@ if($_POST && !$errors):
                 $errors['err']=__('Permission Denied. You are not allowed to edit tickets');
             elseif($ticket->update($_POST,$errors)) {
                 $msg=__('Ticket updated successfully');
+                $redirect = 'tickets.php?id='.$ticket->getId();
                 $_REQUEST['a'] = null; //Clear edit action - going back to view.
                 //Check to make sure the staff STILL has access post-update (e.g dept change).
                 if(!$ticket->checkStaffPerm($thisstaff))
@@ -335,6 +339,12 @@ if($_POST && !$errors):
         $thisstaff ->resetStats(); //We'll need to reflect any changes just made!
 endif;
 
+if ($redirect) {
+    if ($msg)
+        Messages::success($msg);
+    Http::redirect($redirect);
+}
+
 /*... Quick stats ...*/
 $stats= $thisstaff->getTicketsStats();
 
-- 
GitLab