#!/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";
$numero1  = $FORM{'numero1'};
$numero  = $FORM{'numero'};
$username = 'calzatodo';
$password = 'password';
$user1    = $FORM{'user1'};
$psw1     = $FORM{'psw1'};
$opz      = $FORM{'opz'};

# 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, DESCRIZIONEENG, DESCRIZIONESPA, DESCRIZIONEPORT,
                                 MARCHI, CATEGORIA1, CATEGORIA2, CATEGORIA3, 
                                 NOMECONTATTO, COGNOMECONTATTO, POSIZIONECONTATTO, DATANASCITACONTATTO, CELLULARECONTATTO, MAILCONTATTO,
                                 NOMEACQUISTI, COGNOMEACQUISTI, CELLULAREACQUISTI, MAILACQUISTI,
                                 NOMEVENDITE, COGNOMEVENDITE, CELLULAREVENDITE, MAILVENDITE,
                                 USER, PASSWORD, PAROLECHIAVE, PAGA, IMMAGINE, LINGUA,
                                 LINGUADESC, DESCRIZIONE, FIERE  FROM Base
                          WHERE ID='$numero1'");

my $return = $stat->execute;

($id, $rag, $indirizzo, $cap, $citta, $provincia, $nazione, $mail, $url, $telefono, $fax, 
$descrizioneita, $descrizioneeng,$descrizionespa,$descrizioneport, $marchi, $cat1, $cat2, $cat3,
$nomecontatto, $cognomecontatto, $posizionecontatto, $datacontatto, $cellularecontatto, $mailcontatto,
$nomeacquisti, $cognomeacquisti, $cellulareacquisti, $mailacquisti,
$nomevendite, $cognomevendite, $cellularevendite, $mailvendite, $user, $password,
$parolechiave, $paga, $immagine, $lingua, $linguadesc, $descrizione, $fiere) = $stat->fetchrow_array;

($nomenazione,$nazioneimmagine) = $dbh->selectrow_array("SELECT NAZIONE,IMMAGINE FROM Nazioni WHERE ID='$nazione'");
($posita,$poseng, $posspa) = $dbh->selectrow_array("SELECT POSIZIONEITA,POSIZIONEENG,POSIZIONESPA FROM Posizioni WHERE ID='$posizionecontatto'");

($from,$frommail) = $dbh->selectrow_array("SELECT RAGIONESOCIALE, MAIL FROM Base WHERE ID LIKE '$numero'");

$dbh->disconnect;

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


print "<html>

<head>
<title>CALZATURA.COM - Invia Mail a $rag</title>
</head>
<body topmargin=0 bgcolor=#E8E8E8 leftmargin=2 link=#305790 vlink=#4375C0 alink=#305790 text=#305790>
<div align=center><center>
<table border=0 cellspacing=0 bordercolor=#111111 width=100%>
  <tr>
    <td width=20% bgcolor=#808080 valign=middle>
    <p align=center><img border=0 src=http://www.calzatura.com/images/mail002.gif width=150 height=25></td>
    <td width=10% bgcolor=#808080 valign=middle>
    <p align=left><b><font face=Arial color=#FFFFFF size=1>INVIA MAIL A:</font></b></td>
    <td width=50% bgcolor=#808080 valign=middle><p align=center>";

if ($opz eq 'az') {
print " <font face=Arial color=#FFFFFF size=2><strong>$rag</strong></font>";
}

if ($opz eq 'cont') {
print " <font face=Arial color=#FFFFFF size=1>";
   if (($nomecontatto ne '') || ($cognomecontatto ne '')) { print " $nomecontatto $cognomecontatto <br>"; }
   if ($posizionecontatto ne '') { print "  $posita <br>";}
print "</font><font face=Arial color=#FFFFFF size=2><strong> $rag</strong></font>";
}

if ($opz eq 'vend') {
print " <font face=Arial color=#FFFFFF size=1>";
    if (($nomevendite ne '') || ($cognomevendite ne '')) { print " $nomevendite $cognomevendite <br> ";}
print " (Contatto Vendite) </font><br><font face=Arial color=#FFFFFF size=2><strong> $rag</strong></font>";
}

if ($opz eq 'acq') {
print " <font face=Arial color=#FFFFFF size=1>";
    if (($nomeacquisti ne '') || ($cognomeacquisti ne '')) { print " $nomeacquisti $cognomeacquisti <br> ";}
print " (Contatto Acquisti) </font><br><font face=Arial color=#FFFFFF size=2><strong> $rag</strong></font>";
}

print " </td>
      <td width=20% bgcolor=#808080 valign=middle>
      <p align=center><font face=Arial size=2 color=#FFFFFF>";

if ($image ne '') {
print " <img border=0 src=$image>";
}

print" </font></td>
    </tr>
  </table>
  </center></div>
<div align=center><center>
<table border=0 cellpadding=2 cellspacing=0 bordercolor=#111111 width=100%>
  <tr>
  <form method=post action=AReasymail2.cgi>
  <input type=hidden name=mail value=$mail>
  <input type=hidden name=user1 value='$user1'>
  <input type=hidden name=psw1 value='$psw1'>
  <input type=hidden name=numero value='$numero'>
  <input type=hidden name=numero1 value='$numero1'>
  <input type=hidden name=opz value='$opz'>
      <td width=15% height=24 bgcolor=#E1F0FF><font face=Arial size=1>Ragione Sociale</font></td>
      <td width=35% bgcolor=#E1F0FF>
      <input type=text name=ragione size=40";

if ($numero ne '') {
print " value='$from'";
}

print "></td>
      <td width=10% height=24 bgcolor=#E1F0FF><font face=Arial size=1><p align=center>E-Mail</font></p></td>
      <td width=40% bgcolor=#E1F0FF><input type=text name=from size=42";

if ($numero ne '') {
print " value='$frommail'";
}

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

  <table border=0 cellspacing=1 width=100% bordercolor=#111111>
    <tr>
      <td width=15% bgcolor=#99CCFF><font face=Verdana size=1>Oggetto:</font></td>
      <td width=85% bgcolor=#99CCFF>
      <input type=text name=oggetto size=100></td>
    </tr>
    <tr>
      <td width=15% bgcolor=#99CCFF valign=top>
      <font face=Verdana size=1>Messaggio:</font></td>
      <td width=85% bgcolor=#99CCFF>
      <textarea rows=7 name=messaggio cols=75></textarea><br>
      <font face=Verdana size=1><p align=center>
      <input type=image name=invia src=http://www.calzatura.com/images/invia.jpg alt=Invia border=0 width=61 height=24></font></td>
  </form>
    </tr>
  </table>
</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;
}
