Joywork/ajax/addClientShow.php
2026-05-22 21:21:54 +03:00

56 lines
2.2 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())."'";
$req_id = 0;
$who_work = 0;
if(isset($_POST['who_work']) && (int)$_POST['who_work'] > 0){
$who_work = (int)$_POST['who_work'];
}
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'];
}
if($who_work > 0){
$idUser = $who_work;
}
$from_id = $_SESSION['id'];
$calendar_view = 0;
if($post[noEvent]) $calendar_view = 1;
$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, address, schedule_date, from_id, calendar_view, funnel_id, step_id) ";
$sql .= " VALUES($idUser, $post[client_id], 'show', '$post[comment]', '$post[address]', $scheduleDate, $from_id, $calendar_view, $funnel_id, $step_id)";
if($req_id > 0){
$sql = "INSERT INTO user_client_events(user_id, req_id, type, comment, address, schedule_date, from_id, calendar_view, funnel_id, step_id) ";
$sql .= " VALUES($idUser, $req_id, 'show', '$post[comment]', '$post[address]', $scheduleDate, $from_id, $calendar_view, $funnel_id, $step_id)";
}
mysql_query($sql);
}