82 lines
3.1 KiB
PHP
82 lines
3.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/ajax/vue_php_function.php");
|
||
|
|
|
||
|
|
ini_set('display_errors', 1);
|
||
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
||
|
|
|
||
|
|
if($_SESSION['id'] && $_POST['partnerId'] && ($_POST['clientId'] || $_POST['reqId'])) {
|
||
|
|
|
||
|
|
$partner_id = (int)$_POST['partnerId'];
|
||
|
|
$client_id = (int)$_POST['clientId'];
|
||
|
|
$req_id = (int)$_POST['reqId'];
|
||
|
|
|
||
|
|
$sql_client = "SELECT doers, who_work FROM clients WHERE id=$client_id";
|
||
|
|
if($req_id > 0){
|
||
|
|
$sql_client = "SELECT doers, who_work FROM requisitions WHERE id=$req_id";
|
||
|
|
}
|
||
|
|
$q_client = mysql_query($sql_client);
|
||
|
|
$r_client = mysql_fetch_assoc($q_client);
|
||
|
|
|
||
|
|
if(!empty($r_client['doers'])){
|
||
|
|
$doers = json_decode(html_entity_decode($r_client['doers']), true);
|
||
|
|
|
||
|
|
if ($doers[$partner_id]) {
|
||
|
|
unset($doers[$partner_id]);
|
||
|
|
|
||
|
|
$sql_conf = "INSERT INTO `events_clients` (`user_id`, `client_id`, `from_id`, `event`, `read`, `send_telegramm`) VALUES (".$_SESSION['id'].", ".$client_id.", ".$partner_id.", 'parallel_del', 1,1)";
|
||
|
|
if($req_id > 0){
|
||
|
|
$sql_conf = "INSERT INTO `events_clients` (`user_id`, `req_id`, `from_id`, `event`, `read`, `send_telegramm`) VALUES (".$_SESSION['id'].", ".$req_id.", ".$partner_id.", 'parallel_del', 1,1)";
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
mysql_query($sql_conf);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
$doer_clients = 0;
|
||
|
|
$confirm = 1;
|
||
|
|
|
||
|
|
if(empty($doers)){
|
||
|
|
$confirm = 1;
|
||
|
|
} else {
|
||
|
|
foreach($doers as $id_user => $doer){
|
||
|
|
if($doer == 0) $confirm = 0;
|
||
|
|
if($id_user != $r_client['who_work']) $doer_clients = 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$sql_up = "UPDATE clients SET doers='".clearInputElement(json_encode($doers))."', doers_confirm=$confirm, doer_clients=$doer_clients WHERE id=$client_id";
|
||
|
|
if($req_id > 0){
|
||
|
|
$sql_up = "UPDATE requisitions SET doers='".clearInputElement(json_encode($doers))."', doers_confirm=$confirm, doer_clients=$doer_clients WHERE id=$req_id";
|
||
|
|
|
||
|
|
}
|
||
|
|
mysql_query($sql_up);
|
||
|
|
|
||
|
|
if($client_id > 0){
|
||
|
|
//сначала чистим
|
||
|
|
mysql_query("DELETE FROM clients_doers WHERE client_id = {$client_id}");
|
||
|
|
//потом вставлям новое
|
||
|
|
foreach($doers as $key => $agent){
|
||
|
|
$sql_i = "INSERT INTO clients_doers (client_id, user_id, confirm) VALUES (" . $client_id . ", ". $key . ", " . $agent . ")";
|
||
|
|
if(!mysql_query($sql_i)) {
|
||
|
|
echo mysql_error();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if($req_id > 0){
|
||
|
|
//сначала чистим
|
||
|
|
mysql_query("DELETE FROM requisition_doers WHERE requisition_id = {$req_id}");
|
||
|
|
//потом вставлям новое
|
||
|
|
foreach($doers as $key => $agent){
|
||
|
|
$sql_i = "INSERT INTO requisition_doers (requisition_id, user_id, confirm) VALUES (" . $req_id . ", ". $key . ", " . $agent . ")";
|
||
|
|
if(!mysql_query($sql_i)) {
|
||
|
|
echo mysql_error();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|