-
Notifications
You must be signed in to change notification settings - Fork 1
/
AJAX_nameList.php
executable file
·57 lines (45 loc) · 1.34 KB
/
AJAX_nameList.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
<?php
include("includes/commonFunctions.inc.php");
if(isset($_GET['search']))
{
$nameList = array();
try
{
include('includes/mysql_credentials.php');
$dbo = new PDO("mysql:host=localhost;dbname=".$mysql_database, $mysql_username, $mysql_password);
$dbo-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbo->prepare('SELECT fullname, displayname FROM profile');
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $cur_name)
{
$nameList[] = $cur_name['fullname'].
' |
<span style="color:#666">'.$cur_name['displayname'].'</span>
|
<a href="#" onclick="addToRecipients(\''.$cur_name['displayname'].'\')">Add</a>';
}
}
catch(PDOException $e)
{
echo("<span class='alert'>An error occurred! Please try again later!</span>");
exit();
}
catch(Exception $e)
{
echo("<span class='alert'>Unexpected error occurred! Please report to administrator!</span>");
exit();
}
$matches = array();
foreach($nameList as $name)
{
$pattern = "/^".$_GET['search']."/i";
if(preg_match($pattern, $name))
$matches[] = $name;
}
foreach($matches as $suggestion)
{
echo($suggestion.'<br/>');
}
}
?>