Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

[Mod Completed] Pending Status & Auto Close

edited November 2013 in Mods and Customizations
I got tired of responding to tickets and leaving them open waiting for a response before closing the ticket. So I created a mod that allows you to check a box "Pending" when responding to a ticket that will automatically close the ticket if there's no further respond for 15 days. I went from hundreds of tickets open at all times to about 30 which was great! No more going through open tickets one by one to find out if they need to be closed or responded to. If it's something I MUST get an answer to I leave it open, otherwise it's "pending."

Here's the changes I made. I've attached the two files I edited too. I'm working 20 hour days and don't have tons of time to answer questions on this so hopefully someone can take this over as it's an awesome mod! I did improve this a bit along the way and my notes should include all the improvements.

Changes:

1). scp\login.php
Added below code from line 54
define(\"OMEGAPVTLTD\",TRUE); //Make includes happy
// do tasks prior to redirecting
include_once(INCLUDE_DIR.'staff/preLogin.php');
2). include\staff\preLogin.php
This is the new file is been added and is in attached zip
3). include\staff\autoClose.php
This is the new file is been added and in attached zip
4). scp\tickets.php
On line 57, Added pending option in array $statusKeys
Added below code from line 96 before comment (//Finally upload attachment if any)
$wasPending=$ticket->isPending();
if(isset($_POST['pending_status']) && $_POST['pending_status']) {
if($ticket->setStatus($_POST['pending_status']) && $ticket->reload()) {
$note=sprintf('%s %s the ticket on reply',$thisuser->getName(),($ticket->isPending()?'Pending': $ticket->isOpen() ? 'Open' : 'Closed'));
$ticket->logActivity('Ticket status changed to '.($ticket->isPending()?'Pending': $ticket->isOpen() ? 'Open' : 'Closed'),$note);
}
}
if($wasPending && !isset($_POST['pending_status']))
{
$ticket->setStatus('open');
$note=sprintf('%s %s the ticket on reply',$thisuser->getName(),$ticket->isOpen()?'reopened':'closed');
$ticket->logActivity('Ticket status changed to '.($ticket->isOpen()?'Open':'Closed'),$note);
}
Modified query on line 433
$sql='SELECT count(open.ticket_id) as open, count(answered.ticket_id) as answered '.
',count(overdue.ticket_id) as overdue, count(assigned.ticket_id) as assigned, count(pending.ticket_id) as pending '.
' FROM '.TICKET_TABLE.' ticket '.
'LEFT JOIN '.TICKET_TABLE.' open ON open.ticket_id=ticket.ticket_id AND open.status=\'open\' AND open.isanswered=0 '.
'LEFT JOIN '.TICKET_TABLE.' answered ON answered.ticket_id=ticket.ticket_id AND answered.status=\'open\' AND answered.isanswered=1 '.
'LEFT JOIN '.TICKET_TABLE.' pending ON pending.ticket_id=ticket.ticket_id AND pending.status=\'pending\' '.
'LEFT JOIN '.TICKET_TABLE.' overdue ON overdue.ticket_id=ticket.ticket_id AND overdue.status=\'open\' AND overdue.isoverdue=1 '.
'LEFT JOIN '.TICKET_TABLE.' assigned ON assigned.ticket_id=ticket.ticket_id AND assigned.staff_id='.db_input($thisuser->getId());

added below code on line 463 for sub menu
$nav->addSubMenu(array('desc'=>'Pending Tickets ('.$stats['pending'].')','title'=>'Pending Tickets', 'href'=>'tickets.php?status=pending', 'iconclass'=>'closedTickets'));



5). include\staff\viewticket.inc.php
Ticket status code is been replaced with below : on line 332
<?
if($ticket->isPending())
{
?>
<input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Reopen\" style=\"display:none;\">
<?php
}else{
$checked=isset($info['ticket_status'])?'checked':''; //Staff must explicitly check the box to change status..
if($ticket->isOpen()){?>
<label><input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Close\" <?=$checked?> > Close on Reply</label>
<?}else{ ?>
<label><input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Reopen\" <?=$checked?> > Reopen on Reply</label>
<?
}
}
$checked=isset($info['pending_status'])?'checked':''; //Staff must explicitly check the box to change status..
if(!$ticket->isClosed())
{
if($ticket->isPending()){
?>
<label><input type=\"checkbox\" name=\"pending_status\" id=\"l_pending_status\" value=\"Open\" checked=\"checked\" > Ticket is pending (Untick to mark not pending)</label>
<?}else{ ?>
<label><input type=\"checkbox\" name=\"pending_status\" id=\"l_pending_status\" value=\"Pending\" <?=$checked?> > Mark As Pending</label>
<?
}
}
?>

FROM

<?
$checked=isset($info['ticket_status'])?'checked':''; //Staff must explicitly check the box to change status..
if($ticket->isOpen()){?>
<label><input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Close\" <?=$checked?> > Close on Reply</label>
<?}else{ ?>
<label><input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Reopen\" <?=$checked?> > Reopen on Reply</label>
<?}?>

6). include\class.ticket.php
Added new function on line 107
function isPending(){
return (strcasecmp($this->getStatus(),'Pending')==0)?true:false;
}

added below case in function setStatus on line 378
case 'pending':
return $this->pending();

added new function on line 397
function pending(){

$sql= 'UPDATE '.TICKET_TABLE.' SET status='.db_input('pending').',updated=NOW() '.
' WHERE ticket_id='.db_input($this->getId());
return (db_query($sql) && db_affected_rows())?true:false;
}
7). include\staff\ tickets.inc.php
added below code on line 32:
case 'pending':
$status='pending';
break;
8). Added new enum ‘pending’ in the table os_ticket in the field status

«1

Comments

  • I am so sorry - I do not understand your change log above. I am using 1.6 RC5 and can not located the items you are specifying. Please advice.

    Thanks
  • Then you should upgrade to 1.6 ST. We are not in the habit of supporting outdated RCs.
  • that was not what I was asking. I know I need to upgrade. When indicating "Added below code from line 54" , what does it really mean? Copy the code after line 54?
  • Thanks for the great mode.
    I'll try it.
  • Hi
    Can you tell me how to do the 8
    8). Added new enum ‘pending’ in the table os_ticket in the field status

    What command should i use?

    Thanks
  • I followed the steps exactly.
    IT DOESN'T WORK!

    the stataus "pending" was not successfully updated when you "mark as pending" option checked and submited.
  • Hi
    Is there anyone can help?
    I'd like to pay $30 to guys who can fix this mode
  • +1 for me.
  • You can PM me for where to send that $30. :P

    This mod is for OST 1.6 ST, if you are not running that version please upgrade first.

    Step 1 -

    Copy the two files [preLogin.pgp and autoClose.php from 1st post in thread] to /include/staff

    In /scp/login.php at circa line 54 after
    require_once('index.php'); //Just incase header is messed up.

    add the following code:
    define(\"OMEGAPVTLTD\",TRUE); //Make includes happy        
    // do tasks prior to redirecting
    include_once(INCLUDE_DIR.'staff/preLogin.php');


    Step 2 -

    update the database [please edit this to fit your installation] with the following MySQL Query

    ALTER TABLE ost_ticket CHANGE status status ENUM('open','closed','pending') DEFAULT 'open';



    Step 3 -

    Make the following code changes


    3A: In /scp/tickets.php

    at circa line 56

    Change
    $statusKeys=array('open'=>'Open','Reopen'=>'Open','Close'=>'Closed');


    to
    $statusKeys=array('open'=>'Open','Reopen'=>'Open','Close'=>'Closed','Pending'=>'Pending');


    at circa line 96 after

    }


    and before

    //Finally upload attachment if any


    Add the following

    $wasPending=$ticket->isPending();
    if(isset($_POST['pending_status']) && $_POST['pending_status']) {
    if($ticket->setStatus($_POST['pending_status']) && $ticket->reload()) {
    $note=sprintf('%s %s the ticket on reply',$thisuser->getName(),($ticket->isPending()?'Pending': $ticket->isOpen() ? 'Open' : 'Closed'));
    $ticket->logActivity('Ticket status changed to '.($ticket->isPending()?'Pending': $ticket->isOpen() ? 'Open' : 'Closed'),$note);
    }
    }
    if($wasPending && !isset($_POST['pending_status']))
    {
    $ticket->setStatus('open');
    $note=sprintf('%s %s the ticket on reply',$thisuser->getName(),$ticket->isOpen()?'reopened':'closed');
    $ticket->logActivity('Ticket status changed to '.($ticket->isOpen()?'Open':'Closed'),$note);
    }


    at circa line 432 change

    $sql='SELECT count(open.ticket_id) as open, count(answered.ticket_id) as answered '.
    ',count(overdue.ticket_id) as overdue, count(assigned.ticket_id) as assigned '.
    ' FROM '.TICKET_TABLE.' ticket '.
    'LEFT JOIN '.TICKET_TABLE.' open ON open.ticket_id=ticket.ticket_id AND open.status=\'open\' AND open.isanswered=0 '.
    'LEFT JOIN '.TICKET_TABLE.' answered ON answered.ticket_id=ticket.ticket_id AND answered.status=\'open\' AND answered.isanswered=1 '.
    'LEFT JOIN '.TICKET_TABLE.' overdue ON overdue.ticket_id=ticket.ticket_id AND overdue.status=\'open\' AND overdue.isoverdue=1 '.
    'LEFT JOIN '.TICKET_TABLE.' assigned ON assigned.ticket_id=ticket.ticket_id AND assigned.staff_id='.db_input($thisuser->getId());


    to

    $sql='SELECT count(open.ticket_id) as open, count(answered.ticket_id) as answered '.
    ',count(overdue.ticket_id) as overdue, count(assigned.ticket_id) as assigned, count(pending.ticket_id) as pending '.
    ' FROM '.TICKET_TABLE.' ticket '.
    'LEFT JOIN '.TICKET_TABLE.' open ON open.ticket_id=ticket.ticket_id AND open.status=\'open\' AND open.isanswered=0 '.
    'LEFT JOIN '.TICKET_TABLE.' answered ON answered.ticket_id=ticket.ticket_id AND answered.status=\'open\' AND answered.isanswered=1 '.
    'LEFT JOIN '.TICKET_TABLE.' pending ON pending.ticket_id=ticket.ticket_id AND pending.status=\'pending\' '.
    'LEFT JOIN '.TICKET_TABLE.' overdue ON overdue.ticket_id=ticket.ticket_id AND overdue.status=\'open\' AND overdue.isoverdue=1 '.
    'LEFT JOIN '.TICKET_TABLE.' assigned ON assigned.ticket_id=ticket.ticket_id AND assigned.staff_id='.db_input($thisuser->getId());


    at circa line 463 after

    if($stats['overdue']) {
    $nav->addSubMenu(array('desc'=>'Overdue ('.$stats['overdue'].')','title'=>'Stale Tickets',
    'href'=>'tickets.php?status=overdue','iconclass'=>'overdueTickets'));

    if(!$sysnotice && $stats['overdue']>10)
    $sysnotice=$stats['overdue'] .' overdue tickets!';
    }


    add the following

    $nav->addSubMenu(array('desc'=>'Pending ('.$stats['pending'].')','title'=>'Pending Tickets', 'href'=>'tickets.php?status=pending', 'iconclass'=>'closedTickets'));



    3B: In /include/staff/viewticket.inc.php

    circa line 333 change

    <?
    $checked=isset($info['ticket_status'])?'checked':''; //Staff must explicitly check the box to change status..
    if($ticket->isOpen()){?>
    <label><input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Close\" <?=$checked?> > Close on Reply</label>
    <?}else{ ?>
    <label><input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Reopen\" <?=$checked?> > Reopen on Reply</label>
    <?}?>


    to

    <?
    if($ticket->isPending())
    {
    ?>
    <input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Reopen\" style=\"display:none;\">
    <?php
    }else{
    $checked=isset($info['ticket_status'])?'checked':''; //Staff must explicitly check the box to change status..
    if($ticket->isOpen()){?>
    <label><input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Close\" <?=$checked?> > Close on Reply</label>
    <?}else{ ?>
    <label><input type=\"checkbox\" name=\"ticket_status\" id=\"l_ticket_status\" value=\"Reopen\" <?=$checked?> > Reopen on Reply</label>
    <?
    }
    }
    $checked=isset($info['pending_status'])?'checked':''; //Staff must explicitly check the box to change status..
    if(!$ticket->isClosed())
    {
    if($ticket->isPending()){
    ?>
    <label><input type=\"checkbox\" name=\"pending_status\" id=\"l_pending_status\" value=\"Pending\" checked=\"checked\" > Ticket is pending (Untick to mark not pending)</label>
    <?}else{ ?>
    <label><input type=\"checkbox\" name=\"pending_status\" id=\"l_pending_status\" value=\"Pending\" <?=$checked?> > Mark As Pending</label>
    <?
    }
    }
    ?>




    3C: In /include/class.ticket.php

    circa line 107 add
    note: I added this after the isOpen function and before the isClosed function.


    function isPending(){
    return (strcasecmp($this->getStatus(),'Pending')==0)?true:false;
    }


    Locate function setStatus circa line 378

    Add

    case 'pending':
    return $this->pending();
    break;



    circa line 397 add

    function pending(){

    $sql= 'UPDATE '.TICKET_TABLE.' SET status='.db_input('pending').',updated=NOW() '.
    ' WHERE ticket_id='.db_input($this->getId());
    return (db_query($sql) && db_affected_rows())?true:false;
    }




    3D: In /include/staff/tickets.inc.php

    circa line 32 add

    case 'pending':
    $status='pending';
    break;
    pending.jpg
    591 x 234 - 20K
  • Thanks for the clear guide. It works!

    My website: Micro Keylogger
    osticket Support Center: http://support.awosoft.com

    also changed client area panel tickets.php to show "View answered" as the function to view pending tickets.
  • Did you get Auto-Close to work?
    My tickets don't seem to close automatically, but everything else works perfectly.
  • looking to be working for me

    hey it looks to be working for me but need to know how to change days as right now it is set for 15 days where would i change that can some one help :p
  • How to change auto close from 15 days

    i also need to alter the time from 15 days and up need a pointer on how to do thath.

    ty
  • Voron:
    Redo step 1. That should fix your issue. I neglected to include something in the directions.

    Gibbc and Glein:
    The number of days is handled in the autoClose.php

    It's part of the sql statement:

    $sql .= \" AND updated <= '\" . date(\"Y-m-d\", strtotime('-5 days')) . \" 00:00:00'\";


    modifying that statement should change the number of days.
  • ntozier;23316 said:
    Voron:
    Redo step 1. That should fix your issue. I neglected to include something in the directions.

    Gibbc and Glein:
    The number of days is handled in the autoClose.php

    It's part of the sql statement:

    $sql .= \" AND updated <= '\" . date(\"Y-m-d\", strtotime('-5 days')) . \" 00:00:00'\";


    modifying that statement should change the number of days.
    this is good i can see this but i still kinda lost what option is it i mean if not updated in 5 days it closes but that not 15 days lol but if this option is set for 5 then i understand
  • No work

    when mark pending option and submit dont work.
  • amazing

    wow easy and works :D

    Good job ntozier
  • it works

    so i found it and it works
    $sql .= \" AND updated <= '\" . date(\"Y-m-d\", strtotime[COLOR=\"Red\"]('-5 days'))[/COLOR] . \" 00:00:00'\";
    is the right place and right now set at 5 days keep minus somthing and all is good :D:)
  • Excellent mod, thank you. I was wondering how to add a new status so I'd know when the user provided additional information. And the auto-close feature perfect.
  • Thanks for this great mod!

    I would like to be able to pend tickets from the internal note, as well as the reply.

    I have tried to work this out using the orginal code but have been unable to get it to update the ticket status.

    Please could you advise?
  • Hi,
    I have changed this mod to show a "My Pending" to allow staff to see only the pending tickets assigned to to themselves. I need to add an "All Pending" sub nav to show all pending tickets, but I am getting stuck because the SubNav HREF cannot be reused:

    'href'=>'tickets.php?status=pending'


    I have changed the sql query by adding the following:

    count(mypending.ticket_id) as mypending

    'LEFT JOIN '.TICKET_TABLE.' mypending ON mypending.ticket_id=ticket.ticket_id AND mypending.status=\'pending\' AND mypending.staff_id='.db_input($thisuser->getId()).' '.


    but this only works if the all pending isnt included because the both reference the same status=pending...
  • this mod does not seem to unpend the ticket when the box is unticked.

    I think it is because it calls the same pending function if the box is ticker or unticked.

    I have created a unpending function which changes the status and adds a timestamp to a new row in the db.

    I cant work out how to call the function based on unticking the box. I presume its a _GET somewhere?

        function unpending() {

    $sql= 'UPDATE '.TICKET_TABLE.' SET status='.db_input('open').',updated=NOW(),pend_end=NOW() '.

    ' WHERE ticket_id='.db_input($this->getId());
    return (db_query($sql) && db_affected_rows())?true:false;
    }
  • great MOD! thanks!

    Goosemoose, thanks for this mod and thanks to ntozier for the step by step instructions!

    I got this installed and I'm waiting to see if it closes the pending tickets by tomorrow (set to -1 in area mentioned).


    much appreciated guys!
  • When i follow the last step i dont see anything every time i click on the open,close,overdue or pending status.... is there anything i forgot to add...
  • Hi sir can u please teach me how to add a date&time when i put it in pending... and when did i remove it on pending status...tnx
  • Hello, thank you for this great step by step guide. I am stuck at step 2. Do I do this in phpmyadmin? I am lost where to access my database. I am using joomla, so everything was installed for me using simple scripts from host.

    EDIT:
    I figured out where my Database is but I am lost on how to add a field into a database table. Any suggestions?
  • How to add a field to your database depends on how you access your database. I personally have SSH access to my database server and usually utilize command line to make changes. There are third party apps that you could utilize. Such as:

    phpmyadmin (web based)
    Navicat (windows app)
    MySQL Workbench (windows app)
    MySQL Admin (deprecated windows app)

    If you can tell us how you setup your database in the first place, we can probably give you a better idea how you would do this.
  • 8). Added new enum ‘pending’ in the table os_ticket in the field status

    How do I do with step number 8? Somehow the search not showed "pending"
    Thank you for your help,
  • Never-mind
    I found it ticket.inc.php
  • cpham55;38891 said:
    8). Added new enum ‘pending’ in the table os_ticket in the field status

    How do I do with step number 8? Somehow the search not showed "pending"
    Thank you for your help,
    You should read post 10.
    http://osticket.com/forums/showpost.php?p=22800&postcount=10

    IMO the directions are better and more explanatory.
Sign In or Register to comment.