/
incident_edit.php
290 lines (260 loc) · 12.5 KB
/
incident_edit.php
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
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
285
286
287
288
289
290
<?php
// edit_incident.php - Form for editing incident title and other fields
//
// SiT (Support Incident Tracker) - Support call tracking system
// 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.
//
// Soon to be replaced
// See incident/edit.inc.php
$permission = 7; // Edit Incidents
require ('core.php');
require (APPLICATION_LIBPATH . 'functions.inc.php');
// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');
// External variables
$submit = $_REQUEST['submit'];
$id = cleanvar($_REQUEST['id']);
$incidentid = $id;
// No submit detected show edit form
if (empty($submit))
{
$title = $strEdit;
include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
// extract incident details
$sql = "SELECT * FROM `{$dbIncidents}` WHERE id='$id'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
$incident = mysql_fetch_array($result);
// SUPPORT INCIDENT
if ($incident["type"] == "Support")
{
echo "<form action='{$_SERVER['PHP_SELF']}' method='post' name='editform'>";
echo "<table class='vertical'>";
echo "<tr><th>{$strTitle}</th><td><input maxlength='150' name='title' size='40' type='text' value=\"".$incident['title']."\" /></td></tr>\n";
echo "<tr><th>{$strTags}</th><td><textarea rows='2' cols='40' name='tags'>".list_tags($id, 2, false)."</textarea></td></tr>\n";
echo "<tr><th>{$strImportant}</th>";
echo "<td>{$strChangingContact}. ";
if ($incident['maintenanceid'] >= 1)
{
echo sprintf($strLoggedUnder, $incident['maintenanceid']).". ";
}
else echo "{$strIncidentNoContract}. ";
echo "{$strToChangeContract}.";
echo "</td></tr>\n";
echo "<tr><th>{$strContact}</th><td>";
echo contact_drop_down("contact", $incident["contact"], TRUE)."</td></tr>\n";
flush();
$maintid = maintenance_siteid($incident['maintenanceid']);
echo "<tr><th>{$strSite}</th><td>".site_name($maintid)."</td></tr>";
echo "<tr><th>{$strSkill}</th><td>".skill_drop_down("software", $incident["softwareid"])."</td></tr>\n";
echo "<tr><th>{$strVersion}</th>";
echo "<td><input maxlength='50' name='productversion' size='30' type='text' value=\"{$incident["productversion"]}\" /></td></tr>\n";
echo "<tr><th>{$strServicePacksApplied}</th>";
echo "<td><input maxlength='100' name='productservicepacks' size='30' type='text' value=\"{$incident["productservicepacks"]}\" /></td></tr>\n";
echo "<tr><th>CC {$strEmail}</th>";
echo "<td><input maxlength='255' name='ccemail' size='30' type='text' value=\"{$incident["ccemail"]}\" /></td></tr>\n";
echo "<tr><th>{$strEscalation}</th>";
echo "<td>".escalation_path_drop_down('escalationpath', $incident['escalationpath'])."</td></tr>";
echo "<tr><th>{$strExternalID}</th>";
echo "<td><input maxlength='50' name='externalid' size='30' type='text' value=\"{$incident["externalid"]}\" /></td></tr>\n";
echo "<tr><th>{$strExternalEngineersName}</th>";
echo "<td><input maxlength='80' name='externalengineer' size='30' type='text' value=\"{$incident["externalengineer"]}\" /></td></tr>\n";
echo "<tr><th>{$strExternalEmail}</th>";
echo "<td><input maxlength='255' name='externalemail' size='30' type='text' value=\"{$incident["externalemail"]}\" /></td></tr>\n";
plugin_do('edit_incident_form');
echo "</table>\n";
echo "<p align='center'>";
echo "<input name='type' type='hidden' value='Support' />";
echo "<input name='id' type='hidden' value=\"{$id}\" />";
echo "<input name='oldtitle' type='hidden' value=\"{$incident['title']}\" />";
echo "<input name='oldcontact' type='hidden' value=\"{$incident['contact']}\" />";
echo "<input name='oldccemail' type='hidden' value=\"{$incident['ccemail']}\" />";
echo "<input name='oldescalationpath' type='hidden' value=\"".db_read_column('name', $dbEscalationPaths, $incident["escalationpath"])."\" />";
echo "<input name='oldexternalid' type='hidden' value=\"{$incident['externalid']}\" />";
echo "<input name='oldexternalengineer' type='hidden' value=\"{$incident['externalengineer']}\" />";
echo "<input name='oldexternalemail' type='hidden' value=\"{$incident['externalemail']}\" />";
echo "<input name='oldpriority' type='hidden' value=\"{$incident['priority']}\" />";
echo "<input name='oldstatus' type='hidden' value=\"{$incident['status']}\" />";
echo "<input name='oldproductversion' type='hidden' value=\"{$incident['productversion']}\" />";
echo "<input name='oldproductservicepacks' type='hidden' value=\"{$incident['productservicepacks']}\" />";
echo "<input name='oldsoftware' type='hidden' value=\"{$incident['softwareid']}\" />";
echo "<input name='submit' type='reset' value='{$strReset}' /> <input name='submit' type='submit' value='{$strSave}' /></p>";
echo "</form>\n";
}
include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
}
else
{
// External variables
$externalid = cleanvar($_POST['externalid']);
$type = cleanvar($_POST['type']);
$ccemail = cleanvar($_POST['ccemail']);
$escalationpath = cleanvar($_POST['escalationpath']);
$externalengineer = cleanvar($_POST['externalengineer']);
$externalemail = cleanvar($_POST['externalemail']);
$title = cleanvar($_POST['title']);
$contact = cleanvar($_POST['contact']);
$software = cleanvar($_POST['software']);
$productversion = cleanvar($_POST['productversion']);
$productservicepacks = cleanvar($_POST['productservicepacks']);
$id = cleanvar($_POST['id']);
$oldtitle = cleanvar($_POST['oldtitle']);
$oldcontact = cleanvar($_POST['oldcontact']);
$maintid = cleanvar($_POST['maintid']);
$oldescalationpath = cleanvar($_POST['oldescalationpath']);
$oldexternalid = cleanvar($_POST['oldexternalid']);
$oldexternalemail = cleanvar($_POST['oldexternalemail']);
$oldproduct = cleanvar($_POST['oldproduct']);
$oldproductversion = cleanvar($_POST['oldproductversion']);
$oldproductservicepacks = cleanvar($_POST['oldproductservicepacks']);
$oldccemail = cleanvar($_POST['oldccemail']);
$oldexternalengineer = cleanvar($_POST['oldexternalengineer']);
$oldsoftware = cleanvar($_POST['oldsoftware']);
$tags = cleanvar($_POST['tags']);
// Edit the incident
// check form input
$errors = 0;
// check for blank contact
if ($contact == 0)
{
$errors += 1;
$error_string .= "<p class='error'>You must select a contact</p>\n";
}
// check for blank title
if ($title == '')
{
$errors += 1;
$error_string .= "<p class='error'>You must enter a title</p>\n";
}
if ($errors > 0)
{
echo "<div>$bodytext</div>";
}
if ($errors == 0)
{
$addition_errors = 0;
replace_tags(2, $id, $tags);
// update support incident
$sql = "UPDATE `{$dbIncidents}` ";
$sql .= "SET externalid='$externalid', ccemail='$ccemail', ";
$sql .= "escalationpath='$escalationpath', externalengineer='$externalengineer', externalemail='$externalemail', title='$title', ";
$sql .= "contact='$contact', softwareid='$software', productversion='$productversion', ";
$sql .= "productservicepacks='$productservicepacks', lastupdated='$now' WHERE id='$id'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
if (!$result)
{
$addition_errors = 1;
$addition_errors_string .= "<p class='error'>Update of incident failed</p>\n";
}
if ($addition_errors == 0)
{
// dump details to incident update
if ($oldtitle != $title) $header .= "Title: $oldtitle -> <b>$title</b>\n";
if ($oldcontact != $contact)
{
$contactname = contact_realname($contact);
$contactsite = contact_site($contact);
$header .= "Contact: " . contact_realname($oldcontact) . " -> <b>{$contactname}</b>\n";
$maintsiteid = maintenance_siteid(incident_maintid($id));
if ($maintsiteid > 0 AND contact_siteid($contact) != $maintsiteid)
{
$maintcontactsite = site_name($maintsiteid);
$header .= "Assigned to <b>{$contactname} of {$contactsite}</b> on behalf of {$maintcontactsite} (The contract holder)\n";
}
}
if ($oldexternalid != $externalid)
{
$header .= "External ID: ";
if ($oldexternalid != '')
{
$header .= $oldexternalid;
}
else
{
$header .= "None";
}
$header .= " -> <b>";
if ($externalid != '')
{
$header .= $externalid;
}
else
{
$header .= "None";
}
$header .= "</b>\n";
}
$escalationpath = db_read_column('name', $dbEscalationPaths, $escalationpath);
if ($oldccemail != $ccemail)
{
$header .= "CC Email: " . $oldccemail . " -> <b>" . $ccemail . "</b>\n";
}
if ($oldescalationpath != $escalationpath)
{
$header .= "Escalation: " . $oldescalationpath . " -> <b>" . $escalationpath . "</b>\n";
}
if ($oldexternalengineer != $externalengineer)
{
$header .= "External Engineer: " . $oldexternalengineer . " -> <b>" . $externalengineer . "</b>\n";
}
if ($oldexternalemail != $externalemail)
{
$header .= "External email: " . $oldexternalemail . " -> <b>" . $externalemail . "</b>\n";
}
if ($oldsoftware != $software)
{
$header .= "Skill: ".software_name($oldsoftware)." -> <b>".software_name($software)."</b>\n";
}
if ($oldproductversion != $productversion)
{
$header .= "Version: ".$oldproductversion." -> <b>".$productversion."</b>\n";
}
if ($oldproductservicepacks != $productservicepacks)
{
$header .= "Service Packs Applied: ".$oldproductservicepacks." -> <b>".$productservicepacks."</b>\n";
}
if (!empty($header)) $header .= "<hr>";
// get current incident status
$sql = "SELECT status FROM `{$dbIncidents}` WHERE id={$id}";
$result = mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
$status = mysql_fetch_object($result);
$status = $status->status;
$owner = incident_owner($id);
$bodytext = $header . $bodytext;
$bodytext = mysql_real_escape_string($bodytext);
$sql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, type, currentowner, currentstatus, bodytext, timestamp) ";
$sql .= "VALUES ('{$id}', '{$sit[2]}', 'editing', '{$owner}', '{$status}', '{$bodytext}', '{$now}')";
$result = mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
if (!$result)
{
$addition_errors = 1;
$addition_errors_string .= "<p class='error'>Addition of incident update failed</p>\n";
}
plugin_do('incident_edited');
}
if ($addition_errors == 0)
{
journal(CFG_LOGGING_NORMAL, 'Incident Edited', "Incident $id was edited", CFG_JOURNAL_INCIDENTS, $id);
html_redirect("incident_details.php?id={$id}");
}
else
{
include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
echo $addition_errors_string;
include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
}
}
else
{
include (APPLICATION_INCPATH . 'incident_html_top.inc.php');
echo $error_string;
include (APPLICATION_INCPATH . 'incident_html_bottom.inc.php');
}
}
?>