#2 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-25 19:51:29

Nejsou :-( jsou tam 3 tabulky a ani v jedné :-( můžu ti poslat soubory které tam mám.

#4 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-25 16:38:35

Tak jsem tam dal ty mapy, a nic se nezobrazuje, píše to že nikdo momentálně neletí

#5 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-25 16:19:43

Ad 1)  do té URL mám napsat jen /acars/reports/ ?

Ad 2) složky mám dobře, xacars je v  xacars a fsacars je v acars

#6 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-25 16:06:08

Pardoon :-( roll

Z toho používám to PHP/MySQL Pirep,

a ten receive_pirep.php, tak tam mám nastaveno

* Change this constants according to your configuration  */
@define ("MYSQL_CONNECT_INCLUDE", "connect_db.php");		// MySQL database connection (a sample file is included)
@define ("REPORT_FILE_URL", "http://www.fl1ght3r.4fan.cz/acars/reports/");				// URL where the complete FSAcars reports will be stored
@define ("REPORT_FILE_PATH", "/home/users/fl1ght3r/fl1ght3r.4fan.cz/web/acars/reports/");				// Folder where the complete FSAcars reports will be stored
@define ("ERROR_LOG_PATH", "/home/users/fl1ght3r/fl1ght3r.4fan.cz/web/acars/errors/error.log");		

#7 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-25 15:57:34

jeje  :-D ja tady motám 2 programy dohromady  :-(, ten program který chci zprovoznit se jmenuje FSacars
http://www.satavirtual.org/fsacars/  omlouvám se.

#9 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-25 11:37:02

<?php
 
/**
 * LiveACARS Service for XAcars
 *
 */
 
// ----------------------------------------------------------------------------
// In functions.php the database is connected as used to
require("db.inc.php");
 
define("ACARS_UNKNOWN",   -1);
define("ACARS_XACARS",    3);
define("ACARS_XACARS_MSFS",    4);
 
 
define("FLIGHTSTATUS_BOARDING", 1);
define("FLIGHTSTATUS_TAXIOUT",  2);
define("FLIGHTSTATUS_DEPARTURE",3);
define("FLIGHTSTATUS_CLIMB",    4);
define("FLIGHTSTATUS_CRUISE",   5);
define("FLIGHTSTATUS_DESC",     6);
define("FLIGHTSTATUS_APPROACH", 7);
define("FLIGHTSTATUS_LANDED",   8);
define("FLIGHTSTATUS_TAXIIN",   9);
define("FLIGHTSTATUS_IN",      10);
define("FLIGHTSTATUS_END",     10);
define("FLIGHTSTATUS_UNKNOWN",  0);
define("FLIGHTSTATUS_CRASH",   99);
 
define("VSPEED_CRZ",   0);
define("VSPEED_GND",   0);  
define("VSPEED_CLB",   +1);
define("VSPEED_DES",   -1);
   
// ----------------------------------------------------------------------------
// Classes for ACARS_FLIGHT and ACARS_POSITION
 
Class acarsFlight
{
    var $flightID;
    var $userID;
    var $acarsID       = ACARS_XACARS;
    var $aircraft      = '';
    var $flightRot     = '';
    var $flightType    = 'IFR';
    var $flightPlan    = '';
    var $departure     = '';
    var $destination   = '';
    var $curPositionID = 0;
    
    function doInsert()
    {
        $sql  = 'INSERT INTO acars_flight(acarsFlightID, userID, acarsID, acType, callsign,
                    flightType, flightPlan, departure, destination) VALUES ( ' 
              . $this->flightID . ', '
              . $this->userID . ', '        
              . $this->acarsID . ', '
              . "'{$this->aircraft}', "
              . "'{$this->flightRot}', "
              . "'{$this->flightType}', "
              . "'{$this->flightPlan}', "
              . "'{$this->departure}', "
              . "'{$this->destination}');";
 
        if(!mysql_query($sql))
            die('0|SQL query failed (INSERT acars flight)   ' . $sql);
    }    
}    
 
Class acarsPosition
{
    var $msgtype    = '??';
    var $flightID   = 0;
    var $remoteTime = 0;
    var $posLat     = 0; 
    var $posLon     = 0;
    var $flightstat = FLIGHTSTATUS_UNKNOWN;
    var $vs         = VSPEED_GND;
    var $hdg = 0;
    var $alt = 0;
    var $gs  = 0;
    var $tas = 0;
    var $ias = 0;
    var $wnd = '00000';
    var $oat = 0;
    var $tat = 0;
    var $fob = 0;
    var $distFromDep    = 0;
    var $distTotal      = 0;    
    var $msgdata = '';
    
    function doInsert()
    {
        $sql  = 'INSERT INTO acars_position (acarsFlightID, acarsMsgID, systemTime, remoteTime, msgtype, flightStatus,  
                 latitude, longitude, heading, altitude, VS, GS, IAS, TAS, FOB, WND, OAT, TAT, distFromDep, 
                 distTotal, pauseMode, message) 
                 VALUES ( '                
             . $this->flightID . ", '', "               // FlightID, MsgID := ''
             . time() . ', '                            // Time Stamp
             . $this->remoteTime . ', '                 // Remote Time Stamp
             . "'{$this->msgtype}', "                   // Messagetype
             . $this->flightstat . ', '                 // Flightstatus
             . $this->posLat .', '. $this->posLon .', ' // Position
             . $this->hdg . ', '                        // Heading
             . $this->alt . ', '                        // Altitude
             . $this->vs . ', '                         // vertical speed
             . $this->gs  . ', ' . $this->ias . ', '    // GS und IAS
             . $this->tas . ', ' . $this->fob . ', '    // TAS, FUEL
             . "'{$this->wnd}', "                       // Winddaten
             . $this->oat . ', ' . $this->tat . ', '    // OAT und TAT
             . $this->distFromDep . ', '                // distFromDep
             . $this->distTotal . ', '                  // distTotal              
             . "0, \"{$this->msgdata}\");";  
        
        if(!mysql_query($sql))
            die('0|SQL query failed (INSERT acars position)   ' . $sql);
 
        if( $this->msgtype <> 'ZZ' )
        {
              // If the message wasn't a ENDFLIGHT message, the actual position is going to be written in acars_flight
            $newID = mysql_insert_id(); // maybe this function does not work on each system
            $query = "UPDATE acars_flight SET curPositionID = {$newID}, active = 1 WHERE acarsFlightID = {$this->flightID};";
            $result = mysql_query($query) or die("0|SQL query failed (UPDATE acars_flight)");
        }
                 
        return True;
    }
}
 
// ----------------------------------------------------------------------------
// Functions
 
function testPilotID($pid)
{
    $q_user = @mysql_query("SELECT id FROM user WHERE isactive=1 and username = '{$pid}' LIMIT 1");
    
    if(@mysql_num_rows($q_user) == 0)
        return -1;
    else
    {
        $user = @mysql_fetch_array($q_user);
        return $user['id'];
    }
}
 
function testUserLogin($pid, $pw)
{
    $q_user = @mysql_query("SELECT id FROM user WHERE isactive=1 and username = '$pid' and password = '$pw' LIMIT 1");
    if(@mysql_num_rows($q_user) <= 0)
    {
      return -1;
    }
    else
    {
      $user = @mysql_fetch_array($q_user); 
      return $user['id'];
    }
}
 
function CheckXAcarsVersion($DATA1)
{
    if( (strcmp($DATA1, "XACARS|1.0")==0)
        || (strcmp($DATA1, "XACARS|1.1")==0)
        || (strcmp($DATA1, "XACARS|2.0")==0)        
        || (strcmp($DATA1, "XACARS|2.5")==0) 
        || (strcmp($DATA1, "XACARS|3.0")==0) )        
        return ACARS_XACARS;
    elseif( (strcmp($DATA1, "XACARS_MSFS|1.0")==0)
        || (strcmp($DATA1, "XACARS_MSFS|1.1")==0)
        || (strcmp($DATA1, "XACARS_MSFS|2.0")==0)        
        || (strcmp($DATA1, "XACARS_MSFS|2.5")==0) 
        || (strcmp($DATA1, "XACARS_MSFS|3.0")==0) ) 
        return ACARS_XACARS_MSFS;
    else
        return ACARS_UNKNOWN;
}
 
Function lbs2kg( $lbs )
{
    return( $lbs / 2.204622915 );
}
 
function latDegDecMin2DecDeg( $dat )
{
    if( $dat=='' )
        return( 0 ); 
 
    $i = 0;
    $j = strpos($dat, ' ', 0);
    $k = max( strpos($dat, '.', $j), $j+1);
 
    $dec  = substr($dat,1,$j);                // degrees
    $dec += substr($dat, $j+1, $k-$j+2) / 60; // decimal minutes
    
    If( $dat{0} == 'S' )
        $dec = -$dec;
        
    return round($dec,4);
}
 
function lonDegDecMin2DecDeg( $dat )
{
    if( $dat=='' )
        return( 0 ); 
    
    $i = 0;
    $j = strpos($dat, ' ', 0);
    $k = max( strpos($dat, '.', $j), $j+1);
 
    $dec  = substr($dat,1,$j);                // degrees
    $dec += substr($dat, $j+1, $k-$j+2) / 60; // decimal minutes
    
    If( $dat{0} == 'W' )
        $dec = -$dec;
 
    return round($dec,4);
}
 
// ----------------------------------------------------------------------------
// Decode ACARS message
 
if (!isset($_REQUEST['DATA1'])) die('0|Invalid Data1');
if (!isset($_REQUEST['DATA2'])) die('0|Invalid Data2');
 
if (($version  = CheckXAcarsVersion($_REQUEST['DATA1'])) <= 0)
    die('0|Invalid XAcars Version');
 
$data2 = $_REQUEST['DATA2'];
if (!isset($_REQUEST['DATA3']))
    $data3 = '';
else
    $data3 = $_REQUEST['DATA3'];
 
if (!isset($_REQUEST['DATA4']))
    $data4 = '';
else
    $data4 = $_REQUEST['DATA4'];
 
$data2 = str_replace("\'", "''", $data2);
$data3 = str_replace("\'", "''", $data3);
$data4 = str_replace("\'", "''", $data4);
 
// Temp logging if you want to see the output in liveacars.log
// ----------------------------------------------------------------------------
/*
$logcontent = '?'.$_REQUEST['DATA1'].'&'.$_REQUEST['DATA2'].'&'.$_REQUEST['DATA3'].'&'.$_REQUEST['DATA4']."\n";
$logfilename = './liveacars.log';
$handle = fopen($logfilename, "a");
fwrite($handle, $logcontent);
fclose($handle);
*/
 
 
// ----------------------------------------------------------------------------
// Writing the date into the database
 
switch ($data2) {
    case "TEST":
        /* Testing the ACARS Connection */
        if( testPilotID($data3) > 0 )
            echo '1';
        else
            echo '0|Unknown PilotID '.$data3;
        break;
 
    case "BEGINFLIGHT":
        /* Begin Flight logging on ACARS */
        $data = split("\|", $data3);
        if( count($data) < 16 )
        {
            echo '0|Invalid login data ('. count($data) . ')';
            break;
        }
        
        $uid = testUserLogin($data[0], $data[17]);
        if( $uid == -1 )
        {
            echo '0|Login failed';
            break;
        }
 
        $acarsflight = new acarsFlight();
        $acarsflight->flightID = time();
        $acarsflight->userID = $uid;
        $acarsflight->acarsID  = ACARS_XACARS;
        
        // *** Origin and Destination Airports
        if (strlen($data[5]) != 0)
        {
            $plan = split('~', $data[5]);
            $acarsflight->departure   = strtoupper($plan[0]);
 
            if (count($plan) > 1)
                $acarsflight->destination = strtoupper($plan[count($plan) - 1]);
        }
 
        $acarsflight->aircraft   = $data[3];       // AircraftRegistration
        $acarsflight->flightType = $data[15];      // flightType   
        $acarsflight->flightPlan = $data[5];       // flightPlan
        $acarsflight->flightRot  = $data[2];       // FlightNumber
        $acarsflight->doInsert();
                
        $acarspos = new acarsPosition();
        $acarspos->flightID     = $acarsflight->flightID;
        $acarspos->msgtype      = 'PR';
        if( $data[6] <> '' )
        {
            //N52 23.1890 E13 31.0944
            $tmp = split(' ', $data[6]);
            
            $acarspos->posLat       = latDegDecMin2DecDeg(trim($tmp[0] . ' ' . $tmp[1]));
            $acarspos->posLon       = lonDegDecMin2DecDeg(trim($tmp[2] . ' ' . $tmp[3]));
        }
        $acarspos->flightstat   = FLIGHTSTATUS_BOARDING;
        $acarspos->waypoint     = $acarsflight->departure;
        $acarspos->hdg          = $data[12];
        $acarspos->alt          = $data[7];
        $acarspos->wnd          = $data[13];
        $acarspos->oat          = $data[14];
        $acarspos->tat          = $data[14];    //Just because GS:=0 at the moment
        $acarspos->fob          = lbs2kg($data[11]);
        $acarspos->distTotal    = $data[16];
        $acarspos->msgdata      = $data3;
        $acarspos->doInsert();
 
        print '1|'.$acarsflight->flightID;
        break;
 
    case "MESSAGE":
        $acarspos = new acarsPosition();
 
        $acarspos->flightID     = $data3;
        $acarspos->msgdata      = $data4;
                
        // Decode the message
        // Messagetype: PR=Position Report, AR=Alitude Report, WX=Weather,
        //              QA=OUT, QB=OFF, QC=ON, QD=IN, QM=Flight Statistics, CM=User Message        
        $j = strpos($data4, 'Msg Label: ', 0);
        if ($j != false) 
        {
            $j = $j + strlen('Msg Label: ');
            $acarspos->msgtype = substr($data4, $j, 2);
        }
        else
            die('ERROR - Wrong Message format: Msg Label is missing');
 
        // Remote Timestamp auslesen  [01/17/2006 06:58Z]
        $acarspos->remoteTime = strtotime( substr($data4, 1,17));
            
        $j = strpos($data4, 'Message:', 0);
        if ($j == false)
            die('ERROR - Wrong Message format: Messagebody is missing');
            
        $j = $j + 9; // strlen('Message:\n')
        $data = split('/', substr($data4, $j));
        
        foreach( $data as $cmdStr)
        {           
 
            $k = strpos($cmdStr, ' '); 
            $cmd = strtoupper(substr($cmdStr, 0, $k));
            $cnt = trim(substr($cmdStr,$k));
 
            switch( $cmd )
            {
                case 'POS':
                    $tmp = split(' ', $cnt);
                    $acarspos->posLat       = latDegDecMin2DecDeg(trim($tmp[0] . ' ' . $tmp[1]));
                    $acarspos->posLon       = lonDegDecMin2DecDeg(trim($tmp[2] . ' ' . $tmp[3]));
                    $i = strpos($cnt, '[');
                    if( $i > 0 )
                        $acarspos->waypoint = substr($cnt, $i+1, -1);
                break;
 
                case 'HDG':
                    if( is_numeric($cnt) == True)
                        $acarspos->hdg = $cnt;
                    break;
                
                case 'ALT':
                    $i = strpos($cnt, ' ');
                    if( $i == false )
                        $acarspos->alt = $cnt;
                    else
                    {
                        $acarspos->alt = substr($cnt, 0, $i);
                        if( strpos( $cnt, 'CLIMB' ) != False)
                            $acarspos->vs = VSPEED_CLB;
                        elseif( strpos( $cnt, 'DESC' ) != False)
                            $acarspos->vs = VSPEED_DES;
                        elseif( strpos( $cnt, 'LEVEL' ) != False)
                            $acarspos->vs = VSPEED_CRZ;
                    }
                    break;
 
                case 'IAS':
                    if( is_numeric($cnt) == True)
                        $acarspos->ias = $cnt;
                    break;
                    
                case 'TAS':
                    if( is_numeric($cnt) == True)
                        $acarspos->tas = $cnt;
                    break;
 
                case 'OAT':
                    if( is_numeric($cnt) == True)
                        $acarspos->oat = $cnt;
                    break;
                    
                case 'TAT':
                    if( is_numeric($cnt) == True)
                        $acarspos->tat = $cnt;
                    break;
 
                case 'FOB':
                    if( is_numeric($cnt) == True)
                        $acarspos->fob = lbs2kg($cnt);
                    break;
                    
                case 'WND':
                    if( is_numeric($cnt) == True)
                        $acarspos->wnd = $cnt;
                    break;
 
                case 'DST':
                    $i = strpos( $cnt, '-' );
                    $acarspos->distFromDep = substr($cnt,0, $i-1);
                    $acarspos->distTotal   = substr($cnt,$i+2);
                    break;
 
                case 'AP':
                    $acarspos->airport = $cnt;
                    break;
            }
        }
        
        switch( $acarspos->msgtype )
        {
            case 'QA':   // QA = OUT Message
                $acarspos->waypoint     = $acarspos->airport;  
                $acarspos->flightstat   = FLIGHTSTATUS_TAXIOUT;
                $acarspos->vs           = VSPEED_GND;
                $acarspos->doInsert();        
                print '1|';
            break;
 
            case 'QB':   // QB = OFF Message
                $query = "SELECT curWaypoint FROM acars_position WHERE acarsFlightID = {$acarspos->flightID} AND msgtype = 'QA'";                
                $result = @mysql_query($query) or die("0|SQL query failed");
                if (@mysql_num_rows($result) > 0)
                {
                    $temp = @mysql_fetch_array($result);
                    $acarspos->waypoint     = $temp[0];  
                }
                $acarspos->flightstat   = FLIGHTSTATUS_DEPARTURE;
                $acarspos->vs           = VSPEED_CLB;
                $acarspos->doInsert();        
                print '1|';
            break;
 
            case 'QC':   // QC = ON  Message
                $acarspos->waypoint     = $acarspos->airport;  
                $acarspos->flightstat   = FLIGHTSTATUS_LANDED;
                $acarspos->vs           = VSPEED_GND;
                $acarspos->doInsert();        
                print '1|';
            break;
 
            case 'QD':   // QD = IN Message
                $acarspos->flightstat   = FLIGHTSTATUS_IN;
                $acarspos->vs           = VSPEED_GND;
                $acarspos->doInsert();        
                print '1|';
            break;
 
            case 'PR':   // PR = Position Report Message
                $acarspos->doInsert();        
                print '1|';
            break;
                
            case 'AR':   // AR = Altitude Report Message
                if( $acarspos->vs == VSPEED_CRZ )
                    $acarspos->flightstat = FLIGHTSTATUS_CRUISE;
                elseif( $acarspos->vs == VSPEED_CLB )
                {
                    if( $acarspos->distFromDep > 30 ) 
                        // Inflight Climb (more then 30nm from departure - insert what you want)
                        $acarspos->flightstat = FLIGHTSTATUS_CRUISE;
                    else
                        // Initial Climb
                        $acarspos->flightstat = FLIGHTSTATUS_CLIMB;
                }
                elseif( $acarspos->vs == VSPEED_DES )
                    if( ($acarspos->distTotal - $acarspos->distFromDep) > 100    ) 
                        // Inflight Descend (more then 100Nm to destination - insert what you want)
                        $acarspos->flightstat = FLIGHTSTATUS_CRUISE;
                    else
                        // Initial Descend
                        $acarspos->flightstat = FLIGHTSTATUS_DESC;
                    
                $acarspos->doInsert();        
                print '1|';
            break;
        }
        break;
 
    case "PAUSEFLIGHT":
        print "1|";
        break;
 
    case "ENDFLIGHT":
        $acarspos = new acarsPosition();
 
        $acarspos->flightID     = $data3;
        $acarspos->flightstat   = FLIGHTSTATUS_END;
        $acarspos->msgtype      = 'ZZ';        
        $acarspos->doInsert();        
 
        print "1|";
        break;
 
    default:
        print "0|Wrong Function";
        break;
 
}
 
?>

Tento php vkládá něco do tabulky acars_position že ?

#10 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 22:13:36

Mi to nějak nejde :-( na konec souboru vložím

echo "<div><endora></div>";

a reklama je porád první...

#11 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 21:43:55

Ten program není můj, nemám k němu ani kod. :-(

A tu reklamu umístím jak ? někam napíšu <endora> že ?

#12 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 21:42:06

$fe = fopen (ERROR_LOG_PATH, "a");
	fwrite($fe, "[DEBUG ".date("d.m.y H:i:s")."] PILOT: ".$_GET['pilot']." DATE: ".$_GET['date']." TIME: ".$_GET['time']." CALLSIGN: ".$_GET['callsign']." REG: ".$_GET['reg']." ORIG: ".$_GET['origin']." DEST: ".$_GET['dest']." EQUIP: ".$_GET['equipment']." FUEL: ".$_GET['fuel']." DURATION: ".$_GET['duration']." DIST: ".$_GET['distance']." MORE: ".$_GET['more']." LOG: ".$_GET['log']."\n");
	fclose($fe);

Toto je na řádce 82-84

#14 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 21:04:07

To nechápu. Prostě program zaznamenává průběh letů v Flight Simulatoru. Po ukončení letu pilot odešle tzv. PIREP. Ten se odesílá přes ten php soubor, a ten ho pak zanáší do DB a  vytváří ten soubor

#15 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 20:49:47

No do programu zasáhnout nemůžu, a ta reklama jde skrýt ? Je to soubor do kterého nikdo přímo neleze, je to jen jakoby prostředník přenosu informací. PHP soubor.

#16 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 20:10:35

Takže jediné řešení je Plus účet.
Tohle je jiný soubor.

<?php
/*
 * You may not remove this header!
 *
 * -----------------------------------------------------------------------------------------------------------------------
 * 'receive_pirep.php' script code was made by Paulo Correia - FSAcars Team (©)2003
 * It's part of the FSAcars 2 for VA's package 
 *
 * This script assumes that the VA has PHP support and a MySQL database on it's site
 * A DDL file to create the following tables is provided: 'pilots', 'reports'
 *
 * The 'reports' table as the following columns:
 * pilot_id,date,time,callsign,origin_id,destination_id,registration,equipment,duration,fuel,distance,fsacars_rep_url
 * ----------------------------------------------------------------------------------------------------------------------
 *
 * FSACARS is distributed freely.
 *
 * Disclaimer
 * Although this product has been intensively tested, the authors accepts no responsibility for any damages caused by the use or misuse of this
 * software. This software is distributed 'as is' with no warranty expressed or implied. The authors will not be responsible for any losses incurred, either directly or indirectly, by the use of this software.
 * Use this software entirely at your own risk. If you do not agree to these terms then you must not use this software.
 *
 * Copyright
 * This software is a copyrighted program. AIBridge is a copyright of José Oliveira. FSACARS coding is a copyright of José Oliveira. FSACARS concept was idealized by Pedro Sousa.
 * It is protected by international copyright laws.
 */

/*
 * Change this constants according to your configuration  */
@define ("MYSQL_CONNECT_INCLUDE", "connect_db.php");		// MySQL database connection (a sample file is included)
@define ("REPORT_FILE_URL", "http://www.fl1ght3r.4fan.cz/acars/");				// URL where the complete FSAcars reports will be stored
@define ("REPORT_FILE_PATH", "/home/users/fl1ght3r/fl1ght3r.4fan.cz/web/acars/reports");				// Folder where the complete FSAcars reports will be stored
@define ("ERROR_LOG_PATH", "/home/users/fl1ght3r/fl1ght3r.4fan.cz/web/acars/errors/error.log");					// Folder and filename where the error log is located
                                                                               
/*
 * Error messages */
@define ("ERROR_OPENING_REPORT_FILE","Error opening report file");
@define ("ERROR_WRITING_REPORT_FILE","Error writing report file");
@define ("PILOT_NOT_FOUND","Pilot not found");
@define ("ERROR_IN_PILOT_QUERY","Pilot query error");
@define ("ERROR_INSERTING_PIREP","Error inserting report");



function CheckFSAcarsInfo() {   
	// Verify input
	if (!isset($_GET['pilot'])) { return 0; }
	
	// Request is not empty
	return 1;
}

function GetFSAcarsInfo() {
	/* ************************************************************************************************
	   @GetFSAcarsInfo
	   Receives inputs sent by FSAcars program and returns an array containing that information
	
	   Inputs: N/A
	   Outputs: string array 
	   ************************************************************************************************ */
	
	// DO NOT EDIT THIS FUNCTION - THIS FIELDS ARE SENT BY FSACARS
	$fsacars_pirep = array (
		"pilot" => $_GET['pilot'],
		"date" => $_GET['date'],
		"time" => $_GET['time'],
		"callsign" => $_GET['callsign'],
		"reg" => $_GET['reg'],
		"origin" => $_GET['origin'],
		"dest" => $_GET['dest'],
		"equipment" => $_GET['equipment'],
		"fuel" => $_GET['fuel'],
		"duration" => $_GET['duration'],
		"distance" => $_GET['distance'],
		"rep_url" => "Dummy",
		"more" => $_GET['more'],
		"fsacars_log" => $_GET['log']	// Get complete FSAcars log
	);
	
	/* DEBUG CODE - Write request to log file
	*/
	$fe = fopen (ERROR_LOG_PATH, "a");
	fwrite($fe, "[DEBUG ".date("d.m.y H:i:s")."] PILOT: ".$_GET['pilot']." DATE: ".$_GET['date']." TIME: ".$_GET['time']." CALLSIGN: ".$_GET['callsign']." REG: ".$_GET['reg']." ORIG: ".$_GET['origin']." DEST: ".$_GET['dest']." EQUIP: ".$_GET['equipment']." FUEL: ".$_GET['fuel']." DURATION: ".$_GET['duration']." DIST: ".$_GET['distance']." MORE: ".$_GET['more']." LOG: ".$_GET['log']."\n");
	fclose($fe);
	
	return $fsacars_pirep;
}

function SavePIREPFile($pirep_array) {
	/* ************************************************************************************************
	   @SavePIREPFile
	   Receives a string array with FSAcars pireps and creates or appends information to pirep file
	
	   Inputs: string array
	   Outputs: 1 sucess, 0 error
	   ************************************************************************************************ */
	
	/* Build report filename and URL */
	$filename=$pirep_array['pilot'].str_replace("/","",$pirep_array['date']).str_replace(":","",$pirep_array['time']).".txt";
	$pirep_array['rep_url']=REPORT_FILE_URL.$pirep_array['pilot']."/".$filename;
	
	/* Parse FsAcars log */
	$fsacars_log_lines_array = explode("*",$pirep_array['fsacars_log']);

	/* Create or Append FSAcars report file */
	$fp = fopen (REPORT_FILE_PATH."/".$pirep_array['pilot']."/".$filename, "a");
	if (!$fp) {
		/* Error opening file */
		$fe = fopen (ERROR_LOG_PATH, "a");
		fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] PILOT: ".$pirep_array['pilot']." - ".ERROR_OPENING_REPORT_FILE." - ".$filename."\n");
		fclose($fe);
		
		return 0;
	}

	/*
	* Write all log lines received from FSAcars */
	for($i=0;$i<count($fsacars_log_lines_array);$i++) {
    		if (!fwrite($fp, $fsacars_log_lines_array[$i] . "\n")) {
        		/* Error writing to file */
        		$fe = fopen (ERROR_LOG_PATH, "a");
			fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] PILOT".$pirep_array['pilot']." - ".ERROR_WRITING_REPORT_FILE." - ".$filename."\n");
			fclose($fe);
        		
        		return 0;
    		}
	}    

	/* Close file */
	fclose($fp);
	
	return 1;
}

function InsertReportIntoDB($pirep_array) {
	/* ************************************************************************************************
	   @InsertReportIntoDB
	   Receives a string array with FSAcars pireps and inserts summary into reports table
	
	   Inputs: string array
	   Outputs: 1 sucess, 0 error
	   ************************************************************************************************ */

	/* If this is the first chunk insert PIREP on database */
	if ($pirep_array['more']=="0") {
    		/* connect to database */
    		include(MYSQL_CONNECT_INCLUDE);

    		/*
    		 * Verify pilot identity (From VA Pilots table) */
    		$the_pilot = $pirep_array['pilot'];

    		$stmt = "select pilot_id from pilots where pilot_num='$the_pilot'";
    		$result = mysql_query($stmt);
    		
    		/* mysql error */
    		if (!$result) {
    			$fe = fopen (ERROR_LOG_PATH, "a");
			fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".ERROR_IN_PILOT_QUERY." - Pilot ".$pirep_array['pilot']." - ".mysql_error()." SQL: ".$stmt."\n");
			fclose($fe);
			
			return 0;
    		}
    		
    		if (mysql_num_rows($result) == 0) {
       			/* Pilot not found */
       			$fe = fopen (ERROR_LOG_PATH, "a");
			fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".PILOT_NOT_FOUND." - Pilot ".$pirep_array['pilot']."\n");
			fclose($fe);
			
			return 0;
    		} else {
          			/* Pilot found */
          			$pilot_id = mysql_result($result,0,"pilot_id");

          			/* Insert info on reports table */
          			$values = $pilot_id.",'".$pirep_array['date']."','".$pirep_array['time']."','".$pirep_array['callsign']."','".$pirep_array['origin']."','".$pirep_array['dest']."','".$pirep_array['reg']."','".$pirep_array['equipment']."','".$pirep_array['duration']."',".$pirep_array['fuel'].",".$pirep_array['distance'].",'".$pirep_array['rep_url']."'";
          			$stmt = "INSERT INTO reports (pilot_id,date,time,callsign,origin_id,destination_id,registration,equipment,duration,fuel,distance,fsacars_rep_url) VALUES ($values)";          			
          			$result = mysql_query($stmt);
    
          			if (!$result) {
    					$fe = fopen (ERROR_LOG_PATH, "a");
					fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".ERROR_INSERTING_PIREP." - Pilot ".$pirep_array['pilot']." - ".mysql_error()." SQL: ".$stmt."\n");
					fclose($fe);
			
					return 0;
    				}
                             
          			/* Close the database connection */
          			mysql_close();
    		}
    	}
    	
    	return 1;
}

function main() {
	/* ************************************************************************************************
	   @main
	   
	   Inputs: N/A
	   Outputs: "OK" sucess, "NOTOK" error
	   ************************************************************************************************ */
	$res = CheckFSAcarsInfo();
	if ($res == 0) {
		return "NOTOK";
	}
	
	$a = GetFSAcarsInfo();
	
	$res = SavePIREPFile(&$a);
	if ($res == 0) {
		return "NOTOK";
	}
	
	$res = InsertReportIntoDB($a);
	if ($res == 0) {
		return "NOTOK";
	}
	
	// Report sucessfully received
	return "OK";
}

/* receive_pirep.php return to FSACARS */
$out = main();
echo $out;

?>

#17 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 14:36:25

No ono se to odešle v pořádku, ale ten program kontroluje odeslaní podle toho výpisu z webu, očekává to 1|Pirep accepted, a místo toho tam je Neodymové magnety a bůh ví co ještě, a pak za tim 1|pirep accepted. A vyhodnotí to jako chybu. A uživateli toho programu napíše chybu...

#18 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 12:20:37

Nebo ještě jedna věc. jak bude znít ta adresa té složky ?  fl1ght3r.4fan.cz/acars/reports

Do téhle složky chci aby se data ukládala. mám /home/users/fl1ght3r/fl1ght3r.4fan.cz/web/reports je to dobře ?

#19 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-24 11:47:45

<?php

/**
 * PIREP Service for XAcars
 *
 */


// ----------------------------------------------------------------------------
// In functions.php the database is connected as used to
require("db.inc.php");

// ----------------------------------------------------------------------------
// General Constants

define("ACARS_UNKNOWN",     0);
define("ACARS_XACARS",      3);
define("ACARS_XACARS_MSFS", 4);
define("ONLINE_VATSIM",     1);
define("ONLINE_IVAO",       2);
define("ONLINE_FPI",        3);
define("ONLINE_OTHER",      0);


// ----------------------------------------------------------------------------
// PIREP Class

Class acarsPirep
{
    var $pirepID       = 0;
    var $timeReport    = 0;
    var $acarsID       = ACARS_UNKNOWN;
    var $userID        = 0;
    var $flightRot     = 0;
    var $acICAO        = '';
    var $flightType    = 'IFR';
    var $departure     = '';
    var $destination   = '';
    var $alternate     = '';

    var $depTime       = '00:00';
    var $blockTime     = 0;
    var $blockFuel     = 0;
    var $flightTime    = 0;
    var $flightFuel    = 0;

    var $cruise        = 0;
    var $pax           = 0;
    var $cargo         = 0;
    var $online        = 0;
    var $message       = '';
            
    function doInsert()
    {
        $sql  = 'INSERT INTO acars_pirep (timereport, acarsid, iduser, flightrot, acicao, 
                    flighttype, departure, destination, alternate, deptime, blocktime, blockfuel, flighttime,
                    flightfuel, cruise, pax, cargo, online, message) VALUES ( ' 
              . $this->timeReport . ', '
              . $this->acarsID . ', '
              . $this->userID . ', '        
              . "'{$this->flightRot}', "
              . "'{$this->acICAO}', "
              . "'{$this->flightType}', "
              . "'{$this->departure}', "
              . "'{$this->destination}', "
              . "'{$this->alternate}', "
              . $this->depTime . ', '
              . $this->blockTime . ', '
              . $this->blockFuel . ', '
              . $this->flightTime . ', '
              . $this->flightFuel . ', '
              . $this->cruise . ', '
              . $this->pax . ', '
              . $this->cargo . ', '
              . $this->online . ', '
              . "'{$this->message}');";
              
        if(!mysql_query($sql))
            die('0|SQL query failed (INSERT acars pirep)   ' . $sql);
        
        $this->pirepID = mysql_insert_id();
                              
        return 1;
    }
            
}

// ----------------------------------------------------------------------------
// Functions

function testUserLogin($pid, $pw)
{
    $q_user = @mysql_query("SELECT id FROM user WHERE isactive=1 and username = '$pid' and password = '$pw' LIMIT 1");
    if(@mysql_num_rows($q_user) <= 0)
    {
      return -1;
    }
    else
    {
      $user = @mysql_fetch_array($q_user); 
      return $user['id'];
    }
}

function CheckXAcarsVersion($DATA1)
{
    if( (strcmp($DATA1, "XACARS|1.0")==0)
        || (strcmp($DATA1, "XACARS|1.1")==0)
        || (strcmp($DATA1, "XACARS|2.0")==0)        
        || (strcmp($DATA1, "XACARS|2.5")==0) 
        || (strcmp($DATA1, "XACARS|3.0")==0) )        
        return ACARS_XACARS;
    elseif( (strcmp($DATA1, "XACARS_MSFS|1.0")==0)
        || (strcmp($DATA1, "XACARS_MSFS|1.1")==0)
        || (strcmp($DATA1, "XACARS_MSFS|2.0")==0)        
        || (strcmp($DATA1, "XACARS_MSFS|2.5")==0) 
        || (strcmp($DATA1, "XACARS_MSFS|3.0")==0) ) 
        return ACARS_XACARS_MSFS;
    else
        return ACARS_UNKNOWN;
}

Function data2Int( $data, $default )
{
    if( !empty($data) || (isset($data) && $data == '0') )
        return( (integer)$data );
    else
        return $default;
}

Function data2Str( $data, $default, $allowTags, $stripSql = True )
{
    if( !empty($data) )
    {
        if( $stripSql == True)
            $str = mysqlclean($data, -1);
        else
            $str = $data;
            
        if( $allowTags == True )
            return( strip_tags($str, ALLOWABLE_TAGS) );
        else
            return( strip_tags($str) );
    }
    else
        return $default;
}

Function time2min( $time )
{
    if( !empty($time) )
        return( substr($time,0,2)*60 + substr($time,3,2) );
    else
        return 0;
}

Function lbs2kg( $lbs )
{
    return( $lbs / 2.204622915 );
}

// ----------------------------------------------------------------------------
// Decoding ACARS Message

if (!isset($_REQUEST['DATA1'])) die('0|Invalid Data1');
if (!isset($_REQUEST['DATA2'])) die('0|Invalid Data2');

if (($version  = CheckXAcarsVersion($_REQUEST['DATA1'])) <= 0)
    die('0|ERROR: Unknown XAcars version!');

$data2 = $_REQUEST['DATA2'];
$data = split("~", $data2);

$uid = testUserLogin($data[0], $data[1]);
if( $uid == -1 )
    die('0|ERROR: Invalid login!');    

// ----------------------------------------------------------------------------
// Parameterlist:
// DATA1=XACARS|1.0&DATA2=username~password~flightnumber~aircrafticao~altitudeorFL~flightrules~depicao~desticao~alticao~deptime(dd.mm.yyyy hh:mm)~blocktime(hh:mm)~flighttime(hh:mm)~blockfuel~flightfuel~pax~cargo~online(VATSIM|ICAO|FPI|[other])

$pirep = new acarsPirep();
$pirep->timeReport    = time();
$pirep->acarsID       = $version;
$pirep->userID        = $uid;
$pirep->flightRot     = $data[2];
$pirep->acICAO        = $data[3];
$pirep->flightType    = $data[5];

$pirep->departure     = substr($data[6], 0,4);
$pirep->destination   = substr($data[7], 0,4);
$pirep->alternate     = substr($data[8], 0,4);

// Reading timestamp "25.02.2006 12:18"
$pirep->depTime       = strtotime( substr($data[9],3,2) . '/' . substr($data[9],0,2) . '/' . substr($data[9],6));
$pirep->blockTime     = time2min($data[10]);
$pirep->blockFuel     = lbs2kg(data2Int($data[12],0));
$pirep->flightTime    = time2min($data[11]);
$pirep->flightFuel    = lbs2kg(data2Int($data[13],0));

if( $data[4] <> '' )
    $pirep->cruise    = data2Int(substr($data[4],2),0) * 100;
$pirep->pax           = data2Int($data[14],0);
$pirep->cargo         = lbs2kg(data2Int($data[15],0));

if( strtoupper($data[16]) == 'VATSIM' )
   $pirep->online        = ONLINE_VATSIM;
else if( strtoupper($data[16]) == 'IVAO' ) 
   $pirep->online        = ONLINE_IVAO;
else if( strtoupper($data[16]) == 'FPI' ) 
   $pirep->online        = ONLINE_FPI;
else  
   $pirep->online        = ONLINE_OTHER;

$rc = $pirep->doInsert();

if ($rc)
  echo "1|PIREP ACCEPTED";
else echo "0|ERROR";

?>


A v programu se zobrazí chyba a znění chyby je 1|PIREP ACCEPTED a text reklamy

PIREP se sice odeslal ale program hází chybu

#20 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-23 19:48:56

Udělal jsem, nepomohlo :-(

Už asi vím čím to je, ono se to uploaduje přes php soubor který je na ftp. Ale do toho ftp se vloží reklama :-(.
A on to pak přečte chybně.

Zkoušel jsem to s jiným programem a ten to odeslal, a vyskočila chyba a ve znění té chyby bylo : Neodymové magnety,......)

Dá se to nějak obejít ?

#21 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-23 17:44:47

username, pass mám dobře...


a tomu druhému nerozumím...pls napiš postup:-)

#22 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-22 21:31:00

To budou jen jakoby odletěné lety ;-) zobrazené např v google earth.

Ten connect:

mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
mysql_select_db($dbName) or die("Unable to select database $dbName");


   @define ("REPORT_FILE_PATH", "fl1ght3r.4fan.cz/web/ACARS/reports/");
   @define ("ERROR_LOG_PATH", "fl1ght3r.4fan.cz/web/ACARS/errors/");
       tady do těch dvou, se budou ukládat soubory.

#23 Re: Ostatní problémy » Problem nejspis s databází » 2010-10-22 20:40:59

Zdravím,
Mám problém s jedním programem na reportování letů z Flight Simulátoru.

Píše to: ERROR Sending log Data base error.

@define ("MYSQL_CONNECT_INCLUDE", "connect_db.php");
@define ("REPORT_FILE_URL", "http://www.fl1ght3r.4fan.cz/ACARS");
@define ("REPORT_FILE_PATH", "fl1ght3r.4fan.cz/web/ACARS/reports/");
@define ("ERROR_LOG_PATH", "fl1ght3r.4fan.cz/web/ACARS/errors/");

v connect_db.php  je:

$hostName = "localhost";
$userName = "fsacars";
$password = "*****";
$dbName = "acars";

Je to správně ?

Zápatí

Založeno na FluxBB | CZ a SK