Exemple #1
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 #2
0
            LocalRedirect("/bitrix/admin/sender_group_admin.php?lang=" . LANG);
        }
    } else {
        if (!empty($arError)) {
            $message = new CAdminMessage(implode("<br>", $arError));
        }
        $bVarsFromForm = true;
    }
}
//Edit/Add part
ClearVars();
$str_SORT = 100;
$str_ACTIVE = "Y";
$str_VISIBLE = "Y";
if ($ID > 0) {
    $rubric = new CDBResult(\Bitrix\Sender\GroupTable::getById($ID));
    if (!$rubric->ExtractFields("str_")) {
        $ID = 0;
    }
}
$endpointList = array();
if ($ID > 0) {
    $groupConnectorDb = \Bitrix\Sender\GroupConnectorTable::getList(array('filter' => array('GROUP_ID' => $ID)));
    while ($groupConnector = $groupConnectorDb->fetch()) {
        if (!empty($groupConnector['ENDPOINT'])) {
            $endpointList[] = $groupConnector['ENDPOINT'];
        }
    }
}
if ($bVarsFromForm) {
    $DB->InitTableVarsForEdit("b_sender_group", "", "str_");
Exemple #3
0
        }
    }
}
//Edit/Add part
ClearVars();
$str_SORT = 100;
$str_ACTIVE = "Y";
$str_VISIBLE = "Y";
if ($ID > 0) {
    $rubric = new CDBResult(\Bitrix\Sender\MailingTable::getById($ID));
    if (!$rubric->ExtractFields("str_")) {
        $ID = 0;
    }
}
$GROUP_EXIST = array();
$groupDb = \Bitrix\Sender\GroupTable::getList(array('select' => array('NAME', 'ID', 'ADDRESS_COUNT'), 'filter' => array('ACTIVE' => 'Y'), 'order' => array('SORT' => 'ASC', 'NAME' => 'ASC')));
while ($arGroup = $groupDb->fetch()) {
    $GROUP_EXIST[] = $arGroup;
}
if ($bVarsFromForm) {
    $DB->InitTableVarsForEdit("b_sender_mailing", "", "str_");
}
\CJSCore::Init(array("sender_admin"));
$APPLICATION->SetTitle($ID > 0 ? GetMessage("sender_mailing_edit_title_edit") . $ID : GetMessage("sender_mailing_edit_title_new"));
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
$aMenu = array(array("TEXT" => GetMessage("sender_mailing_edit_list"), "TITLE" => GetMessage("sender_mailing_edit_list_title"), "LINK" => "sender_mailing_admin.php?lang=" . LANG, "ICON" => "btn_list"));
if ($ID > 0) {
    $aMenu[] = array("SEPARATOR" => "Y");
    $aMenu[] = array("TEXT" => GetMessage("sender_mailing_edit_add"), "TITLE" => GetMessage("sender_mailing_edit_add_title"), "LINK" => "sender_mailing_edit.php?lang=" . LANG, "ICON" => "btn_new");
    $aMenu[] = array("TEXT" => GetMessage("sender_mailing_edit_del"), "TITLE" => GetMessage("sender_mailing_edit_del_title"), "LINK" => "javascript:if(confirm('" . GetMessage("sender_mailing_edit_del_confirm") . "'))window.location='sender_mailing_admin.php?ID=" . $ID . "&action=delete&lang=" . LANGUAGE_ID . "&" . bitrix_sessid_get() . "';", "ICON" => "btn_delete");
    $aMenu[] = array("SEPARATOR" => "Y");
Exemple #4
0
				$arFields["ACTIVE"]=($_REQUEST['action']=="activate"?"Y":"N");
				$dataUpdateDb = \Bitrix\Sender\GroupTable::update($dataPrimary, $arFields);
				if(!$dataUpdateDb->isSuccess())
				{
					$LAST_ERROR = $dataUpdateDb->getErrorMessages();
					$LAST_ERROR = $LAST_ERROR[0];
					$lAdmin->AddGroupError(GetMessage("rub_save_error").$LAST_ERROR, $ID);
				}
				break;
		}

	}
}

$groupListDb = \Bitrix\Sender\GroupTable::getList(array(
	'filter' => $arFilter,
	'order' => array($by=>$order)
));
$rsData = new CAdminResult($groupListDb, $sTableID);
$rsData->NavStart();
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("rub_nav")));

$lAdmin->AddHeaders(array(
	array(	"id"		=>"ID",
		"content"	=>"ID",
		"sort"		=>"ID",
		"align"		=>"right",
		"default"	=>true,
	),
	array(	"id"		=>"NAME",
		"content"	=>GetMessage("rub_name"),
		"sort"		=>"NAME",