-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
executable file
·46 lines (38 loc) · 982 Bytes
/
search.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
<?php
require_once 'php/DataBase.class.php';
require_once 'config.php';
$MySQLDatabase = new DataBase($db_host, $db_name);
$role = '';
$results = array();
// Check for missing parameters
if (!@$_GET['term']){
echo 'this script requires a get variable like "search.php?term=xxxxxxx"';
return;
}
$MySQLDatabase
->connect($db_user, $db_pass)
->getRole($_SERVER['PHP_AUTH_USER'], $role)
->searchUsers($_GET['term'], $results)
->disconnect();
// Matching users should be returned in standard json format.
//echo json_encode($results),'<br/><br/>';
// Replacement for json_encode. Remove after netserv upgrades to php 5.3
$firstItem = true;
$firstResult = true;
echo '[';
foreach ($results as $matchingUsers) {
if (!$firstResult)
echo ',';
echo '{';
foreach ($matchingUsers as $attribute => $value) {
if (!$firstItem)
echo ',';
echo '"',$attribute,'":"',$value,'"';
$firstItem = false;
}
$firstItem = true;
echo '}';
$firstResult = false;
}
echo ']';
?>