AddEventHandler("tasks", "OnBeforeTaskAdd", "MyOnBeforeTaskAdd");
function MyOnBeforeTaskAdd(&$arTask){
if(empty($arTask["DEADLINE"]) && CModule::IncludeModule("tasks") && CModule::IncludeModule("crm") && CModule::IncludeModule('intranet')){
$arTaskForCheck = [
"CREATED_BY" => $arTask["CREATED_BY"]?? $USER->GetID(),
"RESPONSIBLE_ID" => $arTask["RESPONSIBLE_ID"]?? $USER->GetID(),
];
CheckTaskEmptyDeadLine($arTaskForCheck);
}
}
AddEventHandler("tasks", "OnBeforeTaskUpdate", "MyOnBeforeTaskUpdate");
function MyOnBeforeTaskUpdate($id, &$data, &$arTask){
$deadline = $data["DEADLINE"] ?? $arTask["DEADLINE"];
if(empty($deadline) && CModule::IncludeModule("tasks") && CModule::IncludeModule("crm") && CModule::IncludeModule('intranet')){
$arTaskForCheck = [
"CREATED_BY" => $data["CREATED_BY"] ?? $arTask["CREATED_BY"],
"RESPONSIBLE_ID" => $data["RESPONSIBLE_ID"] ?? $arTask["RESPONSIBLE_ID"],
];
CheckTaskEmptyDeadLine($arTaskForCheck);
}
}
function CheckTaskEmptyDeadLine($arTask){
$needDepartments = [1609, 1610, 1611, 1612, 1242, 1292, 181, 183];
$arDepartments = CIntranetUtils::GetUserDepartments($arTask["CREATED_BY"]);
if($arTask["CREATED_BY"]!=$arTask["RESPONSIBLE_ID"]){
$arDepartments = array_merge($arDepartments, CIntranetUtils::GetUserDepartments($arTask["RESPONSIBLE_ID"]));
}
foreach($arDepartments as $departmentId){
if(in_array($departmentId,$needDepartments)){
if(CModule::IncludeModule("im")){
global $USER;
$arFields = array(
"NOTIFY_TITLE" => "Ошибка: крайний срок задачи пустой", //заголовок
"MESSAGE" => "Менеджеры ОПМ не могут ставить и исполнять задачи без срока",
"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, // IM_MESSAGE_PRIVATE, IM_MESSAGE_CHAT, IM_MESSAGE_OPEN, IM_MESSAGE_SYSTEM, IM_MESSAGE_OPEN_LINE
"TO_USER_ID" => $USER->GetID(),
"FROM_USER_ID" => $USER->GetID(),
//"AUTHOR_ID" => $userIdOther, //может отличаться от FROM_USER_ID
"NOTIFY_TYPE" => IM_NOTIFY_SYSTEM, // IM_NOTIFY_CONFIRM, IM_NOTIFY_SYSTEM, IM_NOTIFY_FROM
"NOTIFY_MODULE" => "main", // module id sender (ex: xmpp, main, etc)
"NOTIFY_EVENT" => "manage",
);
CIMMessenger::Add($arFields);
}
throw new SystemException("Error empty deadline");
}
}
} |