#!/usr/bin/perl ################################################################### # reitti.cgi or reitti.pl # ################################################################### # Reittihärveli - Sovellus suunnistuksen reittipiirrosten # # keräykseen ja esittämiseen tämiseen # # Distributed by: jryyppo ät gmail.com # # ================================================================# # Copyright (c) 2003-2014 Jarkko Ryyppö - All Rights Reserved. # # Software by: Jarkko Ryyppö # # Sponsored by: - # $RG_version='20140330'; ################################################################### # The software is free for non-commercial use. The software can # # be used only for purposes related to the sport of orienteering. # # # # This program comes as it is. Use it at your own risk. This is # # software with ABSOLUTELY NO WARRANTY. This program is # # distributed in the hope that it will be useful, but # # WITHOUT ANY WARRANTY; without even the implied warranty of # # FITNESS FOR A PARTICULAR PURPOSE. # # # # Developers of this software are not responsible for what the # # user does with help of this software. # # # # THE USER MUST NOT USE SOFTWARE FOR ILLEGAL ACTIONS. # # # # By installing and/or using our software, you agree with these # # terms of use. # ################################################################### use CGI::Carp qw(fatalsToBrowser); use Fcntl ":flock"; use POSIX; #!!! duke use Math::Round; use Encode qw(encode decode is_utf8); use CGI qw(:cgi-lib :standard); $CGI::POST_MAX=1024 * 10000; # max 10000K posts use POSIX qw(strftime); ReadParse(); #!!! duke if(!($in{'act'} eq 'map' || $in{'act'} eq 'jsclassescourses' || $in{'act'} eq 'jskilp' || $in{'act'} eq 'jskilppiirto' || $in{'act'} eq 'jsreitit' || $in{'act'} eq 'jsradat' || $in{'act'} eq 'jsanim')) { die; } $in{'gps'}=0; #block gps upload $RG_TIME_ZONE_OFFSET=14440; #4 hours $RG_TRACK_CUT_START=3600*10; #10.00 $RG_TRACK_CUT_END=3600*23; #23.00 if($in{'act'} =~ /js/i || ($in{'act'} eq 'map' && $in{'id'} > 0 && $in{'keksi'} eq '')){ #$charset_default='UTF-8'; $charset_default='WINDOWS-1251'; # binmode(STDOUT, ":utf8"); ## overkill no-no-never-ever-cache approach print header( -type=>"text/html; charset=".$charset_default, # date in the past -expires => 'Sat, 26 Jul 1997 05:00:00 GMT', # always modified -Last_Modified => strftime('%a, %d %b %Y %H:%M:%S GMT', gmtime), # HTTP/1.0 -Pragma => 'no-cache', # HTTP/1.1 + IE-specific (pre|post)-check -Cache_Control => join(', ', qw( private no-cache no-store must-revalidate max-age=0 pre-check=0 post-check=0 )), ); }else{ ## @languages=('ca','de','ee','en','es','fi','fr','he','lt','lv','no','ru','se','pt'); ## You can add new languages by (1)adding new item here, (2) adding language texts with ## correct parameter names to map.txt (like ) ## and making new file "lang_YOURLANGUAGE.txt" ## (you can figure it out with these examples I hope) ## ## 1. Default language: (choices are currently 'ca','de','ee','en','es','fi','fr','he','lt','lv','no','ru','se') $default_lang='ru'; ## default language for the new js UI: $defaultlang='ru'; ## ## Default charset: $charset_default='ISO-8859-1'; # Language spesific charsets: ## $charset{'fi'}='ISO-8859-1'; ## example $charset{'ru'}='WINDOWS-1251'; $charset{'he'}='WINDOWS-1255'; if($in{'act'} eq 'help'){ if($charset{$in{'kieli'}} ne ''){b $charset_default=$charset{$in{'kieli'}}; } } print "Content-Type: text/html; charset=".$charset_default."\n\n"; } $livepasswd=''; # password disabled if empty if($in{'lang'} eq '' && $in{'kieli'} ne ''){ $in{'lang'}=$in{'kieli'}; } ######################### ## ## 2. File locking (turn this off if you get lock errors or 500 errors no matter what you do) ## #$locking=1; # locking is on $locking=0; # locking is off ## ## 3. Paths ## For UNIX, Linux: # $path='../kartat/'; ## file path to "kartat" folder # $httppath='../'; ## http path to the folder of leaflet.js, gadget.gif etc #!!! duke $path='/home4/goraru/public_html/randomrace.ru/gadget/kartat/'; ## file path to "kartat" folder $httppath='/gadget/'; ## http path to the folder of leaflet.js, gadget.gif etc $reitti_path='/gadget/cgi-bin/'; # # ## For IIS (Windows): #$path='C:/inetpub/wwwroot/gadget/kartat/'; ## file path to "kartat" folder # $httppath='../'; ## http path to the folder reitti.jar is located ## $norouteanim=1; ## ## Save event location using map calibration or gps uploads, so sites # like omaps.worldofo.com can geo locate map/event. 1=yes, 0 =no $geolocateevent=1; ## ## 4. OGraphApplet: 1=yes, 0 =no $OGraphApplet=0; ## ## 5. Splitsbrowser : 1=yes, 0 =no $Splitsbrowser=1; ## ## 6. Splitalyzer : 1=yes, 0 =no $splitsalyzer=0; ## ## 7. Event level names: # Default event level names $eLevel{'I'}='International'; $eLevel{'N'}='National'; $eLevel{'R'}='Regional'; $eLevel{'L'}='Local'; $eLevel{'T'}='Training'; # default Club name (for pre-opening the menu tree); $defaultClub=''; #$menuStyle='list'; ## Language specifics ## Finnish if($in{'kieli'} eq 'fi'){ $eLevel{'I'}='Kansainvälinen'; $eLevel{'N'}='Kansallinen'; $eLevel{'R'}='Alueellinen'; $eLevel{'L'}='Paikallinen'; $eLevel{'T'}='Harjoitus'; } # menu texts if not in Finnish: $latestRoutes='Latest routes'; $events='Events:'; $latestEvents='Latest events'; $eventsByOrg='Events by club'; $eventsByDate='Events by date'; ######################################################################################### if($httppath eq ''){$httppath='./';} $gadgeticon=$httppath.'logo6.ico'; if($default_lang ne 'fi'){ $logo=$httppath.'gadget.gif'; }else{ $logo=$httppath.'harveli.gif'; } $piste=$httppath.'piste.gif'; ## Check extension $apu=$0; $apu=~ s/\\/\//g; @apu = split (/\//,$apu); ($remove,$extension)= split(/\./,$apu[$#apu]); ################### #################### rgjs section begins############################# $in{'eventid'}=1*$in{'eventid'}; #### if($in{'act'} eq 'map' && $in{'keksi'} eq '' && $in{'id'} >0 ){ # if not, then java ui $in{'eventid'}=1*$in{'id'}; open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); foreach $rec (@kartat) { chomp($rec); @r=split(/\|/,$rec,8); if($r[0] eq $in{'eventid'}){ ($eventid,$karttaid,$tyyppi,$nimi,$paiva,$seura,$taso,$notes)=split(/\|/,$rec,8); $eventname=$paiva.' '.$nimi; } } ($imwidth, $imheight, $format) = ImageSize($path.$karttaid.'.jpg'); $gpsdata=''; ### GPS start if($in{'gps'} ==1){ ## gps asemointi $GPSATHLETE=1*$in{'kilpailijagps'}; open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarjanimi,$nimi,$laika,$aika,$sija,$tulos,$valiajat)=split(/\|/,$rec); if($id eq $in{'kilpailijagps'}){ $valiajat=~ s/\r//g; $valiajat=~ s/\n//g; $GPSSPLITS=$valiajat; if(substr($GPSSPLITS,-1) ne ';'){ $GPSSPLITS.=';'; } $gpsclass=$sarjanro; if($tyyppi ne '3'){ $gpsrata=$sarjanro; }else{ $gpsrata=$sija; } } } close SISAAN; open(SISAAN, "<".$path."ratapisteet_$in{'eventid'}.txt"); @d=; close(SISAAN); foreach $rec (@d){ chomp($rec); ($id,$rastit)=split(/\|/,$rec,2); if($id eq $gpsrata){ $rpisteet=$rastit; } } $GPSSPLITS.='|'.$rpisteet; if($tyyppi eq '2'){ $in{'calibtype'} = 'manual'; $gpsrata=$in{'sarjagps'}; } $GPSMODE=0; if($in{'calibtype'} eq 'manual'){ $GPSMODE=1; ### pre calibrated map parameters open(HANDLE, "<".$path."kartat.txt")|| die; @kdata=; close(HANDLE); $coord[0]=''; $coord[4]=''; foreach $rec (@kdata){ chomp($rec); ($mapid,$mapname)=split(/\|/,$rec); if($karttaid eq $mapid){ ($a,$b,$c,$s1x,$o1x,$s1y,$o1y,$s2x,$o2x,$s2y,$o2y,$s3x,$o3x,$s3y,$o3y)=split(/\|/,$rec); if($o1x != 0){ $s1y=-$s1y; $s2y=-$s2y; $s3y=-$s3y; $lat0=$o1y; $lon0=$o1x; $kaavao1y=$o1y; $kaavao1x=$o1x; $r=6370000; $pi=3.1415926535897932384626433832795; $lat=$o1y; $lon=$o1x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o1y=$north; $o1x=$east; $lat=$o2y; $lon=$o2x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o2y=$north; $o2x=$east; $lat=$o3y; $lon=$o3x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o3y=$north; $o3x=$east; $xnolla1=$o1x; $ynolla1=$o1y; $xi=$o2x-$xnolla1;$yi=$o2y-$ynolla1;$xj=$o3x-$xnolla1;$yj=$o3y-$ynolla1; $xnolla=$s1x; $ynolla=$s1y; $x1 = $s2x-$xnolla;$y1 = $s2y-$ynolla;$x2 = $s3x-$xnolla;$y2 = $s3y-$ynolla; #nollalla jakamisen esto if($xj==0){$xj=0.000000000001;} if($yj==0){$yj=0.000000000001;} if(($xj * $yi - $yj * $xi)==0){$xj=$xj+0.000000000001;} if(($yj * $xi - $xj * $yi)==0){$yj=$yj+0.0000000000001;} $Gb = ($x1 * $xj - $x2 * $xi) / ($xj * $yi - $yj * $xi); $Ga = ($x2 - $Gb * $yj) / $xj; $Gd = ($y1 * $yj - $y2 * $yi) / ($yj * $xi - $xj * $yi); $Gc = ($y2 - $Gd * $xj) / $yj; } } } } #!!! duke $gpsstarttime=0; #################### track log processing $pi=3.1415926535897932384626433832795; $q = $in{CGI}; if($in{'gpsurl'} =~ /http/i){ require LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->max_size(10485760); # 10 Mb; $response = $ua->get($in{'gpsurl'}); if ($response->is_success) { $d= $response->decoded_content; # or whatever } else { die $response->status_line; exit; } }else{ $file = $q->param('tracklog'); binmode $file; @d =<$file>; close($file); $d= join('',@d); } #!!! duke # open(XXHANDLE,">>"."$path/222111.txt"); $pi=3.1415926535897932384626433832795; if($d =~ /\'); $p2=index($point,''); if($p1>-1 && $p2>-1){ # $tim=substr($point,$p1+6,$p2-$p1-6); $tim=~ s/Z//g; $tim=~ s/\-/\:/g; $tim=~ s/T/\:/g; ($tyear,$tmon,$tday,$thour,$tmin,$tsec)=split(/\:/,$tim); $tim=3600*$thour+60*$tmin+$tsec; $day=$tyear.'_'.$tmon.'_'.$tday; # print XXHANDLE "$tim $RG_TRACK_CUT_START $RG_TRACK_CUT_END "; if(($tim+$RG_TIME_ZONE_OFFSET)<$RG_TRACK_CUT_START || ($tim+$RG_TIME_ZONE_OFFSET)>$RG_TRACK_CUT_END) { # print XXHANDLE "cut\n"; next; } # print XXHANDLE "!\n"; } $p1=index($point,"lat=\""); $p2=index($point,"\"",$p1+6); if($p1>-1 && $p2>-1){ $lat=substr($point,$p1+5,$p2-$p1-5); $lat =~ s/ //g; $lat =~ s/\"//g; } $p1=index($point,"lon=\""); $p2=index($point,"\"",$p1+6); if($p1>-1 && $p2>-1){ $lon=substr($point,$p1+5,$p2-$p1-5); $lon =~ s/ //g; $lon =~ s/\"//g; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $alt=substr($point,$p1+4,$p2-$p1-4); $alt =~ s/ //g; $alt=1*$alt; } if($lat!=-9999999 && $lon !=-9999999){ $count++; if($lat0==-987654){ $lat0=$lat; $lon0=$lon; $daycount=0; $tim0=$tim; $day0=$day; #!!! duke $gpsstarttime=$tim0; } #!!! duke # print XXHANDLE "$lat, $lon, $lat0, $lon0\r\n"; ## this not very scientific, byt must do for now ... $r=6370000; $northing=-floor(($lat-$lat0)/360*2*$pi*$r*100)/100; $easting=floor(($lon-$lon0)/360*2*$r*$pi *cos(abs($lat0)/180*$pi)*100)/100; #!!! duke # print XXHANDLE "$northing, $easting\r\n"; if($day0 ne $day){ $day0 == $day; $daycount++; } $tim=$tim+$daycount*60*60*24-$tim0; if($Ga ne ''){ #($lon,$lat)=($lat,$lon); $lat0=$kaavao1y; $lon0=$kaavao1x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $easting = floor(100*($s1x+ ((($Ga*($east-$xnolla1) + $Gb*($north-$ynolla1))))))/100; $northing= -floor(100*($s1y+ ((($Gc*($north-$ynolla1) + $Gd*($east-$xnolla1))))))/100; #!!! duke # print XXHANDLE "$north, $east\r\n"; # print XXHANDLE "$northing, $easting\r\n---\r\n"; } $GPSparam.="$tim,$easting,$northing;"; if($mineast>$easting){$mineast=$easting;} if($maxeast<$easting){$maxeast=$easting;} if($minnorth>$northing){$minnorth=$northing;} if($maxnorth<$northing){$maxnorth=$northing;} } } @ad=split(/\;/,$GPSparam); $GPSparam=''; foreach $pt (@ad){ @r=split(/\,/,$pt); if( $r[0]>$edtim){ if($edtim ne '' && $edtim +1 < $r[0] ){ for($i=$edtim+1;$i<$r[0];$i++){ $tim=$i; $easting=floor(100*(($i-$edtim)/($r[0]-$edtim)*$r[1]+($r[0]-$i)/($r[0]-$edtim)*$edeast))/100; $northing=floor(100*(($i-$edtim)/($r[0]-$edtim)*$r[2]+($r[0]-$i)/($r[0]-$edtim)*$ednorth))/100; $GPSparam.="$tim,$easting,$northing;"; } } $GPSparam.=join(',',@r).";"; } $edtim=$r[0]; $edeast=$r[1]; $ednorth=$r[2]; } } # GPX #!!! duke # close XXHANDLE; #!!! duke removed section # if($d =~ /\/i && $d =~ /\/i){ # suunto xml # ($pois,$d)=split(/\/i,$d,2); # $out=''; # @d=split(/\/i,$d); # $lat0=-987654; # foreach $rec (@d){ # ($pois,$lat)=split(/Latitude\>/i,$rec,2); # ($lat,$dat)=split(/\/i,$rec,2); # ($lon,$dat)=split(/\/i,$rec,2); # ($tim,$pois)=split(/\$easting){$mineast=$easting;} # if($maxeast<$easting){$maxeast=$easting;} # if($minnorth>$northing){$minnorth=$northing;} # if($maxnorth<$northing){$maxnorth=$northing;} # } # } # @ad=split(/\;/,$GPSparam); # $GPSparam=''; # foreach $pt (@ad){ # @r=split(/\,/,$pt); # if( $r[0]>$edtim){ # if($edtim ne '' && $edtim +1 < $r[0] ){ # for($i=$edtim+1;$i<$r[0];$i++){ # $tim=$i; # $easting=floor(100*(($i-$edtim)/($r[0]-$edtim)*$r[1]+($r[0]-$i)/($r[0]-$edtim)*$edeast))/100; # $northing=floor(100*(($i-$edtim)/($r[0]-$edtim)*$r[2]+($r[0]-$i)/($r[0]-$edtim)*$ednorth))/100; # $GPSparam.="$tim,$easting,$northing;"; # } # } # $GPSparam.=join(',',@r).";"; # } # $edtim=$r[0]; # $edeast=$r[1]; # $ednorth=$r[2]; # } # } if($Ga eq ''){ # not if map is geo-referenced ### scale it to the center of the map $gpsdata=''; @d=split(/\;/,$GPSparam); $size=$imheight/($maxnorth-$minnorth); $side=$imheight; if($imwidth/($maxeast-$mineast)<$size){ $size=$imwidth/($maxeast-$mineast); $side=$imwidth; } foreach $rec (@d){ ($t,$e,$n)=split(/\,/,$rec); $e=floor(($side*0.1+($e-$mineast)*$size*0.8)*100)/100; $n=floor(($side*0.1+($n-$minnorth)*$size*0.8)*100)/100; $gpsdata.="$t,$e,$n;"; } }else{ $gpsdata=$GPSparam; } # geo locate event if($geolocateevent == 1){ open (SISAAN,"<$path/eventlocations.txt"); @elocat=; close(SISAAN); $posexist=0; foreach $eventl (@elocat){ ($enumb,$elat,$elon)=split(/\|/,$eventl); if($enumb == $eventid){ $posexist=1; } } if($posexist==0){ open (HANDLE,">>"."$path/eventlocations.txt"); &lock_file; print HANDLE $eventid."|".$lat0."|".$lon0."\n"; &unlock_file; close HANDLE; } } } ### GPS end #!!! duke open (SISAAN,"<".$path."initanim.txt"); @d=; close(SISAAN); foreach $rec (@d) { chomp($rec); ($evid,$mapcenterlat,$mapcenterlon,$mapzoom,$animsttime)=split(/\|/,$rec); if($evid eq $eventid){ last; } } $popupdatastr=''; %popupdata=(); $popupdelstr=''; %popupdel=(); open (SISAAN,"<".$path."popups_".$eventid.".txt"); @d=; close(SISAAN); $popupcnt=0; foreach $rec (@d) { chomp($rec); $rec =~ s/\n//g; $rec =~ s/\r//g; @r=split(/\|/,$rec); if($r[3] ne '') { @rrr=split(/\:/,$r[3]); $r[3]=$rrr[0]*3600+$rrr[1]*60; } else { $r[3]=0; } if($r[4] ne '') { @rrr=split(/\:/,$r[4]); $r[4]=$rrr[0]*3600+$rrr[1]*60; $popupdel{$r[4]}="[$r[4],$popupcnt]"; } else { $r[4]=0; } $popupdata{$r[3]}="[$r[0],$r[1],'$r[2]',$r[3],$r[4],$popupcnt]"; $popupcnt++; } foreach $key (sort keys %popupdata) { if($popupdatastr ne '') {$popupdatastr.=",";} $popupdatastr.=$popupdata{$key}; } foreach $key (sort keys %popupdel) { if($popupdelstr ne '') {$popupdelstr.=",";} $popupdelstr.=$popupdel{$key}; } #!!! duke #open (HANDLE,">>"."$path/111.txt"); #print HANDLE $gpsdata; #close HANDLE; open (SISAAN,"<$path/../mappage.html"); @page=; close(SISAAN); $page=join('',@page); $title="$eventname"; $notes= "$eventname

$seura

$notes

"; #!!! duke $in{'touch'}=0; # if($in{'touch'} ne '1' && $in{'gps'} ne '1'){ # $notes.=">>Touch mode" # } #!!! duke $notes =~ s/\"//gi; $notes =~ s/\\//gi; $page=~ s/#eventid#/${eventid}/gi; $page=~ s/#eventtype#/${tyyppi}/gi; $page=~ s/#eventname#/${eventname}/gi; $page=~ s/#mapid#/${karttaid}/gi; $page=~ s/#mapheight#/${imheight}/gi; $page=~ s/#mapwidth#/${imwidth}/gi; $page=~ s/#eventnotes#/${notes}/gi; $page=~ s/#title#/${title}/gi; $page=~ s/#httppath#/${httppath}/gi; $page=~ s/#ext#/${extension}/gi; $page=~ s/#GPSDATA#/${gpsdata}/; $page=~ s/#GPSSPLITS#/${GPSSPLITS}/; $GPSMODE=1*$GPSMODE; $page=~ s/#GPSMODE#/${GPSMODE}/; $page=~ s/#GPSRATA#/${gpsrata}/; $page=~ s/#GPSCLASS#/${gpsclass}/; $page=~ s/#GPSATHLETE#/${GPSATHLETE}/; #!!! duke $page=~ s/#MAPCENTERLAT#/${mapcenterlat}/; $page=~ s/#MAPCENTERLOT#/${mapcenterlon}/; $page=~ s/#MAPZOOM#/${mapzoom}/; $page=~ s/#ANIMSTTIME#/${animsttime}/gi; $page=~ s/#GPSSTARTTIME#/${gpsstarttime}/; $page=~ s/#POPUPDATA#/${popupdatastr}/; $page=~ s/#POPUPDEL#/${popupdelstr}/; $page=~ s/#reitti-path#/${reitti_path}/gi; if($in{'gps'}==1) {$loadanimbydef=0;} else {$loadanimbydef=1;} $page=~ s/#loadanimbydef#/$loadanimbydef/; if($loadanimbydef) { $page=~ s/#css-mapright#/0/g; $page=~ s/#css-defvis#/visibility: hidden;/g; $page=~ s/#css-hiderright#/0/g; } else { $page=~ s/#css-mapright#/200/g; $page=~ s/#css-defvis#//g; $page=~ s/#css-hiderright#/200/g; } #!!! duke if($in{'touch'} ne ''){ $viewport=""; $page=~ s/#viewport#/${viewport}/gi; $page=~ s/#touchmode#/1/gi; }else{ $page=~ s/#viewport#//gi; $page=~ s/#touchmode#/0/gi; } ### language parameters open (SISAAN,"<".$path."/../languages.txt"); binmode(SISAAN, ":utf8"); @terms=; close(SISAAN); $langs="\n"; foreach $rec (@terms) { chomp($rec); $rec=~ s/\n//g; $rec=~ s/\r//g; if($rec =~ /\=/ ){ ($name,$rec)=split(/\=/,$rec,2); ($pois,$text,$pois)=split(/\"/,$rec,3); $name=~ s/ //g; if($name =~ /\_/){ $term{$name}=$text; ($lang,$nro)=split(/\_/,$name); if($islang{$lang} eq ''){ $langs.="\n"; $islang{$lang}=1; } } } } ##### $lang=$in{'lang'}; if($lang eq ''){ $lang=$defaultlang; } for($i=0;$i<90;$i++){ $s='term_'.$i; $r=$term{$lang.'_'.$i}; if($term{$lang.'_'.$i} eq ''){ $r=$term{'eng_'.$i}; } $page=~ s/#${s}#/${r}/g; } $page=~ s/#languages#/${langs}/g; $page=~ s/#lang#/${lang}/g; ## disabling multiselect for ipad iphone if($ENV{HTTP_USER_AGENT} =~ /ipad/i || $ENV{HTTP_USER_AGENT} =~ /iphone/i){ $s='\(\"\#kilp\"\)\.MultiSelect'; $r='("#kilp_disabled").MultiSelect'; $page=~ s/${s}/${r}/; } #### print $page; exit; } ################################### if($in{'act'} eq 'jsclassescourses'){ $eventid=$in{'eventid'}*1; open (SISAAN,"<".$path."sarjat_".$eventid.".txt"); @d=; close(SISAAN); foreach $rec (@d) { chomp($rec); $rec =~ s/\"//g; $rec =~ s/\n//g; $rec =~ s/\r//g; @r=split(/\|/,$rec); $rec = "{\"$r[0]\":\"$r[1]\"}"; } print '['.join(',',@d)."]\n"; exit; } ###################################### if($in{'act'} eq 'jskilp'){ $in{'eventid'}=1*$in{'eventid'}; ## tarkistetan piirtäneet tähtimerkintää varten open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $tahti{$id}="*"; } close(SISAAN); ### open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarja,$nimi,$laika,$aika,$sijahajonta,$tulos,$valiajat)=split(/\|/,$rec); if($sarjanro eq $in{'sarja'} || ($in{'sarja'} eq '99999' && $tahti{$id} eq '*')){ if($in{'eventtype'} ne '3'){ # $out[$#out+1] ="{\"$id\":\"$tahti{$id}".encode('cp1251',$sijahajonta)." $nimi $tulos \"}"; $out[$#out+1] ="{\"$id\":\"$tahti{$id}$sijahajonta $nimi $tulos \"}"; }else{ $out[$#out+1] = "{\"$id\":\"$tahti{$id} $nimi $tulos;$sijahajonta\"}"; } } } close(SISAAN); print '['.join(',',@out)."]\n"; exit; } ##################### ######################################### if($in{'act'} eq 'jskilppiirto'){ $sarja=1*$in{'sarja'}; $eventid=$in{'eventid'}*1; open (SISAAN,"<".$path."kilpailijat_".$eventid.".txt"); @d=; close(SISAAN); foreach $rec (@d) { chomp($rec); $rec =~ s/\"//g; $rec =~ s/\n//g; $rec =~ s/\r//g; @r=split(/\|/,$rec); if($r[1] == $sarja && $r[1] < 50000 ){ $out[$#out+1] = "{\"$r[0]\":\"$r[3]\"}"; } } print '['.join(',',@out)."]\n"; exit; } ##################################################################################### if($in{'act'} eq 'jsreitit'){ ## tästä appletti lataa viivat $gpsid=','; @temp=split(/\,/,$in{'kilp'}); foreach $rec (@temp){ if($rec > 50000){ $rec=$rec-50000; $gpsid.=$rec.','; } } $kilp=','.join(',',@temp).','; $in{'kilp'}=','.$in{'kilp'}.','; open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarjanimi,$nimi,$laika,$aika,$sija,$tulos,$valiajat,$GPSa)=split(/\|/,$rec); $s=','.${id}.','; if($kilp=~ /${s}/){ $valiajat=~ s/\r//g; $valiajat=~ s/\n//g; $valiajat{''.$id}=$valiajat; $valiajat{''.($id+50000)}=$valiajat; } if($in{'kilp'}=~ /${s}/){ $GPSa{''.($id)}=$GPSa; } } close SISAAN; open(SISAAN, "<".$path."ratapisteet_$in{'eventid'}.txt"); @d=; close(SISAAN); foreach $rec (@d){ chomp($rec); ($id,$rastit)=split(/\|/,$rec,2); $rpisteet{$id}=$rastit; } open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); @merkinnat=; close(SISAAN); { $i=0;$loytyi=0; foreach $rec (@merkinnat) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $i++; $s=','.$id.','; if ($in{'kilp'} =~ /${s}/){ $i++; $viivat =~ s/R//g; $viivat =~ s/#//g; $viivat=~ s/N//; if($id < 50000){ foreach $rasti (split(/N/,$rpisteet{$idkilp})){ $viivat =~s/N${rasti}N/N${rasti}C${rasti}N/; } }else{ # gps leg splitting @temp=split(/\;/,$valiajat{''.$id}); @ani=split(/N/,$GPSa{''.$id}); foreach $sp (@temp){ $i=0; while($i>-1 && $i<20){ $C=$ani[floor($sp/3)+$i]; $i++; ($C,$pois)=split(/\,/,$C); if($viivat =~ /N${C}N/){ $viivat =~s/N${C}N/N${C}C${C}N/; $i=-1; } } #$viivat =~s/N${C}N/N${C}C${C}N/; } } $out{$id}= "\{\"$id\":\"".$valiajat{''.$id}."S".$viivat."\"}"; } } } print "["; $count=0; foreach $id (reverse(split(/\,/,$in{'kilp'}))){ if($out{$id} ne ''){ if($count>0){print ",";} print $out{$id}; $count++; } } print "]\n"; exit; } #####################################3 if($in{'act'} eq 'jsradat'){ if($in{"hajonnat"} ne''){ $in{"hajonnat"}=','.join(',',&uniq(split(/\,/,$in{"hajonnat"}))).','; $in{"hajonnat"}=','.$in{"hajonnat"}.','; open (SISAAN,"<$path"."radat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$status,$nimi,$viivat)=split(/\|/,$rec); if (index($in{"hajonnat"},','.$id.',')>-1){ $viivat =~ s/R//g; $viivat =~ s/#//g; $out.= "$viivat"."N"; } } close(SISAAN); }else{#henk koht open (SISAAN,"<$path"."radat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$status,$nimi,$viivat)=split(/\|/,$rec); if ($in{"sarja"} == $id || $in{"sarja"} eq '99999'){ $viivat =~ s/R//g; $viivat =~ s/#//g; if($in{"sarja"} ne '99999'){ $out.= "$viivat"."N"; }else{ $out.= "$viivat"."N"; $count++; } } } close(SISAAN); }# henkkoht moodi if($in{"sarja"} eq '99999'){ ## vain ympyrät kaikkien ratojen systeemiin if($count > 10){ @d=split(/N/,$out); $out=''; foreach $rec (@d){ ($type,$rest)=split(/\;/,$rec,2); if($e{$rec} eq'' && $type eq '1'){ $e{$rec}=1; $out.=$rec."N"; } } } } print "[{\"courses\":\"$out\"}]\n"; exit; } ############################### if($in{'act'} eq 'jsanim'){ open(SISAAN, "<".$path."ratapisteet_$in{'eventid'}.txt"); @d=; close(SISAAN); foreach $rec (@d){ chomp($rec); ($id,$rastit)=split(/\|/,$rec,2); $rpisteet{$id}=$rastit; } # Tästä apletti pyytää animaatiopisteet $raika=3; ## step - aika sekunteina open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); $viesti=0; foreach $rec (@kartat) { chomp($rec); ($id,$karttaid,$tyyppi,$nimi)=split(/\|/,$rec,4); if($id==$in{'eventid'} && $tyyppi ==3){ $viesti=1; } } ## haetaan suora reitti open (SISAAN,"<".$path."ratapisteet_$in{'eventid'}.txt"); @ratap=; close(SISAAN); foreach $rec (@ratap){ chomp($rec); ($id,$data)=split(/\|/,$rec,2); @temp=split(/N/,$data); $data=""; foreach $recb (@temp){ chomp($recb); ($x,$y)=split(/\;/,$recb,2); $data=$data.($x).";".($y)."N"; } $suorareitti{$id}=$data; ($pis,$data)=split(/N/,$data,2); $suorarastit{$id}=$data; } ## suora reitti ok $gpsid=','; @temp=split(/\,/,$in{'kilp'}); foreach $rec (@temp){ if($rec > 50000){ $rec=$rec-50000; $gpsid.=$rec.','; } } $in{'kilp'}=','.$in{'kilp'}.','; ## haetaan valiajat $kilp=1;$laikaMin=99999999; #!!! duke open (SISAAN,"<".$path."gpsstarttimes_$in{'eventid'}.txt"); @gpsst=; close(SISAAN); @trackicon=(); foreach $ddd (@gpsst){ chomp($ddd); ($kilpid,$gpsstime,$trackiconnum)=split(/\|/,$ddd); $lahtoaika[$kilpid]=$gpsstime+$RG_TIME_ZONE_OFFSET; $trackicon[$kilpid]=$trackiconnum; # if($gpsstime<$laikaMin){ # $laikaMin=$gpsstime; # } } #!!! duke open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); $ok=0; while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarjanimi,$nimi,$laika,$aika,$sija,$tulos,$valiajat,$GPSa)=split(/\|/,$rec); $s=','.$id.','; if($in{'kilp'} =~ /${s}/){ $kilp=$id; if($lahtoaika[$kilp] eq ''){ $lahtoaika[$kilp]=$laika; }else{ $laika=$lahtoaika[$kilp]; } $lahtoaika[$kilp]=$laika; if($laika<$laikaMin && $laika eq $laika+0){ $laikaMin=$laika; } if($vajat[$kilp] eq ''){ $vajat[$kilp]=$valiajat; } $gpsani[$kilp]=$GPSa; $srj{$kilp}=$sarjanro; if($viesti ==1){ $srj{$kilp}=$sija; } $ok=1; } if($gpsid =~ /${s}/){ $vajat[$id+50000]=$valiajat; $lahtoaika[$id+50000]=$laika; } } if($ok==0){exit;} #} close(SISAAN); # valiajat nyt muuttujassa $vajat[] $kilp=1; { open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); $ok=0; while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $s=','.$id.','; if($in{'kilp'} =~ /${s}/){ $kilp=$id; $viiva[$kilp]=$viivat; $rast[$kilp]=$rastit; $ok=1; } } } close(SISAAN); ## nyt on valiajat, reittipiirros ja rastipisteet selvillä ## nyt lasketaan animaatioille pisteet ## tämä pitäisi tehdä clientissä serveriä säästääksemme, mutta ## ei nyt jaksa javalla väsätä, ehkä sitten joskus $kilp=1; #while($in{"k".$kilp} ne''){ @kilp=split(/\,/,$in{'kilp'}); foreach $kilp (@kilp){ if($kilp ne ''){ if($viiva[$kilp] eq ''){ # ei ollut piirtänyt, tilalle suora reitti $viiva[$kilp]="N".$suorareitti{$srj{$kilp}}; $rast[$kilp]="N".$suorarastit{$srj{$kilp}}; #exit; } $aikasiirto=0; if($kilp<50000){ $out= ''.$lahtoaika[$kilp].';'.($lahtoaika[$kilp]-$laikaMin).'H'; @reitti=split(/N/,$viiva[$kilp]); @valiajat=split(/\;/,$vajat[$kilp]); @rastit=split(/N/,$rast[$kilp]); $i=0; $viiva[$kilp]=$viiva[$kilp]."N"; $viivatemp=""; foreach $rec (@rastit){ $i++; if($rec ne ""){ $j="NC".$i."N";$k="N".$rec."N"; ($temp,$viiva[$kilp])=split(/${k}/,$viiva[$kilp],2); $viiva[$kilp]="N".$viiva[$kilp]; $viivatemp=$viivatemp.$temp.$j; } } $viiva[$kilp]=$viivatemp; $i=0; foreach $rec (@rastit){ $i++;$j="NC".$i."N";$k="N".$rec.'|'.$rec."N"; $viiva[$kilp]=~ s/${j}/${k}/; } $viiva[$kilp]=~ s/^\|//; $viiva[$kilp]=~ s/NN/N/g; $viiva[$kilp]=~ s/NN/N/g; $viiva[$kilp]=~ s/NN/N/g; @rastivalit=split(/\|/,$viiva[$kilp]); $ulos=join("\n",@rastivalit); $i=0; $matkasiirto=0; foreach $rec (@rastivalit){ $rec=~ s/^N//; $matkasiirto=0; $i++; } $i_rastit=0; $i_reitti=0; $i_valiajat=0; $i_piste=0; $aika=0; $matka=0; while ($valiajat[$i_rastit] ne '' && ($i_rastit==0 || $valiajat[$i_rastit]>$valiajat[$i_rastit-1])){ $rastivalit[$i_rastit]=~ s/^N//; @viivab=split(/N/,$rastivalit[$i_rastit]); # lasketaan pituus $x0=0; $y0=0; $pituus=0; $i=0; $lisaaika=0; foreach $rec (@viivab){ ($x1,$y1)=split(/\;/,$rec); if($i>0){ $pituus=$pituus+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)); if($x0 == $x1 && $y0 == $y1){ ## 2 peräkkäistä klikkausta = pysähdys 3 sec $lisaaika=$lisaaika+3; } } $x0=$x1;$y0=$y1; $i++; } $valiaika=$valiajat[$i_rastit]-$valiajat[$i_rastit-1]; if($i_rastit==0){ $valiaika=$valiajat[$i_rastit]; } ## hyomioidaan pysähdykset $valiaika=$valiaika-$lisaaika; if($valiaika ==0 || $valiaika<0 ){ $valiaika=0.00001; } $step=($pituus/($valiaika/$raika)); $matkasiirto=$aikasiirto*$step; # pisteet polylinen varrelle $i=0;$seis=0; foreach $rec (@viivab){ ($x1,$y1)=split(/\;/,$rec); if($i>0){ if($x0 == $x1 && $y0 == $y1){ $seis++; ## ei kahta peräkkäistä klikkausta samaan pisteeseen }else{ $plkm=1; while($matka+$step*$plkm-$matkasiirto < $matka+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1))){ $i_piste++; #lasketaan animaatioreittipiste $ax=floor((($step*$plkm-$matkasiirto)*$x1+$x0*(sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1))-($step*$plkm-$matkasiirto)))/(sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)))); $ay=floor((($step*$plkm-$matkasiirto)*$y1+$y0*(sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1))-($step*$plkm-$matkasiirto)))/(sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)))); $info=""; $out.= "$ax;".$ay.",".$info."N"; if($seis > 0){ for($ii=0;$ii<$seis;$ii++){ $out.= "$ax;$ay,".$info."N"; } $seis=0; } $plkm++; } $matkasiirto=$matka+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1))-($matka+$step*($plkm-1)-$matkasiirto); $matka=$matka+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)); $aikasiirto=$matkasiirto/$step*1; } } $x0=$x1;$y0=$y1; $i++; } $i_rastit++; } }else{ ## gps animaatip #$out.= "0;0;0,0N"; $out= ''.$lahtoaika[$kilp].';'.($lahtoaika[$kilp]-$laikaMin).'H'; $out.= $gpsani[$kilp]; #!!! duke $out.= "H".$trackicon[$kilp]; } $out=~ s/\r//g; $out=~ s/\n/N/g; #foreach $rasti (split(/N/,$rpisteet{$kilp})){ #$out =~ s/N${rasti}\,N/N${rasti},N${rasti}\,NCN/; #} if($out =~/\0){print ",";} print $out{$id}; $count++; } } print "]\n"; exit; } if($in{'act'} eq 'jskommentit'){ $in{'eventid'}=1*$in{'eventid'}; open (SISAAN,"<$path"."kommentit_$in{'eventid'}.txt"); @kommentit=; close(SISAAN); $in{'kilp'}=','.$in{'kilp'}.','; $i=0; foreach $rec (@kommentit) { chomp($rec); ($idkilp,$id,$nimi,$aika,$kommentit)=split(/\|/,$rec); $i++; $s=','.${id}.','; if($in{'kilp'}=~ /${s}/){ $kommentit =~ s/#nl#/\\n/g; $kommentit =~ s/#cr#//g; $out{$id}= "{\"$#out\":\"\\n\\n$nimi:\\n".$kommentit."
\"}"; } } ### print "["; $count=0; foreach $id ((split(/\,/,$in{'kilp'}))){ if($out{$id} ne ''){ if($count>0){print ",";} print $out{$id}; $count++; } } print "]\n"; exit; } ################################################### if ($in{"act"} eq "splitsbrowserjs"){ open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); $viesti=0; foreach $rec (@kartat) { chomp($rec); ($id,$karttaid,$tyyppi,$nimi)=split(/\|/,$rec); if($id==$in{'id'}){ $eventname='SplitsBrowser - '.$nimi; } } open (SISAAN,"<$path/../splitsbrowser/splits-graph-template.html"); @page=; close(SISAAN); $page=join('',@page); $dataurl='reitti.cgi?act=splitsbrowsercsv&id='.$in{'id'}; $s='url/to/some/event/data'; $page=~ s/${s}/${dataurl}/gi; $page=~ s/Page title/${eventname}/i; $page=~ s/#httppath#/${httppath}/gi; print $page; exit; } ################ ratapisteet #################### if ($in{"act"} eq "jsratapisteet"){ ## tästä appletti kysyy radan ratapiirrokset open (SISAAN,"<$path"."ratapisteet_".$in{'eventid'}.".txt"); while (defined ($rec = )) { chomp($rec); ($id,$pisteet)=split(/\|/,$rec); $pisteet=~ s/\r//g; $pisteet=~ s/\n//g; if ($in{"course"} == $id ){ print "[{\"1\":\"$pisteet\"}]\n"; } } close(SISAAN); exit; } ############################### if($in{'act'} eq 'jsvaliajat'){ $sarja=1*$in{'sarja'}; $eventid=$in{'eventid'}*1; $gpsid=','; @temp=split(/\,/,$in{'kilp'}); foreach $rec (@temp){ if($rec > 50000){ $rec=$rec-50000; $gpsid.=$rec.','; } } $in{'kilp'}=','.$in{'kilp'}.','; $kilp=','.join(',',@temp).','; $nro=1;$otsikko=">>SplitsBrowser"; open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarjanimi,$nimi,$laika,$aika,$sija,$tulos,$valiajat)=split(/\|/,$rec); $s=','.${id}.','; if($kilp=~ /${s}/){#$id eq $in{'k'.$nro} && @splits=split(/\;/,$valiajat); if($in{'kilp'} =~ /${s}/){ $old=0; if($nro==1){ $i=1; } $j=-1; $nimi=~ s/ /\ \;/g; $ulos="".$nimi.""; foreach $rec (@splits){ chomp($rec); if($nro==1){ $otsikko=$otsikko."".$i.""; $i++; } $j++; $min=floor(($rec-$old)/60); $sec=($rec-$old)-60*floor(($rec-$old)/60); if ($sec <10){$sec='0'.$sec;} $old=$rec; $ulos=$ulos."$min.$sec"; } if($nro==1){ $out.= "$otsikko\n"; } $out.= "$ulos"; if($i==$j){ $out.= "$nimi\n"; } $nro++; }## nogps if($gpsid =~ /${s}/){ $old=0; if($nro==1){ $i=1; } $j=-1; $nimi=~ s/ /\ \;/g; $ulos="GPS ".$nimi.""; foreach $rec (@splits){ chomp($rec); if($nro==1){ $otsikko=$otsikko."".$i.""; $i++; } $j++; $min=floor(($rec-$old)/60); $sec=($rec-$old)-60*floor(($rec-$old)/60); if ($sec <10){$sec='0'.$sec;} $old=$rec; $ulos=$ulos."$min.$sec"; } if($nro==1){ $out.= "$otsikko\n"; } $out.= "$ulos"; if($i==$j){ $out.= "GPS $nimi\n"; } } $nro++; } } close(SISAAN); #$out.= "$otsikko\n"; #$out.= "\n Route lengths (in pixels) \n"; #$out.= "$otsikko------\n"; ### open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); $viesti=0; foreach $rec (@kartat) { chomp($rec); ($id,$karttaid,$tyyppi,$nimi)=split(/\|/,$rec,4); if($id==$in{'eventid'} && $tyyppi ==3){ $viesti=1; } } $kilp=1; { open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); $ok=0; while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $s=','.${id}.','; if($id < 50000 && $in{'kilp'}=~ /${s}/){ $viiva[$kilp]=$viivat; $rast[$kilp]=$rastit; $nim[$kilp]=$nimi; $ok=1; } } close(SISAAN); } ## nyt onreittipiirros ja rastipisteet selvillä $kilp=1; while($in{"k".$kilp} ne''){ if($viiva[$kilp] ne ''){ $out.= substr($nim[$kilp]." ",0,20); if($in{"k".$kilp}<100000){ @reitti=split(/N/,$viiva[$kilp]); @rastit=split(/N/,$rast[$kilp]); $i=0; $viiva[$kilp]=$viiva[$kilp]."N"; $viivatemp=""; foreach $rec (@rastit){ $i++; if($rec ne ""){ $j="NC".$i."N";$k="N".$rec."N"; ($temp,$viiva[$kilp])=split(/${k}/,$viiva[$kilp],2); $viiva[$kilp]="N".$viiva[$kilp]; $viivatemp.=$temp.$j; } } $viiva[$kilp]=$viivatemp; $i=0; foreach $rec (@rastit){ $i++;$j="NC".$i."N";$k="N".$rec.'|'.$rec."N"; $viiva[$kilp]=~ s/${j}/${k}/; } $viiva[$kilp]=~ s/^\|//; $viiva[$kilp]=~ s/NN/N/g; $viiva[$kilp]=~ s/NN/N/g; $viiva[$kilp]=~ s/NN/N/g; @rastivalit=split(/\|/,$viiva[$kilp]); $ulos=join("\n",@rastivalit); $i=0; foreach $rec (@rastivalit){ $rec=~ s/^N//; } $i_rastit=0; $i_reitti=0; $i_piste=0; $aika=0; $matka=0; $totpit=0; foreach $rc (@rastivalit){ $rastivalit[$i_rastit]=~ s/^N//; @viivab=split(/N/,$rastivalit[$i_rastit]); # lasketaan pituus $x0=0; $y0=0; $pituus=0; $i=0; foreach $rec (@viivab){ ($x1,$y1)=split(/\;/,$rec); if($i>0){ $pituus=$pituus+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)); }else{ $alkux=$x1;$alkuy=$y1; } $x0=$x1;$y0=$y1; $i++; } if($alkux !=$x1 && $alkuy !=$y1){ #print substr((floor($pituus/sqrt(($alkux-$x1)*($alkux-$x1)+($alkuy-$y1)*($alkuy-$y1))*1000)/10).' ',0,5).' '; #print substr((($pituus-sqrt(($alkux-$x1)*($alkux-$x1)+($alkuy-$y1)*($alkuy-$y1)))).' ',0,5).' '; #$out.= substr(floor($pituus).' ',0,5).' '; $totpit+=$pituus; }else{ #$out.= ' '; } $i_rastit++; } } #$out.= ' '.floor($totpit).' '.$nim[$kilp]."\n"; }else{ #print "\n"; } } ### $out=~ s/\"//g; $out=~ s/\n//g; print "[{\"1\":\"$out
\"}]\n"; exit; } sub uniq { my %seen = (); my @r = (); foreach my $a (@_) { unless ($seen{$a}) { push @r, $a; $seen{$a} = 1; } } return @r; } # ImageSize.pl # # This code is Copyright 2003,2007 Tony Lewis . # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see http://www.gnu.org/licenses/. # ################################################################################ # Return the size of an image (width, height) # # my ($width, $height, $format) = ImageSize($filePath) # # If the return values are negative, an error occurred. Each combination of # values indicates a specific error. # # The first number indicates an open error or which image type failed: # -1 open or read header of image file failed # -2 GIF failure # -3 JPG failure # -4 BMP failure # -5 PNG failure # # The second number indicates the specific error that occurred. (See the code # for the meanings of the various combinations. # ################################################################################ sub ImageSize { my ($path) = @_; my ($w, $h, $w1, $w2, $w3, $w4, $h1, $h2, $h3, $h4, $header, $marker, $skip, $len, $len1, $len2); # Guess the format from the file extension my ($format) = $path =~ m/\.(...)$/; $format = lc($format); open IMGSIZEF, "$path" or return (-1,-1,$format); # Override the guessed format if header indicates the type of file return ImageSizeCloseF(-1,-2,$format) if read(IMGSIZEF, $header, 8) < 8; $format = "gif" if substr($header,0,6) eq "GIF87a" || substr($header,0,6) eq "GIF89a"; $format = "jpg" if substr($header,0,2) eq "\xff\xd8"; $format = "bmp" if substr($header,0,2) eq "BM"; $format = "png" if substr($header,0,8) eq "\x89PNG\r\n\x1A\n"; seek(IMGSIZEF,0,0); ############ GIF if ($format eq "gif") { return ImageSizeCloseF(-2,-1,$format) if read(IMGSIZEF, $header, 6) < 6; return ImageSizeCloseF(-2,-2,$format) if $header ne "GIF87a" && $header ne "GIF89a"; return ImageSizeCloseF(-2,-3,$format) if read(IMGSIZEF, $w1, 1) < 1; return ImageSizeCloseF(-2,-4,$format) if read(IMGSIZEF, $w2, 1) < 1; return ImageSizeCloseF(-2,-5,$format) if read(IMGSIZEF, $h1, 1) < 1; return ImageSizeCloseF(-2,-6,$format) if read(IMGSIZEF, $h2, 1) < 1; return ImageSizeCloseF(ord($w2) * 256 + ord($w1), ord($h2) * 256 + ord($h1),$format); ############ JPG } elsif ($format eq "jpg") { return ImageSizeCloseF(-3,-1,$format) if read(IMGSIZEF, $header, 2) < 2; return ImageSizeCloseF(-3,-2,$format) if $header ne "\xff\xd8"; # SOI marker while (1) { return ImageSizeCloseF(-3,-3,$format) if read(IMGSIZEF, $header, 1) < 1 || ord($header) != 0xFF; return ImageSizeCloseF(-3,-4,$format) if read(IMGSIZEF, $marker, 1) < 1; return ImageSizeCloseF(-3,-5,$format) if read(IMGSIZEF, $len1, 1) < 1; return ImageSizeCloseF(-3,-6,$format) if read(IMGSIZEF, $len2, 1) < 1; $len = ord($len1) * 256 + ord($len2) - 2; if (ord($marker) < 0xC0 || ord($marker) > 0xCA || ord($marker) == 0xC4 || ord($marker) == 0xC8 || ord($marker) == 0xCC) { return ImageSizeCloseF(-3,-7,$format) if read(IMGSIZEF, $skip, $len) < $len; } else { return ImageSizeCloseF(-3,-8,$format) if read(IMGSIZEF, $skip, 1) < 1; # precision return ImageSizeCloseF(-3,-9,$format) if read(IMGSIZEF, $h1, 1) < 1; return ImageSizeCloseF(-3,-10,$format) if read(IMGSIZEF, $h2, 1) < 1; return ImageSizeCloseF(-3,-11,$format) if read(IMGSIZEF, $w1, 1) < 1; return ImageSizeCloseF(-3,-12,$format) if read(IMGSIZEF, $w2, 1) < 1; return ImageSizeCloseF(ord($w1) * 256 + ord($w2), ord($h1) * 256 + ord($h2),$format); } } ############ BMP } elsif ($format eq "bmp") { return ImageSizeCloseF(-4,-1,$format) if read(IMGSIZEF, $header, 2) < 2; return ImageSizeCloseF(-4,-2,$format) if $header ne "BM"; return ImageSizeCloseF(-4,-3,$format) if read(IMGSIZEF, $skip, 12) < 12; # rest of the BMP file header return ImageSizeCloseF(-4,-4,$format) if read(IMGSIZEF, $skip, 4) < 4; # Bitmap Header: length return ImageSizeCloseF(-4,-5,$format) if read(IMGSIZEF, $w1, 1) < 1; return ImageSizeCloseF(-4,-6,$format) if read(IMGSIZEF, $w2, 1) < 1; return ImageSizeCloseF(-4,-7,$format) if read(IMGSIZEF, $w3, 1) < 1; return ImageSizeCloseF(-4,-8,$format) if read(IMGSIZEF, $w4, 1) < 1; return ImageSizeCloseF(-4,-9,$format) if read(IMGSIZEF, $h1, 1) < 1; return ImageSizeCloseF(-4,-10,$format) if read(IMGSIZEF, $h2, 1) < 1; return ImageSizeCloseF(-4,-11,$format) if read(IMGSIZEF, $h3, 1) < 1; return ImageSizeCloseF(-4,-12,$format) if read(IMGSIZEF, $h4, 1) < 1; return ImageSizeCloseF(ord($w4) * (256**3) + ord($w3) * (256**2) + ord($w2) * 256 + ord($w1), ord($h4) * (256**3) + ord($h3) * (256**2) + ord($h2) * 256 + ord($h1),$format); ############ PNG } elsif ($format eq "png") { return ImageSizeCloseF(-5,-1,$format) if read(IMGSIZEF, $header, 8) < 8; return ImageSizeCloseF(-5,-2,$format) if $header ne "\x89PNG\r\n\x1A\n"; return ImageSizeCloseF(-5,-3,$format) if read(IMGSIZEF, $skip, 4) < 4; # length of the IHDR chunk return ImageSizeCloseF(-5,-4,$format) if read(IMGSIZEF, $skip, 4) < 4; # chunk type return ImageSizeCloseF(-5,-5,$format) if $skip ne "IHDR"; return ImageSizeCloseF(-5,-6,$format) if read(IMGSIZEF, $w1, 1) < 1; return ImageSizeCloseF(-5,-7,$format) if read(IMGSIZEF, $w2, 1) < 1; return ImageSizeCloseF(-5,-8,$format) if read(IMGSIZEF, $w3, 1) < 1; return ImageSizeCloseF(-5,-9,$format) if read(IMGSIZEF, $w4, 1) < 1; return ImageSizeCloseF(-5,-10,$format) if read(IMGSIZEF, $h1, 1) < 1; return ImageSizeCloseF(-5,-11,$format) if read(IMGSIZEF, $h2, 1) < 1; return ImageSizeCloseF(-5,-12,$format) if read(IMGSIZEF, $h3, 1) < 1; return ImageSizeCloseF(-5,-13,$format) if read(IMGSIZEF, $h4, 1) < 1; return ImageSizeCloseF(ord($w1) * (256**3) + ord($w2) * (256**2) + ord($w3) * 256 + ord($w4), ord($h1) * (256**3) + ord($h2) * (256**2) + ord($h3) * 256 + ord($h4),$format); } return ImageSizeCloseF(-1, -3,$format); } sub ImageSizeCloseF { close IMGSIZEF; return @_; } ################################# if($in{'act'} eq "jsstrk"){ open (HANDLE,"<".$path."kilpailijat_$in{'eventid'}.txt"); @d=; close HANDLE; if($in{'etype'} eq '2'){ ## if add mode ## get ID foreach $rec (@d){ ($id,$rest)=split(/\|/,$rec,2); if($id>50000){$id=$id-50000;} if($in{'id'} < $id){$in{'id'}=$id;} } $in{'id'}=(1*$in{'id'})+1; }else{ ## read original version of name, to avoid some charset trouble foreach $rec (@d){ @r=split(/\|/,$rec); if($in{'id'} == $r[0] && $r[3] ne ''){$in{'suunnistaja'}=$r[3];} } } ## input $in{'suunnistaja'}=~ s/#chsmcl#/\;/g; $in{'suunnistaja'}=~ s/#chnd#/\&/g; $success = utf8::downgrade($in{'komm'}, FAIL_OK); $in{'komm'}=~ s/#chsmcl#/\;/g; $in{'komm'}=~ s/#chnd#/\&/g; ## gps if($in{'GPS'}==1){ # !!! duke # $in{'suunnistaja'}=' GPS '.$in{'suunnistaja'}; $in{'suunnistaja'}=$in{'suunnistaja'}; $in{'id'}=50000+$in{'id'}; } open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); @merkinnat=; close(SISAAN); $ok=1; foreach $rec (@merkinnat) { chomp($rec); ($idkilp,$id,$nimi,$hajonta,$viivat,$rastit)=split(/\|/,$rec); if($id eq $in{'id'}){ $ok=0; ## eli piirros oli jo olemassa, ei tallenneta } } $in{'track'} =~ s/\n//g; $in{'track'} =~ s/\r//g; ($reitti,$rastit)=split(/\|/,$in{'track'}); if($ok == 1){ if($in{'GPS'}!=1){ open (HANDLE,">>".$path."merkinnat_$in{'eventid'}.txt"); $out=''.$in{'rataid'}."|".$in{'id'}."| $in{'suunnistaja'}|$in{'hajonta'}|$reitti|$rastit"; $out =~ s/\n//g; $out =~ s/\r//g; &lock_file; print HANDLE $out."\n"; &unlock_file; close HANDLE; }else{ @GPSD=split(/N/,$reitti); $reitti=''; foreach $gd (@GPSD){ chomp($gd); if($gd ne ''){ ($Gx,$Gy,$Gt)=split(/\;/,$gd); if($Gx ne $GxOLD || $Gy ne $GyOLD){ $reitti.='N'.$Gx.';'.$Gy; $GxOLD=$Gx; $GyOLD=$Gy; } } } $reitti.='|'; ## gps animaatio $GAIKA=0;$ani='';$i=0; foreach $gd (@GPSD){ chomp($gd); if($gd ne ''){ ($Gx,$Gy,$Gt)=split(/\;/,$gd); if($i%3==1){ $ani.=$Gx.';'.$Gy.',0N'; } $i++; } } open (HANDLE,">>".$path."merkinnat_$in{'eventid'}.txt"); &lock_file; print HANDLE $in{'rataid'}."|".$in{'id'}."| $in{'suunnistaja'}|$in{'hajonta'}|$reitti|$rastit\n"; &unlock_file; close HANDLE; #!!! duke open (HANDLE,">>".$path."gpsstarttimes_$in{'eventid'}.txt"); $in{'gpsstarttime'}=1*$in{'gpsstarttime'}; if(substr($in{'suunnistaja'},0,2) eq 'ÊÏ' || $in{'rataid'}==2) {$trackicon=2;} else {$trackicon=1;} print HANDLE $in{'id'}."|".$in{'gpsstarttime'}."|".$trackicon."\n"; close HANDLE; } $in{'komm'}=~ s/\n/#nl#/g; $in{'komm'}=~ s/\r/#cr#/g; $out=$in{'rataid'}."|".$in{'id'}."|$in{'suunnistaja'}||$in{'komm'}"; $out =~ s/\n//g; $out =~ s/\r//g; open (HANDLE,">>".$path."kommentit_$in{'eventid'}.txt"); &lock_file; print HANDLE $out."\n"; &unlock_file; close HANDLE; if($in{'etype'} eq '2' || $in{'GPS'}==1){ ## if add mode if($in{'GPS'}!=1){ ## leg lengths ($pois,$lahto,$muut)=split(/N/,$reitti,3); $sLength=0; @aControls=split(/N/,($lahto.$rastit)); $ai=0; foreach $aControl (@aControls){ $ai++; if($ai>1){ ($ax1,$ay1)=split(/\;/,$aControls[$ai-2]); ($ax2,$ay2)=split(/\;/,$aControls[$ai-1]); $aleg[$ai-1]=sqrt(($ax1-$ax2)*($ax1-$ax2)+($ay1-$ay2)*($ay1-$ay2)); # Pythagoras } } ## $usersplits=''; $splitnro=0;$splitmissing=0; @splits=split(/m/,$in{'usersplits'}); foreach $split (@splits){ $splitnro++; ($min,$sec)=split(/s/,$split); if(floor(60*$min+(1*$sec))>0 && $splitmissing==0){ $usersplits.=floor(60*$min+(1*$sec)).';'; $fsplit=floor(60*$min+(1*$sec)); } if(floor(60*$min+(1*$sec))==0){# a split is missing if($splitmissing==0){ $splitmissing=$splitnro; } } if(floor(60*$min+(1*$sec))>0 && $splitmissing>0){ # there has been missing split before this split $sLength=0; for($j=$splitmissing;$j<$splitnro+1;$j++){ $sLength=$sLength+$aleg[$j]; } $averagespeed=(floor(60*$min+(1*$sec))-$lastsplit)/$sLength; $sLength=0; for($j=$splitmissing;$j<$splitnro+1;$j++){ $sLength=$sLength+$aleg[$j]; $usersplits.=floor($lastsplit+$sLength*$averagespeed).';'; } $splitmissing=0; $lastsplit=floor(60*$min+(1*$sec)); } } $result=$min.':'.$sec; }# if gps!=1 if($in{'GPS'}==1){ $GPSani=$ani; } $out=$in{'id'}."|".$in{'rataid'}."||$in{'suunnistaja'}|0||$in{'hajonta'}|$result|$usersplits|$GPSani"; open (HANDLE,">>".$path."kilpailijat_$in{'eventid'}.txt"); $out =~ s/\n//g; $out =~ s/\r//g; &lock_file; print HANDLE $out."\n"; &unlock_file; close HANDLE; } } print "\n"; exit; } #!!! duke MASS LOAD TRACKS ################################# if($in{'act'} eq "massloadtrk"){ ## get map parameters open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); foreach $rec (@kartat) { chomp($rec); @r=split(/\|/,$rec,8); if($r[0] eq $in{'eventid'}){ ($eventid,$karttaid,$tyyppi,$nimi,$paiva,$seura,$taso,$notes)=split(/\|/,$rec,8); $eventname=$paiva.' '.$nimi; } } ($imwidth, $imheight, $format) = ImageSize($path.$karttaid.'.jpg'); $in{'calibtype'} = 'manual'; $GPSMODE=0; if($in{'calibtype'} eq 'manual'){ $GPSMODE=1; ### pre calibrated map parameters open(HANDLE, "<".$path."kartat.txt")|| die; @kdata=; close(HANDLE); $coord[0]=''; $coord[4]=''; foreach $rec (@kdata){ chomp($rec); ($mapid,$mapname)=split(/\|/,$rec); if($karttaid eq $mapid){ ($a,$b,$c,$s1x,$o1x,$s1y,$o1y,$s2x,$o2x,$s2y,$o2y,$s3x,$o3x,$s3y,$o3y)=split(/\|/,$rec); if($o1x != 0){ $s1y=-$s1y; $s2y=-$s2y; $s3y=-$s3y; $lat0=$o1y; $lon0=$o1x; $kaavao1y=$o1y; $kaavao1x=$o1x; $r=6370000; $pi=3.1415926535897932384626433832795; $lat=$o1y; $lon=$o1x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o1y=$north; $o1x=$east; $lat=$o2y; $lon=$o2x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o2y=$north; $o2x=$east; $lat=$o3y; $lon=$o3x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o3y=$north; $o3x=$east; $xnolla1=$o1x; $ynolla1=$o1y; $xi=$o2x-$xnolla1;$yi=$o2y-$ynolla1;$xj=$o3x-$xnolla1;$yj=$o3y-$ynolla1; $xnolla=$s1x; $ynolla=$s1y; $x1 = $s2x-$xnolla;$y1 = $s2y-$ynolla;$x2 = $s3x-$xnolla;$y2 = $s3y-$ynolla; #nollalla jakamisen esto if($xj==0){$xj=0.000000000001;} if($yj==0){$yj=0.000000000001;} if(($xj * $yi - $yj * $xi)==0){$xj=$xj+0.000000000001;} if(($yj * $xi - $xj * $yi)==0){$yj=$yj+0.0000000000001;} $Gb = ($x1 * $xj - $x2 * $xi) / ($xj * $yi - $yj * $xi); $Ga = ($x2 - $Gb * $yj) / $xj; $Gd = ($y1 * $yj - $y2 * $yi) / ($yj * $xi - $xj * $yi); $Gc = ($y2 - $Gd * $xj) / $yj; } } } } ### get map parameters end open (HANDLE,"<".$path."kilpailijat_$in{'eventid'}.txt"); @d=; close HANDLE; ## get ID foreach $rec (@d){ ($id,$rest)=split(/\|/,$rec,2); if($id>50000){$id=$id-50000;} if($in{'id'} < $id){$in{'id'}=$id;} } $in{'id'}=(1*$in{'id'})+1; ## input $tracks_path='../tracks/'; $overwritetracks=1; $in{'suunnistaja'}=''; $in{'komm'}=''; $in{'rataid'}=0; $in{'hajonta'}=''; $result=''; $usersplits=''; $in{'gpsstarttime'}=0; $rastit=''; ## gps $in{'id'}=50000+$in{'id'}; open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); @merkinnat=; close(SISAAN); $out_merkinnat=''; $out_gpsstarttime=''; $out_komm=''; $out_kilpailijat=''; $lat0=-987654; $tracknum=1; # print "id: ".$in{'id'}."
\n"; @filesarr=(); opendir(DIR, $tracks_path); while ($file_name = readdir(DIR) ) { if($file_name eq '.' || $file_name eq '..') {next;} @extension=split(/\./,$file_name); if($extension[$#$extension] ne 'gpx') {next;} push(@filesarr,$file_name); } @filesarr = sort(@filesarr); foreach $file_name (@filesarr) { if($file_name eq '.' || $file_name eq '..') {next;} @extension=split(/\./,$file_name); if($extension[$#$extension] ne 'gpx') {next;} $file_name1=''; foreach my $i (0 .. ($#extension-1)) { if($i!=0) {$file_name1.='.';} $file_name1.=$extension[$i]; } $in{'suunnistaja'}=$file_name1; print $file_name."..."; #!!! duke $gpsstarttime=0; #################### track log processing $pi=3.1415926535897932384626433832795; open(HANDLE, "<".$tracks_path.$file_name); binmode HANDLE; @d =; close(HANDLE); $d= join('',@d); #!!! duke #open(XXHANDLE,">>"."$path/222.txt"); $GPSparam=''; if($d =~ /\'); $p2=index($point,''); if($p1>-1 && $p2>-1){ # $tim=substr($point,$p1+6,$p2-$p1-6); $tim=~ s/Z//g; $tim=~ s/\-/\:/g; $tim=~ s/T/\:/g; ($tyear,$tmon,$tday,$thour,$tmin,$tsec)=split(/\:/,$tim); $tim=3600*$thour+60*$tmin+$tsec; $day=$tyear.'_'.$tmon.'_'.$tday; if(($tim+$RG_TIME_ZONE_OFFSET)<$RG_TRACK_CUT_START || ($tim+$RG_TIME_ZONE_OFFSET)>$RG_TRACK_CUT_END) { next; } } $p1=index($point,"lat=\""); $p2=index($point,"\"",$p1+6); if($p1>-1 && $p2>-1){ $lat=substr($point,$p1+5,$p2-$p1-5); $lat =~ s/ //g; $lat =~ s/\"//g; } $p1=index($point,"lon=\""); $p2=index($point,"\"",$p1+6); if($p1>-1 && $p2>-1){ $lon=substr($point,$p1+5,$p2-$p1-5); $lon =~ s/ //g; $lon =~ s/\"//g; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $alt=substr($point,$p1+4,$p2-$p1-4); $alt =~ s/ //g; $alt=1*$alt; } if($lat!=-9999999 && $lon !=-9999999){ $count++; if($trackstart) { $trackstart=0; if($lat0==-987654){ $lat0=$lat; $lon0=$lon; } $daycount=0; $tim0=$tim; $day0=$day; #!!! duke $gpsstarttime=$tim0; } #!!! duke #print XXHANDLE "$lat, $lon, $lat0, $lon0\r\n"; ## this not very scientific, byt must do for now ... $r=6370000; $northing=-floor(($lat-$lat0)/360*2*$pi*$r*100)/100; $easting=floor(($lon-$lon0)/360*2*$r*$pi *cos(abs($lat0)/180*$pi)*100)/100; #!!! duke #print XXHANDLE "$northing, $easting\r\n"; if($day0 ne $day){ $day0 == $day; $daycount++; } $tim=$tim+$daycount*60*60*24-$tim0; if($Ga ne ''){ #($lon,$lat)=($lat,$lon); $lat0=$kaavao1y; $lon0=$kaavao1x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $easting = floor(100*($s1x+ ((($Ga*($east-$xnolla1) + $Gb*($north-$ynolla1))))))/100; $northing= -floor(100*($s1y+ ((($Gc*($north-$ynolla1) + $Gd*($east-$xnolla1))))))/100; #!!! duke #print XXHANDLE "$north, $east\r\n"; #print XXHANDLE "$northing, $easting\r\n---\r\n"; } $GPSparam.="$tim,$easting,$northing;"; if($mineast>$easting){$mineast=$easting;} if($maxeast<$easting){$maxeast=$easting;} if($minnorth>$northing){$minnorth=$northing;} if($maxnorth<$northing){$maxnorth=$northing;} } } @ad=split(/\;/,$GPSparam); $GPSparam=''; foreach $pt (@ad){ @r=split(/\,/,$pt); if( $r[0]>$edtim){ if($edtim ne '' && $edtim +1 < $r[0] ){ for($i=$edtim+1;$i<$r[0];$i++){ $tim=$i; $easting=floor(100*(($i-$edtim)/($r[0]-$edtim)*$r[1]+($r[0]-$i)/($r[0]-$edtim)*$edeast))/100; $northing=floor(100*(($i-$edtim)/($r[0]-$edtim)*$r[2]+($r[0]-$i)/($r[0]-$edtim)*$ednorth))/100; $GPSparam.="$tim,$easting,$northing;"; } } $GPSparam.=join(',',@r).";"; } $edtim=$r[0]; $edeast=$r[1]; $ednorth=$r[2]; } } # GPX if($GPSparam eq '') {print "Not GPX file.
\n"; next;} #!!! duke #close XXHANDLE; if($Ga eq ''){ # not if map is geo-referenced ### scale it to the center of the map $gpsdata=''; @d=split(/\;/,$GPSparam); if($tracknum==1) { $size=$imheight/($maxnorth-$minnorth); $side=$imheight; if($imwidth/($maxeast-$mineast)<$size){ $size=$imwidth/($maxeast-$mineast); $side=$imwidth; } } foreach $rec (@d){ ($t,$e,$n)=split(/\,/,$rec); # $e=floor(($side*0.1+($e-$mineast)*$size*0.8)*100)/100; # $n=floor(($side*0.1+($n-$minnorth)*$size*0.8)*100)/100; #$e=floor(($side*0.1+$e)*100)/100; #$n=floor(($side*0.1+$n)*100)/100; $gpsdata.="$t,$e,$n;"; } $GPSparam=$gpsdata; } $in{'gpsstarttime'}=$gpsstarttime; if(substr($in{'suunnistaja'},0,2) eq 'ÊÏ' || substr($in{'suunnistaja'},0,5) eq 'Ôèíèø') {$trackicon=2; $in{'rataid'}=2;} else {$trackicon=1; $in{'rataid'}=1;} @GPSD=split(/\;/,$GPSparam); $reitti=''; foreach $gd (@GPSD){ chomp($gd); if($gd ne ''){ ($Gt,$Gx,$Gy)=split(/\,/,$gd); $reitti.='N'.round($Gx).';'.-round($Gy).';'.$Gt; } } @GPSD=split(/N/,$reitti); $reitti=''; foreach $gd (@GPSD){ chomp($gd); if($gd ne ''){ ($Gx,$Gy,$Gt)=split(/\;/,$gd); if($Gx ne $GxOLD || $Gy ne $GyOLD){ $reitti.='N'.$Gx.';'.$Gy; $GxOLD=$Gx; $GyOLD=$Gy; } } } $reitti.='|'; ## gps animaatio $GAIKA=0;$ani='';$i=0; foreach $gd (@GPSD){ chomp($gd); if($gd ne ''){ ($Gx,$Gy,$Gt)=split(/\;/,$gd); if($i%3==1){ $ani.=$Gx.';'.$Gy.',0N'; } $i++; } } $out_merkinnat.=$in{'rataid'}."|".$in{'id'}."| $in{'suunnistaja'}|$in{'hajonta'}|$reitti|$rastit\n"; #!!! duke $in{'gpsstarttime'}=1*$in{'gpsstarttime'}; $out_gpsstarttime.=$in{'id'}."|".$in{'gpsstarttime'}."|".$trackicon."\n"; $in{'komm'}=~ s/\n/#nl#/g; $in{'komm'}=~ s/\r/#cr#/g; $out=$in{'rataid'}."|".$in{'id'}."|$in{'suunnistaja'}||$in{'komm'}"; $out =~ s/\n//g; $out =~ s/\r//g; $out_komm.=$out."\n"; $GPSani=$ani; $out=$in{'id'}."|".$in{'rataid'}."||$in{'suunnistaja'}|0||$in{'hajonta'}|$result|$usersplits|$GPSani"; $out =~ s/\n//g; $out =~ s/\r//g; $out_kilpailijat.=$out."\n"; print "id ".$in{'id'}."...OK
\n"; # print "
".$in{'gpsstarttime'}."---".$reitti."\n
".$GPSani."

\n\n"; $in{'id'}++; $tracknum++; } # exit; if($overwritetracks) {open (HANDLE,">".$path."merkinnat_$in{'eventid'}.txt");} else {open (HANDLE,">>".$path."merkinnat_$in{'eventid'}.txt");} &lock_file; print HANDLE $out_merkinnat; &unlock_file; close HANDLE; #!!! duke if($overwritetracks) {open (HANDLE,">".$path."gpsstarttimes_$in{'eventid'}.txt");} else {open (HANDLE,">>".$path."gpsstarttimes_$in{'eventid'}.txt");} $in{'gpsstarttime'}=1*$in{'gpsstarttime'}; print HANDLE $out_gpsstarttime; close HANDLE; if($overwritetracks) {open (HANDLE,">".$path."kommentit_$in{'eventid'}.txt");} else {open (HANDLE,">>".$path."kommentit_$in{'eventid'}.txt");} &lock_file; print HANDLE $out_komm; &unlock_file; close HANDLE; if($overwritetracks) {open (HANDLE,">".$path."kilpailijat_$in{'eventid'}.txt");} else {open (HANDLE,">>".$path."kilpailijat_$in{'eventid'}.txt");} &lock_file; print HANDLE $out_kilpailijat; &unlock_file; close HANDLE; print "\n"; exit; } #!!! duke MASS LOAD TRACKS END #################### rgjs section ends############################# ##################### Version #############################3 if($in{'act'} eq 'version'){ print $RG_version; exit; } ##################### OGraphAppletJar #############################3 if($in{'act'} eq 'OGraphAppletJar'){ open(SISAAN, "<".$path."EmitGraph3.jar"); binmode SISAAN; @data=; close(SISAAN); binmode STDOUT; print @data; exit; } ##################### OGraphApplet #############################3 if($in{'act'} eq 'OGraphApplet'){ print " OGraphApplet on RouteGadget
"; #EmitGraph3.jar open(SISAAN, "<".$path."kisat.txt"); @kilpailut=; close(SISAAN); $i=0; foreach $rec (@kilpailut){ chomp($rec); @field=split(/\|/,$rec); if($field[2] != 3){ $i++; print " \n"; } } print"
"; exit; } ##################### OGraphAppletSplits #############################3 if($in{'act'} eq 'ographsplits'){ $in{'id'}=1*$in{'id'}; open(SISAAN, "<".$path."kilpailijat_$in{'id'}.txt"); @data=; close(SISAAN); @data = sort { (split '\|', $a, 9)[1] <=> (split '\|', $b, 9)[1] } @data; $sarja=''; foreach $rec (@data){ chomp($rec); @field=split(/\|/,$rec); if($sarja ne $field[2]){ $sarja=$field[2]; print "#Sarja $sarja\n"; } # $field[8] =~ s/\;/\|/g; if($field[8] ne '' && $field[5]>0){ @row=split(/\;/,$field[8]); print " $field[3]|"; foreach $sp (@row){ $sec=floor(60*($sp/60-floor($sp/60))); if($sec<10){$sec='0'.$sec;} $hou=''; $min=floor($sp/60); if($min>59){ $hou=floor($min/60); $min=$min-$hou*60; if($hou<10){$hou='0'.$hou;} if($min<10){$min='0'.$min;} } print ''.$hou.$min.$sec.'|'; } print "\n"; } } } ##################### splitsbrowserjar #############################3 if($in{'act'} eq 'splitsbrowserJar'){ open(SISAAN, "<".$path."splitsbrowser.jar"); binmode SISAAN; @data=; close(SISAAN); binmode STDOUT; print @data; exit; } ##################### splitalyzerjar #############################3 if($in{'act'} eq 'splitalyzerjar'){ open(SISAAN, "<".$path."splitalyzer.jar"); binmode SISAAN; @data=; close(SISAAN); binmode STDOUT; print @data; exit; } ##################### splistalyzer #############################3 if($in{'act'} eq 'splitalyzer'){ $eventid=1*$in{'id'}; open(SISAAN, "<".$path."kisat.txt"); @kilpailut=; close(SISAAN); $i=0; foreach $rec (@kilpailut){ chomp($rec); @field=split(/\|/,$rec); $i++; if($field[0] == $eventid){ $ename=$field[3]; } } print " $ename A Java enabled browser is required to view this page  "; exit; } ##################### splitsbrowser #############################3 if($in{'act'} eq 'splitsbrowser'){ $eventid=1*$in{'id'}; open(SISAAN, "<".$path."kisat.txt"); @kilpailut=; close(SISAAN); $i=0; foreach $rec (@kilpailut){ chomp($rec); @field=split(/\|/,$rec); $i++; if($field[0] == $eventid){ $ename=$field[3]; } } print " $ename A Java enabled browser is required to view this page  "; } ################# gps point saver ################## if($in{'act'} eq 's'){ if($livepasswd ne ''){ if($livepasswd ne $in{'p'}){ exit; } } ### transformation $competitor=1*$in{'c'}; #$in{'d'}=substr($in{'d'},0,rindex($in{'d'},'x')); $o=''.$in{'c'}.'|'.$in{'d'}."\n"; ## all data to log file for back up open(ULOS,">>".$path."GPS_ALL.txt"); print ULOS $o; close ULOS; open(HANDLE,"<".$path.'coord.txt'); @f=; close(HANDLE); $compmax=0; foreach $rec (@f){ chomp($rec); if($rec =~/\|/){ @r=split(/\|/,$rec); $rname{1*$r[0]}=$r[1]; if($compmax < 1*$r[0]){$compmax = 1*$r[0];} } } ($o1x,$o1y)=split(/\,/,$f[0]); ($o2x,$o2y)=split(/\,/,$f[1]); ($o3x,$o3y)=split(/\,/,$f[2]); ($s1x,$s1y)=split(/\,/,$f[3]); ($s2x,$s2y)=split(/\,/,$f[4]); ($s3x,$s3y)=split(/\,/,$f[5]); $s1y=-$s1y; $s2y=-$s2y; $s3y=-$s3y; $lat0=$o1y; $lon0=$o1x; $r=6370000; $pi=3.1415926535897932384626433832795; $lat=$o1y; $lon=$o1x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o1y=$north; $o1x=$east; $lat=$o2y; $lon=$o2x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o2y=$north; $o2x=$east; $lat=$o3y; $lon=$o3x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o3y=$north; $o3x=$east; $xnolla1=$o1x; $ynolla1=$o1y; $xi=$o2x-$xnolla1;$yi=$o2y-$ynolla1;$xj=$o3x-$xnolla1;$yj=$o3y-$ynolla1; $xnolla=$s1x; $ynolla=$s1y; $x1 = $s2x-$xnolla;$y1 = $s2y-$ynolla;$x2 = $s3x-$xnolla;$y2 = $s3y-$ynolla; #nollalla jakamisen esto if($xj==0){$xj=0.000000000001;} if($yj==0){$yj=0.000000000001;} if(($xj * $yi - $yj * $xi)==0){$xj=$xj+0.000000000001;} if(($yj * $xi - $xj * $yi)==0){$yj=$yj+0.0000000000001;} $Gb = ($x1 * $xj - $x2 * $xi) / ($xj * $yi - $yj * $xi); $Ga = ($x2 - $Gb * $yj) / $xj; $Gd = ($y1 * $yj - $y2 * $yi) / ($yj * $xi - $xj * $yi); $Gc = ($y2 - $Gd * $xj) / $yj; @d=split(/x/,$in{'d'}); $out='';$timemax=0; $i=0; foreach $rec (@d){ @pt=split(/\,/,$rec); $ts=1*$pt[0]; $lon=1*$pt[1]; $lat=1*$pt[2]; $sat=$pt[3]; $sat=~ s/\n//g; $sat=~ s/\r//g; $i++; if($i==1){ $servertime=time; $ts_=$ts-floor($ts/3600)*3600; $ts_=floor(($servertime-$ts_)/3600+.5)*3600+$ts_; $ts=$ts_; $lon_=$lon; $lat_=$lat; $lon=$lon/1000000; $lat=$lat/1000000; }else{ $ts=$ts+$ts_; $lon=($lon+$lon_)/1000000; $lat=($lat+$lat_)/1000000; } $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $easting = floor($s1x+ ((($Ga*($east-$xnolla1) + $Gb*($north-$ynolla1))))); $northing= floor($s1y+ ((($Gc*($north-$ynolla1) + $Gd*($east-$xnolla1))))); $out.=''.$ts.','.$competitor.','.(1*$easting).','.(1*$northing).','.$rname{$competitor}.' ('.$sat.")\n"; if($timemax<$ts){$timemax=$ts;} } open(HANDLE,">>".$path."GPS.txt"); print HANDLE $out; close HANDLE; $old=''; open(HANDLE,"<".$path."GPS.txt"); @old=; close HANDLE; foreach $rec (@old){ chomp($rec); ($ts,$c,$east,$north)=split(/\,/,$rec); if($ts +210 > $timemax && $ts < $timemax){ $old.=$rec."\n"; } } $out=$old.$out; @out=split(/\n/,$out); @out = sort { (split /\,/, $a, 4)[1] <=> (split /\,/, $b, 4)[1] || (split /\,/, $a, 4)[0] <=> (split /\,/, $b, 4)[0] } @out; $out=join("\n",@out); open(HANDLE,">".$path."GPSLAST.txt"); print HANDLE $out; close HANDLE; print "OK"; exit; } ##################### splitalyzer starts #############################3 if($in{'act'} eq 'splitalyzerstarttimes'){ $in{'id'}=1*$in{'eventid'}; open(SISAAN, "<".$path."kilpailijat_$in{'id'}.txt"); @data=; close(SISAAN); #@data = sort { # (split '\|', $a, 9)[1] <=> # (split '\|', $b, 9)[1] # } @data; foreach $rec (@data){ chomp($rec); @field=split(/\|/,$rec); if($field[0] <50000){ if($field[1] ne $edsarja){ print "$field[2]\n"; $edsarja=$field[1]; } $start=''.floor($field[4]/60).':'.($field[4]-60*floor($field[4]/60)); print " $field[0] v $start \n"; } } } ##################### splitalyzer splits #############################3 if($in{'act'} eq 'splitalyzersplits'){ $in{'id'}=1*$in{'eventid'}; ## rastimaarat sarjoittain open(SISAAN, "<".$path."ratapisteet_$in{'id'}.txt"); @d=; close(SISAAN); foreach $rec (@d){ chomp($rec); @field=split(/\|/,$rec); @f=split(/N/,$field[1]); $rmaara{$field[0]}=$#f; } open(SISAAN, "<".$path."kilpailijat_$in{'id'}.txt"); @data=; close(SISAAN); @data = sort { (split '\|', $a, 9)[1] <=> (split '\|', $b, 9)[1] } @data; ## lasketaan väliaikojen määrä foreach $rec (@data){ chomp($rec); @field=split(/\|/,$rec); @splits=split(/\;/,$field[8]); if(abs($#splits - $rmaara{$field[1]}) < 3){ $rmaara2{$field[1]}+=$#splits; $rmaara2count{$field[1]}++; } } # laskettu foreach $rec (@data){ chomp($rec); @field=split(/\|/,$rec); if($rmaara{$field[1]} >2 && $field[0] <50000){ if($field[1] ne $edsarja){ # rastimaara kohdalleen if($rmaara2count{$field[1]}>0){ $rmaara{$field[1]}=floor(0.5+ $rmaara2{$field[1]}/$rmaara2count{$field[1]})+1; } print "$field[1] $field[2] () ".($rmaara{$field[1]}-1)." P \n"; $edsarja=$field[1]; for($i=0;$i<$rmaara{$field[1]}-1;$i++){ print ' '.($i+1)."()"; } print " Z\n"; $pos=0; } $pos++; print ' '.$pos.' '.$field[0].' '.$field[3]; @splits=split(/\;/,$field[8]); print ' '.floor($splits[$rmaara{$field[1]}-1]/60).':'.($splits[$rmaara{$field[1]}-1]-60*floor($splits[$rmaara{$field[1]}-1]/60)); for($i=0;$i<$rmaara{$field[1]};$i++){ $out= ' '.floor($splits[$i]/60).':'.($splits[$i]-60*floor($splits[$i]/60)); if($out eq ' 0:0'){ print ' ---'; }else{ print $out; } } print " \n v \n"; } } } ##################### splitsbrowser splits #############################3 if($in{'act'} eq 'splitsbrowsercsv'){ $in{'id'}=1*$in{'id'}; open(SISAAN, "<".$path."kilpailijat_$in{'id'}.txt"); @data=; close(SISAAN); @data = sort { (split '\|', $a, 9)[1] <=> (split '\|', $b, 9)[1] } @data; foreach $rec (@data){ chomp($rec); @field=split(/\|/,$rec); if($sarja ne $field[2]){ $srjccuont{$sarja}=$lkmmax; $sarja=$field[2]; $sarja =~s/\,/ /g; $lkmmax=0; } @row=split(/\;/,$field[8]); if($lkmmax<$#row+1){$lkmmax=$#row+1;} } $srjccuont{$sarja}=$lkmmax; $sarja=''; $lkm=0; $tmp=''; $firsclass=1; foreach $rec (@data){ chomp($rec); @field=split(/\|/,$rec); if($sarja ne $field[2]){ if($srjccuont{$sarja}>1 && $sarja ne ''){ if($firsclass==0){ print "\n"; } $firsclass=0; $sarjout=$sarja; $sarjout =~ s/\:/ /g; $sarjout =~ s/\,/ /g; print "$sarjout,".($srjccuont{$sarja}-1)."\n"; print $tmp; } $lkm=0; $tmp=''; $sarja=$field[2]; $sarja =~s/\,/ /g; } $min=floor($field[4]/60); $sec=$field[4]-60*$min; $hour=floor($min/60); $min=$min-$hour*60; if($hour<10 && $hour>-1){$hour='0'.(1*$hour);} if($min<10 && $min>-1){$min='0'.(1*$min);} if($sec<10 && $sec>-1){$sec='0'.(1*$sec);} $stime=$hour.':'.$min.':'.$sec; #$stime=1*$field[4]; #$stime=$hour.':'.$min.''; #$stime="08:12:37"; # $field[8] =~ s/\;/\|/g; if($field[8] ne '' ){ @row=split(/\;/,$field[8]); $field[3] =~s/\,/ /g; $tmp2= "$field[3], , ,$stime"; $lkm=0; $sp_prev=0; foreach $spcum (@row){ $sp=$spcum-$sp_prev; $sp_prev=$spcum; $newrow=0; if($sp>0){ $newrow=1; $sec=floor($sp-60*floor($sp/60)); if($sec<10 && $sec>-1){$sec='0'.(1*$sec);} $min=floor($sp/60); if($min<10 && $min>-1){$min='0'.(1*$min);} $lkm++; if($lkm-1<$srjccuont{$sarja}){ $tmp2.= ','.$min.':'.$sec; } } } while($lkm<$srjccuont{$sarja}){ $lkm++; $tmp2.= ',15:00'; } $tmp2.= "\n"; $tmp.=$tmp2; } } if( $tmp ne '' && $srjccuont{$sarja}>1 && $sarja ne ''){ if($firsclass==0){ print "\n"; } $sarjout=$sarja; $sarjout =~ s/\:/ /g; $sarjout =~ s/\,/ /g; print "$sarjout,".($srjccuont{$sarja}-1)."\n"; print $tmp; } print "\n"; } ##################### viimeiset ############################# if($in{'act'} eq 'viimeiset5'){ open (SISAAN,"<$path"."sarjat_$in{'eventid'}.txt"); @class=; close(SISAAN); foreach $rec (@class){ chomp($rec); ($id,$name)=split(/\|/,$rec,2); $classname{$id}=$name; } open (SISAAN,"<$path"."kommentit_$in{'eventid'}.txt"); @kommentit=; close(SISAAN); print "
"; if($default_lang ne 'fi'){ print "

List of latest routes (".(1+$#kommentit)." routes):

    "; }else{ print "

    Uusimmat reittipiirrokset (piirroksia yhteensä ".(1+$#kommentit)." kpl):

      "; } $i=0; while(($i<20 || $in{'all'}== 1) && $#kommentit >= $i){ ($idkilp,$id,$nimi,$aika,$kommentit)=split(/\|/,$kommentit[$#kommentit-$i]); print "
    • ($classname{$idkilp}) $nimi"; $i++; } if($in{'all'} != 1){ if($default_lang ne 'fi'){ print "

    View all

    "; }else{ print "

    Näytä kaikki

    "; } } print "
"; exit; } ##################### menu #############################3 if($in{'act'} eq 'mobile'){ open(SISAAN, "<".$path."kisat.txt"); @data=; close(SISAAN); $out= " mRouteGadget Events:
"; foreach $rec (@data){ chomp($rec); ($id,$karttaid,$tyyppi,$nimi,$paiva,$seura,$taso,$notes)=split(/\|/,$rec,8); $out=$out."
$nimi\n"; } $out=$out.""; $out =~s/ä/\ä\;/g; $out =~s/ö/\ö\;/g; $out =~s/å/\å\;/g; $out =~s/Ä/\Ä\;/g; $out =~s/Ö/\Ö\;/g; $out =~s/Å/\Å\;/g; print $out; exit; } if($in{'act'} eq 'valitsesarja'){ $out=" mRouteGadget Select Class:
"; open (SISAAN,"<$path"."sarjat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$nimi)=split(/\|/,$rec); $out=$out."
$nimi\n"; } close(SISAAN); $out =~s/ä/\ä\;/g; $out =~s/ö/\ö\;/g; $out =~s/å/\å\;/g; $out =~s/Ä/\Ä\;/g; $out =~s/Ö/\Ö\;/g; $out =~s/Å/\Å\;/g; print $out; exit; exit; } if($in{'act'} eq 'valitsereitit'){ $out= " mRouteGadget
Select map part:
Whole map
NE
SE
SW
NW
Select routes: (max 3)
"; open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); $j=0; while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $i++; if($idkilp eq $in{"sarja"}){ ## eli on tässä sarjassa $j++; @ulos[$j]="$id,$nimi
\n"; } } close(SISAAN); @ulos = sort { (split '\,', $a, 2)[0] <=> (split '\,', $b, 2)[0] } @ulos; $out= $out.join('',@ulos)."

"; $out =~s/ä/\ä\;/g; $out =~s/ö/\ö\;/g; $out =~s/å/\å\;/g; $out =~s/Ä/\Ä\;/g; $out =~s/Ö/\Ö\;/g; $out =~s/Å/\Å\;/g; print $out; exit; } ##################### menu #############################3 if($in{'get'} eq 'table'){ open(SISAAN, "<".$path."kisat.txt"); @data=; close(SISAAN); @data = sort { (split /\|/, $a, 6)[4] cmp (split /\|/, $b, 6)[4] } @data; print @data; exit; } ##################### RG index interface ############################ if($in{'info'} eq 'csv'){ open(SISAAN, "<".$path."kisat.txt"); @data=; close(SISAAN); @data = sort { (split /\|/, $a, 6)[4] cmp (split /\|/, $b, 6)[4] } @data; if($in{'first'}!=1){ @data = reverse @data; } foreach $rec (@data){ chomp($rec); ($id,$karttaid,$tyyppi,$nimi,$paiva,$seura,$taso,$notes)=split(/\|/,$rec,8); open(SISAAN, "<".$path."kommentit_".$id.".txt"); @d=; close(SISAAN); $count=1+$#d; print "$id|$tyyppi|$nimi|$paiva|$seura|$taso|$count\n"; } exit; } ##################### menu #############################3 if($in{'act'} eq 'menu' || $in{'act'} eq ''){ if($menuStyle eq 'list'){ open(SISAAN, "<".$path."kisat.txt"); @data=; close(SISAAN); $out= "

param('tracklog'); binmode $file; @d =<$file>; close($file); open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); foreach $rec (@kartat) { chomp($rec); ($id,$karttaid,$tyyppi,$nimi,$paiva,$seura,$taso,$notes)=split(/\|/,$rec,8); if($in{'id'} eq $id){ $mapid=$karttaid; } } open(HANDLE, "<".$path."kartat.txt")|| die; @kdata=; close(HANDLE); $coord[0]=''; $coord[4]=''; foreach $rec (@kdata){ chomp($rec); ($id,$nimi)=split(/\|/,$rec); if($id eq $mapid){ ($id,$nimi,$copyright,$s1x,$o1x,$s1y,$o1y,$s2x,$o2x,$s2y,$o2y,$s3x,$o3x,$s3y,$o3y)=split(/\|/,$rec); if($o1x != 0){ $s1y=-$s1y; $s2y=-$s2y; $s3y=-$s3y; $lat0=$o1y; $lon0=$o1x; $kaavao1y=$o1y; $kaavao1x=$o1x; $r=6370000; $pi=3.1415926535897932384626433832795; $lat=$o1y; $lon=$o1x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o1y=$north; $o1x=$east; $lat=$o2y; $lon=$o2x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o2y=$north; $o2x=$east; $lat=$o3y; $lon=$o3x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o3y=$north; $o3x=$east; $xnolla1=$o1x; $ynolla1=$o1y; $xi=$o2x-$xnolla1;$yi=$o2y-$ynolla1;$xj=$o3x-$xnolla1;$yj=$o3y-$ynolla1; $xnolla=$s1x; $ynolla=$s1y; $x1 = $s2x-$xnolla;$y1 = $s2y-$ynolla;$x2 = $s3x-$xnolla;$y2 = $s3y-$ynolla; #nollalla jakamisen esto if($xj==0){$xj=0.000000000001;} if($yj==0){$yj=0.000000000001;} if(($xj * $yi - $yj * $xi)==0){$xj=$xj+0.000000000001;} if(($yj * $xi - $xj * $yi)==0){$yj=$yj+0.0000000000001;} $Gb = ($x1 * $xj - $x2 * $xi) / ($xj * $yi - $yj * $xi); $Ga = ($x2 - $Gb * $yj) / $xj; $Gd = ($y1 * $yj - $y2 * $yi) / ($yj * $xi - $xj * $yi); $Gc = ($y2 - $Gd * $xj) / $yj; } } } if($in{'regtest'} eq '1'){ # reg test gpx open(HANDLE,"<".$path.'coord.txt'); @f=; close(HANDLE); $compmax=0; foreach $rec (@f){ chomp($rec); if($rec =~/\|/){ @r=split(/\|/,$rec,2); $rname{1*$r[0]}=$r[1]; if($compmax < 1*$r[0]){$compmax = 1*$r[0];} } } ($o1x,$o1y)=split(/\,/,$f[0]); ($o2x,$o2y)=split(/\,/,$f[1]); ($o3x,$o3y)=split(/\,/,$f[2]); ($s1x,$s1y)=split(/\,/,$f[3]); ($s2x,$s2y)=split(/\,/,$f[4]); ($s3x,$s3y)=split(/\,/,$f[5]); $s1y=-$s1y; $s2y=-$s2y; $s3y=-$s3y; $lat0=$o1y; $lon0=$o1x; $r=6370000; $pi=3.1415926535897932384626433832795; $lat=$o1y; $lon=$o1x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o1y=$north; $o1x=$east; $lat=$o2y; $lon=$o2x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o2y=$north; $o2x=$east; $lat=$o3y; $lon=$o3x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $o3y=$north; $o3x=$east; $xnolla1=$o1x; $ynolla1=$o1y; $xi=$o2x-$xnolla1;$yi=$o2y-$ynolla1;$xj=$o3x-$xnolla1;$yj=$o3y-$ynolla1; $xnolla=$s1x; $ynolla=$s1y; $x1 = $s2x-$xnolla;$y1 = $s2y-$ynolla;$x2 = $s3x-$xnolla;$y2 = $s3y-$ynolla; #nollalla jakamisen esto if($xj==0){$xj=0.000000000001;} if($yj==0){$yj=0.000000000001;} if(($xj * $yi - $yj * $xi)==0){$xj=$xj+0.000000000001;} if(($yj * $xi - $xj * $yi)==0){$yj=$yj+0.0000000000001;} $Gb = ($x1 * $xj - $x2 * $xi) / ($xj * $yi - $yj * $xi); $Ga = ($x2 - $Gb * $yj) / $xj; $Gd = ($y1 * $yj - $y2 * $yi) / ($yj * $xi - $xj * $yi); $Gc = ($y2 - $Gd * $xj) / $yj; ### $splitter="-1 && $p2>-1){ $lat=substr($point,$p1+5,$p2-$p1-5); $lat =~ s/ //g; $lat =~ s/\"//g; } $p1=index($point,"lon=\""); $p2=index($point,"\"",$p1+5); if($p1>-1 && $p2>-1){ $lon=substr($point,$p1+5,$p2-$p1-5); $lon =~ s/ //g; $lon =~ s/\"//g; } ($lon,$lat)=($lat,$lon); $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $easting = floor($s1x+ ((($Ga*($east-$xnolla1) + $Gb*($north-$ynolla1))))); $northing= -floor($s1y+ ((($Gc*($north-$ynolla1) + $Gd*($east-$xnolla1))))); $GPSparam.="1,$easting,$northing;"; } } # reg test gpx if($in{'gpstype'} eq 'HST'){ $GPSparam=''; $pi=3.1415926535897932384626433832795; $splitter="Run"; $start='<'.$splitter; $end=''; $sea=$start.'>'; $rep=$start.' >'; $d= join('',@d); $d=~ s/${sea}/${rep}/g; $start=$start.' '; @routes=split(/${start}/,$d); $routecount=0; $rec= $routes[1]; $routecount++; ($rec,$del)=split(/${end}/,$rec); $starttime="Start time unknown"; $p1=index($rec,'StartTime='); $p2=index($rec,"\"",$p1+12); if($p1>-1 && $p2>$p1){ $starttime=substr($rec,$p1+10,$p2-$p1-10); $starttime =~ s/ //g; $starttime =~ s/\"//g; $starttime =~ s/t/ /gi; $starttime =~ s/z/ /gi; } @trackpoints=split(//,$rec); $lat0=-987654; foreach $point (@trackpoints){ $lat=-9999999; $lon=-9999999; $alt=-9999999; $p1=index($point,''); if($p1>-1 && $p2>-1){ # $tim=substr($point,$p1+6,$p2-$p1-6); $tim=~ s/Z//g; $tim=~ s/\-/\:/g; $tim=~ s/T/\:/g; ($tyear,$tmon,$tday,$thour,$tmin,$tsec)=split(/\:/,$tim); $tim=floor(3600*$thour+60*$tmin+$tsec); $day=$tyear.'_'.$tmon.'_'.$tday; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $lat=substr($point,$p1+17,$p2-$p1-17); $lat =~ s/ //g; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $lon=substr($point,$p1+18,$p2-$p1-18); $lon =~ s/ //g; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $alt=substr($point,$p1+16,$p2-$p1-16); $alt =~ s/ //g; } if($lat!=-9999999 && $lon !=-9999999){ $count++; if($lat0==-987654){ $lat0=$lat; $lon0=$lon; $daycount=0; $tim0=$tim; $day0=$day; $gpsstarttime=$tim0; } ## this not very scientific, byt must do for now ... $r=6370000; $northing=-floor(($lat-$lat0)/360*2*$pi*$r); $easting=floor(($lon-$lon0)/360*2*$r*$pi *cos(abs($lat0)/180*$pi)); if($day0 ne $day){ $day0 = $day; $daycount++; } $tim=$tim+$daycount*60*60*24-$tim0; $GPSparam.="$tim,$easting,$northing;"; } } # add points if too big gaps @ad=split(/\;/,$GPSparam); $GPSparam=''; foreach $pt (@ad){ @r=split(/\,/,$pt); if($edtim ne '' && $ed +3 < $r[0]){ for($i=$edtim+1;$i<$r[0];$i++){ $tim=$i; $easting=floor(($i-$edtim)/($r[0]-$edtim)*$r[1]+($r[0]-$i)/($r[0]-$edtim)*$edeast); $northing=floor(($i-$edtim)/($r[0]-$edtim)*$r[2]+($r[0]-$i)/($r[0]-$edtim)*$ednorth); $GPSparam.="$tim,$easting,$northing;"; } } $GPSparam.=join(',',@r).";"; $edtim=$r[0]; $edeast=$r[1]; $ednorth=$r[2]; } } # HST if($in{'gpstype'} eq 'TCX'){ $GPSparam=''; $pi=3.1415926535897932384626433832795; $splitter="Activity"; $start='<'.$splitter; $end=''; $sea=$start.'>'; $rep=$start.' >'; $d= join('',@d); $d=~ s/${sea}/${rep}/g; $start=$start.' '; @routes=split(/${start}/,$d); $routecount=0; $rec= $routes[1]; $routecount++; ($rec,$del)=split(/${end}/,$rec); $starttime="Start time unknown"; $p1=index($rec,'StartTime='); $p2=index($rec,"\"",$p1+12); if($p1>-1 && $p2>$p1){ $starttime=substr($rec,$p1+10,$p2-$p1-10); $starttime =~ s/ //g; $starttime =~ s/\"//g; $starttime =~ s/t/ /gi; $starttime =~ s/z/ /gi; } @trackpoints=split(//,$rec); $lat0=-987654; foreach $point (@trackpoints){ $lat=-9999999; $lon=-9999999; $alt=-9999999; $p1=index($point,''); if($p1>-1 && $p2>-1){ # $tim=substr($point,$p1+6,$p2-$p1-6); $tim=~ s/Z//g; $tim=~ s/\-/\:/g; $tim=~ s/T/\:/g; ($tyear,$tmon,$tday,$thour,$tmin,$tsec)=split(/\:/,$tim); $tim=3600*$thour+60*$tmin+$tsec; $day=$tyear.'_'.$tmon.'_'.$tday; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $lat=substr($point,$p1+17,$p2-$p1-17); $lat =~ s/ //g; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $lon=substr($point,$p1+18,$p2-$p1-18); $lon =~ s/ //g; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $alt=substr($point,$p1+16,$p2-$p1-16); $alt =~ s/ //g; } if($lat!=-9999999 && $lon !=-9999999){ $count++; if($lat0==-987654){ $lat0=$lat; $lon0=$lon; $daycount=0; $tim0=$tim; $day0=$day; } ## this not very scientific, byt must do for now ... $r=6370000; $northing=-floor(($lat-$lat0)/360*2*$pi*$r); $easting=floor(($lon-$lon0)/360*2*$r*$pi *cos(abs($lat0)/180*$pi)); if($day0 ne $day){ $day0 == $day; $daycount++; } $tim=$tim+$daycount*60*60*24-$tim0; $GPSparam.="$tim,$easting,$northing;"; } } } # TCX if($in{'gpstype'} eq 'GPX' || $in{'calib'} eq '1'){ $GPSparam=''; $pi=3.1415926535897932384626433832795; $splitter="'); $p2=index($point,''); if($p1>-1 && $p2>-1){ # # $tim=substr($point,$p1+6,$p2-$p1-6); $tim=~ s/Z//g; $tim=~ s/\-/\:/g; $tim=~ s/T/\:/g; ($tyear,$tmon,$tday,$thour,$tmin,$tsec)=split(/\:/,$tim); $tim=floor(3600*$thour+60*$tmin+$tsec); $day=$tyear.'_'.$tmon.'_'.$tday; } $p1=index($point,"lat=\""); $p2=index($point,"\"",$p1+1); if($p1>-1 && $p2>-1){ $lat=substr($point,$p1+5,$p2-$p1-5); $lat =~ s/ //g; $lat =~ s/\"//g; } $p1=index($point,"lon=\""); $p2=index($point,"\"",$p1+1); if($p1>-1 && $p2>-1){ $lon=substr($point,$p1+5,$p2-$p1-5); $lon =~ s/ //g; $lon =~ s/\"//g; } $p1=index($point,''); $p2=index($point,''); if($p1>-1 && $p2>-1){ $alt=substr($point,$p1+4,$p2-$p1-4); $alt =~ s/ //g; } if($lat!=-9999999 && $lon !=-9999999){ $count++; if($lat0==-987654){ $lat0=$lat; $lon0=$lon; $daycount=0; $tim0=$tim; $day0=$day; $gpsstarttime=$tim0; } ## this not very scientific, byt must do for now ... $r=6370000; $northing=-floor(($lat-$lat0)/360*2*$pi*$r); $easting=floor(($lon-$lon0)/360*2*$r*$pi *cos(abs($lat0)/180*$pi)); ### if($Ga ne '' && $in{'calib'} ne '1'){ #($lon,$lat)=($lat,$lon); $lat0=$kaavao1y; $lon0=$kaavao1x; $north= (($lat-$lat0)/360*2*$pi*$r); $east= (($lon-$lon0)/360*2*$r*$pi *cos($lat0/180*$pi)); $easting = floor($s1x+ ((($Ga*($east-$xnolla1) + $Gb*($north-$ynolla1))))); $northing= -floor($s1y+ ((($Gc*($north-$ynolla1) + $Gd*($east-$xnolla1))))); } ## if($day0 ne $day){ $day0 = $day; $daycount++; } $tim=$tim+$daycount*60*60*24-$tim0; $GPSparam.="$tim,$easting,$northing;"; if($easting>$gpsxmax){$gpsxmax=$easting;$gpsxmaxe=1*$lon;$gpsxmaxn=1*$lat;} if($northing>$gpsymax){$gpsymax=$northing;$gpsymaxn=1*$lat;$gpsymaxe=1*$lon;} if($easting<$gpsxmin){$gpsxmin=$easting;$gpsxmine=1*$lon;$gpsxminn=1*$lat;} if($northing<$gpsymin){$gpsymin=$northing;$gpsyminn=1*$lat;$gpsymine=1*$lon;} } } # add points if too big gaps @ad=split(/\;/,$GPSparam); $GPSparam=''; foreach $pt (@ad){ @r=split(/\,/,$pt); if($edtim ne '' && $ed +3 < $r[0]){ for($i=$edtim+1;$i<$r[0];$i++){ $tim=$i; $easting=floor(($i-$edtim)/($r[0]-$edtim)*$r[1]+($r[0]-$i)/($r[0]-$edtim)*$edeast); $northing=floor(($i-$edtim)/($r[0]-$edtim)*$r[2]+($r[0]-$i)/($r[0]-$edtim)*$ednorth); $GPSparam.="$tim,$easting,$northing;"; } } $GPSparam.=join(',',@r).";"; $edtim=$r[0]; $edeast=$r[1]; $ednorth=$r[2]; } } # GPX #KML (FRWD Google Earth Export) if ($in{'gpstype'} eq 'KML') { $gpsstarttime=0; # unknown $GPSparam = ''; $pi = 3.1415926535897932384626433832795; $d = join('', @d); ($pois, $d) = split(//i, $d, 2); ($d, $pois) = split(/<\/coordinates>/i, $d, 2); $d =~ s/\t/ /; $d =~ s/\n/ /; $d =~ s/ +/ /; @trackpoints = split(/ /, $d); $PMKparam = ''; $e = join('', @d); @placemarks = split(//, $e); $kesto = 0; $placemarkcount = 0; foreach $placemark (@placemarks) { $placemarkcount++; $placemark =~ s/\t/ /; $placemark =~ s/\n/ /; $placemark =~ s/ +/ /; $description = $placemark; ($pois, $description) = split(//, $description, 2); ($description, $pois) = split(/<\/description>/, $description, 2); $timeindex = index($description, ':mm:ss): '); if ($timeindex > -1) { $time = $description; ($pois, $time) = split(/\:mm\:ss\)\: /, $time, 2); ($time, $pois) = split(/<\/p>/, $time, 2); ($tunnit, $minuutit, $sekunnit) = split(/\:/, $time, 3); $kesto = $tunnit * 60 * 60 + $minuutit * 60 + $sekunnit; $coordinates = $placemark; ($pois, $coordinates) = split(//, $coordinates, 2); ($coordinates, $pois) = split(/<\/coordinates>/, $coordinates, 2); ($lon, $lat, $alt) = split(/\,/, $coordinates, 3); $PMKparam .= "$kesto,$lon,$lat;"; } } $trackpointcount = @trackpoints; $interval = int($kesto / $trackpointcount + .5); @placemarks = split(/\;/, $PMKparam); $currentplacemark = 0; $lat0 = -987654; $tim = 0; $runningtim = $interval * -1; foreach $point (@trackpoints) { if ($point) { $lat = -9999999; $lon = -9999999; $pmktim = 0; $pmklat = -9999999; $pmklon = -9999999; ($pmktim, $pmklon, $pmklat) = split(/\,/, @placemarks[$currentplacemark]); ($lon, $lat) = split(/\,/, $point); if ($lon == $pmklon && $lat == $pmklat) { $tim = $pmktim; $currentplacemark++; if ($runningtim + $interval == $tim) { $runningtim = $tim; } } else { $tim = $runningtim + $interval; $runningtim = $tim; } if ($lat != -9999999 && $lon != -9999999 && $lat != 0 && $lon != 0) { $count++; if ($lat0 == -987654) { $lat0 = $lat; $lon0 = $lon; } ## this not very scientific, byt must do for now ... $r = 6370000; $northing = -floor(($lat - $lat0) / 360 * 2 * $pi * $r); $easting = floor(($lon - $lon0) / 360 * 2 * $r * $pi * cos(abs($lat0) / 180 * $pi)); $GPSparam .= "$tim,$easting,$northing;"; } } } } # KML (FRWD Google Earth Export) if($in{'gpstype'} eq 'FRWD'){ $route=join('',@d); $route =~ s/\r//g; ($head,$route)=split(/Route data\:\n/,$route,2); ($route,$rest)=split(/\n\n/,$route,2); @d=split(/\n/,$route); @cols=split(/\t/,$d[0]); $i=0; foreach $rec (@cols){ $coli{$rec}=$i; $i++; } $GPSparam=''; $lat0=-987654; $i=0; foreach $rec (@d){ if($i>0){ $rec =~ s/\,/\./g; @cols=split(/\t/,$d[$i]); $lat=&trim($cols[$coli{'N/S latitude (ddmm.mmmm)'}]); $lon=&trim($cols[$coli{'E/W longitude (dddmm.mmmm)'}]); if($lat ne '' && $lon ne '' ){ $lat=substr($lat,0,2)+substr($lat,2,10)/60; $lon=substr($lon,0,2)+substr($lon,2,10)/60; if($lat0==-987654){ $lat0=$lat; $lon0=$lon; $tim0=1*$cols[$coli{'Time'}]; $gpsstarttime=$tim0; } ## this not very scientific, byt must do for now ... $r=6370000; $N=-floor(($lat-$lat0)/360*2*$pi*$r); $E=floor(($lon-$lon0)/360*2*$r*$pi *cos(abs($lat0)/180*$pi)); $tim=1*$cols[$coli{'Time'}]-$tim0; $GPSparam.="$tim,$E,$N;"; } } $i++; } # add points if too big gaps @ad=split(/\;/,$GPSparam); $GPSparam=''; foreach $pt (@ad){ @r=split(/\,/,$pt); if($edtim ne '' && $ed +3 < $r[0]){ for($i=$edtim+1;$i<$r[0];$i++){ $tim=$i; $easting=floor(($i-$edtim)/($r[0]-$edtim)*$r[1]+($r[0]-$i)/($r[0]-$edtim)*$edeast); $northing=floor(($i-$edtim)/($r[0]-$edtim)*$r[2]+($r[0]-$i)/($r[0]-$edtim)*$ednorth); $GPSparam.="$tim,$easting,$northing;"; } } $GPSparam.=join(',',@r).";"; $edtim=$r[0]; $edeast=$r[1]; $ednorth=$r[2]; } } # FRWD if($in{'gpstype'} eq 'SDF'){ $route=join('',@d); $route =~ s/\r//g; ($head,$route)=split(/\[POINTS\]\n/,$route,2); ($route,$rest)=split(/\[/,$route,2); @d=split(/\n/,$route); $GPSparam=''; $lat0=-987654; $i=0; foreach $rec (@d){ if($i>0){ @cols=split(/\,/,$rec); # "TP",06.03.2005,16:54.51,60.2565145,24.9067569,6,4.06,159.6,3061.6449732686 $lat=&trim($cols[3]); $lon=&trim($cols[4]); $tim=$cols[1].':'.$cols[2]; $tim=~s/\./\:/g; ($tday,$tmon,$tyear,$thour,$tmin,$tsec)=split(/\:/,$tim); $tim=3600*$thour+60*$tmin+$tsec; $day=$tyear.'_'.$tmon.'_'.$tday; if($lat0==-987654){ $lat0=$lat; $lon0=$lon; $daycount=0; $tim0=$tim; $day0=$day; $gpsstarttime=$tim0; } ## this not very scientific, byt must do for now ... $r=6370000; $northing=-floor(($lat-$lat0)/360*2*$pi*$r); $easting=floor(($lon-$lon0)/360*2*$r*$pi *cos(abs($lat0)/180*$pi)); if($day0 ne $day){ $day0 = $day; $daycount++; } $tim=$tim+$daycount*60*60*24-$tim0; $GPSparam.="$tim,$easting,$northing;"; } $i++; } # add points if too big gaps @ad=split(/\;/,$GPSparam); $GPSparam=''; foreach $pt (@ad){ @r=split(/\,/,$pt); if($edtim ne '' && $ed +3 < $r[0]){ for($i=$edtim+1;$i<$r[0];$i++){ $tim=$i; $easting=floor(($i-$edtim)/($r[0]-$edtim)*$r[1]+($r[0]-$i)/($r[0]-$edtim)*$edeast); $northing=floor(($i-$edtim)/($r[0]-$edtim)*$r[2]+($r[0]-$i)/($r[0]-$edtim)*$ednorth); $GPSparam.="$tim,$easting,$northing;"; } } $GPSparam.=join(',',@r).";"; $edtim=$r[0]; $edeast=$r[1]; $ednorth=$r[2]; } } # SDF } ## # tsekataan kieli $kieli=$default_lang; foreach $rec (@languages){ if($in{'kieli'} eq $rec){$kieli=$rec;} } open (SISAAN,"<".$path."../lang_".$kieli.".txt"); @lang=; close(SISAAN); $lang=join('',@lang); ($lang, $langkiitos)=split(/####/,join('',@lang)); if($in{'kohdistus'}eq "1"){ $muu="\n\n"; } if($in{'piirrarastit'}eq "1"){ $muu=$muu."\n\n"; } if($in{'eipiirtaneet'} eq "1" || $norouteanim==1){ $muu=$muu.="\n"; } $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; if($in{'calib'} eq '1'){ $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n"; $muu=$muu."\n\n "; } if($in{'calib'} ne '1' && $in{'regtest'} ne '1' && ($in{'tracking'} ==1 || $in{'id'} eq '0' ) && ! ($in{'piirrarastit'} eq '1')){ $muu=$muu."\n"; } if($in{'width'} eq''){$in{'width'}=775; } if($in{'height'} eq''){$in{'height'}=500; } $in{'width'}=1*$in{'width'}; $in{'height'}=1*$in{'height'}; open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); if($in{'id'} eq '0'){ undef @kartat; $kartat[0]="0|0|2| | | | |"; } foreach $rec (@kartat) { chomp($rec); ($id,$karttaid,$tyyppi,$nimi,$paiva,$seura,$taso,$notes)=split(/\|/,$rec,8); $nimi=$paiva.' '.$nimi; if($id eq $in{'id'}){ $muu=$muu."\n"; open (SISAAN,"<".$path."../map.txt"); @sivu=; close(SISAAN); if($id==0 && $in{'mapid'} ne ''){ $karttaid=1*$in{'mapid'}; } $sivu= join('',@sivu); $sivu =~ s/##httppath##/${httppath}/g; $sivu =~ s/##extension##/${extension}/g; $sivu =~ s/##logo##/${logo}/g; $sivu =~ s/##icon##/${gadgeticon}/g; $sivu =~ s/##piste##/${piste}/g; $sivu =~ s/##kieli##/${kieli}/g; $sivu =~ s/##nimi##/${nimi}/g; $sivu =~ s/##status##/2/; $sivu =~ s/##id##/${in{'id'}}/; $sivu =~ s/##karttaid##/${karttaid}/; $sivu =~ s/##ratapiirto##/${in{'ratapiirto'}}/; $sivu =~ s/##muu##/${muu}/; $sivu =~ s/##ohjeet##/${lang}/; $sivu =~ s/##width##/${in{'width'}}/g; $sivu =~ s/##height##/${in{'height'}}/g; $temp=''; foreach $rec (@languages){ $temp=$temp."|$rec"; } $temp=$temp."             GPS"; $temp=~ s/\|//; $sivu =~ s/##languages##/${temp}/; print $sivu; exit; }} } ################# gps upload #################### if ($in{"act"} eq "gpsu"){ print"
GPS track log file upload [Help]



"; #### If KML, saving interval (in seconds):

} ################# animaatio #################### if ($in{"act"} eq "anim"){ # Tästä apletti pyytää animaatiopisteet $raika=3; ## step - aika sekunteina open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); $viesti=0; foreach $rec (@kartat) { chomp($rec); ($id,$karttaid,$tyyppi,$nimi)=split(/\|/,$rec,4); if($id==$in{'eventid'} && $tyyppi ==3){ $viesti=1; } } ## haetaan suora reitti open (SISAAN,"<".$path."ratapisteet_$in{'eventid'}.txt"); @ratap=; close(SISAAN); foreach $rec (@ratap){ chomp($rec); ($id,$data)=split(/\|/,$rec,2); @temp=split(/N/,$data); $data=""; foreach $recb (@temp){ chomp($recb); ($x,$y)=split(/\;/,$recb,2); $data=$data.($x).";".($y)."N"; } $suorareitti{$id}=$data; ($pis,$data)=split(/N/,$data,2); $suorarastit{$id}=$data; } ## suora reitti ok ## haetaan valiajat $kilp=1;$laikaMin=99999999; #while($in{"k".$kilp} ne''){ open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); $ok=0; while (defined ($rec = ) && $in{"k".$kilp} ne'') { chomp($rec); ($id,$sarjanro,$sarjanimi,$nimi,$laika,$aika,$sija,$tulos,$valiajat,$GPSa)=split(/\|/,$rec); if($id eq $in{'k'.$kilp}){ $lahtoaika[$kilp]=$laika; if($laika<$laikaMin){ $laikaMin=$laika; } $vajat[$kilp]=$valiajat; $gpsani[$kilp]=$GPSa; $srj{$kilp}=$sarjanro; if($viesti ==1){ $srj{$kilp}=$sija; } $kilp++;$ok=1; seek(SISAAN, 0, 0); } } if($ok==0){exit;} #} close(SISAAN); # valiajat nyt muuttujassa $vajat[] $kilp=1; while($in{"k".$kilp} ne''){ open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); $ok=0; while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); if ($in{"k".$kilp} eq $id){ $viiva[$kilp]=$viivat; $rast[$kilp]=$rastit; $kilp++;$ok=1; } } if($ok==0){ # ei ollut piirtänyt, tilalle suora reitti $viiva[$kilp]="N".$suorareitti{$srj{$kilp}}; $rast[$kilp]="N".$suorarastit{$srj{$kilp}}; $kilp++; #exit; } } close(SISAAN); ## nyt on valiajat, reittipiirros ja rastipisteet selvillä ## nyt lasketaan animaatioille pisteet ## tämä pitäisi tehdä clientissä serveriä säästääksemme, mutta ## ei nyt jaksa javalla väsätä, ehkä sitten joskus $kilp=1; while($in{"k".$kilp} ne''){ $aikasiirto=0; if($in{"k".$kilp}<50000){ print ''.($lahtoaika[$kilp]-$laikaMin).';'; @reitti=split(/N/,$viiva[$kilp]); @valiajat=split(/\;/,$vajat[$kilp]); @rastit=split(/N/,$rast[$kilp]); $i=0; $viiva[$kilp]=$viiva[$kilp]."N"; $viivatemp=""; foreach $rec (@rastit){ $i++; if($rec ne ""){ $j="NC".$i."N";$k="N".$rec."N"; ($temp,$viiva[$kilp])=split(/${k}/,$viiva[$kilp],2); $viiva[$kilp]="N".$viiva[$kilp]; $viivatemp=$viivatemp.$temp.$j; } } $viiva[$kilp]=$viivatemp; $i=0; foreach $rec (@rastit){ $i++;$j="NC".$i."N";$k="N".$rec.'|'.$rec."N"; $viiva[$kilp]=~ s/${j}/${k}/; } $viiva[$kilp]=~ s/^\|//; $viiva[$kilp]=~ s/NN/N/g; $viiva[$kilp]=~ s/NN/N/g; $viiva[$kilp]=~ s/NN/N/g; @rastivalit=split(/\|/,$viiva[$kilp]); $ulos=join("\n",@rastivalit); $i=0; $matkasiirto=0; foreach $rec (@rastivalit){ $rec=~ s/^N//; $matkasiirto=0; $i++; } $i_rastit=0; $i_reitti=0; $i_valiajat=0; $i_piste=0; $aika=0; $matka=0; $eka=1; while ($valiajat[$i_rastit] ne '' && ($i_rastit==0 || $valiajat[$i_rastit]>$valiajat[$i_rastit-1])){ $rastivalit[$i_rastit]=~ s/^N//; @viivab=split(/N/,$rastivalit[$i_rastit]); # lasketaan pituus $x0=0; $y0=0; $pituus=0; $i=0; $lisaaika=0; foreach $rec (@viivab){ ($x1,$y1)=split(/\;/,$rec); if($i>0){ $pituus=$pituus+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)); if($x0 == $x1 && $y0 == $y1){ ## 2 peräkkäistä klikkausta = pysähdys 3 sec $lisaaika=$lisaaika+3; } } $x0=$x1;$y0=$y1; $i++; } $valiaika=$valiajat[$i_rastit]-$valiajat[$i_rastit-1]; if($i_rastit==0){ $valiaika=$valiajat[$i_rastit]; } ## hyomioidaan pysähdykset $valiaika=$valiaika-$lisaaika; if($valiaika ==0 || $valiaika<0 ){ $valiaika=0.00001; } $step=($pituus/($valiaika/$raika)); $matkasiirto=$aikasiirto*$step; # pisteet polylinen varrelle $i=0;$seis=0; foreach $rec (@viivab){ ($x1,$y1)=split(/\;/,$rec); if($i>0){ if($x0 == $x1 && $y0 == $y1){ $seis++; ## ei kahta peräkkäistä klikkausta samaan pisteeseen }else{ $plkm=1; while($matka+$step*$plkm-$matkasiirto < $matka+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1))){ $i_piste++; #lasketaan animaatioreittipiste $ax=floor((($step*$plkm-$matkasiirto)*$x1+$x0*(sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1))-($step*$plkm-$matkasiirto)))/(sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)))); $ay=floor((($step*$plkm-$matkasiirto)*$y1+$y0*(sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1))-($step*$plkm-$matkasiirto)))/(sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)))); $info=""; if($eka==1){ $eka=0; $info='C'; } print "$ax;".$ay.",".$info."N"; $info=""; if($seis > 0){ for($ii=0;$ii<$seis;$ii++){ print "$ax;$ay,".$info."N"; } $seis=0; } $plkm++; } $matkasiirto=$matka+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1))-($matka+$step*($plkm-1)-$matkasiirto); $matka=$matka+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)); $aikasiirto=$matkasiirto/$step*1; } } $x0=$x1;$y0=$y1; $i++; } $i_rastit++; $eka=1; } }else{ ## gps animaatip #print "0;0;0,0N"; print ''.($lahtoaika[$kilp]-$laikaMin).';'; print $gpsani[$kilp]; } $kilp++; print "\n"; } } ################# viivat #################### if ($in{"act"} eq "viivat"){ ## tästä appletti lataa viivat open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); @merkinnat=; close(SISAAN); $kilp=1; while($in{"k".$kilp} ne''){ $in{"id"}=$in{"k".$kilp}; $i=0;$loytyi=0; foreach $rec (@merkinnat) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $i++; if ($in{"id"} eq $id){ $i++; $loytyi=1; $viivat =~ s/N/\n/g; $viivat =~ s/R/\r/g; $viivat =~ s/#/g/; print "\n1".$viivat; } } if($i==0){ print " "; } if($loytyi==0){ print "\n1\n0;0"; } print "\n"; $kilp++; } } ################# kommentit #################### if ($in{"act"} eq "kommentit"){ ## Tästä apletti pyytää kommentit open (SISAAN,"<$path"."kommentit_$in{'eventid'}.txt"); @kommentit=; close(SISAAN); $kilp=1; while($in{"k".$kilp} ne''){ $in{"id"}=$in{"k".$kilp}; $i=0; foreach $rec (@kommentit) { chomp($rec); ($idkilp,$id,$nimi,$aika,$kommentit)=split(/\|/,$rec); $i++; if ($in{"id"} eq $id){ $kommentit =~ s/#nl#/\n/g; $kommentit =~ s/#cr#/\r/g; #$kommentit=~ s/\;/#chsmcl#/g; print "\n\n$nimi:\n".$kommentit; } } $kilp++; } } # ####### TALLENNUKSET########################################## ############# Reittipiirroksen tallennus ###################### if($in{'act'} eq "tallennapiirros"){ open (HANDLE,"<".$path."kilpailijat_$in{'eventid'}.txt"); @d=; close HANDLE; if($in{'lisaa'} eq '1'){ ## if add mode ## get ID foreach $rec (@d){ ($id,$rest)=split(/\|/,$rec,2); if($id>50000){$id=$id-50000;} if($in{'id'} < $id){$in{'id'}=$id;} } $in{'id'}=(1*$in{'id'})+1; }else{ ## read original version of name, to avoid some charset trouble foreach $rec (@d){ @r=split(/\|/,$rec); if($in{'id'} == $r[0] && $r[3] ne ''){$in{'suunnistaja'}=$r[3];} } } ## input $in{'suunnistaja'}=~ s/#chsmcl#/\;/g; $in{'suunnistaja'}=~ s/#chnd#/\&/g; $in{'kommentit'}=~ s/#chsmcl#/\;/g; $in{'kommentit'}=~ s/#chnd#/\&/g; ## gps if($in{'GPS'}==1){ $lahtoaika=-1; foreach $rec (@d){ ($id_t,$sarjanro_t,$sarjanimi_t,$nimi_t,$laika_t,$aika_t,$sija_t,$tulos_t,$valiajat_t,$GPSa_t)=split(/\|/,$rec); if($id_t == $in{'id'}){ $lahtoaika=$laika_t; } } $in{'suunnistaja'}=' GPS '.$in{'suunnistaja'}; $in{'id'}=50000+$in{'id'}; } open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); @merkinnat=; close(SISAAN); $ok=1; foreach $rec (@merkinnat) { chomp($rec); ($idkilp,$id,$nimi,$hajonta,$viivat,$rastit)=split(/\|/,$rec); if($id eq $in{'id'}){ $ok=0; ## eli piirros oli jo olemassa, ei tallenneta } } $in{'rdata'}=~ s/\,/\;/g; ($reitti,$rastit)=split(/\|/,$in{'rdata'}); if($ok == 1){ if($in{'GPS'}!=1){ open (HANDLE,">>".$path."merkinnat_$in{'eventid'}.txt"); &lock_file; print HANDLE $in{'rataid'}."|".$in{'id'}."| $in{'suunnistaja'}|$in{'hajonta'}|$reitti|$rastit\n"; &unlock_file; close HANDLE; }else{ @GPSD=split(/N/,$reitti); $reitti=''; foreach $gd (@GPSD){ chomp($gd); if($gd ne ''){ ($Gx,$Gy,$Gt)=split(/\;/,$gd); if($Gx ne $GxOLD && $Gy ne $GyOLD){ $reitti.='N'.$Gx.';'.$Gy; $GxOLD=$Gx; $GyOLD=$Gy; } } } $reitti.='|'; ## gps animaatio $GAIKA=0;$ani=''; foreach $gd (@GPSD){ chomp($gd); if($gd ne ''){ ($Gx,$Gy,$Gt)=split(/\;/,$gd); while($Gt > $GAIKA){ $ani.=$Gx.';'.$Gy.',0N'; $GAIKA=$GAIKA+3; } } } open (HANDLE,">>".$path."merkinnat_$in{'eventid'}.txt"); &lock_file; print HANDLE $in{'rataid'}."|".$in{'id'}."| $in{'suunnistaja'}|$in{'hajonta'}|$reitti|$rastit\n"; &unlock_file; close HANDLE; } $in{'kommentit'}=~ s/\n/#nl#/g; $in{'kommentit'}=~ s/\r/#cr#/g; open (HANDLE,">>".$path."kommentit_$in{'eventid'}.txt"); &lock_file; print HANDLE $in{'rataid'}."|".$in{'id'}."|$in{'suunnistaja'}||$in{'kommentit'}\n"; &unlock_file; close HANDLE; if($in{'lisaa'} eq '1' || $in{'GPS'}==1){ ## if add mode if($in{'GPS'}!=1){ ## leg lengths ($pois,$lahto,$muut)=split(/N/,$reitti,3); $sLength=0; @aControls=split(/N/,($lahto.$rastit)); $ai=0; foreach $aControl (@aControls){ $ai++; if($ai>1){ ($ax1,$ay1)=split(/\;/,$aControls[$ai-2]); ($ax2,$ay2)=split(/\;/,$aControls[$ai-1]); $aleg[$ai-1]=sqrt(($ax1-$ax2)*($ax1-$ax2)+($ay1-$ay2)*($ay1-$ay2)); # Pythagoras } } ## $usersplits=''; $splitnro=0;$splitmissing=0; @splits=split(/m/,$in{'usersplits'}); foreach $split (@splits){ $splitnro++; ($min,$sec)=split(/s/,$split); if(floor(60*$min+(1*$sec))>0 && $splitmissing==0){ $usersplits.=floor(60*$min+(1*$sec)).';'; $lastsplit=floor(60*$min+(1*$sec)); } if(floor(60*$min+(1*$sec))==0){# a split is missing if($splitmissing==0){ $splitmissing=$splitnro; } } if(floor(60*$min+(1*$sec))>0 && $splitmissing>0){ # there has been missing split before this split $sLength=0; for($j=$splitmissing;$j<$splitnro+1;$j++){ $sLength=$sLength+$aleg[$j]; } $averagespeed=(floor(60*$min+(1*$sec))-$lastsplit)/$sLength; $sLength=0; for($j=$splitmissing;$j<$splitnro+1;$j++){ $sLength=$sLength+$aleg[$j]; $usersplits.=floor($lastsplit+$sLength*$averagespeed).';'; } $splitmissing=0; $lastsplit=floor(60*$min+(1*$sec)); } } $result=$min.':'.$sec; }# if gps!=1 if($in{'GPS'}==1){ $GPSani=$ani; } open (HANDLE,">>".$path."kilpailijat_$in{'eventid'}.txt"); &lock_file; if($in{'hajonta'} eq 'null'){ $in{'hajonta'}=''; } $lahtoaika=floor(1*$lahtoaika); if($lahtoaika ==-1){ $lahtoaika=floor(1*$in{'gpsstarttime'}); } print HANDLE $in{'id'}."|".$in{'rataid'}."||$in{'suunnistaja'}|$lahtoaika||$in{'hajonta'}|$result|$usersplits|$GPSani\n"; &unlock_file; close HANDLE; } } print "\n"; exit; } ###################### tallennusonnistui-sivu ################# if ($in{"act"} eq "tallennettu"){ ## language check $kieli="fi"; foreach $rec (@languages){ if($rec eq $in{'kieli'}){ $kieli=$rec; } } open (SISAAN,"<".$path."../lang_".$kieli.".txt"); @lang=; close(SISAAN); $lang=join('',@lang); ($lang, $langkiitos)=split(/####/,join('',@lang)); print " OK







$langkiitos
"; exit; } ################# radat #################### if ($in{"act"} eq "rata"){ if($in{'kohdistus'} ne '1'){ ## tästä appletti kysyy radan ratapiirrokset ## jos viestimoodi if($in{"hajonnat"} ne''){ open (SISAAN,"<$path"."radat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$status,$nimi,$viivat)=split(/\|/,$rec); if ($in{"id"} eq $id || index($in{"hajonnat"},'s'.$id.'s')>-1){ $viivat =~ s/N/\n/g; $viivat =~ s/R/\r/g; $viivat =~ s/#//g; print "$viivat\n"; } } close(SISAAN); }else{#henk koht open (SISAAN,"<$path"."radat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$status,$nimi,$viivat)=split(/\|/,$rec); if ($in{"id"} == $id || $in{"id"} eq '99999'){ $viivat =~ s/N/\n/g; $viivat =~ s/R//g; $viivat =~ s/#//g; if($in{"id"} ne '99999'){ print "$viivat\n"; }else{ $count++; $out.=$viivat."\n"; } } } close(SISAAN); if($in{"id"} eq '99999'){ ## vain ympyrät kaikkien ratojen systeemiin if($count > 10){ @d=split(/\n/,$out); $out=''; foreach $rec (@d){ ($type,$rest)=split(/\;/,$rec,2); if($e{$rec} eq'' && $type eq '1'){ $e{$rec}=1; print "$rec\n"; } } }else{ print $out; } } }# henkkoht moodi }else{ open (SISAAN,"<$path"."rastikanta_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$x,$y)=split(/\|/,$rec); $x=floor($x*10); $y=floor($y*10); print "1;$x;$y;0;0\n"; } close(SISAAN); } } ################# ratapisteet #################### if ($in{"act"} eq "ratapisteet"){ ## tästä appletti kysyy radan ratapiirrokset open (SISAAN,"<$path"."ratapisteet_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$pisteet)=split(/\|/,$rec); if ($in{"id"} == $id ){ $pisteet =~ s/N/\n/g; print "$pisteet\n"; } } close(SISAAN); } ############################################################### sub lock_file{ if($locking eq '1'){ $exit=15; # max yritykset/sekunnit $lock_i=0; if (!flock (HANDLE,LOCK_EX) ){ $released=FALSE; until ($released eq TRUE || $lock_i>$exit) { $lock_i++; sleep 1; if (flock(HANDLE,2)) { $released=TRUE; } } } if ($lock_i>$exit) { print "Lock error. - Virhe lukituksessa.
If this is new insall: path is wrong, there is no enough permissios or locking should be turned of on this server."; exit; } } } sub trim { my $string = shift; for ($string) { s/^\s+//; s/\s+$//; } return $string; } sub unlock_file { if($locking eq '1'){ flock(HANDLE,LOCK_UN); } }
"; if($default_lang ne 'fi'){ $out=$out."

$events

"; }else{ $out=$out."

Tapahtumat:

"; } $out=$out.""; $count=0; @data = sort { (split /\|/, $a, 6)[4] cmp (split /\|/, $b, 6)[4] } @data; if($in{'first'}!=1){ @data = reverse @data; } foreach $rec (@data){ $count++; chomp($rec); ($id,$karttaid,$tyyppi,$nimi,$paiva,$seura,$taso,$notes)=split(/\|/,$rec,8); if($in{'count'}<$count && $in{'count'}+30>=$count ){ $out=$out.""; $bcolor="#f8f8ff"; if($count % 2 == 0){$bcolor="#E8E8F0";} if($default_lang ne 'fi'){ $out=$out.""; }else{ $out=$out.""; } if($Splitsbrowser==1 && $tyyppi != 3){ $out=$out. "\n"; }else{ $out=$out. "\n"; } if($splitalyzer==1 && $tyyppi != 3){ $out=$out. "\n"; }else{ $out=$out. "\n"; } } } $out=$out. "
$paiva$nimi$seura$eLevel{$taso}[$latestRoutes]$paiva$nimi$seura$eLevel{$taso}[Uusimmat piirrokset][SplitsBrowser]
 
[Splitalyzer]
 
\n"; if($OGraphApplet ==1 && $tyyppi != 3){ if($default_lang eq 'fi'){ $out=$out."

Väliaika-graafit: OGraphApplet

"; }else{ $out=$out."

Split graphics: OGraphApplet

"; } } $out=$out."
"; if($in{'count'}>0){ $out=$out."<<<"; } if($in{'count'}+30 < $count){ $out=$out." >>>"; } $out=$out."

"; $out =~s/ä/\ä\;/g; $out =~s/ö/\ö\;/g; $out =~s/å/\å\;/g; $out =~s/Ä/\Ä\;/g; $out =~s/Ö/\Ö\;/g; $out =~s/Å/\Å\;/g; print $out; }else{ $plusgif=""; $minusgif=""; $perloadimages=""; $igif=""; ## event tree menu #### open(SISAAN, "<".$path."kisat.txt"); @data=; close(SISAAN); $out= "
"; #if($default_lang ne 'fi'){ #$out.="

$events"; #}else{ #$out.="

Tapahtumat:"; #} if ((-e "".$path."coord.txt") eq "1") { $out.="
Live tracking"; open(SISAAN, "<".$path."radat_0.txt"); @trradat=; close(SISAAN); foreach $tr (@trradat){ @r=split(/\|/,$tr); $out.="

$r[2]"; } $out.="

Live GPS tracking with backround map"; } $out.="


                                                          "; $out.="

"; if($OGraphApplet ==1 && $tyyppi != 3){ if($default_lang eq 'fi'){ $out.="

Väliaika-graafit: OGraphApplet

"; }else{ $out.="

Split graphics: OGraphApplet

"; } } $out.="
$perloadimages
"; print $out; } exit; } ################# sarjat #################### if ($in{"act"} eq "sarjat"){ ## lasketaan montako piirrosta on missäkin sarjassa open (SISAAN,"<$path"."kommentit_$in{'eventid'}.txt"); @kommentit=; close(SISAAN); foreach $rec (@kommentit) { chomp($rec); ($idkilp,$id,$nimi,$aika,$kommentit)=split(/\|/,$rec); $i++; $lkm{$idkilp}++; } ## luetaan saarjat open (SISAAN,"<$path"."sarjat_$in{'eventid'}.txt"); if($in{'kohdistus'}eq "1"){ print "1;Koko rastikanta\n"; }else{ while (defined ($rec = )) { chomp($rec); ($id,$nimi)=split(/\|/,$rec); print "$id;$nimi (".(1*$lkm{$id}).")\n"; } close(SISAAN); print "99999;kaikki\n"; } } ################# kilpailijat/sarja############## if ($in{"act"} eq "kilpailijat"){ if($in{'sarja'} ne "99999"){ open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); if($in{'viesti'} ne '1'){ while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarja,$nimi,$laika,$aika,$sija,$tulos,$valiajat)=split(/\|/,$rec); if($sarjanro eq $in{'sarja'}){ print "$id;$sija $nimi $tulos\n"; } } }else{ while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarja,$nimi,$laika,$osuus,$hajonta,$tulos,$valiajat)=split(/\|/,$rec); if($sarjanro eq $in{'sarja'}){ print "$id;$hajonta;$sija $nimi $tulos\n"; } } } close(SISAAN); }else{ $j=0;$i=0; open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $i++; print $id.";$nimi\n"; $j++; } close(SISAAN); } } ################# piirtaneetkilpailijat/sarja############## ############# kilpailijalista ############## if ($in{"act"} eq "piirtaneetkilpailijat"){ ## Tästä appletti kysyy piirtaneetkilpailijat if($in{'kaikki'} eq "1" && $in{"rata"} ne "99999"){ ## tarkistetan piirtäneet tähtimerkintää varten open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $tahti{$id}="*"; } close(SISAAN); ### open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarja,$nimi,$laika,$aika,$sijahajonta,$tulos,$valiajat)=split(/\|/,$rec); if($sarjanro eq $in{'rata'}){ if($in{'viesti'} ne '1'){ print "$tahti{$id}$sijahajonta $nimi $tulos ;$id\n"; }else{ print "$tahti{$id} $nimi $tulos;$sijahajonta;$id\n"; } } } close(SISAAN); }else{ $j=0;$i=0; if($in{'viesti'} ne '1'){ open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); $i++; if($idkilp eq $in{"rata"} || $in{"rata"} eq "99999"){ ## eli on tässä sarjassa @ulos[$j]=$nimi.";".$id."\n"; $j++; } } close(SISAAN); @ulos = sort { (split '\;', $a, 2)[1] <=> (split '\;', $b, 2)[1] } @ulos; print @ulos; }else{ # viesti open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$hajonta,$viivat,$rastit)=split(/\|/,$rec); $i++; if($idkilp eq $in{"rata"} || $in{"rata"} eq "99999"){ ## eli on tässä sarjassa @ulos[$j]=$nimi.';'.$hajonta.';'.$id."\n"; $j++; } } close(SISAAN); @ulos = sort { (split '\;', $a, 3)[2] <=> (split '\;', $b, 3)[2] } @ulos; print @ulos; } } } ################# rastit kohdistukseen ############## if ($in{"act"} eq "rastisto"){ open (SISAAN,"<$path"."sarjojenkoodit_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($sarjaid,$koodit)=split(/\|/,$rec,2); $codes=$codes."|".$koodit; } @dat=split(/\|/,$codes); $ulos=""; $rastilkm=1; foreach $rec (@dat){ if($rec ne ''){ if($koodi{$rec}!=1){ $koodi{$rec}=1; $ulos=$ulos.$rec."\n"; } } } print $ulos; } ################# fotot ############# if ($in{"act"} eq "valokuvat"){ open (SISAAN,"<$path"."valokuvat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($x,$y,$url)=split(/\|/,$rec,3); if($x ne '' && $y ne '' && $url ne '' ){ $x=floor($x); $y=floor($y); print "$x;$y;$url\n"; } } } ################# valiajat ############## if ($in{"act"} eq "valiajat"){ $nro=1;$otsikko="-------------------"; open (SISAAN,"<$path"."kilpailijat_$in{'eventid'}.txt"); while (defined ($rec = )) { chomp($rec); ($id,$sarjanro,$sarjanimi,$nimi,$laika,$aika,$sija,$tulos,$valiajat)=split(/\|/,$rec); if($id eq $in{'k'.$nro} && $id < 50000){ @splits=split(/\;/,$valiajat); $old=0;$i=1; $ulos=' '.substr($nimi." ",0,19); foreach $rec (@splits){ chomp($rec); if($nro==1){ $otsikko=$otsikko.substr("--".$i."----",0,6); $i++; } $min=floor(($rec-$old)/60); $sec=($rec-$old)-60*floor(($rec-$old)/60); if ($sec <10){$sec='0'.$sec;} $old=$rec; $ulos=$ulos.substr("$min.$sec ",0,6); } if($nro==1){ print "$otsikko\n"; } print "$ulos $nimi\n"; $nro++; } } close(SISAAN); print "$otsikko\n"; print "\n Route lengths (in pixels) \n"; print "$otsikko------\n"; ### # Tästä apletti saa reittipituuded # 2|gadget_060225.zip|RouteGadget 25.2.2006 (latest)

Now you can make direct links to route drawings. Take a look at latest routes page. Route choice lengths are viewed under split times. A bug in SI csv parser fixed (non english SI files).

open (SISAAN,"<".$path."kisat.txt"); @kartat=; close(SISAAN); $viesti=0; foreach $rec (@kartat) { chomp($rec); ($id,$karttaid,$tyyppi,$nimi)=split(/\|/,$rec,4); if($id==$in{'eventid'} && $tyyppi ==3){ $viesti=1; } } $kilp=1; while($in{"k".$kilp} ne ''){ open (SISAAN,"<$path"."merkinnat_$in{'eventid'}.txt"); $ok=0; while (defined ($rec = )) { chomp($rec); ($idkilp,$id,$nimi,$aika,$viivat,$rastit)=split(/\|/,$rec); if ($in{"k".$kilp} eq $id){ $viiva[$kilp]=$viivat; $rast[$kilp]=$rastit; $nim[$kilp]=$nimi; $kilp++;$ok=1; } } close(SISAAN); if($ok==0){$kilp++;} } ## nyt onreittipiirros ja rastipisteet selvillä $kilp=1; while($in{"k".$kilp} ne''){ if($viiva[$kilp] ne ''){ print substr($nim[$kilp]." ",0,20); if($in{"k".$kilp}<100000){ @reitti=split(/N/,$viiva[$kilp]); @rastit=split(/N/,$rast[$kilp]); $i=0; $viiva[$kilp]=$viiva[$kilp]."N"; $viivatemp=""; foreach $rec (@rastit){ $i++; if($rec ne ""){ $j="NC".$i."N";$k="N".$rec."N"; ($temp,$viiva[$kilp])=split(/${k}/,$viiva[$kilp],2); $viiva[$kilp]="N".$viiva[$kilp]; $viivatemp.=$temp.$j; } } $viiva[$kilp]=$viivatemp; $i=0; foreach $rec (@rastit){ $i++;$j="NC".$i."N";$k="N".$rec.'|'.$rec."N"; $viiva[$kilp]=~ s/${j}/${k}/; } $viiva[$kilp]=~ s/^\|//; $viiva[$kilp]=~ s/NN/N/g; $viiva[$kilp]=~ s/NN/N/g; $viiva[$kilp]=~ s/NN/N/g; @rastivalit=split(/\|/,$viiva[$kilp]); $ulos=join("\n",@rastivalit); $i=0; foreach $rec (@rastivalit){ $rec=~ s/^N//; } $i_rastit=0; $i_reitti=0; $i_piste=0; $aika=0; $matka=0; $totpit=0; foreach $rc (@rastivalit){ $rastivalit[$i_rastit]=~ s/^N//; @viivab=split(/N/,$rastivalit[$i_rastit]); # lasketaan pituus $x0=0; $y0=0; $pituus=0; $i=0; foreach $rec (@viivab){ ($x1,$y1)=split(/\;/,$rec); if($i>0){ $pituus=$pituus+sqrt(($x0-$x1)*($x0-$x1)+($y0-$y1)*($y0-$y1)); }else{ $alkux=$x1;$alkuy=$y1; } $x0=$x1;$y0=$y1; $i++; } if($alkux !=$x1 && $alkuy !=$y1){ #print substr((floor($pituus/sqrt(($alkux-$x1)*($alkux-$x1)+($alkuy-$y1)*($alkuy-$y1))*1000)/10).' ',0,5).' '; #print substr((($pituus-sqrt(($alkux-$x1)*($alkux-$x1)+($alkuy-$y1)*($alkuy-$y1)))).' ',0,5).' '; print substr(floor($pituus).' ',0,5).' '; $totpit+=$pituus; }else{ print ' '; } $i_rastit++; } } print ' '.floor($totpit).' '.$nim[$kilp]."\n"; }else{ print "\n"; } $kilp++; } ### } ############################################# if ($in{'act'} eq 'help' ){ # tsekataan kieli $kieli=$default_lang; foreach $rec (@languages){ if($in{'kieli'} eq $rec){$kieli=$rec;} } open (SISAAN,"<".$path."../lang_".$kieli.".txt"); @lang=; close(SISAAN); $lang=join('',@lang); ($lang, $langkiitos)=split(/####/,join('',@lang)); open (SISAAN,"<".$path."../map.txt"); @sivu=; close(SISAAN); $sivu= join('',@sivu); ($head,$applet,$end)=split(/applet/i,$sivu); $head=$head.'table width=100% height=94% cellpadding=25 cellspacing=1>

'.$lang.'