-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
52 lines (49 loc) · 1.17 KB
/
index.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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
@include('model/Contact.class.php');
$contact = new Contact;
if(isset($_GET['request'])){
$request = $_GET['request'];
}
else{
$request = '';
}
if($request == 'create'){
@include('view/form.php');
}
elseif($request == 'save'){
$contact->setFirstName($_POST['first_name']);
$contact->setSecondName($_POST['second_name']);
$contact->setCity($_POST['city']);
if($contact->isValid()){
$contact->save();
header('Location:/?mensage=Usuário cadastrado com sucesso!');
}
else{
echo "Inválido!";
}
}
elseif($request == 'edit'){
$contact = $contact->find($_GET['id']);
@include('view/edit.php');
}
elseif($request == 'update'){
$contact->setFirstName($_POST['first_name']);
$contact->setSecondName($_POST['second_name']);
$contact->setCity($_POST['city']);
if($contact->isValid()){
$contact->update($_POST['id']);
header('Location:/?mensage=Usuário cadastrado com sucesso!');
}
}
elseif($request == 'destroy'){
$contact = $contact->destroy($_GET['id']);
}
else{
if(isset($_GET['name']) && $_GET['name']){
$result = $contact->all($_GET['name']);
}
$result = $contact->all();
@include('view/list.php');
}