/** * Process submitting of the mail form. * * @param Request $request Incoming request. * @return string Rendered page content. * @throws NotFoundException If the thread with specified ID and token is * not found. */ public function submitFormAction(Request $request) { $errors = array(); $thread_id = $request->attributes->get('thread_id'); $token = $request->attributes->get('token'); // Try to load the thread $thread = Thread::load($thread_id, $token); if (!$thread) { throw new NotFoundException('The thread is not found.'); } $email = $request->request->get('email'); $group = $thread->groupId ? group_by_id($thread->groupId) : null; if (!$email) { $errors[] = no_field('Your email'); } elseif (!MailUtils::isValidAddress($email)) { $errors[] = wrong_field('Your email'); } if (count($errors) > 0) { $request->attributes->set('errors', $errors); // Render the mail form again return $this->showFormAction($request); } $history = ''; $last_id = -1; $messages = $thread->getMessages(true, $last_id); foreach ($messages as $msg) { $history .= message_to_text($msg); } // Load mail templates and substitute placeholders there. $mail_template = MailTemplate::loadByName('user_history', get_current_locale()); if ($mail_template) { $this->sendMail(MailUtils::buildMessage($email, MIBEW_MAILBOX, $mail_template->buildSubject(), $mail_template->buildBody(array($thread->userName, $history, Settings::get('title'), Settings::get('hosturl'))))); } else { trigger_error('Cannot send e-mail because "user_history" mail template cannot be loaded.', E_USER_WARNING); } $page = setup_logo($group); $page['email'] = $email; return $this->render('mailsent', $page); }
function get_messages($threadid, $meth, $isuser, &$lastid) { global $kind_for_agent, $kind_avatar, $webim_encoding, $mysqlprefix; $link = connect(); $query = sprintf("select messageid,ikind,unix_timestamp(dtmcreated) as created,tname,tmessage from {$mysqlprefix}chatmessage " . "where threadid = %s and messageid > %s %s order by messageid", $threadid, $lastid, $isuser ? "and ikind <> {$kind_for_agent}" : ""); $messages = array(); $msgs = select_multi_assoc($query, $link); foreach ($msgs as $msg) { $message = ""; if ($meth == 'xml') { switch ($msg['ikind']) { case $kind_avatar: $message = "<avatar>" . myiconv($webim_encoding, "utf-8", escape_with_cdata($msg['tmessage'])) . "</avatar>"; break; default: $message = "<message>" . myiconv($webim_encoding, "utf-8", escape_with_cdata(message_to_html($msg))) . "</message>\n"; } } else { if ($msg['ikind'] != $kind_avatar) { $message = $meth == 'text' ? message_to_text($msg) : topage(message_to_html($msg)); } } $messages[] = $message; if ($msg['messageid'] > $lastid) { $lastid = $msg['messageid']; } } mysql_close($link); return $messages; }