add "Notifications Log" page, record sent mails, fast history search, fix redirection to groups

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@720 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2010-01-10 13:39:49 +00:00
parent ecfe7ebfc4
commit f9965f4d10
18 changed files with 385 additions and 63 deletions

View File

@ -299,6 +299,10 @@ img.left {
margin-bottom:8px;
}
.packedFormField select {
min-width: 130px;
}
div.errinfo {
color: #c13030;
}
@ -475,6 +479,16 @@ table.list td a.man {
padding-left: 15px;
}
table.list td a.mail {
background: url(images/mail.png) no-repeat left center;
padding-left: 24px;
}
table.list td a.xmpp {
background: url(images/xmpp.png) no-repeat left center;
padding-left: 24px;
}
table.list tbody tr:hover td, table.list tbody tr:hover td a, table.statistics tbody tr:hover td {
color: #1D485E;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -110,7 +110,18 @@ $dbtables = array(
"locale" => "varchar(8)",
"groupid" => "int references chatgroup(groupid)",
"vcvalue" => "varchar(1024) NOT NULL",
)
),
"chatnotification" => array(
"id" => "INT NOT NULL auto_increment PRIMARY KEY",
"locale" => "varchar(8)",
"vckind" => "varchar(16)",
"vcto" => "varchar(256)",
"dtmcreated" => "datetime DEFAULT 0",
"vcsubject" => "varchar(256)",
"tmessage" => "text NOT NULL",
"refoperator" => "int NOT NULL references chatoperator(operatorid)",
),
);
$memtables = array();
@ -123,6 +134,7 @@ $dbtables_can_update = array(
"chatgroup" => array("vcemail"),
"chatgroupoperator" => array(),
"chatresponses" => array(),
"chatnotification" => array(),
);
function show_install_err($text) {

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';
$featuresversion = '1.6.4';

View File

@ -0,0 +1,52 @@
<?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 log_notification($locale,$kind,$to,$subj,$text,$refop,$link) {
$query = sprintf(
"insert into chatnotification (locale,vckind,vcto,vcsubject,tmessage,refoperator,dtmcreated) values ('%s','%s','%s','%s','%s',%s,%s)",
$locale,
$kind,
mysql_real_escape_string($to,$link),
mysql_real_escape_string($subj,$link),
mysql_real_escape_string($text,$link),
$refop ? $refop : "0",
"CURRENT_TIMESTAMP" );
perform_query($query,$link);
}
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);
log_notification($current_locale, "mail", $toaddr, $subject, $body, null, $link);
@mail($toaddr, $real_subject, wordwrap(myiconv($webim_encoding, $mail_encoding, $body),70), $headers);
}
?>

View File

@ -223,20 +223,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 = "";
@ -260,9 +270,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

@ -221,6 +221,7 @@ menu.groups=Groups
menu.locale.content=Change locale.
menu.locale=Language
menu.main=Main
menu.notifications=Notifications
menu.operator=You are {0}
menu.profile.content=You can change your personal information on this page.
menu.profile=Profile
@ -229,6 +230,16 @@ menu.updates.content=Check for news and updates.
menu.updates=Updates
my_settings.error.password_match=Entered passwords do not match
no_such_operator=No such operator
notifications.locale=Language
notifications.locale.all=-all-
notifications.kind=Kind of notification
notifications.kind.all=-all-
notifications.kind.mail=E-Mail
notifications.kind.xmpp=XMPP/Jabber
notifications.head.to=To
notifications.head.subj=Subject
notifications.head.msg=Text
notifications.head.time=Time
operator.group.no_description=&lt;no description&gt;
operator.groups.intro=Choose groups according to operator skills.
operator.groups.title=Operator groups
@ -272,6 +283,8 @@ page.groups.isaway=Away
page.groups.isonline=Online
page.groups.new=Create new group...
page.groups.title=Groups
page.notifications.title=Notifications Log
page.notifications.intro=The list displays all notifications sent by messenger, including instant text messages and E-Mails.
page.preview.agentchat=Chat window (operator-mode)
page.preview.agentrochat=View Chat window (operator in readonly mode)
page.preview.chatsimple=Simple chat window, refresh to post messages (IE 5, Opera 7)

View File

@ -482,3 +482,4 @@ updates.intro=
updates.latest=Последняя версия:
updates.news=Новости:
updates.title=Обновления
menu.notifications=Óâåäîìëåíèÿ

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

@ -0,0 +1,82 @@
<?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
*/
require_once('../libs/common.php');
require_once('../libs/chat.php');
require_once('../libs/operator.php');
require_once('../libs/pagination.php');
$operator = check_login();
$page = array();
$errors = array();
if( !is_capable($can_administrate, $operator)) {
die("Permission denied.");
}
setlocale(LC_TIME, getstring("time.locale"));
# locales
$all_locales = get_available_locales();
$locales_with_label = array(array('id' => '', 'name' => getlocal("notifications.locale.all")));
foreach($all_locales as $id) {
$locales_with_label[] = array('id' => $id, 'name' => getlocal_($id,"names"));
}
$page['locales'] = $locales_with_label;
$lang = verifyparam("lang", "/^([\w-]{2,5})?$/", "");
if( $lang && !in_array($lang,$all_locales) ) {
$lang = "";
}
# kind
$kind = verifyparam("kind", "/^(mail|xmpp)?$/", "");
$page['allkinds'] = array('', 'mail', 'xmpp');
# fetch
$conditions = array();
if($kind) {
$conditions[] = "vckind = '$kind'";
}
if($lang) {
$conditions[] = "locale = '$lang'";
}
$link = connect();
select_with_pagintation(
"id, locale, vckind, vcto, unix_timestamp(dtmcreated) as created, vcsubject, tmessage, refoperator", "chatnotification",
$conditions,
"order by created desc", "", $link);
mysql_close($link);
$page['formlang'] = $lang;
$page['formkind'] = $kind;
prepare_menu($operator);
start_html_output();
require('../view/notifications.php');
exit;
?>

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');

View File

@ -75,7 +75,7 @@ require_once('inc_errors.php');
<td class="notlast">
<?php echo htmlspecialchars(topage($a['vclocalename'])) ?> / <?php echo htmlspecialchars(topage($a['vccommonname'])) ?>
</td>
<td>
<td class="notlast">
<?php if(is_online($a)) { ?>
<?php echo getlocal("page_agents.isonline") ?>
<?php } else if(is_away($a)) { ?>

View File

@ -56,6 +56,7 @@ function tpl_menu() { global $page, $webimroot, $errors;
<li<?php menuli("settings")?>><a href='<?php echo $webimroot ?>/operator/settings.php'><?php echo getlocal('leftMenu.client_settings') ?></a></li>
<li<?php menuli("translate")?>><a href='<?php echo $webimroot ?>/operator/translate.php'><?php echo getlocal('menu.translate') ?></a></li>
<li<?php menuli("updates")?>><a href='<?php echo $webimroot ?>/operator/updates.php'><?php echo getlocal('menu.updates') ?></a></li>
<li<?php menuli("notifications")?>><a href='<?php echo $webimroot ?>/operator/notifications.php'><?php echo getlocal('menu.notifications') ?></a></li>
<?php } ?>
<?php if(isset($page['currentopid']) && $page['currentopid']) {?>
<li<?php menuli("profile")?>><a href='<?php echo $webimroot ?>/operator/operator.php?op=<?php echo $page['currentopid'] ?>'><?php echo getlocal('menu.profile') ?></a></li>

View File

@ -0,0 +1,136 @@
<?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
*/
require_once("inc_menu.php");
$page['title'] = getlocal("page.notifications.title");
$page['menuid'] = "notifications";
function shorten($text,$len) {
if(strlen($text) > $len)
return substr($text,0,$len)."..";
return $text;
}
function tpl_header() { global $page, $webimroot;
?>
<script type="text/javascript" language="javascript" src="<?php echo $webimroot ?>/js/jquery-1.3.2.min.js"></script>
<?php
}
function tpl_content() { global $page, $webimroot, $errors;
?>
<?php echo getlocal("page.notifications.intro") ?>
<br />
<br />
<?php
require_once('inc_errors.php');
?>
<form name="notifyFilterForm" method="get" action="<?php echo $webimroot ?>/operator/notifications.php">
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">
<div class="packedFormField">
<?php echo getlocal("notifications.kind") ?><br/>
<select name="kind" onchange="this.form.submit();"><?php
foreach($page['allkinds'] as $k) {
echo "<option value=\"".$k."\"".($k == form_value("kind") ? " selected=\"selected\"" : "").">".getlocal("notifications.kind.".($k ? $k : "all"))."</option>";
} ?></select>
</div>
<div class="packedFormField">
<?php echo getlocal("notifications.locale") ?><br/>
<select name="lang" onchange="this.form.submit();"><?php
foreach($page['locales'] as $k) {
echo "<option value=\"".$k["id"]."\"".($k["id"] == form_value("lang") ? " selected=\"selected\"" : "").">".$k["name"]."</option>";
} ?></select>
</div>
<br clear="all"/>
</div><div class="formbottom"><div class="formbottomi"></div></div></div>
</form>
<br/>
<?php if( $page['pagination'] ) { ?>
<table class="list">
<thead>
<tr class="header">
<th>
<?php echo getlocal("notifications.head.to") ?>
</th><th>
<?php echo getlocal("notifications.head.subj") ?>
</th><th>
<?php echo getlocal("notifications.head.msg") ?>
</th><th>
<?php echo getlocal("notifications.head.time") ?>
</th>
</tr>
</thead>
<tbody>
<?php
if( $page['pagination.items'] ) {
foreach( $page['pagination.items'] as $b ) { ?>
<tr>
<td class="notlast">
<a href="#" class="<?php echo $b['vckind'] == 'xmpp' ? 'xmpp' : 'mail' ?>">
<?php echo htmlspecialchars(shorten(topage($b['vcto']),30)) ?>
</a>
</td>
<td class="notlast">
<?php echo htmlspecialchars(shorten(topage($b['vcsubject']),30)) ?>
</td>
<td class="notlast">
<?php echo htmlspecialchars(shorten(topage($b['tmessage']),30)) ?>
</td>
<td>
<?php echo date_to_text($b['created']) ?>
</td>
</tr>
<?php
}
} else {
?>
<tr>
<td colspan="4">
<?php echo getlocal("tag.pagination.no_items.elements") ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
if( $page['pagination.items'] ) {
echo "<br/>";
echo generate_pagination($page['pagination']);
}
}
?>
<?php
} /* content */
require_once('inc_main.php');
?>