#Paulo Costa Carvalho #Do Not modify or read this module without my authorization #paulo@buscario.com.br #Object Flowchart Module #Disclosure : This program can´t be read, distributed, copied or modified without #my written permission. - Abril 25 2004 #v0.99 28 fev 2006 package anuncio; use strict; use common; our @text_vars = qw (nome telefone email url titulo cidade bairro endereco valor metragem txtAnuncio); our @pulldowns = qw (localizacao estado tipo_imovel); our @buttons = qw (corretoup operacao); our @tipo_imovel = ("1", "Andar Corrido", "Apto. 1 quarto", "Apto. 2 quartos", "Apto. 3 quartos", "Apto. 4 ou mais quartos", "Área Comercial", "Área Industrial", "Casa ou Terreno", "Cobertura", "Conjugado", "Galpão", "Garagem", "Loja", "Prédio Comercial", "Prédio Residencial", "Sala", "Sítos e Fazendas", "Sobrado", "Sobreloja",); our %operacao = ("a" => "Aluguel", "v" => "Compra / Venda", "t" => "Temporada"); ################################################################################ #Constructor use Class::Struct; struct anuncio => { target => '$', }; sub init { my ($self, %args) = @_; %{$self} = %args; return $self; } sub load_me { my ($self) = @_; my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); my $id_anuncio = $_[1]; #Get the data $sth = $dbh->prepare('SELECT * FROM anuncio where id_anuncio = (?)') or dienice ("Falha na preparação da busca
$DBI::errstr"); my $rv = $sth->execute($id_anuncio) or common::dienice("Cant´t execute querry in database
$DBI::errstr"); while ($h = $sth->fetchrow_hashref) {%sqldata=%{$h};} #If there are no results, warn the user if ($rv == 0) {common::dienice("Favor verificar página e ID");} #Lets return our search %{$self} = %sqldata; return $self; } ################################################################################ sub get_add_html { my ($self) = @_; my $add = common::get_file("templates/prog/class_add_template.htm"); my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); my $id_anuncio = $_[1]; common::dienice("Favor informe o id do anuncio a ser mostrado") unless ($id_anuncio); #Prepare array $sth = $dbh->prepare('SELECT * FROM anuncio WHERE id_anuncio = (?)') or dienice ("Falha na preparação da busca
$DBI::errstr"); $sth->execute($id_anuncio) or common::dienice("Error->$DBI::errstr"); my $mail; while ($h = $sth->fetchrow_hashref) { $self->{imagem} = $h->{imagem}; #Adicionar virgula ao valor $h->{valor} =~ /([0-9]{3}\Z)/; $h->{valor} =~ s/([0-9]{3}\Z)/\.$1/ if (length($h->{valor}) > 3); $h->{valor} .= ",00"; foreach my $tv (@text_vars) { next if $tv eq "url"; $mail = $h->{email}; next if $tv eq "email"; $add =~ s/--$tv--/$h->{$tv}/; } my $img = " "; if ($self->{imagem} == 1) {$img = ""} $add =~ s/--tipo_imovel--/$tipo_imovel[$h->{tipo_imovel}]/; $add =~ s/--data--/$h->{data}/; $add =~ s/--image--/$img/; my $email = "$mail"; $add =~ s/--email--/$email/; $add =~ s/--url--/{url}\">$h->{url}<\/a>/; $add =~ s/--operacao--/$operacao{$h->{operacao}}/; } return ($add); } sub update_html_anunciantes { my ($self) = @_; my $output = common::get_file("templates/prog/head0.htm"); my $google_code = common::get_file("templates/google_code_classificados.txt"); my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); #Prepare array $sth = $dbh->prepare('SELECT * FROM hp_users WHERE titulo_classificados != (?)') or dienice ("Falha na preparação da busca
$DBI::errstr"); $sth->execute("") or common::dienice("Error->$DBI::errstr"); $output =~ s/--google_code--/$google_code/; while ($h = $sth->fetchrow_hashref) { $output .= "
{id}>$h->{titulo_classificados}
\n"; } open (WRITE, ">links_classificados.htm"); print WRITE $output; close (WRITE); } ################################################################################ sub get_id_anuncio_aleatorio { my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); my @anuncios; #Prepare array $sth = $dbh->prepare('SELECT id_anuncio FROM anuncio WHERE imagem = (?) ORDER BY data desc limit 30'); $sth->execute(1) or common::dienice("Error->$DBI::errstr"); while ($h = $sth->fetchrow_hashref) {push (@anuncios, $h->{id_anuncio})} my $rand = int(rand(scalar(@anuncios))); return ($anuncios[$rand]); } ################################################################################ sub get_personal_page_header { my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); my $titulo; my $descricao; common::dienice("Please inform user id") unless ($_[1]); $sth = $dbh->prepare('SELECT titulo_classificados, texto_classificados FROM hp_users WHERE id = (?)'); $sth->execute($_[1]) or common::dienice("Error->$DBI::errstr"); while ($h = $sth->fetchrow_hashref) {$titulo = $h->{titulo_classificados}; $descricao = $h->{texto_classificados};} return ($titulo, $descricao); } ################################################################################ sub get_add_ids_from_user { my ($self) = @_; my $id_user = $_[1]; my @id_anuncios; my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); #Prepare array $sth = $dbh->prepare('SELECT id_anuncio FROM anuncio WHERE id_user = (?) ORDER BY operacao, valor') or dienice ("Falha na preparação da busca
$DBI::errstr"); $sth->execute($id_user) or common::dienice("Error->$DBI::errstr"); while ($h = $sth->fetchrow_hashref) {push (@id_anuncios, $h->{id_anuncio});} return (@id_anuncios); } ################################################################################ sub apagar { my ($self, $id_user, $id_anuncio) = @_; common::dienice("Empty variable") unless ($id_user and $id_anuncio); my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); #Prepare array $sth = $dbh->prepare('DELETE from anuncio WHERE id_user = (?) AND id_anuncio = (?)') or dienice ("Falha na preparação da busca
$DBI::errstr"); $sth->execute($id_user, $id_anuncio) or common::dienice("Error->$DBI::errstr"); my $img = "classificados/images/"; $img .= "$id_anuncio"; $img .= ".jpg"; unlink($img); } ################################################################################ sub get_add_form { my ($self) = @_; my $form = common::get_file("templates/prog/classificados_anunciar.htm"); $form =~s/--target--/$self->{target}/; #Substitute text variables foreach my $tv (@text_vars) {$form =~ s/--$tv--/$self->{$tv}/;} #Pulldowns foreach my $pd (@pulldowns) { my $wv = "--$pd"; $wv .= "_$self->{$pd}--"; $form =~ s/$wv/selected/; } #Radio_buttons foreach my $pd (@buttons) { my $wv = "--$pd"; $wv .= "_$self->{$pd}--"; $form =~ s/$wv/checked/; } return ($form); } ################################################################################ sub registrar { my ($self) = @_; my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); #Verificar se anúncio esta registrado $sth = $dbh->prepare('SELECT id_user FROM anuncio WHERE endereco = (?)') or dienice ("Falha na preparação da busca
$DBI::errstr"); my $rv = $sth->execute($self->{endereco}) or common::dienice("Error->$DBI::errstr"); common::dienice("Imóvel já cadastrado") if $rv == 1; ##Verify for html foreach my $v (@text_vars, @pulldowns, @buttons) { common::dienice("uso de caractere ilegal (<).") if $self->{$v} =~ /\{operacao}); common::dienice("Favor slecione o Estado") unless ($self->{estado}); common::dienice("Favor slecione o Cidade") unless ($self->{cidade}); common::dienice("Favor selecione o tipo de imóvel") unless ($self->{tipo_imovel}); common::dienice("Favor selecione o tipo de operação") unless ($self->{operacao}); common::dienice("Favor entre com o título para o anúncio") unless ($self->{titulo}); common::dienice("Favor selecione caso seja corretor ou proprietário") unless ($self->{corretoup}); #Registrar Anuncio $sth = $dbh->prepare('INSERT INTO anuncio values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),?,?,?,?,?,?)') or dienice ("Falha na preparação da busca
$DBI::errstr"); $sth->execute("",$self->{id_user},$self->{nome},$self->{telefone},$self->{email},$self->{corretoup},$self->{url}, $self->{operacao}, $self->{titulo},$self->{localizacao},$self->{estado},$self->{cidade},$self->{bairro}, $self->{endereco}, $self->{valor}, $self->{metragem},$self->{txtAnuncio},$self->{tipo_imovel},"N",1,1,1,1,1) or common::dienice ("Cant´t execute querry in database
$DBI::errstr"); } ################################################################################ sub atualizar { my ($self, $id_anuncio, $id_user) = @_; common::dienice("Please inform id_anuncio") unless $id_anuncio; common::dienice("Please inform id_user") unless $id_user; common::dienice("Favor selecione o tipo de imóvel") unless $self->{tipo_imovel}; my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); foreach my $v (@text_vars, @pulldowns, @buttons) { my $query = "UPDATE anuncio set $v = (?) WHERE id_anuncio = (?) AND id_user = (?)"; $sth = $dbh->prepare("$query"); $sth->execute($self->{$v}, $id_anuncio, $id_user); } $sth = $dbh->prepare("UPDATE anuncio set data = NOW() WHERE id_anuncio = (?) AND id_user = (?)"); $sth->execute($id_anuncio, $id_user) or common::dienice($DBI::errstr); } ################################################################################ sub get_html_search_form { my $form = common::get_file("templates/prog/classificados_search_form.htm"); my $estado_pulldown = get_html_estado_pulldown(); my $tipo_imovel = get_html_tipo_imovel_pulldown(); $form =~ s/--estado--/$estado_pulldown/; $form =~ s/--tipo_imovel--/$tipo_imovel/; return($form); } #private sub get_html_tipo_imovel_pulldown { my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); my $answer .= ""; return ($answer); } sub get_html_estado_pulldown { my ($h, %sqldata, $sth); my $dbh = common::dbiconnect(); my $answer .= ""; return ($answer); } ################################################################################ 1;