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

45 lines
1.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
if ($_SESSION['id'] && $_GET['userId'] && is_numeric($_GET['userId']) && $_GET['objectId'] && is_numeric($_GET['objectId'])) {
$get = clearInputData($_GET);
$userId = $_SESSION['id'];
$newUserId = intval($get['userId']);
$objectId = intval($get['objectId']);
// Получаем текущего пользователя
$currentUser = new User;
$currentUser->get($userId);
// Определяем: это руководитель или второй админ?
$isDirector = ($currentUser->company_id == $currentUser->id);
$isAdmin = ($currentUser->users_admin == 1);
// Получаем получателя
$newUser = new User;
$newUser->get($newUserId);
// Проверяем, что оба из одной компании
if ((int)$currentUser->company_id !== (int)$newUser->company_id) {
die("Разные компании");
}
// Формируем запрос
if ($isDirector || $isAdmin) {
// Руководитель или админ может отменить любую передачу в своей компании
$sql = "DELETE FROM `objects_to_send`
WHERE object_id = " . $objectId . "
AND sended_user_id IN (
SELECT id FROM users WHERE company_id = " . (int)$currentUser->company_id . "
)";
} else {
// Обычный пользователь — только свои передачи
$sql = "DELETE FROM `objects_to_send`
WHERE sended_user_id = " . $userId . "
AND object_id = " . $objectId;
}
mysql_query($sql);
}