-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprofile.php
107 lines (83 loc) · 4.34 KB
/
profile.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
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en">
<head>
<?php
//start session
session_start();
//check session vaiable username is present and user logged in
if(isset($_SESSION['username']))
{
//include relevant files
include "header.php";
include "connection.php";
?>
<title><?php echo $_SESSION['fname']."'s "; ?>Profile</title>
</head>
<body>
<?php
$username = $_SESSION['username'];
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
echo '<h1>'.$fname.'\'s Profile</h1>';
echo '<h3>First Name:</h3><h4>'.$fname.'</h4></br>';
echo '<h3>Last Name:</h3><h4>'.$lname.'</h4></br>';
/*Find and display all the active tasks that belong to this user */
echo '<h3>Current Active Tasks</h3>';
$query = "SELECT * FROM task WHERE username = '$username' AND active = TRUE";
$result = pg_query($db,$query);
echo '<table class="table">
<tr><th>Task Name</th><th>Description</th><th>Location</th><th>Date</th><th>Start</th><th>End</th><th>Price</th><th>View Bids</th></tr>';
while($tasks = pg_fetch_array($result)){
echo '<tr><td>'.$tasks['tname'].'</td><td>'.$tasks['tdiscrip'].'</td><td>'.$tasks['location'].'</td><td>'.$tasks['sdate'].'</td><td>'.$tasks['starttime'].'</td><td>'.$tasks[endtime].'</td><td>'.$tasks['setprice'].'</td>
<td><form action="winner.php" method="POST"><input id="blank" type="hidden" name="Taskid" value="'.$tasks['tid'].'"> <input type="submit" class="btn btn-secondary btn-sm" name="viewbids" id="submit" value="View Bids"/></form></td></tr>';
}
echo '</table>';
/*Find and display all the tasks that this user has bid on*/
echo '<h3>Tasks Bid on</h3>';
echo '<table class="table">
<tr><th>Task Name</th><th>Description</th><th>Location</th><th>Date</th><th>Start</th><th>End</th><th>Ask Price</th><th>Bid Price</th></tr>';
$query = "SELECT * FROM task INNER JOIN bids on bids.tid = task.tid WHERE bids.username = '$username'";
$result = pg_query($db,$query);
while($tasks = pg_fetch_array($result)){
echo '<tr><td>'.$tasks['tname'].'</td><td>'.$tasks['tdiscrip'].'</td><td>'.$tasks['location'].'</td><td>'.$tasks['sdate'].'</td><td>'.$tasks['starttime'].'</td><td>'.$tasks[endtime].'</td><td>'.$tasks['setprice'].'</td><td>'.$tasks['price'].'</td></tr>';
}
echo '</table>';
/*Find and display all the tasks that this user has Won*/
echo '<h3>Tasks Won</h3>';
echo '<table class="table">
<tr><th>Task Name</th><th>Description</th><th>Location</th><th>Date</th><th>Start</th><th>End</th><th>Ask Price</th><th>Bid Price</th></tr>';
$query = "SELECT DISTINCT * FROM task INNER JOIN bids on bids.tid = task.tid INNER JOIN winner on winner.tid = task.tid WHERE winner.username = '$username' AND bids.username = '$username' ORDER BY sdate DESC";
$result = pg_query($db,$query);
while($tasks = pg_fetch_array($result)){
echo '<tr><td>'.$tasks['tname'].'</td><td>'.$tasks['tdiscrip'].'</td><td>'.$tasks['location'].'</td><td>'.$tasks['sdate'].'</td><td>'.$tasks['starttime'].'</td><td>'.$tasks[endtime].'</td><td>'.$tasks['setprice'].'</td><td>'.$tasks['price'].'</td></tr>';
}
echo '</table>';
/*Find and display all the past tasks that belong to this user*/
echo '<h3>Past Tasks</h3>';
echo '<table class="table">
<tr><th>Task Name</th><th>Description</th><th>Location</th><th>Date</th><th>Start</th><th>End</th><th>Price</th><th>Winner</th></tr>';
$query = "SELECT * FROM task WHERE username = '$username' AND active = FALSE";
$result = pg_query($db,$query);
while($tasks = pg_fetch_array($result)){
/*see if there is a winner for each respective past task*/
$tid = $tasks['tid'];
$qry = "SELECT username FROM winner WHERE tid = '$tid'";
$winner = pg_query($db,$qry);
echo '<tr><td>'.$tasks['tname'].'</td><td>'.$tasks['tdiscrip'].'</td><td>'.$tasks['location'].'</td><td>'.$tasks['sdate'].'</td><td>'.$tasks['starttime'].'</td><td>'.$tasks[endtime].'</td><td>'.$tasks['setprice'].'</td>';
if(pg_num_rows($winner)==0){
echo '<td>No Winner</td>';
}else{
$twinner = pg_fetch_array($winner);
echo '<td class="admin-yes">'.$twinner['username'].'</td>';
}
echo '</tr>';
}
echo '</table>';
}else{
//if user is not logged in
header ('location: login.php');
}
?>
</body>
</html>