596 lines
25 KiB
PHP
596 lines
25 KiB
PHP
<?php
|
||
|
||
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
||
echo '[';
|
||
if ($_SESSION['id']) {
|
||
|
||
$post = clearInputData($_POST);
|
||
|
||
$startDateWhere = "1";
|
||
$endDateWhere = "1";
|
||
|
||
if (isset($post['start'])) {
|
||
$startDateWhere = "schedule_date > '".$post['start']."'";
|
||
}
|
||
|
||
if (isset($post['end'])) {
|
||
$endDateWhere = "schedule_date < '".$post['end']."'";
|
||
}
|
||
|
||
$where = "1";
|
||
|
||
if(isset($post['active']) && $post['active'] == 1){
|
||
$where = "calendar_view = 0";
|
||
}
|
||
|
||
// Общее хранилище deal_id для дедупликации
|
||
$seenDealIds = array();
|
||
$deals = array();
|
||
|
||
// Явные колонки (НЕ e.*): user_object_events получил 19-ю колонку moved_on_copy → e.* стал 20, а вторая ветка
|
||
// UNION = 19 → запрос падал с «different number of columns» → задачи по своим объектам пропадали из календаря.
|
||
$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, e.deal_id, o.nazv from user_object_events e, objects o WHERE user_id = $_SESSION[id] and o.id=e.object_id and schedule_date is not null and $where 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, 0 as deal_id,
|
||
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 = $_SESSION[id] and $where and $startDateWhere and $endDateWhere";
|
||
$rez = mysql_query($sql);
|
||
/*if($_SESSION['id'] == 21113){
|
||
echo $sql;
|
||
}*/
|
||
|
||
$i = 0;
|
||
while ($event = mysql_fetch_assoc($rez)) {
|
||
// Deal-события обрабатываются отдельно во втором цикле
|
||
if ($event['type'] == 'deal' && !empty($event['deal_id'])) {
|
||
continue;
|
||
}
|
||
|
||
if ($i > 0) {
|
||
echo ',{';
|
||
} else {
|
||
echo '{';
|
||
}
|
||
echo '"id" : "'.$i.'", ';
|
||
echo '"table_id" : "'.$event['id'].'", ';
|
||
echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", ';
|
||
// Для сделок не выводим object_id чтобы клик шёл на client_id/req_id
|
||
if ($event['type'] != 'deal') {
|
||
echo '"object_id" : "'.$event['object_id'].'",';
|
||
}
|
||
|
||
$event['nazv'] = str_replace('"', "'", $event['nazv']);
|
||
$event['nazv'] = str_replace('"', "'", $event['nazv']);
|
||
|
||
if ($event['type'] == 'moderation') {
|
||
$className = "moderation";
|
||
if ($event['calendar_view'] != 0) {
|
||
$className .= " viewed";
|
||
}
|
||
|
||
echo '"title": "Модерация '.$event['nazv'].'","className" : "'.$className.'"';
|
||
}
|
||
|
||
if ($event['type'] == 'sub_moderation') {
|
||
$className = "moderation";
|
||
if ($event['calendar_view'] != 0) {
|
||
$className .= " viewed";
|
||
}
|
||
|
||
echo '"title": "Комментарий к модерация '.$event['nazv'].'","className" : "'.$className.'"';
|
||
}
|
||
|
||
if ($event['type'] == 'call') {
|
||
|
||
$className = "call";
|
||
if ($event['calendar_view'] != 0) {
|
||
$className .= " viewed";
|
||
}
|
||
|
||
echo '"title": "Звонок '.$event['nazv'].'","className" : "'.$className.'"';
|
||
}
|
||
|
||
if ($event['type'] == 'meet') {
|
||
|
||
$className = "meet";
|
||
if ($event['calendar_view'] != 0) {
|
||
$className .= " viewed";
|
||
}
|
||
|
||
echo '"title": "Встреча '.$event['nazv'].'","className" : "'.$className.'"';
|
||
}
|
||
|
||
if ($event['type'] == 'show') {
|
||
|
||
$className = "showing";
|
||
if ($event['calendar_view'] != 0) {
|
||
$className .= " viewed";
|
||
}
|
||
|
||
echo '"title": "Показ '.$event['nazv'].'","className" : "'.$className.'"';
|
||
}
|
||
|
||
if ($event['type'] == 'deal') {
|
||
|
||
$className = "deal";
|
||
if ($event['calendar_view'] != 0) {
|
||
$className .= " viewed";
|
||
}
|
||
|
||
// Подтягиваем название сделки
|
||
$dealTitle = $event['nazv'];
|
||
if (!empty($event['deal_id'])) {
|
||
if (!isset($deals[$event['deal_id']])) {
|
||
$q_deal = mysql_query("SELECT title FROM deals WHERE id = " . intval($event['deal_id']) . " LIMIT 1");
|
||
if ($q_deal && mysql_num_rows($q_deal) > 0) {
|
||
$deals[$event['deal_id']] = mysql_fetch_assoc($q_deal)['title'];
|
||
} else {
|
||
$deals[$event['deal_id']] = '';
|
||
}
|
||
}
|
||
$dealTitle = $deals[$event['deal_id']] ?: $event['nazv'];
|
||
}
|
||
|
||
echo '"title": "'.str_replace('"', "'", $dealTitle).'","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++;
|
||
}
|
||
|
||
// Найденные листинги парсера: задачи пользователя из своей таблицы. Offset-free: object_id = РЕАЛЬНЫЙ el.id
|
||
// (реальный el.id коллизит с objects.id), листинг различаем по флагу is_external=1.
|
||
// table_id = реальный id события — завершение адресует конкретную задачу. LEFT JOIN: листинг мог уйти по TTL,
|
||
// задача остаётся (адрес тогда пустой). Комментарии — не задачи, пропускаем. deal/moderation у листингов нет.
|
||
$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 = $_SESSION[id] AND e.schedule_date IS NOT NULL AND $where AND $startDateWhere AND $endDateWhere";
|
||
$rezListing = mysql_query($sqlListing);
|
||
while ($rezListing && ($event = mysql_fetch_assoc($rezListing))) {
|
||
if ($event['type'] == 'comment') {
|
||
continue;
|
||
}
|
||
$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']);
|
||
|
||
if ($i > 0) {
|
||
echo ',{';
|
||
} else {
|
||
echo '{';
|
||
}
|
||
echo '"id" : "'.$i.'", ';
|
||
echo '"table_id" : "'.$event['id'].'", '; // РЕАЛЬНЫЙ id события: завершение адресует конкретную задачу
|
||
echo '"from" : "listing", '; // сигнал для setEventViewed-гарда: завершать в external_listing_events
|
||
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'].'",'; // реальный el.id: клик открывает окно задач листинга (openEventsWindow)
|
||
|
||
$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.'","className" : "'.$className.'"';
|
||
} else if ($event['type'] == 'show') {
|
||
echo '"title": "Показ '.$label.'","className" : "'.$className.'"';
|
||
} else if ($event['type'] == 'even') {
|
||
echo '"title": "'.$evName.' '.$label.'","className" : "'.$className.'"';
|
||
} else {
|
||
echo '"title": "Звонок '.$label.'","className" : "'.$className.'"';
|
||
}
|
||
|
||
echo "}";
|
||
$i++;
|
||
}
|
||
|
||
$sql = "SELECT *, deal_id FROM user_client_events WHERE user_id = $_SESSION[id] and schedule_date is not null and cancel=0 and $where and $startDateWhere and $endDateWhere";
|
||
$agencyId = User::getUserAgencyID();
|
||
if($agencyId != 7384){
|
||
$sql = "SELECT *, deal_id FROM user_client_events WHERE user_id = $_SESSION[id] and megafon=0 and mango=0 and telphin=0 and beeline=0 and mts=0 and tele2=0 and allo=0 and schedule_date is not null and cancel=0 and $where and $startDateWhere and $endDateWhere";
|
||
}
|
||
$rez = mysql_query($sql);
|
||
|
||
// Собираем все deal-события по deal_id
|
||
$dealEvents = array();
|
||
while ($event = mysql_fetch_assoc($rez)) {
|
||
if ($event['type'] == 'deal' && !empty($event['deal_id'])) {
|
||
$did = (int)$event['deal_id'];
|
||
if (!isset($dealEvents[$did])) {
|
||
$dealEvents[$did] = array();
|
||
}
|
||
$dealEvents[$did][] = $event;
|
||
} else {
|
||
// Не сделки — выводим сразу
|
||
if ($i > 0) { echo ',{'; } else { echo '{'; }
|
||
$fio = '';
|
||
if($event['client_id'] > 0){
|
||
$sql_cl = "SELECT fio from clients WHERE id=$event[client_id]";
|
||
$q_cl = mysql_query($sql_cl);
|
||
$fio = str_replace("\\","/", mysql_fetch_assoc($q_cl)['fio']);
|
||
} else if($event['req_id'] > 0) {
|
||
$sql_cl = "SELECT name from requisitions WHERE id=$event[req_id]";
|
||
$q_cl = mysql_query($sql_cl);
|
||
$fio = mysql_fetch_assoc($q_cl)['name'];
|
||
}
|
||
$fio = str_replace('"', "'", $fio);
|
||
$fio = str_replace('"', "'", $fio);
|
||
echo '"id" : "'.$i.'", ';
|
||
echo '"table_id" : "'.$event['id'].'", ';
|
||
echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", ';
|
||
if($fio == ''){
|
||
$sql_u = "SELECT first_name, last_name, middle_name FROM users WHERE id = ".$event['user_id'];
|
||
$q_u = mysql_query($sql_u);
|
||
$r_u = mysql_fetch_assoc($q_u);
|
||
$fio = '(исполнитель '.trim($r_u['last_name'] . ' ' . $r_u['first_name'] . ' ' . $r_u['middle_name']).')';
|
||
}
|
||
echo '"client_id" : "'.$event['client_id'].'",';
|
||
echo '"req_id" : "'.$event['req_id'].'",';
|
||
if ($event['type'] == 'comment') {
|
||
$className = "comment";
|
||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||
echo '"title": "Комментарий '.$fio.'","className" : "'.$className.'"';
|
||
}
|
||
if ($event['type'] == 'call') {
|
||
$className = "call";
|
||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||
echo '"title": "Звонок '.$fio.'","className" : "'.$className.'"';
|
||
}
|
||
if ($event['type'] == 'meet') {
|
||
$className = "meet";
|
||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||
echo '"title": "Встреча '.$fio.'","className" : "'.$className.'"';
|
||
}
|
||
if ($event['type'] == 'show') {
|
||
$className = "showing";
|
||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||
echo '"title": "Показ '.$fio.'","className" : "'.$className.'"';
|
||
}
|
||
if ($event['type'] == 'even') {
|
||
$className = "even";
|
||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||
echo '"title": "'.$event['name'].' '.$fio.'","className" : "'.$className.'"';
|
||
}
|
||
echo "}";
|
||
$i++;
|
||
}
|
||
}
|
||
|
||
// Выводим по одному событию на сделку с приоритетом
|
||
foreach ($dealEvents as $did => $events) {
|
||
// Подтягиваем данные сделки
|
||
if (!isset($deals[$did])) {
|
||
$q_deal = mysql_query("SELECT title, side_one_requisition_id, side_two_requisition_id FROM deals WHERE id = " . $did . " LIMIT 1");
|
||
$deals[$did] = ($q_deal && mysql_num_rows($q_deal) > 0) ? mysql_fetch_assoc($q_deal) : null;
|
||
}
|
||
$deal = $deals[$did];
|
||
$dealTitle = $deal ? $deal['title'] : '';
|
||
$sideOneReqId = $deal ? (int)$deal['side_one_requisition_id'] : 0;
|
||
$sideTwoReqId = $deal ? (int)$deal['side_two_requisition_id'] : 0;
|
||
|
||
// Приоритет: 1) заявка стороны 1, 2) заявка стороны 2, 3) объект
|
||
$bestEvent = null;
|
||
$bestType = '';
|
||
|
||
// 1. Ищем событие с req_id == side_one_requisition_id
|
||
foreach ($events as $ev) {
|
||
if ($sideOneReqId > 0 && (int)$ev['req_id'] == $sideOneReqId) {
|
||
$bestEvent = $ev;
|
||
$bestType = 'req_one';
|
||
break;
|
||
}
|
||
}
|
||
|
||
// 2. Ищем событие с req_id == side_two_requisition_id
|
||
if (!$bestEvent) {
|
||
foreach ($events as $ev) {
|
||
if ($sideTwoReqId > 0 && (int)$ev['req_id'] == $sideTwoReqId) {
|
||
$bestEvent = $ev;
|
||
$bestType = 'req_two';
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 3. Ищем событие с client_id > 0
|
||
if (!$bestEvent) {
|
||
foreach ($events as $ev) {
|
||
if (!empty($ev['client_id'])) {
|
||
$bestEvent = $ev;
|
||
$bestType = 'client';
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 4. Ищем событие с req_id > 0
|
||
if (!$bestEvent) {
|
||
foreach ($events as $ev) {
|
||
if (!empty($ev['req_id'])) {
|
||
$bestEvent = $ev;
|
||
$bestType = 'req';
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 5. Берём любое
|
||
if (!$bestEvent) {
|
||
$bestEvent = $events[0];
|
||
$bestType = 'any';
|
||
}
|
||
|
||
if ($i > 0) { echo ',{'; } else { echo '{'; }
|
||
echo '"id" : "'.$i.'", ';
|
||
echo '"table_id" : "'.$bestEvent['id'].'", ';
|
||
echo '"start" : "'.date(DateTime::ATOM, strtotime($bestEvent['schedule_date'])).'", ';
|
||
|
||
// Для клика: передаём client_id или req_id (без object_id)
|
||
if (!empty($bestEvent['client_id'])) {
|
||
echo '"client_id" : "'.$bestEvent['client_id'].'",';
|
||
echo '"req_id" : "0",';
|
||
} else if (!empty($bestEvent['req_id'])) {
|
||
echo '"client_id" : "0",';
|
||
echo '"req_id" : "'.$bestEvent['req_id'].'",';
|
||
} else {
|
||
echo '"client_id" : "0",';
|
||
echo '"req_id" : "0",';
|
||
}
|
||
|
||
$className = "deal";
|
||
if ($bestEvent['calendar_view'] != 0) { $className .= " viewed"; }
|
||
|
||
echo '"title": "'.str_replace('"', "'", $dealTitle).'","className" : "'.$className.'"';
|
||
echo "}";
|
||
$i++;
|
||
}
|
||
|
||
//if($_SESSION['id'] == 5238){
|
||
if (isset($post['start'])) {
|
||
// echo $post['start'];
|
||
$startDateWhereBirthday = "DATE_FORMAT(birthday, '%Y-%m-%d') >='".date('1930-m-d', strtotime($post['start']))."'";
|
||
/*if (date('m', strtotime($post['start']))=='12' && (date('m', strtotime($post['end']))=='01' || date('m', strtotime($post['end']))=='02')){
|
||
$startDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') >='01-01'";
|
||
}*/
|
||
}
|
||
|
||
if (isset($post['end'])) {
|
||
$endDateWhereBirthday = "DATE_FORMAT(birthday, '%Y-%m-%d') < '".date('Y-m-d', strtotime($post['end']))."'";
|
||
//echo date('m', strtotime($post['end']))."\n";
|
||
/* if (date('m', strtotime($post['end']))=='01' && (date('m', strtotime($post['start']))=='12' || date('m', strtotime($post['start']))=='11')){
|
||
$endDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') <='12-31'";
|
||
}*/
|
||
|
||
}
|
||
$sql = "SELECT id, fio, birthday FROM clients WHERE cancel=0 AND who_work = ".$_SESSION['id']." AND ".$startDateWhereBirthday." AND ".$endDateWhereBirthday;
|
||
/* if($_SESSION['id'] == 5238){
|
||
echo $sql;
|
||
}*/
|
||
$q = mysql_query($sql);
|
||
while ($b = mysql_fetch_assoc($q)) {
|
||
if ($i > 0) {
|
||
echo ',{';
|
||
} else {
|
||
echo '{';
|
||
}
|
||
$fio = $b['fio'];
|
||
|
||
$fio = str_replace('"', "'", $fio);
|
||
$fio = str_replace('"', "'", $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(date('Y-', strtotime($post['start'])) != date('Y-', strtotime($post['end']))){
|
||
if ($i > 0) {
|
||
echo ',{';
|
||
} else {
|
||
echo '{';
|
||
}
|
||
$fio = $b['fio'];
|
||
echo '"id" : "'.$i.'", ';
|
||
echo '"table_id" : "'.$b['id'].'", ';
|
||
echo '"start" : "'.date('Y-', strtotime($post['end'])).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, '%Y-%m-%d') >= '".date('1930-m-d', strtotime($post['start']))."'";
|
||
/* if (date('m', strtotime($post['start']))=='12' && (date('m', strtotime($post['end']))=='01' || date('m', strtotime($post['end']))=='02')){
|
||
$startDateWhereBirthday = "DATE_FORMAT(employees.birthday, '%m-%d') >= '01-01'";
|
||
}*/
|
||
}
|
||
|
||
if (isset($post['end'])){
|
||
$endDateWhereBirthday = "DATE_FORMAT(employees.birthday, '%Y-%m-%d') < '".date('Y-m-d', strtotime($post['end']))."'";
|
||
|
||
//echo date('m', strtotime($post['end']))."\n";
|
||
/* if (date('m', strtotime($post['end']))=='01' && (date('m', strtotime($post['start']))=='12' || date('m', strtotime($post['start']))=='11')){
|
||
$endDateWhereBirthday = "DATE_FORMAT(employees.birthday, '%m-%d') <= '12-31'";
|
||
}*/
|
||
}
|
||
|
||
$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
|
||
FROM `partners_employees` AS employees
|
||
LEFT JOIN `users` AS users ON employees.created_by = users.id OR employees.updated_by = users.id
|
||
WHERE (users.id = $userId OR users.id_manager = $userId OR users.id_manager IN (
|
||
SELECT id FROM `users` WHERE id_manager = $userId
|
||
))
|
||
AND employees.birthday_notify > 0 AND employees.status > 0
|
||
AND $startDateWhereBirthday
|
||
AND $endDateWhereBirthday";
|
||
|
||
if (!$_SESSION['agency']) {
|
||
$sql .= " AND (
|
||
employees.created_by = " . $userId . " OR
|
||
employees.updated_by = " . $userId . " OR
|
||
employees.id IN (
|
||
SELECT clients.employee_id
|
||
FROM `clients` AS clients
|
||
WHERE clients.who_work = " . $userId . "
|
||
)
|
||
)";
|
||
}
|
||
|
||
$sql .= " GROUP BY employees.id";
|
||
|
||
$q = mysql_query($sql);
|
||
while ($b = mysql_fetch_assoc($q)) {
|
||
|
||
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++;
|
||
if(date('Y-', strtotime($post['start'])) != date('Y-', strtotime($post['end']))){
|
||
if ($i > 0)
|
||
echo ',{';
|
||
else
|
||
echo '{';
|
||
|
||
echo '"id" : "' . $i . '", ';
|
||
echo '"employee_id" : "' . $b['id'] .'", ';
|
||
echo '"start" : "' . date('Y-', strtotime($post['end'])) . 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'];
|
||
|
||
if ($_SESSION['users_admin']) {
|
||
$agencyId = $user->agencyId;
|
||
}
|
||
|
||
if (isset($post['start'])){
|
||
$startDateWhereBirthday = "DATE_FORMAT(birthday, '%Y-%m-%d') >='".date('1930-m-d', strtotime($post['start']))."'";
|
||
/* if (date('m', strtotime($post['start']))=='12' && (date('m', strtotime($post['end']))=='01' || date('m', strtotime($post['end']))=='02')){
|
||
$startDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') >='01-01'";
|
||
}*/
|
||
}
|
||
|
||
if (isset($post['end'])){
|
||
$endDateWhereBirthday = "DATE_FORMAT(birthday, '%Y-%m-%d') < '".date('Y-m-d', strtotime($post['end']))."'";
|
||
/* if (date('m', strtotime($post['end']))=='01' && (date('m', strtotime($post['start']))=='12' || date('m', strtotime($post['start']))=='11')){
|
||
$endDateWhereBirthday = "DATE_FORMAT(birthday, '%m-%d') <= '12-31'";
|
||
}*/
|
||
}
|
||
|
||
$usersIds = User::getAllAgencyUsers($agencyId);
|
||
if (!empty($usersIds)) {
|
||
$sql = "SELECT id,
|
||
first_name,
|
||
last_name,
|
||
middle_name,
|
||
birthday,
|
||
phone
|
||
FROM users
|
||
WHERE (
|
||
id IN (". implode(',', $usersIds) .") AND
|
||
id != $_SESSION[id]
|
||
)
|
||
AND $startDateWhereBirthday
|
||
AND $endDateWhereBirthday
|
||
GROUP BY id";
|
||
|
||
//echo $sql;
|
||
|
||
$q = mysql_query($sql);
|
||
while ($b = mysql_fetch_assoc($q)) {
|
||
|
||
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++;
|
||
if(date('Y-', strtotime($post['start'])) != date('Y-', strtotime($post['end']))){
|
||
if ($i > 0)
|
||
echo ',{';
|
||
else
|
||
echo '{';
|
||
|
||
echo '"id" : "' . $i . '", ';
|
||
echo '"user_id" : "' . $b['id'] .'", ';
|
||
echo '"start" : "' . date('Y-', strtotime($post['end'])) . date('m-d', strtotime($b['birthday'])) . '", ';
|
||
echo '"title": "День рождения у «' . trim($b['last_name'] . ' ' . $b['first_name'] . ' ' . $b['middle_name']) . '», сотрудника Вашего агентства.", "className" : "birthday"';
|
||
echo "}";
|
||
$i++;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
echo ']';
|