#!/usr/bin/perl
###################################################################
# reitti.cgi or reitti.pl #
###################################################################
# Reittihärveli - Sovellus suunnistuksen reittipiirrosten #
# keräykseen ja esittämiseen tämiseen #
# Distributed by: jryyppo ät welho.com #
# ================================================================#
# Copyright (c) 2003-2005 Jarkko Ryyppö - All Rights Reserved. #
# Software by: Jarkko Ryyppö #
# Sponsored by: - #
###################################################################
# 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 Fcntl ":flock";
use POSIX;
use CGI qw(:cgi-lib);
$CGI::POST_MAX=1024 * 4000; # max 4000K posts
ReadParse();
#########################################################################################
$RG_version='RouteGadget reitti.cgi version: 6.3.2007';
##
@languages=('ca','de','ee','en','es','fi','fr','he','lt','lv','no','ru','se');
## 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='fi';
##
## Default charset:
$charset_default='ISO-8859-1';
# Language spesific charsets:
## $charset{'fi'}='ISO-8859-1'; ## example
$charset{'ru'}='WINDOWS-1251';
$charset{'he'}='WINDOWS-1255';
##
## 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 reitti.jar
##
## For IIS (Windows):
# $path='C:/inetpub/wwwroot/gadget/kartat/'; ## file path to "kartat" folder
# $httppath='../'; ## http path to the folder reitti.jar is located
##
## 4. View animation of runners without route: 0=no, 1=yes
$norouteanim=1;
##
## 5. OGraphApplet: 1=yes, 0 =no
$OGraphApplet=0;
##
## 7. Splitsbrowser : 1=yes, 0 =no
$Splitsbrowser=0;
##
## 7. Splitalyzer : 1=yes, 0 =no
$splitalyzer=0;
##
## 8. 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($in{'act'} eq 'help'){
if($charset{$in{'kieli'}} ne ''){
$charset_default=$charset{$in{'kieli'}};
}
}
print "Content-Type: text/html; charset=".$charset_default."\n\n";
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]);
##################### 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
";
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).