250 lines
11 KiB
PHP
250 lines
11 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 getSTMT($CIDADE,$SQL){
|
|
$SMTM;
|
|
if($CIDADE=='AGUASDELINDOIA'){
|
|
$SMTM = self::$instAGUA->prepare($SQL);
|
|
}else if($CIDADE=='CORUMBATAI'){
|
|
$SMTM = self::$instCORUMBATAI->prepare($SQL);
|
|
}else if($CIDADE=='IRACEMAPOLIS'){
|
|
$SMTM = self::$instIRACEMAPOLIS->prepare($SQL);
|
|
}else{
|
|
//caso o id não foi passado recebe essa mensagem
|
|
die('cidade não cadastrada');
|
|
}
|
|
return $SMTM;
|
|
}
|
|
public function getLoginControle($NO_USERNAME,$CIDADE){
|
|
if(!$NO_USERNAME==''){
|
|
$this->sql = "SELECT * FROM LOGIN WHERE NO_USERNAME = ?";
|
|
$Con = new Controller();
|
|
$this->stmt = $Con -> getSTMT($CIDADE,$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 getBoletim($CD_MATRICULA,$CIDADE){
|
|
if(!$CD_MATRICULA==''){
|
|
$this->sql = "SELECT * FROM SEC_BOLETIM sb WHERE CD_MATRICULA = ?";
|
|
$Con = new Controller();
|
|
$this->stmt = $Con -> getSTMT($CIDADE,$this->sql);
|
|
$this->stmt->bindValue(1,$CD_MATRICULA);
|
|
$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...');
|
|
}
|
|
}
|
|
public function getLoginPais($CPF){
|
|
if(!$CPF==''){
|
|
$this->sql = "SELECT * FROM usuarios WHERE CPF = ?";
|
|
$this->stmt = self::$instMARIA->prepare($this->sql);
|
|
$this->stmt->bindValue(1,$CPF);
|
|
$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 getFilhos($NOME,$PARENTESCO,$CIDADE){
|
|
if($PARENTESCO=='PAI'){
|
|
$this->sql = "SELECT a.CD_ALUNO,s.CD_MATRICULA,a.NR_RA,a.NO_PAI,a.NO_MAE, a.NO_ALUNO,a.DT_NASCIMENTO,s.ANO_FREQ,s.CD_SALA,ss.TURMA,ss.CD_SERIE,ps.DESC_SERIE,
|
|
s.CD_CAD_DIVERSO, cd.NO_FANTASIA, cd.NO_RAZAO_SOCIAL, cd.TX_DIRETOR, cd.TX_VICE_DIRETOR, cd.TX_COORDENADOR, cd.NO_EMAIL, cd.NO_SITE
|
|
FROM ALUNO as a
|
|
INNER JOIN SEC_MATRICULA s ON a.CD_ALUNO = s.CD_ALUNO
|
|
INNER JOIN SEC_SALAS ss ON s.CD_SALA = ss.CD_SALA
|
|
INNER JOIN PASSE_SERIE ps ON ss.CD_SERIE = ps.CD_SERIE
|
|
INNER JOIN CAD_DIVERSO cd ON s.CD_CAD_DIVERSO = cd.CD_CAD_DIVERSO
|
|
WHERE a.NO_PAI LIKE ? AND s.ANO_FREQ ='2023'";
|
|
$Con = new Controller();
|
|
$this->stmt = $Con -> getSTMT($CIDADE,$this->sql);
|
|
$this->stmt->bindValue(1,"%".$NOME."%");
|
|
$this->stmt->execute();
|
|
$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
return $this-> res;
|
|
}else if($PARENTESCO=='MAE'){
|
|
$this->sql = "SELECT a.CD_ALUNO,s.CD_MATRICULA, a.NR_RA,a.NO_PAI,a.NO_MAE, a.NO_ALUNO,a.DT_NASCIMENTO,s.ANO_FREQ,s.CD_SALA,ss.TURMA,ss.CD_SERIE,ps.DESC_SERIE,
|
|
s.CD_CAD_DIVERSO, cd.NO_FANTASIA, cd.NO_RAZAO_SOCIAL, cd.TX_DIRETOR, cd.TX_VICE_DIRETOR, cd.TX_COORDENADOR, cd.NO_EMAIL, cd.NO_SITE
|
|
FROM ALUNO as a
|
|
INNER JOIN SEC_MATRICULA s ON a.CD_ALUNO = s.CD_ALUNO
|
|
INNER JOIN SEC_SALAS ss ON s.CD_SALA = ss.CD_SALA
|
|
INNER JOIN PASSE_SERIE ps ON ss.CD_SERIE = ps.CD_SERIE
|
|
INNER JOIN CAD_DIVERSO cd ON s.CD_CAD_DIVERSO = cd.CD_CAD_DIVERSO
|
|
WHERE a.NO_MAE LIKE ? AND s.ANO_FREQ ='2023'";
|
|
$Con = new Controller();
|
|
$this->stmt = $Con -> getSTMT($CIDADE,$this->sql);
|
|
$this->stmt->bindValue(1,"%".$NOME."%");
|
|
$this->stmt->execute();
|
|
$this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
return $this-> res;
|
|
}
|
|
}
|
|
public function getAlunos($NOME,$CIDADE){
|
|
//CRIADO PARA TESTE COM PARAMETRO
|
|
if(!$NOME==''){
|
|
$this->sql = "SELECT a.CD_ALUNO,s.CD_MATRICULA,a.NR_RA,a.NO_PAI,a.NO_MAE, a.NO_ALUNO,a.DT_NASCIMENTO,s.ANO_FREQ,s.CD_SALA,ss.TURMA,ss.CD_SERIE,ps.DESC_SERIE,
|
|
s.CD_CAD_DIVERSO, cd.NO_FANTASIA, cd.NO_RAZAO_SOCIAL
|
|
FROM ALUNO as a
|
|
INNER JOIN SEC_MATRICULA s ON a.CD_ALUNO = s.CD_ALUNO
|
|
INNER JOIN SEC_SALAS ss ON s.CD_SALA = ss.CD_SALA
|
|
INNER JOIN PASSE_SERIE ps ON ss.CD_SERIE = ps.CD_SERIE
|
|
INNER JOIN CAD_DIVERSO cd ON s.CD_CAD_DIVERSO = cd.CD_CAD_DIVERSO
|
|
WHERE a.NO_ALUNO LIKE ? AND s.ANO_FREQ ='2023'";
|
|
$Con = new Controller();
|
|
$this->stmt = $Con -> getSTMT($CIDADE,$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...');
|
|
}
|
|
}
|
|
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'];
|
|
$ALUNO = $_POST['ALUNO'];
|
|
$CPF = $_POST['CPF'];
|
|
$NOME = $_POST['NOME'];
|
|
$SENHA = $_POST['SENHA'];
|
|
$PARENTESCO = $_POST['PARENTESCO'];
|
|
$DATA_CADASTRO = $_POST['DATA_CADASTRO'];
|
|
$CONDICAO = $_POST['CONDICAO'];
|
|
$CIDADE = $_POST['CIDADE'];
|
|
if($CONDICAO=='NOVO'){
|
|
$this->sql = "INSERT INTO usuarios (CD_ALUNO, ALUNO, CPF, NOME, SENHA, PARENTESCO, DATA_CADASTRO, CONDICAO, CIDADE)
|
|
VALUES (:CD_ALUNO, :ALUNO, :CPF, :NOME, :SENHA, :PARENTESCO, :DATA_CADASTRO, :CONDICAO, :CIDADE)";
|
|
$this->stmt = self::$instMARIA->prepare($this->sql);
|
|
$this->stmt->bindValue(':CD_ALUNO', $CD_ALUNO);
|
|
$this->stmt->bindValue(':ALUNO', $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->bindValue(':CIDADE', $CIDADE);
|
|
$this->stmt->execute();
|
|
if($this->stmt){
|
|
echo 'cadastrado com sucesso';
|
|
}else{
|
|
echo 'erro';
|
|
}
|
|
}else{
|
|
$this->sql = "UPDATE usuarios SET CD_ALUNO = :CD_ALUNO, ALUNO = :ALUNO, NOME = :NOME, SENHA = :SENHA,
|
|
PARENTESCO = :PARENTESCO, DATA_CADASTRO = :DATA_CADASTRO, CONDICAO = :CONDICAO, CPF = :CPF, CIDADE = :CIDADE WHERE CPF = :CPF";
|
|
$this->stmt = self::$instMARIA->prepare($this->sql);
|
|
$this->stmt->bindValue(':CD_ALUNO', $CD_ALUNO);
|
|
$this->stmt->bindValue(':ALUNO', $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->bindValue(':CIDADE', $CIDADE);
|
|
$this->stmt->execute();
|
|
if($this->stmt){
|
|
echo 'editado com sucesso';
|
|
}else{
|
|
echo 'erro';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class DBA{
|
|
protected $stmt, $sql, $res;
|
|
protected static $instAGUA;
|
|
protected static $instCORUMBATAI;
|
|
protected static $instIRACEMAPOLIS;
|
|
protected static $instMARIA;
|
|
//faz a chamada da instancia da conexão com o banco de dados
|
|
function __construct(){
|
|
try{
|
|
if(self::$instAGUA === null){
|
|
//self::$instFIRE = new \PDO(STR_BD,USUARIO,SENHA);
|
|
self::$instAGUA = new \PDO(STR_BD_AGUA,USUARIO_HOMO,SENHA_HOMO);
|
|
}
|
|
//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::$instCORUMBATAI === null){
|
|
//self::$instFIRE = new \PDO(STR_BD,USUARIO,SENHA);
|
|
self::$instCORUMBATAI = new \PDO(STR_BD_CORUMBATAI,USUARIO_HOMO,SENHA_HOMO);
|
|
}
|
|
//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::$instIRACEMAPOLIS === null){
|
|
//self::$instFIRE = new \PDO(STR_BD,USUARIO,SENHA);
|
|
self::$instIRACEMAPOLIS = new \PDO(STR_BD_IRACEMAPOLIS,USUARIO_HOMO,SENHA_HOMO);
|
|
}
|
|
//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();
|
|
}
|
|
}
|
|
} |