-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.php
171 lines (166 loc) · 5.5 KB
/
router.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
<?php
include_once('app/controllers/pet.controller.php');
include_once('app/controllers/menu.controller.php');
include_once('app/controllers/user.controller.php');
include_once('app/controllers/city.controller.php');
include_once('app/controllers/animaltype.controller.php');
// defino la base url para la construccion de links con urls semánticas
define('BASE_URL', '//'.$_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . dirname($_SERVER['PHP_SELF']).'/');
// lee la acción
if (!empty($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = 'home'; // acción por defecto si no envían
}
// parsea la accion Ej: suma/1/2 --> ['suma', 1, 2]
$params = explode('/', $action);
// determina que camino seguir según la acción
switch ($params[0]) {
case 'login':
$controller = new UserController();
$controller->showLogin();
break;
case 'signup':
$controller = new UserController();
$controller->showSignup();
break;
case 'adduser':
$controller = new UserController();
$controller->adduser();
break;
case 'verify':
$controller = new UserController();
$controller->logIn();
break;
case 'logout':
$controller = new UserController();
$controller->logOut();
break;
case 'home':
$controller = new PetController();
$amount = isset($params[1]) ? $params[1] : 0;
$controller->showHome($amount);
break;
case 'admin':
$controller = new PetController();
$amount = isset($params[1]) ? $params[1] : 0;
$controller->showAdmin($amount);
break;
case 'mis-mascotas':
$controller = new PetController();
$controller->showMyPets();
break;
case 'categorias':
$controller = new PetController();
$controller->showCategories();
break;
case 'sobre-nosotros':
$controller = new MenuController();
$controller->showAbout();
break;
case 'filtrar':
$controller = new PetController();
$amount = isset($params[1]) ? $params[1] : 0;
$controller->showByFilter($amount);
break;
case 'ver':
$controller = new PetController();
$id = $params[1];
$controller->show($id);
break;
case 'agregar':
$controller = new PetController();
$controller->showAddPetForm();
break;
case 'insertar-mascota':
$controller = new PetController();
$controller->add();
break;
case 'editar':
$controller = new PetController();
$id = $params[1];
$controller->edit($id);
break;
case 'actualizar-mascota':
$controller = new PetController();
$id = isset($params[1]) ? $params[1] : null;
$controller->update($id);
break;
case 'eliminar':
$controller = new PetController();
$id = isset($params[1]) ? $params[1] : null;
$controller->delete($id);
break;
case 'encontrar':
$controller = new PetController();
$id = isset($params[1]) ? $params[1] : null;
$controller->setFound($id);
break;
case 'agregar-ciudad':
$controller = new CityController();
$controller->showAddNewCity();
break;
case 'insertar-ciudad':
$controller = new CityController();
$controller->add();
break;
case 'editar-ciudad':
$controller = new CityController();
$id = isset($params[1]) ? $params[1] : null;
$controller->edit($id);
break;
case 'actualizar-ciudad':
$controller = new CityController();
$id = isset($params[1]) ? $params[1] : null;
$controller->update($id);
break;
case 'eliminar-ciudad':
$controller = new CityController();
$id = isset($params[1]) ? $params[1] : null;
$controller->delete($id);
break;
case 'agregar-tipo-de-animal':
$controller = new AnimalTypeController();
$controller->showAddNewAnimalType();
break;
case 'insertar-tipo-de-animal':
$controller = new AnimalTypeController();
$controller->add();
break;
case 'editar-tipo-de-animal':
$controller = new AnimalTypeController();
$id = isset($params[1]) ? $params[1] : null;
$controller->edit($id);
break;
case 'actualizar-tipo-de-animal':
$controller = new AnimalTypeController();
$id = isset($params[1]) ? $params[1] : null;
$controller->update($id);
break;
case 'eliminar-tipo-de-animal':
$controller = new AnimalTypeController();
$id = isset($params[1]) ? $params[1] : null;
$controller->delete($id);
break;
case 'usuarios':
$controller = new UserController();
$controller->showAll();
break;
case 'modificar-permiso-usuario':
//La url debe estar formada así: 'modificar-permiso-usuario/[userId]/[permiso]'
$userId = isset($params[1]) ? $params[1] : null;
$permissionId = isset($params[2]) ? $params[2] : null;
$controller = new UserController();
$controller->updateUserPermissions($userId,$permissionId);
break;
case 'eliminar-usuario':
$userId = isset($params[1]) ? $params[1] : null;
$controller = new UserController();
$controller->deleteUser($userId);
break;
default:
header("HTTP/1.0 404 Not Found");
$controller = new MenuController();
$controller->showNotFound();
break;
}