Skip to content

Commit

Permalink
Merge pull request #256 from va-net/v1-1-0
Browse files Browse the repository at this point in the history
v1.1.0 Beta 1
  • Loading branch information
velocity23 authored Nov 17, 2020
2 parents da3f45e + 597c2f0 commit 2392781
Show file tree
Hide file tree
Showing 34 changed files with 534 additions and 157 deletions.
2 changes: 2 additions & 0 deletions acars.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$user = new User();

Page::setTitle('ACARS - '.Config::get('va/name'));
Page::excludeAsset('datatables');
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('index.php');
Expand Down
39 changes: 0 additions & 39 deletions admin.php

This file was deleted.

2 changes: 2 additions & 0 deletions admin/codeshares.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$user = new User();

Page::setTitle('Codeshares Admin - '.Config::get('va/name'));
Page::excludeAsset('datatables');
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
2 changes: 2 additions & 0 deletions admin/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$user = new User();

Page::setTitle('Events Admin - '.Config::get('va/name'));
Page::excludeAsset('datatables');
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
1 change: 1 addition & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$user = new User();

Page::setTitle('Site Dashboard - '.Config::get('va/name'));
Page::excludeAsset('datatables');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
2 changes: 2 additions & 0 deletions admin/multipliers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$user = new User();

Page::setTitle('Multipliers Admin - '.Config::get('va/name'));
Page::excludeAsset('datatables');
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
1 change: 1 addition & 0 deletions admin/news.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$user = new User();

Page::setTitle('News Admin - '.Config::get('va/name'));
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
17 changes: 11 additions & 6 deletions admin/operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$user = new User();

Page::setTitle('Operations Admin - '.Config::get('va/name'));
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down Expand Up @@ -679,6 +680,9 @@ function reverseFormatEditFlightTime() {
$routesArray = [];
foreach ($routelines[0] as $l) {
$segments = preg_split('/, ?/', $l);
if (strpos($segments[10], ".") === FALSE && strpos($segments[10], ":") === FALSE) {
$segments[10] .= ".00";
}
array_push($routesArray, array(
"fltnum" => $segments[1],
"dep" => $segments[2],
Expand All @@ -702,22 +706,23 @@ function reverseFormatEditFlightTime() {
$j = 0;
$doneAircraft = [];
echo '<table class="w-100 mb-2">';
for ($j=0; $j<$i-1; $j++) {
$r = $routesArray[$j];
$i = 0;
foreach ($routesArray as $r) {
if (!in_array($r['aircraftid'], $doneAircraft)) {
echo '<tr class="border-bottom border-top"><td class="align-middle p-2"><b>';
echo $r['aircraftid'];
echo '</b></td><td class="align-middle py-2">';
echo '<input hidden name="rego'.$j.'" value="'.$r["aircraftid"].'" />';
echo '<select required class="form-control mb-2 aircraftSelect" name="aircraft'.$j.'" id="'.$j.'">';
echo '<input hidden name="rego'.$i.'" value="'.$r["aircraftid"].'" />';
echo '<select required class="form-control mb-2 aircraftSelect" name="aircraft'.$i.'" id="'.$i.'">';
echo '<option value>Aircraft Type</option>';
echo $aircraftOptions;
echo '</select>';
echo '<select required class="form-control" name="livery'.$j.'" id="livery'.$j.'">';
echo '<select required class="form-control" name="livery'.$i.'" id="livery'.$i.'">';
echo '<option value>Select an Aircraft to Get Liveries</option>';
echo '</select>';
echo '</td></tr>';
array_push($doneAircraft, $r['aircraftid']);
$i++;
}
}
echo '</table>';
Expand All @@ -730,7 +735,7 @@ function reverseFormatEditFlightTime() {
var id = $(this).attr("id");
$("#livery" + id).html("<option value>Loading...</option>");
$.ajax({
url: "vanet.php",
url: "/vanet.php",
type: "POST",
data: { method: "liveriesforaircraft", data: $(this).val() },
success: function(html){
Expand Down
2 changes: 2 additions & 0 deletions admin/pireps.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$user = new User();

Page::setTitle('PIREPs Admin - '.Config::get('va/name'));
Page::excludeAsset('datatables');
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
1 change: 1 addition & 0 deletions admin/recruitment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_once '../core/init.php';

$user = new User();
Page::excludeAsset('chartjs');

Page::setTitle('Recruitment Admin - '.Config::get('va/name'));

Expand Down
2 changes: 2 additions & 0 deletions admin/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$user = new User();

Page::setTitle('Site Admin - '.Config::get('va/name'));
Page::excludeAsset('datatables');
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
1 change: 1 addition & 0 deletions admin/staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$user = new User();

Page::setTitle('Staff Admin - '.Config::get('va/name'));
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
2 changes: 2 additions & 0 deletions admin/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
$user = new User();

Page::setTitle('VA Stats - '.Config::get('va/name'));
Page::excludeAsset('datatables');
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down
3 changes: 2 additions & 1 deletion admin/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$user = new User();

Page::setTitle('Users Admin - '.Config::get('va/name'));
Page::excludeAsset('chartjs');

if (!$user->isLoggedIn()) {
Redirect::to('/index.php');
Expand Down Expand Up @@ -85,7 +86,7 @@
echo '<button class="btn btn-primary text-light userEdit" data-callsign="'.$user['callsign'].'"
data-name="'.$user['name'].'" data-email="'.$user['email'].'" data-ifc="'.$user['ifc'].'"
data-joined="'.date_format(date_create($user['joined']), 'Y-m-d').'" data-status="'.$user['status'].'"
data-id="'.$user['id'].'" data-thrs="'.Time::secsToString($user["transhours"] + $user["transhours"]).'"
data-id="'.$user['id'].'" data-thrs="'.Time::secsToString($user["transhours"]).'"
data-admin="'.$user['isAdmin'].'" data-tflts="'.$user["transflights"].'"><i class="fa fa-edit"></i>
</button>';
echo '&nbsp;<button id="delconfirmbtn" class="btn text-light btn-danger"
Expand Down
3 changes: 3 additions & 0 deletions apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use RegRev\RegRev;

Page::setTitle('Apply - '.Config::get('va/name'));
Page::excludeAsset('datatables');
Page::excludeAsset('chartjs');
Page::excludeAsset('momentjs');

$user = new User();
if ($user->isLoggedIn()) {
Expand Down
4 changes: 0 additions & 4 deletions assets/style.css.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
}
}

table {
text-align: center;
}

* {
font-family: 'Rubik', sans-serif;
}
Expand Down
148 changes: 148 additions & 0 deletions classes/Notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

/*
Flare, a fully featured and easy to use crew centre, designed for Infinite Flight.
Copyright (C) 2020 Lucas Rebato
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

class Notifications {

/**
* @var DB
*/
private static $_db;

/**
* @var array
*/
private static $_events = [
"user/accepted" => "handleUserAccepted",
"vanet/event/added" => "handleEventAdded",
"news/added" => "handleNewsAdded",
"pirep/accepted" => "handlePirep",
"pirep/denied" => "handlePirep",
];

private static function init()
{
self::$_db = DB::getInstance();
}

/**
* @return array
* @param int $userId User ID
*/
public static function mine($userId, $limit = 5)
{
self::init();

if (!is_numeric($limit)) throw new Exception("Parameter Limit must be Numeric");

$sql = "SELECT *, DATE_FORMAT(CONVERT_TZ(`datetime`, @@session.time_zone, '+00:00'), '%Y-%m-%dT%TZ') AS formattedDate FROM notifications
WHERE pilotid=? OR pilotid=0 ORDER BY datetime DESC LIMIT {$limit}";

return self::$_db->query($sql, [$userId])->results();
}

/**
* @return null
* @param int $pilot Pilot ID
* @param string $icon Icon
* @param string $subject Notification Subject
* @param string $content Notification Content
*/
public static function notify($pilot, $icon, $subject, $content)
{
self::init();

if (strlen($icon) > 20) throw new Exception("Parameter icon must be 20 Characters or Less");
if (strlen($subject) > 20) throw new Exception("Parameter subject must be 20 Characters or Less");
if (strlen($content) > 60) throw new Exception("Parameter content must be 60 Characters or Less");

$res = self::$_db->insert('notifications', [
'pilotid' => $pilot,
'icon' => $icon,
'subject' => $subject,
'content' => $content,
]);
}

/* EVENT HANDLERS */

/**
* @return null
* @param Event $ev
*/
public static function handleEvent($ev)
{
if (!array_key_exists($ev->event, self::$_events)) return;

call_user_func_array('self::'.self::$_events[$ev->event], [$ev]);
}

/**
* @return null
* @param Event $ev
*/
private static function handleUserAccepted($ev)
{
$args = $ev->params;
$vaname = Config::get('va/name');
$content = "Welcome to {$vaname}! We hope you enjoy your stay.";
if (strlen($content) > 60) return;
self::notify($args[0], "fa-smile-beam", $content);
}

/**
* @return null
* @param Event $ev
*/
private static function handleEventAdded($ev)
{
$args = $ev->params;
$content = "An Event Called {$args['Name']} was just posted. Check it out!";
if (strlen($content) > 60) return;
self::notify(0, "fa-calendar", "New Event", $content);
}

/**
* @return null
* @param Event $ev
*/
private static function handleNewsAdded($ev)
{
$args = $ev->params;
$content = "A News Item titled {$args['subject']} was just added by {$args['author']}";
if (strlen($content) > 60) return;
self::notify(0, "fa-newspaper", "News Added", $content);
}

/**
* @return null
* @param Event $ev
*/
private static function handlePirep($ev)
{
self::init();
$args = $ev->params;
if ($ev->event == 'pirep/accepted') {
$pirep = self::$_db->get('pireps', ['id', '=', $args['id']])->results();
if (count($pirep) == 0) return;
$pirep = $pirep[0];
$content = "Your PIREP from {$pirep->departure} to {$pirep->arrival} was Accepted";
if (strlen($content) > 60) return;
self::notify(0, "fa-check", "PIREP Accepted", $content);
} else {
$pirep = self::$_db->get('pireps', ['id', '=', $args['id']])->results();
if (count($pirep) == 0) return;
$pirep = $pirep[0];
$content = "Your PIREP from {$pirep->departure} to {$pirep->arrival} was Denied";
if (strlen($content) > 60) return;
self::notify(0, "fa-times", "PIREP Denied", $content);
}
}

}
Loading

0 comments on commit 2392781

Please sign in to comment.