-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocomplete.php
executable file
·84 lines (74 loc) · 1.75 KB
/
autocomplete.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
<?php
/****
*
* @author: [email protected]
* @SVN: $Id$
* @Copyright 2009,2010 Litwicki Media LLC
*
***/
define('MY_DASHBOARD', true);
$root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($root_path . 'common.' . $phpEx);
$type = $_GET['type'];
if( $type == 'invoice' )
{
$sql = "SELECT
c.client_id as value, c.company,
(SELECT COUNT(invoice_id) FROM ".INVOICES_TABLE." WHERE client_id=c.client_id) AS invoice_count
FROM
".CLIENTS_TABLE." c
WHERE
(
company like '%" . sanitize($_GET['term']) . "%'
OR company like '%" . ucwords(sanitize($_GET['term'])) . "%'
AND client_id IN(SELECT client_id FROM ".INVOICES_TABLE.")
)";
$result = $db->sql_query($sql);
if( $db->sql_affectedrows($result) > 0 )
{
while( $row = $db->sql_fetchrow($result) )
{
$row['label'] = 'Client #' . $row['value'] . ' - ' . $row['company'] . ' (' . $row['invoice_count'] . ')';
$autocomplete[] = $row;
}
}
else
{
$row['label'] = 'No matches...';
$row['value'] = '0';
$autocomplete[] = $row;
}
}
if( $type == 'clientuser' || $type == 'messageuser' )
{
$sql = "SELECT
user_id, user_realname
FROM
".USERS_TABLE."
WHERE
user_realname like '%" . sanitize($_GET['term']) . "%'
OR user_realname like '%" . ucwords(sanitize($_GET['term'])) . "%'";
$result = $db->sql_query($sql);
if( $db->sql_affectedrows($result) > 0 )
{
while( $row = $db->sql_fetchrow($result) )
{
$row['label'] = $row['user_realname'] . ' (' . $row['user_id'] . ')';
$row['value'] = $row['user_id'];
$autocomplete[] = $row;
}
}
else
{
$row['label'] = 'No matches...';
$row['value'] = '0';
$autocomplete[] = $row;
}
}
if(!empty($autocomplete))
{
echo json_encode($autocomplete);
}
exit;
?>