200 lines
8.7 KiB
PHP
200 lines
8.7 KiB
PHP
<?php
|
||
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
||
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
||
$pdo->query("SET NAMES 'utf8'");
|
||
/*error_reporting(E_ALL | E_STRICT);
|
||
ini_set('display_errors', 1);*/
|
||
|
||
|
||
//Получение взможных ответственных за модерацию
|
||
if(isset($_POST['get_user_moderation'])){
|
||
if((int)$_POST['user_id'] > 0 && (isset($_SESSION['id']) && $_SESSION['id'] > 0) && isset($_POST['object_id']) && (int)$_POST['object_id'] > 0){
|
||
$object_id = (int)$_POST['object_id'];
|
||
$users = array();
|
||
$this_users = array();
|
||
$user_id = (int)$_POST['user_id'];
|
||
$user = new User();
|
||
$user->get($user_id);
|
||
$result['modr'] = array();
|
||
$result['html'] = '';
|
||
$result['obj'] = array();
|
||
$users_moderation = array();
|
||
|
||
$agency_id = $user->agencyId;
|
||
|
||
//Все юзеры агенства
|
||
$sql_users = "SELECT * FROM users WHERE id in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id)))";
|
||
$q_users = $pdo->query($sql_users);
|
||
while($r_users = $pdo->fetch_assoc($q_users)){
|
||
$users[$r_users['id']] = $r_users;
|
||
if($r_users['id'] == $user_id){
|
||
$this_users = $r_users;
|
||
}
|
||
}
|
||
|
||
//Поиск модераций
|
||
$sql_modr = "SELECT * FROM objects_moderation_advert WHERE object_id={$object_id} AND agent_id={$user_id}";
|
||
$q_modr = $pdo->query($sql_modr);
|
||
if($pdo->num_rows($q_modr) > 0){
|
||
$r_modr = $pdo->fetch_assoc($q_modr);
|
||
//Если отправлено на модерацию
|
||
$sql_modr_users = "SELECT * FROM `objects_moderation_advert_user_work` WHERE moderation_id = {$r_modr['id']}";
|
||
$q_modr_users = $pdo->query($sql_modr_users);
|
||
if($pdo->num_rows($q_modr_users) > 0){
|
||
$result['modr'] = $r_modr;
|
||
$result['modr']['is_moderation'] = 0;
|
||
while($r_moder_users = $pdo->fetch_assoc($q_modr_users)){
|
||
$users_moderation[] = (int)$r_moder_users['user_id'];
|
||
if($r_moder_users['is_moderation'] == 1){
|
||
$result['modr']['is_moderation'] = 1;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$pdo_sphinx = new MysqlPdo(hstsph2, null, null, null, true, '9306');
|
||
|
||
$obj = $pdo_sphinx->fetch_assoc($pdo_sphinx->query("SELECT * FROM objects WHERE id={$object_id}"));
|
||
if($obj){
|
||
$result['obj'] = $obj;
|
||
}
|
||
|
||
|
||
//SELECT * FROM `objects_moderation_advert_user_work`"
|
||
|
||
//var_dump($users);
|
||
|
||
$result['users'] = $users_moderation;
|
||
|
||
$result['html'] .= '<select id="moderation_who_work_'.$object_id.'" multiple="">';
|
||
|
||
foreach ($users as $emp){
|
||
$selected = '';
|
||
if($emp['blocked'] == 0){
|
||
if(($emp['manager'] == 1 || $emp['agency'] == 1 || $emp['users_admin'] == 1) && $emp['show_all_objects_page'] == 1){
|
||
|
||
if(in_array($emp['id'], $users_moderation)) $selected = ' selected';
|
||
$result['html'] .= '<option value="'.$emp['id'].'"'.$selected.'>'.htmlspecialchars_decode(trim($emp['last_name'] . ' ' . $emp['first_name'] . ' ' . $emp['middle_name'])).'</option>';
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
$result['html'] .= '</select>';
|
||
|
||
echo json_encode($result);
|
||
|
||
}
|
||
}
|
||
|
||
//Получение взможных ответственных за задачу по модерации
|
||
if(isset($_POST['get_user_event_moderation'])){
|
||
if((int)$_POST['event_id'] > 0 && (isset($_SESSION['id']) && $_SESSION['id'] > 0)){
|
||
|
||
$event_id = (int)$_POST['event_id'];
|
||
$object_id = 0;
|
||
$users = array();
|
||
$this_users = array();
|
||
$user_id = (int)$_SESSION['id'];
|
||
$user = new User();
|
||
$user->get($user_id);
|
||
$result['html'] = '';
|
||
$result['text'] = '';
|
||
$sub_id = (int)$_POST['sub_id'];
|
||
|
||
$agency_id = $user->agencyId;
|
||
|
||
//Все юзеры агенства
|
||
$sql_users = "SELECT * FROM users WHERE id in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id)))";
|
||
$q_users = $pdo->query($sql_users);
|
||
while($r_users = $pdo->fetch_assoc($q_users)){
|
||
$users[$r_users['id']] = $r_users;
|
||
if($r_users['id'] == $user_id){
|
||
$this_users = $r_users;
|
||
}
|
||
}
|
||
|
||
$sql_event = "SELECT * FROM user_object_events WHERE id = {$event_id}";
|
||
$q_event = $pdo->query($sql_event);
|
||
$r_event = $pdo->fetch_assoc($q_event);
|
||
if(isset($r_event['object_id']) && $r_event['object_id'] > 0){
|
||
$object_id = (int)$r_event['object_id'];
|
||
}
|
||
|
||
if($object_id > 0){
|
||
|
||
$pdo_sphinx = new MysqlPdo(hstsph2, null, null, null, true, '9306');
|
||
|
||
//ответственный по объекту
|
||
$sql_obj = "SELECT * FROM objects WHERE id={$object_id}";
|
||
$q_obj = $pdo_sphinx->query($sql_obj);
|
||
$r_obj = $pdo_sphinx->fetch_assoc($q_obj);
|
||
if(isset($r_obj['id_add_user']) && $r_obj['id_add_user'] > 0){
|
||
$user_add = (int)$r_obj['id_add_user'];
|
||
}
|
||
}
|
||
|
||
$user_for = 0;
|
||
|
||
if($sub_id > 0){
|
||
$sql_sub = "SELECT * FROM user_sub_comments WHERE id = {$sub_id}";
|
||
$q_sub = $pdo->query($sql_sub);
|
||
$r_sub = $pdo->fetch_assoc($q_sub);
|
||
$result['text'] = $r_sub['sub_comment'];
|
||
$user_for = (int)$r_sub['user_for'];
|
||
}
|
||
|
||
|
||
$result['html'] .= '<select id="sub_comment_who_work_'.$event_id.'">';
|
||
$result['html'] .= '<option value="0"></option>';
|
||
|
||
foreach ($users as $emp){
|
||
$selected = '';
|
||
if($emp['id'] == $user_for) $selected = ' selected';
|
||
if($emp['blocked'] == 0){
|
||
if(($emp['manager'] == 1 || $emp['agency'] == 1 || $emp['users_admin'] == 1) && $emp['show_all_objects_page'] == 1){
|
||
$result['html'] .= '<option value="'.$emp['id'].'"'.$selected.'>'.htmlspecialchars_decode(trim($emp['last_name'] . ' ' . $emp['first_name'] . ' ' . $emp['middle_name'])).'</option>';
|
||
|
||
} else if($user_add > 0 && $emp['id'] == $user_add) {
|
||
$result['html'] .= '<option value="'.$emp['id'].'"'.$selected.'>'.htmlspecialchars_decode(trim($emp['last_name'] . ' ' . $emp['first_name'] . ' ' . $emp['middle_name'])).'</option>';
|
||
}
|
||
}
|
||
}
|
||
|
||
$result['html'] .= '</select>';
|
||
|
||
echo json_encode($result);
|
||
|
||
}
|
||
}
|
||
|
||
|
||
//Отправка модераций
|
||
if(isset($_POST['send_moderation']) && isset($_POST['object_id']) && (int)$_POST['object_id'] > 0){
|
||
$who_work = json_decode($_POST['who_work'], true);
|
||
$object_id = (int)$_POST['object_id'];
|
||
$user_id = (int)$_SESSION['id'];
|
||
$comment = '';
|
||
if(isset($_POST['comment'])){
|
||
$comment = $_POST['comment'];
|
||
}
|
||
$moderationClass = new ModerationAdvert($pdo);
|
||
$result = $moderationClass->sendModeration($user_id, $object_id, $who_work, $comment);
|
||
echo json_encode($result);
|
||
|
||
}
|
||
|
||
//Подтверждение модерации
|
||
if(isset($_POST['confirm_moderation']) && isset($_POST['object_id']) && (int)$_POST['object_id'] > 0){
|
||
$object_id = (int)$_POST['object_id'];
|
||
|
||
$moderationClass = new ModerationAdvert($pdo);
|
||
$result = $moderationClass->confirmModeration($object_id);
|
||
echo json_encode($result);
|
||
}
|
||
|
||
?>
|