OSTicket 1.6 ST: Add Pending Status, and Autoclose tickets after 5 days.

Based on the Pending and Autoclose mod posted by GooseMoose on the OSTicket forums, here are my re-written directions on how to do it, as well as a bug fix.

What:

This MOD is for OSTicket 1.6 ST and will add in a new ticket status type of "pending". If any ticket is left pending for 5 days it will close the ticket. It also adds a new section at the top [see image] that displays how many pending tickets there are and lets you click the link to look at them.


UPDATE: Please note that today Sept 14th, 2011 I noticed that I forgot to include part of step 1 in my directions. This step has been updated accordingly, sorry for any confusion it may have caused.

Directions:

Step 1 -

Copy the two files [preLogin.pgp and autoClose.php] in the attached zip 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 [document root]/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 Tickets ('.$stats['pending'].')','title'=>'Pending Tickets', 'href'=>'tickets.php?status=pending', 'iconclass'=>'closedTickets'));

3B: In [document root]/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
}else{ ?>
<label><input type="checkbox" name="ticket_status" id="l_ticket_status" value="Reopen" =$checked?> > Reopen on Reply
}?>

to

if($ticket->isPending())
{
	?>
	isOpen()){?>
	<label><input type="checkbox" name="ticket_status" id="l_ticket_status" value="Close" =$checked?> > Close on Reply
	}else{ ?>
	<label><input type="checkbox" name="ticket_status" id="l_ticket_status" value="Reopen" =$checked?> > Reopen on Reply
	
	}
}
$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)
	}else{ ?>
	<label><input type="checkbox" name="pending_status" id="l_pending_status" value="Pending" =$checked?> > Mark As Pending
	
	}
}
?>

3C: In [document root]/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 and 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 [document root]/include/staff/tickets.inc.php

circa line 32 add

case 'pending':
        $status='pending';
        break;


*** Update 05 Mar 2013 ***

For some reason Drupal hosed some of my file attachments. Here is a link to the pending mod files that you need to complete this modification.

Pending Mod files: pending-mod-files.zip