forked from pedrocastagna/WebDevSec-main
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetClient.php
More file actions
164 lines (134 loc) · 4.08 KB
/
setClient.php
File metadata and controls
164 lines (134 loc) · 4.08 KB
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
<?php
include_once 'controllers/session_control.php';
include_once 'controllers/functions.php';
include_once 'controllers/model.php';
include_once 'controllers/header.php';
include_once 'config/app.php';
$session = new session_control();
$functions = new functions();
$model = new model();
$act = "";
$id = "";
$nome = "";
$sobrenome = "";
$documento = "";
$telefone = "";
$email = "";
$user = "";
$password = "";
$endereco = "";
$cidade = "";
$uf = "";
$cep = "";
$pais = "";
if($_POST["act"]){$act = $_POST["act"];}
if($_POST["id"]){$id = $_POST["id"];}
if($act == 'new' || $act == 'edit'){
if($_POST["nome"]){$nome = utf8_decode($_POST["nome"]);}
if($_POST["sobrenome"]){$sobrenome = utf8_decode($_POST["sobrenome"]);}
if($_POST["documento"]){$documento = utf8_decode($_POST["documento"]);}
if($_POST["telefone"]){$telefone = preg_replace('/[^0-9-()]/','',$_POST["telefone"]);}
if($_POST["email"]){$email = $_POST["email"];}
if($_POST["endereco"]){$endereco = $_POST["endereco"];}
if($_POST["cidade"]){$cidade = $_POST["cidade"];}
if($_POST["estado"]){$uf = $_POST["estado"];}
if($_POST["cep"]){$cep = preg_replace('/[^0-9-]/','',$_POST["cep"]);}
if($_POST["pais"]){$pais = $_POST["pais"];}
if(!$endereco OR !$cidade OR !$cep OR !$uf OR !$pais ){
$errMsg = 'Informe o Endereço Completo'.$endereco.' - '.$cidade.' - '.$cep.' - '.$uf .' - '.$pais;
}
if(!$telefone) $errMsg = 'Informe um Telefone';
if(!$documento) $errMsg = 'Informe o Documento';
if(!$nome) $errMsg = 'Informe o Nome';
if(!$sobrenome) $errMsg = 'Informe o Sobrenome';
if(!$email) $errMsg = 'Informe um E-mail';
if(!$act) $errMsg = 'Ops! Impossível continuar. Tente novamente.';
}else if($act == 'del'){
if(!$id) $errMsg = 'Ops! Impossível continuar. Tente novamente.';
}
if($errMsg){
echo $errMsg;
}else {
if ($act == 'new' || $act == 'edit') {
$conn = new connect();
$qry = "SELECT * FROM clients WHERE email = '" . $email . "' or documento = '" . $documento . "'";
$query = $conn->query($qry);
$seachClient = $conn->row($query);
$rsClient = $conn->fetch_array($query);
}
if ($act == 'new' ) {
if ($seachClient) {
$errMsg = "Já existe outro cliente com este endereço de e-mail ou documento";
echo $errMsg;
exit();
}
$password = $functions->createPassword();
$qry = '
insert into clients (
nome,
sobrenome,
documento,
telefone,
email,
password,
endereco,
cidade,
estado,
cep,
pais
)';
$qry .= '
VALUES (
"' . $nome . '",
"' . $sobrenome . '",
"' . $documento . '",
"' . $telefone . '",
"' . $email . '",
"' . $password . '",
"' . $endereco . '",
"' . $cidade . '",
"' . $uf . '",
"' . $cep . '",
"' . $pais . '"
';
$qry .= ')';
} else if ($act == 'edit') {
if ($seachClient > 1) {
$errMsg = "Já existe outro cliente com este endereço de e-mail ou documento";
echo $errMsg;
exit();
} else if ($seachClient == 1) {
if ($rsClient["id"] != $id) {
$errMsg = "Já existe outro cliente com este endereço de e-mail ou documento";
echo $errMsg;
exit();
}
}
$qry = 'update clients SET ';
$qry .= '
nome = "' . $nome . '",
sobrenome = "' . $sobrenome . '",
documento = "' . $documento . '",
email = "' . $email . '",
telefone = "' . $telefone . '",
endereco = "' . $endereco . '",
cidade = "' . $cidade . '",
estado = "' . $uf . '",
cep = "' . $cep . '",
pais = "' . $pais . '"';
$qry .= ' WHERE id = ' . $id;
} else if ($act == 'del') {
$qry = 'DELETE FROM clients WHERE id = ' . $id;
}
$exec = $model->model_exec($qry);
if (!$exec) {
$errMsg = "Ocorreu um erro durante a atualização do cadastro. Contacte o Administrador";
echo $errMsg;
exit();
}
if ($errMsg) {
echo $errMsg;
} else {
echo 1;
}
}