x
1
BEGIN
2
DECLARE _perm TINYINT(1);
3
SET _perm = (SELECT BIT_OR(0 < (userclasses.permissions & (1 << 15) OR userclasses.permissions & 1)) FROM userclasses JOIN users WHERE FIND_IN_SET(userclasses.classid, users.clientid) AND users.userid=userid);
4
5
PREPARE STMT FROM
6
"SELECT a.ContactID, IFNULL(b.Name, 'Global') AS `Name`, a.FirstName, a.LastName, a.Address1, a.Address2, a.City, a.State, a.Zip, a.Phone, a.Cell, a.Fax, a.Pager, a.Email, a.MSN, a.AIM, a.ICQ, a.Last_User, a.ClientID, a.LocationID, c.Name as LocationName, a.Password
7
FROM contacts a LEFT JOIN clients b ON a.clientid = b.clientid LEFT JOIN locations c ON a.locationid = c.locationid
8
Where
9
(a.clientid = 0 OR a.clientid = b.clientid) AND (
10
a.ClientID like CONCAT('%', ?, '%') or
11
a.FirstName like CONCAT('%', ?, '%') or
12
a.LastName like CONCAT('%', ?, '%') or
13
a.Address1 like CONCAT('%', ?, '%') or
14
a.Address2 like CONCAT('%', ?, '%') or
15
a.City like CONCAT('%', ?, '%') or
16
a.State like CONCAT('%', ?, '%') or
17
a.Zip like CONCAT('%', ?, '%') or
18
a.Phone like CONCAT('%', ?, '%') or
19
a.Fax like CONCAT('%', ?, '%') or
20
a.Cell like CONCAT('%', ?, '%') or
21
a.Pager like CONCAT('%', ?, '%') or
22
a.Email like CONCAT('%', ?, '%') or
23
a.MSN like CONCAT('%', ?, '%') or
24
a.AIM like CONCAT('%', ?, '%') or
25
a.ICQ like CONCAT('%', ?, '%')
26
) AND (a.clientid = 0 OR a.clientid IN (Select usersec.clientid FROM UserSec WHERE UserID=?))
27
AND (?)
28
order by b.Name, a.LastName, a.Firstname ASC
29
LIMIT ?,?";
30
SET @LIMIT = (page * pagesize) - pagesize;
31
SET @size = pagesize;
32
SET @s = search;
33
SET @U = userid;
34
SET @P = _perm;
35
EXECUTE STMT USING @s,@s,@s,@s,@s,@s,@s,@s,@s,@s,@s,@s,@s,@s,@s,@s,@U,@P,@LIMIT,@size;
36
37
END