-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
44 lines (33 loc) · 1.01 KB
/
update.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
<?php
require_once __DIR__ . '/vendor/autoload.php';
define('TITLE', 'Editar usuário');
use \App\Models\User;
use \App\Repository\UserDao;
use \App\Repository\ColorDao;
// ID VALIDATION
if (!isset($_GET['id']) or !is_numeric($_GET['id'])) {
header('location: index.php?status=error');
exit;
}
$colors = ColorDao::getColors();
$user = UserDao::getUserById($_GET['id']);
// USER VALIDATION
if (!$user instanceof User) {
header('location: index.php?status=error');
exit;
}
// POST VALIDATION
if (isset($_POST['name'], $_POST['email'])) {
$user = new User();
$userDao = new UserDao();
$user->setId($_GET['id']);
$user->setName($_POST['name']);
$user->setEmail($_POST['email']);
$user->setColor($_POST['color']);
$userDao->update($user);
header('location: index.php?status=success');
exit;
}
include __DIR__ . '/resources/views/components/header.php';
include __DIR__ . '/resources/views/components/update-form.php';
include __DIR__ . '/resources/views/components/footer.php';