CExtranet::OnSocNetGroupUpdateHandler: Bitrix method

      
<?php 
//  CExtranet :: OnSocNetGroupUpdateHandler()
//  /dist/bitrix/modules/extranet/classes/general/extranet.php:836

    
public static function OnSocNetGroupUpdateHandler($ID$arFields)
    {
        global 
$bArchiveBeforeUpdate$APPLICATION;

        if (!
array_key_exists("CLOSED"$arFields))
            return 
true;

        if (
intval($ID) <= 0)
            return 
false;

        if (!
CModule::IncludeModule('socialnetwork'))
            return 
false;

        if (
CModule::IncludeModule('extranet'))
        {
            
$arSocNetGroup CSocNetGroup::GetByID($ID);
            if (!
$arSocNetGroup)
            {
                
$APPLICATION->ThrowException(GetMessage("SONET_NO_GROUP"), "ERROR_NO_GROUP");
                return 
false;
            }
            else
            {
                
$ExtranetSiteID CExtranet::GetExtranetSiteID();
                
$arGroupSites = array();

                
$rsGroupSite CSocNetGroup::GetSite($ID);
                while(
$arGroupSite $rsGroupSite->Fetch())
                {
                    
$arGroupSites[] = $arGroupSite["LID"];
                }

                if (!
in_array($ExtranetSiteID$arGroupSites))
                {
                    return 
true;
                }
            }
        }
        else
        {
            return 
true;
        }

        
$bFromArchiveToOpen $bFromOpenToArchive false;
        if (
$arFields["CLOSED"] == "Y" && !$bArchiveBeforeUpdate)
        {
            
$bFromOpenToArchive true;
        }
        elseif (
$arFields["CLOSED"] != "Y" && $bArchiveBeforeUpdate)
        {
            
$bFromArchiveToOpen true;
        }

        
$arEmail = array();

        if (
$bFromOpenToArchive || $bFromArchiveToOpen)
        {
            
$dbRequests CSocNetUserToGroup::GetList(
                array(),
                array(
                    
"GROUP_ID" => $ID,
                    
"<=ROLE" => SONET_ROLES_USER,
                    
"USER_ACTIVE" => "Y"
                
),
                
false,
                array(),
                array(
"ID""USER_ID""USER_NAME""USER_LAST_NAME""USER_EMAIL")
            );

            if (
$dbRequests)
            {
                while (
$arRequests $dbRequests->GetNext())
                {
                    
$arEmail[] = array(
                        
"NAME" => $arRequests["USER_NAME"],
                        
"LAST_NAME" => $arRequests["USER_LAST_NAME"],
                        
"EMAIL" => $arRequests["USER_EMAIL"]
                    );
                }
            }
        }

        if (
$bFromOpenToArchive)
        {
            foreach(
$arEmail as $recipient)
            {
                
$arEventFields = array(
                    
"WG_ID" => $ID,
                    
"WG_NAME" => $arFields["NAME"],
                    
"MEMBER_NAME" => $recipient["NAME"],
                    
"MEMBER_LAST_NAME" => $recipient["LAST_NAME"],
                    
"MEMBER_EMAIL" => $recipient["EMAIL"],
                );

                
CEvent::Send("EXTRANET_WG_TO_ARCHIVE"SITE_ID$arEventFields);
            }
        }

        if (
$bFromArchiveToOpen)
        {
            foreach(
$arEmail as $recipient)
            {
                
$arEventFields = array(
                    
"WG_ID" => $ID,
                    
"WG_NAME" => $arFields["NAME"],
                    
"MEMBER_NAME" => $recipient["NAME"],
                    
"MEMBER_LAST_NAME" => $recipient["LAST_NAME"],
                    
"MEMBER_EMAIL" => $recipient["EMAIL"],
                );

                
CEvent::Send("EXTRANET_WG_FROM_ARCHIVE"SITE_ID$arEventFields);
            }
        }

        return 
true;
    }