#!/usr/bin/perl

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

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

        use CGI;
        use DBI;

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



$utente   = $FORM{'utente'};
$password = $FORM{'password'};
$identificativo = $FORM{'identificativo'};

$rivista    = $FORM{'rivista'};
$categoria    = $FORM{'categoria'};
$testo  = $FORM{'testo'};
$mese    = $FORM{'mese'};
$anno    = $FORM{'anno'};
$azienda2 = $FORM{'azienda'};

if ($FORM{'B3'} ne '') {
$condizione = ' WHERE ';
if ($rivista ne '') {
    $condizione = $condizione." RIVISTA LIKE '$rivista' ";
    }
if ($categoria ne '') {
   if ($categoria ne '') {
      $condizione = $condizione." and ";
   }
    $condizione = $condizione." CATEGORIA LIKE '$categoria' ";
    }
if ($azienda2 ne '') {
   $azienda = $FORM{'azienda'}.'%';
# Open DB connection
   $dbh = DBI->connect("DBI:mysql:calzatura_com_calzatura:mysql.register.it", GS1219_CALZATURA, michela);
   if (!dbh) { print "Errore!"; }
   my $stat2 = $dbh->prepare("SELECT ID, RAGIONESOCIALE, IMMAGINE FROM Base
                             WHERE RAGIONESOCIALE LIKE '$azienda' ORDER BY RAGIONESOCIALE");
   my $return = $stat2->execute;
   $indice1 = 0;
   while (($id2, $rag2, $immagine) = $stat2->fetchrow_array) {
         if ($indice1 > 0) {
            $cond2 = $cond2." or ";
         }
         $indice1 = $indice1 + 1;
         $cond2 = $cond2." AZIENDA='$id2' ";
   }


$dbh->disconnect;

   if ($cond2 ne '') {
      if ($condizione ne ' WHERE ') { $condizione = $condizione.' and';}
      $condizione = $condizione." (".$cond2.")";
   }
}

if ($mese ne '') {
   if ($condizione ne ' WHERE ') { $condizione = $condizione.' and';}
      $umese = "%-$mese-%";
      $condizione = $condizione." DATARIVISTA LIKE '$umese' ";
    }
if ($anno ne '') {
   if ($condizione ne ' WHERE ') { $condizione = $condizione.' and';}
      $uanno = "$anno-%-%";
      $condizione = $condizione." DATARIVISTA LIKE '$uanno' ";
    }
if ($testo ne '') {
   $testo2 = '%'.$testo.'%';
   if ($condizione ne ' WHERE ') { $condizione = $condizione.' and';}
      $condizione = $condizione." TITOLOITA LIKE '$testo2' or REDITA LIKE '$testo2'";
   }
}

if ($condizione eq ' WHERE ') { $condizione = '';}

print "Content-type: text/html\n\n";

        if ($mese eq '01') { $visualmese='gennaio'; }
        if ($mese eq '02') { $visualmese='febbraio'; }
        if ($mese eq '03') { $visualmese='marzo'; }
        if ($mese eq '04') { $visualmese='aprile'; }
        if ($mese eq '05') { $visualmese='maggio'; }
        if ($mese eq '06') { $visualmese='giugno'; }
        if ($mese eq '07') { $visualmese='luglio'; }
        if ($mese eq '08') { $visualmese='agosto'; }
        if ($mese eq '09') { $visualmese='settembre'; }
        if ($mese eq '10') { $visualmese='ottobre'; }
        if ($mese eq '11') { $visualmese='novembre'; }
        if ($mese eq '12') { $visualmese='dicembre'; }


print "<body bgcolor=#cccccc text=#000080 link=#000080 vlink=#000080 alink=#000080 topmargin=0 leftmargin=0>
<table border=0 cellpadding=0 cellspacing=3 width=100%>
  <tr>
    <td width=70% bgcolor=#808080><font face=Verdana color=#FFFFFF><p align=center><strong>LE AZIENDE INFORMANO</strong></font></td>
<td width=10% bgcolor=#808080>
        <form action=mkinserimento.cgi>
        <input type=hidden name=utente value=$utente>
        <input type=hidden name=password value=$password>
        <input type=hidden name=identificativo value=$identificativo>
        <input type=submit value='Inserisci' name=B1 style='background-color: rgb(255,255,255); border: thin solid rgb(0,0,128)'></td>
        </form>
<td width=10% bgcolor=#808080>
        <form action=mkchange.cgi>
        <input type=hidden name=utente value=$utente>
        <input type=hidden name=password value=$password>
        <input type=submit value='Modifica' name=B1 style='background-color: rgb(255,255,255); border: thin solid rgb(0,0,128)'></td>
        </form>
    <td width=10% bgcolor=#808080>
        <form action=mkdisplay.cgi>
        <input type=hidden name=utente value=$utente>
        <input type=hidden name=password value=$password>
        <input type=submit value='Sfoglia' name=B1 style='background-color: rgb(255,255,255); border: thin solid rgb(0,0,128)'></td>
        </form>
  </tr>
</table>
  <table border=0 cellpadding=0 cellspacing=3 width=100% bgcolor=#E6E6E6>
<form action=mkdisplay.cgi>
    <tr>
      <td width=26%><font face=Arial size=1 color=#000080><strong>Cerca per: Rivista</strong></font><br>
      <select name=rivista size=1>
        <option value=''></option>
        <option value='Ars Arpel'>Ars Arpel</option>
        <option value='Ars Sutoria'>Ars Sutoria</option>
        <option value='Calzatura'>Calzatura</option>
        <option value='Fotoshoe'>Fotoshoe</option>
        <option value='International Technology'>International Technology</option>
        <option value='Leather International'>Leather International</option>
        <option value='Serma'>Serma</option>
        <option value='Shoe Intelligence'>Shoe Intelligence</option></select></td>
      <td width=22%><font face=Arial size=1 color=#000080><strong>Categoria</strong></font><br>
      <select name=categoria size=1>
        <option value=''></option>
        <option value='Calzatura'>Calzature</option>
        <option value='Componenti'>Componenti</option>
        <option value='Lavoro conto Terzi'>Lavoro conto Terzi</option>
        <option value='Macchinari'>Macchinari</option>
        <option value='Pellami'>Pellami</option>
        <option value='Pelletteria'>Pelletteria</option>
        <option value='Sintetici'>Sintetici</option>
        <option value='Suole'>Suole</option>
        <option value='Tessuti'>Tessuti</option>
        <option value='Varie'>Varie</option></select></td>
      <td width=20%><font face=Arial size=1 color=#000080><strong>Azienda</strong></font><br>
        <input type=text name=azienda size=15></td>
      <td width=20%><font face=Arial size=1 color=#000080><strong>Testo</stong></font><br>
        <input type=text name=testo size=10></td>
      <td width=5%><font face=Arial size=1 color=#000080><strong>Mese</strong></font><br>
        <select name=mese size=1>
        <option value=></option>
        <option value=01>gen</option>
        <option value=02>feb</option>
        <option value=03>mar</option>
        <option value=04>apr</option>
        <option value=05>mag</option>
        <option value=06>giu</option>
        <option value=07>lug</option>
        <option value=08>ago</option>
        <option value=09>set</option>
        <option value=10>ott</option>
        <option value=11>nov</option>
        <option value=12>dic</option></select></td>
      <td width=7%><font face=Arial size=1 color=#000080><strong>Anno</strong></font><br>
        <select name=anno size=1>
        <option value=></option>
	<option value=2000>2000</option>
        <option value=2001>2001</option>
        <option value=2002>2002</option>
        <option value=2003>2003</option></select></td>
      <td width=5% valign=bottom><input type=submit value=GO name=B3></td>
</form>
  </tr>
</table>";

##################################################################################

# Open DB connection
$dbh = DBI->connect("DBI:mysql:calzatura_com_calzatura:mysql.register.it", GS1219_CALZATURA, michela);
if (!dbh) { print "Errore!"; }

$count = $dbh->do("SELECT * FROM Redazionali
                   $condizione");

if ($count < 1) {
   print "<body bgcolor=#cccccc text=#000080 link=#000080 vlink=#000080 alink=#000080 topmargin=0 leftmargin=0>
<div align=center><center>

<table border=0 cellspacing=0 width=100% height=1 cellpadding=0>
  <tr>
    <td width=2% valign=top bgcolor=#CCCCCC height=3></td>
    <td width=10% height=3 bgcolor=#CCCCCC></td>
    <td width=79% height=3 bgcolor=#CCCCCC>&nbsp; </td>
    <td width=2% align=right valign=top bgcolor=#CCCCCC height=3></td>
  </tr>
  <tr>
    <td width=2% valign=top bgcolor=#C8DCF0 height=1><img
    src=http://www.calzatura.com/images/angle1.gif width=7 height=8></td>
    <td width=10% height=1 bgcolor=#C8DCF0></td>
    <td width=79% height=1 bgcolor=#C8DCF0 rowspan=2><table border=0 width=100%
    cellspacing=0 cellpadding=0 height=11>
      <tr>
        <td width=66% height=11><font face=arial,helvetica color=000000 size=2><b>&nbsp;</b></font></td>
        <td width=33% height=11>&nbsp;</td>
        <td width=15% height=11></td>
      </tr>
    </table>
    </td>
    <td width=2% align=right valign=top bgcolor=#C8DCF0 height=1><img
    src=http://www.calzatura.com/images/angle2.gif width=11 height=12></td>
  </tr>
  <tr>
    <td width=2% bgcolor=#C8DCF0 height=1></td>
    <td width=10% height=1 bgcolor=#E1E1E1 rowspan=2 valign=top></td>
    <td width=2% align=right bgcolor=#C8DCF0 height=1></td>
  </tr>
  <tr>
    <td width=2% bgcolor=#C8DCF0 height=21></td>
    <td width=79% height=21 bgcolor=#E1E1E1><table border=0 width=100%
    cellspacing=0 cellpadding=5>
      <tr>
        <td width=100%><p align=left><small><font face=Arial color=#000080><u><em>Nessun
        Oggetto Trovato per la ricerca Eseguita</em></u></font></small></td>
      </tr>
    </table>
    </td>
    <td width=2% align=right bgcolor=#C8DCF0 height=21></td>
  </tr>
  <tr>
    <td width=2% valign=bottom bgcolor=#C8DCF0 height=1><img
    src=http://www.calzatura.com/images/angle3.gif width=11 height=12></td>
    <td width=10% height=1 bgcolor=#C8DCF0></td>
    <td width=79% height=1 bgcolor=#C8DCF0></td>
    <td width=2% align=right valign=bottom bgcolor=#C8DCF0 height=1><img
    src=http://www.calzatura.com/images/angle4.gif width=11 height=12></td>
  </tr>
</table>
</center></div>
<hr WIDTH=400 align=center>

<p align=center><font FACE=arial,helvetica size=1 color=#FF0000><a
HREF=http://www.calzatura.com target=_top>Calzatura</a></font><font
FACE=arial,helvetica COLOR=000000 size=1> E-Mail: <a
href=mailto:info\@calzatura.com>info\@calzatura.com</a><br>
All Rights Reserved.</font></p>
</body>";
exit;
}

$pagina       = $FORM{'pagina'};
$iniziopagina = $FORM{'iniziopagina'};

if ($pagina eq '') {
   $pagina = 1;
}

if ($iniziopagina eq '') {
   $iniziopagina = 1;
}

if ($pagina < $iniziopagina) {
   $pagina = $iniziopagina;
}

$inizio = ($pagina * 10) - 10;
$fine = 10;

my $stat = $dbh->prepare("SELECT ID, TITOLOITA, TITOLOENG, TITOLOSPA, REDITA, REDENG, REDSPA,
                                 FOTOA, FOTOB, FOTOC, FOTOD,
                                 TIT1ITA, TIT1ENG, TIT1SPA, TIT2ITA, TIT2ENG, TIT2SPA,
                                 TIT3ITA, TIT3ENG, TIT3SPA, TIT4ITA, TIT4ENG, TIT4SPA,
                                 AZIENDA, IMGAZIENDA, RIVISTA, IMGRIVISTA, NUMRIVISTA, DATARIVISTA,
                                 USER, PASSWORD, DATAINS, CATEGORIA
                          FROM Redazionali
                          $condizione
                          ORDER BY DATARIVISTA desc LIMIT $inizio,10");

my $return = $stat->execute;

if ($count > 0) {
   $npag = int($count/10);
   if ($npag < ($count/10)) {
      $npag = $npag + 1;
   }
}


      print "<div align=center><center>
             <table border=0 cellpadding=0 cellspacing=0 width=100%><tr>
             <td width=10% align=left><small><font face=Arial>Pag. <strong>$pagina</strong> di <strong>$npag</strong></font></small></td>
             <td width=50%><font face=Verdana size=1 color=#000080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>Ricerca:</strong>&nbsp;&nbsp; $rivista - $azienda2 - $testo - $visualmese - $anno</font></td>
             <td width=40% align=right><font face=Arial size=1 color=#000080>Pag.&nbsp;&nbsp;</font>";

if ($iniziopagina > 1) {
    $iniziopaginanew = $iniziopagina - 10;
    print "<small><font face=Arial>[<a href=mkdisplay.cgi?parole=$testo&pagina=$iniziopaginanew&iniziopagina=$iniziopaginanew>prec</a>]&nbsp;</font></small>";
}

$init = $iniziopagina;
until (($init > $npag) || ($init > ($iniziopagina + 10)) || ($npag == 1)) {
    print "<small><font face=Arial><a href=mkdisplay.cgi?parole=$testo&pagina=$init&iniziopagina=$iniziopagina>$init</a>&nbsp;</font></small>";
    $init = $init + 1;
}

if ($init < $npag) {
    $iniziopaginanew = $iniziopagina + 10;
    print "<small><font face=Arial>[<a href=mkdisplay.cgi?parole=$testo&pagina=$iniziopagina&iniziopagina=$iniziopaginanew>succ</a>]&nbsp;</font></small>";
}


print "</td></table>";
print "<table border=0 cellpadding=0 cellspacing=2 width=100%>
  <tr>
    <td width=15% bgcolor=#000080><strong><font face=Verdana color=#CDDEFD><small><small>Azienda</small></small></font></strong></td>
    <td width=74% bgcolor=#000080><strong><font face=Verdana color=#CDDEFD><small><small>Redazionale</small></small></font></strong></td>
    <td width=11% bgcolor=#000080><strong><font face=Verdana color=#CDDEFD><small><small>Rivista</small></small></font></strong></td>
  </tr>
</table>";

	unless (open (DATA,"/easysearch/password.txt")) {die (&error);}
		if ($uselock eq '1') {
			flock DATA, 2;
			seek DATA, 0, 0;
		}
		@input = <DATA>;
		if ($uselock eq '1') {
			flock DATA, 8;
		}
                $currentline = @input;
	close (DATA);

$colore = "#E7E7E7";

while (($id, $titoloita, $titoloeng, $titolospa, $redita, $redeng, $redspa, 
$fotoA, $fotoB, $fotoC, $fotoD,
$tit1ita, $tit1eng, $tit1spa, $tit2ita, $tit2eng, $tit2spa,
$tit3ita, $tit3eng, $tit3spa, $tit4ita, $tit4eng, $tit4spa,
$azienda, $imgazienda, $rivista, $imgrivista, $numrivista, $datarivista,
$utente, $password, $datains, $categoria) = $stat->fetchrow_array) {
$i = $currentline;
$trovato = 'no';
$ident = '';

until (($i < 0) || ($trovato eq 'si')) {
      @data = split(/::/,$input[$i]);
      $uutente = "\U$data[0]";
      $upassword = "\U$data[1]";
      $uutente2 = "\U$utente";
      $upassword2 = "\U$password";
      if (($uutente eq $uutente2) && ($upassword eq $upassword2)) {
         $trovato = 'si';
         $ident = $data[2];
         }
      else
         {
         --$i;
      }
}

$nazione = '';

if (($ident ne '0000') && ($ident ne '')) {
   ($citta,$provincia,$nazione,$u,$p) = $dbh->selectrow_array("SELECT CITTA, PROVINCIA, NAZIONE, USER, PASSWORD FROM Base WHERE ID='$ident'");
}


if ($colore eq '#E7E7E7') {
   $colore = '#CCCCCC';
   }
else
   {
   $colore = '#E7E7E7';
}


($ragionesociale,$indirizzo,$cap,$citta,$provincia,$nazione,$mail,$telefono,$fax,$imgragione) = $dbh->selectrow_array("SELECT RAGIONESOCIALE,INDIRIZZO,CAP,CITTA,PROVINCIA,NAZIONE,MAIL,TELEFONO,FAX,IMMAGINE FROM Base WHERE ID='$azienda'");
($nomenazione,$imgnazione) = $dbh->selectrow_array("SELECT NAZIONE,IMMAGINE FROM Nazioni WHERE ID='$nazione'");

$d1 = substr($redita,0,350);
$d1 = $d1." ...";

print "<table bgcolor=$colore border=0 cellpadding=5 cellspacing=0 width=100%>
         <tr>
           <td width=15% rowspan=2>";

if ($imgragione ne '') {
print " <a href=mkdisplay2.cgi?id=$id&identificativo=$identificativo target=_blank><img src=$imgragione width=100 height=50 alt='$ragionesociale - $indirizzo - $cap - $citta - $provincia - $nomenazione - Tel: $telefono - Fax: $fax' border=0></a>";
}


print "</td>
       <td width=40%><font face=Arial size=1 color=#000080><strong><a href=mkdisplay2.cgi?id=$id target=_blank>$titoloita</a></strong></font></td>
       <td width=34%><p align=right><font face=Arial size=1 color=#000080><em>";

if ($rivista ne '') {
print "&quot; $rivista &quot; &nbsp; ";
}

if ($numrivista ne '') {
print "N° $numrivista &nbsp;&nbsp;&nbsp;";
}

@vardata = split(/-/,$datarivista);

if ($datarivista ne '0000-00-00') {
print "($vardata[1]/$vardata[0])";
}

print "</em></font></td>
       <td width=11% rowspan=2>";

###################################

if ($rivista eq 'Ars Arpel') {
print "<a href=http://www.calzatura.com/web/arsarpel/index.htm target=_blank><img src=http://www.calzatura.com/cgi/riviste/arpel.jpg width=80 height=40 alt='$rivista' border=0></a>";
}

if ($rivista eq 'Ars Sutoria') {
print "<a href=http://www.calzatura.com/web/arsarpel/index.htm target=_blank><img src=http://www.calzatura.com/cgi/riviste/ars.jpg width=80 height=40 alt='$rivista' border=0></a>";
}

if ($rivista eq 'Calzatura') {
print "<img src=http://www.calzatura.com/cgi/riviste/calzatura.jpg width=80 height=40 alt='$rivista' border=0>";
}

if ($rivista eq 'Fotoshoe') {
print "<img src=http://www.calzatura.com/cgi/riviste/fotoshoe.jpg width=80 height=40 alt='$rivista' border=0>";
}

if ($rivista eq 'International Technology') {
print "<a href=http://www.calzatura.com/web/internationaltechnology/index.htm target=_blank><img src=http://www.calzatura.com/cgi/riviste/it.jpg width=80 height=40 alt='$rivista' border=0></a>";
}

if ($rivista eq 'Leather International') {
print "<img src=http://www.calzatura.com/cgi/riviste/leather.jpg width=80 height=40 border=0>";
}

if ($rivista eq 'Serma') {
print "<a href=http://www.serma.net target=_blank><img src=http://www.calzatura.com/cgi/riviste/serma.jpg width=80 height=40 alt='$rivista' border=0></a>";
}

if ($rivista eq 'Shoe Intelligence') {
print "<a href=http://www.calzatura.com/web/shoeintelligence/index.htm target=_blank><img src=http://www.calzatura.com/cgi/riviste/shoeintelligence.jpg width=80 height=40 alt='$rivista' border=0></a>";
}

########################################


print "</td>
  </tr>
  <tr>
    <td width=74% colspan=2><font face=Arial size=1 color=#000080>$d1</font></td>
  </tr>
</table>";

}

print "<hr><p align=center><font FACE=arial,helvetica size=1 color=#FF0000><a
HREF=http://www.calzatura.com target=_top>Calzatura</a></font><font
FACE=arial,helvetica COLOR=000000 size=1> E-Mail: <a
href=mailto:info\@calzatura.com>info\@calzatura.com</a><br>
All Rights Reserved.</font></p>";

$dbh->disconnect;

exit;

##################################################################################


sub error {    
	$noshow = 1;
	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;
}
