-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_func.php
142 lines (112 loc) · 3.67 KB
/
account_func.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
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
//A php file to access and display relevent account information
//Server information
session_start();
//Include the file which establishes and checks database conection
include_once 'db_connection.php';
//Check that the user is logged in, if not disconnect
if($_SESSION["loggedIn"] == 0)
{
echo "You are not logged in";
$conn->close();
}//if
?>
<?php
//Set up an SQL query to select user information, check if the account
//can be found and display the correct user information if so
$accountFound = false;
$sql = "SELECT ID, Name, Email, Rating, Phone FROM Users";
$userResult = $conn->query($sql);
$sessionId = $_SESSION["id"];
while($userRow = $userResult->fetch_assoc())
{
if($userRow["ID"] == $sessionId)
{
echo "Your account information: <br><br>";
echo "Name: " . $userRow["Name"] . "<br>";
echo "Email: " . $userRow["Email"] . "<br>";
if($userRow["Rating"] == null)
echo "Rating: You haven't got a rating yet <br>";
else
echo "Rating: " . $userRow["Rating"] . "<br>";
if($userRow["Phone"] == null)
echo "Phone: Implement a way to input phone <br><br>";
else
echo "Phone: " . $userRow["Phone"] . "<br><br>";
$accountFound = true;
}//if
}//while
if(!$accountFound)
{
echo "Your account cannot be found, please contact Kaloyan";
$conn->close();
}//if
?>
<?php
//Select any relevant found items on the site and display it's information
$foundItems = 0;
$sql = "SELECT ID, FinderId, ItemName, Descript, Location, Date FROM Items";
$itemsResult = $conn->query($sql);
echo "Found items: <br><br>";
while($itemsRow = $itemsResult->fetch_assoc())
{
if($itemsRow["FinderId"] == $sessionId)
{
$isMatched = false;
$sql = "SELECT FinderID, MislayerID, ItemID FROM Matched";
$matchedResult = $conn->query($sql);
while($matchedRow = $matchedResult->fetch_assoc())
{
if($matchedRow["FinderID"] == $sessionId && $matchedRow["ItemID"] == $itemsRow["ID"])
{
$isMatched = true;
}//if
}//while
if(!$isMatched)
{
$foundItems++;
echo "Item: " . $foundItems . "<br>";
printItem($itemsRow["ItemName"], $itemsRow["Descript"], $itemsRow["Location"],
$itemsRow["Date"]);
}//if
}//if
}//while
if($foundItems == 0)
echo "You haven't found anything";
//Select any matched items and display them
$matchedItems = 0;
$sql = "SELECT FinderID, MislayerID, ItemID FROM Matched";
$matchedResult = $conn->query($sql);
echo "Matched items: <br><br>";
while($matchedRow = $matchedResult->fetch_assoc())
{
if($matchedRow["MislayerID"] == $sessionId || $matchedRow["FinderID"] == $sessionId)
{
$sql = "SELECT ID, FinderId, ItemName, Descript, Location, Date FROM Items";
$itemsResult = $conn->query($sql);
while($itemsRow = $itemsResult->fetch_assoc())
{
if($itemsRow["ID"] == $matchedRow["ItemID"])
{
$matchedItems++;
echo "Matched Item: " . $matchedItems . "<br>";
printItem($itemsRow["ItemName"], $itemsRow["Descript"], $itemsRow["Location"],
$itemsRow["Date"]);
}//if
}//while
}//if
}//while
if($matchedItems == 0)
{
echo "You have no matched items <br><br>";
}//if
<?php
//A function to print out an Item, for a corresponding ID
function printItem($name, $descript, $location, $date)
{
echo "Item name: " . $name . "<br>";
echo "Decription: " . $descript . "<br>";
echo "Location: " . $location . "<br>";
echo "Date and time found: " . $date . "<br><br>";
}//printItems
?>