Actual prod

This commit is contained in:
mac 2026-07-02 08:12:13 +03:00
parent 7770a35e55
commit 7ee214b7ff

View File

@ -7,23 +7,23 @@ $usersArr = json_decode($_POST['responsible'], true);
$usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_admin']);
$gmtmsk = get_time_zone_user();
$time_zone = '';
$gmtmsk = get_time_zone_user();
$time_zone = '';
if($gmtmsk >= 0){
if($gmtmsk >= 0){
$time_zone = '+'.$gmtmsk.' hour';
} else {
} else {
$time_zone = '-'.$gmtmsk.' hour';
}
}
$this_datetime = ($time_zone == '') ? date("Y-m-d H:i:s") : date("Y-m-d H:i:s", strtotime($time_zone));
$this_datetime = ($time_zone == '') ? date("Y-m-d H:i:s") : date("Y-m-d H:i:s", strtotime($time_zone));
$where = '';
$whereObj = '';
if(isset($_POST['tasks'])){
$where = '';
$whereObj = '';
if(isset($_POST['tasks'])){
$view = $_POST['tasks'];
}
/* if($view == 'open_tasks'){
}
/* if($view == 'open_tasks'){
$where = " AND e.calendar_view = 0 AND DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') >= '".date("Y-m-d H:i:s")."'";
} else if($view == 'overdue_tasks'){
$where = " AND calendar_view = 0 AND DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') < '".date("Y-m-d H:i:s")."'";
@ -31,43 +31,43 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
$where = " AND calendar_view = 1";
}*/
if($view == 'open_tasks'){
if($view == 'open_tasks'){
$where = " AND e.calendar_view = 0 AND DATE_FORMAT(e.schedule_date, '%Y-%m-%d %H:%i:%s') >= '".$this_datetime."'";
} else if($view == 'overdue_tasks'){
} else if($view == 'overdue_tasks'){
$where = " AND e.calendar_view = 0 AND DATE_FORMAT(e.schedule_date, '%Y-%m-%d %H:%i:%s') < '".$this_datetime."'";
} else if($view == 'completed_tasks'){
} else if($view == 'completed_tasks'){
$where = " AND e.calendar_view = 1";
}
}
if(isset($_POST['event'])){
if(isset($_POST['event'])){
$where .= " AND `e`.`type` = '".$_POST['event']."'";
}
}
$whereObj = $where;
//printf($_POST);
$_SESSION['filter_emp'] = $_POST['responsible'];
$bd_usl_managers = '';
$bd_doers = '';
$bd_usl = '';
$arrIdUser = array();
$arrIdAgent = array();
foreach($usersId as $userId){
$whereObj = $where;
//printf($_POST);
$_SESSION['filter_emp'] = $_POST['responsible'];
$bd_usl_managers = '';
$bd_doers = '';
$bd_usl = '';
$arrIdUser = array();
$arrIdAgent = array();
foreach($usersId as $userId){
$arrIdUser[] = "who_work = $userId";
$arrIdAgent[] = "id_agent = $userId";
}
$period = 'all';
$whereTasks = "";
$bd_piriod = '';
$bd_do_period = '';
$eobj = true;
$isReq = false;
$table = "clients";
$dateAdd = "date_add";
}
$period = 'all';
$whereTasks = "";
$bd_piriod = '';
$bd_do_period = '';
$eobj = true;
$isReq = false;
$table = "clients";
$dateAdd = "date_add";
$ecl = true;
$eall = false;
$ecl = true;
$eall = false;
if(isset($_POST['type_calendar'])){
if(isset($_POST['type_calendar'])){
if($_POST['type_calendar'] == 'client' || $_POST['type_calendar'] == 'req'){
$eobj = false;
if($_POST['type_calendar'] == 'req'){
@ -77,28 +77,28 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
if($_POST['type_calendar'] == 'object'){
$ecl = false;
}
} else {
} else {
$eall = true;
}
}
if($_POST['period']){
if($_POST['period']){
$period = $_POST['period'];
$onDate = $_POST['start'];
$offDate = $_POST['end'];
}
else {
}
else {
unset($_SESSION['client_period']);
}
}
$dates = getPeriod($period, $onDate, $offDate);
$date_between = $dates['between'];
$whereTasks = $dates['whereTasks'];
$dates = getPeriod($period, $onDate, $offDate);
$date_between = $dates['between'];
$whereTasks = $dates['whereTasks'];
$date_add = 'date_add';
$date_add = 'date_add';
if($isReq){
if($isReq){
$table = 'requisitions';
$date_add = 'created_at';
$agentId = 'user_id as id_agent';
@ -115,10 +115,10 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
$bd_piriod = " AND created_at ".$date_between;
$bd_do_period = " AND created_at < '".$dates['dateStart']."'";
}
}
if(isset($_POST['charts_type'])){
if(isset($_POST['charts_type'])){
$typesArr = json_decode(html_entity_decode($_POST['charts_type']), ENT_QUOTES);
if(!empty($typesArr)){
$typeArr = array();
@ -128,13 +128,13 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
$bd_usl .= " AND (".implode(" OR ",$typeArr).")";
}
$_SESSION['filter_client_type'] = $_POST['charts_type'];
} else {
} else {
unset($_SESSION['filter_client_type']);
}
}
$part_task = '';
$part_task = '';
if($isReq){
if($isReq){
if (isset($_POST['charts_activities']) && !empty($_POST['charts_activities']) && $_POST['charts_activities'] != 'null') {
$activitiesArr = json_decode(html_entity_decode($_POST['charts_activities']), ENT_QUOTES);
$bd_usl .= " AND `id` IN (
@ -147,7 +147,7 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
} else {
unset($_SESSION['filter_activities']);
}
} else {
} else {
if (isset($_POST['charts_activities']) && !empty($_POST['charts_activities']) && $_POST['charts_activities'] != 'null') {
@ -161,9 +161,9 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
} else {
unset($_SESSION['filter_activities']);
}
}
}
/*if (isset($_POST['charts_activities']) && !empty($_POST['charts_activities']) && $_POST['charts_activities'] != 'null') {
/*if (isset($_POST['charts_activities']) && !empty($_POST['charts_activities']) && $_POST['charts_activities'] != 'null') {
$activitiesArr = json_decode(html_entity_decode($_POST['charts_activities']), ENT_QUOTES);
$bd_usl .= " AND id IN (
SELECT client_id FROM clients_activities
@ -171,19 +171,19 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
)";
$_SESSION['filter_activities'] = $_POST['charts_activities'];
} else {
} else {
unset($_SESSION['filter_activities']);
}*/
}*/
if (isset($_POST['charts_activities']) && !empty($_POST['charts_activities']) && $_POST['charts_activities'] != 'null') {
if (isset($_POST['charts_activities']) && !empty($_POST['charts_activities']) && $_POST['charts_activities'] != 'null') {
$activitiesArr = json_decode(html_entity_decode($_POST['charts_activities']), ENT_QUOTES);
$part_task .= " AND req_id IN (
SELECT req_id FROM requisitions_activities
WHERE activity_id IN (" . implode(", ", $activitiesArr) . "))";
}
}
if(isset($_POST['charts_objects_type'])){
if(isset($_POST['charts_objects_type'])){
$typesArr = json_decode(html_entity_decode($_POST['charts_objects_type']), ENT_QUOTES);
if(!empty($typesArr)){
$typeArr = array();
@ -193,11 +193,11 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
$bd_usl .= " AND (".implode(" OR ",$typeArr).")";
}
$_SESSION['filter_client_objects_type'] = $_POST['charts_objects_type'];
} else {
} else {
unset($_SESSION['filter_client_objects_type']);
}
}
if(isset($_POST['charts_rol'])){
if(isset($_POST['charts_rol'])){
$rolesArr = json_decode(html_entity_decode($_POST['charts_rol']), ENT_QUOTES);
if(!empty($rolesArr)){
$sroleArr = array();
@ -207,11 +207,11 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
$bd_usl .= " AND (".implode(" OR ",$roleArr).")";
}
$_SESSION['filter_client_rol'] = $_POST['charts_rol'];
} else {
} else {
unset($_SESSION['filter_client_rol']);
}
}
if(isset($_POST['source'])){
if(isset($_POST['source'])){
$sourcesArr = json_decode(html_entity_decode($_POST['source']), ENT_QUOTES);
$sourceArr = array();
if(!empty($sourcesArr )){
@ -230,11 +230,11 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
} else {
unset($_SESSION['filter_source']);
}
} else {
} else {
unset($_SESSION['filter_source']);
}
}
if(isset($_POST['funnel']) && $_POST['funnel'] != 'all'){
if(isset($_POST['funnel']) && $_POST['funnel'] != 'all'){
$funnelArr = json_decode(html_entity_decode($_POST['funnel']), ENT_QUOTES);
if(!empty($funnelArr)){
@ -243,40 +243,40 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
else
$bd_usl .= " AND funnel_id in ({$funnelArr})";
}
}
}
if(isset($_POST['step'])){
if(isset($_POST['step'])){
$step = (int)$_POST['step'];
$bd_usl .= " AND step_id = $step";
}
}
//if($isReq){
$bd_usl .= " AND cancel=0";
//}
$bd_usl_managers = " AND (".implode(" OR ",$arrIdUser).")";
//if($isReq){
$bd_usl .= " AND cancel=0";
//}
$bd_usl_managers = " AND (".implode(" OR ",$arrIdUser).")";
foreach ($usersId as $us) {
foreach ($usersId as $us) {
if($bd_doers != ''){
$bd_doers .= ' or ';
}
$bd_doers .= "`doers` like '%&quot;".$us."&quot;:1%'";
}
}
$post = clearInputData($_POST);
$post = clearInputData($_POST);
$startDateWhere = "1";
$endDateWhere = "1";
$startDateWhere = "1";
$endDateWhere = "1";
if (isset($post['start'])) {
if (isset($post['start'])) {
$startDateWhere = "DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') >= '".$post['start']." 00:00:00'";
}
}
if (isset($post['end'])) {
if (isset($post['end'])) {
$endDateWhere = "DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') <= '".$post['end']." 23:59:59'";
}
}
if($post['emp']){
if($post['emp']){
$agencyId = $post['emp'];
if($post['filter_stage'] && $post['filter_stage'] == 'filter_work_add'){
$bd_usl_managers .= " AND id_agent in (SELECT id FROM `users` WHERE id=$agencyId or id_manager=$agencyId or id_manager in (select id from users where id_manager=$agencyId))";
@ -289,30 +289,30 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
$where .= " AND user_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))";
$bd_doers = '';
$usersId = [$agencyId];
}
}
$sqlCl = "SELECT `id` FROM $table WHERE 1 $bd_usl_managers $bd_usl ";
$sqlCl = "SELECT `id` FROM $table WHERE 1 $bd_usl_managers $bd_usl ";
if($bd_doers != ''){
if($bd_doers != ''){
$sqlCl .= " UNION ";
$sqlCl .= "SELECT `id` FROM $table WHERE 1 $bd_usl and (".$bd_doers.") ";
}
if($_POST['step']){
}
if($_POST['step']){
$sqlCl = "SELECT `id` FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between ";
}
}
//echo $sqlCl;
//echo $sqlCl;
$q = mysql_query($sqlCl);
$row = mysql_num_rows($q);
$q = mysql_query($sqlCl);
$row = mysql_num_rows($q);
$whereEv = '';
$tempEv = array();
/*if(!$isReq){
$whereEv = '';
$tempEv = array();
/*if(!$isReq){
$tempEv[] = 0;
}*/
if($row > 0){
}*/
if($row > 0){
while($r = mysql_fetch_assoc($q)){
$tempEv[] = $r['id'];
}
@ -324,9 +324,9 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
$whereEv = ' AND (req_id in ('.implode(', ', $tempEv).') AND client_id = 0';
}
}
}
}
if($eall){
if($eall){
$user_this = new User();
$user_this->get($_SESSION['id']);
$wh = new WebHookIn();
@ -353,20 +353,20 @@ $usersId = $cl -> getUsersFilter($usersArr, $_POST['user_id'], $_POST['users_adm
}
}
}
}
if($whereEv != ''){
if($whereEv != ''){
$whereEv .= ")";
}
}
$from_users = array();
$sql_user = "SELECT id, CONCAT(last_name, ' ', first_name, ' ', middle_name) as user_fio FROM users WHERE id in (".implode(',', $usersId).")
$from_users = array();
$sql_user = "SELECT id, CONCAT(last_name, ' ', first_name, ' ', middle_name) as user_fio FROM users WHERE id in (".implode(',', $usersId).")
UNION SELECT user_id as id, CONCAT(last_name, ' ', first_name, ' ', middle_name, ' (удален)') as user_fio FROM users_delete WHERE user_id in (".implode(',', $usersId).")";
$q_user = mysql_query($sql_user);
while( $from_user = mysql_fetch_assoc($q_user)){
$q_user = mysql_query($sql_user);
while( $from_user = mysql_fetch_assoc($q_user)){
$from_users[$from_user['id']] = $from_user['user_fio'];
}
}
/*$time = microtime(true) - $start;
@ -379,7 +379,9 @@ echo '[';
if (isset($_POST['user_id'])) {
if($eobj){
$sql = "SELECT e.*, o.nazv, o.adres, o.dom, o.korpus, o.litera from user_object_events e, objects o WHERE user_id in (". implode(', ', $usersId).") $whereObj $part_task and o.id=e.object_id and e.schedule_date is not null and $startDateWhere and $endDateWhere";
// Явные колонки (НЕ e.*): после колонки moved_on_copy в user_object_events e.* стал шире 2-й ветки UNION
// → «different number of columns» → задачи по своим объектам пропадали из «Кабинет → Задачи». Порядок o.* выровнен со 2-й веткой.
$sql = "SELECT e.id, e.user_id, e.from_id, e.object_id, e.req_id, e.create_date, e.type, e.address, e.sum, e.document_id, e.schedule_date, e.comment, e.platforms_advert, e.calendar_view, e.cancel, e.tel, e.max, e.name, o.adres, o.dom, o.korpus, o.litera, o.nazv from user_object_events e, objects o WHERE user_id in (". implode(', ', $usersId).") $whereObj $part_task and o.id=e.object_id and e.schedule_date is not null and $startDateWhere and $endDateWhere";
$sql .= "union
SELECT s.id, s.user_for as user_id, 0 as from_id, e.object_id as object_id, 0 as req_id, created_at as create_date, 'sub_moderation' as type,
'' as address,null as sum, null as document_id, created_at as schedule_date, sub_comment as comment, '' as platforms_advert, e.calendar_view,e.cancel, 0 as tel, 0 as max,'' as name, o.adres, o.dom, o.korpus, o.litera,
@ -517,14 +519,63 @@ if (isset($_POST['user_id'])) {
echo "}";
$i++;
}
}
/*$time = microtime(true) - $start;
// Найденные листинги парсера: задачи из своей таблицы, чтобы Кабинет→Задачи показывал их наравне с бейджем
// шапки и личным календарём. Offset-free: object_id = РЕАЛЬНЫЙ el.id (он коллизит с objects.id),
// листинг помечаем флагом is_external=1. table_id = реальный id события, from=listing — завершение адресует
// external_listing_events. LEFT JOIN: листинг мог уйти по TTL (адрес тогда пустой). Комментарии — не задачи;
// сделок/модерации у листингов нет.
// $whereObj (фильтры состояния/типа задачи: calendar_view/schedule_date/type) применяем — эти колонки есть у листинга (алиас e).
// $part_task — req-фильтр по активностям: у листинга нет заявки → при активном фильтре листинги исключаем целиком.
if (empty($part_task)) {
$sqlListing = "SELECT e.*, IFNULL(el.address_text, '') AS adres
FROM external_listing_events e
LEFT JOIN external_listings el ON el.id = e.external_listing_id
WHERE e.user_id IN (".implode(', ', $usersId).") AND e.schedule_date IS NOT NULL $whereObj AND $startDateWhere AND $endDateWhere";
$rezListing = mysql_query($sqlListing);
while ($rezListing && ($event = mysql_fetch_assoc($rezListing))) {
if ($event['type'] == 'comment') {
continue;
}
$from_id = $event['user_id'];
if (!empty($event['from_id'])) $from_id = $event['from_id'];
$label = trim($event['adres']) !== '' ? $event['adres'] : ('EXT-' . $event['external_listing_id']);
$label = str_replace(array('"', '\\', "\r", "\n", '&quot;'), array("'", '/', ' ', ' ', "'"), $label);
$evName = str_replace(array('"', '\\', "\r", "\n", '&quot;'), array("'", '/', ' ', ' ', "'"), (string)$event['name']);
$suffix = isset($from_users[$from_id]) ? (' - '.$from_users[$from_id]) : '';
if ($i > 0) { echo ',{'; } else { echo '{'; }
echo '"id" : "'.$i.'", ';
echo '"table_id" : "'.$event['id'].'", ';
echo '"from" : "listing", ';
echo '"is_external" : "1", '; // явный маркер листинга для openEventsWindow (&src=ext); id-диапазон больше не различает
echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", ';
echo '"object_id" : "'.(int)$event['external_listing_id'].'",';
$className = ($event['type'] == 'meet') ? 'meet' : (($event['type'] == 'show') ? 'showing' : (($event['type'] == 'even') ? 'even' : 'call'));
if ($event['calendar_view'] != 0) $className .= ' viewed';
if ($event['type'] == 'meet') {
echo '"title": "Встреча '.$label.$suffix.'","className" : "'.$className.'"';
} else if ($event['type'] == 'show') {
echo '"title": "Показ '.$label.$suffix.'","className" : "'.$className.'"';
} else if ($event['type'] == 'even') {
echo '"title": "'.$evName.' '.$label.$suffix.'","className" : "'.$className.'"';
} else {
echo '"title": "Звонок '.$label.$suffix.'","className" : "'.$className.'"';
}
echo "}";
$i++;
}
} // конец if (empty($part_task)) — листинговый блок
}
/*$time = microtime(true) - $start;
if($_SESSION['id'] == 6635){
if($_SESSION['id'] == 6635){
echo "\nобъекты".$time." сек.";
}*/
if($ecl){
if($ecl){
// echo $whereTasks;
if ($startDateWhere != "1" || $endDateWhere != "1") {
@ -536,7 +587,8 @@ if($ecl){
$where .= ' and megafon=0 and mango=0 and telphin=0 and beeline=0 and mts=0 and tele2=0 and allo=0';
}
$sql = "SELECT * FROM user_client_events as e WHERE user_id in (". implode(', ', $usersId).") $whereTasks $whereEv $where $part_task and schedule_date is not null and cancel=0 and $startDateWhere and $endDateWhere";
// задачи по ответственному = чистый user_id (как личный календарь): убрали $whereEv — who_work-пересечение по ТЕКУЩЕМУ владельцу клиента, из-за него не показывались задачи по переназначенным клиентам
$sql = "SELECT * FROM user_client_events as e WHERE user_id in (". implode(', ', $usersId).") $whereTasks $where $part_task and schedule_date is not null and cancel=0 and $startDateWhere and $endDateWhere";
if($isReq && empty($whereEv))
$sql = "SELECT * FROM user_client_events as e WHERE user_id in (". implode(', ', $usersId).") and req_id = '-1' and schedule_date is not null and cancel=0 and $startDateWhere and $endDateWhere";
@ -551,14 +603,17 @@ if($ecl){
$clientsIds = array();
$reqsIds = array();
$usersEventIds = array();
$dealIds = array();
$clients = array();
$reqs = array();
$usersEvent = array();
$deals = array();
while ($event = mysql_fetch_assoc($rez)){
$events[] = $event;
if($event['client_id'] > 0) $clientsIds[] = (int)$event['client_id'];
if($event['req_id'] > 0) $reqsIds[] = (int)$event['req_id'];
if($event['user_id'] > 0) $usersEventIds[] = (int)$event['user_id'];
if($event['type'] == 'deal' && !empty($event['deal_id'])) $dealIds[] = (int)$event['deal_id'];
}
if(!empty($clientsIds)){
@ -585,11 +640,26 @@ if($ecl){
}
}
if(!empty($dealIds)){
$sql_deal = "SELECT id, title FROM deals WHERE id in (".implode(',', array_unique($dealIds)).")";
$q_deal = mysql_query($sql_deal);
while($r_deal = mysql_fetch_assoc($q_deal)){
$deals[$r_deal['id']] = $r_deal['title'];
}
}
foreach ($events as $event) {
$from_id = $event['user_id'];
$cancel = 0;
if(!empty($event['from_id'])) $from_id = $event['from_id'];
if ($event['type'] == 'deal' && !empty($event['deal_id'])) {
if (in_array($event['deal_id'], $seenDealIds)) {
continue;
}
$seenDealIds[] = $event['deal_id'];
}
$fio = '';
if($event['client_id'] > 0 && isset($clients[$event['client_id']])){
@ -600,6 +670,10 @@ if($ecl){
$cancel = (int)$reqs[$event['req_id']]['cancel'];
}
if ($event['type'] == 'deal' && !empty($event['deal_id']) && isset($deals[$event['deal_id']])) {
$fio = $deals[$event['deal_id']];
}
if($cancel == 0){
if ($i > 0) {
@ -716,7 +790,7 @@ if($ecl){
/*$time = microtime(true) - $start;
if($_SESSION['id'] == 6635){
if($_SESSION['id'] == 6635){
echo "\n клиенты".$time." сек.";
}*/
if($view !='overdue_tasks' && !isset($_POST['event'])){
@ -869,7 +943,7 @@ if($_SESSION['id'] == 6635){
/* $time = microtime(true) - $start;
if($_SESSION['id'] == 6635){
if($_SESSION['id'] == 6635){
echo "\n дни ".$time." сек.";
}*/
}