Add Time Spent at the Bottom of Each Staff’s Page of osTicket v1.6 RC5

For those of you who have implemented the modification I made about: Add Auto Staff Time Sheet Feature into osTicket v1.6 RC5, then this following modification is for you. It has the relationship with that modification above. After you implemented the previous one, and then if you wanted to display the time spent of each your staff at the bottom of staff’s page, simply access from Admin Panel -> Staff -> Staff Members, then click one of the records on the list. This modification will add some information that useful to know, especially for admin or manager. They are: Total time spent on tickets, Average time spent per ticket, Time spent within the last 14 days, Time spent within the last 7 days, Time spent on yesterday, and then Time spent on today.

Open your \include\staff\staff.inc.php file, and find this code:

147
148
        </tr>
    </table>

then replace with this following code:

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
        </tr>
 
        <?php if ($_REQUEST['a']!='new') { ?>
        <tr class="header"><td colspan=2>Employee Rating</td></tr>
        <tr class="subheader"><td colspan=2>
            Time Spent on tickets</b></td>
        </tr>
        <tr><th>Total</th>
            <td class="mainTableAlt">
            <?php
 
            $sql1 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                     FROM '.TICKET_RESPONSE_TABLE.'
                     WHERE staff_id='.db_input($rep["staff_id"]).'';
            $sql2 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                     FROM '.TICKET_NOTE_TABLE.'
                     WHERE staff_id='.db_input($rep["staff_id"]).'';
            $res1 = db_query($sql1);
            $res2 = db_query($sql2);
            $row1 = mysql_fetch_row($res1);
            $row2 = mysql_fetch_row($res2);
            $total_time = $row1[0] + $row2[0]; 
            $total_tick = $row1[1] + $row2[1];
            $total_time_format = Ticket::formatStaffTimeSheet($total_time);              
            echo $total_time_format;            
            ?>
            </td>
        </tr>
        <tr><th>Average Time per Ticket</th>
            <td class="mainTableAlt">
            <?php
            $avg_time_per_ticket = round($total_time / $total_tick);
            $avg_time_per_ticket_format = Ticket::formatStaffTimeSheet($avg_time_per_ticket);
            echo $avg_time_per_ticket_format;
            ?>
            </td>
        </tr>   
 
        <tr><th>Last 14 Days</th>
            <td class="mainTableAlt">
            <?php
             $sql1 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                      FROM '.TICKET_RESPONSE_TABLE.'
                      WHERE staff_id='.db_input($rep["staff_id"]).'
                      AND 14 >= TIMESTAMPDIFF(DAY,created,NOW())';
             $sql2 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                      FROM '.TICKET_NOTE_TABLE.'
                      WHERE staff_id='.db_input($rep["staff_id"]).'
                      AND 14 >= TIMESTAMPDIFF(DAY,created,NOW())';
             $res1 = db_query($sql1);
             $res2 = db_query($sql2);
             $row1 = mysql_fetch_row($res1);
             $row2 = mysql_fetch_row($res2);
             $total_time = $row1[0] + $row2[0]; 
             $total_tick = $row1[1] + $row2[1];
             $total_time_format = Ticket::formatStaffTimeSheet($total_time);              
             echo $total_time_format;                                        
             ?>
            </td>
        </tr>        
 
 
        <tr><th>Last 7 Days</th>
            <td class="mainTableAlt">
            <?php
            $sql1 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                     FROM '.TICKET_RESPONSE_TABLE.'
                     WHERE staff_id='.db_input($rep["staff_id"]).'
                     AND 7 >= TIMESTAMPDIFF(DAY,created,NOW())';
            $sql2 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                     FROM '.TICKET_NOTE_TABLE.'
                     WHERE staff_id='.db_input($rep["staff_id"]).'
                     AND 7 >= TIMESTAMPDIFF(DAY,created,NOW())';
            $res1 = db_query($sql1);
            $res2 = db_query($sql2);
            $row1 = mysql_fetch_row($res1);
            $row2 = mysql_fetch_row($res2);
            $total_time = $row1[0] + $row2[0]; 
            $total_tick = $row1[1] + $row2[1];
            $total_time_format = Ticket::formatStaffTimeSheet($total_time);              
            echo $total_time_format;                          
            ?>
            </td>
        </tr>        
 
        <tr><th>Yesterday</th>
            <td class="mainTableAlt">
            <?php
 
            $yday=strtotime("-1day");
            $yesterday=date("Y-m-d", $yday);
 
            $sql1 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                     FROM '.TICKET_RESPONSE_TABLE.'
                     WHERE staff_id='.db_input($rep["staff_id"]).' 
                     AND created LIKE "'.$yesterday.'%"';
            $sql2 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                     FROM '.TICKET_NOTE_TABLE.'
                     WHERE staff_id='.db_input($rep["staff_id"]).' 
                     AND created LIKE "'.$yesterday.'%"';
            $res1 = db_query($sql1);
            $res2 = db_query($sql2);
            $row1 = mysql_fetch_row($res1);
            $row2 = mysql_fetch_row($res2);
            $total_time = $row1[0] + $row2[0]; 
            $total_tick = $row1[1] + $row2[1];
            $total_time_format = Ticket::formatStaffTimeSheet($total_time);              
            echo $total_time_format;                          
            ?>
            </td>
        </tr>        
 
        <tr><th>Today</th>
            <td class="mainTableAlt">
            <?php
            $sql1 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                     FROM '.TICKET_RESPONSE_TABLE.'
                     WHERE staff_id='.db_input($rep["staff_id"]).'
                     AND 0 = TIMESTAMPDIFF(DAY,created,NOW())';
            $sql2 = 'SELECT SUM( time_spent ), COUNT( time_spent )
                     FROM '.TICKET_NOTE_TABLE.'
                     WHERE staff_id='.db_input($rep["staff_id"]).'
                     AND 0 = TIMESTAMPDIFF(DAY,created,NOW())';
            $res1 = db_query($sql1);
            $res2 = db_query($sql2);
            $row1 = mysql_fetch_row($res1);
            $row2 = mysql_fetch_row($res2);
            $total_time = $row1[0] + $row2[0]; 
            $total_tick = $row1[1] + $row2[1];
            $total_time_format = Ticket::formatStaffTimeSheet($total_time);              
            echo $total_time_format;                          
            ?>
            </td>
        </tr>        
 
        <?php } ?>
 
    </table>

Enjoy the result!

Share

869 viewsPrint This Post Print This Post

Comments

  1. Emanuel says:

    Dear,

    I try to implement the modify, but in the table ost_ticket_response i don’t have created the field time_spent and for that, i can’t apply the modify
    please you can tell me where created that field

  2. @Emanuel

    You have to apply first the modification from this following article:

    Add Auto Staff Time Sheet Feature into osTicket v1.6 RC5.

    Please read carefully the first sentence above.

Speak Your Mind

*


*