$mailingChainOld = \Bitrix\Sender\MailingChainTable::getRowById(array('ID' => $ID)); if ($mailingChainOld) { $MESSAGE_OLD = $mailingChainOld['MESSAGE']; } } $MESSAGE = CMain::ProcessLPA($MESSAGE, $MESSAGE_OLD); } $arFields = array("MAILING_ID" => $MAILING_ID, "SUBJECT" => $SUBJECT, "EMAIL_FROM" => $EMAIL_FROM, "MESSAGE" => $MESSAGE, "CREATED_BY" => $USER->GetID(), "REITERATE" => "N", "AUTO_SEND_TIME" => "", "DAYS_OF_WEEK" => "", "DAYS_OF_MONTH" => "", "TIMES_OF_DAY" => ""); if (empty($MESSAGE) && isset($IS_TEMPLATE_LIST_SHOWN) && $IS_TEMPLATE_LIST_SHOWN == 'Y') { $arError[] = GetMessage("sender_chain_edit_error_select_template"); } if (empty($arError)) { $mailingAddDb = \Bitrix\Sender\MailingChainTable::add($arFields); if ($mailingAddDb->isSuccess()) { $ID = $mailingAddDb->getId(); \Bitrix\Sender\MailingChainTable::initPosting($ID); $res = $ID > 0; $MAILING_CHAIN_ID = $ID; } else { $arError = $mailingAddDb->getErrorMessages(); } } } if (empty($arError)) { if ($MAILING_CHAIN_ID > 0) { //add or delete files //Delete checked if (is_array($FILES_del)) { $FILE_ID_tmp = array(); foreach ($FILES_del as $file => $fileMarkDel) { $file = intval($file);
} else { $status = MailingChainTable::STATUS_SEND; } MailingChainTable::update($mailingChainPrimary, array('STATUS' => $status)); $message = array("MESSAGE" => GetMessage("MAILING_ADM_SENDING_PLANING"), "DETAILS" => $arMailingChain['SUBJECT'] . '#PROGRESS_BAR#', "HTML" => true, "TYPE" => "PROGRESS", "PROGRESS_TOTAL" => 1, "PROGRESS_VALUE" => 1); if (\Bitrix\Sender\MailingChainTable::isReadyToSend($ID)) { $message["BUTTONS"] = array(array("ID" => "btn_cont", "VALUE" => GetMessage("MAILING_ADM_BTN_NEXT"), "ONCLICK" => "window.location='sender_mailing_chain_admin.php?MAILNG_ID=" . $MAILING_ID . "&ID=" . $ID . "&action=send&lang=" . LANGUAGE_ID . "'")); } $actionJsList = true; } } else { switch ($arMailingChain["STATUS"]) { case MailingChainTable::STATUS_NEW: $messageDetails = '<br><p>' . GetMessage("MAILING_ADM_SENDING_NOTE_LINE1") . '<br>' . GetMessage("MAILING_ADM_SENDING_NOTE_LINE2") . '</p>'; $message = array("MESSAGE" => GetMessage("MAILING_ADM_SENDING_SEND"), "BUTTONS" => array(array("ID" => "btn_stop", "VALUE" => GetMessage("MAILING_ADM_BTN_STOP"), "ONCLICK" => "Stop()"), array("ID" => "btn_cont", "VALUE" => GetMessage("MAILING_ADM_BTN_CONT"), "ONCLICK" => "Cont()"))); MailingChainTable::initPosting($mailingChainId); MailingChainTable::update($mailingChainPrimary, array('STATUS' => MailingChainTable::STATUS_SEND)); $actionJsList = true; $actionJsMoveProgress = true; break; case MailingChainTable::STATUS_SEND: \Bitrix\Main\Application::getInstance()->getConnection()->startTransaction(); \Bitrix\Sender\MailingManager::chainSend($mailingChainId); \Bitrix\Main\Application::getInstance()->getConnection()->commitTransaction(); $sendErrors = \Bitrix\Sender\MailingManager::getErrors(); if (empty($sendErrors)) { $messageDetails = '<br><p>' . GetMessage("MAILING_ADM_SENDING_NOTE_LINE1") . '<br>' . GetMessage("MAILING_ADM_SENDING_NOTE_LINE2") . '</p>'; $message = array("MESSAGE" => GetMessage("MAILING_ADM_SENDING_SEND"), "BUTTONS" => array(array("ID" => "btn_stop", "VALUE" => GetMessage("MAILING_ADM_BTN_STOP"), "ONCLICK" => "Stop()"), array("ID" => "btn_cont", "VALUE" => GetMessage("MAILING_ADM_BTN_CONT"), "ONCLICK" => "Cont()"))); $actionJsMoveProgress = true; } else { $message = $sendErrors->getMessage();
/** * @return string * @throws \Bitrix\Main\ArgumentException */ public static function checkPeriod($isAgentExec = true) { $isAgentExecInSetting = \COption::GetOptionString("sender", "reiterate_method") !== 'cron'; if ($isAgentExec && !$isAgentExecInSetting || !$isAgentExec && $isAgentExecInSetting) { return ""; } $dateTodayPhp = new \DateTime(); $datetimeToday = Type\DateTime::createFromPhp(clone $dateTodayPhp); $dateToday = clone $dateTodayPhp; $dateToday = Type\Date::createFromPhp($dateToday->setTime(0, 0, 0)); $dateTomorrow = clone $dateTodayPhp; $dateTomorrow = Type\Date::createFromPhp($dateTomorrow->setTime(0, 0, 0))->add('1 DAY'); $arDateFilter = array($dateToday, $dateTomorrow); $chainDb = MailingChainTable::getList(array('select' => array('ID', 'LAST_EXECUTED', 'POSTING_ID', 'DAYS_OF_MONTH', 'DAYS_OF_WEEK', 'TIMES_OF_DAY'), 'filter' => array('=REITERATE' => 'Y', '=MAILING.ACTIVE' => 'Y', 'STATUS' => MailingChainTable::STATUS_WAIT))); while ($arMailingChain = $chainDb->fetch()) { $lastExecuted = $arMailingChain['LAST_EXECUTED']; /* @var \Bitrix\Main\Type\DateTime $lastExecuted*/ if ($lastExecuted && $lastExecuted->getTimestamp() >= $dateToday->getTimestamp()) { continue; } $timeOfExecute = static::getDateExecute($dateTodayPhp, $arMailingChain["DAYS_OF_MONTH"], $arMailingChain["DAYS_OF_WEEK"], $arMailingChain["TIMES_OF_DAY"]); if ($timeOfExecute) { $arUpdateMailChain = array('LAST_EXECUTED' => $datetimeToday); $postingDb = PostingTable::getList(array('select' => array('ID'), 'filter' => array('=MAILING_CHAIN_ID' => $arMailingChain['ID'], '><DATE_CREATE' => $arDateFilter))); $arPosting = $postingDb->fetch(); if (!$arPosting) { $postingId = MailingChainTable::initPosting($arMailingChain['ID']); } else { $postingId = $arPosting['ID']; $arUpdateMailChain['POSTING_ID'] = $postingId; PostingTable::initGroupRecipients($postingId); } if ($postingId) { $arUpdateMailChain['STATUS'] = MailingChainTable::STATUS_SEND; $arUpdateMailChain['AUTO_SEND_TIME'] = Type\DateTime::createFromPhp($timeOfExecute); } MailingChainTable::update(array('ID' => $arMailingChain['ID']), $arUpdateMailChain); } } return static::getAgentNamePeriod(); }