#!c:\perl\bin\perl.exe
##########################################################################
# CGI UNTITLED #
# VERSION 0.0.1 #
# DATE 26/11/2000 #
# AUTHOR Paulo Dom #
# EMAIL paulodom@hotmail.com #
# COMPANY System-Fox www.systemfox.cjb.net #
##########################################################################
$title = "UnionBrasil Guia On-Line Bragança Paulista e Região"; # Titulo do Servidor
$fields = 12; # Numero de campos no mesmo registro
$results = 1000; # Numero maximo de resultados obtidos
&parse_form;
$searchstring = $FORM{'procurar-string'};
$bairstring = $FORM{'perto-string'};
$indicestring = $FORM{'indice-procura'};
$cidadestring = 'Bragança Paulista';
$verbanner = 1;
&addrecord if ($searchstring eq "**NOVO REGISTRO**");
#----------------------------- TODAS AS CIDADES--------------------------------------
#---------------------------- BRAGANÇA PAULISTA -------------------------------------
if ($cidadestring eq 'Bragança Paulista'){
if ($indicestring eq 'Todos os Indices') {
$filename = 'D:\webs\unionb\data\database\braganca\urls.txt'; # dados
}
if ($indicestring eq 'Todos') {
$filename = 'D:\webs\unionb\data\database\braganca\urls.txt'; # dados
}
if ($indicestring eq 'Financia') {
$filename = 'D:\webs\unionb\data\database\braganca\financia.txt'; # dados
}
if ($indicestring eq 'Cartão') {
$filename = 'D:\webs\unionb\data\database\braganca\cartao.txt'; # dados
}
if ($indicestring eq 'Cheque Pré') {
$filename = 'D:\webs\unionb\data\database\braganca\cheque.txt'; # dados
}
if ($indicestring eq 'Entrega') {
$filename = 'D:\webs\unionb\data\database\braganca\entrega.txt'; # dados
}
if ($indicestring eq '24 Horas') {
$filename = 'D:\webs\unionb\data\database\braganca\24horas.txt'; # dados
}
if ($indicestring eq 'Dom/feriados') {
$filename = 'D:\webs\unionb\data\database\braganca\dom.txt'; # dados
}
if ($indicestring eq 'Horario') {
$filename = 'D:\webs\unionb\data\database\braganca\horario.txt'; # dados
}
if ($indicestring eq 'Parcelado') {
$filename = 'D:\webs\unionb\data\database\braganca\parc.txt'; # dados
}
if ($indicestring eq 'Promoções') {
$filename = 'D:\webs\unionb\data\database\braganca\promo.txt'; # dados
}
if ($indicestring eq 'On-line') {
$filename = 'D:\webs\unionb\data\database\braganca\online.txt'; # dados
}
if ($indicestring eq 'Grátis') {
$filename = 'D:\webs\unionb\data\database\braganca\gratis.txt'; # dados
}
}
&open_file("FILE1","",$filename);
&open_file("FILE2","",$filename);
# &open_file("FILE3","",$filename);
print "Content-type: text/html\n\n";
print "
";
print "";
print " Resultado da Pesquisa - <> ";
#------------------------------------------------------------------------------------------------
#---------pate superior---------
#-----fim da parte superior----
$counter = 0;
while ($cont = &read_file("FILE2")) {
# Separa os campos pelo caractere |
@tabledata = split(/\s*\|\s*/,$cont ,$fields);
if ($bairstring) {
&check_record2;
}
else {
&check_record;
}
if ($counter==0) {
$banner = $var2;
}
if ($found == 1) {
$counter++;
}
}
if ($counter == 0) {
$banner = 0;
&formulario3;
# &newform;
&nao_encontrado;
# print "
\n";
# print "
Não foi encontrada nada com $searchstring .\n";
}
else{
# &newform;
&formulario3;
#-----------contador-----------------
print "";
#----imagem de fundo--------------
print "";
print "";
#------fim de imagem de fundo-----
print "";
print "";
print " ";
print " ";
#print " ";
#print " | ";
#print " ";
#print " ";
print " | ";
print "
";
print "
";
print "<\CENTER>";
#---fim do supr----
print "";
print "";
print "Foram encontrados";
print "$refe $counter  $searchstring em $indicestring perto do $bairstring
| ";
print "
";
}
#------------------------------------------------------------------------------------------------
# FAZ A PROCURA NA TABELA
$teste1 = $FORM{'indice-soma'};
$teste = $teste1+10;
#$banner =0;
$counter = 0;
$page = -1;
$break = 0;
$prox = 0;
while ($line = &read_file("FILE1")) {
# Separa os campos pelo caractere |
@tabledata = split(/\s*\|\s*/,$line ,$fields);
if ($bairstring) {
&check_record2;
}
else {
&check_record;
}
if ($found == 1) {
if ($counter==0) {
#print "\n";
print "";
#$grupo = $var;
}
&print_record;
}
}
if ($group eq $var){
$counter++;
$break++;
}
else {
$group = $var;
$break++;
}
}
}
if (found !=0) {
print "voltar";
}
&formulario3;
# &newform;
# &formulario3;
close(FILE1);
#########################################
# #
# Imprime os Registros #
# #
#########################################
sub print_record {
#----------------teste-------------------
#--------fim do teste----------
print "
";
print " ";
print " | ";
print " ";
print " ";
print " ";
print " ";
print " ";
print " | ";
print " ";
print " ";
print " | ";
print " | ";
print "
";
print " ";
print " | ";
print " ";
print " ";
print " ";
if ($linklogo) {
print " ";
print " ";
}
else {
print " | ";
#print " ";
}
print " | ";
print " ". $linktitle . " | ";
print " ";
print " ";
print " End:".$linkdescrip. " | ";
print " ";
print " ";
print " ".$linkbair." Tel: ".$linkfone." | ";
print " ";
print " ";
print " ";
print " ";
print " ";
print " ";
print " ";
print " | ";
print " ";
print " ";
print " | ";
print " ";
print " ";
print " | ";
print " | ";
print "
";
if ($linkurl) {
print " ";
print " | ";
print " ";
print " ";
print " ";
print " ";
print " ";
print " | ";
print " | ";
print " ";
print " ";
print " | ";
print " ";
print " ";
print " | ";
print " | ";
print "
";
print "
";
}
else{
print " ";
print " | ";
print " ";
print " ";
print " ";
print " ";
print " ";
print " | ";
print " | ";
print " ";
print " ";
print " | ";
print " ";
print " ";
print " | ";
print " | ";
print "
";
print "";
}
}
sub print_record2 {
print "";
print" ";
print "";
print " | ";
print " | ";
print " | ";
print "
";
print "
";
print "";
print" ";
print "";
print " | ";
print " | ";
print " | ";
print "
";
print "
";
print "";
print" ";
print "";
print " | ";
print " " . $linktitle ." | ";
print " | ";
print "
";
print "
";
print "";
print" ";
print "";
print " | ";
print " End. " . $linkdescrip ." | ";
print " | ";
print "
";
print "
";
print "";
print" ";
print "";
print " | ";
print " " . $linkbair ." - Tel: ".$linkfone. " | ";
print " | ";
print "
";
print "
";
if ($linkurl) {
print "";
print" ";
print "";
print " | ";
print " | ";
print " | ";
print " | ";
print "
";
print "
";
}
else {
print "";
print" ";
print "";
print " | ";
print " | ";
print " | ";
print " | ";
print "
";
print "
";
}
}
##########################################
#
# Cheka para ver se existe a String
#
##########################################
sub check_record {
# pega os dados do registro vindo do arquivo e le. $tabledata
$linktitle = $tabledata[0]; #name company
$linkdescrip = $tabledata[1]; #address the company
$linkwords = $tabledata[2]; #primary key
$var = $tabledata[2]; #rotate image
$linkbair = $tabledata[3]; #bair of the company
$linkfone = $tabledata[4]; #telephone of the company
$linkimage = $tabledata[6]; #location the image of the company
$linkurl = $tabledata[7]; #hyperlink the page of the company
$linkchave = $tabledata[8]; #secundary key
$linklogo = $tabledata[11]; #logo
$var2 = $tabledata[8];
if ($counter ==0){
$group = $tabledata[2];
}
#Constroi as linhas com os campos resultado da pesquisa
$searchline = $linktitle ." " . $linkwords ." ".$linkchave;
# $searchline = $linktitle ." " . $linkwords ." " .$linkchave;
# Pesquisa por palavras chaves
# A pesquisa so sera feita se a String tiver mais de dois caracteres
# don't think we want people to search for and or or etc.
$sfound = 0;
$found = 0;
$notfound = 1;
if ($searchstring eq '*.*') {
$notfound =0;
}
$stlen = length($searchstring);
if ($stlen == 1){
$notfound =0;
}
if ($stlen > -1) {
@words = split(/ +/,$searchstring);
foreach $aword (@words) {
if ($searchline =~ /\b$aword/i){
$sfound = 1;
}
else {
$notfound = 0;
}
}
}
if ($sfound == 1 && $notfound == 1) {
$found = 1;
}
# Se a string for muito pequena .. faca found = 1
if ($stlen <= -1) {
$found = 1;
}
# Se esta pagina nao tiver titulo entao retorne nao encontrado
$tlen = length($linktitle);
if ($tlen < -1) {
$found = 0;
}
}
sub check_record2 {
# pega os dados do registro vindo do arquivo e le. $tabledata
$linktitle = $tabledata[0];
$linkdescrip = $tabledata[1];
$linkwords = $tabledata[2];
$var = $tabledata[2];
$linkbair = $tabledata[3];
$linkfone = $tabledata[4];
$linkimage = $tabledata[6];
$linkchave = $tabledata[8];
$linklogo = $tabledata[11];
$var2 = $tabledata[8];
if ($counter ==0){
$group = $tabledata[2];
}
#chop($linkurl);
#Constroi as linhas com os campos resultado da pesquisa
$searchline = $linktitle ." " . $linkwords ." " .$linkchave;
#$searchline = $linktitle . " " . $linkdescrip . " " . $linkwords;
$searchline2 = $linkbair . " " . $linkdescrip;
# Pesquisa por palavras chaves
# A pesquisa so sera feita se a String tiver mais de dois caracteres
# don't think we want people to search for and or or etc.
$sfound = 0;
$found = 0;
$notfound = 1;
$stlen = length($searchstring);
#$stlen2 = length($bairstring);
if ($stlen > -1) {
@words = split(/ +/,$searchstring);
@words2 = split(/ +/,$bairstring);
foreach $aword (@words) {
foreach $aword2 (@words2) {
if ($searchline2 =~ /\b$aword2/i){
if ($searchline =~ /\b$aword/i){
$sfound = 1;
}
else {
$notfound = 0;
}
}
}
}
}
if ($sfound == 1 && $notfound == 1) {
$found = 1;
}
# Se a string for muito pequena .. faca found = 1
if ($stlen <= -1) {
$found = 1;
}
# Se esta pagina nao tiver titulo entao retorne nao encontrado
$tlen = length($linktitle);
if ($tlen < -1) {
$found = 0;
}
}
############################################
#
# Gravando Novo Endereco
#
############################################
sub addrecord {
$linktitle = $FORM{'linktitle'};
$linkdescrip = $FORM{'linkdescrip'};
$linkwords = $FORM{'linkwords'};
$linkemail = $FORM{'linkemail'};
$linkurl = $FORM{'linkurl'};
# Convertendo < tags para <
$linktitle =~ s/\</g;
$linkdescrip =~ s/\</g;
$linkwords =~ s/\</g;
$linkemail =~ s/\</g;
$linkurl =~ s/\</g;
&open_file("FILE1",">>",$filename);
&write_file("FILE1",$linktitle . "|". $linkdescrip. "|" .$linkwords ."|" .$linkemail ."|" .$linkurl ."\n");
close(FILE1);
print "Content-type: text/html\n\n";
print "Obrigado !!!\n";
# print "
Obrigado pela contribuição !
\n";
print "\n";
exit;
}
sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@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;
}
}
sub open_file {
local ($filevar, $filemode, $filename) = @_;
open ($filevar,$filemode . $filename) ||
die ("Não posso abrir $filename");
}
sub read_file {
local ($filevar) = @_;
<$filevar>;
}
sub write_file {
local ($filevar, $line, $cont) = @_;
print $filevar ($line);
}
sub formulario3 {
print "