#!/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;

($nomenazione,$areacode, $urlnazione) = $dbh->selectrow_array("SELECT NAZIONE, AREACODE, IMMAGINE FROM Nazioni WHERE ID='$nazione'");
($cittanome, $cittanaz, $cittaimg, $cittaaero, $cittatreno) = $dbh->selectrow_array("SELECT CITTA, NAZIONE, IMG, LINKAERO, LINKTRENO FROM Mappy WHERE CITTA='$citta'");

$esiste = '';
($esiste) = $dbh->selectrow_array("SELECT NOME FROM Myway WHERE PASSWORD like '$password'");

$dbh->disconnect;

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 width=11 height=12></font></td>
    <td width=79% height=21 bgcolor=#CDDEFD><font face=Verdana size=2 color=#B30000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

if ($urlnazione =~ 'http') {
        print "<img src=$urlnazione width=18 height=12 border=0 alt='$nomenazione'>&nbsp;";
}

if ($esiste ne '') { 
$collegamyway = "http://www.calzatura.com/".$esiste.".it";
}

if (($url eq '') && ($esiste ne '')) {
   $url = $collegamyway;
}

if ($url !~ 'http://') {
    $url = '';
}

if ($url ne '') { 
print "<strong><a href=$url target=_blank>$rag </a></strong>"; 
}
else { 
print "<strong>$rag </b></strong>";
}

print "</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 width=11 height=12></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=79% height=21 bgcolor=#E1E1E1 valign=top>
    <div align=center>
      <center>
      <table border=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=100% id=AutoNumber1 cellpadding=8>
        <tr>
          <td width=50% valign=top>
          <img border=0 src=$cittaimg></td>
          <td width=50% valign=top>
          <p align=center><font face=Verdana size=2 color=#B30000>";

if ($url ne '') { 
print "<strong><a href=$url target=_blank>$rag </a></strong>"; 
}
else { 
print "<strong>$rag </strong>";
}

print " </font></p>
          <p align=left><font face=Arial size=2>";

if ($indirizzo ne '') {
print "$indirizzo<br>";
}

if ($cap ne '') {
print "$cap ";
}

if ($citta ne '') {
print " $citta<br>";
}

if ($provincia ne '') {
print "$provincia <br>";
}

if ($nomenazione ne '') {
print "$nomenazione <br>";
}

if ($telefono ne '') {
print "Tel: ";
if ($areacode ne '') { print " +$areacode "; }
print " $telefono <br>";
}

if ($fax ne '') {
print " Fax: ";
if ($areacode ne '') { print " +$areacode "; }
print " $fax";
}

print " </font></p>
          <p align=center>&nbsp;</p>";

if (($cittaaero ne '') || ($cittatreno ne '')) {
print"          <p align=center><font face=Arial size=2><b>Come raggiungerci:</b></font></p>
          <div align=center>
            <center>
            <table border=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=100% id=AutoNumber2>";

if ($cittaaero ne '') {
print "              <tr>
                <td width=34% align=center><font face=Arial size=2>
                <a href=$cittaaero target=_blank><img border=0 src=http://www.calzatura.com/images/search/air.gif width=45 height=45></a></font></td>
                <td width=66%><b><font size=2 face=Arial><a href=$cittaaero target=_blank>via aerea</a></font></b></td>
              </tr>";
}
if ($cittatreno ne '') {
print "              <tr>
                <td width=34% align=center>
                <a href=$cittatreno target=_blank><img border=0 src=http://www.calzatura.com/images/search/train.gif width=45 height=45></a></td>
                <td width=66%><b><font size=2 face=Arial><a href=$cittaaero target=_blank>via treno</a></font></b></td>
              </tr>";
}
print "            </table>
            </center>
          </div>";
}

print "          <p><font face=Arial size=2></font></p>

          <p>&nbsp;</td>
        </tr>
      </table>
      </center>
    </div>
    </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 width=11 height=12></font></td>
    <td width=79% 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 width=11 height=12></font></td>
  </tr>
</table>
</center></div>
</body>";

print "$footing";

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;
}
