From 763b2b37136fe351f53ed948636419d2119694e1 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 2 Mar 2015 16:15:36 -0600
Subject: [PATCH] oops: Don't connect the autoLock unless owned by viewing
 agent

---
 include/staff/ticket-view.inc.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 572fc90c6..15fcee9f2 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -22,6 +22,7 @@ $user  = $ticket->getOwner(); //Ticket User (EndUser)
 $team  = $ticket->getTeam();  //Assigned team.
 $sla   = $ticket->getSLA();
 $lock  = $ticket->getLock();  //Ticket lock obj
+$mylock = ($lock && $lock->getStaffId() == $thisstaff->getId()) ? $lock : null;
 $id    = $ticket->getId();    //Ticket ID.
 
 //Useful warnings and errors the user might want to know!
@@ -514,7 +515,7 @@ $tcount = $ticket->getThreadEntries($types)->count();
         <input type="hidden" name="id" value="<?php echo $ticket->getId(); ?>">
         <input type="hidden" name="msgId" value="<?php echo $msgId; ?>">
         <input type="hidden" name="a" value="reply">
-        <input type="hidden" name="lockCode" value="<?php echo $ticket->getLock()->getCode(); ?>">
+        <input type="hidden" name="lockCode" value="<?php echo ($mylock) ? $mylock->getCode() : ''; ?>">
         <span class="error"></span>
         <table style="width:100%" border="0" cellspacing="0" cellpadding="3">
            <tbody id="to_sec">
@@ -703,7 +704,7 @@ $tcount = $ticket->getThreadEntries($types)->count();
         <input type="hidden" name="id" value="<?php echo $ticket->getId(); ?>">
         <input type="hidden" name="locktime" value="<?php echo $cfg->getLockTime() * 60; ?>">
         <input type="hidden" name="a" value="postnote">
-        <input type="hidden" name="lockCode" value="<?php echo $ticket->getLock()->getCode(); ?>">
+        <input type="hidden" name="lockCode" value="<?php echo ($mylock) ? $mylock->getCode() : ''; ?>">
         <table width="100%" border="0" cellspacing="0" cellpadding="3">
             <?php
             if($errors['postnote']) {?>
@@ -1057,14 +1058,14 @@ $(function() {
     });
 <?php
     // Set the lock if one exists
-    if ($lock) { ?>
+    if ($mylock) { ?>
 !function() {
   var setLock = setInterval(function() {
     if (typeof(window.autoLock) === 'undefined')
       return;
     clearInterval(setLock);
     autoLock.setLock({
-      id:<?php echo $lock->getId(); ?>,
+      id:<?php echo $mylock->getId(); ?>,
       time: <?php echo $cfg->getLockTime() * 60; ?>}, 'acquire');
   }, 50);
 }();
-- 
GitLab