-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowCustomers.php
More file actions
142 lines (128 loc) · 4.06 KB
/
Copy pathShowCustomers.php
File metadata and controls
142 lines (128 loc) · 4.06 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
include_once 'lib/DBHelper.php';
$dbh = new DBHelper();
$userSearchIndex = array();
$userSearchMap = array();
?>
<html>
<head>
<link rel="stylesheet" href="css/roncabeanz_style.css" type="text/css" />
<link href="css/Header.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 80%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<?php
session_start();
$_SESSION['ref'] = $_SERVER['SCRIPT_NAME'];
session_write_close();
?>
<div class="container">
<?php
include 'Header.php';
?>
</div>
<?php
$isAdmin = $_SESSION['admin'];
if(!$isAdmin){ ?>
<h1> <br><br> You do not have permission to view this page!</h1> <?php
}
else{
?>
<div class="row"></div>
<div>
<div class="ui-widget">
<label for="searchUser" style="font-size: 2vh">Search for User: <br></label>
<br>
<input id="searchUser", placeholder="Enter Name, email, or phone number", style="height: 50px; width: 400px">
</div>
<br>
</div>
<h1>The Beanz Customers</h1>
<?php
//Step2
$query = "SELECT * FROM `User` WHERE groupID = 'Customer' ORDER BY lastname, firstName";
//Step3
$result = $dbh->query($query);
$num_fields = mysqli_num_fields($result);
$fields = mysqli_fetch_fields($result);
//$row = mysqli_fetch_array($result);
?>
<table>
<tr>
<?php for ($i = 0; $i < $num_fields-1; $i++){ ?>
<th><?php echo $fields[$i]->name;?></th>
<?php } ?>
</tr>
<?php while ($row = mysqli_fetch_array($result)) {?>
<tr>
<?php
$curUser = User::fromRow($row);
$curName = $curUser->fname." ".$curUser->lname;
array_push($userSearchIndex, $curName);
$userSearchMap[$curName] = $curUser->email;
array_push($userSearchIndex, $curUser->homePhone);
$userSearchMap[$curUser->homePhone] = $curUser->email;
array_push($userSearchIndex, $curUser->cellPhone);
$userSearchMap[$curUser->cellPhone] = $curUser->email;
array_push($userSearchIndex, $curUser->email);
$userSearchMap[$curUser->email] = $curUser->email;
?>
<td><?php echo $curUser->lname ?></td>
<td><?php echo $curUser->fname ?></td>
<?php $uemail = $curUser->email; ?>
<td><a href="ShowCustomer.php?uid=<?php echo urlencode($uemail); ?>"><?php echo $uemail ?></a></td>
<td>********</td>
<td><?php echo $curUser->address;?></td>
<td><?php echo $curUser->apt;?></td>
<td><?php echo $curUser->city;?></td>
<td><?php echo $curUser->state;?></td>
<td><?php echo $curUser->zipCode;?></td>
<td><?php echo $curUser->homePhone;?></td>
<td><?php echo $curUser-> cellPhone;?></td>
</tr>
<?php } ?>
</table>
<?php
//Step 4
$dbh->close();
?>
<script>
$( function() {
var availableTags = <?php echo json_encode($userSearchIndex);?>;
$( "#searchUser" ).autocomplete({
source: availableTags
});
} );
</script>
<script>
var input = document.getElementById("searchUser");
input.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
var name = document.getElementById("searchUser").value;
var uids = <?php echo json_encode($userSearchMap); ?>;
var uid = uids[name];
window.location.href = "ShowCustomer.php?uid=" + uid;
}
});
</script>
<?php } ?>
</body>
</html>