78 $current_time = time();
79 $time_of_exec =
false;
81 while (($arRubric = $rubrics->Fetch()) && $time_of_exec ===
false)
83 if ($arRubric[
'LAST_EXECUTED'] ==
'')
90 if ($last_executed <= 0)
101 sort($arToD, SORT_NUMERIC);
104 $arSDate = localtime($last_executed);
105 $sdate = mktime(0, 0, 0, $arSDate[4] + 1, $arSDate[3], $arSDate[5] + 1900);
106 while ($sdate < $current_time && $time_of_exec ===
false)
108 $arSDate = localtime($sdate);
109 if ($arSDate[6] == 0)
116 $flag = array_search($arSDate[3], $arDoM);
119 $flag = array_search($arSDate[6], $arDoW);
124 $flag = array_search($arSDate[6], $arDoW);
131 if ($flag !==
false && $arToD)
133 foreach ($arToD as $intToD)
135 if ($sdate + $intToD > $last_executed && $sdate + $intToD <= $current_time)
137 $time_of_exec = $sdate + $intToD;
142 $sdate = mktime(0, 0, 0, date(
'm',$sdate), date(
'd',$sdate) + 1, date(
'Y',$sdate));
144 if ($time_of_exec !==
false)
146 $arRubric[
'START_TIME'] = ConvertTimeStamp($last_executed,
'FULL');
147 $arRubric[
'END_TIME'] = ConvertTimeStamp($time_of_exec,
'FULL');
148 $arRubric[
'SITE_ID'] = $arRubric[
'LID'];
151 $result =
'CPostingTemplate::Execute();';
159 if (!is_object(
$USER))
164 $rsSite = CSite::GetByID($arRubric[
'SITE_ID']);
165 $arSite = $rsSite->Fetch();
172 $strFileName =
$_SERVER[
'DOCUMENT_ROOT'] .
'/' . $arRubric[
'TEMPLATE'] .
'/template.php';
173 if (file_exists($strFileName))
178 $strBody = ob_get_contents();
187 $arLang = $rsLang->Fetch();
191 $arFields[
'AUTO_SEND_TIME'] = $arRubric[
'END_TIME'];
193 $arFields[
'MSG_CHARSET'] = $arLang[
'CHARSET'];
197 if (array_key_exists(
'FILES',
$arFields))
201 $cPosting->SaveFile(
$ID, $arFile);
206 $cPosting->ChangeStatus(
$ID,
'P');
207 if (COption::GetOptionString(
'subscribe',
'subscribe_auto_method') !==
'cron')
209 CAgent::AddAgent(
'CPosting::AutoSend(' .
$ID .
',true,"' . $arRubric[
'LID'] .
'");',
'subscribe',
'N', 0, $arRubric[
'END_TIME'],
'Y', $arRubric[
'END_TIME']);
215 $strSql =
'UPDATE b_list_rubric SET LAST_EXECUTED=' .
$DB->CharToDateFunction($arRubric[
'END_TIME']) .
' WHERE ID=' . intval($arRubric[
'ID']);
223 if ($strDaysOfMonth <>
'')
225 $arDoM = explode(
',', $strDaysOfMonth);
227 foreach ($arDoM as $strDoM)
229 if (preg_match(
'/^(\d{1,2})$/', trim($strDoM), $arFound))
231 if (intval($arFound[1]) < 1 || intval($arFound[1]) > 31)
240 elseif (preg_match(
'/^(\d{1,2})-(\d{1,2})$/', trim($strDoM), $arFound))
242 if (intval($arFound[1]) < 1 || intval($arFound[1]) > 31 || intval($arFound[2]) < 1 || intval($arFound[2]) > 31 || intval($arFound[1]) >= intval($arFound[2]))
248 for (
$i = intval($arFound[1]);
$i <= intval($arFound[2]);
$i++)