function find_prew_mails($id, $ret = array()) { try { $message = Message::find($id); } catch (InvalidArgumentException $e) { $message = array(); } if (!$message) { return $ret; } $message["sender"] = mls_getAdrName($message["creator_id"]); $ret[] = $message; $ret = find_prew_mails($message["parent_id"], $ret); return $ret; }
foreach ($ids as $id) { if (intval($id) > 0) { $message = Message::find($id); if ($message) { if ($message["addr"] == "u" . $_SESSION["user"]["data"]["id"]) { mls_setreaded($message); $n++; } } } } $GUI->OK("Отмечено писем: " . $n); die("" . $n); } if (isset($_REQUEST["ids_to_trash"])) { $n = 0; $ids = explode(";", $_REQUEST["ids_to_trash"]); foreach ($ids as $id) { if (intval($id) > 0) { $message = Message::find($id); if ($message) { if ($message["addr"] == "u" . $_SESSION["user"]["data"]["id"]) { mls_setbasket($message, 1); $n++; } } } } $GUI->OK("Перемещено в корзину писем: " . $n); die("" . $n); }
<?php use Components\Classes\Roles; use Components\Classes\db; use Components\Entity\Message; include_once "functions.php"; if (isset($_REQUEST["read"])) { $message = Message::find(intval($_REQUEST["read"])); if ($message) { $GUI->tmpls[] = $active_module_root . "read.tmpl.php"; include "inc_read.php"; return; } else { $GUI->ERR("Письмо не найдено"); page_ReloadSubSec(); } } if (isset($_REQUEST['delete'])) { \Components\Entity\EmailNotification::delete($_REQUEST['delete']); } $tbl = $GUI->Table("mls_problems", array("cur_sort_up" => true)); $tbl->Width = "100%"; $tbl->DataMYSQL('email_notifications en JOIN ' . TABLE_MESSAGES . ' m ON m.id=en.message_id', 'en.*, m.id AS mid', 'en'); $tbl->FilterMYSQL("en.attempts_to_send>0"); $tbl->Pager(CGUI_PAGER_FLAG_SEL | CGUI_PAGER_FLAG_RR | CGUI_PAGER_FLAG_R | CGUI_PAGER_FLAG_FF | CGUI_PAGER_FLAG_F, 10, array(10, 20, 50, 100, 0)); global $n; if (Roles::isActionAllowed($GUI->mmenu->selected->id, $GUI->mmenu->selected->selected->id, $_SESSION["user"]["data"]["group_id"], "Просмотр сообщения")) { $tbl->RowEvent2 = "if(window.locationLocked === undefined || window.locationLocked ==false) { document.location.href=\"?section=mls&subsection=" . MLS_SELECTED_INBOX . "&type=o&read=%var.message_id%\";} else window.locationLocked = false;"; } $tbl->OnRowStart = "_set_row_color"; $columns_resource = Roles::getColumns($GUI->mmenu->selected->id, $GUI->mmenu->selected->selected->id, $_SESSION["user"]["data"]["group_id"]);
if (isset($_REQUEST["_ans"])) { $id = intval($_REQUEST["_ans"]); $m = Message::find($id); if ($m && mls_userMaySee($m, $_SESSION["user"]["data"]["id"]) && $m["creator_id"] == $_REQUEST["_to"]) { $ansv_to = $m; $h = $frm->Hidden($id); $h->linkName = "ans"; $frm->Label("В ответ на письмо №" . $id . " от " . date("d.m.y", $m["created"]), 10, $ypos); $ypos += 30; } } $resend_to = false; if (isset($_REQUEST["_rep"])) { $id = intval($_REQUEST["_rep"]); // Переслать. Получим письмо, убедимся что пользователь может его видеть $m = Message::find($id); if ($m && mls_userMaySee($m, $_SESSION["user"]["data"]["id"])) { $ansv_to = false; $need_to = false; $resend_to = $m; } } $frm->Label("Тема", 10, $ypos); $s = ""; if ($ansv_to) { $s = "[Ответ на исх. №" . $ansv_to["id"] . " от " . date("d.m.y", $ansv_to["created"]) . "]"; } if ($resend_to) { $s = $resend_to["subject"]; } if (!empty($_REQUEST["_order"])) {
/** * @deprecated * @param $id * @return array */ function mls_get($id) { return Message::find($id); }
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'"); }
<?php use Components\Classes\Roles; use Components\Classes\db; use Components\Entity\Message; if (isset($_REQUEST["_add"])) { $message = Message::find(intval($_REQUEST["_add"])); if ($message && $message["addr"] == "u" . $_SESSION["user"]["data"]["id"]) { mls_setbasket($message, 1); if ($message["basket"]) { $GUI->OK("Перемещено в корзину"); } else { $GUI->ERR("Не удалось переместить в корзину"); } } else { $GUI->ERR("Нельзя переместить в корзину"); } page_reloadToSec("2"); } $tbl = $GUI->Table("mls_in", array("cur_sort_up" => true)); $tbl->Width = "100%"; $tbl->DataMYSQL("messages"); $tbl->FilterMYSQL("addr='u" . $_SESSION["user"]["data"]["id"] . "' AND basket=1"); $tbl->Pager(CGUI_PAGER_FLAG_SEL | CGUI_PAGER_FLAG_RR | CGUI_PAGER_FLAG_R | CGUI_PAGER_FLAG_FF | CGUI_PAGER_FLAG_F, 10, array(10, 20, 50, 100, 0)); global $n; if (Roles::isActionAllowed($GUI->mmenu->selected->id, $GUI->mmenu->selected->selected->id, $_SESSION["user"]["data"]["group_id"], "Просмотр сообщения")) { $tbl->RowEvent2 = "document.location.href=\"?section=mls&subsection=2&type=b&read=%var%\""; } $tbl->OnRowStart = "_set_row_color"; $columns_resource = Roles::getColumns($GUI->mmenu->selected->id, $GUI->mmenu->selected->selected->id, $_SESSION["user"]["data"]["group_id"]); if (!is_resource($columns_resource)) {