function UpdateMessage($MESSAGE_ID, $arFields, $checkRights = "Y")
 {
     $err_mess = CTicket::err_mess() . "<br>Function: UpdateMessage<br>Line: ";
     global $DB, $USER;
     $MESSAGE_ID = intval($MESSAGE_ID);
     $bAdmin = "N";
     $bSupportTeam = "N";
     if ($checkRights == "Y") {
         $bAdmin = CTicket::IsAdmin() ? "Y" : "N";
         $bSupportTeam = CTicket::IsSupportTeam() ? "Y" : "N";
         $uid = $USER->GetID();
     } else {
         $bAdmin = "Y";
         $bSupportTeam = "Y";
         $uid = 0;
     }
     if ($bAdmin == "Y") {
         $ownerSid = $arFields["OWNER_SID"];
         $ownerUserID = $arFields["OWNER_USER_ID"];
         $arFields_u = array("TIMESTAMP_X" => $DB->GetNowFunction(), "C_NUMBER" => intval($arFields["C_NUMBER"]), "MESSAGE" => "'" . $DB->ForSql($arFields["MESSAGE"]) . "'", "MESSAGE_SEARCH" => "'" . ToUpper($DB->ForSql($arFields["MESSAGE"])) . "'", "SOURCE_ID" => intval($arFields["SOURCE_ID"]) > 0 ? intval($arFields["SOURCE_ID"]) : "null", "OWNER_SID" => "'" . $DB->ForSql($ownerSid, 255) . "'", "OWNER_USER_ID" => intval($ownerUserID) > 0 ? intval($ownerUserID) : "null", "MODIFIED_USER_ID" => intval($uid) > 0 ? intval($uid) : "null", "MODIFIED_GUEST_ID" => intval($_SESSION["SESS_GUEST_ID"]) > 0 ? intval($_SESSION["SESS_GUEST_ID"]) : "null", "EXTERNAL_ID" => intval($arFields["EXTERNAL_ID"]) > 0 ? intval($arFields["EXTERNAL_ID"]) : "null", "TASK_TIME" => intval($arFields["TASK_TIME"]) > 0 ? intval($arFields["TASK_TIME"]) : "null", "EXTERNAL_FIELD_1" => "'" . $DB->ForSql($arFields["EXTERNAL_FIELD_1"]) . "'", "IS_SPAM" => strlen($arFields["IS_SPAM"]) > 0 ? "'" . $arFields["IS_SPAM"] . "'" : "null", "IS_HIDDEN" => $arFields["IS_HIDDEN"] == "Y" ? "'Y'" : "'N'", "IS_LOG" => $arFields["IS_LOG"] == "Y" ? "'Y'" : "'N'", "IS_OVERDUE" => $arFields["IS_OVERDUE"] == "Y" ? "'Y'" : "'N'", "NOT_CHANGE_STATUS" => $arFields["NOT_CHANGE_STATUS"] == "Y" ? "'Y'" : "'N'");
         $notChangeStatus = is_set($arFields, "NOT_CHANGE_STATUS") && $arFields["NOT_CHANGE_STATUS"] == "Y" ? "Y" : "N";
         $rows = $DB->Update("b_ticket_message", $arFields_u, "WHERE ID='" . $MESSAGE_ID . "'", $err_mess . __LINE__);
         if (intval($rows) > 0) {
             $rsMessage = CTicket::GetMessageByID($MESSAGE_ID, $checkRights);
             if ($arMessage = $rsMessage->Fetch()) {
                 $ticketID = $arMessage["TICKET_ID"];
                 // обновим прикрепленные файлы
                 $not_image_extension_suffix = COption::GetOptionString("support", "NOT_IMAGE_EXTENSION_SUFFIX");
                 $not_image_upload_dir = COption::GetOptionString("support", "NOT_IMAGE_UPLOAD_DIR");
                 $max_size = COption::GetOptionString("support", "SUPPORT_MAX_FILESIZE");
                 $arrFiles = $arFields["FILES"];
                 if (is_array($arrFiles) && count($arrFiles) > 0) {
                     foreach ($arrFiles as $arFile) {
                         if (strlen($arFile["name"]) > 0 || $arFile["del"] == "Y") {
                             if ($bSupportTeam != "Y" && $bAdmin != "Y") {
                                 $max_file_size = intval($max_size) * 1024;
                             }
                             $fes = "";
                             $upload_dir = "support";
                             if (!CFile::IsImage($arFile["name"], $arFile["type"])) {
                                 $fes = $not_image_extension_suffix;
                                 $arFile["name"] .= $fes;
                                 $upload_dir = $not_image_upload_dir;
                             }
                             if (!array_key_exists("MODULE_ID", $arFile) || strlen($arFile["MODULE_ID"]) <= 0) {
                                 $arFile["MODULE_ID"] = "support";
                             }
                             $fid = intval(CFile::SaveFile($arFile, $upload_dir, $max_file_size));
                             // если стоял флаг "Удалить" то
                             if ($arFile["del"] == "Y") {
                                 // удалим связку
                                 $strSql = "\n\t\t\t\t\t\t\t\t\t\tDELETE FROM\n\t\t\t\t\t\t\t\t\t\t\tb_ticket_message_2_file\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\tFILE_ID=" . intval($arFile["old_file"]) . "\n\t\t\t\t\t\t\t\t\t\t";
                                 $DB->Query($strSql, false, $err_mess . __LINE__);
                             }
                             // если успешно загрузили файл то
                             if ($fid > 0) {
                                 // если это был новый файл то
                                 if (intval($arFile["old_file"]) <= 0) {
                                     // добавим связку
                                     $md5 = md5(uniqid(mt_rand(), true) . time());
                                     $arFields_fi = array("HASH" => "'" . $DB->ForSql($md5, 255) . "'", "MESSAGE_ID" => $MESSAGE_ID, "FILE_ID" => $fid, "TICKET_ID" => $ticketID, "EXTENSION_SUFFIX" => strlen($fes) > 0 ? "'" . $DB->ForSql($fes, 255) . "'" : "null");
                                     $DB->Insert("b_ticket_message_2_file", $arFields_fi, $err_mess . __LINE__);
                                 } else {
                                     // обновим связку
                                     $arFields_fu = array("FILE_ID" => $fid, "EXTENSION_SUFFIX" => strlen($fes) > 0 ? "'" . $DB->ForSql($fes, 255) . "'" : "null");
                                     $DB->Update("b_ticket_message_2_file", $arFields_fu, "WHERE FILE_ID = " . intval($arFile["old_file"]), $err_mess . __LINE__);
                                 }
                             }
                         }
                     }
                 }
                 if ($arFields["IS_SPAM"] == "Y") {
                     CTicket::MarkMessageAsSpam($MESSAGE_ID, "Y", $checkRights);
                 } elseif ($arFields["IS_SPAM"] == "N") {
                     CTicket::MarkMessageAsSpam($MESSAGE_ID, "N", $checkRights);
                 } elseif ($arFields["IS_SPAM"] != "Y" && $arFields["IS_SPAM"] != "N") {
                     CTicket::UnMarkMessageAsSpam($MESSAGE_ID, $checkRights);
                 }
                 //if ($notChangeStatus != "Y")
                 CTicket::UpdateLastParams($ticketID);
                 //if ($notChangeStatus!="Y" && $hidden!="Y" && $log!="Y")
                 //{
                 //CTicketReminder::Update($ticketID);
                 //}
                 if ($log != "Y") {
                     $strSql = "SELECT SITE_ID, TITLE FROM b_ticket T WHERE ID='{$ticketID}'";
                     $rsTicket = $DB->Query($strSql, false, $err_mess . __LINE__);
                     $arTicket = $rsTicket->Fetch();
                     CSupportSearch::writeWordsInTable($MESSAGE_ID, $arTicket["SITE_ID"], $arTicket["TITLE"] . " " . $arFields["MESSAGE"]);
                 }
             }
         }
     }
 }
Exemple #2
0
 function UnMarkAsSpam($ticketID, $checkRights = "Y")
 {
     $err_mess = CAllTicket::err_mess() . "<br>Function: UnMarkAsSpam<br>Line: ";
     global $DB, $USER;
     $ticketID = intval($ticketID);
     if ($ticketID <= 0) {
         return;
     }
     if ($checkRights == "Y") {
         $bAdmin = CTicket::IsAdmin() ? "Y" : "N";
         $bSupportTeam = CTicket::IsSupportTeam() ? "Y" : "N";
     } else {
         $bAdmin = "Y";
         $bSupportTeam = "Y";
     }
     if ($bAdmin == "Y" || $bSupportTeam == "Y") {
         $arFilter = array("TICKET_ID" => $ticketID, "TICKET_ID_EXACT_MATCH" => "Y");
         $a = $b = $c = null;
         if ($rsMessages = CTicket::GetMessageList($a, $b, $arFilter, $c, $checkRights)) {
             // снимаем отметку о спаме только у первого сообщения
             if ($arMessage = $rsMessages->Fetch()) {
                 CTicket::UnMarkMessageAsSpam($arMessage["ID"], $checkRights);
             }
         }
         $arFields = array("IS_SPAM" => "null");
         $DB->Update("b_ticket", $arFields, "WHERE ID=" . $ticketID, $err_mess . __LINE__);
     }
 }