Exemple #1
0
if ($POST_RIGHT == "D") {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
$sTableID = "tbl_sender_contact";
if ($_REQUEST["action"] == "js_pull" && check_bitrix_sessid() && $POST_RIGHT >= "W") {
    require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_js.php";
    $connectorCountInfo = '(' . htmlspecialcharsbx($_REQUEST['CONNECTOR_COUNT_INFO_CURR']) . ' ' . GetMessage('CONTACT_ADM_PULL_FROM') . ' ' . htmlspecialcharsbx($_REQUEST['CONNECTOR_COUNT_INFO_ALL']) . ')';
    $connectorDataPage = intval($_REQUEST['CONNECTOR_PAGE']);
    $isShowConnectorInfo = $connectorDataPage <= 0;
    $isShowNextButton = (bool) intval($_REQUEST['CONNECTOR_NEXT_EXIST']);
    $isPulling = false;
    $isUpdateList = false;
    $connector = null;
    $endpoint = $_REQUEST['CONNECTOR_ENDPOINT'];
    if (is_array($endpoint) && isset($endpoint['MODULE_ID']) && !empty($endpoint['CODE'])) {
        $connector = \Bitrix\Sender\ConnectorManager::getConnector($endpoint);
    }
    if ($connector) {
        if ($isShowConnectorInfo) {
            $countAll = $connector->getDataCount();
            $message = array("MESSAGE" => $connector->getName() . $connectorCountInfo, "DETAILS" => GetMessage("CONTACT_ADM_PULL") . '#PROGRESS_BAR#' . '<p>' . GetMessage("CONTACT_ADM_PULL_ALL") . ' <b>' . $countAll . '</b> ', "HTML" => true, "TYPE" => "PROGRESS", "PROGRESS_TOTAL" => $countAll, "PROGRESS_VALUE" => 0, "BUTTONS" => array(array("ID" => "btn_start", "VALUE" => GetMessage("CONTACT_ADM_BTN_START"), "ONCLICK" => "Start()")));
            if ($isShowNextButton) {
                $message["BUTTONS"][] = array("ID" => "btn_next", "VALUE" => GetMessage("CONTACT_ADM_BTN_SKIP"), "ONCLICK" => "Next()");
            }
        } else {
            $timeout = \COption::GetOptionInt("sender", "interval");
            $arPullResult = \Bitrix\Sender\ContactTable::addFromConnector($connector, $connectorDataPage, $timeout);
            $arPullResult['COUNT_NEW'] += intval($_REQUEST['COUNTER_ADDRESS_NEW']);
            $arPullResult['COUNT_ERROR'] += intval($_REQUEST['COUNTER_ADDRESS_ERROR']);
            $message = array("MESSAGE" => $connector->getName() . $connectorCountInfo, "DETAILS" => ($arPullResult['STATUS'] ? GetMessage("CONTACT_ADM_PULLING") : GetMessage("CONTACT_ADM_PULLED")) . '#PROGRESS_BAR#' . '<p>' . GetMessage("CONTACT_ADM_PULL_ALL") . ' <b>' . $arPullResult['COUNT_ALL'] . '</b> </p>' . '<p>' . GetMessage("CONTACT_ADM_PULL_NEW") . ' <b>' . $arPullResult['COUNT_NEW'] . '</b> </p>' . '<p>' . GetMessage("CONTACT_ADM_PULL_ERROR") . ' <b>' . $arPullResult['COUNT_ERROR'] . '</b> </p>', "HTML" => true, "TYPE" => "PROGRESS", "PROGRESS_TOTAL" => $arPullResult['COUNT_ALL'], "PROGRESS_VALUE" => $arPullResult['COUNT_PROGRESS'], "BUTTONS" => array());
            if ($arPullResult['STATUS']) {
Exemple #2
0
 /**
  * @param $postingId
  * @param bool $checkDuplicate
  * @return bool
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function initGroupRecipients($postingId, $checkDuplicate = false)
 {
     $arPosting = \Bitrix\Sender\PostingTable::getRowById(array('ID' => $postingId));
     if (!$arPosting) {
         return false;
     }
     $checkRecipientDuplicate = $checkDuplicate;
     if (!$checkDuplicate) {
         if ($arPosting['STATUS'] == \Bitrix\Sender\PostingTable::STATUS_NEW) {
             $primary = array('POSTING_ID' => $postingId);
             \Bitrix\Sender\PostingRecipientTable::delete($primary);
             $checkRecipientDuplicate = false;
         }
     }
     // fetch all unsubscribed emails of current mailing for excluding from recipients
     $arEmailNotSend = array();
     $recipientUnsubDb = \Bitrix\Sender\PostingUnsubTable::getList(array('select' => array('EMAIL' => 'POSTING_RECIPIENT.EMAIL'), 'filter' => array('POSTING.MAILING_ID' => $arPosting['MAILING_ID'])));
     while ($recipientUnsub = $recipientUnsubDb->fetch()) {
         $arEmailNotSend[] = $recipientUnsub['EMAIL'];
     }
     $groupConnectorsDataCount = array();
     $connection = \Bitrix\Main\Application::getConnection();
     $conHelper = $connection->getSqlHelper();
     $statusRecipientNone = \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_NONE;
     // fetch all connectors for getting emails
     $groupDb = \Bitrix\Sender\MailingGroupTable::getList(array('select' => array('INCLUDE', 'CONNECTOR_ENDPOINT' => 'GROUP.GROUP_CONNECTOR.ENDPOINT', 'GROUP_ID'), 'filter' => array('MAILING_ID' => $arPosting['MAILING_ID']), 'order' => array('INCLUDE' => 'DESC', 'GROUP_ID' => 'ASC')));
     while ($group = $groupDb->fetch()) {
         $connector = \Bitrix\Sender\ConnectorManager::getConnector($group['CONNECTOR_ENDPOINT']);
         if (!$connector) {
             continue;
         }
         $connectorDataCount = 0;
         $connector->setFieldValues($group['CONNECTOR_ENDPOINT']['FIELDS']);
         $connectorDataDb = $connector->getData();
         while (true) {
             $emailList = array();
             $connectorDataList = array();
             $maxPart = 200;
             while ($arConnectorData = $connectorDataDb->Fetch()) {
                 // collect connectors counter of addresses
                 $connectorDataCount++;
                 // exclude unsubscribed addresses
                 $arConnectorData['EMAIL'] = trim(strtolower($arConnectorData['EMAIL']));
                 if (strlen($arConnectorData['EMAIL']) <= 0 || in_array($arConnectorData['EMAIL'], $arEmailNotSend)) {
                     continue;
                 }
                 $emailList[] = $arConnectorData['EMAIL'];
                 $connectorDataList[$arConnectorData['EMAIL']] = $arConnectorData;
                 $maxPart--;
                 if ($maxPart == 0) {
                     break;
                 }
             }
             if (empty($emailList)) {
                 break;
             }
             foreach ($emailList as &$email) {
                 $email = $conHelper->forSql($email);
             }
             $emailListString = "'" . implode("', '", $emailList) . "'";
             if ($group['INCLUDE']) {
                 // add address if not exists
                 if ($checkRecipientDuplicate) {
                     $recipientEmailDb = $connection->query("select EMAIL from b_sender_posting_recipient where EMAIL in (" . $emailListString . ") and POSTING_ID=" . intval($postingId));
                     while ($recipientEmail = $recipientEmailDb->fetch()) {
                         unset($connectorDataList[$recipientEmail['EMAIL']]);
                     }
                 }
                 if (!empty($connectorDataList)) {
                     foreach ($connectorDataList as $email => $arConnectorData) {
                         $arRecipient = array('NAME' => "'" . $conHelper->forSql($arConnectorData['NAME']) . "'", 'EMAIL' => "'" . $conHelper->forSql($arConnectorData['EMAIL']) . "'", 'STATUS' => "'" . $statusRecipientNone . "'", 'POSTING_ID' => intval($postingId));
                         if (array_key_exists('USER_ID', $arConnectorData) && intval($arConnectorData['USER_ID']) > 0) {
                             $arRecipient['USER_ID'] = intval($arConnectorData['USER_ID']);
                         }
                         $insertColumnNamesString = implode(", ", array_keys($arRecipient));
                         $insertColumnValuesString = implode(", ", array_values($arRecipient));
                         $connection->query("insert into b_sender_posting_recipient(" . $insertColumnNamesString . ") values(" . $insertColumnValuesString . ")");
                     }
                 }
             } else {
                 // delete address from posting
                 $connection->query("delete from b_sender_posting_recipient where EMAIL in (" . $emailListString . ") and POSTING_ID=" . intval($postingId));
             }
         }
         //\Bitrix\Sender\GroupConnectorTable::update(array('ID' => $group['GROUP_CONNECTOR_ID']), array('ADDRESS_COUNT' => $connectorDataCount));
         // collect groups counter of addresses
         if (array_key_exists($group['GROUP_ID'], $groupConnectorsDataCount)) {
             $groupConnectorsDataCount[$group['GROUP_ID']] += $connectorDataCount;
         } else {
             $groupConnectorsDataCount[$group['GROUP_ID']] = $connectorDataCount;
         }
     }
     // update group counter of addresses
     foreach ($groupConnectorsDataCount as $groupId => $groupDataCount) {
         \Bitrix\Sender\GroupTable::update($groupId, array('ADDRESS_COUNT' => $groupDataCount));
     }
     return true;
 }
Exemple #3
0
 public static function getPersonalizeList($id)
 {
     $result = array();
     // fetch all connectors for getting emails
     $groupConnectorDb = \Bitrix\Sender\MailingGroupTable::getList(array('select' => array('CONNECTOR_ENDPOINT' => 'GROUP.GROUP_CONNECTOR.ENDPOINT', 'GROUP_ID'), 'filter' => array('MAILING_ID' => $id, 'INCLUDE' => true), 'order' => array('GROUP_ID' => 'ASC')));
     while ($groupConnector = $groupConnectorDb->fetch()) {
         $connector = null;
         if (is_array($groupConnector['CONNECTOR_ENDPOINT'])) {
             $connector = \Bitrix\Sender\ConnectorManager::getConnector($groupConnector['CONNECTOR_ENDPOINT']);
         }
         if (!$connector) {
             continue;
         }
         $result = array_merge($result, $connector->getPersonalizeList());
     }
     return $result;
 }