in reply to help on searching a file

#!/usr/bin/perl ########################## # Database Interface # # By Er Galvão Abbott # # SoluçãoWeb # # Maio/2000 # ########################## use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); @referers = ('www.solucaoweb.com.br/cgi-bin/Matrix','www.solucaoweb.co +m.br/cgi-bin/Matrix'); print "Content-type: text/html\n\n"; local($check_referer) = 0; if ($ENV{'HTTP_REFERER'}) { foreach $referer (@referers) { if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) +{ $check_referer = 1; last; } } } else { $check_referer = 1; } if ($check_referer != 1) { &Red_Alert } read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @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_date; # Variáveis globais $base = "http://www.solucaoweb.com.br/Matrix"; $pessoais = "produtos/pessoais.dat"; $comerciais = "produtos/comerciais.dat"; $basicos = "produtos/basicos.dat"; $mailprog = '/usr/sbin/sendmail'; #&search_database2($comerciais,$search_for); # #$count2 = @results2; # #&search_database3($basicos,$search_for); # #$count3 = @results3; # Lê os campos do form e os transforma em pares no formato $FORM{'name +'} e valor $user = $FORM{'usuario'}; $userc = $user.".con"; $conta = "count/".$userc; open (CON, "$conta"); $numero = <CON>; close (CON); $numero = $numero + 1; open (CON, ">$conta"); print CON $numero; close CON; $database = "data/".$user."_".$months[$mon].".data"; $recipient0 = $user."\@matrix.com.br"; $recipient1 = "admpoa\@matrix.com.br"; $recipient2 = "gcom\@matrix.com.br"; $recipient3 = "abbott\@matrix.com.br"; $recipient4 = "atech\@matrix.com.br"; $recipient5 = "stech\@matrix.com.br"; #$recipient6 = "ergalvao\@solucaoweb.com.br"; # Cria o formato do registro, delimitando os campos por '|' $record = join '|', $FORM{'pessoa'},$FORM{'razao_social'},$FORM{'ender +eco'},$FORM{'bairro'},$FORM{'cep'},$FORM{'cidade'},$FORM{'estado'},$F +ORM{'fone_residencial'},$FORM{'fone_comercial'},$FORM{'celular'},$FOR +M{'cpf_ou_cnpj'},$FORM{'dominio'},$FORM{'dominio_1'},$FORM{'tipo_domi +nio_1'},$FORM{'dominio_2'},$FORM{'tipo_dominio_2'},$FORM{'dominio_3'} +,$FORM{'tipo_dominio_3'},$FORM{'dominio_4'},$FORM{'tipo_dominio_4'},$ +FORM{'dominio_5'},$FORM{'tipo_dominio_5'},$FORM{'responsavel'},$FORM{ +'cpf'},$FORM{'user1'},$FORM{'user2'},$FORM{'user3'},$FORM{'caixa1'},$ +FORM{'caixa2'},$FORM{'caixa3'},$FORM{'caixa4'},$FORM{'caixa5'},$FORM{ +'caixa6'},$FORM{'caixa7'},$FORM{'caixa8'},$FORM{'caixa9'},$FORM{'caix +a10'},$FORM{'descricao91'},$FORM{'descricao41p'},$FORM{'descricao81'} +,$FORM{'descricao82'},$FORM{'descricao41e'},$FORM{'descricao03'},$FOR +M{'descricao04b'},$FORM{'descricao32b'},$FORM{'descricao42b'},$FORM{' +descricao43b'},$FORM{'descricao44b'},$FORM{'descricao46b'},$FORM{'des +cricao04c'},$FORM{'descricao32c'},$FORM{'descricao42c'},$FORM{'descri +cao43c'},$FORM{'descricao44c'},$FORM{'descricao46c'},$FORM{'descricao +48'},$FORM{'descricao49'},$FORM{'descricao50'},$FORM{'descricao34'},$ +FORM{'descricaoxx'},$FORM{'descricaoyy'},$FORM{'descricaozz'},$FORM{' +descricao05'},$FORM{'descricao06'},$FORM{'descricao07'},$FORM{'descri +cao09'},$FORM{'descricao12'},$FORM{'descricaoww'},$FORM{'descricao29' +},$FORM{'descricao30'},$FORM{'instalacao'},$FORM{'EndInst'},$FORM{'Ba +irroInst'},$FORM{'CEPInst'},$FORM{'CidadeInst'},$FORM{'EstadoInst'},$ +FORM{'pagto'},$FORM{'NomeCartao'},$FORM{'operadora'},$FORM{'numeroCar +tao'},$FORM{'validade'},$FORM{'info'}; &AddRecord($database,$record); sub AddRecord{ $database=$_[0]; $record =$_[1]; # Abre o arquivo txt e inclui o registro open (DB,">>$database") or die "Error: $!\n"; print DB "$record\n"; close(DB); # Envia os dados por e-mail #if ($FORM{'dominio'} eq "com" || $FORM{'instalacao'} eq "com" || $FOR +M{'la'} ne "0") #{ &sendit($recipient0); #&sendit($recipient1); #&sendit($recipient2); #&sendit($recipient4); #&sendit($recipient5); #} #else #{ #&sendit($recipient0); #&sendit($recipient1); #&sendit($recipient2); #} $numeroant = $numero - 1; print<<HTML; <html> <head> <title>Matrix - Sistema de Cadastro de Vendas</title> </head> <body bgcolor="#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="12%"><img src="$base/img/logo.jpg" width="178" height=" +146"></td> <td width="4%">&nbsp;</td> <td width="84%" align="center" valign="middle"><font size="5" face +="Verdana, Arial, Helvetica, sans-serif" color="#000080">Matrix - Cadastro de Venda</font> <hr color="#800000"> <br> <font face="Verdana, Arial, Helvetica, sans-serif" size="2" colo +r="#000080">Em caso de d&uacute;vidas quanto &agrave; utiliza&ccedil;&atilde;o +deste sistema,<br> entre em contato com a Matrix, atrav&eacute;s do telefone 228-43 +00.</font></td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center">&nbsp;</td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center"> <font face="Verdana, Arial, Helvet +ica, sans-serif" size="3" color="#000080">Cadastro n&ordm;</font><font face="Verdana, Arial, Helvetica, sans-serif" + size="3"> <font color="#0000FF">000$numeroant</font> <font color="#000080" +>inclu&iacute;do com sucesso.</font></font><br> <br> <font face="Verdana, Arial, Helvetica, sans-serif" size="2" colo +r="#000080">Clique <a href="http://www.solucaoweb.com.br/cgi-bin/Matrix/bigone.cgi? +user=$user">aqui</a> para cadastrar uma nova venda.</font></td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center">&nbsp;</td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center">&nbsp;</td> </tr> <tr> <td width="12%">&nbsp;</td> <td width="4%">&nbsp;</td> <td width="84%" align="center">&nbsp;</td> </tr> </table> <hr color="#800000"> <center> <font face="Verdana" size="2" color="#000080">Aplicativo desenvolvido +por <a href="http://www.solucaoweb.com.br/" target="_blank">SoluçãoWe +b</a></font> </center> </body> </html> HTML return; } sub sendit { open (MAIL, "|$mailprog -t") or die "Error: $!\n"; print MAIL "From: $recipient0\n"; print MAIL "To: $_[0]\n"; print MAIL "Subject: Venda na Web\n\n"; print MAIL "Identificação do Vendedor:\n"; print MAIL "--------------------------\n\n"; print MAIL "ID Usuário: $FORM{'usuario'}\n"; print MAIL "Venda Nº: $FORM{'numero'}\n\n"; print MAIL "Identificação do Cliente:\n"; print MAIL "-------------------------\n\n"; print MAIL "Tipo Cliente: Pessoa $FORM{'pessoa'}\n"; print MAIL "Razão Social/Nome: $FORM{'razao_social'}\n\n"; print MAIL "Endereço: $FORM{'endereco'}\n"; print MAIL "Bairro : $FORM{'bairro'} CEP : $FORM{'cep'}\n"; print MAIL "Cidade : $FORM{'cidade'} Estado : $FORM{'estado'}\n"; print MAIL "Tel Residencial : $FORM{'fone_residencial'} Tel Comercial +: $FORM{'fone_comercial'}\n"; print MAIL "Celular : $FORM{'celular'} CPF ou CNPJ : $FORM{'cpf_ou_cnp +j'}\n\n"; print MAIL "Dados do Domínio:\n"; print MAIL "-----------------\n\n"; print MAIL "$FORM{'dominio'} Domínio\n"; print MAIL "Domínio 1 : $FORM{'dominio_1'} $FORM{'tipo_dominio_1'}\n" +; print MAIL "Domínio 2 : $FORM{'dominio_2'} $FORM{'tipo_dominio_2'}\n" +; print MAIL "Domínio 3 : $FORM{'dominio_3'} $FORM{'tipo_dominio_3'}\n" +; print MAIL "Domínio 4 : $FORM{'dominio_4'} $FORM{'tipo_dominio_4'}\n" +; print MAIL "Domínio 5 : $FORM{'dominio_5'} $FORM{'tipo_dominio_5'}\n\ +n"; print MAIL "Responsável pelo Domínio : $FORM{'responsavel'}\n"; print MAIL "CPF : $FORM{'cpf'}\n\n"; print MAIL "Usernames preferidos:\n"; print MAIL "---------------------\n\n"; print MAIL "Username 1 : $FORM{'user1'}\n"; print MAIL "Username 2 : $FORM{'user2'}\n"; print MAIL "Username 3 : $FORM{'user3'}\n\n"; print MAIL "Caixas Postais:\n"; print MAIL "---------------\n\n"; print MAIL "Cx Postal 1 : $FORM{'caixa1'}\n"; print MAIL "Cx Postal 2 : $FORM{'caixa2'}\n"; print MAIL "Cx Postal 3 : $FORM{'caixa3'}\n"; print MAIL "Cx Postal 4 : $FORM{'caixa4'}\n"; print MAIL "Cx Postal 5 : $FORM{'caixa5'}\n"; print MAIL "Cx Postal 6 : $FORM{'caixa6'}\n"; print MAIL "Cx Postal 7 : $FORM{'caixa7'}\n"; print MAIL "Cx Postal 8 : $FORM{'caixa8'}\n"; print MAIL "Cx Postal 9 : $FORM{'caixa9'}\n"; print MAIL "Cx Postal 10 : $FORM{'caixa10'}\n\n"; print MAIL "Pacotes Pessoais:\n"; print MAIL "----------------\n\n"; $search_for = "a"; $search_field = "all"; &search_database($pessoais,$search_for); $count = @results; foreach $results (@results){ ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split(/\|/,$ +results); print MAIL "$descricao $FORM{'Quantidade_$key'}\n\n"; } #foreach $results (@results){ # ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split( +/\|/,$results); #print MAIL "$descricao $FORM{$qid}\n\n"; #} #print MAIL "$FORM{'aa'} : $FORM{'ka'} unidades\n"; #print MAIL "$FORM{'ab'} : $FORM{'kb'} unidades\n\n"; print MAIL "Pacotes Comerciais:\n"; print MAIL "----------------\n\n"; #foreach $results2 (@results2){ # ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split( +/\|/,$results2); #print MAIL "$descricao $FORM{$qid}\n\n"; #} # #print MAIL "$FORM{'ac'}: $FORM{'kc'} unidades\n"; #print MAIL "$FORM{'ad'}: $FORM{'kd'} unidades\n"; #print MAIL "$FORM{'ae'}: $FORM{'ke'} unidades\n"; #print MAIL "$FORM{'af'}: $FORM{'kf'} unidades\n"; #print MAIL "$FORM{'ag'}: $FORM{'kg'} unidades\n"; #print MAIL "$FORM{'ah'}: $FORM{'kh'} unidades\n"; #print MAIL "$FORM{'ai'}: $FORM{'ki'} unidades\n"; #print MAIL "$FORM{'aj'}: $FORM{'kj'} unidades\n"; #print MAIL "$FORM{'ak'}: $FORM{'kk'} unidades\n"; #print MAIL "$FORM{'al'}: $FORM{'kl'} unidades\n"; #print MAIL "$FORM{'am'}: $FORM{'km'} unidades\n"; #print MAIL "$FORM{'an'}: $FORM{'kn'} unidades\n"; #print MAIL "$FORM{'ao'}: $FORM{'ko'} unidades\n"; #print MAIL "$FORM{'ap'}: $FORM{'kp'} unidades\n"; #print MAIL "$FORM{'aq'}: $FORM{'kq'} unidades\n"; #print MAIL "$FORM{'ar'}: $FORM{'kr'} unidades\n"; #print MAIL "$FORM{'as'}: $FORM{'ks'} unidades\n"; #print MAIL "$FORM{'at'}: $FORM{'kt'} unidades\n"; #print MAIL "$FORM{'au'}: $FORM{'ku'} unidades\n"; #print MAIL "$FORM{'av'}: $FORM{'kv'} unidades\n"; #print MAIL "$FORM{'aw'}: $FORM{'kw'} unidades\n"; #print MAIL "$FORM{'ax'}: $FORM{'kx'} unidades\n"; #print MAIL "$FORM{'ay'}: $FORM{'ky'} unidades\n\n"; # print MAIL "Serviços Básicos:\n"; print MAIL "----------------\n\n"; #foreach $results3 (@results3){ # ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid) = split( +/\|/,$results3); #print MAIL "$descricao $FORM{$qid}\n\n"; #} #print MAIL "$FORM{'ba'}: $FORM{'la'} unidades\n"; #print MAIL "$FORM{'bb'}: $FORM{'lb'} unidades\n"; #print MAIL "$FORM{'bc'}: $FORM{'lc'} unidades\n"; #print MAIL "$FORM{'bd'}: $FORM{'ld'} unidades\n"; #print MAIL "$FORM{'be'}: $FORM{'le'} unidades\n"; #print MAIL "$FORM{'bf'}: $FORM{'lf'} unidades\n"; #print MAIL "$FORM{'bg'}: $FORM{'lg'} unidades\n"; #print MAIL "$FORM{'bh'}: $FORM{'lh'} unidades\n\n"; print MAIL "Dados da Instalação:\n"; print MAIL "--------------------\n\n"; print MAIL "$FORM{'instalacao'} Instalação\n\n"; print MAIL "Endereço : $FORM{'EndInst'}\n"; print MAIL "Bairro : $FORM{'BairroInst'} CEP : $FORM{'CEPInst'}\n"; print MAIL "Cidade : $FORM{'CidadeInst'}Estado : $FORM{'EstadoInst'}\n +\n"; print MAIL "Pagamento:\n"; print MAIL "----------\n\n"; print MAIL "Forma de Pagto : $FORM{'pagto'}\n"; print MAIL "Nome Constante no Cartão : $FORM{'NomeCartao'}\n"; print MAIL "Operadora : $FORM{'operadora'}\n"; print MAIL "Numero do Cartao : $FORM{'numeroCartao'}\n"; print MAIL "Validade : $FORM{'validade'}\n\n"; print MAIL "Informações Adicionais:\n"; print MAIL "-----------------------\n\n"; print MAIL "$FORM{'info'}\n"; close(MAIL); return; } sub get_date { @days = ('Dom','Seg','Ter','Qua','Qui','Sex','Sab'); @months = ('Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set',' +Out','Nov','Dez'); ($mday,$mon,$year,$wday) = (localtime(time))[3,4,5,6]; $year += 1900; $date = "$mday de $months[$mon] de $year"; return; } sub search_database{ my $search_for = $_[1]; open(DB, $_[0]) or die "Error opening file: $!\n"; while(<DB>){ if($search_field eq "all"){ if(/$search_for/oi){push @results, $_}; } else { ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid)=split(/ +\|/); if(${$search_field} =~ /$search_for/oi){push @results, $_}; } } close (DB); } sub search_database2{ my $search_for = $_[1]; open(DB2, $_[0]) or die "Error opening file: $!\n"; while(<DB2>){ if($search_field eq "all"){ if(/$search_for/oi){push @results2, $_}; } else { ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid)=split(/ +\|/); if(${$search_field} =~ /$search_for/oi){push @results2, $_}; } } close (DB2); } sub search_database3{ my $search_for = $_[1]; open(DB3, $_[0]) or die "Error opening file: $!\n"; while(<DB3>){ if($search_field eq "all"){ if(/$search_for/oi){push @results3, $_}; } else { ($key,$descricao,$inscricao,$mensalidade,$codIBM,$qid)=split(/ +\|/); if(${$search_field} =~ /$search_for/oi){push @results3, $_}; } } close (DB3); }


Er Galvão Abbott a.k.a. Lobo, DaWolf Webdeveloper