function getConstraintForLevel($level)
{
    if ($level == "Lycées" || $level == "Lycée" || $level == "Lycee") {
        return getConstraintLycees();
    } else {
        if ($level == "Collèges" || $level == "Collège" || $level == "College") {
            return getConstraintColleges();
        } else {
            return getConstraintCollegesLycees();
        }
    }
}
function getNearbySchools($academyID, $schoolType, $X, $Y)
{
    // TODO: on pourrait ajouter une limite à la query, mais ça ne semble pas utile.
    if ($schoolType == "Lycée") {
        $filterType = getConstraintLycees();
    } else {
        if ($schoolType == "Collège") {
            $filterType = getConstraintColleges();
        } else {
            $filterType = getConstraintCollegesLycees();
        }
    }
    $query = "SELECT \n     `recommend_listedschool`.appellation_officielle_uai as name,\n     SUBSTRING_INDEX(`recommend_listedschool`.localite_acheminement_uai, 'CEDEX', 1) as city,\n     SQRT(POW(:X - `recommend_listedschool`.X, 2) + POW(:Y - `recommend_listedschool`.Y, 2)) as distance\n     FROM `recommend_listedschool` \n     WHERE {$filterType} \n     AND academyID = :academyID\n     AND (patronyme_uai NOT LIKE '' OR appellation_officielle_uai NOT LIKE 'Collège')\n     AND (appellation_officielle_uai NOT LIKE '%privé%' COLLATE utf8_general_ci)\n     AND \n          NOT EXISTS (SELECT * FROM `recommend_school_listedschool` \n           JOIN `school_year` \n           ON `school_year`.schoolID = `recommend_school_listedschool`.schoolID \n           AND `school_year`.year >= 2013\n           WHERE `recommend_school_listedschool`.listedschoolID = `recommend_listedschool`.ID)\n     ORDER BY SQRT(POW(:X - `recommend_listedschool`.X, 2) + POW(:Y - `recommend_listedschool`.Y, 2)) ";
    // LIMIT 10
    $stmt = getDb()->prepare($query);
    // $stmt->debugDumpParams();
    $stmt->execute(array(':academyID' => $academyID, ':X' => $X, ':Y' => $Y));
    reportErrors($stmt);
    $results = $stmt->fetchAll(PDO::FETCH_OBJ);
    if ($results === FALSE) {
        $results = array();
    }
    return $results;
    // array of {name,city,distance} objects, ordered by distance.
}