function cron_sendEmailNotifications() { $execution_time = ini_get('max_execution_time'); if (empty($execution_time)) { $execution_time = DEF_EXEC_TIME; } else { if ($execution_time > MAX_EXEC_TIME * 2) { $execution_time = MAX_EXEC_TIME * 2; } } $execution_time_start = time(); $execution_time_end = $execution_time_start + $execution_time / 2; $notifications = \Components\Entity\EmailNotification::findBy(array(), array('attempts_to_send' => 'ASC'), EMAIL_NOTIFICATION_LIMIT, 0); $notification_index = 0; $good_cnt = 0; $notification_count = count($notifications); while (time() <= $execution_time_end && $notification_index < $notification_count) { $notification = $notifications[$notification_index]; $message = \Components\Entity\Message::find($notification['message_id']); if (!empty($message)) { //Прочитано, или не шлем - надо его сразу убить, чтобы потом когда включим не повалил шквал старых писем if ($message['readed'] || !\Components\Entity\EmailNotificationType::isSendable($notification['type'])) { \Components\Entity\EmailNotification::delete($notification['id']); } else { $attachments = array(); // надо только для писем типа \Components\Entity\EmailNotification::TO_SUBSCRIBED_AUTHORS_ON_DISTRIBUTION $all_added_size = 0; $fna = 0; if ($notification['type'] == \Components\Entity\EmailNotification::TO_SUBSCRIBED_AUTHORS_ON_DISTRIBUTION && !empty($message['order_id'])) { $files = get_order_files($message['order_id']); foreach ($files as $file) { $all_added_size += $file['size']; if ($all_added_size > 16000000) { // write to body, but not add file $fna++; } else { $attachments[] = array('path' => get_file_path($message['order_id'], $file), 'name' => $file['name']); } } } $subtext = ""; if ($fna) { $subtext = "<br><br>-----------------------------------<br>" . "Еще " . $fna . " файла(ов) не были добавлены к письму из-за ограничения размеров"; } // Это условие проверено выше //if ( \Components\Entity\EmailNotificationType::isSendable($notification['type']) ) //{ $email = new \Components\Classes\Email(); $email->IsHTML(true); $email->setData(array('email' => $notification['receiver_email'], 'name' => ''), $message['subject'], $message['text'] . $subtext, $attachments, true, Message::getReceiverEmailAndName($message['creator_id']), Message::getReceiverEmailAndName($message['creator_id'])); try { $send_result = $email->send(); if ($send_result) { \Components\Entity\EmailNotification::delete($notification['id']); $good_cnt++; } else { \Components\Entity\EmailNotification::update($notification['id'], array('attempts_to_send' => $notification['attempts_to_send'] + 1, 'last_attempt' => time(), 'last_error' => $email->ErrorInfo)); } } catch (\Components\Exceptions\Exception $e) { \Components\Entity\EmailNotification::update($notification['id'], array('attempts_to_send' => $notification['attempts_to_send'] + 1, 'last_attempt' => time())); } unset($email); //} } } $notification_index++; } db::query("update ofc_sys_log set p_value=" . $execution_time_start . " where p_name='email_notify_last_tm_start'"); db::query("update ofc_sys_log set p_value=" . (time() - $execution_time_start) . " where p_name='email_notify_last_tm_work'"); db::query("update ofc_sys_log set p_value=" . $notification_index . " where p_name='email_notify_last_all_cnt'"); db::query("update ofc_sys_log set p_value=" . $good_cnt . " where p_name='email_notify_last_good_cnt'"); }
} if ($order["napr_id"]) { $napr = get_naprav_name($order["napr_id"]); } if ($order['disc_id']) { $disc = get_discipline_name($order['disc_id']); } else { $disc = $order['disc_user']; } $cost = $order["cost_kln"]; if ($cost == 0) { $cost = "оценка"; } print "<div style='margin-bottom: 5px'><a href='?type=cabinet'><< к списку заказов</a></div>" . "<div style='font-size: 12pt; font-weight: bold; margin-bottom: 10px;'>" . $order["subject"] . "</div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Номер заказа:</div><div class='cab_ord_row_val'>" . $order["id"] . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Вид работы:</div><div class='cab_ord_row_val'>" . $type . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Направление:</div><div class='cab_ord_row_val'>" . $napr . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Дисциплина:</div><div class='cab_ord_row_val'>" . $disc . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Принят:</div><div class='cab_ord_row_val'>" . date("d.m.Y", $order["created"]) . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Дата сдачи:</div><div class='cab_ord_row_val'>" . date("d.m.Y", $order["time_kln"]) . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Статус:</div><div class='cab_ord_row_val'>" . $status . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Стоимость, руб.:</div><div class='cab_ord_row_val'>" . $cost . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Оплачено, руб.:</div><div class='cab_ord_row_val'>" . $order["oplata_kln"] . "</div><div class='clear'></div></div>" . "<div class='cab_ord_row'><div class='cab_ord_row_capt'>Требования:</div><div class='cab_ord_row_val'>" . $order["about_kln"] . "</div><div class='clear'></div></div>"; $html = array(); $files = get_order_files($order["id"], 0); if (count($files)) { $html[] = '<p style="margin-top: 20px;">Файлы</p>'; $html[] = '<table cellpadding="4" cellspacing="1" width="100%">'; $html[] = '<tr class="header">'; $html[] = '<td>Название</td>'; $html[] = '<td>Размер</td>'; $html[] = '<td>Дата добавления</td>'; $html[] = '<td>Скачать</td>'; $html[] = '</tr>'; foreach ($files as $file) { $html[] = '<tr>'; $html[] = '<td>' . $file['name'] . '</td>'; $html[] = '<td>' . get_file_size($file['size']) . '</td>'; $html[] = '<td>' . _get_fmt_date_time($file['created']) . '</td>'; $html[] = '<td>' . generate_file_link_for_frame($file) . '</td>';