Ejemplo n.º 1
0
    /**
     * 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)
            );
        }
    }
Ejemplo n.º 2
0
 }
 if (!has_online_operators($groupid)) {
     $page = array();
     setup_logo();
     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();
Ejemplo n.º 3
0
/**
 * Prepare data to display leave message form
 *
 * @param string $name User name
 * @param string $email User email
 * @param int $group_id Id of selected group
 * @param string $info User info
 * @param string $referrer URL of referrer page
 * @return array Array of leave message form data
 */
function setup_leavemessage($name, $email, $group_id, $info, $referrer)
{
    $data = prepare_chat_app_data();
    // Create some empty arrays
    $data['leaveMessage'] = array();
    $group = group_by_id($group_id);
    $group_name = '';
    if ($group) {
        $group_name = get_group_name($group);
    }
    $data['leaveMessage']['leaveMessageForm'] = array('name' => $name, 'email' => $email, 'groupId' => $group_id, 'groupName' => $group_name, 'info' => $info, 'referrer' => $referrer, 'showCaptcha' => (bool) (Settings::get("enablecaptcha") == "1" && can_show_captcha()));
    $data['page.title'] = (empty($group_name) ? '' : $group_name . ': ') . getlocal('Leave your message');
    $data['leaveMessage']['page'] = array('title' => $data['page.title']);
    if (Settings::get('enablegroups') == '1') {
        $data['leaveMessage']['leaveMessageForm']['groups'] = prepare_groups_select($group_id);
    }
    $data['startFrom'] = 'leaveMessage';
    return $data;
}
Ejemplo n.º 4
0
            if (!is_valid_email($email)) {
                $errors[] = wrong_field("form.field.email");
            }
        }
    }
}
if ($settings["enablecaptcha"] == "1" && can_show_captcha()) {
    $captcha = getparam('captcha');
    $original = isset($_SESSION["mibew_captcha"]) ? $_SESSION["mibew_captcha"] : "";
    if (empty($original) || empty($captcha) || $captcha != $original) {
        $errors[] = getlocal('errors.captcha');
    }
    unset($_SESSION['mibew_captcha']);
}
if (count($errors) > 0) {
    setup_leavemessage($visitor_name, $email, $message, $groupid, $groupname, $info, $referrer, can_show_captcha());
    setup_logo();
    expand("styles", getchatstyle(), "leavemessage.tpl");
    exit;
}
$message_locale = $settings['left_messages_locale'];
if (!locale_exists($message_locale)) {
    $message_locale = $home_locale;
}
store_message($visitor_name, $email, $info, $message, $groupid, $referrer);
$subject = getstring2_("leavemail.subject", array($visitor_name), $message_locale);
$body = getstring2_("leavemail.body", array($visitor_name, $email, $message, $info ? "{$info}\n" : ""), $message_locale);
if (isset($group) && !empty($group['vcemail'])) {
    $inbox_mail = $group['vcemail'];
} else {
    $inbox_mail = $settings['email'];