~sit-developers/sit/master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
<?php
// incident_service_levels.php - Display sla status
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2010-2014 The Support Incident Tracker Project
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//

// Author: Ivan Lucas <ivanlucas[at]users.sourceforge.net>

require ('core.php');
$permission = PERM_INCIDENT_LIST; // View Incidents
require (APPLICATION_LIBPATH . 'functions.inc.php');

require (APPLICATION_LIBPATH . 'auth.inc.php');

$incidentid = clean_int($_REQUEST['id']);
$id = $incidentid;

$title = $strServiceLevels;

include (APPLICATION_INCPATH . 'incident_html_top.inc.php');

// Retrieve incident
// extract incident details
$sql  = "SELECT *, i.id AS incidentid, ";
$sql .= "c.id AS contactid ";
$sql .= "FROM `{$dbIncidents}` AS i, `{$dbContacts}` AS c ";
$sql .= "WHERE (i.id='{$incidentid}' AND i.contact = c.id) ";
$sql .= " OR i.contact=NULL ";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
$incident = mysql_fetch_object($result);

$site_name = site_name($incident->siteid);
$product_name = product_name($incident->product);
if ($incident->softwareid > 0) $software_name = software_name($incident->softwareid);

$servicelevel_tag = $incident->servicelevel;
if ($servicelevel_tag == '')
{
    $servicelevel_tag = maintenance_servicelevel_tag($incident->maintenanceid);
}
$opened_for = format_seconds(time() - $incident->opened);

echo "<h2>".icon('sla', 32)." ";
echo "{$strServiceHistory}</h2>";
echo "<p align='center'>{$strServiceLevel}: {$servicelevel_tag}</p>";

// Create an array containing the service level history
$slahistory = incident_sla_history($incidentid);

if (count($slahistory) >= 1)
{
    echo "<table class='maintable'>";
    echo "<tr><th>{$strEvent}</th><th>{$strUser}</th><th>{$strTarget}</th><th>{$strActual}</th><th>{$strDateAndTime}</th></tr>\n";
    foreach ($slahistory AS $history)
    {
        if (empty($history['targetsla'])) break; // Skip any empty SLA history
        if ($history['targetmet'] == FALSE)
        {
            $class = 'critical';
        }
        else
        {
            $class = 'shade2';
        }
        echo "<tr class='{$class}'>";
        echo "<td>";
        echo icon($slatypes[$history['targetsla']]['icon'], 16)." ";
        echo target_type_name($history['targetsla'])."</td>";
        echo "<td>";
        if (!empty($history['userid']))
        {
            echo user_realname($history['userid'], TRUE);
        }
        echo "</td>";
        echo "<td>".format_workday_minutes($history['targettime'])."</td>";
        echo "<td>";
        if ($history['timestamp'] == 0)
        {
            echo "<em>";
        }
        echo format_workday_minutes($history['actualtime']);
        if ($history['timestamp'] == 0)
        {
            echo "</em>";
        }
        echo "</td>";
        echo "<td>";
        if ($history['timestamp'] > 0)
        {
            echo ldate($CONFIG['dateformat_datetime'],$history['timestamp']);
        }
        echo "</td>";
    }
    echo "</table>\n";
}
else
{
    echo user_alert($strNothingToDisplay, E_USER_NOTICE);
}

//start status summary
$sql = "SELECT u.id AS updatesid, incidentid, userid, type, timestamp, currentstatus, is.id, is.name AS name ";
$sql .= "FROM `{$dbUpdates}` AS u, `{$dbIncidentStatus}` AS `is` ";
$sql .= " WHERE incidentid = '{$incidentid}' ";
$sql .= " AND u.currentstatus = is.id ";
$sql .= " ORDER BY timestamp ASC";

$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);

if (mysql_num_rows($result) > 0)
{
    $updatearray = array();
    $last = -1;
    $laststatus;
    while ($row = mysql_fetch_object($result))
    {
        $updatearray[$row->currentstatus]['name'] = $row->name;
        if ($last == -1)
        {
            $updatearray[$row->currentstatus]['time'] = 0;
        }
        else
        {
            $updatearray[$laststatus]['time'] += 60 * calculate_incident_working_time($row->incidentid, $last, $row->timestamp, array(2,7));
        }

        $laststatus = $row->currentstatus;
        $last = $row->timestamp;
    }

    if ($incident->status == 7 OR $incident->status == 2)
    {
        $end = $incident->closed;
    }
    else
    {
        $end = $now;
    }

    $publicholidays = get_public_holidays($incident->opened, $end);

    //calculate the last update
    $updatearray[$laststatus]['time'] += 60 * calculate_working_time($last, time(), $publicholidays);

    if (extension_loaded('gd'))
    {
        echo "<h3>{$strStatusSummary}</h3>";
        $data = array();
        $legends;
        foreach ($updatearray as $row)
        {
            array_push($data, $row['time']);
            $legends .= $GLOBALS[$row['name']]."|";
        }
        $data = implode('|',$data);
        $title = urlencode($strStatusSummary);
        echo "<div style='text-align:center;'>";
        echo "<img src='chart.php?type=pie&data={$data}&legends={$legends}&title={$title}&unit=seconds' />";
        echo "</div>";
    }
    else
    {
        echo "<table class='maintable'>";
        echo "<tr><th>{$strStatus}</th><th>{$strTime}</th></tr>\n";
        foreach ($updatearray as $row)
        {
            echo "<tr><td>".$row['name']. "</td><td>".format_seconds($row['time'])."</td></tr>";
        }
        echo '</table>';
    }
}

include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');

?>