141 lines
5.4 KiB
PHP
141 lines
5.4 KiB
PHP
<?php
|
|
namespace app\controllers;
|
|
use League\Plates\Engine;
|
|
use PDO;
|
|
class Controller extends DBA{
|
|
public static function view(string $view, array $data = []){
|
|
|
|
$viewsPath = dirname(__FILE__,2)."/views";
|
|
|
|
if(!file_exists($viewsPath . DIRECTORY_SEPARATOR . $view.".php")){
|
|
throw new \Exception("A view {$view} não existe");
|
|
}
|
|
|
|
$templates = new Engine($viewsPath);
|
|
echo $templates-> render($view,$data);
|
|
}
|
|
public function getLogin($NO_USERNAME){
|
|
if(!$NO_USERNAME==''){
|
|
$this->sql = "SELECT * FROM LOGIN WHERE NO_USERNAME = ?";
|
|
$this->stmt = self::$instFIRE->prepare($this->sql);
|
|
$this->stmt->bindValue(1,$NO_USERNAME);
|
|
$this->stmt->execute();
|
|
$this->res = $this->stmt->fetch(PDO::FETCH_OBJ);
|
|
return $this-> res;
|
|
}else{
|
|
//caso o id não foi passado recebe essa mensagem
|
|
die('informação incompleta...');
|
|
}
|
|
}
|
|
public function getAlunos($NOME){
|
|
//CRIADO PARA TESTE COM PARAMETRO
|
|
if(!$NOME==''){
|
|
$this->sql = "SELECT * FROM ALUNO WHERE NO_ALUNO LIKE ?";
|
|
$this->stmt = self::$instFIRE->prepare($this->sql);
|
|
$this->stmt->bindValue(1,"%".$NOME."%");
|
|
$this->stmt->execute();
|
|
$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
return $this-> res;
|
|
}else{
|
|
//caso o id não foi passado recebe essa mensagem
|
|
die('informação incompleta...');
|
|
}
|
|
//FUNCIONANDO PARA TODA A TABELA ALUNO
|
|
//$this->sql = "SELECT * FROM ALUNO";
|
|
//$this->stmt = self::$inst->prepare($this->sql);
|
|
//$this->stmt -> execute();
|
|
//$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
//print_r($this->res);
|
|
//return $this->res;
|
|
}
|
|
public function getPais($CD_ALUNO){
|
|
$this->sql = "SELECT * FROM usuarios WHERE CD_ALUNO = ?";
|
|
$this->stmt = self::$instMARIA->prepare($this->sql);
|
|
$this->stmt->bindValue(1,$CD_ALUNO);
|
|
$this->stmt->execute();
|
|
$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
return $this-> res;
|
|
}
|
|
public function deletaPais($CPF){
|
|
$this->sql = "DELETE FROM usuarios WHERE CPF = ?";
|
|
$this->stmt = self::$instMARIA->prepare($this->sql);
|
|
$this->stmt->bindValue(1,$CPF);
|
|
$this->stmt->execute();
|
|
if($this->stmt){
|
|
echo 'deletado com sucesso';
|
|
}else{
|
|
echo 'erro';
|
|
}
|
|
}
|
|
public function inserirPais(){
|
|
$CD_ALUNO = $_POST['CD_ALUNO'];
|
|
$CPF = $_POST['CPF'];
|
|
$NOME = $_POST['NOME'];
|
|
$SENHA = $_POST['SENHA'];
|
|
$PARENTESCO = $_POST['PARENTESCO'];
|
|
$DATA_CADASTRO = $_POST['DATA_CADASTRO'];
|
|
$CONDICAO = $_POST['CONDICAO'];
|
|
if($CONDICAO=='NOVO'){
|
|
$this->sql = "INSERT INTO usuarios (CD_ALUNO, CPF, NOME, SENHA, PARENTESCO, DATA_CADASTRO, CONDICAO) VALUES (:CD_ALUNO, :CPF, :NOME, :SENHA, :PARENTESCO, :DATA_CADASTRO, :CONDICAO)";
|
|
$this->stmt = self::$instMARIA->prepare($this->sql);
|
|
$this->stmt->bindValue(':CD_ALUNO', $CD_ALUNO);
|
|
$this->stmt->bindValue(':CPF', $CPF);
|
|
$this->stmt->bindValue(':NOME', $NOME);
|
|
$this->stmt->bindValue(':SENHA', $SENHA);
|
|
$this->stmt->bindValue(':PARENTESCO', $PARENTESCO);
|
|
$this->stmt->bindValue(':DATA_CADASTRO', $DATA_CADASTRO);
|
|
$this->stmt->bindValue(':CONDICAO', $CONDICAO);
|
|
$this->stmt->execute();
|
|
if($this->stmt){
|
|
echo 'cadastrado com sucesso';
|
|
}else{
|
|
echo 'erro';
|
|
}
|
|
}else{
|
|
$this->sql = "UPDATE usuarios SET CD_ALUNO = :CD_ALUNO, NOME = :NOME, SENHA = :SENHA, PARENTESCO = :PARENTESCO, DATA_CADASTRO = :DATA_CADASTRO, CONDICAO = :CONDICAO WHERE CPF = :CPF";
|
|
$this->stmt = self::$instMARIA->prepare($this->sql);
|
|
$this->stmt->bindValue(':CD_ALUNO', $CD_ALUNO);
|
|
$this->stmt->bindValue(':CPF', $CPF);
|
|
$this->stmt->bindValue(':NOME', $NOME);
|
|
$this->stmt->bindValue(':SENHA', $SENHA);
|
|
$this->stmt->bindValue(':PARENTESCO', $PARENTESCO);
|
|
$this->stmt->bindValue(':DATA_CADASTRO', $DATA_CADASTRO);
|
|
$this->stmt->bindValue(':CONDICAO', $CONDICAO);
|
|
$this->stmt->execute();
|
|
if($this->stmt){
|
|
echo 'editado com sucesso';
|
|
}else{
|
|
echo 'erro';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class DBA{
|
|
protected $stmt, $sql, $res;
|
|
protected static $instFIRE;
|
|
protected static $instMARIA;
|
|
//faz a chamada da instancia da conexão com o banco de dados
|
|
function __construct(){
|
|
try{
|
|
if(self::$instFIRE === null){
|
|
self::$instFIRE = new \PDO(STR_BD,USUARIO,SENHA);
|
|
}
|
|
//retorna a instancia com sucesso
|
|
//echo "Connected successfully";
|
|
}catch(\PDOException $e){
|
|
//retorna caso de erro na conexão
|
|
echo "Connection failed: " . $e->getMessage();
|
|
}
|
|
try{
|
|
if(self::$instMARIA === null){
|
|
self::$instMARIA = new \PDO(DB_CONTROLE,USER,PASS);
|
|
}
|
|
//retorna a instancia com sucesso
|
|
//echo "Connected successfully";
|
|
}catch(\PDOException $e){
|
|
//retorna caso de erro na conexão
|
|
echo "Connection failed: " . $e->getMessage();
|
|
}
|
|
}
|
|
} |