-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
110 lines (97 loc) · 2.78 KB
/
functions.php
File metadata and controls
110 lines (97 loc) · 2.78 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
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
<?php
$assignedUHF = array(); // array that stores all already assigned frequencies, both for stations+ils and radiomap.
function execute($mode1, $mode2) // master function that defines which work functions get called based on what the User wants to do.
{
if($mode1)
{
radiomap($_FILES["radiomap"]["tmp_name"]);
$ret = stationsils($_FILES["stationsils"]["tmp_name"], $mode2);
}
else
{
$ret = stationsils($_FILES["stationsils"]["tmp_name"], $mode2);
}
echo "<textarea rows='35' readonly>".$ret."</textarea>";
}
function radiomap($file)
{
global $assignedUHF;
$lines = explode("\n", file_get_contents($file));
foreach($lines as $line)
{
if(substr($line, 0, 2) != "//" && $line != "\r" && !empty($line))
{
$el = explode(", ", $line);
if(is_numeric($el[1]))
array_push($assignedUHF, $el[1]);
}
}
}
function stationsils($file, $mode)
{
// min 225.00 - max 399.95 / GUARD 243.00
$lines = explode("\n", file_get_contents($file));
$output = "";
$to_assign = array(6, 12, 13, 14); // randomly assign 6, 12, 13, 14; TwrU/OpsU/GndU/AppU
global $assignedUHF;
if($mode) // if the user wants to keep already assigned ATC frequencies.
{
foreach($lines as $line)
{
$el = explode(" ", $line);
if(substr($line, 0, 1) != "#" && $line != "\r" && !empty($line))
{
foreach($to_assign as $n)
{
if($el[$n] != 0)
array_push($assignedUHF, $el[$n]);
}
}
}
}
foreach($lines as $line)
{
$el = explode(" ", $line);
if(substr($line, 0, 1) != "#" && $line != "\r" && !empty($line)) // Exclude line conditions
{
if($mode) // if the user wants to keep already assigned ATC frequencies.
{
foreach($to_assign as $n)
{
if($el[$n] == 0) // only generate frequencies for unassigned slots
{
do {
$el[$n] = rand(225000, 399750);
} while($el[$n] % 25 != 0 || in_array($el[$n], $assignedUHF) || $el[$n] == 243000); // repeat if not a 25kHz step, frequency already used or is GUARD
array_push($assignedUHF, $el[$n]);
}
}
}
else // if the user doesn't care about keeping already assigned ATC frequencies.
{
foreach($to_assign as $n)
{
do {
$el[$n] = rand(225000, 399750);
} while($el[$n] % 25 != 0 || in_array($el[$n], $assignedUHF) || $el[$n] == 243000); // repeat if not a 25kHz step, frequency already used or is GUARD
array_push($assignedUHF, $el[$n]);
}
}
$tmpOut = "";
foreach($el as $e) // Combine modified line elements to a single line for output
{
if(empty($tmpOut))
$tmpOut = $e;
else
$tmpOut = $tmpOut." ".$e;
}
$output = $output.$tmpOut;
}
else // if the line is excluded
{
$output = $output.$line."\n";
}
}
return $output;
}
?>