-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
370 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,163 @@ | ||
<?php | ||
// include '../classes/dao/UsuarioDAO.class.php'; | ||
// include '../classes/model/Usuario.class.php'; | ||
class UsuarioCtrl{ | ||
|
||
private $usuarioDao; | ||
|
||
public function UsuarioCtrl() { | ||
$this->usuarioDao = new UsuarioDAO(); | ||
} | ||
|
||
public function buscarUserPorId ($id){ | ||
$linha_user = $this->usuarioDao->buscarUsuario($id); | ||
if ($linha_user <> "" || $linha_user <> null ){ | ||
$usuario = new Usuario($linha_user->id_colaborador, | ||
$linha_user->Login, | ||
$linha_user->Senha, | ||
$linha_user->cpf, | ||
$linha_user->tipo, | ||
$linha_user->last_log_date, | ||
$linha_user->email_activated, | ||
$linha_user->Email); | ||
return $usuario; | ||
}else { | ||
header("location: ../erro.php"); | ||
} | ||
|
||
|
||
} | ||
|
||
public function buscarUserPorLogin ($login){ | ||
$linha_user = $this->usuarioDao->buscarUsuarioLogin($login); | ||
if ($linha_user <> "" || $linha_user <> null ){ | ||
$usuario = new Colaborador($linha_user->id_colaborador, | ||
$linha_user->Login, | ||
$linha_user->Senha, | ||
$linha_user->cpf, | ||
$linha_user->tipo, | ||
$linha_user->last_log_date, | ||
$linha_user->email_activated, | ||
$linha_user->Email); | ||
return $usuario; | ||
}else { | ||
//header("location: ../erro.php"); | ||
} | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
/** | ||
* UsuarioCtrl.class [ Controller ] | ||
* Responsavel por fazer o Controle entre a View e o BD para tabela <b>usuario</b> | ||
* @copyright (c) 2016, Armando JR. ELFISERVICE | ||
*/ | ||
class UsuarioCtrl { | ||
|
||
private $usuarioDao; | ||
|
||
public function __construct() { | ||
$this->usuarioDao = new UsuarioDAO(); | ||
} | ||
|
||
/** | ||
* Fazer INSERT no BD na tabela = usuario | ||
* @param Usuario $Obj = passar uma Instancia deste tipo para inserir no BD | ||
* @return boolean = TRUE se Sucesso ao inserir dados no BD e FALSE se houver algum problema na INSERÇÃO ou se o OBJETO não foi passado corretamente | ||
*/ | ||
public function inserirBD(Usuario $Obj) { | ||
if ($Obj instanceof Usuario) { | ||
|
||
foreach ((array) $Obj as $campo => $valor) { | ||
$campo = str_replace("\0Usuario\0", "", $campo); | ||
$campoArr[$campo] = $campo; | ||
} | ||
|
||
// unset($campoArr['id']); | ||
$arrObj = array_values((array) $Obj); | ||
// unset($arrObj[0]); | ||
|
||
|
||
$campoArr = implode(', ', array_keys($campoArr)); | ||
$valores = " '" . implode("','", array_values($arrObj)) . "' "; | ||
// var_dump($valores); | ||
//die; | ||
if ($this->usuarioDao->insert($campoArr, $valores)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Fazer SELECT no BD na tabela = <b>usuario</b> | ||
* @param string $campos = Campos do BD a serem pesquisados | ||
* @param string $termos = Termos para Filtrar a Busca no BD (WHERE, etc) | ||
* @return Array de Objetos do tipo --><b>Usuario</b><-- se encontrar resultados, se não retorna NULL | ||
*/ | ||
public function buscarBD($campos, $termos) { | ||
$select = $this->usuarioDao->select($campos, $termos); | ||
if (!empty($select)) { | ||
return $this->montarObjeto($select); | ||
} else { | ||
return NULL; | ||
} | ||
} | ||
|
||
/** | ||
* Fazer UPDATE no BD na tabela = <b>usuario</b> | ||
* @param <b>Usuario</b> $obj = passar uma Instancia deste tipo para inserir no BD | ||
* @return boolean = TRUE se Sucesso ao ATUALIZAR dados no BD e FALSE se houver algum problema na ATUALIZAÇÃO ou se o OBJETO não foi passado DO TIPO CORRETO | ||
*/ | ||
public function atualizarBD(Usuario $obj) { | ||
if ($obj instanceof Usuario) { | ||
$id = $obj->getId(); | ||
$obj->setId(""); | ||
|
||
foreach ((array) $obj as $campo => $valor) { | ||
if (!$valor == NULL || !$valor == "" || $valor == "0") { | ||
$campo = str_replace("\0Usuario\0", "", $campo); | ||
$camposDados[] = $campo . " = '" . $valor . "'"; | ||
} | ||
} | ||
|
||
//unset($camposDados[0]); | ||
$camposDados = implode(', ', $camposDados); | ||
|
||
if ($this->usuarioDao->update($camposDados, "WHERE id = '$id' ")) { | ||
|
||
return TRUE; | ||
} else { | ||
return FALSE; | ||
} | ||
} else { | ||
return FALSE; | ||
} | ||
} | ||
|
||
/** | ||
* Logica para Alteração de Senha do Usuario | ||
* @param $dados = array com os dados do campo das senhas | ||
* @return Mensagem de Erro ou Sucesso | ||
*/ | ||
public function alterarSenha($dados, $userlogin) { | ||
$senha_atual = md5($dados['passatual']); | ||
$senha_nova = $dados['passnova']; | ||
$senha_nova2 = $dados['passnova2']; | ||
$id_user = $dados['id_user']; | ||
if ((!$senha_atual) || (!$senha_nova) || (!$senha_nova2)) { | ||
return WSErro("Favor preencher todos os campos!", WS_ERROR); | ||
} else if ($senha_atual <> $userlogin->getSenha()) { | ||
return WSErro("Senha atual incorreta!", WS_ERROR); | ||
} else if ($senha_nova <> $senha_nova2) { | ||
return WSErro("Senha nova 1 e 2 são diferentes! Favor digitar novamente.", WS_ERROR); | ||
} else { | ||
$senha_nova_md5 = md5($senha_nova); | ||
$obj = new Usuario($id_user, "", "", $senha_nova_md5); | ||
if ($this->atualizarBD($obj)) { | ||
$textoCorpo = "<div> <p>Senha alterada com sucesso, segue abaixo:</p></div> <div> <p>Login: {$userlogin->getLogin()} <br> Nova Senha: <b>{$senha_nova}</b> </p></div>"; | ||
$email = new EmailGenerico(array($userlogin->getLogin()), "Senha Alterada no Sistema", $textoCorpo, array(), array(), 1); | ||
if($email->enviarEmailSMTP()){ | ||
$textoWSerro = "Atualizada a senha com sucesso!<br>Foi enviado um Email com seus novos dados."; | ||
}else{ | ||
$textoWSerro = "Atualizada a senha com sucesso!<br>Ops! Ocorreu um Erro ao tentar enviar um Email com seus novos dados."; | ||
} | ||
|
||
return WSErro($textoWSerro, WS_ACCEPT); | ||
} else { | ||
return WSErro("Ocorreu algum erro ao tentar Atualizar, favor tentar novamente!.", WS_ERROR); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Alterar o Tipo da Conta do Colaborador | ||
* @param type $dados = Array com os dados para Alteração, Tipo e ID | ||
* @return String = com Mensagem de Sucesso ou Erro | ||
*/ | ||
public function alterarTipoConta($dados) { | ||
$id_user = $dados['id_user']; | ||
$tipo_conta_user = $dados['tipo']; | ||
|
||
if (!empty($id_user) && !empty($tipo_conta_user)) { | ||
$obj = new Usuario($id_user, "", "", "", $tipo_conta_user); | ||
if ($this->atualizarBD($obj)) { | ||
return WSErro("Atualizado tipo de conta com sucesso!.", WS_ACCEPT); | ||
} else { | ||
return WSErro("Ocorreu algum erro ao tentar Atualizar, favor tentar novamente!.", WS_ERROR); | ||
} | ||
}else{ | ||
return WSErro("Campo vazio, Não atualizado!", WS_ALERT); | ||
} | ||
} | ||
|
||
//-------------------------------------------------- | ||
//----------------PRIVATES--------------------- | ||
//-------------------------------------------------- | ||
private function montarObjeto($arrayDados) { | ||
$arrayObj = array(); | ||
foreach ($arrayDados as $dado) { | ||
extract($dado); | ||
$arrayObj[] = new Usuario($id, $id_colaborador, $Login, $Senha, $tipo, $ativo, $last_log_date); | ||
} | ||
|
||
return $arrayObj; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
<?php | ||
/** | ||
* UsuarioDAO.class [ DAO ] | ||
* Responsavel gerencia a PErsistencia para Tabela usuario | ||
* @copyright (c) 2017, Armando JR. ELFISERVICE | ||
*/ | ||
class UsuarioDAO implements CRUD{ | ||
|
||
const Tabela = 'usuario'; | ||
|
||
public function delete($termos, $tabela = self::Tabela) { | ||
return FALSE; | ||
} | ||
|
||
public function insert($camposBd, $valores, $tabela = self::Tabela) { | ||
$insert = new Insert(); | ||
$insert->ExecInsert($tabela, $camposBd, $valores); | ||
return $insert->getResultado(); | ||
} | ||
|
||
public function select($campos, $termos, $tabela = self::Tabela) { | ||
$read = new Read(); | ||
$read->ExecRead($campos, $tabela, $termos); | ||
return $read->getResultado(); | ||
} | ||
|
||
public function update($camposDados, $termos, $tabela = self::Tabela) { | ||
$update = new Update(); | ||
$update->ExecUpdate($tabela, $camposDados, $termos); | ||
return $update->getResultado(); | ||
} | ||
|
||
class UsuarioDAO{ | ||
|
||
public function UsuarioDAO(){ | ||
|
||
} | ||
|
||
public function buscarUsuario($id){ | ||
$sql_user = mysql_query("SELECT * FROM colaboradores WHERE id_colaborador='$id'") or die (mysql_error()); | ||
$linha_user = mysql_fetch_object($sql_user); | ||
return $linha_user; | ||
} | ||
|
||
public function buscarUsuarioLogin($login){ | ||
$sql_user = mysql_query("SELECT * FROM colaboradores WHERE Login='$login'") or die (mysql_error()); | ||
$linha_user = mysql_fetch_object($sql_user); | ||
return $linha_user; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.