get($_SESSION['id']); if($user->agency == 0 && $user->manager == 0 && $user->id_manager == 0) { $user->agency = 1; } $autosearch_instce = null; if ($user->can('autosearch')) { $autosearch_instce = new AutoSearch(); } $usersIds = array(); $usersIds[] = $agencyId; $sql_users = "SELECT id FROM users WHERE id in (select id from users where id=$agencyId or id_manager=$agencyId or id_manager in (select id from users where id_manager=$agencyId or id_manager in (select id from users where id_manager=$agencyId)))"; $q_users = mysql_query($sql_users); while($r_users = mysql_fetch_assoc($q_users)){ $usersIds[] = (int)$r_users['id']; } $sqlClient = "select id, phone, email, objects, summa, budget from clients where id = $clientId and (id_agent in (".implode(',', $usersIds).") or who_work in (".implode(',', $usersIds)."))"; $clientRes = mysql_query($sqlClient); if (mysql_num_rows($clientRes) > 0) { $client = mysql_fetch_assoc($clientRes); mask_client_contacts_inplace($client); // Инфо-кнопка по автопоиску для клиента, который проходит по заявке подбор объекта $autosearch = []; if (!is_null($autosearch_instce)) { $filter = $autosearch_instce->getFilterByClient($client['id'], $_SESSION['id']); if (isset($filter['id'])) { $autosearch = [ 'id' => $filter['id'], 'active' => isset($filter['is_active']) ? $filter['is_active'] : 0, 'total' => isset($filter['total']) ? $filter['total'] : 0, 'count' => isset($filter['count']) ? $filter['count'] : 0, 'error' => isset($filter['error']) ? $filter['error'] : null ]; } } $phone = $client['phone']; // Не форматируем уже замаскированный номер ("+7 *** *** ** **") — иначе маска покрошится substr-ом. if (strpos($phone, '+7') !== false && strpos($phone, '*') === false) { $phone = substr($phone, 0, 2) . "(" . substr($phone, 2, 3) . ")" . substr($phone, 5, 3) . "-" . substr($phone, 8, 2) . "-" . substr($phone, 10, 2); } $client_objects = json_decode(html_entity_decode($client['objects']), true); $eventsLess = []; $eventsEq = []; $eventsMore = []; $eventsSql = "SELECT count(id) as res, client_id FROM user_client_events WHERE calendar_view = 0 and cancel=0 and schedule_date is not null and client_id = $clientId and schedule_date < '" . date("Y-m-d H:i:s") . "' GROUP BY client_id"; $qEvents = mysql_query($eventsSql); if(mysql_num_rows($qEvents) > 0){ while ($objEvent = mysql_fetch_assoc($qEvents)) { $events_res = (int)$objEvent["res"]; } } $events1Sql = "SELECT count(id) as res, client_id FROM user_client_events WHERE calendar_view = 0 and cancel=0 and schedule_date is not null and client_id = $clientId and DATE_FORMAT(schedule_date, '%Y-%m-%d') = '" . date("Y-m-d") . "' GROUP BY client_id"; $qEvents1 = mysql_query($events1Sql); if(mysql_num_rows($qEvents1) > 0){ while ($objEvent1 = mysql_fetch_assoc($qEvents1)) { $events_res1 = (int)$objEvent1["res"]; } } $events2Sql = "SELECT count(id) as res, client_id FROM user_client_events WHERE calendar_view = 0 and cancel=0 and schedule_date is not null and client_id = $clientId and DATE_FORMAT(schedule_date, '%Y-%m-%d') > '" . date("Y-m-d") . "' GROUP BY client_id"; $qEvents2 = mysql_query($events2Sql); if(mysql_num_rows($qEvents2) > 0){ while ($objEvent2 = mysql_fetch_assoc($qEvents2)) { $events_res2 = (int)$objEvent2["res"]; } } ?>