-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnection.php
More file actions
207 lines (181 loc) · 8.96 KB
/
connection.php
File metadata and controls
207 lines (181 loc) · 8.96 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
session_start();
if (empty($_SESSION["shoppingCart"])){
$_SESSION["shoppingCart"] = array();
}
if(empty($_SESSION["totalPrice"])){
$_SESSION["totalPrice"] = 0;
}
// if addEpisode == true
// add it array_push($_SESSION["shoppingCart"], $_POST["episodeId"])
?>
<!DOCTYPE html>
<html>
<head>
<title>Cartoons</title>
<!--Style (External) Sheet Reference-->
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300|Raleway" rel="stylesheet">
<link rel = "stylesheet" type = "text/css" href = "style.css" />
<script type="text/javascript" src="jquery-3.2.0.js"></script>
<script type="text/javascript">
var isShown = false;
$(document).ready(function(){
$('.togglebutton').click(function() {
$("#"+ $(this).data('id')).toggle();
});
});
</script>
</head>
<body>
<div class="wrapper">
<?php
include "header.php";
$tab = '       ';
// ******************* ESTABLISH CONNE*********************************
function getConnected() {
$servername = getenv('IP');
$dbPort = 3306;
$database = "cartoonCatalog";
$username = getenv('C9_USER');
$password = "";
$dbConn = new PDO("mysql:host=$servername;port=$dbPort;dbname=$database", $username, $password);
$dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbConn;
}
// ******************* SQL DISPLAY TABLE FUNCTION **********************
function printTable($dbConn, $sql) {
$count = 0;
$index = 0;
$stmt = $dbConn->prepare($sql);
$stmt->execute();
echo "<form method='POST' action='reviewOrder.php'>";
echo '<table>';
echo '<tr style="background:#982F74;">';
echo '<th><b>Episode Name</th>';
echo '<th><b>Show Title</th>';
echo '<th><b>Price</th>';
echo '<th><b>Add to Cart</th>';
echo '</tr>';
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$count += 1;
echo '<tr>';
// echo '<td>';
// $row["episodeName"]
echo '<td>';
echo "<span class='togglebutton' id='fakeLink' data-id=" . $index . ">" . $row['episodeName'] . "</span>";
echo "<div id=" . $index ." style='display:none'>";
echo "<br>Creator: " . $row["creator"] . "<br>"
."Length: " . $row["length"] . " mins<br>"
."Air Date: " . $row["airDate"] . "<br>"
."Season: " . $row["seasonNum"] . "<br>";
$characters = getChar($row["showTitle"]);
echo "<br><u>Character List:</u>\n";
echo "<ul>";
foreach ($characters as $character) {
echo "<li>".$character["characterName"];
if($character["age"]!="N/A")
echo "(".$character["age"]." yrs old)</li>";
else
echo "(".$character["age"].")</li>";
}
echo "</ul>";
++$index;
echo "</div>";
echo '</td>';
// echo '</td>';
echo '<td>'.$row["showTitle"].'</td>';
echo '<td>'.$row["price"].'</td>';
echo '<td><input type="checkbox" name="add['.$count.']" value="'.$row["episodeName"].'"></td>';
echo '</tr>';
}
echo '</table>';
echo '<input type="submit" value="Place Order">';
echo '</form>';
echo '<br>';
}
// ******************* Display Filtered Tables (Episodes) **********************
function displayEpisodeInfo($sort) {
$dbConn = getConnected();
if ($sort== "desc")
$sort = "DESC";
else
$sort = "ASC";
if ($_POST["filter"] == "show") {
$sql = 'SELECT e.*, s.creator
FROM Episode as e
JOIN `Show` as s
ON e.showTitle = s.showTitle
ORDER BY e.showTitle '.$sort;
$labels = array('Show Title', 'Episode Name', 'Price');
} else if ($_POST["filter"] == "price") {
$sql = 'SELECT e.*, s.creator
FROM Episode as e
JOIN `Show` as s
ON e.showTitle = s.showTitle
ORDER BY e.price '.$sort;
$labels = array('Price', 'Episode Name', 'Show Title');
} else {
// Default Values
$sql = 'SELECT e.*, s.creator
FROM Episode as e
JOIN `Show` as s
ON e.showTitle = s.showTitle
ORDER BY e.episodeName '.$sort;
$labels = array('Episode Name', 'Show Title', 'Price');
}
printTable($dbConn, $sql);
}
function getChar($show) {
$dbConn = getConnected();
$sql = "SELECT c.characterName, c.age
FROM `Character` as c
WHERE c.showTitle = '$show'";
$stmt = $dbConn->prepare($sql);
$stmt->execute();
$charArray = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
array_push($charArray, $row);
}
return $charArray;
}
?>
<center>
<div>
<form action="connection.php" method="POST">
<!--Filter-->
<label>Filter Episode By: </label>
<input type="radio" name="filter" value="name"/>
<label>Episode Name</label>
<input type="radio" name="filter" value="show" />
<label>Show</label>
<input type="radio" name="filter" value="price" />
<label>Price</label>
<?php
echo $tab;
?>
<!--Sorting-->
<label>Sort By: </label>
<input type="radio" name="sort" value="asc"/>
<label>Ascending</label>
<input type="radio" name="sort" value="desc" />
<label>Descending</label>
<?php
echo $tab;
?>
<input type="submit" value="Submit" />
</form>
</div>
</center>
<br>
<?php
$sort = $_POST["sort"];
echo "<center>";
displayEpisodeInfo($sort);
echo "</center>";
?>
<!--<form method="POST" action="reviewOrder.php">-->
<!--<input type="submit" value="Place Order">-->
<!--</form>-->
</div>
</body>
</html>