#!/usr/bin/perl ############################################################################## # Meeting.pl $basedir = "/home/stephm69/public_html/kayakdemer"; $rass_dir = "rassemblement/2004"; $temp_pg_file = "aff_page.txt"; @stats_names = ("nbr_pers","nbr_empl","tr_need","tr_offre","trkayak_need","trkayak_offre"); %stats_names = ("nbr_pers","Nombre de personnes", "nbr_empl","Nombre d\'emplacements", "tr_need","Places kayakistes demandées", "tr_offre","Places kayakistes offertes", "trkayak_need","Places kayaks demandées", "trkayak_offre","Places kayaks offertes", "nom","Nom", "email","Courriel", "telephone","Numéro de téléphone", "lieu","Lieu de départ", "attente","Personnes en attente"); $max_part=65; ############### &parse_form; &get_variables; if($fct eq "remove") { &get_stats; $STATS{'nbr_pers'} = $STATS{'nbr_pers'} + $FORM{'nmbr'}; $STATS{'nbr_empl'} = $STATS{'nbr_empl'} + $FORM{'emplacements'}; &store_stats; $dtlpg = "inscription_dtls.html"; &write_stats; &error("Le nombre de participants a été modifié $page"); } if($fct eq "prio") { &get_compnmbr; $nmbr_prio = $nmbr_prio + $FORM{'nmbr'}; &set_compnmbr; @stats_names = ("attente"); $STATS{"attente"} = $nmbr_prio; $dtlpg = "priorite_dtls.html"; &write_stats; &error("Le nombre d\'inscriptions en priorité a été modifié $page"); } if($page) { open(MAIN,">$basedir/$rass_dir/$temp_pg_file") || die $!; print MAIN "$page"; close(MAIN); &error("La page affichée sera $page"); } &get_stats; open(MAIN,"$basedir/$rass_dir/$temp_pg_file") || die $!; $curpg =
; close(MAIN); if($STATS{'nbr_pers'} >= $max_part && $curpg eq "inscription_form.html") { open(MAIN,">$basedir/$rass_dir/$temp_pg_file") || die $!; print MAIN "complet.html"; close(MAIN); } elsif($STATS{'nbr_pers'} < $max_part && $curpg eq "complet.html") { open(MAIN,">$basedir/$rass_dir/$temp_pg_file") || die $!; print MAIN "inscription_form.html"; close(MAIN); } &produce_pg; ####################### # Parse Form Subroutine sub parse_form { local($name,$value); # Get the input if($ENV{'CONTENT_LENGTH'}) { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } $change = $buffer; # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Remove any NULL characters, Server Side Includes $value =~ s/\0//g; $value =~ s///g; if ($allow_html != 1) { $value =~ s/<([^>]|\n)*>//g; } else { unless ($name eq 'body') { $value =~ s/<([^>]|\n)*>//g; } } $FORM{$name} = $value; } } ############### # Get Variables sub get_variables { if ($FORM{'fct'}) { $fct = "$FORM{'fct'}"; } if ($FORM{'page'}) { $page = "$FORM{'page'}"; } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $month = ($mon + 1); @months = ("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"); $year += 1900; $long_date = sprintf("%02d %s %4d",$mday,$months[$mon],$year); $year %= 100; if ($use_time == 1) { $date = sprintf("%02d:%02d:%02d %02d/%02d/%02d",$hour,$min,$sec,$month,$mday,$year); } else { $date = sprintf("%02d/%02d/%02d",$mday,$month,$year); } } ########## sub get_stats { open(MAIN,"$basedir/$rass_dir/stats.txt") || die $!; @all_stats =
; close(MAIN); foreach $sl (@all_stats) { ($tag,$val)=split(/\|/,$sl); $val =~ s/\s$//g; $val =~ s/\n//g; $STATS{$tag}=$val; } } ########## sub store_stats { open(MAIN,">$basedir/$rass_dir/stats.txt") || die $!; foreach $sl (@stats_names) { print MAIN $sl."|".$STATS{$sl}."\n"; } close(MAIN); } ######### sub get_compnmbr { open(MAIN,"$basedir/$rass_dir/stats_prio.txt") || die $!; $nmbr_prio =
; close(MAIN); } ######### sub set_compnmbr { open(MAIN,">$basedir/$rass_dir/stats_prio.txt") || die $!; print MAIN "$nmbr_prio"; close(MAIN); } ############# sub write_stats { $prnt = 1; open(MAIN,"$basedir/$rass_dir/$dtlpg") || die $!; @lines =
; close(MAIN); open(MAIN,">$basedir/$rass_dir/$dtlpg") || die $!; foreach $dpl (@lines) { if($dpl =~ //) { $prnt = 0; print MAIN "\n"; print MAIN "\n"; foreach $sv (@stats_names) { print MAIN "\n"; } print MAIN "
".$stats_names{$sv}."".$STATS{$sv}."
\n"; } elsif($dpl =~ //) { print MAIN "\n"; $prnt = 1; } elsif($prnt) { print MAIN $dpl; } } } ########## sub produce_pg { open(MAIN,"$basedir/$rass_dir/$temp_pg_file") || die $!; $pgtoshow =
; close(MAIN); if($fct eq "form") { $pgtoshow = "inscription_form.html"; } $total = $STATS{'nbr_pers'}; $reste = $max_part - $total; open(MAIN,"$basedir/$rass_dir/$pgtoshow") || die $!; @lines =
; close(MAIN); print "Content-type: text/html\n\n"; foreach $il (@lines) { if($il =~ //) { print " Places déjà réservées: $total (Reste $reste places)
"; } else { print "$il"; } } } ######################################### sub error { $error = $_[0]; print "Content-type: text/html\n\n"; print "$error
\n"; print "[ Retour au formulaire ]\n"; exit; }