141 lines
5.4 KiB
PHP
141 lines
5.4 KiB
PHP
<?php
|
||
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
||
if(isset($_POST['add_edit_client'])){
|
||
$post = clearInputData($_POST);
|
||
$result = Clients::addEdit($post);
|
||
if($result == $post['id']){
|
||
Clients::updateFunnel($post);
|
||
echo $result;
|
||
} else {
|
||
echo $result;
|
||
}
|
||
}
|
||
if(isset($_POST['stage_edit'])){
|
||
|
||
$stage = (int)$_POST['stage_edit'];
|
||
$id = (int)$_POST['id'];
|
||
$reqId = (int)$_POST['id_req'];
|
||
|
||
if($id > 0 || $reqId > 0){
|
||
|
||
$arrs = ['', 'Новый', 'В работе','Презентация','Показ','Бронь','Подаем на ипотеку','Сделка', 'Закрыт'];
|
||
|
||
$sql = "SELECT `stage`, `deleted`, confirm, who_work FROM clients WHERE id = {$id}";
|
||
if($reqId > 0){
|
||
$sql = "SELECT `stage`, `deleted`, confirm, who_work FROM requisitions WHERE id = {$reqId}";
|
||
|
||
}
|
||
|
||
$q = mysql_query($sql);
|
||
$r = mysql_fetch_assoc($q);
|
||
$confirm = (int)$r['confirm'];
|
||
if($r['deleted'] > 0) {
|
||
$r['stage'] = 8;
|
||
|
||
}
|
||
if($confirm == 10) {
|
||
$confirm = 1;
|
||
if($r['who_work'] == 0){
|
||
$confirm = 0;
|
||
}
|
||
}
|
||
$prev_stage = $arrs[$r['stage']];
|
||
$dop_text = 'c «'.$prev_stage.'» на «'.$arrs[$stage].'»';
|
||
$sql = "UPDATE `clients` SET `stage` = '{$stage}', `deleted` = 0, confirm={$confirm} WHERE `id` = {$id}";
|
||
if($reqId > 0){
|
||
$sql = "UPDATE `requisitions` SET `stage` = '{$stage}', `deleted` = 0, confirm={$confirm} WHERE `id` = {$reqId}";
|
||
|
||
}
|
||
//echo $sql;
|
||
mysql_query($sql);
|
||
$date = time();
|
||
$create_at = date('Y-m-d H:i:s', $date);
|
||
$in_sql = "INSERT INTO `events_clients` (`user_id`, `client_id`, `from_id`, `event`, `read`, `dop_text`) VALUES (".$_SESSION['id'].", {$id}, '0', 'stageedit', '1', '{$dop_text}')";
|
||
$in_history = "INSERT INTO `steps_history`(`client_id`, `step_id`, `date`, `type`, `user_id`, `created_at`)
|
||
VALUES ({$id}, {$r['stage']}, {$date}, 1, {$_SESSION['id']}, '{$create_at}')";
|
||
if($stage > $r['stage']){
|
||
for($i=($r['stage']+1); $i<$stage; $i++){
|
||
$in_history .= ", ({$id}, {$i}, {$date}, 1, {$_SESSION['id']}, '{$create_at}')";
|
||
}
|
||
}
|
||
if($reqId > 0){
|
||
$in_sql = "INSERT INTO `events_clients` (`user_id`, `req_id`, `from_id`, `event`, `read`, `dop_text`) VALUES (".$_SESSION['id'].", {$reqId}, '0', 'stageedit', '1', '{$dop_text}')";
|
||
$in_history = "INSERT INTO `steps_history`(`req_id`, `step_id`, `date`, `type`, `user_id`, `created_at`)
|
||
VALUES ({$reqId}, {$r['stage']}, {$date}, 1, {$_SESSION['id']}, '{$create_at}')";
|
||
if($stage > $r['stage']){
|
||
for($i=($r['stage']+1); $i<$stage; $i++){
|
||
$in_history .= ", ({$reqId}, {$i}, {$date}, 1, {$_SESSION['id']}, '{$create_at}')";
|
||
}
|
||
}
|
||
}
|
||
|
||
mysql_query($in_sql);
|
||
mysql_query($in_history);
|
||
if(isset($_POST['turn'])){
|
||
$set_turns = json_decode(html_entity_decode($_POST['turn']), ENT_QUOTES);
|
||
$time = time();
|
||
foreach($set_turns as $key => $turn){
|
||
$sql = "UPDATE `clients` SET `turntime` = ".$time.", `turn` = ".$turn." WHERE `id` = {$key}";
|
||
if($reqId > 0){
|
||
$sql = "UPDATE `requisitions` SET `turntime` = ".$time.", `turn` = ".$turn." WHERE `id` = {$key}";
|
||
|
||
}
|
||
// echo $sql;
|
||
mysql_query($sql);
|
||
}
|
||
}
|
||
}
|
||
|
||
echo 1;
|
||
}
|
||
|
||
if(isset($_POST['done_event'])){
|
||
$event_id = (int)$_POST['done_event'];
|
||
$done = (int)$_POST['done'];
|
||
$sql = "UPDATE `user_client_events` SET `calendar_view` = {$done} WHERE `id` = {$event_id}";
|
||
|
||
mysql_query($sql);
|
||
}
|
||
|
||
if(isset($_POST['verifity_phone'])){
|
||
//$phone = $_POST['verifity_phone'];
|
||
$post = clearInputData($_POST);
|
||
$res = Clients::verifity_phone($post);
|
||
echo $res;
|
||
/* $error_add = Clients::addEdit($post);
|
||
if(!$error_add){
|
||
echo 1;
|
||
} else {
|
||
echo $error_add;
|
||
}*/
|
||
}
|
||
|
||
$is_watched = $_POST['is_watched'];
|
||
$watched_req_id = $_POST['watched_req_id'];
|
||
$watched_obj_id = $_POST['watched_obj_id'];
|
||
$watched_user_id = $_POST['watched_user_id'];
|
||
|
||
if ($is_watched !== null) {
|
||
if (!$watched_req_id || !$watched_obj_id || !$watched_user_id) {
|
||
echo json_encode(['status' => 'error', 'message' => 'Missing parameters']);
|
||
exit;
|
||
}
|
||
|
||
$sql_check = "SELECT id FROM watched_requisitions
|
||
WHERE user_id = $watched_user_id AND req_id = $watched_req_id AND object_id = $watched_obj_id";
|
||
$result = mysql_query($sql_check);
|
||
|
||
if (mysql_num_rows($result) > 0) {
|
||
$sql_update = "UPDATE watched_requisitions
|
||
SET watched = $is_watched
|
||
WHERE user_id = $watched_user_id AND req_id = $watched_req_id AND object_id = $watched_obj_id";
|
||
mysql_query($sql_update);
|
||
} else {
|
||
$sql_insert = "INSERT INTO watched_requisitions (user_id, req_id, object_id, watched)
|
||
VALUES ($watched_user_id, $watched_req_id, $watched_obj_id, $is_watched)";
|
||
mysql_query($sql_insert);
|
||
}
|
||
|
||
echo json_encode(['status' => 'success', 'watched' => $is_watched]);
|
||
}
|