include("../includes/authenticate.php");
chdir("./squawks/");
/*
$hostname="localhost";
$mysql_login="lesc_club";
$mysql_password="club-224";
$database="lesc_club";
if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))) {
print("Can't connect to server.");
} else {
if (!(mysql_select_db("$database",$db))) {
print("Can't connect to database.");
}
}
*/
if ($_POST) {
if ($userdata['username'] && $_POST['comment']) {
if ($_POST['action']=="add") {
addSquawk($_POST['acid'], $_POST['groundable'], $userdata['username'], $_POST['comment']);
} else {
addSquawkComment($_POST['sqid'], $_POST['action'], $_POST['groundable'], $userdata['username'], $_POST['comment']);
}
}
}
function addSquawk($acid, $groundable, $user, $comment) {
$groundable = $groundable?1:0;
$result = mysql_query("insert into lesc_squawk (acid, groundable, status) values ('".$acid."', '".$groundable."', 1)");
$sqid = mysql_insert_id();
addSquawkComment($sqid, 'opened', $groundable, $user, $comment);
}
function addSquawkComment($sqid, $action, $groundable, $user, $comment) {
$groundable = $groundable?1:0;
// update log
$result = mysql_query("insert into lesc_squawk_log
(sqid, user, action, comment) values ('".$sqid."','".$user."','".$action."','".$comment."')");
// update lesc_squawk
$sql = "update lesc_squawk set groundable='".$groundable."',status='".(($action=='closed')?0:1)."' where sqid='".$sqid."'";
$result = mysql_query($sql);
$sql = "select acid from lesc_squawk where sqid='".$sqid."'";
$result = mysql_query($sql);
$acid = mysql_result($result,0,0);
updateACStatus($acid);
}
function updateACStatus($acid) {
$sql = "select count(*) as count from lesc_squawk where acid='".$acid."' and groundable=1 and status=1";
$result = mysql_query($sql);
$count = mysql_result($result,0,0);
if ($count > 0) {
$result = mysql_query("update lesc_aircraft set status='GROUNDED' where acid='".$acid."'");
} else {
$result = mysql_query("update lesc_aircraft set status='CLEAR' where acid='".$acid."'");
}
}
function getAircraft() {
$aircraft = array();
$result = mysql_query("select * from lesc_aircraft where active=1");
while ($row = mysql_fetch_assoc($result)) {
$row['squawks'] = getSquawks($row['acid']);
$aircraft[] = $row;
}
return $aircraft;
}
function getSquawks($acid) {
$squawks = array();
$squawks['current'] = array();
$squawks['history'] = array();
$result = mysql_query("select * from lesc_squawk where acid='".$acid."' order by status desc, date desc");
while ($row = mysql_fetch_assoc($result)) {
$row['logs'] = getSquawkLogs($row['sqid']);
if ($row['status']==1) {
$squawks['current'][] = $row;
} else {
$squawks['history'][] = $row;
}
}
return $squawks;
}
function getSquawkLogs($sqid) {
$logs = array();
$result = mysql_query("select * from lesc_squawk_log where sqid='".$sqid."' order by date desc");
while ($row = mysql_fetch_assoc($result)) {
$logs[] = $row;
}
return $logs;
}
$ac = getAircraft();
/*
header("content-type: text/plain");
print_r($ac);
exit;
*/
?>
LESC Squawks
Logged in: =$userdata['username']?>
echo "
";
foreach ($ac as $each) {
$ac_status = $each['status'];
if ($ac_status == 'CLEAR' && count($each['squawks']['current'])>0) {
$ac_status = 'SQUAWKS';
}
?>
|
|
=$each['tailno']?>
|
=$each['type']?>
|
add squawk
|
|
if (count($each['squawks']['current'])==0) {
echo " • No Current Squawks ";
} else {
?>
}
foreach ($each['squawks']['current'] as $squawk) {
$log = $squawk['logs'][(count($squawk['logs'])-1)];
?>
|
=date("m/d/Y h:ia", strtotime($log['date']))?> opened by =$log['user']?>
=$log['comment']?>
|
$count = count($squawk['logs'])-1;
for ($i=0;$i<$count;$i++) {
$log = $squawk['logs'][$i];
?>
=date("m/d/Y h:ia", strtotime($log['date']))?> =$log['action']?> by =$log['user']?>
=$log['comment']?>
}
?>
|
close
comment
|
|
}
?>
if (count($each['squawks']['history'])==0) {
echo "• No Squawk History ";
} else {
?>
[+] Squawk History (=count($each['squawks']['history'])?>)
}
foreach ($each['squawks']['history'] as $squawk) {
$log = $squawk['logs'][(count($squawk['logs'])-1)];
?>
|
=date("m/d/Y h:ia", strtotime($log['date']))?> =$log['action']?> by =$log['user']?>
=$log['comment']?>
|
$count = count($squawk['logs'])-1;
for ($i=0;$i<$count;$i++) {
$log = $squawk['logs'][$i];
?>
=date("m/d/Y h:ia", strtotime($log['date']))?> =$log['action']?> by =$log['user']?>
=$log['comment']?>
}
?>
|
re-open
comment
|
|
}
?>
|
|
}
?>