🖥️ Server: LiteSpeed
💻 System: Linux in-mum-web1643.main-hosting.eu 5.14.0-611.42.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 24 05:30:20 EDT 2026 x86_64
👤 User: u621169360 (621169360)
🐘 PHP: 8.2.30
🚫 Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
📄 fetch_trainings.php
📁 Path: /home/u621169360/domains/agriexpertt.com/public_html/mobile/Flutter/fetch_trainings.php
📊 Size: 3.21 KB
🔒 Perm: 0644
📝 MIME: text/x-php
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
require_once 'db.php';
$response = [
'success' => false,
'message' => 'Invalid request'
];
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
try {
// Optional filters
$status = $_GET['status'] ?? 'upcoming';
$limit = intval($_GET['limit'] ?? 10);
$offset = intval($_GET['offset'] ?? 0);
// Prepare SQL query
$query = "SELECT
id,
title,
date,
time,
location,
description,
fees,
trainer_name,
training_type,
difficulty_level,
category,
training_image,
max_participants
FROM trainings
WHERE status = :status
ORDER BY date ASC
LIMIT :limit OFFSET :offset";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':status', $status, PDO::PARAM_STR);
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();
$trainings = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Count total trainings for this status
$count_query = "SELECT COUNT(*) FROM trainings WHERE status = :status";
$count_stmt = $pdo->prepare($count_query);
$count_stmt->bindParam(':status', $status, PDO::PARAM_STR);
$count_stmt->execute();
$total_trainings = $count_stmt->fetchColumn();
// Prepare response
$response = [
'success' => true,
'message' => 'Trainings retrieved successfully',
'total_trainings' => intval($total_trainings),
'trainings' => array_map(function($training) {
return [
'id' => $training['id'],
'title' => $training['title'],
'date' => date('Y-m-d', strtotime($training['date'])),
'time' => date('H:i', strtotime($training['time'])),
'location' => $training['location'],
'description' => $training['description'],
'fees' => floatval($training['fees']),
'trainer_name' => $training['trainer_name'] ?? 'TBD',
'training_type' => $training['training_type'],
'difficulty_level' => $training['difficulty_level'],
'category' => $training['category'],
'training_image' => $training['training_image'] ?? null,
'max_participants' => intval($training['max_participants'])
];
}, $trainings)
];
} catch (PDOException $e) {
$response = [
'success' => false,
'message' => 'Database error: ' . $e->getMessage()
];
} catch (Exception $e) {
$response = [
'success' => false,
'message' => $e->getMessage()
];
}
}
// Send JSON response
echo json_encode($response);
exit();
?> ✨ File Manager Magic ✨