Viewing file: blog_comentarios_class.php (5.95 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
class BlogComentarios {
var $id, $id_texto, $ip, $data, $nome, $email, $comentario, $ativo, $deletado;
var $conexao, $tabela;
function BlogComentarios() {
$this->id = Null;
$this->id_texto = Null;
$this->ip = Null;
$this->data = Null;
$this->nome = Null;
$this->email = Null;
$this->comentario = Null;
$this->deletado = Null;
$this->tabela = "blog_comentarios";
global $conexao;
$this->conexao = $conexao;
}
function get($nome) {
return stripslashes($this->$nome);
}
function set($nome,$valor) {
$this->$nome = $valor;
}
function carrega($dados) {
$this->id = $dados['BCM_RowID'];
$this->id_texto = $dados['BCM_Texto_DR'];
$this->ip = $dados['BCM_IP'];
$this->data = formata_data($dados['BCM_Data']);
$this->nome = $dados['BCM_Nome'];
$this->email = $dados['BCM_Email'];
$this->comentario = $dados['BCM_Comentario'];
$this->ativo = $dados['BCM_AtivoSN'];
$this->deletado = $dados['BCM_DeletadoSN'];
}
function verNotNull() {
if (strlen($this->get("ip"))==0)
$this->set("ip",$_SERVER['REMOTE_ADDR']);
if (strlen($this->get("data"))==0)
$this->set("data",date("d/m/Y H:i:s"));
if (strlen($this->get("ativo"))==0)
$this->set("ativo","S");
if (strlen($this->get("deletado"))==0)
$this->set("deletado","N");
if (
(strlen($this->get("id_texto"))==0) or
(strlen($this->get("ip"))==0) or
(strlen($this->get("data"))==0) or
(strlen($this->get("nome"))==0) or
(strlen($this->get("comentario"))==0) or
(strlen($this->get("ativo"))==0) or
(strlen($this->get("deletado"))==0)
) {
return false;
}
else
return true;
}
function inserir() {
if (!$this->verNotNull())
return false;
$id_texto = $this->get("id_texto");
$ip = "'".$this->get('ip')."'";
$data = "'".prepara_data($this->get('data'))."'";
$nome = "'".$this->get('nome')."'";
$email = "'".$this->get('email')."'";
$comentario = "'".$this->get('comentario')."'";
$ativo = "'".$this->get("ativo")."'";
$deletado = "'".$this->get("deletado")."'";
$sql = "INSERT INTO $this->tabela (BCM_Texto_DR, BCM_IP, BCM_Data, BCM_Nome, BCM_Email, BCM_Comentario, BCM_AtivoSN, BCM_DeletadoSN) VALUES ($id_texto, $ip, $data, $nome, $email, $comentario, $ativo, $deletado)";
if ($this->conexao->Executar($sql)) {
$this->set("id",mysql_insert_id($this->conexao->conexao));
return true;
}
else {
$this->set("id","");
return false;
}
}
function alterar($id) {
if (!is_numeric($id)) return false;
if (!$this->verNotNUll())
return false;
$this->set("id",$id);
$id_texto = $this->get("id_texto");
$ip = "'".$this->get('ip')."'";
$data = "'".prepara_data($this->get('data'))."'";
$nome = "'".$this->get('nome')."'";
$email = "'".$this->get('email')."'";
$comentario = "'".$this->get('comentario')."'";
$ativo = "'".$this->get("ativo")."'";
$sql = "UPDATE $this->tabela SET BCM_Texto_DR = $id_texto, BCM_IP = $ip, BCM_Data = $data, BCM_Nome = $nome, BCM_Email = $nome, BCM_Comentario = $comentario, BCM_AtivoSN = $ativo WHERE BCM_RowID = $id";
if ($this->conexao->Executar($sql))
return true;
else
return false;
}
function deletar($id) {
if (!$this->buscar($id)) return false;
return $this->conexao->Executar("UPDATE $this->tabela SET BCM_DeletadoSN = 'S' WHERE BCM_RowID=".$this->get("id"));
}
function buscar($id) {
if (!is_numeric($id)) return false;
$dados = $this->conexao->UmFetch("SELECT * FROM $this->tabela WHERE BCM_RowID=$id");
if (is_array($dados)) {
$this->carrega($dados);
return true;
}
else
return false;
}
function listar($where="",$orderby="BCM_Data",$inicio="0",$qtd="") {
$sql = "SELECT * FROM $this->tabela";
if ($where) $where = "($where) AND BCM_DeletadoSN = 'N'";
else $where = "BCM_DeletadoSN = 'N'";
$sql = $sql." WHERE ".$where;
if ($orderby) $sql = $sql." ORDER BY ".$orderby;
if (is_numeric($inicio) and is_numeric($qtd))
$sql = $sql." LIMIT $inicio,$qtd";
return $this->conexao->Executar($sql);
}
function listar_ativos($where="",$orderby="BCM_Data desc",$inicio="",$qtd="") {
if ($where) $where = "($where) AND BCM_AtivoSN = 'S'";
else $where = "BCM_AtivoSN = 'S'";
return $this->listar($where,$orderby,$inicio,$qtd);
}
function listar_por_texto($id_texto,$where="",$orderby="BCM_Data",$inicio="",$qtd="") {
if ($where) $where = "($where) AND BCM_Texto_DR = '$id_texto'";
else $where = "BCM_Texto_DR = '$id_texto'";
return $this->listar($where,$orderby,$inicio,$qtd);
}
function listar_ativos_por_texto($id_texto,$where="",$orderby="BCM_Data desc",$inicio="",$qtd="") {
if ($where) $where = "($where) AND BCM_Texto_DR = '$id_texto'";
else $where = "BCM_Texto_DR = '$id_texto'";
return $this->listar_ativos($where,$orderby,$inicio,$qtd);
}
function Fetch($resultado) {
$dados = $this->conexao->Fetch($resultado);
if ($dados) {
$this->carrega($dados);
return true;
}
else
return false;
}
function ativar($id) {
if (!is_numeric($id)) return false;
return $this->conexao->Executar("UPDATE $this->tabela SET BCM_AtivoSN = 'S' WHERE BCM_RowID = $id");
}
function desativar($id) {
if (!is_numeric($id)) return false;
return $this->conexao->Executar("UPDATE $this->tabela SET BCM_AtivoSN = 'N' WHERE BCM_RowID = $id");
}
function ativar_desativar($id) {
if (!is_numeric($id)) return false;
$this->buscar($id);
if ($this->get("ativo")=='S')
return $this->desativar($id);
else
return $this->ativar($id);
}
}
?>
|