Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
velocity23 committed Dec 16, 2024
2 parents f25723b + dcacb06 commit 80fc6d5
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 24 deletions.
156 changes: 156 additions & 0 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1494,4 +1494,160 @@ function accessDenied()
]);
});

// Migrate to VANet Portal
Router::add('/portal_migrate', function () {
global $user;
if (!$user->hasPermission('site') || !$user->hasPermission('staffmanage')) accessDenied();

$aircraft = array_map(function ($a) {
return [
"aircraftLiveryId" => $a->ifliveryid,
"minimumRankId" => $a->rankreq,
"requiredAwardId" => $a->awardreq,
"notes" => $a->notes,
];
}, Aircraft::fetchActiveAircraft()->results());

$routeAircraft = Route::fetchAllAircraftJoins();
$routes = array_map(function ($a) use (&$routeAircraft) {
return [
"id" => $a["id"],
"flightNumber" => $a["fltnum"],
"departureAirportIcao" => $a["dep"],
"arrivalAirportIcao" => $a["arr"],
"estimatedFlightTime" => $a["duration"],
"notes" => $a["notes"],
"aircraftLiveryIds" => array_map(function ($x) {
return $x->aircraftliveryid;
}, array_values(array_filter($routeAircraft, function ($x) use ($a) {
return $x->routeid == $a["id"];
}))),
];
}, Route::fetchAll());

$awardRecipients = Awards::getAllRecipients();
$awards = array_map(function ($a) use (&$awardRecipients) {
return [
"id" => $a->id,
"name" => $a->name,
"description" => $a->description,
"imageUrl" => $a->imageurl,
"userIds" => array_map(function ($x) {
return $x->pilotid;
}, array_values(array_filter($awardRecipients, function ($x) use ($a) {
return $x->awardid == $a->id;
})))
];
}, Awards::getAll());

$allaircraft = Aircraft::fetchAllAircraft();
$allcomments = Pirep::getAllComments();
$flights = array_map(function ($f) use ($allaircraft, $allcomments) {
$aircraftData = array_values(array_filter($allaircraft, function ($x) use ($f) {
return $x->id == $f["aircraftid"];
}));
return [
"departureIcao" => $f["departure"],
"arrivalIcao" => $f["arrival"],
"flightNumber" => $f["flightnum"],
"date" => $f["date"],
"fuelUsed" => $f["fuelused"],
"flightTime" => $f["flighttime"],
"aircraftLiveryId" => $aircraftData[0]->ifliveryid,
"multiplierCode" => null,
"status" => $f["status"],
"pilotId" => $f["pilotid"],
"comments" => array_map(function ($y) {
return [
"userId" => $y->userid,
"content" => $y->content,
"dateTime" => date_format(date_create($y->dateposted), "c"),
];
}, array_values(array_filter($allcomments, function ($y) use ($f) {
return $y->pirepid == $f["id"];
})))
];
}, Pirep::fetchAll());

$multipliers = array_map(function ($m) {
return [
"code" => strval($m->code),
"multiplicationFactor" => $m->multiplier,
"name" => $m->name,
"expiresAt" => null,
];
}, Pirep::fetchMultipliers());

$ranks = array_map(function ($r) {
return [
"id" => $r->id,
"name" => $r->name,
"minFlightTime" => $r->timereq,
];
}, Rank::fetchAllNames()->results());

$leaves = [];
if (class_exists('ActivityPlugin')) {
$leaves = array_map(function ($l) {
return [
"startDate" => $l->fromdate,
"endDate" => $l->todate,
"reason" => $l->reason,
"userId" => $l->pilot,
];
}, ActivityPlugin::currentFutureLeave());
}

$allpermissions = Permissions::getAllEntries();
$members = array_map(function ($u) use ($allpermissions) {
return [
"id" => $u->id,
"email" => $u->email,
"callsign" => $u->callsign,
"userId" => $u->ifuserid,
"transferHours" => $u->transhours,
"transferFlights" => $u->transflights,
"permissions" => array_map(function ($p) {
return $p->name;
}, array_values(array_filter($allpermissions, function ($p) use ($u) {
return $p->userid == $u->id;
}))),
];
}, User::getActiveUsers());

$data = Json::encode([
"aircraft" => $aircraft,
"routes" => $routes,
"awards" => $awards,
"flights" => $flights,
"multipliers" => $multipliers,
"ranks" => $ranks,
"leaveOfAbsences" => $leaves,
"members" => $members,
]);
$gzdata = gzencode($data, 9);

$myinfo = VANet::myInfo();
$response = HttpRequest::hacky(VANet::baseUrl() . "/airline/v2/" . urlencode($myinfo["id"]) . "/flare-import", "POST", $gzdata, [
"X-Api-Key: " . Config::get('vanet/api_key'),
"Content-Type: application/json",
"Content-Encoding: gzip",
]);
$resData = Json::decode($response);
if ($resData === null) {
internalError();
}

var_dump($resData);

if ($resData["success"]) {
echo Json::encode([
'status' => ErrorCode::NoError,
'result' => null,
]);
} else {
internalError();
}
});

Router::run('/api.php');
6 changes: 3 additions & 3 deletions classes/controllers/RoutesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function search()
if (Input::get('duration') == 0) {
array_push($searchwhere, 'duration <= ?');
array_push($stmts, 3600);
} elseif (Input::get('duration') == 10) {
} elseif (Input::get('duration') == 14) {
array_push($searchwhere, 'duration >= ?');
array_push($stmts, 36000);
array_push($stmts, 60 * 60 * 14);
} elseif (is_numeric(Input::get('duration'))) {
array_push($searchwhere, 'duration >= ?');
array_push($stmts, Input::get('duration') * 3600);
Expand Down Expand Up @@ -114,7 +114,7 @@ public function view($id)
if ($data->route === FALSE) $this->notFound();

$data->aircraft = Route::aircraft($id);
$data->pireps = Route::pireps($data->route->fltnum);
$data->pireps = Route::pireps($data->route->fltnum, $data->route->dep, $data->route->arr);
$this->render('route_view', $data);
}
}
2 changes: 1 addition & 1 deletion classes/data/Aircraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function findAircraft($liveryId)
}

/**
* @return DB
* @return array
*/
public static function fetchAllAircraft()
{
Expand Down
11 changes: 11 additions & 0 deletions classes/data/Awards.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public static function getAll()
return $q->results();
}

public static function getAllRecipients()
{
self::init();
$q = self::$_db->getAll('awards_granted');
if ($q->error()) {
throw new Exception("Failed to fetch award recipients");
}

return $q->results();
}

public static function get($id)
{
self::init();
Expand Down
10 changes: 10 additions & 0 deletions classes/data/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,14 @@ public static function usersWith($perm)
$sql = "SELECT u.* FROM pilots u WHERE u.id IN (SELECT p.userid FROM permissions p WHERE name=?)";
return self::$_db->query($sql, [$perm])->results();
}

/**
* @return array
*/
public static function getAllEntries()
{
self::init();

return self::$_db->getAll('permissions')->results();
}
}
14 changes: 14 additions & 0 deletions classes/data/Pirep.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ public static function getComments($pirepid)
return $q->results();
}


/**
* @return array|null
* @param int $pirepid PIREP ID
*/
public static function getAllComments()
{
self::init();
$q = self::$_db->getAll('pireps_comments');
if ($q->error()) return null;

return $q->results();
}

/**
* @return array|null
* @param int $id Comment ID
Expand Down
6 changes: 3 additions & 3 deletions classes/data/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ public static function nextId()
* @return array
* @param int $fltnum Flight Number
*/
public static function pireps($fltnum)
public static function pireps($fltnum, $dep, $arr)
{
self::init();

$sql = "SELECT pireps.*, pilots.name AS pilotname, aircraft.name AS aircraftname FROM (
pireps INNER JOIN pilots ON pireps.pilotid=pilots.id
) INNER JOIN aircraft ON pireps.aircraftid=aircraft.id
WHERE pireps.flightnum=? AND pireps.status=1";
return self::$_db->query($sql, [$fltnum], true)->results();
WHERE pireps.flightnum=? AND pireps.departure=? AND pireps.arrival=? AND pireps.status=1";
return self::$_db->query($sql, [$fltnum, $dep, $arr], true)->results();
}

/**
Expand Down
9 changes: 9 additions & 0 deletions classes/data/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ public function getAllUsers()
return $usersarray;
}

/**
* @return array
*/
public static function getActiveUsers()
{
$db = DB::newInstance();
return $db->get('pilots', ['status', '=', 1])->results();
}

/**
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ services:
environment:
PMA_HOST: db
ports:
- 8080:80
- 8090:80
depends_on:
- db
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ services:
networks:
flare:
driver: bridge
hostt:
driver: host

volumes:
flare-mysql:
8 changes: 6 additions & 2 deletions themes/default/views/route_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@
<option value="5">5-6hrs</option>
<option value="6">6-7hrs</option>
<option value="7">7-8hrs</option>
<option value="9">8-9hrs</option>
<option value="8">8-9hrs</option>
<option value="9">9-10hrs</option>
<option value="10">10hrs+</option>
<option value="10">10-11hrs</option>
<option value="11">11-12hrs</option>
<option value="12">12-13hrs</option>
<option value="13">13-14hrs</option>
<option value="14">14hrs+</option>
</select>
</div>
<input type="submit" class="btn bg-custom" value="Search" />
Expand Down
28 changes: 16 additions & 12 deletions themes/tailwind/views/admin/routes_new.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,30 @@
</div>
<div class="space-y-1">
<label for="notes">Notes</label>
<input id="notes" name="notes" type="text" class="form-control" value="<?= Page::$pageData->route->notes ?>" />
<input id="notes" name="notes" type="text" class="form-control" />
</div>
<input type="hidden" name="aircraft" :value="aircraft.map(a => a.id).join(',')" />
</div>
<div class="flex-1 p-3 dark:bg-white/10 bg-gray-100 rounded">
<h2 class="text-2xl font-bold mb-2">Route Aircraft</h2>
<ul class="list-disc mb-3 ml-5">
<ul class="mb-3 space-y-0.5">
<template x-for="a in aircraft" :key="a.id">
<li x-text="`${a.name} (${a.liveryname})`"></li>
<li class="flex items-center group">
<span class="flex-1" x-text="`${a.name} (${a.liveryname})`"></span>
<span class="invisible group-hover:visible flex-none text-gray-400 cursor-pointer" title="Remove Aircraft" @click="aircraft = aircraft.filter(ac => ac.id != a.id)">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
</svg>
</span>
</li>
</template>
</ul>
<div class="space-y-1">
<label for="newaircraft">Add Aircraft</label>
<select id="newaircraft" x-ref="newaircraft" class="form-control" @change.prevent="if ($event.target.value) { aircraft.push(allaircraft.find(a => a.ifliveryid == $event.target.value)); $refs.newaircraft.value = ''; }">
<option value>Select</option>
<template x-for="a in allaircraft.filter(ac => !aircraft.includes(ac))">
<option :value="a.ifliveryid" x-text="`${a.name} (${a.liveryname})${a.notes ? ' - ' + a.notes : ''}`"></option>
</template>
</select>
</div>
<select class="form-control" @change.prevent="if ($event.target.value) { aircraft.push(allaircraft.find(a => a.ifliveryid == $event.target.value)); $el.value = ''; }">
<option value>Add Aircraft</option>
<template x-for="a in allaircraft.filter(ac => !aircraft.some(a => a.id == ac.id))">
<option :value="a.ifliveryid" x-text="`${a.name} (${a.liveryname})${a.notes ? ' - ' + a.notes : ''}`"></option>
</template>
</select>
</div>
</div>
<button type="submit" :disabled="aircraft.length < 1" class="button-primary">
Expand Down
4 changes: 2 additions & 2 deletions themes/tailwind/views/route_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
<select id="duration" name="duration" class="form-control">
<option value>Any Flight Time</option>
<option value="0" <?= Input::get('duration') == '0' ? ' selected' : '' ?>>&lt; 1hr</option>
<?php foreach (range(1, 9) as $dur) : ?>
<?php foreach (range(1, 13) as $dur) : ?>
<option value="<?= $dur ?>" <?= Input::get('duration') == $dur ? ' selected' : '' ?>><?= $dur . '-' . ($dur + 1) ?> hours</option>
<?php endforeach; ?>
<option value="10" <?= Input::get('duration') == '10' ? ' selected' : '' ?>>10hrs+</option>
<option value="14" <?= Input::get('duration') == '14' ? ' selected' : '' ?>>14hrs+</option>
</select>
</div>
<div class="space-y-1">
Expand Down

0 comments on commit 80fc6d5

Please sign in to comment.