35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
|
|
include("../elements/functions.php");
|
|
|
|
// ----------------------------API CALL--------------------//
|
|
$jsonFilePath = __DIR__ . '/../urls/api_endpoints.json';
|
|
$jsonData = file_get_contents($jsonFilePath);
|
|
$endpoints = json_decode($jsonData, true);
|
|
$url = $endpoints["access_duration"];
|
|
// ----------------------- ENDS HERE-------------------------//
|
|
|
|
if (!isset($_SESSION['token'])) {
|
|
include('token_exp.php');
|
|
}
|
|
|
|
$token = $_SESSION['token'];
|
|
$result = make_get_request($url, ["Authorization: $token"]);
|
|
$response = json_decode($result, true);
|
|
$_SESSION["response"] = $response;
|
|
|
|
|
|
if (isset($response['items']) && is_array($response['items'])) {
|
|
$user_list = array_map(function($user) {
|
|
$access_duration = $user['access_duration'] ?? '-';
|
|
// Separate digits and text part
|
|
preg_match('/(\d+)(\D+)/', $access_duration, $matches);
|
|
return [
|
|
"duration_value" => $matches[1] ?? '', // Numeric part (e.g., '1')
|
|
"duration_unit" => $matches[2] ?? '' // Text part (e.g., 'h', 'd')
|
|
];
|
|
}, $response['items']);
|
|
}
|
|
?>
|