-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkasKeluar.php
48 lines (38 loc) · 1.83 KB
/
kasKeluar.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
<?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);
$rincian = trim($data->rincian);
$tangal = trim($data->tangal);
$total = trim($data->total);
$sql = "UPDATE `kaskeluar` SET `rincian` = '$rincian', `tangal` = '$tangal', `total` = '$total' WHERE `kas`.`id` = '$id'";
$query = mysqli_query($conn, $sql);
if ($query) jsonHandler(200, 'kas kelas berhasil diupdate');
jsonHandler(500, 'Terjadi kesalahan.');
endif;
jsonHandler(403, "Authorization Token salah!");
endif;
jsonHandler(405, 'HTTP method untuk request harus PUT');