// Подписка на рассылку при регистрации
AddEventHandler("main", "OnAfterUserAdd", "OnAfterUserAddHandler");
function OnAfterUserAddHandler(&$arFields)
{
$errors = Array();
if($arFields["ID"]>0 && $arFields["UF_SUBSCRIBE"])
{
if(CModule::IncludeModule("subscribe")) {
$USER_ID = $arFields["ID"];
$EMAIL = $arFields["EMAIL"];
$arFilter = array(
"ACTIVE" => "Y",
"LID" => "s1",
"VISIBLE"=>"Y",
);
$rsRubrics = CRubric::GetList(array(), $arFilter);
$arRubrics = array();
while($arRubric = $rsRubrics->GetNext()) $arRubrics[] = $arRubric["ID"];
$obSubscription = new CSubscription;
$rsSubscription = $obSubscription->GetList(array(), array("USER_ID" => $USER_ID));
$arSubscription = $rsSubscription->Fetch();
if(is_array($arSubscription))
{
$rs = $obSubscription->Update(
$arSubscription["ID"],
array(
"FORMAT" => "html",
"RUB_ID" => $arRubrics,
),
false
);
}
else
{
$ID = $obSubscription->Add(array(
"USER_ID" => $USER_ID,
"ACTIVE" => "Y",
"EMAIL" => $EMAIL,
"FORMAT" => "html",
"CONFIRMED" => "Y",
"SEND_CONFIRM" => "N",
"RUB_ID" => $arRubrics,
));
}
}
}
}
|