#!/usr/bin/perl

########################################################
#                                                      #
# Gestdb v1.0 by Michela Fontana                       #
# Website : http://www.calzatura.com                   #
# Created : 01/01/2004                                 #
#                                                      #
########################################################

############   ADJUST THESE VARIABLES   ################

        use CGI;
        use DBI;
        

# Get the Dbase information

$mysql1  = 'calzatura_com_calzatura';
$mysql2  = 'mysql.register.it';
$mysql3  = 'GS1219_CALZATURA';
$mysql4  = 'michela';
       
# Get the form variables

	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 = '/italy/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 = '/italy/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;
	}


#------------------------------------------------- M A I N
print "Content-type: text/html\n\n";
$numero         = $FORM{'numero'};
$numero1         = $FORM{'numero1'};
$username = 'calzatodo';
$password = 'password';

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

my $stat = $dbh->prepare("SELECT ID, RAGIONESOCIALE, INDIRIZZO, CAP, CITTA, PROVINCIA, NAZIONE, MAIL,
                          URL, TELEFONO, FAX, DESCRIZIONEITA, MARCHI, IMMAGINE, PAGA, CATEGORIA1, CATEGORIA2, CATEGORIA3, 
                          NOMECONTATTO, COGNOMECONTATTO, MAILCONTATTO, NOMEACQUISTI, COGNOMEACQUISTI, CELLULAREACQUISTI,
                          NOMEVENDITE, COGNOMEVENDITE, CELLULAREVENDITE  FROM Base
                          WHERE ID='$numero1'");

my $return = $stat->execute;

($id, $rag, $indirizzo, $cap, $citta, $provincia, $nazione, $mail,
 $url, $telefono, $fax, $descrizione, $marchi, $immagine, $paga, $cat1, $cat2, $cat3, $nomecontatto, $cognomecontatto, $emailpersonale,
 $nomeacquisti, $cognomeacquisti, $cellulareacquisti, $nomevendite, $cognomevendite, $cellularevendite) = $stat->fetchrow_array;

($nazioneimmagine) = $dbh->selectrow_array("SELECT IMMAGINE FROM Nazioni WHERE ID='$nazione'");

$image = 'http://www.calzatura.com/images/banner/banner_motore/clicca.gif';

if ($immagine =~ 'http') {
   $image = $immagine;
}

print "$heading";

print "<body topmargin=0 bgcolor=#E8E8E8 leftmargin=2 link=#305790 vlink=#4375C0 alink=#305790 text=#305790>
       <div align=center><center>
<table border=0 cellspacing=0 width=100% height=1 cellpadding=0>
  <tr>
    <td width=2% bgcolor=#C8DCF0 height=21 valign=top>
    <p align=left><font face=Verdana size=2 color=#000080>
    <img src=http://www.calzatura.com/images/angle1.gif></font></td>
    <td width=9% height=21 bgcolor=#CDDEFD></td>
    <td width=70% height=21 bgcolor=#CDDEFD><font face=Verdana size=2 color=#B30000><b>$rag</b></font></td>
    <td width=2% align=right bgcolor=#C8DCF0 height=21 valign=top>
    <p align=right><font face=Verdana size=2 color=#000080>
    <img src=http://www.calzatura.com/images/angle2.gif></font></td>
    <font FACE=arial,helvetica COLOR=000000 SIZE=1>
  </tr>
  <tr>
    </font><td width=2% bgcolor=#C8DCF0 height=21><font face=Verdana size=1
    color=#000080></font></td>
    <td width=9% height=21 bgcolor=#E1E1E1><font face=Verdana size=1 color=#000080><strong>MARCHI:</strong>
    </font></td>
    <td width=70% height=21 bgcolor=#E1E1E1><font face=Verdana color=#000080
    size=2>$marchi</font></td>
    <td width=2% align=right bgcolor=#C8DCF0 height=21><font face=Verdana size=1
    color=#000080></font></td>
    <font FACE=arial,helvetica COLOR=000000 SIZE=1>
  </tr>
  <tr>
    </font><td width=2% valign=bottom bgcolor=#C8DCF0 height=1><font face=Verdana
    size=2 color=#000080><img src=http://www.calzatura.com/images/angle3.gif></font></td>
    <td width=9% height=1 bgcolor=#C8DCF0><font face=Verdana size=2 color=#000080></font></td>
    <td width=70% height=1 bgcolor=#C8DCF0><font face=Verdana size=2 color=#000080></font></td>
    <td width=2% align=right valign=bottom bgcolor=#C8DCF0 height=1><font
    face=Verdana size=2 color=#000080><img
    src=http://www.calzatura.com/images/angle4.gif></font></td>
    <font FACE=arial,helvetica COLOR=000000 SIZE=1>
  </tr>
</table>
</center></div></font>
</body>";

print "$footing";

$dbh->disconnect;

exit;

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

sub error {    
	$noshow = 1;
	&heading;
	print "<CENTER><FONT $font><h2>File Access Error</h2><P><B>You have an error in your PATH configuration variables in the $ENV{'SCRIPT_NAME'} file.</B><P>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.<P>If you require help installing this script please consider purchasing the professional version of this script. Your purchase includes full tech support and installation.<P><B>Get it at : <A HREF=http://www.getperl.com/easysearch/>http://www.getperl.com/easysearch/</A></B></FONT></CENTER><P>\n";
	&footer;
}
