0 or client_id>0)"; $q = mysql_query($sql); while($r = mysql_fetch_assoc($q)){ $sql_in = "SELECT `agency_name`, `first_name`, `last_name`, `middle_name`, `agency`, `manager` FROM `users` WHERE `id` = '".$r['user_id']."'"; $q_in = mysql_query($sql_in); $r_in = mysql_fetch_assoc($q_in); $post = "Сотрудник "; if($r_in['agency'] == 1) $post = "Агентство "; else if($r_in['manager'] == 1) $post = "Менеджер "; $sql_cl = "SELECT `fio` FROM `clients` WHERE `id` = ".$r['client_id']; if($r['req_id'] > 0){ $sql_cl = "SELECT `name` as `fio`, object_id, type_id, `reservation_updated_at` FROM `requisitions` WHERE `id` = ".$r['req_id']; } $q_cl = mysql_query($sql_cl); $r_cl = mysql_fetch_assoc($q_cl); //$result[] = array('id' => $r['id'], 'from' => $r['from_id'],'post' => $post, 'fio' => $r_in['fio'], 'in' => $r['user_id'], 'fio_client' => $r_cl['fio'], 'client_id' => $r['client_id']); $tr = 0; $objectString = ''; $objectNum = 0; $type_req = 0; $agency_fio = trim($r_in['last_name'] . ' ' . $r_in['first_name'] . ' ' . $r_in['middle_name']); if($r_in['agency'] == 1) { $agency_fio = $r_in['agency_name']; } if($r['event'] == 'transmitted_parallel'){ $tr = 1; } else { if($r['req_id'] > 0 && $r_cl['object_id'] > 0){ $objectNum++; $sql_obj = "SELECT nazv FROM `objects` WHERE id= $r_cl[object_id]"; $q_obj = mysql_query($sql_obj); $r_obj = mysql_fetch_assoc($q_obj); $type_req = $r_cl['type_id']; $objectString = $objectString . ($objectNum > 1 ? ", " : "") . $r_obj['nazv']; } else { $sql_client = "SELECT objects FROM clients WHERE id=$r[client_id]"; $q_client = mysql_query($sql_client); $r_client = mysql_fetch_assoc($q_client); $objects = json_decode(html_entity_decode($r_client['objects']), true); foreach($objects as $object){ $objectNum++; $sql_obj = "SELECT nazv FROM `objects` WHERE id= $object"; $q_obj = mysql_query($sql_obj); $r_obj = mysql_fetch_assoc($q_obj); $objectString = $objectString . ($objectNum > 1 ? ", " : "") . $r_obj['nazv']; } } } $objText = ''; if($objectNum > 0) { if($objectNum > 1){ $objText = ' и объекты ' . $objectString; } else { $objText = ' и объект ' . $objectString; } if($r['req_id'] > 0 && $type_req == 4){ $objText = ' по объекту ' . $objectString; } } /** * Complex status reservation ID ($csr_id) */ $csr_id = null; $event_type = preg_split("/_res_|ext_/", $r['event']); $event_type_status = (string)$event_type[1]; if (strpos($r['event'], 'extension_reservation_') !== false) { $csr_id = explode('extension_reservation_', $r['event'])[1]; } if ($csr_id) { /** * Complex status reservation ($csr) */ $complexStatus = new ComplexStatus; $csr = $complexStatus::getReservationById($csr_id); $now = new DateTime("now", new \DateTimeZone("Europe/Moscow")); $reservation_updated_at = new DateTime($r_cl['reservation_updated_at']); $reservation_updated_at = $reservation_updated_at->modify('+' . $csr['booking_day'] . ' day'); $reservation_updated_at = $reservation_updated_at->modify('+' . $csr['booking_hour'] . ' hour'); if ($now >= $reservation_updated_at) { $result['extension_reservations'][] = array( 'id' => (int)$r['id'], 'in' => (int)$r['user_id'], 'tr' => $tr, 'fio' => $agency_fio, 'from' => (int)$r['from_id'], 'post' => $post, 'req_id' => (int)$r['req_id'], 'dop_text' => function_exists('mask_text_for_hide_user') ? mask_text_for_hide_user($r['dop_text']) : $r['dop_text'], 'client_id' => (int)$r['client_id'], 'specify_comment_confirm' => (bool)$csr['specify_comment_confirm'], 'specify_comment_unconfirm' => (bool)$csr['specify_comment_unconfirm'] ); } } else if ($event_type_status === 'confirming' || $event_type_status === 'unconfirming') { $result['confirm_and_unconfirm_extension_reservations'][] = array( 'id' => (int)$r['id'], 'in' => (int)$r['user_id'], 'tr' => $tr, 'fio' => $agency_fio, 'from' => (int)$r['from_id'], 'post' => $post, 'req_id' => (int)$r['req_id'], 'dop_text' => function_exists('mask_text_for_hide_user') ? mask_text_for_hide_user($r['dop_text']) : $r['dop_text'], 'client_id' => (int)$r['client_id'], ); } else { $result['others'][] = array('id' => $r['id'], 'from' => $r['from_id'], 'post' => $post, 'fio' => $agency_fio, 'in' => $r['user_id'], 'fio_client' => $r_cl['fio'], 'client_id' => $r['client_id'], 'req_id'=>$r['req_id'], 'tr'=>$tr, 'objects'=> $objText); } } $result['total'] = array_sum(array_map("count", $result)); if(empty($result)) echo 0; else echo json_encode($result); }