function store_message($name, $email, $info, $message, $groupid, $referrer) { global $state_left, $current_locale, $kind_for_agent, $kind_user; $remoteHost = get_remote_host(); $userbrowser = $_SERVER['HTTP_USER_AGENT']; $visitor = visitor_from_request(); $link = connect(); $thread = create_thread($groupid, $name, $remoteHost, $referrer, $current_locale, $visitor['id'], $userbrowser, $state_left, $link); if ($referrer) { post_message_($thread['threadid'], $kind_for_agent, getstring2('chat.came.from', array($referrer)), $link); } if ($email) { post_message_($thread['threadid'], $kind_for_agent, getstring2('chat.visitor.email', array($email)), $link); } if ($info) { post_message_($thread['threadid'], $kind_for_agent, getstring2('chat.visitor.info', array($info)), $link); } post_message_($thread['threadid'], $kind_user, $message, $link, $name); mysql_close($link); }
/** * Process submitted leave message form. * * Send message to operator email and create special meil thread. * @param array $args Associative array of arguments. It must contains the * following keys: * - 'threadId': for this function this param equals to null; * - 'token': for this function this param equals to null; * - 'name': string, user name; * - 'email': string, user email; * - 'message': string, user message; * - 'info': string, some info about user; * - 'referrer': string, page user came from; * - 'captcha': string, captcha value; * - 'groupId': selected group id. * * @throws \Mibew\RequestProcessor\ThreadProcessorException Can throw an * exception if captcha or email is wrong. */ protected function apiProcessLeaveMessage($args) { // Check captcha if (Settings::get('enablecaptcha') == '1' && can_show_captcha()) { $captcha = $args['captcha']; $original = isset($_SESSION[SESSION_PREFIX . 'mibew_captcha']) ? $_SESSION[SESSION_PREFIX . 'mibew_captcha'] : ''; unset($_SESSION[SESSION_PREFIX . 'mibew_captcha']); if (empty($original) || empty($captcha) || $captcha != $original) { throw new ThreadProcessorException( getlocal('The letters you typed don\'t match the letters that were shown in the picture.'), ThreadProcessorException::ERROR_WRONG_CAPTCHA ); } } // Get form fields $email = $args['email']; $name = $args['name']; $message = $args['message']; $info = $args['info']; $referrer = $args['referrer']; if (!MailUtils::isValidAddress($email)) { throw new ThreadProcessorException( wrong_field("Your email"), ThreadProcessorException::ERROR_WRONG_EMAIL ); } // Verify group id $group_id = ''; if (Settings::get('enablegroups') == '1') { if (preg_match("/^\d{1,8}$/", $args['groupId']) != 0) { $group = group_by_id($args['groupId']); if ($group) { $group_id = $args['groupId']; } } } // Create thread for left message $remote_host = get_remote_host(); $user_browser = $_SERVER['HTTP_USER_AGENT']; $visitor = visitor_from_request(); // Get message locale $message_locale = Settings::get('left_messages_locale'); if (!locale_is_available($message_locale)) { $message_locale = get_home_locale(); } // Create thread $thread = new Thread(); $thread->groupId = $group_id; $thread->userName = $name; $thread->remote = $remote_host; $thread->referer = $referrer; $thread->locale = get_current_locale(); $thread->userId = $visitor['id']; $thread->userAgent = $user_browser; $thread->state = Thread::STATE_LEFT; $thread->closed = time(); $thread->save(); // Send some messages if ($referrer) { $thread->postMessage( Thread::KIND_FOR_AGENT, getlocal('Vistor came from page {0}', array($referrer), get_current_locale(), true) ); } if ($email) { $thread->postMessage( Thread::KIND_FOR_AGENT, getlocal('E-Mail: {0}', array($email), get_current_locale(), true) ); } if ($info) { $thread->postMessage( Thread::KIND_FOR_AGENT, getlocal('Info: {0}', array($info), get_current_locale(), true) ); } $thread->postMessage(Thread::KIND_USER, $message, array('name' => $name)); // Get email for message $inbox_mail = get_group_email($group_id); if (empty($inbox_mail)) { $inbox_mail = Settings::get('email'); } // Send email if ($inbox_mail) { // Prepare message to send by email $mail_template = MailTemplate::loadByName('leave_message', $message_locale); if (!$mail_template) { trigger_error( 'Cannot send e-mail because "leave_message" mail template cannot be loaded.', E_USER_WARNING ); return; } $subject = $mail_template->buildSubject(array($args['name'])); $body = $mail_template->buildBody(array( $args['name'], $email, $message, ($info ? $info . "\n" : ""), )); // Send $this->getMailerFactory()->getMailer()->send( MailUtils::buildMessage($inbox_mail, $email, $subject, $body) ); } }
/** * Start chat thread for user * * @param int $group_id Id of group related to thread * @param array $requested_operator Array of requested operator info * @param string $visitor_id Id of the visitor * @param string $visitor_name Name of the visitor * @param string $referrer Page user came from * @param string $info User info * * @return Thread thread object */ function chat_start_for_user($group_id, $requested_operator, $visitor_id, $visitor_name, $referrer, $info) { // Get user info $remote_host = get_remote_host(); $user_browser = $_SERVER['HTTP_USER_AGENT']; // Check connection limit if (Thread::connectionLimitReached($remote_host)) { die("number of connections from your IP is exceeded, try again later"); } // Check if visitor was invited to chat $is_invited = false; if (Settings::get('enabletracking')) { $invitation_state = invitation_state($_SESSION[SESSION_PREFIX . 'visitorid']); if ($invitation_state['invited']) { $is_invited = true; } } // Get info about requested operator $requested_operator_online = false; if ($requested_operator) { $requested_operator_online = is_operator_online($requested_operator['operatorid']); } // Get thread object if ($is_invited) { // Get thread from invitation $thread = invitation_accept($_SESSION[SESSION_PREFIX . 'visitorid']); if (!$thread) { die("Cannot start thread"); } } else { // Create thread $thread = new Thread(); $thread->state = Thread::STATE_LOADING; $thread->agentId = 0; if ($requested_operator && $requested_operator_online) { $thread->nextAgent = $requested_operator['operatorid']; } } // Update thread fields $thread->groupId = $group_id; $thread->userName = $visitor_name; $thread->remote = $remote_host; $thread->referer = $referrer; $thread->locale = get_current_locale(); $thread->userId = $visitor_id; $thread->userAgent = $user_browser; $thread->save(); $_SESSION[SESSION_PREFIX . 'threadid'] = $thread->id; // Store own thread ids to restrict access for other people if (!isset($_SESSION[SESSION_PREFIX . 'own_threads'])) { $_SESSION[SESSION_PREFIX . 'own_threads'] = array(); } $_SESSION[SESSION_PREFIX . 'own_threads'][] = $thread->id; // Bind thread to the visitor if (Settings::get('enabletracking')) { track_visitor_bind_thread($visitor_id, $thread); } // Send several messages if ($is_invited) { $operator = operator_by_id($thread->agentId); $operator_name = get_operator_name($operator); $thread->postMessage(Thread::KIND_FOR_AGENT, getlocal('Visitor accepted invitation from operator {0}', array($operator_name), get_current_locale(), true)); } else { if ($referrer) { $thread->postMessage(Thread::KIND_FOR_AGENT, getlocal('Vistor came from page {0}', array($referrer), get_current_locale(), true)); } if ($requested_operator && !$requested_operator_online) { $thread->postMessage(Thread::KIND_INFO, getlocal('Thank you for contacting us. We are sorry, but requested operator <strong>{0}</strong> is offline. Another operator will be with you shortly.', array(get_operator_name($requested_operator)), get_current_locale(), true)); } else { $thread->postMessage(Thread::KIND_INFO, getlocal('Thank you for contacting us. An operator will be with you shortly.', null, get_current_locale(), true)); } } // TODO: May be move sending this message somewhere else? if ($info) { $thread->postMessage(Thread::KIND_FOR_AGENT, getlocal('Info: {0}', array($info), get_current_locale(), true)); } // Let plugins know that user is ready to chat. $dispatcher = EventDispatcher::getInstance(); $event_args = array('thread' => $thread); $dispatcher->triggerEvent(Events::THREAD_USER_IS_READY, $event_args); return $thread; }
setup_leavemessage($visitor['name'], $email, $firstmessage, $groupid, $groupname, $info, $referrer, can_show_captcha()); expand("styles", getchatstyle(), "leavemessage.tpl"); exit; } $show_survey = $settings['enablepresurvey'] == '1' && (!(isset($_POST['survey']) && $_POST['survey'] == 'on') || $settings["surveyaskcaptcha"] == "1" && !empty($survey_captcha_failed)); if ($show_survey) { $page = array(); setup_logo(); if (!empty($survey_captcha_failed)) { $errors[] = getlocal('errors.captcha'); } setup_survey($visitor['name'], $email, $groupid, $info, $referrer, can_show_captcha()); expand("styles", getchatstyle(), "survey.tpl"); exit; } $remoteHost = get_remote_host(); $userbrowser = $_SERVER['HTTP_USER_AGENT']; $link = connect(); if (!check_connections_from_remote($remoteHost, $link)) { mysql_close($link); die("number of connections from your IP is exceeded, try again later"); } $thread = create_thread($groupid, $visitor['name'], $remoteHost, $referrer, $current_locale, $visitor['id'], $userbrowser, $state_loading, $link); $_SESSION['threadid'] = $thread['threadid']; // Store own thread ids to restrict access for other people if (!isset($_SESSION['own_threads'])) { $_SESSION['own_threads'] = array(); } $_SESSION['own_threads'][] = $thread['threadid']; if ($referrer) { post_message_($thread['threadid'], $kind_for_agent, getstring2('chat.came.from', array($referrer), true), $link);
function track_build_details() { $result = array('user_agent' => $_SERVER['HTTP_USER_AGENT'], 'remote_host' => get_remote_host()); return serialize($result); }