<?php 




class DaoFuncoes extends conexao {

public function Atualizar(funcoes $funcoes) {

try {

if ($funcoes->getFun_id() != '') {

$sql = " UPDATE funcoes SET
fun_titulo = ?,
fun_descricao = ?,
fun_imagem = ?,
fun_status = ?
WHERE fun_id = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $funcoes->getFun_titulo());
$stmt->bindValue(2, $funcoes->getFun_descricao());
$stmt->bindValue(3, $funcoes->getFun_imagem());
$stmt->bindValue(4, $funcoes->getFun_status());
$stmt->bindValue(5, $funcoes->getFun_id());


} else {

$sql = " INSERT INTO funcoes (fun_titulo,fun_descricao,fun_imagem,fun_status)
VALUES (?,?,?,?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $funcoes->getFun_titulo());
$stmt->bindValue(2, $funcoes->getFun_descricao());
$stmt->bindValue(3, $funcoes->getFun_imagem());
$stmt->bindValue(4, $funcoes->getFun_status());


}
if ($stmt->execute()){
return true;
} else
return false;

} catch (Exception $e) {
print "Erro ao tentar atualizar: ".$e;
}

}

public function PesquisarFuncoes($codigo){
$sql = " SELECT * FROM funcoes WHERE fun_id = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $codigo);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

public function ListarFuncoes(){
$sql = " SELECT * FROM funcoes ORDER BY fun_id ";
$stmt = self::conectar()->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}


public function ListarFuncoes2(){
$sql = " SELECT * FROM funcoes ORDER BY fun_id ";
$stmt = self::conectar()->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}


	
public function deletar($fun_id){		
$sql = " DELETE FROM funcoes WHERE fun_id = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $fun_id); 
$stmt->execute();
}

 
}
