/
ajaxdata.php
291 lines (263 loc) · 10.1 KB
/
ajaxdata.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
291
<?php
// ajaxdata.php - Return data for AJAX calls
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2000-2007 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>
$permission = 0; // not required
require ('core.php');
require (APPLICATION_LIBPATH . 'functions.inc.php');
// This page requires authentication
if ($_REQUEST['action'] == 'contexthelp' AND $_REQUEST['auth'] == 'portal')
{
// Special exception for contexthelp, use the portal authentication for
// portal help tips
$accesslevel = 'any';
require (APPLICATION_LIBPATH . 'portalauth.inc.php');
}
else
{
require (APPLICATION_LIBPATH . 'auth.inc.php');
}
$action = cleanvar($_REQUEST['action']);
$selected = cleanvar($_REQUEST['selected']);
if ($_SESSION['auth'] == TRUE)
{
$styleid = $_SESSION['style'];
}
else
{
$styleid = $CONFIG['default_interface_style'];
}
$iconsql = "SELECT iconset FROM `{$GLOBALS['dbInterfaceStyles']}` WHERE id='{$styleid}'";
$iconresult = mysql_query($iconsql);
if (mysql_error())trigger_error(mysql_error(),E_USER_WARNING);
list($iconset) = mysql_fetch_row($iconresult);
switch ($action)
{
case 'auto_save':
$userid = cleanvar($_REQUEST['userid']);
$incidentid = cleanvar($_REQUEST['incidentid']);
$type = cleanvar($_REQUEST['type']);
$draftid = cleanvar($_REQUEST['draftid']);
$meta = cleanvar($_REQUEST['meta']);
$content = cleanvar($_REQUEST['content']);
if ($userid == $_SESSION['userid'])
{
if ($draftid == -1)
{
$sql = "INSERT INTO `{$dbDrafts}` (userid,incidentid,type,meta,content,lastupdate) VALUES ('{$userid}','{$incidentid}','{$type}','{$meta}','{$content}','{$now}')";
}
else
{
$sql = "UPDATE `{$dbDrafts}` SET content = '{$content}', meta = '{$meta}', lastupdate = '{$now}' WHERE id = {$draftid}";
}
$result = mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
echo mysql_insert_id();
}
break;
case 'servicelevel_timed':
$sltag = servicelevel_id2tag(cleanvar($_REQUEST['servicelevel']));
if (servicelevel_timed($sltag))
{
echo "TRUE";
}
else
{
echo "FALSE";
}
break;
case 'contexthelp':
$context = cleanvar($_REQUEST['context']);
$helpfile = APPLICATION_HELPPATH . "{$_SESSION['lang']}". DIRECTORY_SEPARATOR . "{$context}.txt";
// Default back to english if language helpfile isn't found
if (!file_exists($helpfile)) $helpfile = APPLICATION_HELPPATH . "{$_SESSION['lang']}". DIRECTORY_SEPARATOR. "en-GB/{$context}.txt";
if (file_exists($helpfile))
{
$fp = fopen($helpfile, 'r', TRUE);
$helptext = fread($fp, 1024);
fclose($fp);
echo nl2br($helptext);
}
else echo "Error: Missing helpfile '{$_SESSION['lang']}/{$context}.txt'";
break;
case 'dismiss_notice':
require (APPLICATION_LIBPATH . 'auth.inc.php');
$noticeid = cleanvar($_REQUEST['noticeid']);
$userid = cleanvar($_REQUEST['userid']);
if (is_numeric($noticeid))
{
$sql = "DELETE FROM `{$GLOBALS['dbNotices']}` WHERE id='{$noticeid}' AND userid='{$sit[2]}'";
mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
else echo "deleted {$noticeid}";
}
elseif ($noticeid == 'all')
{
$sql = "DELETE FROM `{$GLOBALS['dbNotices']}` WHERE userid={$userid} LIMIT 20"; // only delete 20 max as we only show 20 max
mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
else echo "deleted {$noticeid}";
}
break;
case 'dashboard_display':
require (APPLICATION_LIBPATH . 'auth.inc.php');
$dashboard = cleanvar($_REQUEST['dashboard']);
$dashletid = 'win'.cleanvar($_REQUEST['did']);
// FIXME need some sanitation here
include (APPLICATION_PLUGINPATH . "dashboard_{$dashboard}.php");
$dashfn = "dashboard_{$dashboard}_display";
echo $dashfn($dashletid);
break;
case 'dashboard_save':
case 'dashboard_edit':
require (APPLICATION_LIBPATH . 'auth.inc.php');
$dashboard = cleanvar($_REQUEST['dashboard']);
$dashletid = 'win'.cleanvar($_REQUEST['did']);
// FIXME need some sanitation here
include (APPLICATION_PLUGINPATH . "dashboard_{$dashboard}.php");
$dashfn = "dashboard_{$dashboard}_edit";
echo $dashfn($dashletid);
break;
case 'autocomplete_sitecontact':
$s = cleanvar($_REQUEST['s']);
// JSON encoded
$sql = "SELECT DISTINCT forenames, surname FROM `{$dbContacts}` ";
$sql .= "WHERE active='true' AND (forenames LIKE '{$s}%' OR surname LIKE '{$s}%')";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
if (mysql_num_rows($result) > 0)
{
while ($obj = mysql_fetch_object($result))
{
$str .= "[\"".$obj->forenames." ".$obj->surname."\"],";
}
}
$sql = "SELECT DISTINCT name FROM `{$dbSites}` ";
$sql .= "WHERE active='true' AND name LIKE '{$s}%'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
if (mysql_num_rows($result) > 0)
{
while ($obj = mysql_fetch_object($result))
{
$str .= "[\"".$obj->name."\"],";
}
}
echo "[".substr($str,0,-1)."]";
break;
case 'tags':
$sql = "SELECT DISTINCT t.name FROM `{$dbSetTags}` AS st, `{$dbTags}` AS t WHERE st.tagid = t.tagid GROUP BY t.name";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
if (mysql_num_rows($result) > 0)
{
while ($obj = mysql_fetch_object($result))
{
$str .= "[".$obj->name."],";
}
}
echo "[".substr($str,0,-1)."]";
break;
case 'contact' :
$s = cleanvar($_REQUEST['s']);
$sql = "SELECT DISTINCT forenames, surname FROM `{$dbContacts}` ";
$sql .= "WHERE active='true' AND (forenames LIKE '{$s}%' OR surname LIKE '{$s}%')";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
if (mysql_num_rows($result) > 0)
{
while ($obj = mysql_fetch_object($result))
{
$str .= "[\"".$obj->forenames." ".$obj->surname."\"],";
}
}
echo "[".substr($str,0,-1)."]";
break;
case 'sites':
$s = cleanvar($_REQUEST['s']);
$sql = "SELECT DISTINCT name FROM `{$dbSites}` ";
$sql .= "WHERE active='true' AND name LIKE '{$s}%'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
if (mysql_num_rows($result) > 0)
{
while ($obj = mysql_fetch_object($result))
{
$str .= "[\"".$obj->name."\"],";
}
}
echo "[".substr($str,0,-1)."]";
break;
case 'slas':
$sql = "SELECT DISTINCT tag FROM `{$dbServiceLevels}`";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
while ($obj = mysql_fetch_object($result))
{
$strIsSelected = '';
if ($obj->tag == $selected)
{
$strIsSelected = "selected='selected'";
}
echo "<option value='{$obj->tag}' $strIsSelected>{$obj->tag}</option>";
}
break;
case 'products':
$sql = "SELECT id, name FROM `{$dbProducts}` ORDER BY name ASC";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
while ($obj = mysql_fetch_object($result))
{
$strIsSelected = '';
if ($obj->id == $selected)
{
$strIsSelected = "selected='selected'";
}
echo "<option value='{$obj->id}' $strIsSelected>{$obj->name}</option>";
}
break;
case 'skills':
$sql = "SELECT id, name FROM `{$dbSoftware}` ORDER BY name ASC";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
while ($obj = mysql_fetch_object($result))
{
$strIsSelected = '';
if ($obj->id == $selected)
{
$strIsSelected = "selected='selected'";
}
echo "<option value='{$obj->id}' $strIsSelected>{$obj->name}</option>";
}
break;
case 'storedashboard':
$id = $_REQUEST['id'];
$val = $_REQUEST['val'];
if ($id == $_SESSION['userid'])
{
//check you're changing your own
$sql = "UPDATE `{$dbUsers}` SET dashboard = '$val' WHERE id = '$id'";
$contactresult = mysql_query($sql);
if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
}
break;
case 'checkldap':
$ldap_host = cleanvar($_REQUEST['ldap_host']);
$ldap_port = cleanvar($_REQUEST['ldap_port']);
$ldap_protocol = cleanvar($_REQUEST['ldap_protocol']);
$ldap_security = cleanvar($_REQUEST['ldap_security']);
$ldap_user = cleanvar($_REQUEST['ldap_bind_user']);
$ldap_password = cleanvar($_REQUEST['ldap_bind_pass']);
$r = ldapOpen($ldap_host, $ldap_port, $ldap_protocol, $ldap_security, $ldap_user, $ldap_password);
if ($r == -1) echo "0"; // Failed
else echo "1"; // Success
break;
default : break;
}
?>