-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateJadwal.php
49 lines (41 loc) · 2.07 KB
/
updateJadwal.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
<?php
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: access');
header('Access-Control-Allow-Methods: PUT');
header('Content-Type: application/json');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
header('HTTP/1.1 200 OK');
die();
}
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: access');
header('Access-Control-Allow-Methods: PUT');
header('Content-Type: application/json');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
require_once __DIR__ . '/src/dbConnect.php';
require_once __DIR__ . '/src/jwtHandler.php';
require_once __DIR__ . '/src/jsonHandler.php';
if ($_SERVER['REQUEST_METHOD'] == 'PUT') :
$data = json_decode(file_get_contents('php://input'));
$headers = getallheaders();
if (array_key_exists('Authorization', $headers) && preg_match('/Bearer\s(\S+)/', $headers['Authorization'], $matches)) :
$datajwt = decodeToken($matches[1]);
$userId = (int) $datajwt;
if (!is_numeric($datajwt)) jsonHandler(401, 'User tidak valid!');
$id = trim($data->id);
$hari = trim($data->hari);
$matkul = trim($data->matkul);
$dosen = mysqli_real_escape_string($conn, htmlspecialchars(trim($data->dosen)));
$ruang = trim($data->ruang);
$jam = mysqli_real_escape_string($conn, htmlspecialchars(trim($data->jam)));
$semester = trim($data->semester);
$sql = "UPDATE `schedule` SET `hari` = '$hari', `matkul` = '$matkul', `dosen` = '$dosen', `ruang` = '$ruang', `jam` = '$jam', `semester` = '$semester' WHERE `schedule`.`id` = '$id'";
$query = mysqli_query($conn, $sql);
if ($query) jsonHandler(200, 'Mata kuliah berhasil diupdate');
jsonHandler(500, 'Terjadi kesalahan.');
endif;
jsonHandler(403, "Authorization Token salah!");
endif;
jsonHandler(405, 'HTTP method untuk request harus PUT');