-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkout.php
More file actions
144 lines (120 loc) · 4.55 KB
/
workout.php
File metadata and controls
144 lines (120 loc) · 4.55 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
143
144
<?php session_start(); ?>
<html>
<!-- Protects against injections using PHP -->
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css" title="css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
<title>Cerulean Connect</title>
</head>
<body>
<header>
<img src="Cascade_Badge.png" width="200" height ="150" alt="Badge of Cerulean City" class="animated infinite pulse faster delay-2s" />
<h2 class="animated heartBeat slow delay-2s">Cerulean Connect</h2>
</header>
<ul>
<li><a href="index.php">Home</a></li>
<li><a class="active" href="workoutRepository.html">Workout Repository</a></li>
<li><a href="newWorkout.html">New Workout</a></li>
</ul>
<div class="container">
<h2 align="center" class="animated lightSpeedIn slow">Workout Query</h2>
<center>
<?php // Connect to the database
$conn = pg_connect("host=localhost port=5432 dbname=CeruleanConnect user=student password=CompSci364")
or die("Could not connect");
$status = pg_connection_status($conn);
if ($status !== PGSQL_CONNECTION_OK)
{
echo pg_last_error($dbconn);
exit;
}
$id = $_REQUEST["userNum"];
$idStr = "";
$idSpec = FALSE;
if(!is_numeric($id)){ $idStr = "$1 = $1";}
else{$idStr = "users.userid = $1"; $idSpec = TRUE;}
$distance = $_REQUEST["distance"];
$distStr = "";
if(!$distance){ $distStr = "$2 = $2";}
else{
$distSym = $_REQUEST["equalitySymbolDistance"];
if($distSym === "lessThan"){$distStr = "distance <= $2";}
else{
if($distSym === "greaterThan"){$distStr = "distance >= $2";}else{$distStr = "distance = $2";}
}
}
$duration = $_REQUEST["duration"];
$duraStr = "";
if(!$duration){ $duraStr = "$3 = $3";}
else{
$duraSym = $_REQUEST["equalitySymbolTime"];
if($duraSym === "lessThan"){$duraStr = "duration <= $3";}
else{
if($duraSym === "greaterThan"){$duraStr = "duration >= $3";}else{$duraStr = "duration = $3";}
}
}
$wtype = $_REQUEST['workoutType'];
$wStr = "";
if(!$wtype){ $wStr = "$4 = $4";}
else{$wStr = "activitytype = $4";}
$sdate = $_REQUEST['startDate'];
$sdateStr = "";
if(!$sdate){$sdateStr = "$5 = $5";}else{$sdateStr = "dateperformed >= $5";}
$edate = $_REQUEST['endDate'];
$edateStr = "";
if(!$edate){$edateStr = "$6 = $6";}else{$edateStr = "dateperformed <= $6";}
$result = pg_prepare($conn, "workoutQuery", 'SELECT users.userid, lastname, firstname, activitytype, dateperformed, distance, duration, avghr, maxhr
FROM workouts join users
ON workouts.userid = users.userid
WHERE '.$idStr.' AND '.$distStr.' AND '.$duraStr.' AND '.$wStr.' AND '.$sdateStr.' AND '.$edateStr.'
ORDER BY dateperformed DESC, users.userid ASC, lastname ASC, firstname ASC;');
$result = pg_execute($conn, "workoutQuery", array($_REQUEST['userNum'], $_REQUEST['distance'], $_REQUEST['duration'], $_REQUEST['workoutType'], $_REQUEST['startDate'], $_REQUEST['endDate']));
echo "Showing results for userid:\"".$_REQUEST['userNum']."\", distance:\"".$_REQUEST['distance']."\", duration:\"".$_REQUEST['duration']."\", activity:\"".$_REQUEST['workoutType']."\", startdate:\"".$_REQUEST['startDate']."\", enddate:\"".$_REQUEST['endDate']."\"";
$counter = 0;
$row = NULL;
$fname = NULL;
$lname = NULL;
echo "<table cellpadding=\"3\" border=\"1\">";
echo "<tbody>";
echo "<tr>";
if(!$idSpec){
echo '<th>User Num</th>';
echo '<th>Last Name</th>';
echo '<th>First name</th>';
}
echo "<th>Activity</th>";
echo "<th>Date Performed</th>";
echo "<th>Distance</th>";
echo "<th>Duration</th>";
echo "<th>Average Heart Rate</th>";
echo "<th>Max Heart Rate</th>";
echo "</tr>";
$row = pg_fetch_array($result);
while($row != NULL){
echo "<tr>";
if(!$idSpec){
echo '<td>'.$row["userid"].'</td>';
echo '<td>'.$row["lastname"].'</td>';
echo '<td>'.$row["firstname"].'</td>';
}
$lname = '.$row["lastname"].';
$fname = '.$row["firstname"].';
echo '<td>'.$row["activitytype"].'</td>';
echo '<td>'.$row["dateperformed"].'</td>';
echo '<td>'.$row["distance"].'</td>';
echo '<td>'.$row["duration"].'</td>';
echo '<td>'.$row["avghr"].'</td>';
echo '<td>'.$row["maxhr"].'</td>';
echo "</tr>";
$row = pg_fetch_array($result);
}
echo "</tbody>";
echo "</table>";
pg_close($conn); // close the database connection this wont actually be here
?>
<a href="workoutRepository.html">Back to Form</a>
</container>
</center>
</body>
</html>