/
PIREPS.php
526 lines (432 loc) · 15.1 KB
/
PIREPS.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
* Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
* View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* @author Nabeel Shahzad
* @copyright Copyright (c) 2008, Nabeel Shahzad
* @link http://www.phpvms.net
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
*/
class PIREPS extends CodonModule {
public $pirep;
public $pirepdata;
/**
* PIREPS::__call()
*
* @param mixed $name
* @param mixed $args
* @return
*/
public function __call($name, $args) {
if ($name == 'new') {
$this->filepirep();
}
}
/**
* PIREPS::index()
*
* @return
*/
public function index() {
$this->viewpireps();
}
/**
* PIREPS::mine()
*
* @return
*/
public function mine() {
$this->viewpireps();
}
/**
* PIREPS::viewpireps()
*
* @return
*/
public function viewpireps() {
if (!Auth::LoggedIn()) {
$this->set('message', 'You are not logged in!');
$this->render('core_error.tpl');
return;
}
if (isset($this->post->submit_pirep) && $this->post->submit_pirep) {
if (!$this->SubmitPIREP()) {
$this->FilePIREPForm();
return false;
}
}
if (isset($this->post->submit)) {
/* See if the PIREP is valid, and whether it's being edited
by the owner, not someone else */
$pirep = PIREPData::getReportDetails($this->post->pirepid);
if (!$pirep) {
$this->set('message', 'Invalid PIREP');
$this->render('core_error.tpl');
return;
}
# Make sure pilot ID's match
if ($pirep->pilotid != Auth::$pilot->pilotid) {
$this->set('message', 'This PIREP is not yours!');
$this->render('core_error.tpl');
return;
}
/* Now do the edit actions */
if ($this->post->action == 'addcomment') {
$ret = PIREPData::addComment($this->post->pirepid, Auth::$pilot->pilotid, $this->post->comment);
$this->set('message', 'Comment added!');
$this->render('core_success.tpl');
}
/* Edit the PIREP custom fields */ elseif ($this->post->action == 'editpirep') {
$ret = PIREPData::saveFields($this->post->pirepid, $_POST);
$this->set('message', 'PIREP edited!');
$this->render('core_success.tpl');
}
}
$this->title = 'My PIREPs';
// Show PIREPs filed
$this->set('userinfo', Auth::$pilot);
$this->set('pilot', Auth::$pilot);
$pirep_list = PIREPData::getAllReportsForPilot(Auth::$pilot->pilotid);
$this->set('pireps', $pirep_list);
$this->set('pirep_list', $pirep_list);
$this->render('pireps_viewall.tpl');
}
/**
* PIREPS::view()
*
* @param string $pirepid
* @return
*/
public function view($pirepid = '') {
$this->viewreport($pirepid);
}
/**
* PIREPS::viewreport()
*
* @param string $pirepid
* @return
*/
public function viewreport($pirepid = '') {
if ($pirepid == '') {
$this->set('message', 'No report ID specified!');
$this->render('core_error.tpl');
return;
}
$pirep = PIREPData::getReportDetails($pirepid);
if (!$pirep) {
$this->set('message', 'This PIREP does not exist!');
$this->render('core_error.tpl');
return;
}
$this->set('pirep', $pirep);
$this->set('fields', PIREPData::GetFieldData($pirepid));
$this->set('comments', PIREPData::GetComments($pirepid));
$this->render('pirep_viewreport.tpl');
$this->render('route_map.tpl');
}
/**
* PIREPS::addcomment()
*
* @return
*/
public function addcomment() {
if (!Auth::LoggedIn()) {
$this->set('message', 'You must be logged in to access this feature!');
$this->render('core_error.tpl');
return;
}
if (!isset($this->get->id)) {
$this->set('message', 'No PIREP specified');
$this->render('core_error.tpl');
return;
}
$pirep = PIREPData::getReportDetails($this->get->id);
if (!$pirep) {
$this->set('message', 'Invalid PIREP');
$this->render('core_error.tpl');
return;
}
# Make sure pilot ID's match
if ($pirep->pilotid != Auth::$pilot->pilotid) {
$this->set('message', 'You cannot add a comment to a PIREP that is not yours!');
$this->render('core_error.tpl');
return;
}
# Show the comment form
$this->set('pirep', $pirep);
$this->render('pireps_addcomment.tpl');
}
/**
* PIREPS::editpirep()
*
* @return
*/
public function editpirep() {
if (!Auth::LoggedIn()) {
$this->set('message', 'You must be logged in to access this feature!');
$this->render('core_error.tpl');
return;
}
if (!isset($this->get->id)) {
$this->set('message', 'No PIREP specified');
$this->render('core_error.tpl');
return;
}
$pirep = PIREPData::GetReportDetails($this->get->id);
if (!$pirep) {
$this->set('message', 'Invalid PIREP');
$this->render('core_error.tpl');
return;
}
# Make sure pilot ID's match
if ($pirep->pilotid != Auth::$pilot->pilotid) {
$this->set('message', 'You cannot add a comment to a PIREP that is not yours!');
$this->render('core_error.tpl');
return;
}
if (PIREPData::isPIREPUnderAge($pirep->pirepid, Config::Get('PIREP_CUSTOM_FIELD_EDIT')) == false) {
$this->set('message', 'You cannot edit a PIREP after the cutoff time of ' .
Config::Get('PIREP_CUSTOM_FIELD_EDIT') . ' hours');
$this->render('core_error.tpl');
return;
}
$this->set('pirep', $pirep);
$this->set('pirepfields', PIREPData::GetAllFields());
$this->render('pirep_editform.tpl');
}
/**
* PIREPS::routesmap()
*
* @return
*/
public function routesmap() {
if (!Auth::LoggedIn()) {
$this->set('message', 'You must be logged in to access this feature!');
$this->render('core_error.tpl');
return;
}
$this->title = 'My Flight Map';
$pireps = PIREPData::findPIREPS(array(
'p.pilotid' => Auth::$pilot->pilotid
));
if (!$pireps) {
$this->set('message', 'There are no PIREPs for this pilot!!');
$this->render('core_error.tpl');
return;
}
$this->set('allschedules', $pireps); #deprecated
$this->set('pirep_list', $pireps);
$this->render('flown_routes_map.tpl');
}
/**
* PIREPS::file()
*
* @return
*/
public function file() {
$this->filepirep();
}
/**
* PIREPS::filepirep()
*
* @return
*/
public function filepirep() {
if (!Auth::LoggedIn()) {
$this->set('message', 'You must be logged in to access this feature!');
$this->render('core_error.tpl');
return;
}
if (isset(CodonRewrite::$peices[2])) {
$id = CodonRewrite::$peices[2];
}
else {
$id = '';
}
$this->FilePIREPForm($id);
}
/**
* PIREPS::getdeptapts()
*
* @param mixed $code
* @return
*/
public function getdeptapts($code) {
if ($code == '') return;
$this->set('name', 'depicao');
$this->set('airport_list', SchedulesData::GetDepartureAirports($code));
$this->render('pireps_airportdropdown.tpl');
}
/**
* PIREPS::getarrapts()
*
* @param string $code
* @param string $icao
* @return
*/
public function getarrapts($code = '', $icao = '') {
if ($icao == '') return;
$this->set('name', 'arricao');
$this->set('airport_list', SchedulesData::getArrivalAiports($icao, $code));
$this->render('pireps_airportdropdown.tpl');
}
/**
* PIREPS::FilePIREPForm()
*
* @param string $bidid
* @return
*/
protected function FilePIREPForm($bidid = '') {
if (!Auth::LoggedIn()) {
$this->set('message', 'You must be logged in to access this feature!');
$this->render('core_error.tpl');
return;
}
$this->set('pilot', Auth::$pilot->firstname . ' ' . Auth::$pilot->lastname);
$this->set('pilotcode', PilotData::GetPilotCode(Auth::$pilot->code, Auth::$pilot->pilotid));
$this->set('pirepfields', PIREPData::GetAllFields());
if ($bidid != '') {
$this->set('bid', SchedulesData::GetBid($bidid)); // get the bid info
}
$airport_list = OperationsData::getAllAirports();
$this->set('allairports', $airport_list); #deprecated
$this->set('airport_list', $airport_list);
$airline_list = OperationsData::getAllAirlines(true);
$this->set('allairlines', $airline_list); #deprecated
$this->set('airline_list', $airline_list);
$aircraft_list = OperationsData::getAllAircraft(true);
/* Skip any aircraft which have aircraft that the pilot
is not rated to fly (according to RANK)
This means the aircraft rank level is higher than
what the pilot's ranklevel, so just do "continue"
and move onto the next route in the list
*/
if(Config::Get('RESTRICT_AIRCRAFT_RANKS') === true) {
foreach($aircraft_list as $index => $aircraft) {
if($aircraft->ranklevel > Auth::$pilot->ranklevel) {
unset($aircraft_list[$index]);
continue;
}
}
}
$this->set('allaircraft', $aircraft_list); #deprecated
$this->set('aircraft_list', $aircraft_list);
$this->render('pirep_new.tpl');
}
/**
* PIREPS::SubmitPIREP()
*
* @return
*/
protected function SubmitPIREP() {
$pilotid = Auth::$pilot->pilotid;
if ($pilotid == '' || Auth::LoggedIn() == false) {
$this->set('message', 'You must be logged in to access this feature!!');
//$this->render('core_error.tpl');
return false;
}
if ($this->post->code == '' || $this->post->flightnum == '' || $this->post-> depicao == ''
|| $this->post->arricao == '' || $this->post->aircraft == '' || $this->post->flighttime == '')
{
$this->set('message', 'You must fill out all of the required fields!');
return false;
}
# Only allow for valid routes to be filed
$sched_data = SchedulesData::getScheduleByFlight($this->post->code, $this->post->flightnum);
if (!$sched_data) {
$this->set('message',
'The flight code and number you entered is not a valid route!');
return false;
}
# See if they entered more than 59 in the minutes part of the flight time
$this->post->flighttime = str_replace(':', '.', $this->post->flighttime);
$parts = explode('.', $this->post->flighttime);
if ($parts[1] > 59) {
$this->set('message', 'You entered more than 60 minutes in the minutes');
return false;
}
/* Check the schedule and see if it's been bidded on */
if (Config::Get('DISABLE_SCHED_ON_BID') == true) {
$biddata = SchedulesData::getBid($sched_data->bidid);
if ($biddata) {
if ($biddata->pilotid != $pilotid) {
$this->set('message', 'You are not the bidding pilot');
//$this->render('core_error.tpl');
return false;
}
}
}
/* Removed this check since maybe it's a training flight or something, who knows
if($this->post->depicao == $this->post->arricao)
{
$this->set('message', 'The departure airport is the same as the arrival airport!');
$this->render('core_error.tpl');
return false;
}*/
$this->post->flighttime = str_replace(':', '.', $this->post->flighttime);
if (!is_numeric($this->post->flighttime)) {
$this->set('message', 'The flight time has to be a number!');
return false;
}
# form the fields to submit
$this->pirepdata = array(
'pilotid' => $pilotid,
'code' => $this->post->code,
'flightnum' => $this->post->flightnum,
'depicao' => $this->post->depicao,
'arricao' => $this->post->arricao,
'aircraft' => $this->post->aircraft,
'flighttime' => $this->post->flighttime,
'route' => $this->post->route,
'submitdate' => 'NOW()',
'fuelused' => $this->post->fuelused,
'source' =>'manual',
'comment' => $this->post->comment
);
CodonEvent::Dispatch('pirep_prefile', 'PIREPS');
if (CodonEvent::hasStop('pirepfile')) {
return false;
}
if (!PIREPData::FileReport($this->pirepdata)) {
$this->set('message', 'There was an error adding your PIREP : ' . PIREPData::$lasterror);
return false;
}
$pirepid = DB::$insert_id;
PIREPData::SaveFields($pirepid, $_POST);
# Remove the bid
$bidid = SchedulesData::GetBidWithRoute($pilotid, $this->post->code, $this->
post->flightnum);
if ($bidid) {
SchedulesData::RemoveBid($bidid->bidid);
}
# Call the event
CodonEvent::Dispatch('pirep_filed', 'PIREPS');
# Set them as non-retired
PilotData::setPilotRetired($pilotid, 0);
# Delete the bid, if the value for it is set
if ($this->post->bid != '') {
SchedulesData::RemoveBid($this->post->bid);
}
return true;
}
/**
* PIREPS::RecentFrontPage()
*
* @param integer $count
* @return
*/
public function RecentFrontPage($count = 10) {
$pirep_list = PIREPData::getRecentReportsByCount($count);
$this->set('reports', $pirep_list); #deprecated
$this->set('pirep_list', $pirep_list);
$this->render('frontpage_reports.tpl');
}
}