IGCflying | Geschützer Bereich
Datei wird weder gespeichert, noch eingetragen.
<?php include ('menu.php'); ?>
<!DOCTYPE html>
<html>
<head>
<style>
    #upload {
    width: 100%;
    text-align: center;
    border-bottom: thin inset #E3E3E0;
    }
    
    #php {
    width: 50%;
    height: 100%;
    overflow: scroll;
    float: left;
    border-right: thin inset #E3E3E0;
    }
    
    #print {
    float: left;
    width: 49%;
    height: 100%;
    overflow: scroll;
    }
    
</style>
<meta name="author" content="Janik Scheuring">
<meta name="description" content="Lade deine igc-Datei hoch, um zu sehen welche Daten ausgelesen werden.">
<title>IGCflying | Geschützer Bereich</title>
</head>
<body>
<div id="upload">
<form id="upload" action="private.php" method="POST" enctype="multipart/form-data">
    <label for="fileselect">Datei auswählen [Dateiname.igc]:</label>
    <input name="datei" type="file" id="fileselect" required="required" title="Bitte eine igc Datei auswählen"/>
    <button name="submit" id="sbutton" type="submit">Hochladen</button>
    Datei wird weder gespeichert, noch eingetragen.
</form>
</div>

<div id="php">
<?php
 highlight_file('private.php'); 
?>
</div>

<div id="print">
<?php

    $extension = pathinfo($_FILES['datei']['name']);

    //check extension
    if (isset($_POST['submit']) and strtolower($extension['extension']) != 'igc') {
         exit("<p>Falsche Datei :(</p>");
    }

    if (is_uploaded_file($_FILES['datei']['tmp_name'])) {
    
    //count time
    $beginn = microtime(true); 

    //Time as UTC 
    date_default_timezone_set('UTC');

    $file = file_get_contents($_FILES['datei']['tmp_name'])
            or die ("<p>Datei konnte nicht gelesen werden :(</p>");
            
            
    //Line to array
    $zeile = explode("\n", $file);

/*    H-Record
*****************************************************************************************************/

    //HFDTE
    $HFDTE = array_values(preg_grep("/HFDTE/", $zeile));
    //Umkonvertieren in das SQL Format JJMMTT
    $date = substr($HFDTE[0], 9, 2).substr($HFDTE[0],7,2).substr($HFDTE[0],5,2);

    //HFPLT        Name of the competing pilot
    $HFPLT = array_values(preg_grep("/PILOT/", $zeile));
    $raw_pilot = explode(":",$HFPLT[0]);
    //trim entfernt leerzeichen am Anfang und Ende. Wichtig für die spätere SQL Suche
    $pilot = trim($raw_pilot[1]);
     
    //HFCM2        Name of the second pilot in a two-seater
    $HFCM2 = array_values(preg_grep("/HFCM2/", $zeile));
    $raw_pilot2 = explode(":",$HFCM2[0]);
    $second_pilot = trim($raw_pilot2[1]);

    //HFGTY        Free-text name of the glider model
    $HFGTY = array_values(preg_grep("/GLIDERTYPE/", $zeile));
    $raw_glidertype = explode(":",$HFGTY[0]);
    $model = trim($raw_glidertype[1]);

    //HFRFW        free-text string descibing the firmware revision of the logger
    $HFRFW = array_values(preg_grep("/HFRFW/", $zeile));
    $raw_firmware = explode(":",$HFRFW[0]);    
    $firmware = trim($raw_firmware[1]);                    

    //HFRHW        free-text string giving the hardware revision number of the logger
    $HFRHW = array_values(preg_grep("/HFRHW/", $zeile));                     
    $raw_harware = explode(":",$HFRHW[0]);
    $hardware = trim($raw_harware[1]);
    
    //HFFTY        Logger free-text manufacturer and model
    $HFFTY = array_values(preg_grep("/HFFTY/", $zeile)); 
    $raw_manufacture = explode(":",$HFFTY[0]);
    $manufacturer = trim($raw_manufacture[1]);

    //HFGPS        Manufacturer and model of the GPS receiver used in the logger
    $HFGPS = array_values(preg_grep("/HFGPS/", $zeile)); 
    $raw_gpsrev = explode(":",$HFGPS[0]);
    $receiver = trim($raw_gpsrev[1]);
  
    //HFCCL        Any free-text description of the class this glider is in
    $HFCCL = array_values(preg_grep("/HFCCL/", $zeile)); 
    if (empty($HFCCL[0])) {
    $HFCCL = array_values(preg_grep("/HOCCL/", $zeile)); 
    }
    $raw_class = explode(":",$HFCCL[0]);
    $glider_class = trim($raw_class[1]);
    
    
/*    B-Record
*****************************************************************************************************/
    $B = preg_grep("/B/", $zeile);
    $line = array_values($B);

    for ($e=0, $e2=1; $e < count($line); $e++, $e2++) {

        //delete equal lines
        if (substr($line[$e], 7) == substr($line[$e2], 7)) {
            unset($line[$e]);
        }
        //only B lines
        if (substr($line[$e], 0, 1) != 'B') {
            unset($line[$e]);
        }
        //delete equal time
        if (substr($line[$e],1, 6) == substr($line[$e2],1, 6)) {
            unset($line[$e]);
        }
        //delete line whit large timediff -> avoid vario heandling mistake 
        if(strtotime(substr($line[$e2],1, 6))-strtotime(substr($line[$e],1, 6)) > 5) {
            unset($line[$e]);
        }
        //lines with content
        if (!empty($line[$e])) {
            $b[] = $line[$e];
        }    
    
    }
    
    /* reset array count */
    array_values($b);


    for ($f=0; $f < count($b); $f++) {
        
        //time
        $time[] = substr($b[$f],1, 6);
        //lat
        $latitude = substr($b[$f],7,8); 
        $latDD = substr($latitude,0,2);
        $latMMmmm = substr($latitude,2,2).'.'.substr($latitude,4,3);
        $NS = substr($latitude,7,1);
        if ($NS == 'N') {
        $lat[] = ($latMMmmm/60)+$latDD;
        }
        else {
        $lat[] = -(($latMMmmm/60)+$latDD);
        }
    
        //lng
        $longitude = substr($b[$f],15, 9);
        $longDDD = substr($longitude,0,3);
        $longMMmmm = substr($longitude,3,2).'.'.substr($longitude,5,3);
        $EW = substr($longitude,8,1);
        if ($EW == 'E') {
        $lng[] = ($longMMmmm/60)+$longDDD;
        }
        else {
        $lng[] = -(($longMMmmm/60)+$longDDD);     
        }
    
        //Altitude
        $press_alt[] = substr($b[$f], 25, 5);
        $gnss_alt[] = substr($b[$f], 30, 5);
    
}

    for ($i=0, $i2=1; $i < count($b); $i++, $i2++) {
        //Distance Haversine formula [km]
        $km[$i2] = 2*6371*asin(sqrt(sin((deg2rad($lat[$i2]-$lat[$i]))/2)*sin((deg2rad($lat[$i2]-$lat[$i]))/2)+
                    cos(deg2rad($lat[$i]))*cos(deg2rad($lat[$i2]))*sin((deg2rad($lng[$i2]-$lng[$i]))/2)*sin((deg2rad($lng[$i2]-$lng[$i]))/2)));
                
        //Time diff [s]
        $time_diff[$i2] = strtotime($time[$i2])-strtotime($time[$i]);
        
            //rise. Calculate with press data when set [m]
            if (!empty($p_alt)) {
                $rise[$i2] = $press_alt[$i2] - $press_alt[$i];
                }
                else {
                $rise[$i2] = $gnss_alt[$i2] - $gnss_alt[$i];
                }
        
        //speed [km/h]
        $speed[$i2] = round(($km[$i2]/($time_diff[$i2]/3600)),2);
        
        //rise [m/s]
        $rise_per_second[$i2] = round($rise[$i2]/$time_diff[$i2], 2);    
            
            //Start wen schneller als Schrittgeschwindigkeit
            if($speed[$i] > 3.6) {
                $start[] = $i;
                $d[] = round($km[$i-1],2);
            }

    }
    
        $s = $start[0];
        $count = count($start);
        $stop = end($start) + 1;
        

    $air_time = date("His", strtotime($time[$stop-1]) - strtotime($time[$s]));
    $avg_speed = round(array_sum($speed)/$count, 2);
    $distance = round(array_sum($d),2);

/*    Place. Hidden to save paragliding365 server
*****************************************************************************************************/

/*        $xml = 'http://www.paragliding365.com/xml_paragliding365.html?devid=[devID]&longitude='.$lng[1].'&latitude='.$lat[1].'';

          $place = @simplexml_load_file($xml) or
          die ("Fehler beim finden des Flugortes :(\n");

        $continent = $place->flightareas->flightarea->continent;
        $country = $place->flightareas->flightarea->country;
        $state = $place->flightareas->flightarea->state;
        $iso = $place->flightareas->flightarea->iso;
        $name = $place->flightareas->flightarea->name;
        $location = $place->flightareas->flightarea->location;
*/

/*    Print instead of SQL INSERT
*****************************************************************************************************/

    echo "<p>";

    echo "Datum[jjmmtt]: ".$date."<br>";
    echo "Pilot: ".$pilot."<br>";
    echo "Modell: ".$model."<br>";
    echo "Pilot 2: ".$second_pilot."<br>";
    echo "firmware: ".$firmware."<br>";
    echo "hardware: ".$hardware."<br>";
    echo "Hersteller: ".$manufacturer."<br>";
    echo "receiver: ".$receiver."<br>";
    echo "Fluggerät: ".$glider_class."<br>";
    echo "Strecke: ".round($distance,2)." km<br>";
    echo "Flugzeit[hhmmss]: ".$air_time."<br>";
    echo "Durchschnittsgeschwindigkeit: ".$avg_speed." km/h<br>";
    
    echo "<br>Zeile"." | Zeit[hhmmss in UTC] | Zeitdif.[s] | speed[km/h] | Breitengrad | Längengrad |  | Höhe Lufddruck | Höhe GPS | Strecke[km]<br>";
    
    for ($s; $s < $stop; $s++) {
        
        echo $s." | ".$time[$s]." | ".$time_diff[$s]." | ".$speed[$s]." | ".$lat[$s]." | ".$lng[$s]." | ".$press_alt[$s]." | ".$gnss_alt[$s]." | ".round($km[$s],2)."<br>";

    }
    echo $test;
    $dauer = microtime(true) - $beginn; 
    echo "<br>Verarbeitung in: $dauer Sekunden";
    
    echo "</p>";
    }
?>
</div>

</body>
</html>