<?php
include('include/headscript.php');
$conn = new mysqli($servername, $username, $password, $database);

$idphoto = $_GET['idphoto'];
$idyogaschool = $_GET['idyogaschool'];

if (isset($idphoto) && isset($idyogaschool)) {
    // Imposta tutte le altre foto a priority '0'
    $conn->query("UPDATE photoyogaschool SET priority = '0' WHERE idyogaschool = $idyogaschool");

    // Imposta la foto selezionata a priority '1'
    $query = $conn->prepare("UPDATE photoyogaschool SET priority = '1' WHERE idphotoyogaschool = ?");
    $query->bind_param("i", $idphoto);
    if ($query->execute()) {
        echo json_encode(['success' => true, 'message' => 'Cover image impostata con successo']);
    } else {
        echo json_encode(['success' => false, 'message' => 'Errore durante l\'impostazione della cover image']);
    }
} else {
    echo json_encode(['success' => false, 'message' => 'Parametri non validi']);
}
