-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarPage.php
executable file
·179 lines (168 loc) · 6.04 KB
/
starPage.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
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
<?php
session_start();
if($_SESSION['username']){
//echo "login successful";
$currentUser = $_SESSION['username'];
$logStatus = "Logout";
$_SESSION['username'] = $currentUser;
}
else{
$currentUser = "Not Logged In";
$logStatus= "Login";
}
require_once('../mysqli_connection_data.php'); //connect to db
$starQuery = "SELECT * FROM STAR ORDER BY constellation asc";
$constellationQuery = "SELECT * FROM CONSTELLATION ORDER BY constellationName ASC";
$starResults = mysqli_query($dbc, $starQuery);
$constellationResults = mysqli_query($dbc, $constellationQuery);
//Fetch all rows of result as an associative array
if($starResults) {
mysqli_fetch_all($starResults, MYSQLI_ASSOC);
} else {
echo "Server Error, We are Sorry for the incovenience"; //Change to a generic message error before deployment
mysqli_close($dbc);
exit;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="main.css" rel="stylesheet">
<title>Star Catalogue</title>
<meta name="description" content="A catalogue of stars">
<meta name="author" content="Team Data (CSC 455 Fall 2018)">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
</head>
<body>
<h1>Star Catalogue Team Data</h1>
<h2>
<?php echo $currentUser; ?>
<form action='' method="post">
<input type="submit" name='logout' id=logout value=<?php echo $logStatus?>>
</form>
</h2>
<?php
function logout(){
$_SESSION['username'] = null;
$currentUser = "Not Logged In";
$logStatus = "Login";
header('Location: Login.php');
}
if(array_key_exists('logout',$_POST)){
echo "logout";
logout();
}
?>
<form method= "POST" action =''>
Reset star chart: <input type = "submit" name="resetBtn" value="Reset">
</form>
<form action="constellationPage.php">
See constellations: <input type="submit" value="Go" />
</form>
<form action= "bookmarks.php" method="get">
Open bookmarks: <input type="submit" value="Go">
<br>
</form>
<form action="">
Search stars: <input type="search" name="search">
<input type="submit" value="Submit">
</form>
<br>
<form method="POST" action=''>
Show most popular Stars: <input type="submit" name="popularBtn" value="Show">
</form>
</body>
<main>
<form method="POST" action=''>
Sort by Bayer Designation: <input type="submit" name="bayerBtn" value="Show">
</form>
<form action = "select_stars.php" method="get">
<!-- Use a PHP loop to generate a select list of constellations in the DB -->
Explore the constellation you are looking for:
<select name="constellation">
<?php foreach ($constellationResults as $constellation) {
$constellationNameID = $constellation['constellationName'];
echo "<option value=\"$constellationNameID\">$constellationNameID</option>";
} ?>
</select>
<input type="submit" value="Find Stars">
</form>
<!--save bookmarks for user button -->
<form action ="bookmarks.php" method="get">
Save bookmarks selected via this button:
<input type="submit" value="Save">
<br> <!-- Output table -->
<table>
<tr>
<th>Bookmark</th>
<th>Star Proper Name</th>
<th>Bayer Designation</th>
<th>Variable Star</th>
<th>Henry Draper Catalogue</th>
<th>Hipparcos</th>
<th>Right Ascension</th>
<th>Declination</th>
<th>Apparent Magnitude</th>
<th>Absolute Magnitude</th>
<th>Cosmic Distance Ladder</th>
<th>Stellar Classification</th>
<th>Notes</th>
<th>Constellation</th>
</tr>
<!-- Output the results table one row at a time -->
<?php
//searching
if (array_key_exists("search", $_GET)) {
$query = "SELECT * FROM STAR WHERE starProperName LIKE " . "'%" . $_GET["search"] . "%'";
//echo $query;
$newStarResults = mysqli_query($dbc, $query);
global $starResults;
$starResults = $newStarResults;
$numResults = $starResults->num_rows;
echo "<br>Found " . $numResults . " results.";
}
if(isset($_POST['popularBtn'])){
$query = "SELECT STAR.starProperName, STAR.bayerDesignation,STAR.variableStar,
STAR.henryDraperCatalogue, STAR.hipparcos, STAR.rightAscension, STAR.declination,
STAR.apparentMagnitude, STAR.absoluteMagnitude, STAR.cosmicDistanceLadder,
STAR.stellarClassification, STAR.notes, BOOKMARK.constellation
FROM BOOKMARK, STAR
WHERE BOOKMARK.star = STAR.starProperName
ORDER BY BOOKMARK.constellation ASC";
$newStarResults = mysqli_query($dbc, $query);
global $starResults;
$starResults = $newStarResults;
//$numResults = $starResults->num_rows;
}
else if(isset($_POST['bayerBtn'])){
$bayerQuery = "SELECT * FROM STAR WHERE STAR.bayerDesignation <> ''";
$starResults = mysqli_query($dbc, $bayerQuery);
}
else if(isset($_POST['resetBtn'])){
$starResults = mysqli_query($dbc, $starQuery);
}
foreach ($starResults as $one_star) { ?>
<tr>
<!-- Each row is an array. -->
<!-- Each item in a row is referenced using the db attribute as the index -->
<td><input type='checkbox' name='newBookmarks[]' value= "<?php echo $one_star['starProperName'] ?>" ></td>
<td><?php echo $one_star['starProperName']; ?></td>
<td><?php echo $one_star['bayerDesignation']; ?></td>
<td><?php echo $one_star['variableStar']; ?></td>
<td><?php echo $one_star['henryDraperCatalogue']; ?></td>
<td><?php echo $one_star['hipparcos']; ?></td>
<td><?php echo $one_star['rightAscension']; ?></td>
<td><?php echo $one_star['declination']; ?></td>
<td><?php echo $one_star['apparentMagnitude']; ?></td>
<td><?php echo $one_star['absoluteMagnitude']; ?></td>
<td><?php echo $one_star['cosmicDistanceLadder']; ?></td>
<td><?php echo $one_star['stellarClassification']; ?></td>
<td><?php echo $one_star['notes']; ?></td>
<td><?php echo $one_star['constellation']; ?></td>
</tr>
<?php }?>
</table>
<br>
</form>
</main>