142 lines
5.4 KiB
PHP
142 lines
5.4 KiB
PHP
<?php
|
||
|
||
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
||
|
||
|
||
if ($_SESSION['id'] && $_POST['schedule_date'] && (($_POST['client_id'] && is_numeric($_POST['client_id'])) || ($_POST['req_id'] && is_numeric($_POST['req_id'])))) {
|
||
$post = clearInputData($_POST);
|
||
$scheduleDate = DateTime::createFromFormat('d.m.Y H:i', $post['schedule_date']);
|
||
$scheduleDate = "'".date("Y-m-d H:i:s", $scheduleDate->getTimestamp())."'";
|
||
|
||
$who_work = 0;
|
||
if(isset($_POST['who_work']) && (int)$_POST['who_work'] > 0){
|
||
$who_work = (int)$_POST['who_work'];
|
||
}
|
||
$req_id = 0;
|
||
if(isset($_POST['req_id']) && $_POST['req_id'] > 0){
|
||
$req_id = (int)$_POST['req_id'];
|
||
}
|
||
|
||
$sql="SELECT * FROM clients WHERE id=$post[client_id]";
|
||
if($req_id > 0){
|
||
$sql="SELECT * FROM requisitions WHERE id=$req_id";
|
||
}
|
||
$rez=mysql_query($sql);
|
||
$client = mysql_fetch_assoc($rez);
|
||
|
||
$idUser = $_SESSION['id'];
|
||
if ($client['who_work'] > 0 && $client['doer_clients'] == 0) {
|
||
// тому событие, чей клиент
|
||
$idUser = $client['who_work'];
|
||
}
|
||
if($post['from_id']){
|
||
$idUser = $post['from_id'];
|
||
if($post['from_id'] == 'not') $idUser = $_SESSION['id'];
|
||
}
|
||
|
||
$post['sum'] = str_replace(' ', '', $post['sum']);
|
||
|
||
if($who_work > 0){
|
||
$idUser = $who_work;
|
||
}
|
||
|
||
$from_id = $_SESSION['id'];
|
||
|
||
$calendar_view = 0;
|
||
if ($post[noEvent])
|
||
$calendar_view = 1;
|
||
|
||
// Формируем интерактивный документ
|
||
$document_id = null;
|
||
$document = Docs::fillInnerDocument($post['blank_id'], $post['client_id'], $post['object_id'], $post['clients_ids']);
|
||
|
||
if (isset($document['doc_id']))
|
||
$document_id = $document['doc_id'];
|
||
|
||
$client_id = $post['client_id'];
|
||
|
||
$funnel_id = 0;
|
||
$step_id = 0;
|
||
if($client['funnel_id']) $funnel_id = (int)$client['funnel_id'];
|
||
if($client['step_id']) $step_id = (int)$client['step_id'];
|
||
|
||
$sql = "INSERT INTO user_client_events(user_id, client_id, type, comment, sum, schedule_date, from_id, calendar_view, document_id, funnel_id, step_id) ";
|
||
$sql .= " VALUES($idUser, $client_id, 'deal', '$post[comment]', '$post[sum]', $scheduleDate, $from_id, $calendar_view, '$document_id', $funnel_id, $step_id)";
|
||
|
||
if($req_id > 0){
|
||
$sql = "INSERT INTO user_client_events(user_id, req_id, type, comment, sum, schedule_date, from_id, calendar_view, document_id, funnel_id, step_id) ";
|
||
$sql .= " VALUES($idUser, $req_id, 'deal', '$post[comment]', '$post[sum]', $scheduleDate, $from_id, $calendar_view, '$document_id', $funnel_id, $step_id)";
|
||
}
|
||
|
||
if (isset($post['object_id'])) {
|
||
$sql2 = "INSERT INTO user_object_events(user_id, object_id, type, comment, sum, schedule_date, document_id) ";
|
||
$sql2 .= " VALUES($idUser, $post[object_id], 'deal', '$post[comment]', '$post[sum]', $scheduleDate, '$document_id')";
|
||
}
|
||
|
||
if (isset($post['clients_ids'])) {
|
||
if(is_array($post['clients_ids'])){
|
||
foreach($post['clients_ids'] as $clientId){
|
||
if($client_id != $clientId){
|
||
$sql21 = "INSERT INTO user_client_events(user_id, client_id, type, comment, sum, schedule_date, from_id, calendar_view, document_id) ";
|
||
$sql21 .= " VALUES($idUser, $clientId, 'deal', '$post[comment]', '$post[sum]', $scheduleDate, $from_id, $calendar_view, '$document_id')";
|
||
mysql_query($sql21);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Событие о сделке в Историю клиента
|
||
$date = DateTime::createFromFormat('d.m.Y H:i', $post['schedule_date']);
|
||
$dop_text = "Запланирована сделка на " . date("Y-m-d H:i:s", $date->getTimestamp());
|
||
|
||
/*$client_id = $post['client_id'];
|
||
if ($req_id > 0)
|
||
$client_id = $req_id;
|
||
|
||
if (isset($post['object_id'])) {
|
||
$sql_obj = "SELECT id, nazv, adres FROM `objects` WHERE `id` = '$post[object_id]' LIMIT 1";
|
||
$rez_obj = mysql_query($sql_obj);
|
||
if ($obj = mysql_fetch_assoc($rez_obj)) {
|
||
$dop_text .= " по объекту " . '<a href="javascript:{}" data-id="'.$obj['id'].'" data-client="'.$client_id.'" class="show_object">'.$obj['nazv'].' ('.$obj['adres'].')</a>';
|
||
}
|
||
}
|
||
|
||
if (isset($post['sum']))
|
||
$dop_text .= "<br/>Сумма сделки: " . $post['sum'] ." руб.";
|
||
|
||
if (isset($post['sum']))
|
||
$dop_text .= "<br/>Комментарий: " . $post['comment'];*/
|
||
|
||
if ($document) {
|
||
$dop_text .= ", сформирован документ: " . '<a title="Скачать файл" download href="/ajax/getInnerDoc.php?id=' . $document['doc_id'] . '&download_pdf=true&t=' . time() . '">
|
||
<span class="file-span ti-file"></span>
|
||
<span class="file-name" data-id="' . $document['doc_id'] . '">' . $document['doc_name'] . '</span>
|
||
</a>.';
|
||
} else {
|
||
$dop_text .= ".";
|
||
}
|
||
|
||
$dop_text .= "<br/>От ";
|
||
|
||
$sql3 = "INSERT INTO `events_clients` (
|
||
user_id,
|
||
client_id,
|
||
from_id,
|
||
event,
|
||
`read`,
|
||
`dop_text`
|
||
) VALUES (
|
||
'".$idUser."',
|
||
'".$client_id."',
|
||
'".$from_id."',
|
||
'add_deal',
|
||
'1',
|
||
'".$dop_text."'
|
||
)";
|
||
|
||
if (!mysql_query($sql) || !((!empty($sql2)) ? mysql_query($sql2) : true) || !mysql_query($sql3))
|
||
echo mysql_error();
|
||
|
||
echo 'true';
|
||
}
|