57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
require_once('php/inc_functions.php');
|
|
|
|
// récupérer les données envoyées
|
|
$strTerm = trim($_GET['term']);
|
|
$strTable = trim($_GET['t']);
|
|
$strField = trim($_GET['f']);
|
|
|
|
$strTerm = preg_replace('/\s+/', ' ', $strTerm);
|
|
$tabParts = explode(' ', $strTerm);
|
|
|
|
$sqlAutocomplete = "SELECT lab_list, lab_autocomplete_where, lab_autocomplete_search FROM adm_labels WHERE lab_table = '" . $GLOBALS['db']->fxEscape($strTable) . "' AND lab_code = '" . $GLOBALS['db']->fxEscape($strField) . "'";
|
|
$tabAutocomplete = $GLOBALS['db']->fxGetRow($sqlAutocomplete);
|
|
|
|
$sqlSearch = $tabAutocomplete['lab_list'];
|
|
|
|
if ($tabAutocomplete['lab_autocomplete_where'] != '')
|
|
$sqlSearch .= " WHERE " . $tabAutocomplete['lab_autocomplete_where'];
|
|
else
|
|
$sqlSearch .= " WHERE 1 = 1";
|
|
|
|
$tabSearchFields = explode(',', $tabAutocomplete['lab_autocomplete_search']);
|
|
$intNbFields = count($tabSearchFields);
|
|
|
|
foreach ($tabParts as $strSearch) {
|
|
if ($intNbFields > 1) {
|
|
for ($intCtr = 0; $intCtr < $intNbFields; $intCtr++) {
|
|
if ($intCtr === 0)
|
|
$sqlSearch .= " AND (";
|
|
|
|
$sqlSearch .= $strField . " LIKE " . "'%" . $GLOBALS['db']->fxEscape($strSearch) . "%'";
|
|
|
|
if (($intCtr + 1) < $intNbFields)
|
|
$sqlSearch .= " OR ";
|
|
else
|
|
$sqlSearch .= ")";
|
|
}
|
|
}
|
|
else
|
|
$sqlSearch .= " AND " . $tabSearchFields[0] . " LIKE " . "'%" . $GLOBALS['db']->fxEscape($strSearch) . "%'";
|
|
}
|
|
|
|
$tabSearch = $GLOBALS['db']->fxGetResults($sqlSearch);
|
|
|
|
if ($tabSearch === false) {
|
|
$user_error = 'Wrong SQL: ' . $sqlSearch;
|
|
trigger_error($user_error, E_USER_ERROR);
|
|
}
|
|
$tabJson = array();
|
|
|
|
for ($intCtr = 1; $intCtr <= count($tabSearch); $intCtr++) {
|
|
$tabJson[] = array('id' => fxUnescape($tabSearch[$intCtr]['id']), 'label' => fxUnescape($tabSearch[$intCtr]['label']), 'value' => fxUnescape($tabSearch[$intCtr]['value']));
|
|
}
|
|
|
|
$strJson = json_encode($tabJson);
|
|
print $strJson;
|
|
?>
|