-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmediatekdocuments.php
More file actions
38 lines (33 loc) · 1.5 KB
/
mediatekdocuments.php
File metadata and controls
38 lines (33 loc) · 1.5 KB
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
<?php
header('Content-Type: application/json');
include_once("Controle.php");
$controle = new Controle();
// Contrôle de l'authentification
if(!isset($_SERVER['PHP_AUTH_USER']) || (isset($_SERVER['PHP_AUTH_USER']) &&
!(($_SERVER['PHP_AUTH_USER']=='admin' && ($_SERVER['PHP_AUTH_PW']=='adminpwd'))))){
$controle->unauthorized();
}else{
// récupération des données
// Nom de la table au format string
$table = filter_input(INPUT_GET, 'table', FILTER_SANITIZE_STRING) ??
filter_input(INPUT_POST, 'table', FILTER_SANITIZE_STRING);
// id de l'enregistrement au format string
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_STRING) ??
filter_input(INPUT_POST, 'id', FILTER_SANITIZE_STRING);
// nom et valeur des champs au format json
$contenu = filter_input(INPUT_GET, 'contenu', FILTER_SANITIZE_STRING,FILTER_FLAG_NO_ENCODE_QUOTES) ??
filter_input(INPUT_POST, 'contenu', FILTER_SANITIZE_STRING,FILTER_FLAG_NO_ENCODE_QUOTES);
if($contenu != ""){
$contenu = json_decode($contenu, true);
}
// traitement suivant le verbe HTTP utilisé
if($_SERVER['REQUEST_METHOD'] === 'GET'){
$controle->get($table, $id);
}else if($_SERVER['REQUEST_METHOD'] === 'POST'){
$controle->post($table, $contenu);
}else if($_SERVER['REQUEST_METHOD'] === 'PUT'){
$controle->put($table, $id, $contenu);
}else if($_SERVER['REQUEST_METHOD'] === 'DELETE'){
$controle->delete($table, $contenu);
}
}