function sendChatTranscripts($_custom = false)
{
    global $CONFIG, $INTERNAL, $GROUPS, $INPUTS;
    initData(array("INTERNAL", "INPUTS"));
    closeChats();
    $defmailbox = Mailbox::GetDefaultOutgoing();
    $result = queryDB(false, "SELECT `voucher_id`,`subject`,`customs`,`internal_id`,`transcript_text`,`transcript_receiver`,`email`,`chat_id`,`fullname`,`group_id` FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `chat_type`=1 AND `endtime`>0 AND `closed`>0 AND `transcript_sent`=0 LIMIT 1;");
    if ($result) {
        while ($row = DBManager::FetchArray($result)) {
            if (empty($row["transcript_text"])) {
                continue;
            }
            queryDB(true, "UPDATE `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` SET `transcript_sent`=1 WHERE `chat_id`='" . DBManager::RealEscape($row["chat_id"]) . "' LIMIT 1;");
            $rcvs = str_replace(array("%fullname%", "%efullname%"), $row["fullname"], $row["transcript_text"]);
            $rcvs = str_replace(array("%email%", "%eemail%"), $row["email"], $rcvs);
            $rcvs = str_replace("%rating%", getRatingAVGFromChatId($row["chat_id"]), $rcvs);
            $subject = $row["subject"];
            $customs = @unserialize($row["customs"]);
            $fakeSender = "";
            foreach ($INPUTS as $index => $input) {
                if ($input->Active && $input->Custom && !isset($GROUPS[$row["group_id"]]->TicketInputsHidden[$index])) {
                    $cv = "";
                    if ($input->Type == "CheckBox") {
                        $cv = !empty($customs[$input->Name]) ? "<!--lang_client_yes-->" : "<!--lang_client_no-->";
                    } else {
                        if (!empty($customs[$input->Name]) || $input->Type == "ComboBox") {
                            $cv = $input->GetClientValue(@$customs[$input->Name]);
                        }
                    }
                    $rcvs = str_replace("%custom" . $index . "%", $cv, $rcvs);
                }
            }
            $rcvs = applyReplacements($rcvs);
            $rcvs = Mailbox::FinalizeEmail($rcvs . "\r\n\r\n<!--lz_ref_link-->");
            $mailbox = null;
            if (!empty($row["group_id"]) && isset($GROUPS[$row["group_id"]]) && !empty($GROUPS[$row["group_id"]]->ChatEmailOut)) {
                $mailbox = Mailbox::GetById($GROUPS[$row["group_id"]]->ChatEmailOut);
            }
            $mailbox = !empty($mailbox) ? $mailbox : $defmailbox;
            if ((!empty($CONFIG["gl_soct"]) || $_custom) && !empty($row["transcript_receiver"])) {
                sendMail($mailbox, $row["transcript_receiver"], $mailbox->Email, $rcvs, $subject);
            }
            if (!empty($CONFIG["gl_scto"]) && !$_custom) {
                initData(array("INTERNAL"));
                $receivers = array();
                $resulti = queryDB(true, "SELECT `sender`,`receiver` FROM `" . DB_PREFIX . DATABASE_POSTS . "` WHERE `chat_id`='" . DBManager::RealEscape($row["chat_id"]) . "';");
                if ($resulti) {
                    while ($rowi = DBManager::FetchArray($resulti)) {
                        if (!empty($INTERNAL[$rowi["sender"]]) && !in_array($rowi["sender"], $receivers)) {
                            $receivers[] = $rowi["sender"];
                        } else {
                            if (!empty($INTERNAL[$rowi["receiver"]]) && !in_array($rowi["receiver"], $receivers)) {
                                $receivers[] = $rowi["receiver"];
                            } else {
                                continue;
                            }
                        }
                        sendMail($mailbox, $INTERNAL[$receivers[count($receivers) - 1]]->Email, $mailbox->Email, $rcvs, $subject);
                    }
                }
            }
            if (!empty($CONFIG["gl_sctg"]) && !$_custom) {
                initData(array("GROUPS"));
                sendMail($mailbox, $GROUPS[$row["group_id"]]->Email, $mailbox->Email, $rcvs, $subject);
            }
            if (!empty($mailbox) && !empty($CONFIG["gl_scct"])) {
                if (!empty($CONFIG["gl_uvec"])) {
                    if (Mailbox::IsValidEmail($row["transcript_receiver"])) {
                        $fakeSender = $row["transcript_receiver"];
                    } else {
                        if (Mailbox::IsValidEmail($row["email"])) {
                            $fakeSender = $row["email"];
                        }
                    }
                }
                sendMail($mailbox, $CONFIG["gl_scct"], $mailbox->Email, $rcvs, $subject, false, null, $fakeSender);
            }
            if (!empty($row["voucher_id"])) {
                $ticket = new CommercialChatVoucher(null, $row["voucher_id"]);
                $ticket->Load();
                $ticket->SendStatusEmail();
            }
        }
    }
    if (!empty($CONFIG["gl_rm_chats"]) && $CONFIG["gl_rm_chats_time"] == 0) {
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CHAT_ARCHIVE . "` WHERE `transcript_sent` = '1';");
    }
}
 function SendAutoresponder($_visitor = null, $_browser = null, $_message = null)
 {
     if (empty($_message)) {
         $_message = $this->Messages[0];
     }
     $tsData = array("", "", "");
     if (!empty(Server::$Groups[$this->Group]->PredefinedMessages)) {
         $pdm = PredefinedMessage::GetByLanguage(Server::$Groups[$this->Group]->PredefinedMessages, $this->Language);
         if ($pdm != null) {
             if (!empty($pdm->EmailTicketResponderBodyPlaintext)) {
                 $tsData[0] = $pdm->EmailTicketResponderBodyPlaintext;
             }
             if (!empty($pdm->EmailTicketResponderBodyHTML)) {
                 $tsData[1] = $pdm->EmailTicketResponderBodyHTML;
             }
             $tsData[2] = $pdm->SubjectTicketResponder;
         }
     }
     for ($i = 0; $i < count($tsData); $i++) {
         $tText = ($i != 1 ? $_message->Text : nl2br($_message->Text)) . "<!--lz_ref_link-->";
         $tsData[$i] = str_replace("%mailtext%", $tText, $tsData[$i]);
         $tsData[$i] = $_message->TextReplace($tsData[$i], $this->Group);
         $tsData[$i] = $this->TextReplace($tsData[$i]);
         $tsData[$i] = Server::$Groups[$this->Group]->TextReplace($tsData[$i], $this->Language);
         if (!empty($_visitor)) {
             $tsData[$i] = $_visitor->TextReplace($tsData[$i]);
         }
         if (!empty($_browser)) {
             $tsData[$i] = $_browser->TextReplace($tsData[$i]);
         }
         $tsData[$i] = Configuration::Replace($tsData[$i]);
         $tsData[$i] = Mailbox::FinalizeEmail($tsData[$i], $i == 1);
         $tsData[$i] = Server::Replace($tsData[$i]);
     }
     //$mailbox = Mailbox::GetDefaultOutgoing();
     $mailbox = Mailbox::GetById(Server::$Groups[$this->Group]->TicketEmailOut, true);
     if ($mailbox != null) {
         $mb = clone $mailbox;
         $replytoint = Mailbox::IsValidEmail($_message->Email) ? $_message->Email : $mb->Email;
         $replytoex = $mb->Email;
         $fakeSender = "";
         if (!empty(Server::$Configuration->File["gl_usmasend"]) && Mailbox::IsValidEmail($_message->Email)) {
             $fakeSender = $_message->Email;
         }
         if (!empty(Server::$Configuration->File["gl_scom"])) {
             Communication::SendEmail($mb, Server::$Configuration->File["gl_scom"], $replytoint, $tsData[0], $tsData[1], $tsData[2], false, null, $fakeSender);
         }
         if (!empty(Server::$Configuration->File["gl_sgom"])) {
             Communication::SendEmail($mb, Server::$Groups[$this->Group]->Email, $replytoint, $tsData[0], $tsData[1], $tsData[2], false, null, $fakeSender);
         }
         if (!empty(Server::$Configuration->File["gl_ssom"]) && Mailbox::IsValidEmail($_message->Email)) {
             Communication::SendEmail($mb, str_replace(";", ",", $_message->Email), $replytoex, $tsData[0], $tsData[1], $tsData[2], false, null, $fakeSender);
         }
     }
 }
예제 #3
0
 function SendAutoresponder($_mailbox, $_message, $_pdm, $_att = null, $_subject = "")
 {
     global $CONFIG, $GROUPS;
     if ($_mailbox != null) {
         $mailbox = clone $_mailbox;
         $replytoint = Mailbox::IsValidEmail($this->Messages[0]->Email) ? $this->Messages[0]->Email : $mailbox->Email;
         $replytoex = $mailbox->Email;
         $fakeSender = "";
         if (empty($_subject)) {
             $_subject = $_pdm != null ? $_pdm->SubjectTicket : "";
             $_subject = str_replace("%ticket_hash%", $this->GetHash(true), $_subject);
         }
         $_message = str_replace("%ticket_hash%", $this->GetHash(true), $_message);
         if (!empty($CONFIG["gl_usmasend"]) && Mailbox::IsValidEmail($this->Messages[0]->Email)) {
             $fakeSender = $this->Messages[0]->Email;
         }
         if (!empty($CONFIG["gl_scom"])) {
             sendMail($mailbox, $CONFIG["gl_scom"], $replytoint, $_message, getSubject($_subject, $this->Messages[0]->Email, $this->Messages[0]->Fullname, $this->Group, "", $this->Messages[0]->Company, $this->Messages[0]->Phone, $this->Messages[0]->IP, $this->Messages[0]->Text, $GROUPS[$this->Group]->GetDescription($this->Language), $this->Messages[0]->Customs), false, $_att, $fakeSender);
         }
         if (!empty($CONFIG["gl_sgom"])) {
             sendMail($mailbox, $GROUPS[$this->Group]->Email, $replytoint, $_message, getSubject($_subject, $this->Messages[0]->Email, $this->Messages[0]->Fullname, $this->Group, "", $this->Messages[0]->Company, $this->Messages[0]->Phone, $this->Messages[0]->IP, $this->Messages[0]->Text, $GROUPS[$this->Group]->GetDescription($this->Language), $this->Messages[0]->Customs), false, $_att, $fakeSender);
         }
         if (!empty($CONFIG["gl_ssom"]) && Mailbox::IsValidEmail($this->Messages[0]->Email)) {
             sendMail($mailbox, str_replace(";", ",", $this->Messages[0]->Email), $replytoex, $_message, getSubject($_subject, $this->Messages[0]->Email, $this->Messages[0]->Fullname, $this->Group, "", $this->Messages[0]->Company, $this->Messages[0]->Phone, $this->Messages[0]->IP, $this->Messages[0]->Text, $GROUPS[$this->Group]->GetDescription($this->Language), $this->Messages[0]->Customs), false, $_att, $fakeSender);
         }
     }
 }