Esempio n. 1
0
    /**
     * This updates the ACARS live data for a pilot
     *
     * @param mixed $data This is the data structure with flight properties
     * @return mixed Nothing
     *
     */
    public static function updateFlightData($pilotid, $data)
    {
        if (!is_array($data)) {
            self::$lasterror = 'Data not array';
            return false;
        }
        if (isset($data['code']) && isset($data['flightnum'])) {
            $data['flightnum'] = $data['code'] . $data['flightnum'];
        }
        // Add pilot info
        $pilotinfo = PilotData::getPilotData($pilotid);
        $data['pilotid'] = $pilotid;
        $data['pilotname'] = $pilotinfo->firstname . ' ' . $pilotinfo->lastname;
        // Store for later
        if (isset($data['registration'])) {
            $ac_registration = $data['registration'];
            unset($data['registration']);
        }
        if (isset($data['depicao'])) {
            $dep_apt = OperationsData::GetAirportInfo($data['depicao']);
            $data['depapt'] = DB::escape($dep_apt->name);
        }
        if (isset($data['arricao'])) {
            $arr_apt = OperationsData::GetAirportInfo($data['arricao']);
            $data['arrapt'] = DB::escape($arr_apt->name);
        }
        if (isset($data['route']) && empty($data['route'])) {
            $flight_info = SchedulesData::getProperFlightNum($data['flightnum']);
            $params = array('s.code' => $flight_info['code'], 's.flightnum' => $flight_info['flightnum']);
            $schedule = SchedulesData::findSchedules($params);
            $schedule = $schedule[0];
            $data['route'] = $schedule->route;
            //$data['route_details'] = serialize(SchedulesData::getRouteDetails($schedule->id));
        } elseif (isset($data['route']) && !empty($data['route'])) {
            /*$tmp = new stdClass();
            		$tmp->deplat = $dep_apt->lat;
            		$tmp->deplng = $dep_apt->lng;
            		$tmp->route = $data['route'];
            		
            		$data['route_details'] = NavData::parseRoute($tmp);
            		$data['route_details'] = serialize($data['route_details']);
            		unset($tmp);*/
        }
        if (!empty($data['route_details'])) {
            $data['route_details'] = DB::escape($data['route_details']);
        }
        if (isset($dep_apt)) {
            unset($dep_apt);
        }
        if (isset($arr_apt)) {
            unset($arr_apt);
        }
        // Clean up times
        if (isset($data['deptime']) && !is_numeric($data['deptime'])) {
            $data['deptime'] = strtotime($data['deptime']);
        }
        if (isset($data['arrtime']) && !is_numeric($data['arrtime'])) {
            $data['arrtime'] = strtotime($data['arrtime']);
        }
        /* Check the heading for the flight
        			If none is specified, then point it straight to the arrival airport */
        if ($data['heading'] == '' || !isset($data['heading']) && isset($data['lat']) && isset($data['lng'])) {
            /* Calculate an angle based on current coords and the
            			destination coordinates */
            $data['heading'] = intval(atan2($data['lat'] - $arr_apt->lat, $data['lng'] - $arr_apt->lng) * 180 / 3.14);
            if ($data['lat'] - $data['lng'] < 0) {
                $data['heading'] += 180;
            }
            if ($data['heading'] < 0) {
                $data['heading'] += 360;
            }
        }
        // Manually add the last set
        $data['lastupdate'] = 'NOW()';
        // first see if we exist:
        $sql = 'SELECT `id`
				FROM ' . TABLE_PREFIX . "acarsdata \n\t\t\t\tWHERE `pilotid`={$pilotid}";
        $exist = DB::get_row($sql);
        $flight_id = '';
        if ($exist) {
            // update
            $upd = array();
            $flight_id = $exist->id;
            foreach ($data as $field => $value) {
                $value = DB::escape(trim($value));
                // Append the message log
                if ($field === 'messagelog') {
                    $upd[] = "`messagelog`=CONCAT(`messagelog`, '{$value}')";
                } elseif ($field === 'lastupdate') {
                    $upd[] = "`lastupdate`=NOW()";
                } elseif ($field === 'deptime' || $field === 'arrtime') {
                    /*	If undefined, set a default time to now (penalty for malformed data?)
                    			Won't be quite accurate.... */
                    if ($value == '') {
                        $value = time();
                    }
                    $upd[] = "`{$field}`=FROM_UNIXTIME({$value})";
                } else {
                    $upd[] = "`{$field}`='{$value}'";
                }
            }
            $upd = implode(',', $upd);
            $query = 'UPDATE ' . TABLE_PREFIX . "acarsdata \n\t\t\t\t\tSET {$upd} \n\t\t\t\t\tWHERE `id`='{$flight_id}'";
            DB::query($query);
        } else {
            // form array with $ins[column]=value and then
            //	give it to quick_insert to finish
            $ins = array();
            $vals = array();
            foreach ($data as $field => $value) {
                $ins[] = "`{$field}`";
                if ($field === 'deptime' || $field === 'arrtime') {
                    if (empty($value)) {
                        $value = time();
                    }
                    $vals[] = "FROM_UNIXTIME({$value})";
                } elseif ($field === 'lastupdate') {
                    $vals[] = 'NOW()';
                } else {
                    $value = DB::escape($value);
                    $vals[] = "'{$value}'";
                }
            }
            $ins = implode(',', $ins);
            $vals = implode(',', $vals);
            $query = 'INSERT INTO ' . TABLE_PREFIX . "acarsdata ({$ins}) \n\t\t\t\t\t\tVALUES ({$vals})";
            DB::query($query);
            $data['deptime'] = time();
            $flight_id = DB::$insert_id;
        }
        $flight_info = self::get_flight_by_id($flight_id);
        // Add this cuz we need it
        $data['code'] = $pilotinfo->code;
        $data['pilotid'] = $pilotid;
        $data['unique_id'] = $flight_id;
        $data['aircraft'] = $flight_info->aircraftname;
        $data['registration'] = $flight_info->registration;
        $res = CentralData::send_acars_data($data);
        return true;
    }
Esempio n. 2
0
    case 'sendpilots':
        $resp = CentralData::send_pilots();
        break;
    case 'sendallpireps':
        $resp = CentralData::send_all_pireps();
        break;
    case 'sendpirep':
        $pirep = PIREPData::findPIREPS(array(), 20);
        $num = rand(0, count($pirep) - 1);
        $resp = CentralData::send_pirep($pirep[$num]->pirepid);
        break;
    case 'sendacars':
        # Send a random flight
        $flights = ACARSData::GetAllFlights();
        $total = count($flights);
        $resp = CentralData::send_acars_data($flights[rand(0, $total - 1)]);
        break;
    case 'sendallacars':
        $resp = CentralData::send_all_acars();
        break;
}
?>
<h3>Response:</h3>
<pre><?php 
$response = CentralData::$xml_response;
echo htmlentities(formatXmlString($response));
?>
</pre>

<h3>Sent Data</h3>
<pre><?php