38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
||
|
|
|
||
|
|
if($_SESSION['id'] && $_POST['comment'] && (($_POST['client_id']) || ($_POST['req_id']))) {
|
||
|
|
$post = clearInputData($_POST);
|
||
|
|
|
||
|
|
$sql="SELECT * FROM clients WHERE id=$post[client_id]";
|
||
|
|
$req_id = 0;
|
||
|
|
if(isset($_POST['req_id']) && $_POST['req_id'] > 0){
|
||
|
|
$req_id = (int)$_POST['req_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'];
|
||
|
|
}
|
||
|
|
|
||
|
|
$from_id = $_SESSION['id'];
|
||
|
|
$sql = "INSERT INTO user_client_events(user_id, client_id, type, comment, from_id) ";
|
||
|
|
$sql .= " VALUES($idUser, $post[client_id], 'comment', '$post[comment]', $from_id)";
|
||
|
|
if($req_id > 0){
|
||
|
|
$sql = "INSERT INTO user_client_events(user_id, req_id, type, comment, from_id) ";
|
||
|
|
$sql .= " VALUES($idUser, $req_id, 'comment', '$post[comment]', $from_id)";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (mysql_query($sql))
|
||
|
|
echo json_encode(['success' => true]);
|
||
|
|
else
|
||
|
|
echo json_encode(['success' => false, 'error' => mysql_error()]);
|
||
|
|
}
|