-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveSearch.php
73 lines (66 loc) · 2.42 KB
/
LiveSearch.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
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<?php
$xmlDoc = new DOMDocument();
$xmlDoc -> load("PhonebookFiles/Web_Phonebook.xml");
$x = $xmlDoc -> getElementsByTagName('Contact');
//get the q parameter from URL
$q = $_GET["q"];
//lookup all links from the xml file if length of q > 0
if (strlen($q) > 0)
{
$ResultItem="";
$Output = '
<table class="table-striped w-100 text-white">
<tr>
<th>Name</th>
<th>Extension</th>
</tr>';
for($i=0; $i < ($x -> length); $i++)
{
$NameNode = $x -> item($i) -> getElementsByTagName('Name');
$ExtNode = $x -> item($i) -> getElementsByTagName('Ext');
if ($NameNode -> item(0) -> nodeType == 1)
{
//find a link matching the search text
if ( (stristr($NameNode -> item(0) -> childNodes -> item(0) -> nodeValue, $q) ) || (stristr($ExtNode -> item(0) -> childNodes -> item(0) -> nodeValue, $q) ) )
{
if ($ResultItem == "")
{
$ResultItem = "
<tr>
<td class='text-left'>
<a href='tel:" . $ExtNode -> item(0) -> childNodes -> item(0) -> nodeValue . "'>" . $NameNode -> item(0) -> childNodes -> item(0) -> nodeValue . "</a>
</td>
<td class='text-right'>
<a href='tel:" . $ExtNode -> item(0) -> childNodes -> item(0) -> nodeValue . "'>" . $ExtNode -> item(0) -> childNodes -> item(0) -> nodeValue . "</a>
</td>
</tr>";
} else
{
$ResultItem = $ResultItem . "
<tr>
<td class='text-left'>
<a href='tel:" . $ExtNode -> item(0) -> childNodes -> item(0) -> nodeValue . "'>" . $NameNode -> item(0) -> childNodes -> item(0) -> nodeValue . "</a>
</td>
<td class='text-right'>
<a href='tel:" . $ExtNode -> item(0) -> childNodes -> item(0) -> nodeValue . "'>" . $ExtNode -> item(0) -> childNodes -> item(0) -> nodeValue . "</a>
</td>
</tr>";
}
}
}
}
$Output = $Output . $ResultItem . "</table>";
}
// Set output to "no suggestion" if no hint was found
// or to the correct values
if ($ResultItem == "")
{
$Response = "No Results";
} else
{
$Response = $Output;
}
//output the response
echo $Response;
?>