50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
session_start();
|
|
require '../../../assets/utils/db_auth.php';
|
|
|
|
try {
|
|
|
|
$keyword = trim($data['keyword'] ?? '');
|
|
|
|
if ($keyword === '') {
|
|
$answer['success'] = 1;
|
|
$answer['result'] = [];
|
|
exit(json_encode($answer));
|
|
}
|
|
|
|
$like = '%' . $keyword . '%';
|
|
|
|
// Search users by email NOT already active/pending in this company
|
|
$sth = $pdo1->prepare("
|
|
SELECT
|
|
u.user_id,
|
|
u.username,
|
|
u.name,
|
|
u.surname,
|
|
u.email
|
|
FROM user u
|
|
WHERE
|
|
u.email LIKE :kw
|
|
AND u.user_id NOT IN (
|
|
SELECT user_id FROM company_map_user
|
|
WHERE company_id = :company_id
|
|
)
|
|
ORDER BY u.email ASC
|
|
LIMIT 10
|
|
");
|
|
$sth->execute([
|
|
':kw' => $like,
|
|
':company_id' => $company_id,
|
|
]);
|
|
db_check($sth, $answer);
|
|
|
|
$answer['success'] = 1;
|
|
$answer['result'] = $sth->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
} catch (Exception $e) {
|
|
$answer['message'] = 'Search failed.';
|
|
http_response_code(500);
|
|
}
|
|
|
|
exit(json_encode($answer));
|
|
?>
|