Joywork/ajax/getPrzClients.php
2026-05-22 21:21:54 +03:00

121 lines
4.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/config_ajax.php");
if(isset($_POST['prz_user'])){
$post = clearInputData($_POST);
$users = [(int)$_POST['prz_user']];
$managers = [(int)$_POST['prz_agency']];
$bd_usl = '';
$bd_user = " who_work in (". implode(',', $users) .")";
$bd_managers_j = '';
if(!empty($post['filter_prz_responsible'])){
$users = [];
$managers = [];
$filter_prz_responsible = array_unique(explode(',', $post['filter_prz_responsible']));
foreach ($filter_prz_responsible as $val) {
if (strripos($val, 'u')){
$users[] = preg_replace('/[^0-9]/', '', $val);
}
if (strripos($val, 'm')){
$managers[] = preg_replace('/[^0-9]/', '', $val);
}
}
if($managers){
$bd_managers_j = " AND id_agent in (SELECT id FROM `users` WHERE id in (". implode(',', $managers) .") or
id_manager in (". implode(',', $managers) .") or
id_manager in (select id from users where id_manager in (". implode(',', $managers) .")))";
$bd_managers = " in (". implode(',', $managers) .")";
}
if($users){
$bd_user_j = " who_work in (". implode(',', $users) .") or
id_agent in (SELECT id FROM `users` WHERE id in (". implode(',', $users) .") or
id_manager in (". implode(',', $users) .") or
id_manager in (select id from users where id_manager in (". implode(',', $users) .")))";
}
} else {
$bd_user_j = " who_work in (". implode(',', $users) .") ";
}
if($post['filter_prz_type']){
$typesArr = json_decode(html_entity_decode($post['filter_prz_type']), ENT_QUOTES);
$typeArr = array();
foreach($typesArr as $typeCl){
$typeArr[] = "work_type like '%&quot;{$typeCl}&quot;%'";
}
$bd_usl .= " AND (".implode(" OR ",$typeArr).")";
}
if($post['filter_prz_source']){
$sourcesArr = json_decode(html_entity_decode($post['filter_prz_source']), ENT_QUOTES);
$sourceArr = array();
foreach($sourcesArr as $sourceCl){
if($sourceCl == 0){
$sourceArr[] = "`source` is null";
$sourceArr[] = "`source` = ''";
$sourceArr[] = "`source` = 'null'";
} else {
$sourceArr[] = "`source` = '{$sourceCl}'";
}
}
$bd_usl .= " AND (".implode(" OR ",$sourceArr).")";
}
if ($post['filter_prz_activities']) {
$activitiesArr = json_decode(html_entity_decode($post['filter_prz_activities']), ENT_QUOTES);
$bd_usl .= " AND `id` IN (
SELECT client_id FROM clients_activities
WHERE activity_id IN (" . implode(", ", $activitiesArr) . ")
)";
}
if($post['filter_prz_rol']){
$rolesArr = json_decode(html_entity_decode($post['filter_prz_rol']), ENT_QUOTES);
$roleArr = array();
foreach($rolesArr as $roleCl){
$roleArr[] = "`role` like '%&quot;{$roleCl}&quot;%'";
}
$bd_usl .= " AND (".implode(" OR ",$roleArr).")";
}
if (in_array(6358, $managers) || in_array(93, $managers)) {
$sql = "SELECT `id`, `email`, `fio`, `phone`, DATE_FORMAT(date_add, '%d.%m.%Y') AS date_add
FROM clients WHERE (($bd_user AND confirm > 0) or (who_work=0 AND id_agent in
(SELECT id FROM `users` WHERE id $bd_managers or id_manager $bd_managers or id_manager in (select id from users where id_manager $bd_managers)))) $bd_usl AND deleted<>1 ORDER BY clients.id DESC";
} else {
$sql = "SELECT `id`, `email`, `fio`, `phone`, DATE_FORMAT(date_add, '%d.%m.%Y') AS date_add
FROM clients WHERE $bd_user_j $bd_usl AND confirm > 0 AND deleted<>1 ORDER BY clients.id DESC";
}
//echo $sql;
$rez = mysql_query($sql);
if ($_POST['type'] == 1) {
$komy_list = "";
while($cl = mysql_fetch_assoc($rez))
{
if(!empty($cl['email'])){
if ($komy_list != "") {
$komy_list .= "[<%;%>]";
}
$komy_list .= $cl['id'];
}
}
echo $komy_list;
exit;
} else {
while($cl = mysql_fetch_assoc($rez))
{
//if(!empty($cl['email'])){
// Маскируем контактные данные клиента, если у пользователя включено скрытие
mask_client_contacts_inplace($cl);
?>
<option data-id="<?=$cl['id']?>" value="<?=$cl['id']?>"><?=$cl['fio']?> (<?=$cl['email']?> <?=$cl['phone']?>)</option>
<?php
//}
}
}
}