$flightPhotos->computeGeoInfo();
    $imagesHtml = "";
    foreach ($flightPhotos->photos as $photoNum => $photoInfo) {
        if ($photoInfo['lat'] && $photoInfo['lon']) {
            $imgIconRel = $flightPhotos->getPhotoRelPath($photoNum) . ".icon.jpg";
            $imgBigRel = $flightPhotos->getPhotoRelPath($photoNum);
            $imgIcon = $flightPhotos->getPhotoAbsPath($photoNum) . ".icon.jpg";
            $imgBig = $flightPhotos->getPhotoAbsPath($photoNum);
            if (file_exists($imgBig)) {
                list($width, $height, $type, $attr) = getimagesize($imgBig);
                list($width, $height) = CLimage::getJPG_NewSize($CONF['photos']['mid']['max_width'], $CONF['photos']['mid']['max_height'], $width, $height);
                $imgTarget = $imgBigRel;
            } else {
                if (file_exists($imgIcon)) {
                    list($width, $height, $type, $attr) = getimagesize($imgIcon);
                    list($width, $height) = CLimage::getJPG_NewSize($CONF['photos']['mid']['max_width'], $CONF['photos']['mid']['max_height'], $width, $height);
                    $imgTarget = $imgIconRel;
                }
            }
            echo " \tdrawPhoto(" . $photoInfo['lat'] . "," . $photoInfo['lon'] . ",{$photoNum},'{$imgIconRel}','{$imgTarget}',{$width},{$height}); \n";
        }
    }
}
?>
	
	<?php 
if ($CONF_airspaceChecks && (L_auth::isAdmin($userID) || $flight->belongsToUser($userID))) {
    ?>
	 // $("#airspaceShow").attr('checked', true);
	  // $("#airspaceShow").trigger('click');
	 // $("#airspaceShow").click();
Пример #2
0
	function computeGeoInfo() {
	
		$changed=0;
		$gotTrack=0;
		foreach ( $this->photos as $photoNum=>$photoInfo) {
			if ($photoInfo['tm']==1) { // 1 -> we have alredy tried to get geotag info but failed
				continue;
			}
			
			if (!$photoInfo['tm']) { // no attemp was made to get GeoInfo
				$imgPath=$this->getPhotoAbsPath($photoNum);
				$gpsData = CLimage::getGPS($imgPath);
				$this->photos[$photoNum]['lat']=$gpsData[0];
				$this->photos[$photoNum]['lon']=$gpsData[1];
				$this->photos[$photoNum]['tm']=$gpsData[2]; // warning tm in local time ...
				$changed=1; // we got at least the tm				
			}
			
			if (!$this->photos[$photoNum]['tm']) { 
				$this->photos[$photoNum]['tm']=1;
				$changed=1;
				continue;
			}
			
			if (!$this->photos[$photoNum]['lat'] && !$this->photos[$photoNum]['lon']) {
				// try to get lat/lon depending on the position in track	
				if (!$gotTrack) {
					//echo "getting track!";	
					$flight=new flight();
					$flight->getFlightFromDB($this->flightID,0); //dont update takeoffs
					list($trackLat,$trackLon,$trackTms,$trackAlt)=$flight->getXYValues(1,1); // get also TM and ALT
					$gotTrack=1;
				}
				
				//correct the tm of the photo that we got from EXIF by subtracking up the timezone offset
				$this->photos[$photoNum]['tm']-=$flight->timezone*3600;
				
				//we will use this to add to every time entry we gto from getXYValues()
				$startTm=strtotime($flight->DATE);
				//echo "Flight start time is ".$flight->DATE." -> ".$startTm;

				$lastTm=$startTm;
				$photoTm=$this->photos[$photoNum]['tm'];
				
				//echo " starttime:$lastTm  photo : $photoTm<BR>".count($trackTms);
				foreach($trackTms as $i=>$tm) {
					$thisTm=$startTm+$tm;
					if ( $photoTm<$thisTm && $photoTm>$lastTm ) {
					
						//echo "found position!!! tm=$thisTm<BR>";
						$this->photos[$photoNum]['lat']=$trackLat[$i];
						$this->photos[$photoNum]['lon']=-$trackLon[$i];
						$this->photos[$photoNum]['alt']=$trackAlt[$i];
						$changed=1;
						break;
					}				
				}				
				
			}
			
			
		}		
		
		if ($changed) {
			$this->putToDB(0); // dont update the flights table
		}
	}
         $flight->private = 0;
     }
     for ($i = 1; $i <= $CONF_photosPerFlight; $i++) {
         $var_name = "photo" . $i . "Filename";
         if ($_REQUEST["photo" . $i . "Delete"] == "1") {
             // DELETE photo
             $flight->deletePhoto($i);
         } else {
             if ($_FILES[$var_name]['name']) {
                 // upload new
                 $flight->deletePhoto($i);
                 //first delete old
                 $flight->{$var_name} = $_FILES[$var_name]['name'];
                 if (move_uploaded_file($_FILES[$var_name]['tmp_name'], $flight->getPhotoFilename($i))) {
                     CLimage::resizeJPG($CONF['photos']['thumbs']['max_width'], $CONF['photos']['thumbs']['max_height'], $flight->getPhotoFilename($i), $flight->getPhotoFilename($i) . ".icon.jpg", $CONF['photos']['compression']);
                     CLimage::resizeJPG($CONF['photos']['normal']['max_width'], $CONF['photos']['normal']['max_height'], $flight->getPhotoFilename($i), $flight->getPhotoFilename($i), $CONF['photos']['compression']);
                 } else {
                     //upload not successfull
                     $flight->{$var_name} = "";
                 }
             }
         }
     }
     $flight->putFlightToDB(1);
     open_inner_table(_CHANGE_FLIGHT_DATA, 650);
     echo "<center> <br><br>" . _THE_CHANGES_HAVE_BEEN_APPLIED . "<br><br><br>";
     echo "<a href='" . getLeonardoLink(array('op' => 'show_flight', 'flightID' => $flightID)) . "'>" . _RETURN_TO_FLIGHT . "</a><br><br><br>";
     echo "</center>";
     close_inner_table();
 } else {
     // show the form
Пример #4
0
    function kmlGetTrack($lineColor = "ff0000", $exaggeration = 1, $lineWidth = 2, $extended = 1)
    {
        global $takeoffRadious, $landingRadious;
        global $moduleRelPath, $baseInstallationPath;
        global $langEncodings, $currentlang;
        $getFlightKML = $this->getFlightKML() . "&c={$lineColor}&w={$lineWidth}&an={$extended}";
        // do some basic check for saned igc file
        if (!$this->checkSanedFiles()) {
            return "";
        }
        if ($extended == 1) {
            //$kml_file_contents.="<Placemark >\n<name>".$this->filename."</name>";
            // $kml_file_contents.=$this->kmlGetDescription($extended,$getFlightKML);
            //$kml_file_contents.="</Placemark>";
            require_once dirname(__FILE__) . "/FN_kml.php";
            kmlGetTrackAnalysis($this->getKMLFilename(1), $this->getIGCFilename(2), 1);
            $kml_file_contents = "\n<NetworkLink>\n  <name>Extended analysis</name>\n  <visibility>1</visibility>\n  <open>1</open>\n  <description> Extra analysis generation by  Man\\'s GPS2GE V2.0 (http://www.parawing.net)</description>\n  <refreshVisibility>0</refreshVisibility>\n  <flyToView>0</flyToView>\n  <Link>\n\t<href>http://" . $_SERVER['SERVER_NAME'] . "/{$baseInstallationPath}/" . $this->getKMLRelPath(1) . "</href>\n  </Link>\n</NetworkLink>";
            return $kml_file_contents;
        }
        $KMLlineColor = "ff" . substr($lineColor, 4, 2) . substr($lineColor, 2, 2) . substr($lineColor, 0, 2);
        $kmzFile = $this->getKMLFilename(0);
        $kmlTempFile = $kmzFile . ".tmp.kml";
        // DEBUG MANOLIS force creation
        if (!file_exists($kmzFile)) {
            // create the kmz file containg the points only
            $filename = $this->getIGCFilename(2);
            $lines = file($filename);
            if ($lines) {
                $i = 0;
                /*
                new ge features
                
                http://googlegeodevelopers.blogspot.com/2010/07/making-tracks-new-kml-extensions-in.html
                http://google-latlong.blogspot.com/2010/06/relive-your-hiking-biking-and-other.html
                
                ****** !!!! ****
                http://code.google.com/intl/el-GR/apis/kml/documentation/kmlreference.html#trackexample
                
                http://sketchup.google.com/3dwarehouse/cldetails?mid=c166a0a48065f4403a426bad1ca64772&ct=mdcc&prevstart=0
                */
                $str = '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
 xmlns:gx="http://www.google.com/kml/ext/2.2">
 ';
                $str .= "<Document>\n\t\t<name>Tracklog File</name>\n\t\t<Schema id=\"schema\">\n\t\t  <gx:SimpleArrayField name=\"Climb\" type=\"float\">\n\t\t\t  <displayName>CLimb (m/s)</displayName>\n\t\t  </gx:SimpleArrayField>\n\t\t</Schema>";
                $strXXX .= '<!-- Normal multiTrack style -->
    <Style id="Track_n">
      <LineStyle>
			<color>ff0000ff</color>
			<width>2</width>
      </LineStyle>
      <IconStyle>
        <Icon>
          <href>http://earth.google.com/images/kml-icons/track-directional/track-0.png</href>
        </Icon>
      </IconStyle>
    </Style>
<!-- Highlighted multiTrack style -->
    <Style id="Track_h">
      <LineStyle>
			<color>ff0000ff</color>
			<width>1</width>
      </LineStyle>
      <IconStyle>
        <scale>1.2</scale>
        <Icon>
          <href>http://earth.google.com/images/kml-icons/track-directional/track-0.png</href>
        </Icon>
      </IconStyle>
    </Style>
	
    <StyleMap id="TrackStyle">
      <Pair>
        <key>normal</key>
        <styleUrl>#Track_n</styleUrl>
      </Pair>
      <Pair>
        <key>highlight</key>
        <styleUrl>#Track_h</styleUrl>
      </Pair>
    </StyleMap>
	
	';
                $str .= "<Placemark id='timeTrack'>\n\t\t\t\t\t<name>Tracklog</name>\n\t\t\t\t\t    <Style id='Track1'>\n      <LineStyle>\n\t\t\t<color>ff0000ff</color>\n\t\t\t<width>2</width>\n      </LineStyle>\n      <IconStyle>\n        <Icon>\n          <href>http://earth.google.com/images/kml-icons/track-directional/track-0.png</href>\n        </Icon>\n      </IconStyle>\n    </Style>";
                $str .= "<gx:MultiTrack id=\"MultiTrack\">\n\t\t\t\t<gx:Track>\t\t\t\t\t\n\t\t\t\t<altitudeMode>absolute</altitudeMode>\n\n";
                //$kml_file_contents=str_replace("&","&#38;",$kml_file_contents);
                // $kml_file_contents=utf8_encode(str_replace("&nbsp;"," ",$kml_file_contents));
                $str = str_replace("&nbsp;", " ", $str);
                $timeStampStr = '';
                foreach ($lines as $line) {
                    $line = trim($line);
                    if (strlen($line) == 0) {
                        continue;
                    }
                    if ($line[0] == 'B') {
                        if (strlen($line) < 23) {
                            continue;
                        }
                        // also check for bad points
                        // 012345678901234567890123456789
                        // B1522144902558N00848090EV0058400000
                        if ($line[24] == 'V') {
                            continue;
                        }
                        $thisPoint = new gpsPoint($line, $this->timezone);
                        $alt = $thisPoint->getAlt();
                        $lon = -$thisPoint->lon;
                        $lat = $thisPoint->lat;
                        // $data_alt[$i]=$thisPoint->getAlt();
                        if ($alt > $this->maxAllowedHeight) {
                            continue;
                        }
                        // $str.=$lon.",".$lat.",".($alt*$exaggeration)." ";
                        if ($tm0) {
                            $dalt = $alt - $alt0;
                            $dt = $thisPoint->getTime() - $tm0;
                            $climb = sprintf("%.1f", $dalt / $dt);
                            if (abs($climb) > 20) {
                                $climb = 0;
                            }
                        } else {
                            $climb = 0;
                        }
                        $tm0 = $thisPoint->getTime();
                        $alt0 = $alt;
                        $strWhen .= "<when>" . $this->DATE . "T" . sec2Time24h($thisPoint->getTime() % (3600 * 24)) . "Z</when>\n";
                        $strCord .= "<gx:coord>" . sprintf("%.5f", $lon) . " " . sprintf("%.5f", $lat) . " " . round($alt) . "</gx:coord>\n";
                        $strClimb .= "<gx:value>{$climb}</gx:value>\n";
                        $simpleTrackStr .= sprintf("%.5f", $lon) . "," . sprintf("%.5f", $lat) . "," . round($alt) . " ";
                        if ($i % 50 == 0) {
                            $simpleTrackStr .= "\n";
                        }
                        $i++;
                    }
                }
                //$str.="</coordinates>\n</LineString>\n";
                $str .= $strWhen . "\n\n" . $strCord . "<ExtendedData>\n\t\t            <SchemaData schemaUrl=\"#schema\">\n\t\t              <gx:SimpleArrayData name=\"Climb\">\n\t\t\t\t\t\t" . $strClimb . "\n\t\t\t\t\t\t </gx:SimpleArrayData>\n\t\t\t\t\t</SchemaData>\n\t\t\t\t  </ExtendedData>\n\t\t\t\t  ";
                $str .= "\t\n\t\t\t\t\t</gx:Track>\n\t\t\t\t</gx:MultiTrack>\n\t\t\t\t\t\t";
                $str .= "</Placemark>";
                $str .= ' <Placemark id="simpleTrack">
    <name>Simple Track</name>
	 <Style id="Track2">
      <LineStyle>
			<color>ff0000ff</color>
			<width>2</width>
      </LineStyle>
    </Style>
	
	<LineString >
  <extrude>0</extrude>
  <altitudeMode>absolute</altitudeMode> 
  <coordinates>' . $simpleTrackStr . '</coordinates>
</LineString>
</Placemark>';
                $str .= "\n\t\t<Style id='s_camera'>\n\t\t<IconStyle>\n\t\t\t<color>ff00ff00</color>\n\t\t\t<scale>0.8</scale>\n\t\t\t<Icon>\n\t\t\t\t<href>http://maps.google.com/mapfiles/kml/shapes/camera.png</href>\n\t\t\t</Icon>\n\t\t\t<hotSpot x='0.5' y='0' xunits='fraction' yunits='fraction'/>\n\t\t</IconStyle>\n\t\t<ListStyle>\n\t\t</ListStyle>\n\t\t</Style>";
                // now the photos
                if ($this->hasPhotos) {
                    require_once dirname(__FILE__) . "/CL_flightPhotos.php";
                    global $CONF;
                    $flightPhotos = new flightPhotos($this->flightID);
                    $flightPhotos->getFromDB();
                    // get geoinfo
                    $flightPhotos->computeGeoInfo();
                    $imagesHtml = "";
                    foreach ($flightPhotos->photos as $photoNum => $photoInfo) {
                        if ($photoInfo['lat'] && $photoInfo['lon']) {
                            $imgIconRel = $flightPhotos->getPhotoRelPath($photoNum) . ".icon.jpg";
                            $imgBigRel = $flightPhotos->getPhotoRelPath($photoNum);
                            $imgIcon = $flightPhotos->getPhotoAbsPath($photoNum) . ".icon.jpg";
                            $imgBig = $flightPhotos->getPhotoAbsPath($photoNum);
                            if (file_exists($imgBig)) {
                                list($width, $height, $type, $attr) = getimagesize($imgBig);
                                list($width, $height) = CLimage::getJPG_NewSize($CONF['photos']['mid']['max_width'], $CONF['photos']['mid']['max_height'], $width, $height);
                                $imgTarget = $imgBigRel;
                            } else {
                                if (file_exists($imgIcon)) {
                                    list($width, $height, $type, $attr) = getimagesize($imgIcon);
                                    list($width, $height) = CLimage::getJPG_NewSize($CONF['photos']['mid']['max_width'], $CONF['photos']['mid']['max_height'], $width, $height);
                                    $imgTarget = $imgIconRel;
                                }
                            }
                            $imgIconRel = "http://" . $_SERVER['SERVER_NAME'] . $baseInstallationPath . "/" . $imgIconRel;
                            $imgTarget = "http://" . $_SERVER['SERVER_NAME'] . str_replace('//', '/', $baseInstallationPath . "/" . $imgTarget);
                            $altitudeMode = "absolute";
                            if ($photoInfo['alt'] == 0) {
                                $altitudeMode = "clampToGround";
                            }
                            $str .= "\n\t\t\t<Placemark>\n\t\t    <name>Photo</name>\n\t\t\t<styleUrl>#s_camera</styleUrl>\n\t\t\t<Snippet maxLines='0' ></Snippet>\n\t\t\t<description><![CDATA[<a href='{$imgTarget}'><img src='{$imgTarget}' width='" . $CONF['photos']['mid']['max_width'] . "' border='0'></a>\n]]></description>\n\t\t\t<Point>\n\t\t\t\t<altitudeMode>{$altitudeMode}</altitudeMode>  \t    \n\t\t\t\t<coordinates>" . $photoInfo['lon'] . "," . $photoInfo['lat'] . "," . $photoInfo['alt'] . "</coordinates>\n\t\t\t</Point>\n\t\t\t</Placemark>";
                        }
                    }
                }
                $str .= "\n</Document>\n</kml>";
                writeFile($kmlTempFile, $str);
                // zip the file
                require_once dirname(__FILE__) . "/lib/pclzip/pclzip.lib.php";
                $archive = new PclZip($kmzFile);
                $v_list = $archive->create($kmlTempFile, PCLZIP_OPT_REMOVE_ALL_PATH);
                $this->deleteFile($kmlTempFile);
            }
        }
        $getFlightKMLcolorUpdater = $this->getFlightKML() . "&c={$lineColor}&w={$lineWidth}&an={$extended}&updateColor=1";
        $kml_file_contents = '';
        $kml_file_contents .= "\n<NetworkLink>\n  <name>Tracklog</name>\n  <visibility>1</visibility>\n  <open>1</open>\n  <refreshVisibility>1</refreshVisibility>\n  <flyToView>1</flyToView>\n  <Link>\n\t<href>http://" . str_replace('//', '/', $_SERVER['SERVER_NAME'] . "/{$baseInstallationPath}/" . $this->getKMLRelPath(0)) . "</href>\n  </Link>\n</NetworkLink>";
        $kml_file_contents .= "\n<NetworkLink>\n  <name>UpdateColor</name>\n  <Link>\n    <href>" . str_replace("&", "&#38;", $getFlightKMLcolorUpdater) . "</href>\n\t</Link>\n</NetworkLink>\n";
        //echo "## $getFlightKMLcolorUpdater ## ";
        //exit;
        return $kml_file_contents;
    }
Пример #5
0
function addFlightFromFile($filename, $calledFromForm, $userIDstr, $argArray = array())
{
    global $CONF_default_cat_add, $CONF_photosPerFlight, $CONF;
    global $CONF_NAC_list, $CONF_use_NAC, $CONF_use_validation, $CONF_airspaceChecks, $CONF_server_id;
    global $userID, $CONF_new_flights_submit_window;
    global $flightsTable;
    set_time_limit(120);
    global $CONF_server_id;
    list($thisServerID, $userIDforFlight) = splitServerPilotStr($userIDstr);
    if (!$thisServerID) {
        $thisServerID = $CONF_server_id;
    }
    require_once dirname(__FILE__) . '/CL_actionLogger.php';
    $log = new Logger();
    $log->userID = $userID + 0;
    // the userId that is logged in , not the one that the flight will be atrributed to
    $log->ItemType = 1;
    // flight;
    $log->ItemID = 0;
    // 0 at start will fill in later if successfull
    $log->ServerItemID = $thisServerID;
    $log->ActionID = 1;
    //1  => add  2  => edit;
    $log->ActionXML = '';
    $log->Modifier = 0;
    $log->ModifierID = 0;
    $log->ServerModifierID = 0;
    $log->Result = 0;
    $log->ResultDescription = "";
    if (!$filename) {
        $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_YOU_HAVENT_SUPPLIED_A_FLIGHT_FILE, 0);
        if (!$log->put()) {
            echo "Problem in logger<BR>";
        }
        return array(ADD_FLIGHT_ERR_YOU_HAVENT_SUPPLIED_A_FLIGHT_FILE, 0);
    }
    // now is the time to remove bad chars from the filename!
    $newFilename = str_replace("'", " ", $filename);
    $newFilename = toLatin1($newFilename);
    if ($newFilename != $filename) {
        rename($filename, $newFilename);
        $filename = $newFilename;
    }
    if (!is_file($filename)) {
        $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_NO_SUCH_FILE, 0);
        if (!$log->put()) {
            echo "Problem in logger<BR>";
        }
        return array(ADD_FLIGHT_ERR_NO_SUCH_FILE, 0);
    }
    if (strtolower(substr($filename, -4)) != ".igc") {
        $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_FILE_DOESNT_END_IN_IGC, 0);
        if (!$log->put()) {
            echo "Problem in logger<BR>";
        }
        return array(ADD_FLIGHT_ERR_FILE_DOESNT_END_IN_IGC, 0);
    }
    $tmpIGCPath = $filename;
    $flight = new flight();
    if ($thisServerID != $CONF_server_id) {
        $flight->userServerID = $thisServerID;
    }
    $flight->userID = $userIDforFlight;
    /*
    	$flight->cat=$gliderCat;
    	$flight->private=$is_private;
    	$flight->category=$category;
    	$flight->comments=$comments;
    	$flight->glider=$glider;
    	$flight->linkURL=$linkURL;
    */
    foreach ($argArray as $varName => $varValue) {
        if ($varName == 'NACclubID' || $varName == 'NACid' || $varName == 'comments') {
            continue;
        }
        $flight->{$varName} = $varValue;
    }
    $comments = $argArray['comments'];
    if ($comments) {
        $flight->commentsNum = 1;
    }
    if (strtolower(substr($flight->linkURL, 0, 7)) == "http://") {
        $flight->linkURL = substr($flight->linkURL, 7);
    }
    if ($flight->cat == -1) {
        $flight->cat = $CONF_default_cat_add;
    }
    # martin jursa 22.06.2008:
    # in case the glider is not given otherwise, try to extract it from the IGC file
    if (empty($flight->glider)) {
        $flight->glider = extractGlider($lines);
    }
    // if no brand was given , try to detect
    $flight->checkGliderBrand();
    //  we must cope with some cases here
    //  1. more flights in the igc
    //  2. garmin saved paths -> zero time difference -> SOLVED!
    if (!$flight->getFlightFromIGC($tmpIGCPath)) {
        $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_THIS_ISNT_A_VALID_IGC_FILE, 0);
        if (!$log->put()) {
            echo "Problem in logger<BR>";
        }
        return array(ADD_FLIGHT_ERR_THIS_ISNT_A_VALID_IGC_FILE, 0);
    }
    // Compute hash now
    $lines = file($tmpIGCPath);
    $hash = md5(implode('', $lines));
    $flight->hash = $hash;
    unset($lines);
    // check for mac newlines -> NOT USED NOW
    // we now use auto_detect_line_endings=true;
    /*
    	if ( count ($lines)==1) {
    		if ($lines[0]=preg_replace("/\r([^\n])/","\r\n\\1",$lines[0])) {		
    			DEBUG('addFlightFromFile',1,"addFlightFromFile: MAC newlines found<BR>");
    			if (!$handle = fopen($tmpIGCPath, 'w')) { 
    				print "Cannot open file ($filename)"; 
    				exit; 
    			} 
    			if (!fwrite($handle, $lines[0])) { 
    			   print "Cannot write to file ($filename)"; 
    			   exit; 
    			} 
    			fclose($handle); 
    		} 
    	}
    */
    // echo $flight->DATE	." >  ". date("Y-m-d",time()+3600*10) ."<BR>";
    // check for dates in the furure
    if ($flight->DATE > date("Y-m-d", time() + 3600 * 10)) {
        @unlink($flight->getIGCFilename(1));
        @unlink($tmpIGCPath . ".olc");
        @unlink($tmpIGCPath);
        $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_DATE_IN_THE_FUTURE, 0);
        if (!$log->put()) {
            echo "Problem in logger<BR>";
        }
        return array(ADD_FLIGHT_ERR_DATE_IN_THE_FUTURE, 0);
    }
    // Two week time limit check - P.Wild
    /// Modification martin jursa 08.05.2007 cancel the upload if flight is too old
    if ($CONF_new_flights_submit_window > 0) {
        if (!L_auth::isAdmin($userID)) {
            if ($flight->DATE < date("Y-m-d", time() - $CONF_new_flights_submit_window * 24 * 3600)) {
                @unlink($flight->getIGCFilename(1));
                @unlink($tmpIGCPath . ".olc");
                @unlink($tmpIGCPath);
                $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_OUTSIDE_SUBMIT_WINDOW, 0);
                if (!$log->put()) {
                    echo "Problem in logger<BR>";
                }
                return array(ADD_FLIGHT_ERR_OUTSIDE_SUBMIT_WINDOW, 0);
            }
        }
    }
    // end martin / peter
    $sameFilenameID = $flight->findSameFilename(basename($filename));
    if ($sameFilenameID > 0) {
        if ($flight->allowDuplicates) {
            while (is_file($flight->getIGCFilename())) {
                $flight->filename = '_' . $flight->filename;
            }
        } else {
            @unlink($flight->getIGCFilename(1));
            @unlink($tmpIGCPath . ".olc");
            @unlink($tmpIGCPath);
            $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_SAME_FILENAME_FLIGHT, 0);
            if (!$log->put()) {
                echo "Problem in logger<BR>";
            }
            return array(ADD_FLIGHT_ERR_SAME_FILENAME_FLIGHT, $sameFilenameID);
        }
    }
    $sameFlightsArray = $flight->findSameTime();
    if (count($sameFlightsArray) > 0) {
        if ($flight->allowDuplicates) {
            // we allow duplicates if they are from another server
            $dupFound = 0;
            foreach ($sameFlightsArray as $k => $fArr) {
                if ($fArr['serverID'] == $flight->serverID) {
                    // if a same flight from this server is present we dont re-insert
                    $dupFound = 1;
                    break;
                } else {
                    // fill in ids of flights to 'disable'
                    $disableFlightsList[$fArr['ID']]++;
                }
            }
        } else {
            $dupFound = 1;
        }
        if ($dupFound) {
            @unlink($flight->getIGCFilename(1));
            @unlink($tmpIGCPath . ".olc");
            @unlink($tmpIGCPath);
            $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_SAME_DATE_FLIGHT, 0);
            if (!$log->put()) {
                echo "Problem in logger<BR>";
            }
            //	return  array( ADD_FLIGHT_ERR_SAME_DATE_FLIGHT,$sameFlightsArray[0]['serverID'].'_'. $sameFlightsArray[0]['ID']);
            return array(ADD_FLIGHT_ERR_SAME_DATE_FLIGHT, $sameFlightsArray[0]['ID']);
        } else {
            DEBUG("FLIGHT", 1, "addFlightFromFile: Duplicate DATE/TIME flight will be inserted<br>");
        }
    }
    $sameFlightsArray = $flight->findSameHash($hash);
    if (count($sameFlightsArray) > 0) {
        if ($flight->allowDuplicates) {
            // we allow duplicates if they are from another server
            //echo "searching in dups ";
            //print_r($sameFlightsArray);
            $dupFound = 0;
            $flightPilot = new pilot($flight->userServerID + 0, $flight->userID + 0);
            $flightPilotMapTable = $flightPilot->pilotMapping();
            // print_r($flightPilotMapTable);
            foreach ($sameFlightsArray as $k => $fArr) {
                if ($fArr['serverID'] == $flight->serverID) {
                    // if a same flight from this server is present we dont re-insert
                    $dupFound = 1;
                    break;
                } else {
                    // check that the existing flight belongs to a pilot that is 'mapped' to
                    // $flight->userID + $flight->userServerID
                    if (!$flightPilotMapTable[$fArr['userServerID']][$fArr['userID']]) {
                        DEBUG("FLIGHT", 1, "addFlightFromFile: Same hash from external Server BUT from the pilot was not mapped into local <br>");
                        // We allow the flight to be submitted but then we must check and disable all duplicates but one
                        //$dupFound=1;
                        //break;
                    }
                    // fill in ids of flights to 'disable'
                    $disableFlightsList[$fArr['ID']]++;
                }
            }
        } else {
            // echo "no dups allowesd";
            $dupFound = 1;
        }
        if ($dupFound) {
            @unlink($flight->getIGCFilename(1));
            @unlink($tmpIGCPath . ".olc");
            @unlink($tmpIGCPath);
            $log->ResultDescription = getAddFlightErrMsg(ADD_FLIGHT_ERR_SAME_HASH_FLIGHT, 0);
            if (!$log->put()) {
                echo "Problem in logger<BR>";
            }
            return array(ADD_FLIGHT_ERR_SAME_HASH_FLIGHT, $sameFlightsArray[0]['ID']);
        } else {
            DEBUG("FLIGHT", 1, "addFlightFromFile: Duplicate HASH flight will be inserted<br>");
            // echo "addFlightFromFile: Duplicate HASH flight will be inserted<br>";
        }
    }
    // print_r($disableFlightsList);
    /*
    	if ( ! $flight->allowDuplicates ) {
    		$sameHashIDArray=$flight->findSameHash( $hash );
    		if (count($sameHashIDArray)>0) 	 {
    			@unlink($flight->getIGCFilename(1));
    			@unlink($tmpIGCPath.".olc");
    			@unlink($tmpIGCPath);
    			$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_SAME_HASH_FLIGHT,0);
    			if (!$log->put()) echo "Problem in logger<BR>";
    			return array(ADD_FLIGHT_ERR_SAME_HASH_FLIGHT,$sameHashIDArray[0]['serverID'].'_'.$sameHashIDArray[0]['ID']);	
    		}
    	}
    */
    //******************************************************
    // PASSED ALL TESTS , NOW DO SOME WORK WITH OUR FLIGHT
    //******************************************************
    // move the flight to corresponding year
    $flight->checkDirs();
    //$yearPath=$flightsAbsPath."/".$userIDstr."/flights/".$flight->getYear();
    //$maps_dir=$flightsAbsPath."/".$userIDstr."/maps/".$flight->getYear();
    //$charts_dir=$flightsAbsPath."/".$userIDstr."/charts/".$flight->getYear();
    //$photos_dir=$flightsAbsPath."/".$userIDstr."/photos/".$flight->getYear();
    //if (!is_dir($yearPath))  	mkdir($yearPath,0755);
    //if (!is_dir($maps_dir))  	mkdir($maps_dir,0755);
    //if (!is_dir($charts_dir))	mkdir($charts_dir,0755);
    //if (!is_dir($photos_dir))	mkdir($photos_dir,0755);
    /**
     * Martin Jursa; to avoid error log flooding
     */
    if (file_exists($tmpIGCPath)) {
        @rename($tmpIGCPath, $flight->getIGCFilename());
    }
    // in case an olc file was created too
    if (file_exists($tmpIGCPath . ".olc")) {
        @rename($tmpIGCPath . ".olc", $flight->getIGCFilename() . ".olc");
    }
    // these commands seem redundant:
    //@unlink($tmpIGCPath.".olc");
    //@unlink($tmpIGCPath);
    /*old:	@rename($tmpIGCPath, $flight->getIGCFilename() );
    	// in case an olc file was created too
    	@rename($tmpIGCPath.".olc", $flight->getIGCFilename().".olc" );
    	@unlink($tmpIGCPath.".olc");
    	@unlink($tmpIGCPath);
    */
    // if we use NACclubs
    // get the NACclubID for userID
    // and see if the flight is in the current year (as defined in the NAclist array
    if ($CONF_use_NAC) {
        require_once dirname(__FILE__) . "/CL_NACclub.php";
        list($pilotNACID, $pilotNACclubID) = NACclub::getPilotClub($userIDforFlight);
        DEBUG("FLIGHT", 1, "addFlightFromFile: pilotNACID:{$pilotNACID}, pilotNACclubID: {$pilotNACclubID}<br>");
        if ($CONF_NAC_list[$pilotNACID]['use_clubs']) {
            DEBUG("FLIGHT", 1, "addFlightFromFile: use_clubs is on<br>");
            if ($argArray['NACclubID'] > 0 && $argArray['NACid'] > 0) {
                $flight->NACclubID = $argArray['NACclubID'];
                $flight->NACid = $argArray['NACid'];
                DEBUG("FLIGHT", 1, "addFlightFromFile: using arguments NACclubID NACid<br>");
            } else {
                DEBUG("FLIGHT", 1, "addFlightFromFile: calculating  NACclubID NACid<br>");
                // check year -> we only put the club for the current season , so that results for previous seasons cannot be affected
                $currSeasonYear = $CONF_NAC_list[$pilotNACID]['current_year'];
                DEBUG("FLIGHT", 1, "addFlightFromFile: currSeasonYear:  {$currSeasonYear}<br>");
                if ($CONF_NAC_list[$pilotNACID]['periodIsNormal']) {
                    $seasonStart = $currSeasonYear - 1 . "-12-31";
                    $seasonEnd = $currSeasonYear . "-12-31";
                } else {
                    $seasonStart = $currSeasonYear - 1 . $CONF_NAC_list[$pilotNACID]['periodStart'];
                    $seasonEnd = $currSeasonYear . $CONF_NAC_list[$pilotNACID]['periodStart'];
                }
                DEBUG("FLIGHT", 1, "addFlightFromFile: seasonStart:{$seasonStart} , seasonEnd:{$seasonEnd}<br>");
                if ($flight->DATE > $seasonStart && $flight->DATE <= $seasonEnd) {
                    DEBUG("FLIGHT", 1, "addFlightFromFile: inside Season !!<br>");
                    $flight->NACclubID = $pilotNACclubID;
                    $flight->NACid = $pilotNACID;
                }
            }
        }
    }
    if ($CONF_use_validation) {
        $ok = $flight->validate(0);
        // dont update DB
    }
    if ($CONF_airspaceChecks) {
        $flight->checkAirspace(0);
        // dont update DB
    }
    $flight->putFlightToDB(0);
    // now do the photos
    if ($calledFromForm) {
        require_once dirname(__FILE__) . "/CL_flightPhotos.php";
        $flightPhotos = new flightPhotos($flight->flightID);
        // $flightPhotos->getFromDB();
        $j = 0;
        for ($i = 0; $i < $CONF_photosPerFlight; $i++) {
            $var_name = "photo" . $i . "Filename";
            $photoName = $_FILES[$var_name]['name'];
            $photoFilename = $_FILES[$var_name]['tmp_name'];
            if ($photoName) {
                if (CLimage::validJPGfilename($photoName) && CLimage::validJPGfile($photoFilename)) {
                    // $newPhotoName=toLatin1($photoName);
                    // Fix for same photo filenames 2009.02.03
                    //global $flightsAbsPath;
                    global $CONF;
                    $newPhotoName = flightPhotos::getSafeName(LEONARDO_ABS_PATH . '/' . str_replace("%PILOTID%", $flight->getPilotID(), str_replace("%YEAR%", $flight->getYear(), $CONF['paths']['photos'])), $photoName);
                    //$flightsAbsPath.'/'.$flight->getPilotID()."/photos/".$flight->getYear() ,
                    //$photoName	) ;
                    $phNum = $flightPhotos->addPhoto($j, $flight->getPilotID() . "/photos/" . $flight->getYear(), $newPhotoName, $description);
                    $photoAbsPath = $flightPhotos->getPhotoAbsPath($j);
                    if (move_uploaded_file($photoFilename, $photoAbsPath)) {
                        CLimage::resizeJPG($CONF['photos']['thumbs']['max_width'], $CONF['photos']['thumbs']['max_height'], $photoAbsPath, $photoAbsPath . ".icon.jpg", $CONF['photos']['compression']);
                        CLimage::resizeJPG($CONF['photos']['normal']['max_width'], $CONF['photos']['normal']['max_height'], $photoAbsPath, $photoAbsPath, $CONF['photos']['compression']);
                        $flight->hasPhotos++;
                        $j++;
                    } else {
                        //upload not successfull
                        $flightPhotos->deletePhoto($j);
                    }
                }
            }
        }
        // also try to get geotag info
        $flightPhotos->computeGeoInfo();
    }
    // took care of photos
    // tkae care of comments
    if ($comments) {
        global $lang2isoGoogle, $currentlang;
        $flightComments = new flightComments($flight->flightID);
        $commentInsertResult = $flightComments->addComment(array('parentID' => 0, 'userID' => $flight->userID + 0, 'userServerID' => $flight->userServerID + 0, 'guestName' => '', 'guestPass' => '', 'guestEmail' => '', 'text' => $comments, 'languageCode' => $lang2isoGoogle[$currentlang]), 0);
    }
    // now is a good time to disable duplicate flights we have found from other servers
    // AND are from the same user (using pilot's mapping table to find that out)
    global $db;
    if (0) {
        foreach ($disableFlightsList as $dFlightID => $num) {
            $query = "UPDATE {$flightsTable} SET private = private | 0x02 WHERE  ID={$dFlightID} ";
            $res = $db->sql_query($query);
            # Error checking
            if ($res <= 0) {
                echo "<H3> Error in query: {$query}</H3>\n";
            }
        }
    }
    //or
    $flight->hideSameFlights();
    set_time_limit(200);
    $flight->computeScore();
    $flight->updateTakeoffLanding();
    //	echo "TakeoffID:".$flight->takeoffID."<BR>";
    if (in_array($flight->takeoffID, $CONF['takeoffs']['private'])) {
        $flight->private = 1;
    }
    $flight->putFlightToDB(1);
    // update
    return array(1, $flight->flightID);
    // ALL OK;
}
Пример #6
0
function checkPilotPhoto($serverID, $pilotID)
{
    $normalImagePath = getPilotPhotoFilename($serverID, $pilotID, 0);
    $thumbImagePath = getPilotPhotoFilename($serverID, $pilotID, 1);
    if (!is_file($thumbImagePath) && is_file($normalImagePath)) {
        // create icon
        CLimage::resizeJPG(150, 150, $normalImagePath, $thumbImagePath, 15);
    }
}
Пример #7
0
					$newPhotoName=flightPhotos::getSafeName(
						LEONARDO_ABS_PATH.'/'.str_replace("%PILOTID%",$flight->getPilotID(),str_replace("%YEAR%",$flight->getYear(),$CONF['paths']['photos']) ),
						$photoName);				
						//$flightsAbsPath.'/'.$flight->getPilotID()."/photos/".$flight->getYear() , 
						//$photoName	) ;
						
					$phNum=$flightPhotos->addPhoto($j,$flight->getPilotID()."/photos/".$flight->getYear(), $newPhotoName,$description);								
					$photoAbsPath=$flightPhotos->getPhotoAbsPath($j);
					
					if ( move_uploaded_file($photoFilename, $photoAbsPath ) ) {
						CLimage::resizeJPG( $CONF['photos']['thumbs']['max_width'],
						 					$CONF['photos']['thumbs']['max_height'],
											$photoAbsPath, $photoAbsPath.".icon.jpg", 
											$CONF['photos']['compression']);
						CLimage::resizeJPG(
						 $CONF['photos']['normal']['max_width'],
						 $CONF['photos']['normal']['max_height'], $photoAbsPath, $photoAbsPath, 
						 $CONF['photos']['compression']);
						$flight->hasPhotos++;
						$photosChanged=true;
						$j++;
					} else { //upload not successfull - track back
						$flightPhotos->deletePhoto($j);
					}
				}
			}
		} 

		// now delete photos if requested
		for($i=0;$i<$CONF_photosPerFlight;$i++) {
			if ($_REQUEST["photo".$i."Delete"]=="1") {		// DELETE photo
				// echo "deleting photo $i<HR>";
     // DELETE photo
     @unlink(getPilotPhotoFilename($serverIDview, $pilotIDview, 1));
     @unlink(getPilotPhotoFilename($serverIDview, $pilotIDview, 0));
     $PilotPhoto = 0;
 } else {
     if ($_FILES['PilotPhoto']['name']) {
         // upload new
         @unlink(getPilotPhotoFilename($serverIDview, $pilotIDview, 1));
         @unlink(getPilotPhotoFilename($serverIDview, $pilotIDview, 0));
         $path = dirname(getPilotPhotoFilename($serverIDview, $pilotIDview));
         if (!is_dir($path)) {
             makeDir($path);
         }
         if (move_uploaded_file($_FILES['PilotPhoto']['tmp_name'], getPilotPhotoFilename($serverIDview, $pilotIDview))) {
             CLimage::resizeJPG(150, 150, getPilotPhotoFilename($serverIDview, $pilotIDview), getPilotPhotoFilename($serverIDview, $pilotIDview, 1), 15);
             CLimage::resizeJPG(800, 800, getPilotPhotoFilename($serverIDview, $pilotIDview), getPilotPhotoFilename($serverIDview, $pilotIDview), 15);
             $PilotPhoto = 1;
         } else {
             //upload not successfull
             @unlink(getPilotPhotoFilename($serverIDview, $pilotIDview, 1));
             @unlink(getPilotPhotoFilename($serverIDview, $pilotIDview, 0));
             $PilotPhoto = 0;
         }
     } else {
         // no change
         if (is_file(getPilotPhotoFilename($serverIDview, $pilotIDview))) {
             $PilotPhoto = 1;
         } else {
             $PilotPhoto = 0;
         }
     }