Ever wanted to input time for jobs in osTicket or be able to track your staff and see how long it takes to do a particular job?
Then this mod is for you!
If you like the mod, Please rate the thread. Thanks. Will help other people to find it as time goes on.
You will need to add the following fields to your DB
Table - ticket_response @ ticket_note
Field - time_spent
Type - INT
Length / Value = 11
Null = No
Default = 0
\include\Class.ticket.php
Change Line 685
function postResponse($msgid,$response,$signature='none',$attachment=false,$canalert=true){
To
function postResponse($msgid,$response,$signature='none',$attachment=false,$canalert=true, $time_spent=0){
Find
if(!$thisuser || !$thisuser->getId() || !$thisuser->isStaff()) //just incase
return 0;
Add After
if (!is_numeric($time_spent)){
return 0;
}
Find
',staff_name='.db_input($thisuser->getName()).
Add After
',time_spent='.db_input($time_spent).
Find
function postNote($title,$note,$alert=true,$poster='') {
Replace With
function postNote($title,$note,$alert=true,$poster='', $time_spent=0) {
Add after global $thisuser,$cfg;
if (!is_numeric($time_spent)){
return 0;
}
Find
',staff_id='.db_input($thisuser?$thisuser->getId()).
Add After
',time_spent='.db_input($time_spent).
Include\staff\viewticket.php
Find
if($ticket->isOverdue())
$warn.='<span class="Icon overdueTicket">Marked overdue!</span>';
Add after
$sql = 'SELECT
(SELECT SUM( time_spent )
FROM '.TICKET_RESPONSE_TABLE.'
WHERE ticket_id='.db_input($id).')
+(SELECT SUM( time_spent )
FROM '.TICKET_NOTE_TABLE.'
WHERE ticket_id='.db_input($id).')
AS total_time';
$result = db_query($sql);
$cursor = mysql_fetch_row($result);
$total_time = $cursor;
// This is for summing each staff members contribution
$sql = 'SELECT staff_id, staff_name, SUM( time_spent ) as time
FROM '.TICKET_RESPONSE_TABLE.'
WHERE ticket_id='.db_input($id).'
GROUP BY staff_id
UNION
SELECT staff_id, source as staff_name, SUM( time_spent ) as time
FROM '.TICKET_NOTE_TABLE.'
WHERE ticket_id='.db_input($id).'
GROUP BY staff_id';
$result = db_query($sql);
$total_time_staff = array();
while($row=db_fetch_array($result)){
$total_time_staff[$row = $row;
$total_time_staff[$row = $total_time_staff[$row + $row;
}
Find
<tr>
<th>Source:</th>
<td><?=$ticket->getSource()?></td>
</tr>
Add After
<tr>
<th>Total Time Spent:</th>
<td><?=$total_time?> minutes</td>
</tr>
Find
<tr><th nowrap>Last Message:</th>
<td><?=Format:($ticket->getLastMessageDate())?></td>
</tr>
</table>
</td>
</tr>
</table>
Add After
<h2 class="msg">Time Sheet</h2>
<table align="center" class="ticketinfo" cellspacing="1" cellpadding="3" width="100%" border=0>
<tr><th>Staff Member</th><th>Total Time Spent</th></tr>
<?php while(list($key, $value) = each($total_time_staff)){ ?>
<tr>
<td><?=$value?></td>
<td><?=$value?> minutes</td>
</tr>
<?php } ?>
</table>
Find
$sql ='SELECT note_id,title,note,source,created FROM '.TICKET_NOTE_TABLE.' WHERE ticket_id='.db_input($id).' ORDER BY created DESC';
Replace With
$sql ='SELECT note_id,title,note,source,created,time_spent FROM '.TICKET_NOTE_TABLE.' WHERE ticket_id='.db_input($id).' ORDER BY created DESC';
Find
<tr class="header"><td><?=Format:($row)?></td></tr>
<?} ?>
<tr><td><?=Format:($row)?></td></tr>
Add After
<tr><td>Time Spent: <?=Format:($row)?> minutes</td></tr>
Find
<td><?=$ticket->getAttachmentStr($respID,'R')?></td></tr>
<?}?>
<tr><td> <?=Format:($resp_row)?></td></tr>
Add After
<tr><td>Time Spent: <?=Format:($resp_row)?> minutes</td></tr>
Begin2 Comment out
<tr><td>Total Time Spent: <?=Format:($total_times[$resp_row)?> minutes</td></tr>
End2 Comment out
Find
</select> <input type='checkbox' value='1' name=append checked="true" />Append
<?}?>
Add After
<label for="time_spent">Time Spent: </label><input type="text" name="time_spent" value="" id="time_spent">
End Add
Begin2 Add
<font class="error"> <?=$errors?></font>
Find
<label for="title">Note Title:</label>
<input type="text" name="title" id="title" value="<?=$info?>" size=30px />
</select><font class="error">* <?=$errors?></font>
Add After
<label for="time_spent">Time Spent: </label><input type="text" name="time_spent" value="" id="time_spent">
<font class="error">* <?=$errors?></font>
scp\tickets.php
Find
$fields = array('type'=>'text', 'required'=>1, 'error'=>'Response message required');
Add After
$fields = array('type'=>'int', 'required'=>1, 'error'=>'Time Spent required');
Find
if(!$errors && ($respId=$ticket->postResponse($_POST,$_POST,$_POST,$_FILES))){
Replace With
if(!$errors && ($respId=$ticket->postResponse($_POST,$_POST,$_POST,$_FILES, true, $_POST))){
Find
$fields = array('type'=>'string', 'required'=>1, 'error'=>'Note message required');
Add After
$fields = array('type'=>'int', 'required'=>1, 'error'=>'Time Spent required');
Find
if(!$errors && $ticket->postNote($_POST,$_POST)){
Replace With
if(!$errors && $ticket->postNote($_POST,$_POST, true, '', $_POST)){
Results