From 7ee214b7ff629802d67760be2c431a51caf5ebab Mon Sep 17 00:00:00 2001 From: mac Date: Thu, 2 Jul 2026 08:12:13 +0300 Subject: [PATCH] Actual prod --- ajax/calendarCharts.php | 1370 +++++++++++++++++++++------------------ 1 file changed, 722 insertions(+), 648 deletions(-) diff --git a/ajax/calendarCharts.php b/ajax/calendarCharts.php index bc8c473..5fd3718 100644 --- a/ajax/calendarCharts.php +++ b/ajax/calendarCharts.php @@ -4,369 +4,369 @@ $start = microtime(true); $cl = new Clients(); $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){ - $time_zone = '+'.$gmtmsk.' hour'; - } else { - $time_zone = '-'.$gmtmsk.' hour'; - } +if($gmtmsk >= 0){ + $time_zone = '+'.$gmtmsk.' hour'; +} 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'])){ - $view = $_POST['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")."'"; - } else if($view == 'completed_tasks'){ - $where = " AND calendar_view = 1"; - }*/ +$where = ''; +$whereObj = ''; +if(isset($_POST['tasks'])){ + $view = $_POST['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")."'"; + } else if($view == 'completed_tasks'){ + $where = " AND calendar_view = 1"; + }*/ - 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'){ - $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'){ - $where = " AND e.calendar_view = 1"; - } +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'){ + $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'){ + $where = " AND e.calendar_view = 1"; +} - if(isset($_POST['event'])){ - $where .= " AND `e`.`type` = '".$_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){ - $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"; - - $ecl = true; - $eall = false; +$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"; - if(isset($_POST['type_calendar'])){ - if($_POST['type_calendar'] == 'client' || $_POST['type_calendar'] == 'req'){ +$ecl = true; +$eall = false; + +if(isset($_POST['type_calendar'])){ + if($_POST['type_calendar'] == 'client' || $_POST['type_calendar'] == 'req'){ $eobj = false; if($_POST['type_calendar'] == 'req'){ $isReq = true; } - } - if($_POST['type_calendar'] == 'object'){ - $ecl = false; - } - } else { - $eall = true; } + if($_POST['type_calendar'] == 'object'){ + $ecl = false; + } +} else { + $eall = true; +} + +if($_POST['period']){ + + $period = $_POST['period']; + $onDate = $_POST['start']; + + $offDate = $_POST['end']; +} +else { + unset($_SESSION['client_period']); +} + +$dates = getPeriod($period, $onDate, $offDate); +$date_between = $dates['between']; +$whereTasks = $dates['whereTasks']; + +$date_add = 'date_add'; + +if($isReq){ + $table = 'requisitions'; + $date_add = 'created_at'; + $agentId = 'user_id as id_agent'; + + $period = 'all'; + $whereTasks = ""; if($_POST['period']){ - $period = $_POST['period']; - $onDate = $_POST['start']; - - $offDate = $_POST['end']; - } - else { - unset($_SESSION['client_period']); } - - $dates = getPeriod($period, $onDate, $offDate); + $dates = getPeriod($period,$_POST['onDate'],$_POST['offDate']); $date_between = $dates['between']; $whereTasks = $dates['whereTasks']; - - $date_add = 'date_add'; - if($isReq){ - $table = 'requisitions'; - $date_add = 'created_at'; - $agentId = 'user_id as id_agent'; - - $period = 'all'; - $whereTasks = ""; - - if($_POST['period']){ - $period = $_POST['period']; - } - $dates = getPeriod($period,$_POST['onDate'],$_POST['offDate']); - $date_between = $dates['between']; - $whereTasks = $dates['whereTasks']; - - $bd_piriod = " AND created_at ".$date_between; - $bd_do_period = " AND created_at < '".$dates['dateStart']."'"; - } + $bd_piriod = " AND created_at ".$date_between; + $bd_do_period = " AND created_at < '".$dates['dateStart']."'"; +} - if(isset($_POST['charts_type'])){ - $typesArr = json_decode(html_entity_decode($_POST['charts_type']), ENT_QUOTES); - if(!empty($typesArr)){ - $typeArr = array(); - foreach($typesArr as $typeCl){ - $typeArr[] = "work_type like '%"{$typeCl}"%'"; - } - $bd_usl .= " AND (".implode(" OR ",$typeArr).")"; +if(isset($_POST['charts_type'])){ + $typesArr = json_decode(html_entity_decode($_POST['charts_type']), ENT_QUOTES); + if(!empty($typesArr)){ + $typeArr = array(); + foreach($typesArr as $typeCl){ + $typeArr[] = "work_type like '%"{$typeCl}"%'"; } - $_SESSION['filter_client_type'] = $_POST['charts_type']; - } else { - unset($_SESSION['filter_client_type']); + $bd_usl .= " AND (".implode(" OR ",$typeArr).")"; } + $_SESSION['filter_client_type'] = $_POST['charts_type']; +} else { + unset($_SESSION['filter_client_type']); +} - $part_task = ''; - - 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 ( +$part_task = ''; + +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 ( SELECT req_id FROM requisitions_activities WHERE activity_id IN (" . implode(", ", $activitiesArr) . ") )"; - - $_SESSION['filter_activities'] = $_POST['charts_activities']; - } else { - unset($_SESSION['filter_activities']); - } - } else { - - - 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 - WHERE activity_id IN (" . implode(", ", $activitiesArr) . ") - )"; - - $_SESSION['filter_activities'] = $_POST['charts_activities']; - } else { - unset($_SESSION['filter_activities']); - } - } - - /*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 - WHERE activity_id IN (" . implode(", ", $activitiesArr) . ") - )"; $_SESSION['filter_activities'] = $_POST['charts_activities']; } else { unset($_SESSION['filter_activities']); - }*/ + } +} else { + 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 ( + $bd_usl .= " AND id IN ( + SELECT client_id FROM clients_activities + WHERE activity_id IN (" . implode(", ", $activitiesArr) . ") + )"; + + $_SESSION['filter_activities'] = $_POST['charts_activities']; + } else { + unset($_SESSION['filter_activities']); + } +} + +/*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 + WHERE activity_id IN (" . implode(", ", $activitiesArr) . ") + )"; + + $_SESSION['filter_activities'] = $_POST['charts_activities']; +} else { + unset($_SESSION['filter_activities']); +}*/ + +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'])){ - $typesArr = json_decode(html_entity_decode($_POST['charts_objects_type']), ENT_QUOTES); - if(!empty($typesArr)){ - $typeArr = array(); - foreach($typesArr as $typeCl){ - $typeArr[] = "`type` like '%"{$typeCl}"%'"; - } - $bd_usl .= " AND (".implode(" OR ",$typeArr).")"; +} + +if(isset($_POST['charts_objects_type'])){ + $typesArr = json_decode(html_entity_decode($_POST['charts_objects_type']), ENT_QUOTES); + if(!empty($typesArr)){ + $typeArr = array(); + foreach($typesArr as $typeCl){ + $typeArr[] = "`type` like '%"{$typeCl}"%'"; } - $_SESSION['filter_client_objects_type'] = $_POST['charts_objects_type']; - } else { - unset($_SESSION['filter_client_objects_type']); + $bd_usl .= " AND (".implode(" OR ",$typeArr).")"; } + $_SESSION['filter_client_objects_type'] = $_POST['charts_objects_type']; +} else { + unset($_SESSION['filter_client_objects_type']); +} - if(isset($_POST['charts_rol'])){ - $rolesArr = json_decode(html_entity_decode($_POST['charts_rol']), ENT_QUOTES); - if(!empty($rolesArr)){ - $sroleArr = array(); - foreach($rolesArr as $roleCl){ - $roleArr[] = "`role` like '%"{$roleCl}"%'"; - } - $bd_usl .= " AND (".implode(" OR ",$roleArr).")"; +if(isset($_POST['charts_rol'])){ + $rolesArr = json_decode(html_entity_decode($_POST['charts_rol']), ENT_QUOTES); + if(!empty($rolesArr)){ + $sroleArr = array(); + foreach($rolesArr as $roleCl){ + $roleArr[] = "`role` like '%"{$roleCl}"%'"; } - $_SESSION['filter_client_rol'] = $_POST['charts_rol']; - } else { - unset($_SESSION['filter_client_rol']); + $bd_usl .= " AND (".implode(" OR ",$roleArr).")"; } + $_SESSION['filter_client_rol'] = $_POST['charts_rol']; +} else { + unset($_SESSION['filter_client_rol']); +} - if(isset($_POST['source'])){ - $sourcesArr = json_decode(html_entity_decode($_POST['source']), ENT_QUOTES); - $sourceArr = array(); - if(!empty($sourcesArr )){ - 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).")"; - - $_SESSION['filter_source'] = $_POST['source']; +if(isset($_POST['source'])){ + $sourcesArr = json_decode(html_entity_decode($_POST['source']), ENT_QUOTES); + $sourceArr = array(); + if(!empty($sourcesArr )){ + foreach($sourcesArr as $sourceCl){ + if($sourceCl == 0){ + $sourceArr[] = "`source` is null"; + $sourceArr[] = "`source` = ''"; + $sourceArr[] = "`source` = 'null'"; } else { - unset($_SESSION['filter_source']); + $sourceArr[] = "`source` = '{$sourceCl}'"; } - } else { - unset($_SESSION['filter_source']); } + $bd_usl .= " AND (".implode(" OR ",$sourceArr).")"; - if(isset($_POST['funnel']) && $_POST['funnel'] != 'all'){ - $funnelArr = json_decode(html_entity_decode($_POST['funnel']), ENT_QUOTES); - - if(!empty($funnelArr)){ - if(is_array($funnelArr)) - $bd_usl .= " AND funnel_id in (".implode(', ',$funnelArr).")"; - else - $bd_usl .= " AND funnel_id in ({$funnelArr})"; - } - } - - 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).")"; - - foreach ($usersId as $us) { - if($bd_doers != ''){ - $bd_doers .= ' or '; - } - $bd_doers .= "`doers` like '%"".$us."":1%'"; + $_SESSION['filter_source'] = $_POST['source']; + } else { + unset($_SESSION['filter_source']); } +} else { + unset($_SESSION['filter_source']); +} +if(isset($_POST['funnel']) && $_POST['funnel'] != 'all'){ + $funnelArr = json_decode(html_entity_decode($_POST['funnel']), ENT_QUOTES); - $post = clearInputData($_POST); - - $startDateWhere = "1"; - $endDateWhere = "1"; - - if (isset($post['start'])) { - $startDateWhere = "DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') >= '".$post['start']." 00:00:00'"; + if(!empty($funnelArr)){ + if(is_array($funnelArr)) + $bd_usl .= " AND funnel_id in (".implode(', ',$funnelArr).")"; + else + $bd_usl .= " AND funnel_id in ({$funnelArr})"; } +} - if (isset($post['end'])) { - $endDateWhere = "DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') <= '".$post['end']." 23:59:59'"; - } +if(isset($_POST['step'])){ + $step = (int)$_POST['step']; + $bd_usl .= " AND step_id = $step"; +} - 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))"; - // $usersId = [$agencyId]; - - } else { - $bd_usl_managers .= " AND who_work in (SELECT id FROM `users` WHERE id=$agencyId or id_manager=$agencyId or id_manager in (select id from users where id_manager=$agencyId))"; - - } - $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 "; +//if($isReq){ +$bd_usl .= " AND cancel=0"; +//} +$bd_usl_managers = " AND (".implode(" OR ",$arrIdUser).")"; +foreach ($usersId as $us) { if($bd_doers != ''){ - $sqlCl .= " UNION "; - $sqlCl .= "SELECT `id` FROM $table WHERE 1 $bd_usl and (".$bd_doers.") "; + $bd_doers .= ' or '; } - if($_POST['step']){ - $sqlCl = "SELECT `id` FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between "; + $bd_doers .= "`doers` like '%"".$us."":1%'"; +} + + +$post = clearInputData($_POST); + +$startDateWhere = "1"; +$endDateWhere = "1"; + +if (isset($post['start'])) { + $startDateWhere = "DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') >= '".$post['start']." 00:00:00'"; +} + +if (isset($post['end'])) { + $endDateWhere = "DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') <= '".$post['end']." 23:59:59'"; +} + +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))"; + // $usersId = [$agencyId]; + + } else { + $bd_usl_managers .= " AND who_work in (SELECT id FROM `users` WHERE id=$agencyId or id_manager=$agencyId or id_manager in (select id from users where id_manager=$agencyId))"; + } + $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]; +} - //echo $sqlCl; - +$sqlCl = "SELECT `id` FROM $table WHERE 1 $bd_usl_managers $bd_usl "; - $q = mysql_query($sqlCl); - $row = mysql_num_rows($q); +if($bd_doers != ''){ + $sqlCl .= " UNION "; + $sqlCl .= "SELECT `id` FROM $table WHERE 1 $bd_usl and (".$bd_doers.") "; +} +if($_POST['step']){ + $sqlCl = "SELECT `id` FROM $table WHERE 1 $bd_usl_managers $bd_usl and $date_add $date_between "; +} - $whereEv = ''; - $tempEv = array(); - /*if(!$isReq){ - $tempEv[] = 0; - }*/ - if($row > 0){ - while($r = mysql_fetch_assoc($q)){ - $tempEv[] = $r['id']; +//echo $sqlCl; + + +$q = mysql_query($sqlCl); +$row = mysql_num_rows($q); + +$whereEv = ''; +$tempEv = array(); +/*if(!$isReq){ + $tempEv[] = 0; +}*/ +if($row > 0){ + while($r = mysql_fetch_assoc($q)){ + $tempEv[] = $r['id']; + } + $whereEv = ' AND (client_id in ('.implode(', ', $tempEv).') '; + if(isset($_POST['type_calendar'])){ + if($_POST['type_calendar'] == 'client'){ + $whereEv = ' AND (client_id in ('.implode(', ', $tempEv).') AND req_id = 0'; + } else if($_POST['type_calendar'] == 'req'){ + $whereEv = ' AND (req_id in ('.implode(', ', $tempEv).') AND client_id = 0'; } - $whereEv = ' AND (client_id in ('.implode(', ', $tempEv).') '; - if(isset($_POST['type_calendar'])){ - if($_POST['type_calendar'] == 'client'){ - $whereEv = ' AND (client_id in ('.implode(', ', $tempEv).') AND req_id = 0'; - } else if($_POST['type_calendar'] == 'req'){ - $whereEv = ' AND (req_id in ('.implode(', ', $tempEv).') AND client_id = 0'; + } +} + +if($eall){ + $user_this = new User(); + $user_this->get($_SESSION['id']); + $wh = new WebHookIn(); + $allUsersIds = array(); + if($user_this->agencyId > 0){ + $allUsersIds = $wh->getAllUserAgency($user_this->agencyId); + } + if(!empty($allUsersIds)){ + $sqlCl2 = "SELECT `id` FROM requisitions WHERE user_id in (".implode(',', $allUsersIds).") AND cancel = 0"; + + $q2 = mysql_query($sqlCl2); + $row2 = mysql_num_rows($q2); + $tempEv = array(); + + while($r2 = mysql_fetch_assoc($q2)){ + $tempEv[] = $r2['id']; + } + if(!empty($tempEv)){ + if($whereEv == ''){ + $whereEv .= ' AND (req_id in ('.implode(', ', $tempEv).') OR (req_id = 0 && client_id = 0)'; + } else { + $whereEv .= ' OR req_id in ('.implode(', ', $tempEv).') OR (req_id = 0 && client_id = 0)'; } } } - if($eall){ - $user_this = new User(); - $user_this->get($_SESSION['id']); - $wh = new WebHookIn(); - $allUsersIds = array(); - if($user_this->agencyId > 0){ - $allUsersIds = $wh->getAllUserAgency($user_this->agencyId); - } - if(!empty($allUsersIds)){ - $sqlCl2 = "SELECT `id` FROM requisitions WHERE user_id in (".implode(',', $allUsersIds).") AND cancel = 0"; - - $q2 = mysql_query($sqlCl2); - $row2 = mysql_num_rows($q2); - $tempEv = array(); +} - while($r2 = mysql_fetch_assoc($q2)){ - $tempEv[] = $r2['id']; - } - if(!empty($tempEv)){ - if($whereEv == ''){ - $whereEv .= ' AND (req_id in ('.implode(', ', $tempEv).') OR (req_id = 0 && client_id = 0)'; - } else { - $whereEv .= ' OR req_id in ('.implode(', ', $tempEv).') OR (req_id = 0 && client_id = 0)'; - } - } - } - - } - - if($whereEv != ''){ - $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)){ - $from_users[$from_user['id']] = $from_user['user_fio']; - } +$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; @@ -378,265 +378,49 @@ echo '['; //echo $sql; 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"; - $sql .= "union + if($eobj){ + // Явные колонки (НЕ 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, o.nazv from user_sub_comments as s LEFT JOIN user_object_events as e on e.id=s.event_id LEFT JOIN objects as o on o.id=object_id WHERE section_id = 1 and user_for in (". implode(', ', $usersId).") $whereObj $part_task and $startDateWhere and $endDateWhere"; - - $rez = mysql_query($sql); - - $i = 0; - while ($event = mysql_fetch_assoc($rez)) { - $from_id = $event['user_id']; - if(!empty($event['from_id'])) $from_id = $event['from_id']; - if ($i > 0) { - echo ',{'; - } else { - echo '{'; - } - echo '"id" : "'.$i.'", '; - // echo '"$sql" : "'.$sql.'", '; - echo '"table_id" : "'.$event['id'].'", '; - echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", '; - echo '"object_id" : "'.$event['object_id'].'",'; - $address = $event['nazv'] .' '.$event['adres']; + $rez = mysql_query($sql); - if ($event['dom']) { - $address = $address . ", " . $event['dom']; - } - - if ($event['korpus']) { - $address = $address . ", корпус " . $event['korpus']; - } - - if ($event['litera']) { - $address = $address . ", литера" . $event['litera']; - } - - $address = str_replace("\\","/", $address); - $address = str_replace("\"","'", $address); - - if ($event['type'] == 'call') { - - $className = "call"; - if ($event['calendar_view'] != 0) { - $className .= " viewed"; - } - - - echo '"title": "Звонок '.$address; - if(isset($from_users[$from_id])){ - echo ' - '.$from_users[$from_id]; - } - echo '","className" : "'.$className.'"'; - } - - if ($event['type'] == 'meet') { - - $className = "meet"; - if ($event['calendar_view'] != 0) { - $className .= " viewed"; - } - - echo '"title": "Встреча '.$address; - if(isset($from_users[$from_id])){ - echo ' - '.$from_users[$from_id]; - } - echo '","className" : "'.$className.'"'; - } - - if ($event['type'] == 'show') { - - $className = "showing"; - if ($event['calendar_view'] != 0) { - $className .= " viewed"; - } - - echo '"title": "Показ '.$address; - if(isset($from_users[$from_id])){ - echo ' - '.$from_users[$from_id]; - } - echo '","className" : "'.$className.'"'; - } - - if ($event['type'] == 'deal') { - - $className = "deal"; - if ($event['calendar_view'] != 0) { - $className .= " viewed"; - } - - echo '"title": "Сделка '.$address; - if(isset($from_users[$from_id])){ - echo ' - '.$from_users[$from_id]; - } - echo '","className" : "'.$className.'"'; - } - - if ($event['type'] == 'moderation') { - $className = "moderation"; - if ($event['calendar_view'] != 0) { - $className .= " viewed"; - } - - echo '"title": "Модерация '.$event['nazv']; - if(isset($from_users[$from_id])){ - echo ' - '.$from_users[$from_id]; - } - echo '","className" : "'.$className.'"'; - } - - if ($event['type'] == 'sub_moderation') { - $className = "moderation"; - if ($event['calendar_view'] != 0) { - $className .= " viewed"; - } - - echo '"title": "Комментарий к модерация '.$event['nazv']; - if(isset($from_users[$from_id])){ - echo ' - '.$from_users[$from_id]; - } - echo '","className" : "'.$className.'"'; - } - - if ($event['type'] == 'even') { - - $className = "even"; - if ($event['calendar_view'] != 0) { - $className .= " viewed"; - } - - echo '"title": "'.$event['name']. ' ' . $event['nazv'] .'","className" : "'.$className.'"'; - } - - - - echo "}"; - $i++; - } -} -/*$time = microtime(true) - $start; - - -if($_SESSION['id'] == 6635){ - echo "\nобъекты".$time." сек."; - }*/ -if($ecl){ - - // echo $whereTasks; - if ($startDateWhere != "1" || $endDateWhere != "1") { - $whereTasks = " and 1 "; - } - - $agency_id = (int)$_POST['agency_id']; - if($agency_id != 7384){ - $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"; - - 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"; - $rez = mysql_query($sql); - //$result['sql'] = $sql; - /*if($_SESSION['id'] == 22687){ - echo "\n".$sql."\n"; - }*/ - //echo $sql; - //Начитки - $events = array(); - $clientsIds = array(); - $reqsIds = array(); - $usersEventIds = array(); - $clients = array(); - $reqs = array(); - $usersEvent = 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(!empty($clientsIds)){ - $sql_cl = "SELECT id, fio from clients WHERE id in (".implode(',',$clientsIds).")"; - $q_cl = mysql_query($sql_cl); - while($r_cl = mysql_fetch_assoc($q_cl)){ - $clients[$r_cl['id']] = str_replace("\\","/", $r_cl['fio']); - } - } - - if(!empty($reqsIds)){ - $sql_cl = "SELECT id, name, cancel from requisitions WHERE id in (".implode(',',$reqsIds).")"; - $q_cl = mysql_query($sql_cl); - while($r_cl = mysql_fetch_assoc($q_cl)){ - $reqs[$r_cl['id']] = $r_cl; - } - } - - if(!empty($usersEventIds)){ - $sql_u = "SELECT id, first_name, last_name, middle_name FROM users WHERE id in (".implode(',',$usersEventIds).")"; - $q_u = mysql_query($sql_u); - while($r_u = mysql_fetch_assoc($q_u)){ - $usersEvent[$r_u['id']] = $r_u; - } - } - - foreach ($events as $event) { - $from_id = $event['user_id']; - $cancel = 0; - if(!empty($event['from_id'])) $from_id = $event['from_id']; - - $fio = ''; - if($event['client_id'] > 0 && isset($clients[$event['client_id']])){ - - $fio = $clients[$event['client_id']]; - } else if($event['req_id'] > 0 && isset($reqs[$event['req_id']])) { - - $fio = $reqs[$event['req_id']]['name']; - $cancel = (int)$reqs[$event['req_id']]['cancel']; - } - - if($cancel == 0){ - + $i = 0; + while ($event = mysql_fetch_assoc($rez)) { + $from_id = $event['user_id']; + if(!empty($event['from_id'])) $from_id = $event['from_id']; if ($i > 0) { echo ',{'; } else { echo '{'; } - echo '"id" : "'.$i.'", '; + // echo '"$sql" : "'.$sql.'", '; echo '"table_id" : "'.$event['id'].'", '; echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", '; - if($fio == ''){ - if(isset($usersEvent[$event['user_id']])){ - $fio = '(исполнитель '.trim($usersEvent[$event['user_id']]['last_name'] . ' ' . $usersEvent[$event['user_id']]['first_name'] . ' ' . $usersEvent[$event['user_id']]['middle_name']).')'; - } + echo '"object_id" : "'.$event['object_id'].'",'; + + $address = $event['nazv'] .' '.$event['adres']; + + if ($event['dom']) { + $address = $address . ", " . $event['dom']; } - echo '"client_id" : "'.$event['client_id'].'",'; - echo '"req_id" : "'.$event['req_id'].'",'; - $fio = str_replace("\\","/", $fio); - $fio = str_replace("\"","'", $fio); - - if ($event['type'] == 'comment') { - - $className = "comment"; - if ($event['calendar_view'] != 0) { - $className .= " viewed"; - } - - - echo '"title": "Комментарий '.$fio; - if(isset($from_users[$from_id])){ - echo ' - '.$from_users[$from_id]; - } - echo '","className" : "'.$className.'"'; + if ($event['korpus']) { + $address = $address . ", корпус " . $event['korpus']; } + if ($event['litera']) { + $address = $address . ", литера" . $event['litera']; + } + + $address = str_replace("\\","/", $address); + $address = str_replace("\"","'", $address); + if ($event['type'] == 'call') { $className = "call"; @@ -644,8 +428,8 @@ if($ecl){ $className .= " viewed"; } - - echo '"title": "Звонок '.$fio; + + echo '"title": "Звонок '.$address; if(isset($from_users[$from_id])){ echo ' - '.$from_users[$from_id]; } @@ -659,7 +443,7 @@ if($ecl){ $className .= " viewed"; } - echo '"title": "Встреча '.$fio; + echo '"title": "Встреча '.$address; if(isset($from_users[$from_id])){ echo ' - '.$from_users[$from_id]; } @@ -673,7 +457,7 @@ if($ecl){ $className .= " viewed"; } - echo '"title": "Показ '.$fio; + echo '"title": "Показ '.$address; if(isset($from_users[$from_id])){ echo ' - '.$from_users[$from_id]; } @@ -687,88 +471,378 @@ if($ecl){ $className .= " viewed"; } - echo '"title": "Сделка '.$fio; + echo '"title": "Сделка '.$address; if(isset($from_users[$from_id])){ echo ' - '.$from_users[$from_id]; } echo '","className" : "'.$className.'"'; } - if ($event['type'] == 'even' || $event['type'] == 'event') { + if ($event['type'] == 'moderation') { + $className = "moderation"; + if ($event['calendar_view'] != 0) { + $className .= " viewed"; + } + + echo '"title": "Модерация '.$event['nazv']; + if(isset($from_users[$from_id])){ + echo ' - '.$from_users[$from_id]; + } + echo '","className" : "'.$className.'"'; + } + + if ($event['type'] == 'sub_moderation') { + $className = "moderation"; + if ($event['calendar_view'] != 0) { + $className .= " viewed"; + } + + echo '"title": "Комментарий к модерация '.$event['nazv']; + if(isset($from_users[$from_id])){ + echo ' - '.$from_users[$from_id]; + } + echo '","className" : "'.$className.'"'; + } + + if ($event['type'] == 'even') { $className = "even"; if ($event['calendar_view'] != 0) { $className .= " viewed"; } - echo '"title": "'.$event['name'].' '.$fio; - if(isset($from_users[$from_id])){ - echo ' - '.$from_users[$from_id]; - } - echo '","className" : "'.$className.'"'; + echo '"title": "'.$event['name']. ' ' . $event['nazv'] .'","className" : "'.$className.'"'; } + + echo "}"; $i++; } + + // Найденные листинги парсера: задачи из своей таблицы, чтобы Кабинет→Задачи показывал их наравне с бейджем + // шапки и личным календарём. 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", '"'), array("'", '/', ' ', ' ', "'"), $label); + $evName = str_replace(array('"', '\\', "\r", "\n", '"'), 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){ - echo "\n клиенты".$time." сек."; - }*/ - if($view !='overdue_tasks' && !isset($_POST['event'])){ - if (isset($post['start'])) { - $startDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') >='".date('m-d', strtotime($post['start']))."'"; - } - if (isset($post['end'])) { - $endDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') < '".date('m-d', strtotime($post['end']))."'"; - } - $sql = "SELECT id, fio, birthday FROM clients WHERE cancel=0 AND who_work = ".$_SESSION['id']." $bd_usl $part_task AND ".$startDateWhereBirthday." AND ".$endDateWhereBirthday; - //echo $sql; - $q = mysql_query($sql); - while ($b = mysql_fetch_assoc($q)) { - if ($i > 0) { - echo ',{'; - } else { - echo '{'; + if($_SESSION['id'] == 6635){ + echo "\nобъекты".$time." сек."; + }*/ + if($ecl){ + + // echo $whereTasks; + if ($startDateWhere != "1" || $endDateWhere != "1") { + $whereTasks = " and 1 "; } - $fio = $b['fio']; - echo '"id" : "'.$i.'", '; - echo '"table_id" : "'.$b['id'].'", '; - echo '"start" : "'.date('Y-', strtotime($post['start'])).date('m-d', strtotime($b['birthday'])).'", '; - echo '"client_id" : "'.$b['id'].'",'; - - //if ($event['type'] == 'call') { - - $className = "birthday"; - /* if ($event['calendar_view'] != 0) { - $className .= " viewed"; - }*/ - - echo '"title": "День рождения «'.$fio.'»","className" : "'.$className.'"'; - // } - echo "}"; - $i++; - } - - if (isset($post['start'])) - $startDateWhereBirthday = "DATE_FORMAT(employees.birthday, '%m-%d') >= '".date('m-d', strtotime($post['start']))."'"; - - if (isset($post['end'])) - $endDateWhereBirthday = "DATE_FORMAT(employees.birthday, '%m-%d') < '".date('m-d', strtotime($post['end']))."'"; - - $userId = $_SESSION['id']; - $user = new User; - $user->get($userId); - if ($_SESSION['users_admin']) { - $userId = $user->agencyId; + $agency_id = (int)$_POST['agency_id']; + if($agency_id != 7384){ + $where .= ' and megafon=0 and mango=0 and telphin=0 and beeline=0 and mts=0 and tele2=0 and allo=0'; } - $sql = "SELECT employees.id, + + // задачи по ответственному = чистый 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"; + $rez = mysql_query($sql); + //$result['sql'] = $sql; + /*if($_SESSION['id'] == 22687){ + echo "\n".$sql."\n"; + }*/ + //echo $sql; + //Начитки + $events = array(); + $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)){ + $sql_cl = "SELECT id, fio from clients WHERE id in (".implode(',',$clientsIds).")"; + $q_cl = mysql_query($sql_cl); + while($r_cl = mysql_fetch_assoc($q_cl)){ + $clients[$r_cl['id']] = str_replace("\\","/", $r_cl['fio']); + } + } + + if(!empty($reqsIds)){ + $sql_cl = "SELECT id, name, cancel from requisitions WHERE id in (".implode(',',$reqsIds).")"; + $q_cl = mysql_query($sql_cl); + while($r_cl = mysql_fetch_assoc($q_cl)){ + $reqs[$r_cl['id']] = $r_cl; + } + } + + if(!empty($usersEventIds)){ + $sql_u = "SELECT id, first_name, last_name, middle_name FROM users WHERE id in (".implode(',',$usersEventIds).")"; + $q_u = mysql_query($sql_u); + while($r_u = mysql_fetch_assoc($q_u)){ + $usersEvent[$r_u['id']] = $r_u; + } + } + + 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']])){ + + $fio = $clients[$event['client_id']]; + } else if($event['req_id'] > 0 && isset($reqs[$event['req_id']])) { + + $fio = $reqs[$event['req_id']]['name']; + $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) { + echo ',{'; + } else { + echo '{'; + } + + echo '"id" : "'.$i.'", '; + echo '"table_id" : "'.$event['id'].'", '; + echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", '; + if($fio == ''){ + if(isset($usersEvent[$event['user_id']])){ + $fio = '(исполнитель '.trim($usersEvent[$event['user_id']]['last_name'] . ' ' . $usersEvent[$event['user_id']]['first_name'] . ' ' . $usersEvent[$event['user_id']]['middle_name']).')'; + } + } + echo '"client_id" : "'.$event['client_id'].'",'; + echo '"req_id" : "'.$event['req_id'].'",'; + + $fio = str_replace("\\","/", $fio); + $fio = str_replace("\"","'", $fio); + + if ($event['type'] == 'comment') { + + $className = "comment"; + if ($event['calendar_view'] != 0) { + $className .= " viewed"; + } + + + echo '"title": "Комментарий '.$fio; + if(isset($from_users[$from_id])){ + echo ' - '.$from_users[$from_id]; + } + echo '","className" : "'.$className.'"'; + } + + if ($event['type'] == 'call') { + + $className = "call"; + if ($event['calendar_view'] != 0) { + $className .= " viewed"; + } + + + echo '"title": "Звонок '.$fio; + if(isset($from_users[$from_id])){ + echo ' - '.$from_users[$from_id]; + } + echo '","className" : "'.$className.'"'; + } + + if ($event['type'] == 'meet') { + + $className = "meet"; + if ($event['calendar_view'] != 0) { + $className .= " viewed"; + } + + echo '"title": "Встреча '.$fio; + if(isset($from_users[$from_id])){ + echo ' - '.$from_users[$from_id]; + } + echo '","className" : "'.$className.'"'; + } + + if ($event['type'] == 'show') { + + $className = "showing"; + if ($event['calendar_view'] != 0) { + $className .= " viewed"; + } + + echo '"title": "Показ '.$fio; + if(isset($from_users[$from_id])){ + echo ' - '.$from_users[$from_id]; + } + echo '","className" : "'.$className.'"'; + } + + if ($event['type'] == 'deal') { + + $className = "deal"; + if ($event['calendar_view'] != 0) { + $className .= " viewed"; + } + + echo '"title": "Сделка '.$fio; + if(isset($from_users[$from_id])){ + echo ' - '.$from_users[$from_id]; + } + echo '","className" : "'.$className.'"'; + } + + if ($event['type'] == 'even' || $event['type'] == 'event') { + + $className = "even"; + if ($event['calendar_view'] != 0) { + $className .= " viewed"; + } + + echo '"title": "'.$event['name'].' '.$fio; + if(isset($from_users[$from_id])){ + echo ' - '.$from_users[$from_id]; + } + echo '","className" : "'.$className.'"'; + } + + echo "}"; + $i++; + } + } + + /*$time = microtime(true) - $start; + + + if($_SESSION['id'] == 6635){ + echo "\n клиенты".$time." сек."; + }*/ + if($view !='overdue_tasks' && !isset($_POST['event'])){ + if (isset($post['start'])) { + $startDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') >='".date('m-d', strtotime($post['start']))."'"; + } + + if (isset($post['end'])) { + $endDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') < '".date('m-d', strtotime($post['end']))."'"; + } + $sql = "SELECT id, fio, birthday FROM clients WHERE cancel=0 AND who_work = ".$_SESSION['id']." $bd_usl $part_task AND ".$startDateWhereBirthday." AND ".$endDateWhereBirthday; + //echo $sql; + $q = mysql_query($sql); + while ($b = mysql_fetch_assoc($q)) { + if ($i > 0) { + echo ',{'; + } else { + echo '{'; + } + $fio = $b['fio']; + echo '"id" : "'.$i.'", '; + echo '"table_id" : "'.$b['id'].'", '; + echo '"start" : "'.date('Y-', strtotime($post['start'])).date('m-d', strtotime($b['birthday'])).'", '; + + echo '"client_id" : "'.$b['id'].'",'; + + //if ($event['type'] == 'call') { + + $className = "birthday"; + /* if ($event['calendar_view'] != 0) { + $className .= " viewed"; + }*/ + + echo '"title": "День рождения «'.$fio.'»","className" : "'.$className.'"'; + // } + echo "}"; + $i++; + } + + if (isset($post['start'])) + $startDateWhereBirthday = "DATE_FORMAT(employees.birthday, '%m-%d') >= '".date('m-d', strtotime($post['start']))."'"; + + if (isset($post['end'])) + $endDateWhereBirthday = "DATE_FORMAT(employees.birthday, '%m-%d') < '".date('m-d', strtotime($post['end']))."'"; + + $userId = $_SESSION['id']; + $user = new User; + $user->get($userId); + if ($_SESSION['users_admin']) { + $userId = $user->agencyId; + } + $sql = "SELECT employees.id, employees.partner_id, employees.name, employees.birthday @@ -781,8 +855,8 @@ if($_SESSION['id'] == 6635){ AND $startDateWhereBirthday AND $endDateWhereBirthday"; - if (!$_SESSION['agency']) { - $sql .= " AND ( + if (!$_SESSION['agency']) { + $sql .= " AND ( employees.created_by = " . $userId . " OR employees.updated_by = " . $userId . " OR employees.id IN ( @@ -791,47 +865,47 @@ if($_SESSION['id'] == 6635){ WHERE clients.who_work = " . $userId . " ) )"; - } + } - $sql .= " GROUP BY employees.id"; + $sql .= " GROUP BY employees.id"; - $q = mysql_query($sql); - while ($b = mysql_fetch_assoc($q)) { + $q = mysql_query($sql); + while ($b = mysql_fetch_assoc($q)) { - if ($i > 0) - echo ',{'; - else - echo '{'; + if ($i > 0) + echo ',{'; + else + echo '{'; - echo '"id" : "' . $i . '", '; - echo '"employee_id" : "' . $b['id'] .'", '; - echo '"start" : "' . date('Y-', strtotime($post['start'])) . date('m-d', strtotime($b['birthday'])) . '", '; - echo '"title": "День рождения партнёра «' . $b['name'] . '»", "className" : "birthday"'; - echo "}"; - $i++; - } + echo '"id" : "' . $i . '", '; + echo '"employee_id" : "' . $b['id'] .'", '; + echo '"start" : "' . date('Y-', strtotime($post['start'])) . date('m-d', strtotime($b['birthday'])) . '", '; + echo '"title": "День рождения партнёра «' . $b['name'] . '»", "className" : "birthday"'; + echo "}"; + $i++; + } - // Дни рождения сотрудников агенства - $agencyId = $_SESSION['id']; - $user = new User; - $user->get($userId); - if ($_SESSION['id_manager']) - $agencyId = $_SESSION['id_manager']; + // Дни рождения сотрудников агенства + $agencyId = $_SESSION['id']; + $user = new User; + $user->get($userId); + if ($_SESSION['id_manager']) + $agencyId = $_SESSION['id_manager']; - if ($_SESSION['users_admin']) { - $agencyId = $user->agencyId; - } + if ($_SESSION['users_admin']) { + $agencyId = $user->agencyId; + } - if (isset($post['start'])) - $startDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') >='".date('m-d', strtotime($post['start']))."'"; + if (isset($post['start'])) + $startDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') >='".date('m-d', strtotime($post['start']))."'"; - if (isset($post['end'])) - $endDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') < '".date('m-d', strtotime($post['end']))."'"; + if (isset($post['end'])) + $endDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') < '".date('m-d', strtotime($post['end']))."'"; - $usersIds = User::getAllAgencyUsers($agencyId); - if (!empty($usersIds)) { - $sql = "SELECT id, + $usersIds = User::getAllAgencyUsers($agencyId); + if (!empty($usersIds)) { + $sql = "SELECT id, first_name, last_name, middle_name, @@ -846,33 +920,33 @@ if($_SESSION['id'] == 6635){ AND $endDateWhereBirthday GROUP BY id"; - //echo $sql; + //echo $sql; - $q = mysql_query($sql); - while ($b = mysql_fetch_assoc($q)) { + $q = mysql_query($sql); + while ($b = mysql_fetch_assoc($q)) { - if ($i > 0) - echo ',{'; - else - echo '{'; + if ($i > 0) + echo ',{'; + else + echo '{'; - echo '"id" : "' . $i . '", '; - echo '"user_id" : "' . $b['id'] .'", '; - echo '"start" : "' . date('Y-', strtotime($post['start'])) . date('m-d', strtotime($b['birthday'])) . '", '; - echo '"title": "День рождения у «' . trim($b['last_name'] . ' ' . $b['first_name'] . ' ' . $b['middle_name']) . '», сотрудника Вашего агентства.", "className" : "birthday"'; - echo "}"; - $i++; + echo '"id" : "' . $i . '", '; + echo '"user_id" : "' . $b['id'] .'", '; + echo '"start" : "' . date('Y-', strtotime($post['start'])) . date('m-d', strtotime($b['birthday'])) . '", '; + echo '"title": "День рождения у «' . trim($b['last_name'] . ' ' . $b['first_name'] . ' ' . $b['middle_name']) . '», сотрудника Вашего агентства.", "className" : "birthday"'; + echo "}"; + $i++; + } } + } + /* $time = microtime(true) - $start; + + if($_SESSION['id'] == 6635){ + echo "\n дни ".$time." сек."; + }*/ } - /* $time = microtime(true) - $start; - - -if($_SESSION['id'] == 6635){ - echo "\n дни ".$time." сек."; - }*/ - } } echo ']';