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 Save() { if (empty($this->UserId)) { return; } $_new = func_num_args() > 0 ? func_get_arg(0) : false; if ($_new) { $this->FirstCall = true; $this->Status = CHAT_STATUS_OPEN; } if (empty($this->ChatId) && empty(Server::$Configuration->File["gl_save_op"])) { $this->DesiredChatPartner = ""; } if (empty($this->FirstActive)) { $this->FirstActive = time(); } if ($this->FirstCall) { DBManager::Execute(true, "INSERT IGNORE INTO `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` (`visitor_id`,`browser_id`,`visit_id`,`priority`,`call_me_back`, `typing` ,`area_code` ,`first_active` ,`last_active` ,`request_operator` ,`request_group` , `chat_ticket_id`, `queue_posts`) VALUES ('" . DBManager::RealEscape($this->UserId) . "','" . DBManager::RealEscape($this->BrowserId) . "','" . DBManager::RealEscape($this->VisitId) . "','" . DBManager::RealEscape($this->Priority) . "'," . DBManager::RealEscape($this->CallMeBack ? 1 : 0) . ",0,'" . DBManager::RealEscape($this->Code) . "','" . DBManager::RealEscape($this->FirstActive) . "','" . DBManager::RealEscape($this->LastActive) . "','" . DBManager::RealEscape($this->DesiredChatPartner) . "','" . DBManager::RealEscape($this->DesiredChatGroup) . "','" . DBManager::RealEscape($this->ChatVoucherId) . "','" . DBManager::RealEscape(serialize($this->QueuedPosts)) . "');"); } else { DBManager::Execute(true, "UPDATE `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` SET `typing`='" . DBManager::RealEscape($this->Typing ? 1 : 0) . "',`queue_message_shown`='" . DBManager::RealEscape($this->QueueMessageShown ? 1 : 0) . "',`archive_created`=" . intval($this->ArchiveCreated) . ",`queue_posts`='" . DBManager::RealEscape(serialize($this->QueuedPosts)) . "',`request_operator`='" . DBManager::RealEscape($this->DesiredChatPartner) . "',`chat_ticket_id`='" . DBManager::RealEscape($this->ChatVoucherId) . "',`request_group`='" . DBManager::RealEscape($this->DesiredChatGroup) . "',`last_active`='" . DBManager::RealEscape(time()) . "' WHERE `browser_id`='" . DBManager::RealEscape($this->BrowserId) . "' AND `visitor_id`='" . DBManager::RealEscape($this->UserId) . "' AND `chat_id`='" . DBManager::RealEscape($this->ChatId) . "' LIMIT 1;"); } parent::Save(); if (count($this->History) == 0) { $url = Visitor::GetLastURLFromVisitor($this->UserId); if (empty($url)) { $this->History[0] = new HistoryUrl(LIVEZILLA_URL . FILE_CHAT, $this->Code, Server::$Configuration->File["gl_site_name"], "", $this->FirstActive); } else { $this->History[0] = new HistoryUrl($url, "", "", "", $this->FirstActive); } $this->History[0]->Save($this->BrowserId, true); } }