canned responses editor, Updates at the top level

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@463 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2009-04-08 22:40:26 +00:00
parent 5c7b5b0aea
commit 334248c474
9 changed files with 426 additions and 13 deletions

View File

@ -90,6 +90,13 @@ $dbtables = array(
"id" => "INT NOT NULL auto_increment PRIMARY KEY",
"vckey" => "varchar(255)",
"vcvalue" => "varchar(255)",
),
"chatresponses" => array(
"id" => "INT NOT NULL auto_increment PRIMARY KEY",
"locale" => "varchar(8)",
"groupid" => "int references chatgroup(groupid)",
"vcvalue" => "varchar(1024) NOT NULL",
)
);
@ -102,6 +109,7 @@ $dbtables_can_update = array(
"chatban" => array(),
"chatgroup" => array(),
"chatgroupoperator" => array(),
"chatresponses" => array(),
);
function show_install_err($text) {

View File

@ -31,8 +31,7 @@ function setup_settings_tabs($active) {
$page['tabs'] = array(
getlocal("page_settings.tab.main") => $active != 0 ? "$webimroot/operator/settings.php" : "",
getlocal("page_settings.tab.features") => $active != 1 ? "$webimroot/operator/features.php" : "",
getlocal("page_settings.tab.themes") => $active != 2 ? "$webimroot/operator/preview.php" : "",
getlocal("page_settings.tab.updates") => $active != 3 ? "$webimroot/operator/updates.php" : "",
getlocal("page_settings.tab.themes") => $active != 2 ? "$webimroot/operator/themes.php" : "",
);
}

View File

@ -13,6 +13,17 @@ button.delete=Delete
button.enter=Enter
button.save=Save
button.search=Search
canned.add=Add message
canned.title=Canned Messages
canned.descr=Edit messages that you frequently type into the chat.
canned.locale=Choose locale
canned.group=Choose group
cannednew.title=New Message
cannednew.descr=Add new message
cannededit.title=Edit Message
cannededit.descr=Adjust existing message
cannededit.done=Saved
cannededit.no_such=No such message
chat.came.from=Vistor came from page {0}
chat.client.changename=Change name
chat.client.name=You are
@ -183,6 +194,7 @@ mailthread.perform=Send
mailthread.title=Send chat history<br>by mail
menu.agents=Agents list
menu.blocked=Blocked visitors
menu.canned=Canned Messages
menu.groups=Groups
menu.groups.content=Department or skill based operator groups.
menu.locale=Language
@ -190,6 +202,7 @@ menu.locale.content=Change locale.
menu.main=Main
menu.operator=You are {0}
menu.translate=Localize
menu.updates=Updates
my_settings.error.password_match=Entered passwords do not match
no_such_operator=No such operator
operator.groups.title=Operator groups
@ -296,7 +309,6 @@ page_settings.intro=Specify options affecting chat window and common system beha
page_settings.tab.features=Optional Services
page_settings.tab.main=General
page_settings.tab.themes=Themes preview
page_settings.tab.updates=Updates
pending.menu.hide=Hide menu >>
pending.menu.show=Show menu >>
pending.table.ban=Ban the visitor

View File

@ -0,0 +1,123 @@
<?php
/*
* This file is part of Web Instant Messenger project.
*
* Copyright (c) 2005-2009 Web Messenger Community
* All rights reserved. This program and the accompanying materials
* are made available under 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
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
require_once('../libs/common.php');
require_once('../libs/operator.php');
require_once('../libs/settings.php');
require_once('../libs/groups.php');
require_once('../libs/pagination.php');
$operator = check_login();
loadsettings();
$errors = array();
$page = array();
function load_canned_messages($locale, $groupid) {
$link = connect();
$query = "select id, vcvalue from chatresponses ".
"where locale = '".$locale."' AND (".
($groupid
? "groupid = $groupid"
: "groupid is NULL OR groupid = 0").
") order by vcvalue";
$result = select_multi_assoc($query, $link);
if(!$groupid && count($result) == 0) {
foreach(explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) {
$result[] = array('id' => '', 'vcvalue' => $answer);
}
if(count($result) > 0) {
$updatequery = "insert into chatresponses (vcvalue,locale,groupid) values ";
for($i=0;$i<count($result);$i++) {
if($i > 0) {
$updatequery .= ", ";
}
$updatequery .= "('".mysql_real_escape_string($result[$i]['vcvalue'], $link)."','$locale', NULL)";
}
perform_query($updatequery, $link);
$result = select_multi_assoc($query, $link);
}
}
mysql_close($link);
return $result;
}
# locales
$all_locales = get_available_locales();
$locales_with_label = array();
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 = in_array($current_locale,$all_locales) ? $current_locale : $all_locales[0];
}
# groups
$groupid = "";
if($settings['enablegroups'] == '1') {
$groupid = verifyparam( "group", "/^\d{0,8}$/", "");
if($groupid) {
$group = group_by_id($groupid);
if(!$group) {
$errors[] = getlocal("page.group.no_such");
$groupid = "";
}
}
$allgroups = get_groups(false);
$page['groups'] = array();
$page['groups'][] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
foreach($allgroups as $g) {
$page['groups'][] = $g;
}
}
# delete
if(isset($_GET['act']) && $_GET['act'] == 'delete') {
$key = isset($_GET['key']) ? $_GET['key'] : "";
if( !preg_match( "/^\d+$/", $key )) {
$errors[] = "Wrong key";
}
if( count($errors) == 0 ) {
$link = connect();
perform_query("delete from chatresponses where id = $key",$link);
mysql_close($link);
header("Location: $webimroot/operator/canned.php?lang=$lang&group=$groupid");
exit;
}
}
# get messages
$messages = load_canned_messages($lang, $groupid);
setup_pagination($messages);
# form values
$page['formlang'] = $lang;
$page['formgroup'] = $groupid;
prepare_menu($operator);
start_html_output();
require('../view/canned.php');
?>

View File

@ -0,0 +1,91 @@
<?php
/*
* This file is part of Web Instant Messenger project.
*
* Copyright (c) 2005-2009 Web Messenger Community
* All rights reserved. This program and the accompanying materials
* are made available under 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
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
require_once('../libs/common.php');
require_once('../libs/operator.php');
require_once('../libs/pagination.php');
function load_message($key) {
$link = connect();
$result = select_one_row("select vcvalue from chatresponses where id = $key", $link);
mysql_close($link);
return $result ? $result['vcvalue'] : null;
}
function save_message($key,$message) {
$link = connect();
perform_query("update chatresponses set vcvalue = '".mysql_real_escape_string($message,$link)."' ".
"where id = $key", $link);
mysql_close($link);
}
function add_message($locale,$groupid,$message) {
$link = connect();
perform_query("insert into chatresponses (locale,groupid,vcvalue) values ('$locale',".
($groupid ? "$groupid, " : "null, ").
"'".mysql_real_escape_string($message,$link)."')", $link);
mysql_close($link);
}
$operator = check_login();
loadsettings();
$stringid = verifyparam("key", "/^\d{0,9}$/", "");
$errors = array();
$page = array();
if($stringid) {
$message = load_message($stringid);
if(!$message) {
$errors[] = getlocal("cannededit.no_such");
$stringid = "";
}
} else {
$message = "";
$page['locale'] = verifyparam("lang", "/^[\w-]{2,5}$/", "");
$page['groupid'] = "";
if($settings['enablegroups'] == '1') {
$page['groupid'] = verifyparam( "group", "/^\d{0,8}$/");
}
}
if(isset($_POST['message'])) {
$message = getparam('message');
if(!$message) {
$errors[] = no_field("form.field.message");
}
if(count($errors) == 0) {
if($stringid) {
save_message($stringid, $message);
} else {
add_message($page['locale'], $page['groupid'], $message);
}
$page['saved'] = true;
prepare_menu($operator, false);
start_html_output();
require('../view/cannededit.php');
exit;
}
}
$page['saved'] = false;
$page['key'] = $stringid;
$page['formmessage'] = topage($message);
prepare_menu($operator, false);
start_html_output();
require('../view/cannededit.php');
exit;
?>

View File

@ -0,0 +1,116 @@
<?php
/*
* This file is part of Web Instant Messenger project.
*
* Copyright (c) 2005-2009 Web Messenger Community
* All rights reserved. This program and the accompanying materials
* are made available under 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
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
require_once("inc_menu.php");
$page['title'] = getlocal("canned.title");
$page['menuid'] = "canned";
function tpl_content() { global $page, $webimroot, $errors;
?>
<?php echo getlocal("canned.descr") ?>
<br />
<br />
<?php
require_once('inc_errors.php');
?>
<form name="cannedForm" method="get" action="<?php echo $webimroot ?>/operator/canned.php">
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">
<div class="packedFormField">
<?php echo getlocal("canned.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>
<?php if($page['showgroups']) { ?>
<div class="packedFormField">
<?php echo getlocal("canned.group") ?><br/>
<select name="group" onchange="this.form.submit();"><?php
foreach($page['groups'] as $k) {
echo "<option value=\"".$k["groupid"]."\"".($k["groupid"] == form_value("group") ? " selected=\"selected\"" : "").">".$k["vclocalname"]."</option>";
} ?></select>
</div>
<?php } ?>
<br clear="all"/>
</div><div class="formbottom"><div class="formbottomi"></div></div></div>
</form>
<br/>
<div class="tabletool">
<img src="<?php echo $webimroot ?>/images/buttons/createban.gif" border="0" alt=""/>
<a href="<?php echo $webimroot ?>/operator/cannededit.php?lang=<?php echo form_value("lang") ?>&amp;group=<?php echo form_value("group")?>" target="_blank"
onclick="this.newWindow = window.open('<?php echo $webimroot ?>/operator/cannededit.php?lang=<?php echo form_value("lang") ?>&amp;group=<?php echo form_value("group")?>', '', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;">
<?php echo getlocal("canned.add") ?>
</a>
</div>
<br clear="all"/>
<?php if( $page['pagination'] ) { ?>
<table class="translate">
<thead>
<tr class="header"><th>
Message
</th><th>
Modify
</th></tr>
</thead>
<tbody>
<?php
if( $page['pagination.items'] ) {
foreach( $page['pagination.items'] as $localstr ) { ?>
<tr>
<td>
<?php echo str_replace("\n", "<br/>",htmlspecialchars(topage($localstr['vcvalue']))) ?>
</td>
<td>
<a href="<?php echo $webimroot ?>/operator/cannededit.php?key=<?php echo $localstr['id'] ?>" target="_blank"
onclick="this.newWindow = window.open('<?php echo $webimroot ?>/operator/cannededit.php?key=<?php echo $localstr['id'] ?>', '', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;">edit</a>,
<a href="<?php echo $webimroot ?>/operator/canned.php?act=delete&amp;key=<?php echo $localstr['id'] ?>&amp;lang=<?php echo form_value("lang") ?>&amp;group=<?php echo form_value("group")?>">delete</a>
</td>
</tr>
<?php
}
} else {
?>
<tr>
<td colspan="3">
<?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');
?>

View File

@ -0,0 +1,71 @@
<?php
/*
* This file is part of Web Instant Messenger project.
*
* Copyright (c) 2005-2009 Web Messenger Community
* All rights reserved. This program and the accompanying materials
* are made available under 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
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
$page['title'] = getlocal($page['key'] ? "cannededit.title" : "cannednew.title");
function tpl_content() { global $page, $webimroot, $errors;
?>
<?php if( $page['saved'] ) { ?>
<?php echo getlocal("cannededit.done") ?>
<script><!--
if(window.opener && window.opener.location) {
window.opener.location.reload();
}
setTimeout( (function() {
window.close();
}), 500 );
//--></script>
<?php } ?>
<?php if( !$page['saved'] ) { ?>
<?php echo getlocal($page['key'] ? "cannededit.descr" : "cannednew.descr") ?>
<br/>
<br/>
<?php
require_once('inc_errors.php');
?>
<form name="cannedForm" method="post" action="<?php echo $webimroot ?>/operator/cannededit.php">
<input type="hidden" name="key" value="<?php echo $page['key'] ?>"/>
<?php if(!$page['key']) { ?>
<input type="hidden" name="lang" value="<?php echo $page['locale'] ?>"/>
<input type="hidden" name="group" value="<?php echo $page['groupid'] ?>"/>
<?php } ?>
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">
<div class="fieldForm">
<div class="field">
<div class="flabel">Message</div>
<div class="fvaluenodesc">
<textarea name="message" cols="20" rows="5" class="wide"><?php echo form_value('message') ?></textarea>
</div>
</div>
<div class="fbutton">
<input type="image" name="save" value="" src='<?php echo $webimroot.getlocal("image.button.save") ?>' alt='<?php echo getlocal("button.save") ?>'/>
</div>
</div>
</div><div class="formbottom"><div class="formbottomi"></div></div></div>
</form>
<?php } ?>
<?php
} /* content */
require_once('inc_main.php');
?>

View File

@ -31,9 +31,11 @@ function tpl_menu() { global $page, $webimroot, $errors;
<?php if(isset($page['showgroups']) && $page['showgroups']) { ?>
<li<?php menuli("groups")?>><a href='<?php echo $webimroot ?>/operator/groups.php'><?php echo getlocal('menu.groups') ?></a></li>
<?php } ?>
<li<?php menuli("canned")?>><a href='<?php echo $webimroot ?>/operator/canned.php'><?php echo getlocal('menu.canned') ?></a></li>
<li<?php menuli("getcode")?>><a href='<?php echo $webimroot ?>/operator/getcode.php'><?php echo getlocal('leftMenu.client_gen_button') ?></a></li>
<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>
</ul>
</li>
<?php } ?>

View File

@ -14,7 +14,7 @@
require_once("inc_menu.php");
$page['title'] = getlocal("updates.title");
$page['menuid'] = "settings";
$page['menuid'] = "updates";
function tpl_header() { global $page, $webimroot;
?>
@ -31,15 +31,6 @@ function tpl_content() { global $page, $webimroot;
<br />
<br />
<div>
<?php if($page['tabs']) { ?>
<ul class="tabs">
<?php foreach($page['tabs'] as $k => $v) { if($v) { ?>
<li><a href="<?php echo $v ?>"><?php echo $k ?></a></li>
<?php } else { ?>
<li class="active"><a href="#"><?php echo $k ?></a></li><?php }} ?>
</ul>
<?php } ?>
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">
News:<br/>