Created
June 1, 2020 11:38
-
-
Save Elvinz/5db6901bba577eae112ea9d27fe7eed0 to your computer and use it in GitHub Desktop.
Уведомления об изменениях элементов инфоблоков
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// В файл /bitrix/php_interface/init.php надо добавить код (создайте файл, если его нет): | |
<? | |
AddEventHandler("iblock", "OnAfterIBlockElementAdd", "IBlockNotifyHandler"); | |
AddEventHandler("iblock", "OnAfterIBlockElementUpdate", "IBlockNotifyHandler"); | |
AddEventHandler("iblock", "OnBeforeIBlockElementDelete", "IBlockNotifyHandler"); | |
function IBlockNotifyHandler(&$arFields) | |
{ | |
if (is_array($arFields)) | |
$f = $arFields; | |
else // delete | |
{ | |
$rs = CIBlockElement::GetById($arFields); | |
$f = $rs->Fetch(); | |
} | |
if (!$f['ID']) | |
return; | |
if (($FLAG = COption::GetOptionString('iblock', 'notify_'.$f['IBLOCK_ID'], 0)) == 0) | |
return; | |
$d = debug_backtrace(); | |
$method = strtolower($d[3]['function']); | |
$arMethod = array( | |
'add' => array('TEXT' => 'Добавление элемента инфоблока', 'MAIL_FLAG' => 1, 'LOG_FLAG' => 256), | |
'update' => array('TEXT' => 'Изменение элемента инфоблока', 'MAIL_FLAG' => 2, 'LOG_FLAG' => 512), | |
'delete' => array('TEXT' => 'Удаление элемента инфоблока', 'MAIL_FLAG' => 4, 'LOG_FLAG' => 1024), | |
); | |
if (!array_key_exists($method, $arMethod)) | |
return; | |
if ($FLAG & $arMethod[$method]['MAIL_FLAG']) | |
{ | |
$subject = $arMethod[$method]['TEXT'].' ['.$f["IBLOCK_ID"].'] '.CIBlock::GetArrayByID($f['IBLOCK_ID'], 'NAME'); | |
$arSend = $f; | |
$arSend['SUBJECT'] = $subject; | |
$arSite = array(); | |
$rs = CSite::GetList($by, $order); | |
while($ar = $rs->Fetch()) | |
$arSite[] = $ar['ID']; | |
CEvent::Send('IBLOCK_ELEMENT_CHANGE_NOTIFY',$arSite,$arSend); | |
} | |
if ($FLAG & $arMethod[$method]['LOG_FLAG']) | |
{ | |
if (!$subject) | |
$subject = $arMethod[$method]['TEXT'].' ['.$f["IBLOCK_ID"].'] '.CIBlock::GetArrayByID($f['IBLOCK_ID'], 'NAME'); | |
CEventLog::Add(array( | |
"SEVERITY" => "SECURITY", | |
"AUDIT_TYPE_ID" => $arMethod[$method]['TEXT'], | |
"MODULE_ID" => "iblock", | |
"ITEM_ID" => $f['ID'], | |
"DESCRIPTION" => $subject, | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment