-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
164 lines (140 loc) · 4.67 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
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
// session_start();
// Autoload -->
spl_autoload_register(function ($class) {
require_once 'classes/' . $class . '.php';
});
$count = Count::getInstance();
// User management -->
// if (isset($_POST['username'])) {
// $_SESSION['username'] = $_POST['username'];
// $_SESSION['id'] = getUserId($_SESSION['username']);
// $_SESSION['role'] = getRole($_SESSION['id']);
// }
$request_uri = explode('?', $_SERVER['REQUEST_URI'], 2);
// Functions::dd($request_uri);
// Routes -->
switch ($request_uri[0]) {
// Views -->
// Home page
case '/':
$currentPageTitle = "Page d'accueil";
require_once 'public/layouts/header.php';
require_once 'public/views/home.php';
require_once 'public/layouts/footer.php';
break;
case '/profile':
$currentPageTitle = "Votre profil";
require_once 'public/layouts/header.php';
require_once 'public/views/profile.php';
require_once 'public/layouts/footer.php';
break;
case '/admin':
$currentPageTitle = "Panel d'administration";
require_once 'public/layouts/header.php';
require_once 'public/views/admin.php';
require_once 'public/layouts/footer.php';
break;
case '/login':
$currentPageTitle = "Se connecter";
require_once 'public/layouts/header.php';
require_once 'public/views/login.php';
require_once 'public/layouts/footer.php';
break;
// Farmers page
case '/displayFarmers':
$currentPageTitle = "Liste des producteurs";
require_once 'public/layouts/header.php';
require_once 'public/views/farmers/displayFarmers.php';
require_once 'public/layouts/footer.php';
break;
// Products page
case '/displayProducts':
$currentPageTitle = "Liste des produits";
require_once 'public/layouts/header.php';
require_once 'public/views/products/displayProducts.php';
require_once 'public/layouts/footer.php';
break;
// One Farmer's Products page
case '/displayProductsByFarmer':
$farmer_id = $request_uri[1];
$products = Product::getProductsByFarmer($farmer_id);
$farmer = Farmer::getOneFarmer($farmer_id);
$farmer_name = $farmer->name;
$currentPageTitle = "Liste des produits de $farmer->name";
require_once 'public/layouts/header.php';
require_once 'public/views/products/displayProductsByFarmer.php';
require_once 'public/layouts/footer.php';
break;
// addFarmer page
case '/addFarmer':
$currentPageTitle = "Ajouter un producteur";
require_once 'public/layouts/header.php';
require_once 'public/views/farmers/addFarmer.php';
require_once 'public/layouts/footer.php';
break;
// editFarmer page
case '/editFarmer':
$currentPageTitle = "Modifier le producteur";
$farmer_id = $request_uri[1];
require_once 'public/layouts/header.php';
require_once 'public/views/farmers/editFarmer.php';
require_once 'public/layouts/footer.php';
break;
// addProduct page
case '/addProduct':
$currentPageTitle = "Ajouter un produit";
require_once 'public/layouts/header.php';
require_once 'public/views/products/addProduct.php';
require_once 'public/layouts/footer.php';
break;
// editProduct page
case '/editProduct':
$currentPageTitle = "Modifier le produit";
$product_id = $request_uri[1];
require_once 'public/layouts/header.php';
require_once 'public/views/products/editProduct.php';
require_once 'public/layouts/footer.php';
break;
// Actions -->
// addFarmer Action
case '/createFarmer':
require 'controllers/farmers/addFarmerAction.php';
header('Location: /admin#section');
break;
// editFarmer Action
case '/updateFarmer':
$farmer_id = $request_uri[1];
require 'controllers/farmers/editFarmerAction.php';
header('Location: /admin#section');
break;
// removeFarmer Action
case '/deleteFarmer':
require 'controllers/farmers/removeFarmerAction.php';
header('Location: /admin#section');
break;
// addProduct Action
case '/createProduct':
require 'controllers/products/addProductAction.php';
header('Location: /admin#section');
break;
// editProduct Action
case '/updateProduct':
$product_id = $request_uri[1];
require 'controllers/products/editProductAction.php';
header('Location: /admin#section');
break;
// removeProduct Action
case '/deleteProduct':
// require 'controllers/removeProductAction.php';
Product::deleteProduct($request_uri[1]);
header('Location: /admin#section');
break;
// Everything else
default:
$currentPageTitle = "Error 404";
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
require_once 'public/layouts/header.php';
require_once 'public/layouts/footer.php';
break;
}