-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddpilots.php
182 lines (153 loc) · 5.87 KB
/
addpilots.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
180
181
182
<h1>Edit Pilots</h1>
<?php
include("SoaringLogBase.php");
// name of this file - used in links
$thisFile = "index.php?addpilots";
session_start();
$loggedIn = False;
if ( isset( $_SESSION['loggedin'] ) ) {
$loggedIn = True;
print("<h2><a href=\"auth.php?logout=1&origin=addpilots\">Logout</a></h2>");
}
else {
print("<h2><a href=\"auth.php?origin=addpilots\">Login</a></h2>");
}
// Initialize variable we'll be using from the database
$logbase = SoaringLogBase::GetInstance();
$database = $logbase->dbObj;
$tableName = $logbase->GetPilotTable();
$memberList = $logbase->GetMembers(true);
// using the _REQUEST array allows input via HTTP POST or URL tags
$inactive = isset($_REQUEST["inactive"]) ? $_REQUEST["inactive"] : null;
$lastBiannual = strtotime(isset($_REQUEST["lastBiannual"]) ? $_REQUEST["lastBiannual"] : null);
$pilotID = isset($_REQUEST["pilotID"]) ? $_REQUEST["pilotID"] : null;
$pilotName = isset($_REQUEST["pilotName"]) ? $_REQUEST["pilotName"] : null;
$modified = isset($_REQUEST["modified"]) ? $_REQUEST["modified"] : null;
if($loggedIn) {
// update an existing record
if($pilotID && !$modified) {
$query = "UPDATE $tableName SET ";
if($pilotName)
$query .= "Name='$pilotName',";
if($lastBiannual)
$query .= "LastBiAnnual='$lastBiannual',";
if($inactive)
$query .= "Inactive='$inactive',";
else
$query .= "Inactive=0";
// trim any trailing commas off the string
$query = rtrim($query, ",");
$query .= " WHERE ID='$pilotID';";
if(!$result = $database->query($query)) {
print("uh oh.... failed to update record :(");
print $query;
}
// refresh the member list
$memberList = $logbase->GetMembers(true);
}
else if($pilotName) {
// Add a new pilot to the database
$query = "INSERT INTO $tableName (ID, Name, LastBiAnnual, Inactive) VALUES (NULL, '$pilotName', NULL, 0);";
if(!$result = $database->query($query))
print("uh oh.... query failed :( $result");
// refresh the member list
$memberList = $logbase->GetMembers(true);
}
}
// print out the list of existing pilots
$query = "SELECT * FROM $tableName ORDER BY Inactive, ID";
if($result = $database->query($query)) {
echo("<table id=\"flightLogTable\" >");
echo("<tr class=\"Head\"><td>Member Name</td><td>Last Flew</td><td>Last Bi-annual</td><td>Inactive</td><td></td></tr>\n");
// skip the first row (it should be null)
$row = $result->fetch(PDO::FETCH_BOTH);
while($row = $result->fetch(PDO::FETCH_BOTH)) {
$editMe = 0;
// do we need to modify this row?
if($pilotID == $row['ID'] && $modified) {
$editMe = 1;
}
if($editMe) {
echo("<tr id=\"row{$row['flightIndex']}\" class=\"IncompleteEntry\"><form id=\"form{$row['flightIndex']}\" name=\"loggingUpdate\" action=\"{$thisFile}\" method=\"POST\"> ");
$entryComplete = false;
}
else {
if ($row['Inactive']) {
echo("<tr class=\"InactivePilot\">");
}
else {
echo("<tr class=\"CompleteEntry\">");
}
$entryComplete = true;
}
// Pilot
if($editMe) {
echo("<td>");
echo("<input type=\"text\" name=\"pilotName\" value=\"{$memberList[$row['ID']]}\" id=\"pilotName{$row['ID']}\"/>");
echo "</td>";
}
else
echo("<td>{$memberList[$row['ID']]}</td>");
// Last flew
$lastFlew = $logbase->GetLastFlew($row['ID']);
if($lastFlew > 1)
echo("<td>" . date("M j, Y", $lastFlew) . "</td>");
else
echo("<td>-------</td>");
// Last bi-annual
if ($row['LastBiAnnual'] > 0) {
$storedLastBiannual = date("M j, Y", $row['LastBiAnnual']);
}
else {
$storedLastBiannual = "-------";
}
if($editMe) {
echo("<td>");
echo("<input type=\"text\" name=\"lastBiannual\" value=\"$storedLastBiannual\" id=\"lastBiannual{$row['ID']}\"/>");
echo "</td>";
}
else
echo("<td>$storedLastBiannual</td>");
// Inactive status
$isInactive = $row['Inactive'];
if($editMe) {
if($isInactive)
echo("<td><input type=\"checkbox\" checked=\"yes\" name=\"inactive\" value=\"inactive\"></td>");
else
echo("<td><input type=\"checkbox\" name=\"inactive\" value=\"inactive\"></td>");
}
else {
if($isInactive)
echo("<td class=\"Inactive\">Inactive</td>");
else
echo("<td>Active</td>");
}
// Submit button and hidden field containing the unique flight index
if($editMe) {
echo "<td><input type=\"hidden\" name=\"pilotID\" value=\"{$row['ID']}\"/><input type=\"submit\" value=\"Update...\" /></form>";
}
else {
if($loggedIn) {
echo "<td><center><button name=\"modify\" class=\"modify\" onClick=\"window.location.href='{$thisFile}&pilotID={$row['ID']}&modified=1'; \" />";
echo "</center></td></tr>\n";
}
else {
echo "<td></td></tr>\n";
}
}
}
if($loggedIn) {
// Row for new entries...
echo "<tr><form name=\"pilotList\" action=\"{$thisFile}\" method=\"POST\">\n";
echo "<td><input type=\"text\" name=\"pilotName\" /></td>\n";
echo "<td>N/A</td>\n";
echo "<td><input type=\"text\" name=\"lastBiannual\" /></td>\n";
echo "<td>N/A</td>";
echo "<td><input type=\"submit\" value=\"Add new...\" /></td>";
echo "</form></tr>";
}
echo("</table><br><br><br>");
}
else
print("Failed to execute query!!!");
?>