| Server IP : 158.247.231.215 / Your IP : 216.73.217.84 Web Server : Apache/2.4.41 (Ubuntu) System : Linux CTMS 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /mnt/blockstorage/ctms/api/custom-api/ |
Upload File : |
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, OPTIONS');
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Authorization");
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}
// Load WordPress and auth helper
require_once('/mnt/blockstorage/ctms/wp-load.php');
require_once('auth-helper.php');
include('../database.php');
// Verify JWT token
$user_id = verify_jwt_token();
if (!$user_id) {
send_error_response('User not authenticated', 401);
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
try {
$user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
if ($user_id <= 0) {
throw new Exception('user_id is required');
}
// Get all requests for this user
$sql = "SELECT
r.id,
r.content_id,
r.version_id,
r.device_type,
r.status,
r.is_downloaded,
r.created_at,
r.approved_at,
r.downloaded_at,
c.title as content_title,
v.version_number
FROM vr_download_requests r
INNER JOIN vr_contents c ON r.content_id = c.id
INNER JOIN vr_content_versions v ON r.version_id = v.id
WHERE r.user_id = $user_id
ORDER BY r.created_at DESC";
$result = $conn->query($sql);
$requests = array();
while ($row = $result->fetch_assoc()) {
$can_download = ($row['status'] === 'approved' && $row['is_downloaded'] == 0);
$requests[] = array(
'id' => intval($row['id']),
'content_id' => intval($row['content_id']),
'content_title' => $row['content_title'],
'version_id' => intval($row['version_id']),
'version_number' => $row['version_number'],
'device_type' => $row['device_type'],
'status' => $row['status'],
'is_downloaded' => (bool)$row['is_downloaded'],
'can_download' => $can_download,
'created_at' => $row['created_at'],
'approved_at' => $row['approved_at'],
'downloaded_at' => $row['downloaded_at']
);
}
$response = array(
'status' => 'success',
'data' => array(
'user_id' => $user_id,
'requests' => $requests,
'total' => count($requests)
)
);
echo json_encode($response);
} catch (Exception $e) {
$response = array(
'status' => 'error',
'message' => $e->getMessage()
);
http_response_code(400);
echo json_encode($response);
}
$conn->close();
} else {
$response = array(
'status' => 'error',
'message' => 'Only GET requests are allowed'
);
http_response_code(405);
echo json_encode($response);
}
?>