47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
require_once('php/inc_functions.php');
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$db = $GLOBALS['db'] ?? null;
|
|
if (!$db) { http_response_code(500); echo json_encode([]); exit; }
|
|
|
|
$action = $_GET['action'] ?? '';
|
|
if ($action !== 'search_email') { echo json_encode([]); exit; }
|
|
|
|
$q = trim($_GET['q'] ?? '');
|
|
if ($q === '' || strlen($q) < 2) { echo json_encode([]); exit; }
|
|
|
|
$eve_id = isset($_GET['eve_id']) ? (int)$_GET['eve_id'] : 0; // << param évènement
|
|
|
|
$like = $db->fxEscape($q);
|
|
|
|
// Filtre de base (recherche e-mail)
|
|
$where = "com_courriel LIKE '%$like%'";
|
|
|
|
// Si on connaît l'événement, exclure les comptes qui l'ont déjà dans la liste
|
|
if ($eve_id > 0) {
|
|
// Pas d'espaces dans tes listes, donc FIND_IN_SET direct
|
|
$where .= " AND (com_eve_promoteur IS NULL OR com_eve_promoteur = '' OR FIND_IN_SET($eve_id, com_eve_promoteur) = 0)";
|
|
}
|
|
|
|
$sql = "
|
|
SELECT com_id, com_courriel
|
|
FROM inscriptions_comptes
|
|
WHERE $where
|
|
ORDER BY com_courriel ASC
|
|
LIMIT 15
|
|
";
|
|
$res = $db->fxQuery($sql);
|
|
echosl($sql);
|
|
$out = [];
|
|
if ($res) {
|
|
while ($r = mysqli_fetch_assoc($res)) {
|
|
$out[] = [
|
|
'id' => (int)$r['com_id'],
|
|
'email' => $r['com_courriel'],
|
|
];
|
|
}
|
|
}
|
|
|
|
echo json_encode($out, JSON_UNESCAPED_UNICODE);
|