60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
header('Content-Type: text/html; charset='.CHARSET);
|
|
$search = (isset($_GET['search'])) ? strtolower($_GET['search']) : '';
|
|
if ($search == false) {
|
|
return;
|
|
}
|
|
|
|
list($searchStr, $filtre) = explode(',', $search);
|
|
$searchStr = trim($searchStr);
|
|
$filtre = str_replace(' ', '', $filtre);
|
|
if (strlen($filtre) != 5 && strlen($filtre) != 2) {
|
|
$filtre = '';
|
|
}
|
|
|
|
require_once 'scoresws/scoresws.php';
|
|
$tableResults =
|
|
scoresws_searchMandataires($searchStr,
|
|
array('V', 'N', 'H', 'A', 'M'),
|
|
$filtre);
|
|
if ($tableResults === false) {
|
|
print 'Erreur durant la recherche';
|
|
exit;
|
|
}
|
|
|
|
$output[] =
|
|
array('label' => "A l'adresse du bien vendu",
|
|
'id' => 'adresse');
|
|
|
|
/*
|
|
REGEX Code Postal : ^(F-)?((2[A|B])|[0-9]{2})[0-9]{3}$
|
|
(?<!/BP /i) Ne pas avoir la présence de BP devant les 5 chiffres
|
|
*/
|
|
// Recherche des codes postaux
|
|
if (count($tableResults) > 0) {
|
|
$i = 0;
|
|
foreach ($tableResults as $code => $lib) {
|
|
$tabResults[$i]['code'] = $code;
|
|
$tabResults[$i]['lib'] =
|
|
htmlspecialchars_decode(html_entity_decode($lib), ENT_QUOTES);
|
|
preg_match('/(?<!bp )((2[A|B])|[0-9]{2})[0-9]{3}( )/i', $lib, $matches);
|
|
$tabResults[$i]['cp'] = $matches[0];
|
|
$i++;
|
|
}
|
|
foreach ($tabResults as $key => $row) {
|
|
$code[$key] = $row['code'];
|
|
$lib[$key] = $row['lib'];
|
|
$cp[$key] = $row['cp'];
|
|
}
|
|
// Classement du tableau
|
|
array_multisort($cp, SORT_NUMERIC, $tabResults);
|
|
|
|
// Affichage des valeurs
|
|
foreach ($tabResults as $item) {
|
|
$output[] =
|
|
array('label' => $item['lib'],
|
|
'id' => $item['code']);
|
|
}
|
|
}
|
|
print json_encode($output);
|