require_once("mysql.class.php");
class Horario extends MySQL
{
var $tabela, $nometabela;
function Horario($conn, $nome)
{ //construtor
$this->conn = $conn;
$this->nometabela = $nome;
//die($this->odbc_conn);
$this->tabela = array();
}
//formata a data do pt_br para ingles
function formataDataEn($dt=''){
if($dt == '') return '';
list($dia,$mes,$ano)=split("/", $dt,3);
$retorno = "".$ano."/".$mes."/".$dia;
return $retorno;
}
// formata a data do mysql pro formato brasileiro
function formataDataPt($dt=''){
if($dt == '') return '';
list($ano,$mes,$dia)=split("-", $dt,3);
$retorno = "".$dia."/".$mes."/".$ano;
return $retorno;
}
function set($campo, $val){
if($this->checkcampo($campo)){
$this->tabela[$campo] = $val;
return true;
}
else return false;
}
function checkcampo($campo){
$this->query="SHOW COLUMNS FROM ".$this->nometabela;
$id = $this->execute();
while ($linha = mysql_fetch_assoc($id)){
if($campo == $linha['Field']){
mysql_free_result($id);
return true;
}
}
mysql_free_result($id);
return false;
}
function get($campo){
if(isset($this->tabela[$campo]))
return $this->tabela[$campo];
else
return null;
}
function insert(){
if($this->TestInsert()){
$carga =
$this->query = "INSERT INTO horarios(horario_entrada, horario_saida, carga_horaria)
VALUES ('".$this->tabela['horario_entrada']."', '".$this->tabela['horario_saida']."', '".$this->tabela['carga_horaria']."')";
$result = $this->execute($this->conn, $this->query);
if(!$result)
return false;
return true;
}
return false;
//die("
Inserção Desabilitada");
}
function TestInsert(){
if($this->count("horarios", " horario_entrada = '".$this->tabela['horario_entrada']."' AND horario_saida = '".$this->tabela['horario_saida']."'")){
echo "";
return false;
}
return true;
}
function reset(){
unset($this->tabela);
// EXECUTAR ESSE CÓDIGO PARA CADA TABELA
/*if(sizeof($this->tabela)){
foreach($this->tabela as $campo => $valor){
unset($this->tabela[$campo]);
}
}*/
}
function listar($campos = "*"){
$this->query = "";
$first = true;
//while(list($key,$val) = each($table))
// echo "\n$key=>$val";
//die("querie".$this->query);
if(sizeof($this->tabela)){
foreach ($this->tabela as $campo => $valor){
if(!is_null($this->tabela[$campo])){
if(!empty($this->tabela[$campo])){
if($first){
$first = false;
$this->query .= " WHERE $campo = '".$valor."'";
}
else
$this->query .= " AND $campo = '".$valor."'";
}
}
}
}
return $this->vt_recordset($campos, array($this->nometabela), $this->query);
}
function consultar() {
$this->query = "SELECT * FROM $this->nometabela ";
$first = true;
foreach ($this->tabela as $campo => $valor){
if(!is_null($this->tabela[$campo])){
if(!empty($this->tabela[$campo])){
if($first){
$first = false;
$this->query .= " WHERE $campo = '".$valor."'";
}
else
$this->query .= " AND $campo = '".$valor."'";
}
}
}
$rs = $this->execute($showerror=true, $debug=true);
$row_rs = mysql_fetch_assoc($rs);
$total_linhas = mysql_num_rows($rs);
if ($total_linhas>0){
foreach ($row_rs as $campo => $valor)
$this->tabela[$campo] = $valor;
$bl_aux = true;
}else $bl_aux = false;
mysql_free_result($rs);
return $bl_aux;
}
function show($campo){
if(isset($this->tabela[$campo]))
return true;
else
return false;
}
}
?>