-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientesController.php
97 lines (88 loc) · 2.91 KB
/
clientesController.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
<?php
require_once "./classes/clientes/Cliente.php";
require_once "./classes/clientes/ClienteDAO.php";
require_once "./authController.php";
class clientesController {
public function newCliente(){
$cliente = new Cliente();
$cliente->setNome($_POST["name"]);
$cliente->setTelefone(preg_replace('/[\(\)\-\s]/', '', $_POST["phone"]));
$erros = $cliente->validate();
if(count($erros) != 0) {
include "views/layout/header.php";
include "views/layout/side-bar.php";?>
<main>
<?php include "views/cliente/novo.php";?>
</main>
<?php include "views/layout/footer.php";
}
else
{
$db = new ClienteDAO();
$db->create($cliente);
header('Location: index.php?acao=cliente/listar');
}
}
public function getClientes() {
$db = new ClienteDAO();
$clientes = $db->all();
return $clientes;
}
public function deleteCliente($id){
$db = new ClienteDAO();
$db->delete($id);
header('Location: index.php?acao=cliente/listar');
}
public function editCliente($id) {
if(!isset($_POST['altera']))
{
require_once("./classes/clientes/ClienteDAO.php");
$db = new ClienteDAO();
$cliente = $db->findOne($id);
include_once "views/layout/header.php";
include_once "views/layout/side-bar.php";?>
<main>
<?php include_once "views/cliente/editar.php";?>
</main>
<?php include_once "views/layout/footer.php";
}
else
{
$cliente = new Cliente();
$cliente->setNome($_POST["name"]);
$cliente->setTelefone(preg_replace('/[\(\)\-\s]/', '', $_POST["phone"]));
$erros = $cliente->validate();
if(count($erros) != 0) {
include_once "views/layout/header.php";
include_once "views/layout/side-bar.php";?>
<main>
<?php include_once "views/cliente/editar.php";?>
</main>
<?php include_once "views/layout/footer.php";
}
else
{
$db = new ClienteDAO();
$db->update($cliente, $id);
header('Location: index.php?acao=cliente/listar');
}
}
}
}
$auth = new AuthController();
$auth->isAuthenticate();
$action = explode("/", $_GET['acao']);
switch($action[0]) {
case 'excluir':
$controller = new clientesController();
$controller->deleteCliente($action[1]);
break;
case 'cadastrar':
$controller = new clientesController();
$controller->newCliente();
break;
case 'editar':
$controller = new clientesController();
$controller->editCliente($action[1]);
break;
}