-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_calendar.php
233 lines (177 loc) · 8.08 KB
/
load_calendar.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<? /* Copyright (C) 1995-2020 John Murtari
This file is part of FLY flight management software
FLY is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FLY is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLY. If not, see <https://www.gnu.org/licenses/>. */ ?>
<?
require("./php_includes.inc");
require("./lib/header.inc");
$action = script_param('action');
$delete = script_param('delete');
$dtype = script_param('dtype');
$calendar = script_param('calendar');
$calendarID = '';
if (!$action) {
$action = 'new'; // first time thru
}
//require("debug.inc");
?>
<div id="divContent">
<?php
if (!hasPerms('admin')) { # we do stuff
DisplayMessage( "Update member info", "NO PERMISSIONS FOR THIS", 0);
}
if ($action == 'update') {
if ($dtype == 'SPECIAL') {
$etype = 'SPECIAL';
} else if (preg_match("/OPS|TOW|CFIG/", $dtype)) {
$etype = 'FLYING';
} else {
DB_Log('ERROR', "Bad event type on calendar update. Got $dtype");
DisplayMessage("System busy", "can't update");
}
// they gave us info, check the data first to make sure it looks good
$lines = explode("\n", str_replace("\r", "", $calendar));
$count = 0;
// start a transaction, we have to make to make updates to a couple of
// tables, it's either all or none
if ($msg = DB_Transaction($Conn, 'START')) {
DisplayMessage("Do a calendar load", $msg);
}
foreach ($lines as $line) {
if (!$line) { // we can take a blank
continue;
}
if ($etype == 'FLYING') {
list($date, $lastName) = explode(',', $line);
$title = 'Flying';
$lastName = trim($lastName);
if (!$date && !$lastName) { // got nothing, skip it
continue;
}
if ($date && !$lastName) { // BAD
echo "<br>SORRY, Bad format in this line, need two values separated by a comma:<br> $line</br>";
$count = 0;
break;
}
// check the name
if ($msg = getMemberID($lastName, '', $memberID)) {
echo "<br>SORRY, Could not find member($msg): $lastName, must match last name as displayed on active members page.</br>";
$count = 0;
break;
}
} else { // SPECIAL
list($date, $title, $notes) = explode(':', $line);
if (!$date && (!$title || !$notes)) { // got nothing, skip it
continue;
}
} // end if -else, type of input data.
// check the date and name, we demand mm/dd/yy
if (!preg_match("/^(0[1-9]|1[0-2]|[1-9])\/(0[1-9]|[1-2][0-9]|3[0-1]|[0-9])\/([0-9]{2})$/",$date)) {
echo "<br>SORRY, Bad date used, should by ONLY mm/dd/yy, got: $date</br>";
$count = 0;
break;
}
// convert the date to mysql, mm/dd/yy --> yyyy-mm-dd
list($month,$day,$year) = explode('/', $date);
$year += 2000;
$mdate = "$year-$month-$day";
// Do we need to do an insert into Calendar.
// first check to see if the date has something that matches
if ($etype == 'FLYING') {
$sql = "SELECT CalendarID FROM Calendar WHERE etype='$etype' AND date='$mdate'";
} else { // SPECIAL
$sql = "SELECT CalendarID FROM Calendar WHERE etype='$etype' AND date='$mdate' AND title='$title'";
}
if ($msg = DB_Query($Conn, $sql, $results)) {
DisplayMessage("Check calendar", "query failed ($msg)", 1);
}
unset($searchInfo);
unset($insertInfo);
unset($calendarID);
// For FLYING events a duplicate cal is not a problem,we just check duty
// FOR SPECIAL events we skip a duplicate on date and title
if (count($results)) { // we have something to add to
$calendarID = $results[0]['CalendarID'];
$searchInfo['CalendarID'] = $calendarID;
echo "<br>Found existing $etype calendar event for $mdate</br>";
if ($etype == 'SPECIAL') {
echo "<br>Found event with same title ($title) for $mdate, skipping.</br>";
continue;
}
// if the person is already there as duty, just skip
$searchInfo['type'] = $dtype;
$searchInfo['memberID'] = $memberID;
if ($msg = DB_Get($Conn, 'Duty', $searchInfo, $results)) {
DisplayMessage("Check existing duty", "query failed ($msg)", 1);
}
if (count($results)) { // we got something
echo "<br>Found member $lastName already has duty for $mdate, skipping.</br>";
continue;
}
} else { // first time on this date
echo "<br>First entry $etype calendar event ($title) for $mdate</br>";
$insertInfo['CalendarID'] = '';
$insertInfo['date'] = $mdate;
$insertInfo['etype'] = $etype;
if ($etype == "FLYING") {
$insertInfo['notes'] = '';
} else {
$insertInfo['title'] = $title;
$insertInfo['notes'] = $notes;
}
if ($msg = DB_Insert($Conn, 'Calendar', $insertInfo, $calendarID)) {
DisplayMessage("Insert calendar entries",
$msg, 1);
}
unset($insertInfo['date']);
unset($insertInfo['etype']);
} // end if-else, calendar item exists
// DB_Log('INFO', "Got $dtype for $mdate for $memberID and calendarID of $calendarID");
// insert duty members if FLYING
if ($etype == "FLYING") {
$insertInfo['type'] = $dtype;
$insertInfo['CalendarID'] = $calendarID;
$insertInfo['MemberID'] = $memberID;
if ($msg = DB_Insert($Conn, 'Duty', $insertInfo)) {
DisplayMessage("Insert duty entries",
$msg, 1);
}
echo "<br>Added member $lastName for $dtype duty on $mdate.</br>";
}
$count++; // got something done
} // end for - all input lines
if (!$count) { // didn't get anything good
echo "<p><b>NO UPDATES/CHANGES MADE TO EXISTING DATA</b></p>";
if ($msg = DB_Transaction($Conn, 'ROLLBACK')) {
DisplayMessage("Do a calendar load", $msg);
}
} else { // we did it
// do the COMMIT
if ($msg = DB_Transaction($Conn, 'COMMIT')) {
DisplayMessage("Do a calendar load", $msg);
}
echo "<p><b>Your info ($count updates) has been loaded successfully!</b></p>";
if ($etype == 'FLYING') {
echo "<p>Click <a href='flying_sched.php'>here for updated schedule.</a></p>";
} else {
echo "<p>Click <a href='event_sched.php'>here for updated schedule.</a></p>";
}
require 'footer.inc';
exit;
} // end if-else success
} // end if - update
require 'load_calendar_content.php';
?>
</div>
<!-- ------------------ Content ends here ---------------------------------- -->
<?php
require 'footer.inc';
?>