forked from sitracker/sitracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinbox.php
More file actions
472 lines (432 loc) · 18 KB
/
inbox.php
File metadata and controls
472 lines (432 loc) · 18 KB
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<?php
// inbox.php - View/Respond to incoming email
//
// 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.
require ('core.php');
$permission = PERM_UPDATE_DELETE;
require (APPLICATION_LIBPATH . 'functions.inc.php');
// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');
// External variables
$sort = cleanvar($_REQUEST['sort']);
$order = cleanvar($_REQUEST['order']);
$filter = cleanvar($_REQUEST['filter']);
$displayid = cleanvar($_REQUEST['id']);
$action = clean_fixed_list($_REQUEST['action'], array('','delete','lock','unlock','updatereason'));
if (empty($displayid))
{
$refresh = $_SESSION['userconfig']['incident_refresh'];
}
else
{
$refresh = 0;
}
$title = $strInbox;
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
if (empty($sort)) $sort = 'date';
function contact_info($contactid, $email, $name, $subject)
{
global $strUnknown, $strIncidentsMulti, $strOpen, $strContact, $strEmail;
$linktext = $strUnknown;
$contactname = '';
$info .= icon('email', 16, $strEmail, $strEmail);
if (!empty($contactid))
{
$info .= " <a href='contact_details.php?id={$contactid}'>";
$info .= icon('contact', 16, $strContact, $strContact);
$info .= "</a>";
$contactname = contact_realname($contactid);
}
$info .= ' ';
if (!empty($contactname) AND $contactname != $strUnknown)
{
$linktext = $contactname;
}
elseif (!empty($name))
{
$linktext = "{$name}";
}
elseif (!empty($email))
{
$linktext = "{$email}";
}
else
{
$linktext .= "{$strUnknown}";
}
if (!empty($email))
{
$mailto = "mailto:{$email}";
if (!empty($subject))
{
$mailto .= "?subject=".urlencode($subject);
}
$info .= "<a href=\"{$mailto}\" class='info'>";
}
$info .= $linktext;
if (!empty($email))
{
$info .= "<span>";
$info .= gravatar($email, 50, FALSE);
$info .= "<div class='popupcontactinfo' style='float:right'>";
if (!empty($contactid))
{
$info .= contact_realname($contactid) . '<br />';
$openincidents = contact_count_open_incidents($contactid);
if ($openincidents > 0)
{
$info .= "<strong>{$strOpen}</strong>: " . sprintf($strIncidentsMulti, $openincidents) . '<br />';
}
}
$info .= "{$email}";
$info .= "</div>";
$info .= "</span>";
$info .= "</a>";
}
if (!empty($contactid))
{
$info .= " (".contact_site($contactid).")";
}
return $info;
}
// Perform action on selected items
if (!empty($action))
{
if (!is_array($_REQUEST['selected']))
{
$_REQUEST['selected'] = array($_REQUEST['selected']);
}
foreach ($_REQUEST['selected'] AS $item => $selected)
{
$selected = clean_int($selected);
$tsql = "SELECT updateid, locked FROM `{$dbTempIncoming}` WHERE id={$selected}";
$tresult = mysqli_query($db, $tsql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_WARNING);
if ($tresult AND mysqli_num_rows($tresult) > 0)
{
$temp = mysqli_fetch_object($tresult);
switch ($action)
{
case 'delete':
if ($temp->locked == $sit[2] OR empty($temp->locked))
{
// Only allow the person who has the update located delete it
$dsql = "DELETE FROM `{$dbUpdates}` WHERE id={$temp->updateid}";
mysqli_query($db, $dsql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_ERROR);
$dsql = "DELETE FROM `{$dbTempIncoming}` WHERE id={$selected}";
mysqli_query($db, $dsql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_ERROR);
}
break;
case 'lock':
$lockeduntil = date('Y-m-d H:i:s', $now + $CONFIG['record_lock_delay']);
$sql = "UPDATE `{$dbTempIncoming}` SET locked='{$sit[2]}', lockeduntil='{$lockeduntil}' ";
$sql .= "WHERE id='{$selected}' AND (locked = 0 OR locked IS NULL)";
$result = mysqli_query($db, $sql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_ERROR);
break;
case 'unlock':
$sql = "UPDATE `{$dbTempIncoming}` AS t SET locked=NULL, lockeduntil=NULL ";
$sql .= "WHERE id='{$selected}' AND locked = '{$sit[2]}'";
$result = mysqli_query($db, $sql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_ERROR);
$displayid = null;
break;
case 'updatereason':
$newreason = clean_dbstring($_REQUEST['newreason']);
$updatetime = date('Y-m-d H:i:s',$now);
$update = "UPDATE `{$dbTempIncoming}` SET reason='{$newreason}', ";
$update .= "reason_user='{$sit['2']}', reason_time='{$updatetime}' WHERE id={$selected}";
mysqli_query($db, $update);
if (mysqli_error($db)) trigger_error(mysqli_error($db),E_USER_ERROR);
break;
default:
trigger_error('Unrecognised form action', E_USER_ERROR);
}
}
}
}
if (empty($displayid))
{
if ($CONFIG['enable_inbound_mail'] == 'disabled')
{
echo "<p class='warning'>{$strInboundEmailIsDisabled}</p>";
}
else
{
echo "<h2>".icon('email', 32)." {$CONFIG['email_address']}: {$strInbox}</h2>";
plugin_do('inbox');
echo "<p align='center'>{$strIncomingEmailText}. <a href='{$_SERVER['PHP_SELF']}'>{$strRefresh}</a></p>";
}
// Show list of items in inbox
$sql = "SELECT * FROM `{$dbTempIncoming}` ";
if (!empty($sort))
{
if ($order == 'a' OR $order == 'ASC' OR $order == '') $sortorder = "ASC";
else $sortorder = "DESC";
switch ($sort)
{
case 'from':
$sql .= " ORDER BY `from` {$sortorder}";
break;
case 'subject':
$sql .= " ORDER BY `subject` {$sortorder}";
break;
case 'date':
$sql .= " ORDER BY `arrived` {$sortorder}";
break;
default:
$sql .= " ORDER BY `id` DESC";
break;
}
}
$result = mysqli_query($db, $sql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_WARNING);
$countresults = mysqli_num_rows($result);
if ($countresults > 0)
{
echo "<form action='{$_SERVER['PHP_SELF']}' id='inboxform' name='inbox' method='post'>";
$shade = 'shade1';
echo "<table class='maintable' id='inboxtable'>";
echo "<tr>";
echo colheader('select', '', FALSE, '', '', '', '1%');
echo colheader('from', $strFrom, $sort, $order, $filter, '', '25%');
echo colheader('subject', $strSubject, $sort, $order, $filter);
echo colheader('date', $strDate, $sort, $order, $filter, '', '15%');
echo colheader('size', $strSize);
echo "</tr>";
while ($incoming = mysqli_fetch_object($result))
{
$num_attachments = 0;
if (!empty($incoming->updateid))
{
$usql = "SELECT * FROM `{$dbUpdates}` WHERE id = '{$incoming->updateid}' LIMIT 1";
$uresult = mysqli_query($db, $usql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_WARNING);
$update = mysqli_fetch_object($uresult);
$asql = "SELECT COUNT(*) FROM `{$dbLinks}` WHERE linktype = 5 AND direction = 'left' AND origcolref = {$incoming->updateid}";
$aresult = mysqli_query($db, $asql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_WARNING);
list($num_attachments) = mysqli_fetch_row($aresult);
}
echo "<tr class='{$shade}' onclick='trow(event);'>";
echo "<td>";
if (empty($incoming->locked) OR $incoming->locked == $sit[2])
{
echo html_checkbox('selected[]', FALSE, $incoming->id);
}
echo "</td>";
echo "<td>".contact_info($incoming->contactid, $incoming->from, $incoming->emailfrom, $incoming->subject)."</td>";
echo "</td>";
// Subject
echo "<td>";
if (($incoming->locked != $sit[2]) AND ($incoming->locked > 0))
{
echo icon('locked', 16) . ' ';
echo sprintf($strLockedByX, user_realname($incoming->locked, TRUE));
if (!empty($incoming->reason))
{
echo " ({$incoming->reason})";
}
echo " — <a name='locked' class='info'>";
echo htmlentities($incoming->subject,ENT_QUOTES, $GLOBALS['i18ncharset']);
}
else
{
if ($incoming->locked > 0)
{
echo icon('locked', 16) . ' ';
if (!empty($incoming->reason))
{
echo " ({$incoming->reason})";
}
}
// TODO option for popup or not (Mantis 619)
// $url = "javascript:incident_details_window('{$incoming->id}','incomingview');";
// $url = "incident_details.php?id={$incoming->id}&win=incomingview";
$url = "inbox.php?id={$incoming->id}";
echo "<a href=\"{$url}\" id='update{$incoming->updateid}' class='info'";
echo " title='{$strViewAndLockHeldEmail}'>";
if (!empty($incoming->incident_id)) echo icon('support',16) . ' ';
echo htmlentities($incoming->subject,ENT_QUOTES, $GLOBALS['i18ncharset']);
}
if (!empty($update->bodytext)) echo '<span>'.parse_updatebody(truncate_string($update->bodytext, 1024)).'</span>';
echo "</a>";
if ($num_attachments > 0) echo ' '.icon('attach', 16, '', "{$strAttachments}: {$num_attachments}");
echo "</td>";
// echo "<td><pre>".print_r($incoming,true)."</pre><hr /></td>";
// Date
echo "<td>";
$arrived = mysql2date($incoming->arrived);
// If there's no arrival time on the email we use the update timestamp
if ($arrived == 0)
{
$arrived = $update->timestamp;
}
if (!empty($update->timestamp))
{
echo ldate($CONFIG['dateformat_datetime'], $arrived);
}
echo "</td>";
// Size
echo "<td style='white-space:nowrap;'>";
echo readable_bytes_size(mb_strlen($update->bodytext));
echo "</td>";
echo "</tr>";
if ($shade == 'shade1') $shade = 'shade2';
else $shade = 'shade1';
}
echo "<tr>";
// Select All
echo "<td>".html_checkbox('item', FALSE, '', "onclick=\"checkAll('inboxform', this.checked);\"")."</td>";
// Operation
echo "<td colspan='*'>";
echo "<select name='action'>";
echo "<option value='' selected='selected'></option>";
echo "<option value='lock'>{$strLock}</option>";
echo "<option value='unlock'>{$strUnlock}</option>";
echo "<option value='delete'>{$strDelete}</option>";
// echo "<option value='assign'>{$strAssign}</option>";
echo "</select>";
echo "<input type='submit' value=\"{$strGo}\" />";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>\n";
}
else
{
echo user_alert($strNoRecords, E_USER_NOTICE);
}
}
else
{
// Display single message
$sql = "SELECT * FROM `{$dbTempIncoming}` WHERE id = {$displayid}";
$result = mysqli_query($db, $sql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_WARNING);
if ($result AND mysqli_num_rows($result) > 0)
{
$incoming = mysqli_fetch_object($result);
$usql = "SELECT * FROM `{$dbUpdates}` WHERE id = '{$incoming->updateid}' LIMIT 1";
$uresult = mysqli_query($db, $usql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_WARNING);
$update = mysqli_fetch_object($uresult);
echo "<div class='detailhead'>";
echo "<div class='detaildate'>";
if (!empty($update->timestamp)) echo date($CONFIG['dateformat_datetime'], $update->timestamp);
echo "</div>";
echo icon('email',16);
if (!empty($_REQUEST['reply']))
{
echo " <strong>{$strReplyTo}:</strong> ";
}
echo " {$incoming->subject}";
if (!empty($_REQUEST['reply']))
{
echo " — ";
echo "<a href='{$_SERVER['PHP_SELF']}?id={$displayid}'>{$strView}</a>";
}
// Inbox item locking
$lockedbyyou = false;
if (!$incoming->locked)
{
//it's not locked, lock for this user
$lockeduntil = date('Y-m-d H:i:s', $now + $CONFIG['record_lock_delay']);
$sql = "UPDATE `{$dbTempIncoming}` SET locked='{$sit[2]}', lockeduntil='{$lockeduntil}' WHERE id='{$displayid}' AND (locked = 0 OR locked IS NULL)";
$result = mysqli_query($db, $sql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_ERROR);
$lockedbyname = $strYou;
$lockedbyyou = true;
$incoming->locked = true;
}
elseif ($incoming->locked != $sit[2])
{
$lockedby = $incoming->locked;
$lockedbysql = "SELECT realname FROM `{$dbUsers}` WHERE id={$lockedby}";
$lockedbyresult = mysqli_query($db, $lockedbysql);
if (mysqli_error($db)) trigger_error("MySQL Query Error ".mysqli_error($db), E_USER_WARNING);
while ($row = mysqli_fetch_object($lockedbyresult))
{
$lockedbyname = $row->realname;
}
}
else
{
$lockedbyname = $strYou;
$lockedbyyou = true;
}
if (empty($_REQUEST['reply']))
{
echo " — ";
// Reply feature incomplete and therefore disabled for 3.90, I aim to finish this code soon. INL 4/5/2013
// echo "<a href='{$_SERVER['PHP_SELF']}?id={$displayid}&reply=true'>{$strReply}</a> | ";
if (!empty($incoming->forenames) OR !empty($incoming->surname))
{
$search_string = urlencode("{$incoming->forenames} {$incoming->surname}");
}
else if (!empty($incoming->emailfrom))
{
$search_string = urlencode($incoming->emailfrom);
}
else
{
$search_string = urlencode($incoming->from);
}
echo "<a href='{$_SERVER['PHP_SELF']}?action=delete&selected={$displayid}'>{$strDelete}</a>";
if (!$incoming->locked)
{
echo " | <a href='{$_SERVER['PHP_SELF']}?id={$displayid}&action=lock&selected={$displayid}'>{$strLock}</a>";
}
elseif ($lockedbyyou)
{
echo " | <a href='{$_SERVER['PHP_SELF']}?id={$displayid}&action=unlock&selected={$displayid}'>{$strUnlock}</a>";
}
echo " | <a href=\"incident_new.php?action=findcontact&incomingid={$displayid}&search_string={$search_string}&from={$incoming->emailfrom}&contactid={$incoming->contactid}&win=incomingcreate\" title=\"{$strCreateAnIncident}\">{$strCreateNewIncident}</a>";
echo " | <a href=\"move_update.php?id={$displayid}&updateid={$incoming->updateid}&contactid={$incoming->contactid}&win=incomingview\" title=\"{$strUpdateIncident}\">";
echo "{$strMoveToIncident}</a>";
if ($lockedbyyou)
{
echo "<div class='detaildate'>";
echo "<form method='post' action='{$_SERVER['PHP_SELF']}?selected={$displayid}&win=incomingview&action=updatereason'>";
echo "{$strMessage}: <input name='newreason' type='text' value=\"{$incoming->reason}\" size='25' maxlength='100' />";
echo "<input type='submit' value='{$strSave}' />";
echo "</form>";
echo "</div>";
}
else
{
echo "<div class='detaildate'>{$incoming->reason}</div>";
}
}
echo "</div>";
// Reply form
echo "<div class='detailentry'>\n";
if (!empty($_REQUEST['reply']))
{
echo "{$strSubject}: <input type='text' value=\"Re: {$incoming->subject}\" size='40' />";
echo "<textarea style='width: 98%' rows='30'>";
echo quote_message($update->bodytext);
echo "</textarea>";
// TODO reply button and make reply actually work.
}
else
{
echo parse_updatebody($update->bodytext, FALSE);
}
echo "</div>";
echo "<p><a href='{$_SERVER['PHP_SELF']}'>< {$strBackToList}</a></p>";
}
else
{
user_alert($strNoRecords, E_USER_NOTICE);
}
}
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
?>