common.php
1.38 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
<?php
if (!Auth::check() || !Auth::user()->admin) {
util::redirect(Route::link('index'));
}
define('EVENTDATE', '2014-07-05');
$GLOBALS['flight_columns'] = array("acid", "type", "adep", "ades", "std", "sta", "route", "info");
function read_flights($fname) {
global $flight_columns;
$fh = fopen($fname, 'r');
$flights = array();
while ($data = fgetcsv($fh)) {
while (count($data) != count($flight_columns)) {
$data[] = ''; // Pad the array - something bad has happened :(
}
$flight = array_combine($flight_columns, $data);
$flight["std"] = strtotime(EVENTDATE . ' ' . $flight["std"]);
$flight["sta"] = strtotime(EVENTDATE . ' ' . $flight["sta"]);
$flights[] = $flight;
}
fclose($fh);
return $flights;
}
function check_flight($flight) {
global $flight_columns;
$result = '';
foreach ($flight_columns as $column) {
if (!isset($flight[$column])) {
$result .= "'$column' column is missing. ";
}
if (!$flight[$column] && $column != "info") {
$result .= "'$column' is empty. ";
}
}
if ($flight["adep"] == $flight["ades"]) {
$result .= "ADEP and ADES are the same. ";
}
if ($flight["adep"] != "YSSY" && $flight["ades"] != "YSSY") {
$result .= "Neither ADEP or ADES are YSSY. ";
}
if ($flight["sta"] < $flight["std"]) {
$result .= "STA is earlier than STD ('save' module will add 24 hours). ";
}
return $result;
}