#!/usr/bin/perl ############################################################################## #Services.pl # Perl program by Stéphane Maltais # # services.pl Version 1.0 # ############################################################################## ############## # DEBUG VARIABLES #$basedir = "c:/temp/services"; ############## $basedir = "/home/stephm69/public_html/kayakdemer/services"; $cgi_url = "http://www.kayakdemer.net/services"; $services_url = "http://www.kayakdemer.net/services"; $regions_file="regions.txt"; $type_srv_file="type_services.txt"; $tous_services="tous_services.txt"; $template_base = "servicesbase_t.php"; $template = "services_t.php"; $background_im = "http://www.kayakdemer.net/bckgrnd.gif"; $title = "Kayak de Mer: Répertoire de services"; # Done ########################################################################### &get_info; &produire_page; ####################### # Parse Form Subroutine sub get_info { local($name,$value); # Get the input $buffer = $ENV{'QUERY_STRING'}; # read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); $change = $buffer; # Split the name-value pairs @pairs = split(/&/, $change); 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; # Remove HTML $value =~ s/<([^>]|\n)*>//g; $FORM{$name} = $value; } } ############################### # Écrire la page des catégories sub produire_page { open(MAIN,"$basedir/$tous_services") || die $!; @tous_services =
; close(MAIN); $nmbr_services = scalar (@tous_services); open(MAIN,"$basedir/$regions_file") || die $!; @regions =
; close(MAIN); foreach $rg (@regions) { ($rg_srt,$rg_lg)=split(/\|/,$rg); $REGION{$rg_srt}=$rg_lg; } open(MAIN,"$basedir/$type_srv_file") || die $!; @type_service =
; close(MAIN); foreach $srv (@type_service) { ($srv_srt,$srv_lg)=split(/\|/,$srv); $SERVICE{$srv_srt}=$srv_lg; } ############################# if (!$FORM{'rg_sel'}) { $tmpl=$template_base; open(MAIN,"$basedir/$tmpl") || die $!; @main =
; close(MAIN); print "Content-type: text/html\n\n"; foreach $main_line (@main) { if ($main_line =~ //) { print " \n"; print "
\n"; print "
\n"; print "RECHERCHE DE SERVICES
\n"; print "$nmbr_services services répertoriés

\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
Régions
Types de service
(Offrant au moins un de ceux sélectionnés)
"; print "\n"; print "\n"; foreach $short_service (sort keys %SERVICE) { $lg_service=$SERVICE{$short_service}; print "\n"; } print "
TOUS LES TYPES DE SERVICE 
$lg_service 
\n"; } else { print "$main_line"; } } } ### Fin fct="" ####################### if ($FORM{'rg_sel'}) { $servprnt=0; $tmpl=$template; open(MAIN,"$basedir/$tmpl") || die $!; @main =
; close(MAIN); print "Content-type: text/html\n\n"; foreach $main_line (@main) { if ($main_line =~ //) { print " \n"; print "
\n"; $reg_srt=$FORM{'rg_sel'}; $region=$REGION{$reg_srt}; $ss=0; if($FORM{'rg_sel'} eq "tous") { $region="Toutes les régions"; } if($FORM{'tous_serv'} eq "on") { $services_sels="Tous les types de service"; $ss=1; } else { foreach $sn (keys %SERVICE) { if($FORM{$sn} eq "on") { if($virg == 1) { $services_sels .=", "; } $services_sels.=$sn; $virg = 1; $ss=1; } } } if($ss == 0) { $services_sels="VOUS DEVEZ SÉLECTIONNER UN TYPE DE SERVICE"; } print "SERVICES CORRESPONDANT À VOS CRITÈRES:
Région: $region
Services: $services_sels

\n"; print "[ AUTRE RECHERCHE ]

\n"; print "\n"; print "\n"; foreach $entreprise (@tous_services) { ($ref_nbr,$nom,$region,$services,$adresse,$ville,$code,$telephone,$url,$contact,$email,$commentaires,$affiliate)=split(/\|/,$entreprise); @servs=split(/\:/,$services); foreach $servp (@servs) { ($servcd,$dispv)=split(/\=/,$servp); $SERV{$servcd}=$dispv; } @affil=split(/\:/,$affiliate); $serv_disp=0; foreach $chk_disp (keys %SERVICE) { if($FORM{$chk_disp} eq "on" && $SERV{$chk_disp} ==1 || $FORM{'tous_serv'} eq "on") { $serv_disp=1; } } $apr=0; foreach $tp (@affil) { if($tp eq $FORM{'rg_sel'}) { $apr=1; } } if (($region eq $FORM{'rg_sel'} || $FORM{'rg_sel'} eq "tous" || $apr ==1) && $serv_disp==1 && $nom) { print "\n"; foreach $val (keys %SERV) { print ""; } print "\n"; ++$servprnt; } } if ($servprnt ==0) { print "\n"; } else { print "\n"; } else { print "SERVICES AFFICHÉS\n"; } } print "
Entreprise
Services
"; print ''; if($FORM{'rg_sel'} eq "tous" || $FORM{'rg_sel'} eq "can" || $FORM{'rg_sel'} eq "pq" || $FORM{'rg_sel'} eq "estcan") { $rer_ln=$REGION{$region}; print "
$rer_ln"; } else { print "
$ville"; } print " (pourv.#$ref_nbr)
 "; if ($SERV{$val} == 1) { $lgservname=$SERVICE{$val}; $alt_txt=$SERVICE{$val}; $alt_txt =~ s/\n//g; $alt_txt =~ s/\s$//g; print "\"$alt_txt\""; } print "


AUCUN SERVICE NE CORRESPOND
À VOTRE RECHERCHE


$servprnt "; if($servprnt ==1) { print "SERVICE AFFICHÉ
\n"; } else { print "$main_line"; } } } ## Fin fct="pregion" ############################ }