75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
// Start output buffering to capture any unintended output
|
|
ob_start();
|
|
|
|
// Enable error reporting for debugging (remove in production)
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
// Include the headscript file (ensure it doesn't output anything)
|
|
require_once('include/headscript.php');
|
|
|
|
// Establish database connection
|
|
$conn = mysqli_connect($servername, $username, $password, $dbname);
|
|
if (!$conn) {
|
|
ob_end_clean();
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['error' => 'Connessione al database fallita']);
|
|
exit;
|
|
}
|
|
|
|
// Check if id_utente is provided
|
|
if (isset($_POST['id_utente'])) {
|
|
$id_utente = intval($_POST['id_utente']);
|
|
|
|
// Query to fetch class details with necessary fields
|
|
$sql = "
|
|
SELECT
|
|
bc.idbookingclass,
|
|
bc.bookingstart,
|
|
bc.status,
|
|
bc.lostlesson,
|
|
bc.prevbookingstart,
|
|
bc.idorder,
|
|
ob.order_date_created,
|
|
s.servicename,
|
|
s.day,
|
|
s.time
|
|
FROM bookingclass bc
|
|
LEFT JOIN orderbook ob ON bc.idorder = ob.idorderbook
|
|
LEFT JOIN service s ON bc.idservice = s.idservice
|
|
WHERE bc.iduser = $id_utente
|
|
ORDER BY bc.bookingstart DESC
|
|
";
|
|
|
|
$result = mysqli_query($conn, $sql);
|
|
if (!$result) {
|
|
ob_end_clean();
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['error' => 'Errore nella query: ' . mysqli_error($conn)]);
|
|
exit;
|
|
}
|
|
|
|
$classes = [];
|
|
|
|
// Fetch all rows and store in an array
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$classes[] = $row;
|
|
}
|
|
|
|
// Clear the output buffer, set the header, and output JSON
|
|
ob_end_clean();
|
|
header('Content-Type: application/json');
|
|
echo json_encode($classes);
|
|
mysqli_close($conn);
|
|
exit;
|
|
}
|
|
|
|
// If id_utente is not provided, return an error
|
|
ob_end_clean();
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['error' => 'ID utente non fornito']);
|
|
mysqli_close($conn);
|
|
exit;
|
|
?>
|