Viewing file: valores_class.php (4.81 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
require_once("funcoes_valores.php");
class Valores{
var $tabela, $campos, $qtd_campos, $campos_data, $campos_valor, $resultado, $dados;
var $conexao;
/*
Autor: Rodrigo J Polette
Empresa: NetNigro
Data: 12/05/2009
*/
function Valores(){
$this->tabela = "irp_servicos_valores";
$this->campos = array("SRV_RowID","SRV_Entrancia","SRV_Valor","SRV_AtivoSN","SRV_DataVigencia");
$this->qtd_campos = count($this->campos);
$this->campos_data = array("SRV_DataVigencia");
$this->campos_valor = array("SRV_Valor");
global $conexao;
$this->conexao = $conexao;
}
function get($nome) {
return stripslashes($this->$nome);
}
function set($nome,$valor) {
$this->$nome = $valor;
}
function carrega($dados) {
$this->dados = $dados;
reset($dados);
while (list($campo,$valor) = each($dados)) {
if (in_array($campo,$this->campos_data))
$this->$campo = FormataData($valor,'SCREEN');
elseif (in_array($campo,$this->campos_valor))
$this->$campo = FormataValor($valor);
else
$this->$campo = stripslashes($valor);
$this->dados[$campo] = $valor;
}
}
function verNotNull(){
if (
(strlen($this->get("SRV_Entrancia"))==0) or
(strlen($this->get("SRV_Valor"))==0) or
(strlen($this->get("SRV_AtivoSN"))==0) or
(strlen($this->get("SRV_DataVigencia"))==0)
) {
return false;
}
else
return true;
}
function inserir() {
if (!$this->verNotNull())
return false;
$nomes = "(";
$valores = "(";
for ($i=0;$i<$this->qtd_campos;$i++) {
$campo = $this->campos[$i];
$valor = $this->get($campo);
if (strlen($valor)==0)
$valor = "NULL";
else {
if (in_array($campo,$this->campos_data))
$valor = FormataData($valor,"BD");
elseif (in_array($campo,$this->campos_valor))
$valor = PreparaValor($valor);
$valor = "'$valor'";
}
$nomes .= "$campo,";
$valores .= "$valor,";
}
$nomes = substr($nomes,0,-1).")";
$valores = substr($valores,0,-1).")";
$sql = "INSERT INTO $this->tabela $nomes VALUES $valores";
if (mysqli_query($this->conexao,$sql)) {
$this->set("SRM_RowID",mysqli_insert_id($this->conexao));
return true;
}
else {
$this->set("SRM_RowID","");
return false;
}
}
function alterar($id) {
if (!is_numeric($id)) return false;
if (!$this->verNotNUll())
return false;
$this->set("SRM_RowID",$id);
$sets = "";
for ($i=0;$i<$this->qtd_campos;$i++) {
$campo = $this->campos[$i];
$valor = $this->get($campo);
if (strlen($valor)==0)
$valor = "NULL";
else {
if (in_array($campo,$this->campos_data))
$valor = FormataData($valor,"BD");
elseif (in_array($campo,$this->campos_valor))
$valor = PreparaValor($valor);
$valor = "'$valor'";
}
$sets .= "$campo = $valor,";
}
$sets = substr($sets,0,-1);
$sql = "UPDATE $this->tabela SET $sets WHERE SRV_RowID=$id";
if (mysqli_query($this->conexao,$sql))
return true;
else
return false;
}
function deletar($id) {
if (!$this->buscar($id)) return false;
return mysqli_query($this->conexao,"DELETE FROM $this->tabela WHERE SRM_RowID=$id");
}
function buscar($id) {
if (!is_numeric($id)) return false;
$dados = mysqli_fetch_assoc(mysqli_query($this->conexao,"SELECT * FROM $this->tabela WHERE SRM_RowID=$id"));
if (is_array($dados)) {
$this->carrega($dados);
return true;
}
else
return false;
}
function listar($where="",$orderby="",$inicio="",$qtd="") {
$sql = "SELECT * FROM $this->tabela";
if ($where) $sql = $sql." WHERE ".$where;
if ($orderby) $sql = $sql." ORDER BY ".$orderby;
if (is_numeric($inicio) and is_numeric($qtd))
$sql = $sql." LIMIT $inicio,$qtd";
$this->resultado = mysqli_query($this->conexao,$sql);
return $this->resultado;
}
function listar_ativos($where="",$orderby="",$inicio="",$qtd="") {
if ($where)
$where .= " AND ";
$where .= "SRV_AtivoSN = 'S'";
return $this->listar($where,$orderby,$inicio,$qtd);
}
function retorna_array() {
$this->listar_ativos("","SRV_DataVigencia");//Nisso a data maior sobreescreve as menores na atribuição do resultado
$retorno = array();
while ($this->Fetch()) {
$retorno[$this->dados['SRV_Entrancia']] = $this->dados;
}
return $retorno;
}
function fetch($resultado = "") {
if ($resultado == "")
$resultado = $this->resultado;
$dados = mysqli_fetch_assoc($resultado);
if ($dados) {
$this->carrega($dados);
return true;
}
else
return false;
}
}
?>
|