#!/usr/bin/perl

########################################################
#                                                      #
# Gestdb v1.0 by Michela Fontana                       #
# Website : http://www.calzatura.com                   #
# Created : 11/07/2001                                 #
#                                                      #
########################################################

        use CGI;
        use DBI;

	$sitetitle = 'Calzatura';

	if ($ENV{'REQUEST_METHOD'} eq 'GET') {
        	$buffer = $ENV{'QUERY_STRING'};
	}	
	else {
        	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	}

# Break em up into a format the script can read

	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs) {
        	($name, $value) = split(/=/, $pair);
        	$value =~ tr/+/ /;
        	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        	$FORM{$name} = $value;
	}

# Get the heading information

  $headfile = '/english/head/head_motore.txt';

   unless (open (DATA,"$headfile")) {die (&error);}
		if ($uselock eq '1') {
			flock DATA, 2;
			seek DATA, 0, 0;
		}
		@headinfo = <DATA>;
		if ($uselock eq '1') {
			flock DATA, 8;
		}
	close (DATA);
	foreach $headline (@headinfo){
		$heading = $heading.$headline;
	}

# Get the footer information

  $footfile = '/english/head/foot.txt';

   unless (open (DATA,"$footfile")) {die (&error);}
		if ($uselock eq '1') {
			flock DATA, 2;
			seek DATA, 0, 0;
		}
		@footinfo = <DATA>;
		if ($uselock eq '1') {
			flock DATA, 8;
		}
	close (DATA);
	foreach $footline (@footinfo){
		$footing = $footing.$footline;
	}

# Get the Dbase information

$mysql1  = 'calzatura_com_calzatura';
$mysql2  = 'mysql.register.it';
$mysql3  = 'GS1219_CALZATURA';
$mysql4  = 'michela';

#------------------------------------------------- M A I N
print "Content-type: text/html\n\n";

$c = $FORM{'c'};

if ($c eq 'trading') {
   $iniziale = 99 ;
   $finale   = 199 ;
}

if ($c eq 'calzaturifici') {
   $iniziale = 200 ;
   $finale   = 299 ;
}

if ($c eq 'pelletterie') {
   $iniziale = 300 ;
   $finale   = 399 ;
}

if ($c eq 'componenti') {
   $iniziale = 400 ;
   $finale   = 499 ;
}

if ($c eq 'macchinari') {
   $iniziale = 500 ;
   $finale   = 599 ;
}

if ($c eq 'servizi') {
   $iniziale = 600 ;
   $finale   = 699 ;
}

if ($c eq 'agenti') {
   $iniziale = 700 ;
   $finale   = 799 ;
}

if ($c eq 'utilita') {
   $iniziale = 800 ;
   $finale   = 899 ;
}

print "$heading";

# Open DB connection
$dbh = DBI->connect("DBI:mysql:$mysql1:$mysql2", $mysql3, $mysql4);
if (!dbh) { print "Errore!"; }

my $stat = $dbh->prepare("SELECT ID, CAT1ITA, CAT1ENG, CAT1SPA,
                                 CAT2ITA, CAT2ENG, CAT2SPA,
                                 CAT3ITA, CAT3ENG, CAT3SPA
                               FROM Categorie WHERE ID >= '$iniziale' AND ID <= '$finale' order by CAT1ENG,CAT2ENG");

my $return = $stat->execute;

$cat1 = '';
$cat2 = '';

while (($id, $cat1ita, $cat1eng, $cat1spa, $cat2ita, $cat2eng, $cat2spa, $cat3ita, $cat3eng, $cat3spa) = $stat->fetchrow_array) {

if ($cat1 ne $cat1eng) {
   print "<div align=center><center>
          <table border=0 cellpadding=0 width=100% bgcolor=#CCCCCC>
          <tr>
          <td width=100% bgcolor=#CDDEFD>
          <font color=#000040 face=Arial size=1><strong>";
   print "$cat1eng";
   $cat1 = $cat1eng;
   print "</strong></font></td>
          </tr>
          </table></div></center>
          <div align=center><center>
          <table border=0 cellpadding=0 width=100% bgcolor=#CCCCCC>
          <tr>";
}

if ($cat2 ne $cat2eng) {
   if ($cat3eng eq '') {
      print "</tr><tr><td width=13% bgcolor=#E8E8E8><strong><font color=#000040 face=Arial size=1>";
      $cat2 = $cat2eng;
      print "</font></strong></td><td width=87% bgcolor=#E8E8E8><font color=#000040 face=Arial size=1>";
      print "<a href=http://www.calzatura.com/search_eng/gstcalza.cgi?&categoria=$id>$cat2eng</a>";
      }
   else
      {
      print "</tr><tr><td width=13% bgcolor=#E8E8E8><strong><font color=#000040 face=Arial size=1>";
      print "$cat2eng";
      $cat2 = $cat2eng;
      print "</font></strong></td><td width=87% bgcolor=#E8E8E8><font color=#000040 face=Arial size=1>";
   }
}

if ($cat3eng ne '') {
   print "<a href=http://www.calzatura.com/search_eng/gstcalza.cgi?&categoria=$id>$cat3eng</a> - ";
}

}

print "</font></td>
  </tr>
  </table></div></center>";

$dbh->disconnect;

print "$footing";

exit;

#------------------------------------------------- E N D  M A I N


sub heading {
	print "$heading";
}

sub footer {
        print "$footer";
        exit;
}

sub error {    
	$noshow = 1;
	&heading;
	print "<body bgcolor=#CCCCCC text=#000080 link=#000080 vlink=#000080 alink=#000080><CENTER><font face=Verdana size=1 color=#B30000><h2 align=center>File Access Error</font></h2><p align=center><font face=Verdana size=1 color=#000080><B>You have an error in your PATH configuration variables in the $ENV{'SCRIPT_NAME'} file.</B></font></p><p align=center><font face=Verdana size=1 color=#000080>Your server reports that your BASE path is : $ENV{'DOCUMENT_ROOT'}<BR>Note that this is reported as your BASE path, not the FULL path to your files.</font></p><p align=center><font face=Verdana size=1 color=#000080><B>Contact us:</font></p><A HREF=http://www.calzatura.com>http://www.calzatura.com</A></B></FONT></CENTER><P></body>\n";
	&footer;
}
