-
Notifications
You must be signed in to change notification settings - Fork 0
/
editarAluno.php
224 lines (165 loc) · 6.69 KB
/
editarAluno.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
include_once "conexao.php";
include_once "Usuario.php";
include_once "recaptcha.php";
include_once "codigosRecaptcha.php";
if(!isset($_SESSION)) session_start();
$conexao = conexao::getConexao();
if(!isset($_SESSION["usuario"])){
header("location: index.php");
}
$dados = $_SESSION["usuario"];
$nivelAcesso = $dados->getNivelAcesso();
if($nivelAcesso != "A"){
header("location: index.php");
}
//Código acima - verificação de login
$msgFinal = null;
//Configurações sobre o recaptcha
$chaveSecreta = $codChaveRe;
$response = null;
$reCaptcha = new reCaptcha($chaveSecreta);
//Verificações para cadastro
if(isset($_POST["rm"]) && isset($_POST['g-recaptcha-response'])){
$response = $reCaptcha->verifyResponse($_SERVER['REMOTE_ADDR'], $_POST['g-recaptcha-response']);
if($response != null && $response->success){
if($_FILES["imagem"]["size"] < 1048576){
try{
$imagem = (strlen($_FILES["imagem"]["name"]) > 0) ? file_get_contents($_FILES["imagem"]["tmp_name"]) : null;
$nome = trim(addslashes($_POST["nome"]));
$sobrenome = trim(addslashes($_POST["sobrenome"]));
$curso = explode(",", trim(addslashes($_POST["cursos"])));
$cpf = trim(addslashes($_POST["cpf"]));
$telefone = trim(addslashes($_POST["telefone"]));
$celular = trim(addslashes($_POST["celular"]));
$sexo = (trim(addslashes($_POST["sexo"])) == "P") ? null : trim(addslashes($_POST["sexo"]));
$rm = trim(addslashes($_POST["rm"]));
$email = trim(addslashes($_POST["email"]));
$logradouro = trim(addslashes($_POST["logradouro"]));
$cep = trim(addslashes($_POST["cep"]));
$numero = trim(addslashes($_POST["numero"]));
$bairro = trim(addslashes($_POST["bairro"]));
$cidade = trim(addslashes($_POST["cidade"]));
$complemento = trim(addslashes($_POST["complemento"]));
$cod_usuario = trim(addslashes($_POST["id_usuario"]));
$rmO = trim(addslashes($_POST["rm_original"]));
$status = trim(addslashes($_POST["status"]));
//Verificando RM
$comando = $conexao->prepare("SELECT * FROM usuario AS u INNER JOIN aluno AS a ON a.id_usuario_aluno = u.id_usuario WHERE a.rm_aluno = :rm_a LIMIT 1");
$comando->bindParam(":rm_a", $rm);
$comando->execute();
$result = $comando->fetchAll();
if((count($result) == 1 && $rm == $rmO) || count($result) == 0){
//Endereco
$comando = $conexao->prepare("UPDATE endereco_aluno SET cep = :cep, logradouro = :logradouro, numero = :numero, bairro = :bairro, cidade = :cidade, complemento = :complemento WHERE rm_aluno_endereco = :rm LIMIT 1");
$cep = str_ireplace('-', '', $cep);
$comando->bindParam(":cep", $cep);
$comando->bindParam(":logradouro", $logradouro);
$comando->bindParam(":numero", $numero);
$comando->bindParam(":bairro", $bairro);
$comando->bindParam(":cidade", $cidade);
$comando->bindParam(":complemento", $complemento);
$comando->bindParam(":rm", $rmO);
$comando->execute();
//Contato
$comando = $conexao->prepare("UPDATE contato_aluno SET telefone = :telefone, celular = :celular, email = :email WHERE rm_aluno_contato = :rm LIMIT 1");
//Retirando maskara dos dados
$telefone = str_ireplace('(', '', $telefone);
$telefone = str_ireplace(')', '', $telefone);
$telefone = str_ireplace('-', '', $telefone);
$celular = str_ireplace('(', '', $celular);
$celular = str_ireplace(')', '', $celular);
$celular = str_ireplace('-', '', $celular);
//Executando cadastro
$comando->bindParam(":telefone", $telefone);
$comando->bindParam(":celular", $celular);
$comando->bindParam(":email", $email);
$comando->bindParam(":rm", $rmO);
$comando->execute();
//Aluno
$comando = null;
if($imagem != null){
$comando = $conexao->prepare("UPDATE aluno SET rm_aluno = :rm, nome = :nome, sobrenome = :sobrenome, cpf = :cpf, sexo = :sexo, img_aluno = :imagem WHERE id_usuario_aluno = :id LIMIT 1");
$cpf = str_ireplace('.', '', $cpf);
$cpf = str_ireplace('-', '', $cpf);
$comando->bindParam(":rm", $rm);
$comando->bindParam(":nome", $nome);
$comando->bindParam(":sobrenome", $sobrenome);
$comando->bindParam(":cpf", $cpf);
$comando->bindParam(":sexo", $sexo);
$comando->bindParam(":imagem", $imagem);
$comando->bindParam(":id", $cod_usuario);
}else{
$comando = $conexao->prepare("UPDATE aluno SET rm_aluno = :rm, nome = :nome, sobrenome = :sobrenome, cpf = :cpf, sexo = :sexo WHERE id_usuario_aluno = :id LIMIT 1");
$cpf = str_ireplace('.', '', $cpf);
$cpf = str_ireplace('-', '', $cpf);
$comando->bindParam(":rm", $rm);
$comando->bindParam(":nome", $nome);
$comando->bindParam(":sobrenome", $sobrenome);
$comando->bindParam(":cpf", $cpf);
$comando->bindParam(":sexo", $sexo);
$comando->bindParam(":id", $cod_usuario);
}
$comando->execute();
//Cursos
//Deletando cursos
$comando = $conexao->prepare("DELETE FROM curso_usuario WHERE usuario_id_usuario = :id");
$comando->bindParam(":id", $cod_usuario);
$comando->execute();
//Adicionando
foreach($curso as $valor){
$comando = $conexao->prepare("INSERT INTO curso_usuario (usuario_id_usuario, curso_id_curso) VALUES (:usuario, :curso)");
$comando->bindParam(":usuario", $cod_usuario);
$comando->bindParam(":curso", $valor);
$comando->execute();
}
//Usuario
$comando = $conexao->prepare("UPDATE usuario SET status_usuario = :status WHERE id_usuario = :id LIMIT 1");
$comando->bindParam(":status", $status);
$comando->bindParam(":id", $cod_usuario);
$comando->execute();
//MSG
$msgFinal = "Aluno editado com sucesso";
}else{
$msgFinal = "Já existe um aluno cadastrado com este RM";
}
}catch(PDOException $ex){
$msgFinal = "Não foi possivel editar este aluno!, Ocorreu um erro na edição!";
}
}else{
$msgFinal = "A imagem selecionada é muito grande!, selecione outra imagem!";
}
}else{
$msgFinal = "Recaptcha Inválido";
}
}else{
header("location: cadAluno.php");
}
if($msgFinal == "Aluno editado com sucesso"){
echo "<main>
<div class='containeAv'>
<div>
<h4>$msgFinal</h4>
</div>
<div>
<i class='fas fa-check-circle'></i>
</div>
</div>
<hr>
<button onclick='deletaMoldal()'>OK</button>
</main>";
}else{
echo "<main>
<div class='containeAv'>
<div>
<h4>$msgFinal</h4>
</div>
<div>
<i class='fas fa-times-circle'></i>
</div>
</div>
<hr>
<button onclick='deletaMoldal()'>OK</button>
</main>";
}
?>