Ejemplo n.º 1
0
$userID = isset($arParams['USER_ID']) ? intval($arParams['USER_ID']) : 0;
if ($userID <= 0) {
    $userID = CCrmPerms::GetCurrentUserID();
}
$arResult['USER_ID'] = $userID;
$elementID = isset($arParams['ELEMENT_ID']) ? intval($arParams['ELEMENT_ID']) : 0;
if ($elementID <= 0) {
    $paramName = isset($arParams['ELEMENT_ID_PARAM_NAME']) ? strval($arParams['ELEMENT_ID_PARAM_NAME']) : '';
    if ($paramName === '') {
        $paramName = 'element_id';
    }
    $elementID = isset($_REQUEST[$paramName]) ? intval($_REQUEST[$paramName]) : 0;
}
$element = array();
if ($elementID > 0) {
    $element = CCrmMailTemplate::GetByID($elementID);
    if (!$element || !CCrmPerms::IsAdmin() && intval($element['OWNER_ID']) !== $userID) {
        ShowError(GetMessage('CRM_MAIL_TEMPLATE_NOT_FOUND'));
        @define('ERROR_404', 'Y');
        if ($arParams['SET_STATUS_404'] === 'Y') {
            CHTTP::SetStatus('404 Not Found');
        }
        return;
    }
    $elementID = $element['ID'];
} else {
    $element['OWNER_ID'] = $userID;
    $element['IS_ACTIVE'] = 'Y';
}
$errors = array();
if (check_bitrix_sessid()) {