-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrem_d.php
59 lines (48 loc) · 1.6 KB
/
rem_d.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
<?
include("config.php");
include("functions.php");
$query = $_GET['q'];
$array_name = explode('*', $query);
$query = str_replace(' ', '*', $query);
$ds=ldap_connect($ldap_server);
//ldap_set_option($ds, LDAP_OPT_SIZELIMIT, 10);
$r=ldap_bind($ds, $ldap_admin, $ldap_password);
if(!$r) die("ldap_bind failed<br>");
//TODO make this generic and store it in the database or a config file
//The filter may need to be a function or something
$search="ou=People,o=nocccd.edu,o=cp";
$filter="(&(objectClass=*)(sn=McPhero*))";
$filter="(&(objectClass=*)(displayname=*McPheron*))";
$filter="(&(objectClass=*)(displayname=$query) )";
//$filter="(&(objectClass=*)(givenname=".$array_name[0].")(sn=Ho))";
//$filter="(&(objectClass=*)(displayname=".$search."))";
@$sr = ldap_search($ds, $search, $filter, array('sn', 'givenname', 'uid', 'displayname'), 0, 11, 10 );
@$info = ldap_get_entries($ds, $sr);
//TODO Security
//$info = array();
$sql = "
select id, firstname, lastname
from person
where id not like '0%'
and lower(firstname) || ' ' || lower(lastname) like '%".strtolower($query)."%'
";
$results = db_query($sql);
if($results){
foreach($results as $item){
$info[] = array(
0=>'sn',
'sn'=>array('count'=>1,0=>$item['lastname']),
1=>'givenname',
'givenname'=>array('count'=>1,0=>$item['firstname']),
2=>'uid',
'uid'=>array('count'=>1,0=>$item['id']),
3=>'displayname',
'displayname'=>array('count'=>1,0=>$item['firstname'].' '.$item['lastname'])
);
$info['count'] = $info['count'] + 1;
}
}
//print_r($info);
$json = json_encode($info);
echo $json;
?>