fast history search, fix redirection to groups, extract webim_mail function into notify.php

This commit is contained in:
Evgeny Gryaznov 2011-02-16 01:43:19 +01:00
parent 7ba431d0de
commit c5bc5ed2f5
8 changed files with 109 additions and 61 deletions

View File

@ -24,6 +24,7 @@ require_once('libs/chat.php');
require_once('libs/expand.php');
require_once('libs/groups.php');
require_once('libs/captcha.php');
require_once('libs/notify.php');
$errors = array();
$page = array();
@ -110,7 +111,9 @@ $body = getstring2_("leavemail.body", array($visitor_name,$email,$message,$info
$inbox_mail = $settings['email'];
if($inbox_mail) {
webim_mail($inbox_mail, $email, $subject, $body);
$link = connect();
webim_mail($inbox_mail, $email, $subject, $body, $link);
mysql_close($link);
}
setup_logo();

View File

@ -338,14 +338,6 @@ function perform_query($query,$link) {
or die(' Query failed: '.mysql_error()/*.": ".$query*/);
}
function rows_count($link,$table,$whereclause="") {
$result = mysql_query("SELECT count(*) FROM $table $whereclause",$link)
or die(' Count query failed: '.mysql_error());
$line = mysql_fetch_array($result, MYSQL_NUM);
mysql_free_result($result);
return $line[0];
}
function select_one_row($query,$link) {
$result = mysql_query($query,$link) or die(' Query failed: ' .
mysql_error().": ".$query);
@ -366,6 +358,20 @@ function select_multi_assoc($query, $link) {
return $result;
}
function db_build_select($fields, $table, $conditions, $orderandgroup) {
$condition = count($conditions) > 0 ? " where ".implode(" and ", $conditions) : "";
if($orderandgroup) $orderandgroup = " ".$orderandgroup;
return "select $fields from $table$condition$orderandgroup";
}
function db_rows_count($table,$conditions,$countfields, $link) {
$result = mysql_query(db_build_select("count(".($countfields ? $countfields : "*").")", $table, $conditions, ""),$link)
or die(' Count query failed: '.mysql_error());
$line = mysql_fetch_array($result, MYSQL_NUM);
mysql_free_result($result);
return $line[0];
}
function start_xml_output() {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
@ -543,21 +549,6 @@ function date_to_text($unixtime) {
return strftime($date_format." ".getlocal("time.timeformat"), $unixtime);
}
function webim_mail($toaddr, $reply_to, $subject, $body) {
global $webim_encoding, $webim_mailbox, $mail_encoding;
$headers = "From: $webim_mailbox\r\n"
."Reply-To: ".myiconv($webim_encoding, $mail_encoding, $reply_to)."\r\n"
."Content-Type: text/plain; charset=$mail_encoding\r\n"
.'X-Mailer: PHP/'.phpversion();
$real_subject = "=?".$mail_encoding."?B?".base64_encode(myiconv($webim_encoding,$mail_encoding,$subject))."?=";
$body = preg_replace("/\n/","\r\n", $body);
@mail($toaddr, $real_subject, wordwrap(myiconv($webim_encoding, $mail_encoding, $body),70), $headers);
}
$dbversion = '1.6.3';
$settings = array(

View File

@ -0,0 +1,37 @@
<?php
/*
* This file is part of Mibew Messenger project.
*
* Copyright (c) 2005-2010 Mibew Messenger Community
* All rights reserved. The contents of this file are subject to the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and
* is available at http://www.eclipse.org/legal/epl-v10.html
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (the "GPL"), in which case
* the provisions of the GPL are applicable instead of those above. If you wish
* to allow use of your version of this file only under the terms of the GPL, and
* not to allow others to use your version of this file under the terms of the
* EPL, indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by the GPL.
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
function webim_mail($toaddr, $reply_to, $subject, $body, $link) {
global $webim_encoding, $webim_mailbox, $mail_encoding, $current_locale;
$headers = "From: $webim_mailbox\r\n"
."Reply-To: ".myiconv($webim_encoding, $mail_encoding, $reply_to)."\r\n"
."Content-Type: text/plain; charset=$mail_encoding\r\n"
.'X-Mailer: PHP/'.phpversion();
$real_subject = "=?".$mail_encoding."?B?".base64_encode(myiconv($webim_encoding,$mail_encoding,$subject))."?=";
$body = preg_replace("/\n/","\r\n", $body);
@mail($toaddr, $real_subject, wordwrap(myiconv($webim_encoding, $mail_encoding, $body),70), $headers);
}
?>

View File

@ -220,20 +220,30 @@ function setup_redirect_links($threadid,$token) {
loadsettings();
$link = connect();
$operatorscount = rows_count($link, "chatoperator");
$groupscount = $settings['enablegroups'] == "1" ? rows_count($link, "chatgroup") : 0;
prepare_pagination(max($operatorscount,$groupscount),8);
$limit = $page['pagination']['limit'];
$query = "select operatorid, vclogin, vclocalename, vccommonname, istatus, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time ".
"from chatoperator order by vclogin $limit";
$operators = select_multi_assoc($query, $link);
$operatorscount = db_rows_count("chatoperator", array(), "", $link);
$groupscount = 0;
if($settings['enablegroups'] == "1") {
$groups = get_groups($link, true);
$groups = array();
foreach(get_groups($link, true) as $group) {
if($group['inumofagents'] == 0) {
continue;
}
$groups[] = $group;
}
$groupscount = count($groups);
}
prepare_pagination(max($operatorscount,$groupscount),8);
$p = $page['pagination'];
$limit = $p['limit'];
$operators = select_multi_assoc(db_build_select(
"operatorid, vclogin, vclocalename, vccommonname, istatus, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time",
"chatoperator", array(), "order by vclogin $limit"), $link);
$groups = array_slice($groups, $p['start'], $p['end']-$p['start']);
mysql_close($link);
$agent_list = "";
@ -257,9 +267,6 @@ function setup_redirect_links($threadid,$token) {
if($settings['enablegroups'] == "1") {
$params = array('thread' => $threadid, 'token' => $token);
foreach($groups as $group) {
if($group['inumofagents'] == 0) {
continue;
}
$params['nextGroup'] = $group['groupid'];
$status = $group['ilastseen'] !== NULL && $group['ilastseen'] < $settings['online_timeout']
? getlocal("char.redirect.operator.online_suff")

View File

@ -72,6 +72,19 @@ function setup_pagination($items,$default_items_per_page=15) {
}
}
function select_with_pagintation($fields, $table, $conditions, $order, $countfields, $link) {
global $page;
$count = db_rows_count($table, $conditions, $countfields, $link);
prepare_pagination($count);
if($count) {
$p = $page['pagination'];
$limit = $p['limit'];
$page['pagination.items'] = select_multi_assoc(db_build_select($fields, $table, $conditions, $order)." ".$limit, $link);
} else {
$page['pagination.items'] = false;
}
}
function setup_empty_pagination() {
global $page;
$page['pagination.items'] = false;

View File

@ -22,6 +22,7 @@
require_once('libs/common.php');
require_once('libs/chat.php');
require_once('libs/expand.php');
require_once('libs/notify.php');
$errors = array();
$page = array();
@ -63,7 +64,9 @@ foreach( $output as $msg ) {
$subject = getstring("mail.user.history.subject");
$body = getstring2("mail.user.history.body", array($thread['userName'],$history) );
webim_mail($email, $webim_mailbox, $subject, $body);
$link = connect();
webim_mail($email, $webim_mailbox, $subject, $body, $link);
mysql_close($link);
setup_logo();
expand("styles", getchatstyle(), "mailsent.tpl");

View File

@ -42,31 +42,25 @@ if($query !== false) {
while ($group = mysql_fetch_array($result, MYSQL_ASSOC)) {
$groupName[$group['groupid']] = $group['vclocalname'];
}
$page['groupName'] = $groupName;
mysql_free_result($result);
$result = mysql_query(
"select DISTINCT unix_timestamp(chatthread.dtmcreated) as created, ".
$page['groupName'] = $groupName;
$escapedQuery = mysql_real_escape_string($query,$link);
select_with_pagintation("DISTINCT unix_timestamp(chatthread.dtmcreated) as created, ".
"unix_timestamp(chatthread.dtmmodified) as modified, chatthread.threadid, ".
"chatthread.remote, chatthread.agentName, chatthread.userName, groupid, ".
"messageCount as size ".
"from chatthread, chatmessage ".
"where chatmessage.threadid = chatthread.threadid and ".
"((chatthread.userName LIKE '%%$query%%') or ".
" (chatmessage.tmessage LIKE '%%$query%%'))".
"order by created DESC", $link)
or die(' Query failed: ' .mysql_error().": ".$query);
$foundThreads = array();
while ($thread = mysql_fetch_array($result, MYSQL_ASSOC)) {
$foundThreads[] = $thread;
}
mysql_free_result($result);
"messageCount as size",
"chatthread, chatmessage",
array(
"chatmessage.threadid = chatthread.threadid",
"((chatthread.userName LIKE '%%$escapedQuery%%') or (chatmessage.tmessage LIKE '%%$escapedQuery%%'))"
),
"order by created DESC",
"DISTINCT chatthread.dtmcreated", $link);
mysql_close($link);
$page['formq'] = topage($query);
setup_pagination($foundThreads);
} else {
setup_empty_pagination();
}

View File

@ -22,6 +22,7 @@
require_once('../libs/common.php');
require_once('../libs/operator.php');
require_once('../libs/settings.php');
require_once('../libs/notify.php');
$errors = array();
$page = array('version' => $version);
@ -46,11 +47,10 @@ if (isset($_POST['loginoremail'])) {
$link = connect();
$query = "update chatoperator set dtmrestore = CURRENT_TIMESTAMP, vcrestoretoken = '$token' where operatorid = ".$torestore['operatorid'];
perform_query($query, $link);
$href = get_app_location(true,false)."/operator/resetpwd.php?id=".$torestore['operatorid']."&token=$token";
webim_mail($email, $email, getstring("restore.mailsubj"), getstring2("restore.mailtext",array(get_operator_name($torestore), $href)), $link);
mysql_close($link);
$link = get_app_location(true,false)."/operator/resetpwd.php?id=".$torestore['operatorid']."&token=$token";
webim_mail($email, $email, getstring("restore.mailsubj"), getstring2("restore.mailtext",array(get_operator_name($torestore), $link)));
$page['isdone'] = true;
require('../view/restore.php');