static function DownloadEmails($cronJob = false, $exists = false, $reload = false) { if (is_array(Server::$Groups)) { foreach (Server::$Groups as $group) { $gmbout = Mailbox::GetById($group->TicketEmailOut); if (is_array($group->TicketEmailIn)) { foreach ($group->TicketEmailIn as $mid) { if (!empty(Server::$Configuration->Database["gl_email"][$mid]) && Server::$Configuration->Database["gl_email"][$mid]->LastConnect < time() - Server::$Configuration->Database["gl_email"][$mid]->ConnectFrequency * 60) { CacheManager::FlushKey(DATA_CACHE_KEY_DBCONFIG); Server::$Configuration->Database["gl_email"][$mid]->SetLastConnect(time()); $newmails = Server::$Configuration->Database["gl_email"][$mid]->Download($reload, Server::$Configuration->Database["gl_email"][$mid]->Delete); if ($reload) { Server::$Configuration->Database["gl_email"][$mid]->SetLastConnect(0); } if (!empty($newmails) && is_array($newmails)) { foreach ($newmails as $temail) { if (TicketEmail::Exists($temail->Id)) { continue; } $Ticket = null; $temail->MailboxId = $mid; $temail->GroupId = $group->Id; if (preg_match_all("/\\[[a-zA-Z\\d]{12}\\]/", $temail->Subject . $temail->Body . $temail->BodyHTML, $matches)) { if (empty(Server::$Configuration->File["gl_avhe"])) { $temail->BodyHTML = ""; } foreach ($matches[0] as $match) { $id = $groupid = $language = ""; if ($exists = Ticket::Exists($match, $id, $groupid, $language)) { $Ticket = new Ticket($id, true); $Ticket->ChannelId = $mid; $Ticket->Group = $groupid; $Ticket->Language = strtoupper($language); $Ticket->Messages[0]->Type = $gmbout != null && $temail->Email == $gmbout->Email || $temail->Email == Server::$Configuration->Database["gl_email"][$mid]->Email ? 1 : 3; $Ticket->Messages[0]->Text = $temail->Body; $Ticket->Messages[0]->Email = !empty($temail->ReplyTo) ? $temail->ReplyTo : $temail->Email; $Ticket->Messages[0]->ChannelId = $temail->Id; $Ticket->Messages[0]->Fullname = $temail->Name; $Ticket->Messages[0]->Subject = $temail->Subject; $Ticket->Messages[0]->Hash = strtoupper(str_replace(array("[", "]"), "", $match)); $Ticket->Messages[0]->Created = $temail->Created; $Ticket->Messages[0]->Save($id, false, null, $Ticket); $Ticket->Reactivate(); $Ticket->SetLastUpdate(time()); Logging::DebugLog("SAVE EMAIL REPLY: " . $Ticket->Messages[0]->Id . " - " . $temail->Id . " - " . $temail->Subject); break; } } } if (!$exists) { if ($group->TicketHandleUnknownEmails == 1) { $temail->Save(); } else { if ($group->TicketHandleUnknownEmails == 0) { $temail->Save(); $temail->Destroy(); $Ticket = new Ticket(CacheManager::GetObjectId("ticket_id", DATABASE_TICKETS), true); $Ticket->ChannelId = $mid; $Ticket->Group = $group->Id; $Ticket->CreationType = 1; $Ticket->Language = strtoupper(Server::$Configuration->File["gl_default_language"]); $Ticket->Messages[0]->Id = $Ticket->Id; $Ticket->Messages[0]->Type = 3; $Ticket->Messages[0]->Text = $temail->Body; $Ticket->Messages[0]->Email = !empty($temail->ReplyTo) ? $temail->ReplyTo : $temail->Email; $Ticket->Messages[0]->ChannelId = $temail->Id; $Ticket->Messages[0]->Fullname = $temail->Name; $Ticket->Messages[0]->Created = $temail->Created; $Ticket->Messages[0]->Subject = $temail->Subject; $Ticket->Messages[0]->Attachments = $temail->Attachments; $Ticket->Messages[0]->SaveAttachments(); $Ticket->Save(); $Ticket->AutoAssignEditor(); $Ticket->SetLastUpdate(time()); LocalizationManager::AutoLoad(strtolower(Server::$Configuration->File["gl_default_language"]), true); $Ticket->SendAutoresponder(new Visitor(""), new VisitorBrowser("", false)); LocalizationManager::AutoLoad("", true); } } } foreach ($temail->Attachments as $attid => $attdata) { file_put_contents(PATH_UPLOADS . $attdata[0], $attdata[2]); KnowledgeBase::Process("SYSTEM", $attid, $attdata[0], 3, $attdata[1], 0, 100, 1); if (!$exists && $group->TicketHandleUnknownEmails == 1) { $temail->SaveAttachment($attid); } if (!empty($Ticket)) { $Ticket->Messages[0]->ApplyAttachment($attid); } } } } if (!$cronJob) { return; } } } } } } }
function SaveTicket($_group, $_name, $_email, $_company, $_country, $_phone, $_cmb = false, $_text, $_custom = true, $_url = "") { global $INPUTS, $CONFIG, $INTERNAL; $isSpam = !empty($CONFIG["gl_sft"]) && createSPAMFilter(); $ticket = new Ticket(getObjectId("ticket_id", DATABASE_TICKETS), strtoupper(!empty($this->Language) ? $this->Language : $CONFIG["gl_default_language"])); $ticket->Messages[0]->Id = $ticket->Id; $ticket->Messages[0]->IP = getIP(); if (!isTicketFlood() && !$isSpam) { initData(array("INPUTS")); $ticket->SenderUserId = $ticket->Messages[0]->SenderUserId = $this->UserId; $ticket->Group = $_group; $ticket->Messages[0]->Fullname = $this->Browsers[0]->Fullname = $_name; $ticket->Messages[0]->Email = $this->Browsers[0]->Email = $_email; $ticket->Messages[0]->Company = $this->Browsers[0]->Company = $_company; $ticket->Messages[0]->Phone = $this->Browsers[0]->Phone = $_phone; $ticket->Messages[0]->Text = $_text; $ticket->Messages[0]->CallMeBack = $_cmb; $ticket->Messages[0]->Country = $_country; $ticket->Messages[0]->EmailId = getId(32); $ticket->Messages[0]->ChannelId = getId(32); $ticket->Messages[0]->Edited = $ticket->Messages[0]->Created = time(); $ticket->Messages[0]->Subject = $_url; $this->Browsers[0]->DesiredChatGroup = $ticket->Group; $this->Browsers[0]->SetCookieGroup(); if ($_custom) { foreach ($INPUTS as $index => $input) { if ($input->Active && $input->Custom) { if (isset($_POST["p_cf" . $index]) && !isset($_group->TicketInputsHidden[$index])) { $ticket->Messages[0]->Customs[$index] = $this->Browsers[0]->Customs[$index] = base64UrlDecode($_POST["p_cf" . $index]); } else { if (isset($_GET["cf" . $index]) && !isset($_group->TicketInputsHidden[$index])) { $ticket->Messages[0]->Customs[$index] = $this->Browsers[0]->Customs[$index] = base64UrlDecode($_GET["cf" . $index]); } } if ($input->Cookie && !empty($ticket->Messages[0]->Customs[$index])) { setCookieValue("cf_" . $index, $ticket->Messages[0]->Customs[$index]); } } else { if ($input->Active) { if ($input->Index == 111 && $input->Cookie) { setCookieValue("form_111", $ticket->Messages[0]->Fullname); } else { if ($input->Index == 112 && $input->Cookie) { setCookieValue("form_112", $ticket->Messages[0]->Email); } else { if ($input->Index == 113 && $input->Cookie) { setCookieValue("form_113", $ticket->Messages[0]->Company); } else { if ($input->Index == 114 && $input->Cookie) { setCookieValue("form_114", $ticket->Messages[0]->Text); } else { if ($input->Index == 116 && $input->Cookie) { setCookieValue("form_116", $ticket->Messages[0]->Phone); } } } } } } } } } if ($CONFIG["gl_adct"] == 1 || !(!empty($CONFIG["gl_rm_om"]) && $CONFIG["gl_rm_om_time"] == 0)) { $ticket->Save(); $ticket->AutoAssignEditor(); $ticket->SetLastUpdate(time()); } $this->AddFunctionCall("lz_chat_mail_callback(true);", false); if (!empty($_POST[POST_EXTERN_REQUESTED_INTERNID]) && !empty($INTERNAL[Operator::GetSystemId(base64UrlDecode($_POST[POST_EXTERN_REQUESTED_INTERNID]))])) { $TicketEditor = new TicketEditor($ticket->Id); $TicketEditor->Editor = Operator::GetSystemId(base64UrlDecode($_POST[POST_EXTERN_REQUESTED_INTERNID])); $TicketEditor->Status = 0; $TicketEditor->GroupId = $ticket->Group; $TicketEditor->Save(); } return $ticket; } else { $this->AddFunctionCall("lz_chat_mail_callback(false);", false); } return false; }
function SaveTicket($_group, $_country, $_cmb = false, $_custom = true, $_url = "", $changed = false) { global $INPUTS, $CONFIG, $INTERNAL, $GROUPS; $isSpam = !empty($CONFIG["gl_sft"]) && createSPAMFilter(); $ticket = new Ticket(getObjectId("ticket_id", DATABASE_TICKETS), strtoupper(!empty($this->Language) ? $this->Language : $CONFIG["gl_default_language"])); $ticket->Messages[0]->Id = $ticket->Id; $ticket->Messages[0]->IP = getIP(); $group = $GROUPS[$_group]; if (!isTicketFlood() && !$isSpam) { initData(array("INPUTS")); $ticket->SenderUserId = $ticket->Messages[0]->SenderUserId = $this->UserId; $ticket->Group = $_group; $ticket->Messages[0]->Fullname = $this->Browsers[0]->Fullname = $group->GetServerInput($INPUTS[111], false, "", $changed); $ticket->Messages[0]->Email = $this->Browsers[0]->Email = $group->GetServerInput($INPUTS[112], false, "", $changed); $ticket->Messages[0]->Company = $this->Browsers[0]->Company = $group->GetServerInput($INPUTS[113], false, "", $changed); $ticket->Messages[0]->Phone = $this->Browsers[0]->Phone = $group->GetServerInput($INPUTS[116], false, "", $changed); $ticket->Messages[0]->Text = $group->GetServerInput($INPUTS[114], false, "", $changed); $ticket->Messages[0]->CallMeBack = $_cmb; $ticket->Messages[0]->Country = $_country; $ticket->Messages[0]->EmailId = getId(32); $ticket->Messages[0]->ChannelId = getId(32); $ticket->Messages[0]->Edited = $ticket->Messages[0]->Created = time(); if (empty($_url)) { $_url = Visitor::GetLastURLFromVisitor($this->UserId); } $ticket->Messages[0]->Subject = $_url; $this->Browsers[0]->DesiredChatGroup = $ticket->Group; $this->Browsers[0]->SetCookieGroup(); if ($_custom) { foreach ($INPUTS as $index => $input) { if ($input->Active && $input->Custom) { $value = $group->GetServerInput($input, false, "", $changed); if ($input->Type != "File" && !empty($value) && !in_array($index, $group->TicketInputsHidden)) { $ticket->Messages[0]->Customs[$index] = $this->Browsers[0]->Customs[$index] = $value; } else { if ($input->Type == "File" && isset($_FILES["p_cf" . $index]) && !in_array($index, $group->TicketInputsHidden)) { $ticket->Messages[0]->Customs[$index] = $this->Browsers[0]->Customs[$index] = $ticket->Messages[0]->AppendPostFile("p_cf" . $index, $this->UserId); } } if ($input->Cookie && !empty($ticket->Messages[0]->Customs[$index]) && $input->Type != "File") { setCookieValue("cf_" . $index, $ticket->Messages[0]->Customs[$index]); } } else { if ($input->Active) { if ($input->Index == 111 && $input->Cookie) { setCookieValue("form_111", $ticket->Messages[0]->Fullname); } else { if ($input->Index == 112 && $input->Cookie) { setCookieValue("form_112", $ticket->Messages[0]->Email); } else { if ($input->Index == 113 && $input->Cookie) { setCookieValue("form_113", $ticket->Messages[0]->Company); } else { if ($input->Index == 114 && $input->Cookie) { setCookieValue("form_114", $ticket->Messages[0]->Text); } else { if ($input->Index == 116 && $input->Cookie) { setCookieValue("form_116", $ticket->Messages[0]->Phone); } } } } } } } } } if ($CONFIG["gl_adct"] == 1 || !(!empty($CONFIG["gl_rm_om"]) && $CONFIG["gl_rm_om_time"] == 0)) { $ticket->Save(); $ticket->AutoAssignEditor(); $ticket->SetLastUpdate(time()); } $this->AddFunctionCall("lz_chat_mail_callback(true);", false); if (!empty($_POST[POST_EXTERN_REQUESTED_INTERNID]) && !empty($INTERNAL[Operator::GetSystemId(base64UrlDecode($_POST[POST_EXTERN_REQUESTED_INTERNID]))])) { $TicketEditor = new TicketEditor($ticket->Id); $TicketEditor->Editor = Operator::GetSystemId(base64UrlDecode($_POST[POST_EXTERN_REQUESTED_INTERNID])); $TicketEditor->Status = 0; $TicketEditor->GroupId = $ticket->Group; $TicketEditor->Save(); } if (!empty($CONFIG["gl_mpm"])) { foreach ($INTERNAL as $operator) { if ($operator->IsInPushMessageState()) { if ($operator->HasAccessToTicket($ticket)) { $operator->AddPushMessage($ticket->Id, $this->SystemId, $_name, 2, $_text); } } } } return $ticket; } else { $this->AddFunctionCall("lz_chat_mail_callback(false);", false); } return false; }
function downloadEmails($cronJob = false, $exists = false, $reload = false) { global $GROUPS, $CONFIG, $INTERNAL; if (is_array($GROUPS)) { foreach ($GROUPS as $group) { $gmbout = Mailbox::GetById($group->TicketEmailOut); if (is_array($group->TicketEmailIn)) { foreach ($group->TicketEmailIn as $mid) { if (!empty($CONFIG["db"]["gl_email"][$mid]) && $CONFIG["db"]["gl_email"][$mid]->LastConnect < time() - $CONFIG["db"]["gl_email"][$mid]->ConnectFrequency * 60) { $CONFIG["db"]["gl_email"][$mid]->SetLastConnect(time()); $newmails = downloadFromMailbox($reload, $CONFIG["db"]["gl_email"][$mid]->Type, $CONFIG["db"]["gl_email"][$mid]->Host, $CONFIG["db"]["gl_email"][$mid]->Port, $CONFIG["db"]["gl_email"][$mid]->Password, $CONFIG["db"]["gl_email"][$mid]->Username, $CONFIG["db"]["gl_email"][$mid]->SSL, $CONFIG["db"]["gl_email"][$mid]->Delete); if ($reload) { $CONFIG["db"]["gl_email"][$mid]->SetLastConnect(0); } if (!empty($newmails) && is_array($newmails)) { foreach ($newmails as $temail) { if (TicketEmail::Exists($temail->Id)) { continue; } $Ticket = null; $temail->MailboxId = $mid; $temail->GroupId = $group->Id; if (preg_match_all("/\\[[a-zA-Z\\d]{12}\\]/", $temail->Subject . $temail->Body, $matches)) { foreach ($matches[0] as $match) { $id = $groupid = $language = ""; if ($exists = Ticket::Exists($match, $id, $groupid, $language)) { $Ticket = new Ticket($id, true); $Ticket->Group = $groupid; $Ticket->Language = strtoupper($language); $Ticket->Messages[0]->Type = $temail->Email == $gmbout->Email || $temail->Email == $CONFIG["db"]["gl_email"][$mid]->Email ? 1 : 3; $Ticket->Messages[0]->Text = $temail->Body; $Ticket->Messages[0]->Email = !empty($temail->ReplyTo) ? $temail->ReplyTo : $temail->Email; $Ticket->Messages[0]->ChannelId = $temail->Id; $Ticket->Messages[0]->Fullname = $temail->Name; $Ticket->Messages[0]->Subject = $temail->Subject; $Ticket->Messages[0]->Hash = strtoupper(str_replace(array("[", "]"), "", $match)); $Ticket->Messages[0]->Edited = $Ticket->Messages[0]->Created = $temail->Created; if (DEBUG_MODE) { logit("SAVE EMAIL REPLY: " . $temail->Id . " - " . $temail->Subject); } $Ticket->Messages[0]->Save($id, $temail->Created); $Ticket->Reactivate(); $Ticket->SetLastUpdate(time()); } } } if (!$exists) { if ($group->TicketHandleUnknownEmails == 1) { if (DEBUG_MODE) { logit("SAVE EMAIL: " . $temail->Id . " - " . $temail->Subject); } $temail->Save(); } else { if ($group->TicketHandleUnknownEmails == 0) { $Ticket = new Ticket(getObjectId("ticket_id", DATABASE_TICKETS), true); $Ticket->Group = $group->Id; $Ticket->CreationType = 1; $Ticket->Language = strtoupper($CONFIG["gl_default_language"]); $Ticket->Messages[0]->Id = $Ticket->Id; $Ticket->Messages[0]->Type = 3; $Ticket->Messages[0]->Text = $temail->Body; $Ticket->Messages[0]->Email = !empty($temail->ReplyTo) ? $temail->ReplyTo : $temail->Email; $Ticket->Messages[0]->ChannelId = $temail->Id; $Ticket->Messages[0]->Fullname = $temail->Name; $Ticket->Messages[0]->Created = $temail->Created; $Ticket->Messages[0]->Subject = $temail->Subject; $Ticket->Messages[0]->Attachments = $temail->Attachments; $Ticket->Messages[0]->SaveAttachments(); $Ticket->Save(); $Ticket->AutoAssignEditor(); $Ticket->SetLastUpdate(time()); languageSelect(strtolower($CONFIG["gl_default_language"]), true); Visitor::SendTicketAutoresponder($Ticket, strtoupper($CONFIG["gl_default_language"]), false); languageSelect("", true); } } if (!empty($CONFIG["gl_mpm"])) { foreach ($INTERNAL as $operator) { if ($operator->IsInPushMessageState()) { if ($operator->HasAccessToEmail($group->Id)) { $operator->AddPushMessage($temail->Id, $this->SystemId, !empty($temail->Name) ? $temail->Name : $temail->Email, 3, $temail->Body); } } } } } foreach ($temail->Attachments as $attid => $attdata) { file_put_contents(PATH_UPLOADS . $attdata[0], $attdata[2]); processResource("SYSTEM", $attid, $attdata[0], 3, $attdata[1], 0, 100, 1); if (!$exists && $group->TicketHandleUnknownEmails == 1) { $temail->SaveAttachment($attid); } if (!empty($Ticket)) { $Ticket->Messages[0]->ApplyAttachment($attid); } } } } if (!$cronJob) { return; } } } } } } }
function SaveTicket($_group, $_country, $_cmb = false, $_custom = true, $_url = "", $changed = false) { $isSpam = !empty(Server::$Configuration->File["gl_sft"]) && Visitor::CreateSPAMFilter($this->UserId); $ticket = new Ticket(CacheManager::GetObjectId("ticket_id", DATABASE_TICKETS), strtoupper(!empty($this->Language) ? $this->Language : Server::$Configuration->File["gl_default_language"])); $ticket->Messages[0]->Id = $ticket->Id; $ticket->Messages[0]->IP = Communication::GetIP(); $group = Server::$Groups[$_group]; if (!isTicketFlood() && !$isSpam) { Server::InitDataBlock(array("INPUTS")); $ticket->SenderUserId = $ticket->Messages[0]->SenderUserId = $this->UserId; $ticket->Group = $_group; $ticket->Messages[0]->Fullname = $this->Browsers[0]->Fullname = $group->GetServerInput(Server::$Inputs[111], false, "", $changed); $ticket->Messages[0]->Email = $this->Browsers[0]->Email = $group->GetServerInput(Server::$Inputs[112], false, "", $changed); $ticket->Messages[0]->Company = $this->Browsers[0]->Company = $group->GetServerInput(Server::$Inputs[113], false, "", $changed); $ticket->Messages[0]->Phone = $this->Browsers[0]->Phone = $group->GetServerInput(Server::$Inputs[116], false, "", $changed); $ticket->Messages[0]->Text = $group->GetServerInput(Server::$Inputs[114], false, "", $changed); $ticket->Messages[0]->CallMeBack = $_cmb; $ticket->Messages[0]->Country = $_country; $ticket->Messages[0]->EmailId = getId(32); $ticket->Messages[0]->ChannelId = getId(32); $ticket->Messages[0]->Edited = $ticket->Messages[0]->Created = time(); if (empty($_url)) { $_url = Visitor::GetLastURLFromVisitor($this->UserId); } $ticket->Messages[0]->Subject = $_url; $this->Browsers[0]->DesiredChatGroup = $ticket->Group; $this->Browsers[0]->SetCookieGroup(); if ($_custom) { foreach (Server::$Inputs as $index => $input) { if ($input->Active && $input->Custom) { $value = $group->GetServerInput($input, false, "", $changed); if ($input->Type != "File" && !empty($value) && !in_array($index, $group->TicketInputsHidden)) { $ticket->Messages[0]->Customs[$index] = $this->Browsers[0]->Customs[$index] = $value; } else { if ($input->Type == "File" && isset($_FILES["p_cf" . $index]) && !in_array($index, $group->TicketInputsHidden)) { $ticket->Messages[0]->Customs[$index] = $this->Browsers[0]->Customs[$index] = $ticket->Messages[0]->AppendPostFile("p_cf" . $index, $this->UserId); } } } $ud = new UserData($ticket->Messages[0]->Fullname, $ticket->Messages[0]->Email, $ticket->Messages[0]->Company, $ticket->Messages[0]->Phone, $ticket->Messages[0]->Customs); $ud->Save(); $ud->SaveToCookie(); } } if (Server::$Configuration->File["gl_adct"] == 1 || !(!empty(Server::$Configuration->File["gl_rm_om"]) && Server::$Configuration->File["gl_rm_om_time"] == 0)) { $ticket->Save(); $ticket->AutoAssignEditor(); $ticket->SetLastUpdate(time()); } $this->AddFunctionCall("lz_chat_mail_callback(true);", false); if (!empty($_POST[POST_EXTERN_REQUESTED_INTERNID]) && !empty(Server::$Operators[Operator::GetSystemId(Encoding::Base64UrlDecode($_POST[POST_EXTERN_REQUESTED_INTERNID]))])) { $TicketEditor = new TicketEditor($ticket->Id); $TicketEditor->Editor = Operator::GetSystemId(Encoding::Base64UrlDecode($_POST[POST_EXTERN_REQUESTED_INTERNID])); $TicketEditor->Status = 0; $TicketEditor->GroupId = $ticket->Group; $TicketEditor->Save(); } if (!empty(Server::$Configuration->File["gl_mpm"])) { foreach (Server::$Operators as $operator) { if ($operator->IsInPushMessageState()) { if ($operator->HasAccessToTicket($ticket)) { $operator->AddPushMessage($ticket->Id, $this->SystemId, $ticket->Messages[0]->Fullname, 2, $ticket->Messages[0]->Text); } } } } return $ticket; } else { $this->AddFunctionCall("lz_chat_mail_callback(false);", false); } return false; }