-
Notifications
You must be signed in to change notification settings - Fork 0
/
try.php
55 lines (49 loc) · 1.33 KB
/
try.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
<?php
require_once('connect.php');
$input = getInput();
//Enter staff id
if ( $input['text'] == "" ) {
// This is the first request. Note how we start the response with CON
$response = "Please enter Staff ID";
sendOutput($response,1);
}else {
//receive what Edwin has sent in as text
$id = $input['text'];
}
$staff = getStaff($id);
if($staff['id'] != 0){
$message= "ID is valid and it belongs to ".$staff['first_name']." ".$staff['last_name'];
}else{
$message = "No Staff with that id";
}
sendOutput($message,2);
//verify if the id belongs to one of the staff members
function getInput()
{
$input = array();
$input['sessionId'] = $_REQUEST["sessionId"];
$input['serviceCode'] = $_REQUEST["serviceCode"];
$input['phoneNumber'] = $_REQUEST["phoneNumber"];
$input['text'] = $_REQUEST["text"];
return $input;
}
function sendOutput($message,$type=2){
//Type 1 is a continuation, type 2 output is an end
if($type==1){
echo "CON ".$message;
}elseif($type==2){
echo "END ".$message;
}else{
echo "END We faced an error";
}
exit;
}
function getStaff($id){
$query = mysql_query("SELECT * FROM staff WHERE id='$id'");
if (mysql_num_rows($query) > 0) {
$row = mysql_fetch_assoc($query);
} else {
$row['id'] = 0;
}
return $row;
}