Use convenient names for database tables

This commit is contained in:
Dmitriy Simushev 2014-07-14 08:36:29 +00:00
parent 2af3df4bc6
commit 2ba5c0e9b3
19 changed files with 204 additions and 203 deletions

View File

@ -1,8 +1,9 @@
# This file contains current database schema that is used for installation. # This file contains current database schema that is used for installation.
# Do not change anything in this file unless you know what you are doing! # Do not change anything in this file unless you know what you are doing!
# Contains information about chat groups # Contains information about chat groups. This table cannot be named just
chatgroup: # "group" because it is reserved SQL word.
opgroup:
fields: fields:
groupid: "int NOT NULL auto_increment PRIMARY KEY" groupid: "int NOT NULL auto_increment PRIMARY KEY"
parent: "int DEFAULT NULL" parent: "int DEFAULT NULL"
@ -20,13 +21,13 @@ chatgroup:
parent: [parent] parent: [parent]
# Contains info about chat threads # Contains info about chat threads
chatthread: thread:
fields: fields:
# ID of the thread. # ID of the thread.
threadid: "int NOT NULL auto_increment PRIMARY KEY" threadid: "int NOT NULL auto_increment PRIMARY KEY"
# Name of the user in chat. # Name of the user in chat.
username: "varchar(64) NOT NULL" username: "varchar(64) NOT NULL"
# ID of the user. This field is foreign key for {chatsitevisitor}.userid # ID of the user. This field is foreign key for {sitevisitor}.userid
userid: "varchar(255)" userid: "varchar(255)"
# Name of the operator who took place in the chat. # Name of the operator who took place in the chat.
agentname: "varchar(64)" agentname: "varchar(64)"
@ -72,10 +73,10 @@ chatthread:
# Total count of user's messages related with the thread. # Total count of user's messages related with the thread.
messagecount: "varchar(16)" messagecount: "varchar(16)"
# ID of the group at Mibew side related with the thread. # ID of the group at Mibew side related with the thread.
groupid: "int references {chatgroup}(groupid)" groupid: "int references {opgroup}(groupid)"
# Contains "by thread" statistics # Contains "by thread" statistics
chatthreadstatistics: threadstatistics:
fields: fields:
statid: "int NOT NULL auto_increment PRIMARY KEY" statid: "int NOT NULL auto_increment PRIMARY KEY"
date: "int NOT NULL DEFAULT 0" date: "int NOT NULL DEFAULT 0"
@ -142,12 +143,12 @@ mailtemplate:
body: "text" body: "text"
# Store chat thread messages # Store chat thread messages
chatmessage: message:
fields: fields:
# Message ID. # Message ID.
messageid: "int NOT NULL auto_increment PRIMARY KEY" messageid: "int NOT NULL auto_increment PRIMARY KEY"
# ID of the thread related with the message. # ID of the thread related with the message.
threadid: "int NOT NULL references {chatthread}(threadid)" threadid: "int NOT NULL references {thread}(threadid)"
# Message kind. It is one of Thread::KIND_* constants. # Message kind. It is one of Thread::KIND_* constants.
ikind: "int NOT NULL" ikind: "int NOT NULL"
# ID of operator who sent the message. This value will be ignored for # ID of operator who sent the message. This value will be ignored for
@ -168,7 +169,7 @@ chatmessage:
idx_agentid: [agentid] idx_agentid: [agentid]
# Contains info about operators # Contains info about operators
chatoperator: operator:
fields: fields:
operatorid: "int NOT NULL auto_increment PRIMARY KEY" operatorid: "int NOT NULL auto_increment PRIMARY KEY"
vclogin: "varchar(64) NOT NULL" vclogin: "varchar(64) NOT NULL"
@ -190,7 +191,7 @@ chatoperator:
code: "varchar(64) DEFAULT ''" code: "varchar(64) DEFAULT ''"
# Contains "by operator" statistics # Contains "by operator" statistics
chatoperatorstatistics: operatorstatistics:
fields: fields:
statid: "int NOT NULL auto_increment PRIMARY KEY" statid: "int NOT NULL auto_increment PRIMARY KEY"
date: "int NOT NULL DEFAULT 0" date: "int NOT NULL DEFAULT 0"
@ -205,21 +206,21 @@ chatoperatorstatistics:
indexes: indexes:
operatorid: [operatorid] operatorid: [operatorid]
chatrevision: revision:
fields: fields:
id: "INT NOT NULL" id: "INT NOT NULL"
# Contains relations between operators and groups # Contains relations between operators and groups
chatgroupoperator: operatortoopgroup:
fields: fields:
groupid: "int NOT NULL references {chatgroup}(groupid)" groupid: "int NOT NULL references {opgroup}(groupid)"
operatorid: "int NOT NULL references {chatoperator}(operatorid)" operatorid: "int NOT NULL references {operator}(operatorid)"
indexes: indexes:
groupid: [groupid] groupid: [groupid]
operatorid: [operatorid] operatorid: [operatorid]
# Contains banned visitors # Contains banned visitors
chatban: ban:
fields: fields:
banid: "INT NOT NULL auto_increment PRIMARY KEY" banid: "INT NOT NULL auto_increment PRIMARY KEY"
dtmcreated: "int NOT NULL DEFAULT 0" dtmcreated: "int NOT NULL DEFAULT 0"
@ -229,22 +230,22 @@ chatban:
blockedcount: "int DEFAULT 0" blockedcount: "int DEFAULT 0"
# Contains dynamic configs # Contains dynamic configs
chatconfig: config:
fields: fields:
id: "INT NOT NULL auto_increment PRIMARY KEY" id: "INT NOT NULL auto_increment PRIMARY KEY"
vckey: "varchar(255)" vckey: "varchar(255)"
vcvalue: "varchar(255)" vcvalue: "varchar(255)"
# Contains canned messages # Contains canned messages
chatresponses: cannedmessage:
fields: fields:
id: "INT NOT NULL auto_increment PRIMARY KEY" id: "INT NOT NULL auto_increment PRIMARY KEY"
locale: "varchar(8)" locale: "varchar(8)"
groupid: "int references {chatgroup}(groupid)" groupid: "int references {opgroup}(groupid)"
vctitle: "varchar(100) NOT NULL DEFAULT ''" vctitle: "varchar(100) NOT NULL DEFAULT ''"
vcvalue: "varchar(1024) NOT NULL" vcvalue: "varchar(1024) NOT NULL"
chatsitevisitor: sitevisitor:
fields: fields:
visitorid: "INT NOT NULL auto_increment PRIMARY KEY" visitorid: "INT NOT NULL auto_increment PRIMARY KEY"
userid: "varchar(255) NOT NULL" userid: "varchar(255) NOT NULL"
@ -255,7 +256,7 @@ chatsitevisitor:
details: "text NOT NULL" details: "text NOT NULL"
invitations: "INT NOT NULL DEFAULT 0" invitations: "INT NOT NULL DEFAULT 0"
chats: "INT NOT NULL DEFAULT 0" chats: "INT NOT NULL DEFAULT 0"
threadid: "INT references {chatthread}(threadid) on delete set null" threadid: "INT references {thread}(threadid) on delete set null"
indexes: indexes:
threadid: [threadid] threadid: [threadid]

View File

@ -36,7 +36,7 @@ function load_canned_messages($locale, $group_id)
} }
return $db->query( return $db->query(
("SELECT id, vctitle, vcvalue FROM {chatresponses} " ("SELECT id, vctitle, vcvalue FROM {cannedmessage} "
. "WHERE locale = :locale AND (" . "WHERE locale = :locale AND ("
. ($group_id ? "groupid = :groupid" : "groupid is NULL OR groupid = 0") . ($group_id ? "groupid = :groupid" : "groupid is NULL OR groupid = 0")
. ") ORDER BY vcvalue"), . ") ORDER BY vcvalue"),
@ -57,7 +57,7 @@ function load_canned_message($key)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$result = $db->query( $result = $db->query(
"SELECT vctitle, vcvalue FROM {chatresponses} WHERE id = ?", "SELECT vctitle, vcvalue FROM {cannedmessage} WHERE id = ?",
array($key), array($key),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -76,7 +76,7 @@ function save_canned_message($key, $title, $message)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"UPDATE {chatresponses} SET vcvalue = ?, vctitle = ? WHERE id = ?", "UPDATE {cannedmessage} SET vcvalue = ?, vctitle = ? WHERE id = ?",
array($message, $title, $key) array($message, $title, $key)
); );
} }
@ -93,7 +93,7 @@ function add_canned_message($locale, $group_id, $title, $message)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("INSERT INTO {chatresponses} (locale,groupid,vctitle,vcvalue) " ("INSERT INTO {cannedmessage} (locale,groupid,vctitle,vcvalue) "
. "VALUES (?, ?, ?, ?)"), . "VALUES (?, ?, ?, ?)"),
array( array(
$locale, $locale,

View File

@ -643,7 +643,7 @@ function ban_for_addr($addr)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT banid,comment FROM {chatban} WHERE dtmtill > :now AND address = :addr", "SELECT banid,comment FROM {ban} WHERE dtmtill > :now AND address = :addr",
array( array(
':addr' => $addr, ':addr' => $addr,
':now' => time(), ':now' => time(),

View File

@ -46,7 +46,7 @@ class BanController extends AbstractController
// Prepare list of all banned visitors // Prepare list of all banned visitors
$db = Database::getInstance(); $db = Database::getInstance();
$blocked_list = $db->query( $blocked_list = $db->query(
"SELECT banid, dtmtill AS till, address, comment FROM {chatban}", "SELECT banid, dtmtill AS till, address, comment FROM {ban}",
null, null,
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -80,7 +80,7 @@ class BanController extends AbstractController
// Remove ban from database // Remove ban from database
$db = Database::getInstance(); $db = Database::getInstance();
$db->query("DELETE FROM {chatban} WHERE banid = ?", array($ban_id)); $db->query("DELETE FROM {ban} WHERE banid = ?", array($ban_id));
// Redirect the current operator to page with bans list // Redirect the current operator to page with bans list
return $this->redirect($this->generateUrl('bans')); return $this->redirect($this->generateUrl('bans'));
@ -119,7 +119,7 @@ class BanController extends AbstractController
$db = Database::getInstance(); $db = Database::getInstance();
$ban = $db->query( $ban = $db->query(
("SELECT banid, (dtmtill - :now) AS days, address, comment " ("SELECT banid, (dtmtill - :now) AS days, address, comment "
. "FROM {chatban} WHERE banid = :banid"), . "FROM {ban} WHERE banid = :banid"),
array( array(
':banid' => $ban_id, ':banid' => $ban_id,
':now' => time(), ':now' => time(),
@ -229,7 +229,7 @@ class BanController extends AbstractController
$till_time = $now + $days * 24 * 60 * 60; $till_time = $now + $days * 24 * 60 * 60;
if (!$ban_id) { if (!$ban_id) {
$db->query( $db->query(
("INSERT INTO {chatban} (dtmcreated, dtmtill, address, comment) " ("INSERT INTO {ban} (dtmcreated, dtmtill, address, comment) "
. "VALUES (:now,:till,:address,:comment)"), . "VALUES (:now,:till,:address,:comment)"),
array( array(
':now' => $now, ':now' => $now,
@ -240,7 +240,7 @@ class BanController extends AbstractController
); );
} else { } else {
$db->query( $db->query(
("UPDATE {chatban} SET dtmtill = :till, address = :address, " ("UPDATE {ban} SET dtmtill = :till, address = :address, "
. "comment = :comment WHERE banid = :banid"), . "comment = :comment WHERE banid = :banid"),
array( array(
':till' => $till_time, ':till' => $till_time,

View File

@ -123,7 +123,7 @@ class CannedMessageController extends AbstractController
$db = Database::getInstance(); $db = Database::getInstance();
$key = $request->attributes->getInt('message_id'); $key = $request->attributes->getInt('message_id');
$db->query("DELETE FROM {chatresponses} WHERE id = ?", array($key)); $db->query("DELETE FROM {cannedmessage} WHERE id = ?", array($key));
// Redirect user to canned messages list. Use only "lang" and "group" // Redirect user to canned messages list. Use only "lang" and "group"
// get params for the target URL. // get params for the target URL.

View File

@ -203,7 +203,7 @@ class RedirectController extends AbstractController
$db = Database::getInstance(); $db = Database::getInstance();
list($groups_count) = $db->query( list($groups_count) = $db->query(
("SELECT count(*) AS count " ("SELECT count(*) AS count "
. "FROM {chatgroupoperator} " . "FROM {operatortoopgroup} "
. "WHERE operatorid = ? AND groupid = ?"), . "WHERE operatorid = ? AND groupid = ?"),
array($operator_id, $thread->groupId), array($operator_id, $thread->groupId),
array( array(

View File

@ -97,9 +97,9 @@ class ManagementController extends AbstractController
// Remove the group and all its relations. // Remove the group and all its relations.
$group_id = $request->attributes->getInt('group_id'); $group_id = $request->attributes->getInt('group_id');
$db->query("DELETE FROM {chatgroup} WHERE groupid = ?", array($group_id)); $db->query("DELETE FROM {opgroup} WHERE groupid = ?", array($group_id));
$db->query("DELETE FROM {chatgroupoperator} WHERE groupid = ?", array($group_id)); $db->query("DELETE FROM {operatortoopgroup} WHERE groupid = ?", array($group_id));
$db->query("UPDATE {chatthread} SET groupid = 0 WHERE groupid = ?", array($group_id)); $db->query("UPDATE {thread} SET groupid = 0 WHERE groupid = ?", array($group_id));
// Redirect user to canned messages list. Use only "sortby" and // Redirect user to canned messages list. Use only "sortby" and
// "sortdirection" get params for the target URL. // "sortdirection" get params for the target URL.

View File

@ -50,8 +50,8 @@ class HistoryController extends AbstractController
if ($query !== false) { if ($query !== false) {
$db = Database::getInstance(); $db = Database::getInstance();
$groups = $db->query( $groups = $db->query(
("SELECT {chatgroup}.groupid AS groupid, vclocalname " . ("SELECT {opgroup}.groupid AS groupid, vclocalname " .
"FROM {chatgroup} " . "FROM {opgroup} " .
"ORDER BY vclocalname"), "ORDER BY vclocalname"),
null, null,
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
@ -70,10 +70,10 @@ class HistoryController extends AbstractController
$search_conditions = array(); $search_conditions = array();
if ($search_type == 'message' || $search_type == 'all') { if ($search_type == 'message' || $search_type == 'all') {
$search_conditions[] = "({chatmessage}.tmessage LIKE :query" $search_conditions[] = "({message}.tmessage LIKE :query"
. ($search_in_system_messages . ($search_in_system_messages
? '' ? ''
: " AND ({chatmessage}.ikind = :kind_user OR {chatmessage}.ikind = :kind_agent)") : " AND ({message}.ikind = :kind_user OR {message}.ikind = :kind_agent)")
. ")"; . ")";
if (!$search_in_system_messages) { if (!$search_in_system_messages) {
$values[':kind_user'] = Thread::KIND_USER; $values[':kind_user'] = Thread::KIND_USER;
@ -81,20 +81,20 @@ class HistoryController extends AbstractController
} }
} }
if ($search_type == 'operator' || $search_type == 'all') { if ($search_type == 'operator' || $search_type == 'all') {
$search_conditions[] = "({chatthread}.agentname LIKE :query)"; $search_conditions[] = "({thread}.agentname LIKE :query)";
} }
if ($search_type == 'visitor' || $search_type == 'all') { if ($search_type == 'visitor' || $search_type == 'all') {
$search_conditions[] = "({chatthread}.username LIKE :query)"; $search_conditions[] = "({thread}.username LIKE :query)";
$search_conditions[] = "({chatthread}.remote LIKE :query)"; $search_conditions[] = "({thread}.remote LIKE :query)";
} }
// Load threads // Load threads
list($threads_count) = $db->query( list($threads_count) = $db->query(
("SELECT COUNT(DISTINCT {chatthread}.dtmcreated) " ("SELECT COUNT(DISTINCT {thread}.dtmcreated) "
. "FROM {chatthread}, {chatmessage} " . "FROM {thread}, {message} "
. "WHERE {chatmessage}.threadid = {chatthread}.threadid " . "WHERE {message}.threadid = {thread}.threadid "
. "AND ({chatthread}.invitationstate = :invitation_accepted " . "AND ({thread}.invitationstate = :invitation_accepted "
. "OR {chatthread}.invitationstate = :invitation_not_invited) " . "OR {thread}.invitationstate = :invitation_not_invited) "
. "AND (" . implode(' OR ', $search_conditions) . ")"), . "AND (" . implode(' OR ', $search_conditions) . ")"),
$values, $values,
array( array(
@ -112,13 +112,13 @@ class HistoryController extends AbstractController
$limit_end = intval($pagination_info['end'] - $pagination_info['start']); $limit_end = intval($pagination_info['end'] - $pagination_info['start']);
$threads_list = $db->query( $threads_list = $db->query(
("SELECT DISTINCT {chatthread}.* " ("SELECT DISTINCT {thread}.* "
. "FROM {chatthread}, {chatmessage} " . "FROM {thread}, {message} "
. "WHERE {chatmessage}.threadid = {chatthread}.threadid " . "WHERE {message}.threadid = {thread}.threadid "
. "AND ({chatthread}.invitationstate = :invitation_accepted " . "AND ({thread}.invitationstate = :invitation_accepted "
. "OR {chatthread}.invitationstate = :invitation_not_invited) " . "OR {thread}.invitationstate = :invitation_not_invited) "
. "AND (" . implode(' OR ', $search_conditions) . ") " . "AND (" . implode(' OR ', $search_conditions) . ") "
. "ORDER BY {chatthread}.dtmcreated DESC " . "ORDER BY {thread}.dtmcreated DESC "
. "LIMIT " . $limit_start . ", " . $limit_end), . "LIMIT " . $limit_start . ", " . $limit_end),
$values, $values,
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
@ -219,8 +219,8 @@ class HistoryController extends AbstractController
if (!empty($user_id)) { if (!empty($user_id)) {
$db = Database::getInstance(); $db = Database::getInstance();
$query = "SELECT {chatthread}.* " $query = "SELECT {thread}.* "
. "FROM {chatthread} " . "FROM {thread} "
. "WHERE userid=:user_id " . "WHERE userid=:user_id "
. "AND (invitationstate = :invitation_accepted " . "AND (invitationstate = :invitation_accepted "
. "OR invitationstate = :invitation_not_invited) " . "OR invitationstate = :invitation_not_invited) "

View File

@ -170,7 +170,7 @@ class ManagementController extends AbstractController
// Disable the operator // Disable the operator
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"update {chatoperator} set idisabled = ? where operatorid = ?", "update {operator} set idisabled = ? where operatorid = ?",
array('1', $operator_id) array('1', $operator_id)
); );
@ -198,7 +198,7 @@ class ManagementController extends AbstractController
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"update {chatoperator} set idisabled = ? where operatorid = ?", "update {operator} set idisabled = ? where operatorid = ?",
array('0', $operator_id) array('0', $operator_id)
); );

View File

@ -72,7 +72,7 @@ class PasswordRecoveryController extends AbstractController
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("UPDATE {chatoperator} " ("UPDATE {operator} "
. "SET dtmrestore = :now, vcrestoretoken = :token " . "SET dtmrestore = :now, vcrestoretoken = :token "
. "WHERE operatorid = :operatorid"), . "WHERE operatorid = :operatorid"),
array( array(
@ -178,7 +178,7 @@ class PasswordRecoveryController extends AbstractController
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("UPDATE {chatoperator} " ("UPDATE {operator} "
. "SET vcpassword = ?, vcrestoretoken = '' " . "SET vcpassword = ?, vcrestoretoken = '' "
. "WHERE operatorid = ?"), . "WHERE operatorid = ?"),
array( array(

View File

@ -217,7 +217,7 @@ class Installer
try { try {
$db->query( $db->query(
'UPDATE {chatoperator} SET vcpassword = :pass WHERE vclogin = :login', 'UPDATE {operator} SET vcpassword = :pass WHERE vclogin = :login',
array( array(
':login' => 'admin', ':login' => 'admin',
':pass' => calculate_password_hash('admin', $password) ':pass' => calculate_password_hash('admin', $password)
@ -341,7 +341,7 @@ class Installer
// Create The First Administrator if needed // Create The First Administrator if needed
try { try {
list($count) = $db->query( list($count) = $db->query(
'SELECT COUNT(*) FROM {chatoperator} WHERE vclogin = :login', 'SELECT COUNT(*) FROM {operator} WHERE vclogin = :login',
array(':login' => 'admin'), array(':login' => 'admin'),
array( array(
'return_rows' => Database::RETURN_ONE_ROW, 'return_rows' => Database::RETURN_ONE_ROW,
@ -350,7 +350,7 @@ class Installer
); );
if ($count == 0) { if ($count == 0) {
$db->query( $db->query(
('INSERT INTO {chatoperator} ( ' ('INSERT INTO {operator} ( '
. 'vclogin, vcpassword, vclocalename, vccommonname, ' . 'vclogin, vcpassword, vclocalename, vccommonname, '
. 'vcavatar, vcemail, iperm ' . 'vcavatar, vcemail, iperm '
. ') values ( ' . ') values ( '
@ -379,7 +379,7 @@ class Installer
// Initialize chat revision counter if it is needed // Initialize chat revision counter if it is needed
try { try {
list($count) = $db->query( list($count) = $db->query(
'SELECT COUNT(*) FROM {chatrevision}', 'SELECT COUNT(*) FROM {revision}',
null, null,
array( array(
'return_rows' => Database::RETURN_ONE_ROW, 'return_rows' => Database::RETURN_ONE_ROW,
@ -388,7 +388,7 @@ class Installer
); );
if ($count == 0) { if ($count == 0) {
$db->query( $db->query(
'INSERT INTO {chatrevision} VALUES (:init_revision)', 'INSERT INTO {revision} VALUES (:init_revision)',
array(':init_revision' => 1) array(':init_revision' => 1)
); );
} }
@ -404,7 +404,7 @@ class Installer
// Set correct database structure version if needed // Set correct database structure version if needed
try { try {
list($count) = $db->query( list($count) = $db->query(
'SELECT COUNT(*) FROM {chatconfig} WHERE vckey = :key', 'SELECT COUNT(*) FROM {config} WHERE vckey = :key',
array(':key' => 'dbversion'), array(':key' => 'dbversion'),
array( array(
'return_rows' => Database::RETURN_ONE_ROW, 'return_rows' => Database::RETURN_ONE_ROW,
@ -413,7 +413,7 @@ class Installer
); );
if ($count == 0) { if ($count == 0) {
$db->query( $db->query(
'INSERT INTO {chatconfig} (vckey, vcvalue) VALUES (:key, :value)', 'INSERT INTO {config} (vckey, vcvalue) VALUES (:key, :value)',
array( array(
':key' => 'dbversion', ':key' => 'dbversion',
':value' => DB_VERSION, ':value' => DB_VERSION,
@ -538,7 +538,7 @@ class Installer
try { try {
$result = $db->query( $result = $db->query(
"SELECT vcvalue AS version FROM {chatconfig} WHERE vckey = :key LIMIT 1", "SELECT vcvalue AS version FROM {config} WHERE vckey = :key LIMIT 1",
array(':key' => 'dbversion'), array(':key' => 'dbversion'),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );

View File

@ -179,7 +179,7 @@ class UsersProcessor extends ClientSideProcessor
$query = "SELECT t.*, " $query = "SELECT t.*, "
. " g.vclocalname AS group_localname, " . " g.vclocalname AS group_localname, "
. " g.vccommonname AS group_commonname " . " g.vccommonname AS group_commonname "
. " FROM {chatthread} t LEFT OUTER JOIN {chatgroup} g ON " . " FROM {thread} t LEFT OUTER JOIN {opgroup} g ON "
. " t.groupid = g.groupid " . " t.groupid = g.groupid "
. " WHERE t.lrevision > :since " . " WHERE t.lrevision > :since "
. " AND t.istate <> " . Thread::STATE_INVITED . " AND t.istate <> " . Thread::STATE_INVITED
@ -196,7 +196,7 @@ class UsersProcessor extends ClientSideProcessor
// If groups are enabled select only threads with empty groupid // If groups are enabled select only threads with empty groupid
// or groups related to current operator // or groups related to current operator
? " AND (g.groupid is NULL" . ($group_ids ? " OR g.groupid IN ($group_ids) OR g.groupid IN " ? " AND (g.groupid is NULL" . ($group_ids ? " OR g.groupid IN ($group_ids) OR g.groupid IN "
. "(SELECT parent FROM {chatgroup} " . "(SELECT parent FROM {opgroup} "
. "WHERE groupid IN ($group_ids)) " : "") . "WHERE groupid IN ($group_ids)) " : "")
. ") " . ") "
: "" : ""
@ -279,7 +279,7 @@ class UsersProcessor extends ClientSideProcessor
$first_message = null; $first_message = null;
if ($thread->shownMessageId != 0) { if ($thread->shownMessageId != 0) {
$line = $db->query( $line = $db->query(
"SELECT tmessage FROM {chatmessage} WHERE messageid = ? LIMIT 1", "SELECT tmessage FROM {message} WHERE messageid = ? LIMIT 1",
array($thread->shownMessageId), array($thread->shownMessageId),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -398,8 +398,8 @@ class UsersProcessor extends ClientSideProcessor
. "t.agentId AS invitedby, " . "t.agentId AS invitedby, "
. "v.invitations, " . "v.invitations, "
. "v.chats " . "v.chats "
. "FROM {chatsitevisitor} v " . "FROM {sitevisitor} v "
. "LEFT OUTER JOIN {chatthread} t " . "LEFT OUTER JOIN {thread} t "
. "ON t.threadid = v.threadid " . "ON t.threadid = v.threadid "
. "WHERE v.threadid IS NULL " . "WHERE v.threadid IS NULL "
. "OR (t.istate = :state_invited " . "OR (t.istate = :state_invited "

View File

@ -117,7 +117,7 @@ class Settings
// Load values from database // Load values from database
$db = Database::getInstance(); $db = Database::getInstance();
$rows = $db->query( $rows = $db->query(
"SELECT vckey, vcvalue FROM {chatconfig}", "SELECT vckey, vcvalue FROM {config}",
null, null,
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -164,12 +164,12 @@ class Settings
foreach ($instance->settings as $key => $value) { foreach ($instance->settings as $key => $value) {
if (!isset($instance->settingsInDb[$key])) { if (!isset($instance->settingsInDb[$key])) {
$db->query( $db->query(
"INSERT INTO {chatconfig} (vckey) VALUES (?)", "INSERT INTO {config} (vckey) VALUES (?)",
array($key) array($key)
); );
} }
$db->query( $db->query(
"UPDATE {chatconfig} SET vcvalue=? WHERE vckey=?", "UPDATE {config} SET vcvalue=? WHERE vckey=?",
array($value, $key) array($value, $key)
); );
} }

View File

@ -129,7 +129,7 @@ class Thread
/** /**
* Contain mapping of thread object properties to fields in database. * Contain mapping of thread object properties to fields in database.
* *
* Keys are object properties and vlues are {chatthread} table fields. * Keys are object properties and vlues are {thread} table fields.
* Properties are available via magic __get and __set methods. Real values * Properties are available via magic __get and __set methods. Real values
* are stored in the Thread::$threadInfo array. * are stored in the Thread::$threadInfo array.
* *
@ -230,7 +230,7 @@ class Thread
$thread = new self(); $thread = new self();
// Create thread // Create thread
$db->query("insert into {chatthread} (threadid) values (NULL)"); $db->query("insert into {thread} (threadid) values (NULL)");
// Set thread Id // Set thread Id
// In this case Thread::$threadInfo array use because id of a thread // In this case Thread::$threadInfo array use because id of a thread
@ -300,7 +300,7 @@ class Thread
// Load thread // Load thread
$thread_info = $db->query( $thread_info = $db->query(
"SELECT * FROM {chatthread} WHERE threadid = :threadid", "SELECT * FROM {thread} WHERE threadid = :threadid",
array(':threadid' => $id), array(':threadid' => $id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -381,7 +381,7 @@ class Thread
$db = Database::getInstance(); $db = Database::getInstance();
$query = "UPDATE {chatthread} SET " $query = "UPDATE {thread} SET "
. "lrevision = :next_revision, " . "lrevision = :next_revision, "
. "dtmmodified = :now, " . "dtmmodified = :now, "
. "dtmclosed = :now, " . "dtmclosed = :now, "
@ -445,7 +445,7 @@ class Thread
$db = Database::getInstance(); $db = Database::getInstance();
$result = $db->query( $result = $db->query(
"SELECT COUNT(*) AS opened FROM {chatthread} WHERE remote = ? AND istate <> ? AND istate <> ?", "SELECT COUNT(*) AS opened FROM {thread} WHERE remote = ? AND istate <> ? AND istate <> ?",
array( array(
$remote, $remote,
Thread::STATE_CLOSED, Thread::STATE_CLOSED,
@ -547,7 +547,7 @@ class Thread
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"DELETE FROM {chatthread} WHERE threadid = :id LIMIT 1", "DELETE FROM {thread} WHERE threadid = :id LIMIT 1",
array(':id' => $this->id) array(':id' => $this->id)
); );
} }
@ -672,7 +672,7 @@ class Thread
$values[] = $this->threadInfo[$field_db_name]; $values[] = $this->threadInfo[$field_db_name];
} }
$query = "UPDATE {chatthread} t SET " . implode(', ', $set_clause) $query = "UPDATE {thread} t SET " . implode(', ', $set_clause)
. " WHERE threadid = ?"; . " WHERE threadid = ?";
$values[] = $this->id; $values[] = $this->id;
$db->query($query, $values); $db->query($query, $values);
@ -765,7 +765,7 @@ class Thread
// Load messages // Load messages
$query = "SELECT messageid AS id, ikind AS kind, dtmcreated AS created, " $query = "SELECT messageid AS id, ikind AS kind, dtmcreated AS created, "
. " tname AS name, tmessage AS message, plugin, data " . " tname AS name, tmessage AS message, plugin, data "
. "FROM {chatmessage} " . "FROM {message} "
. "WHERE threadid = :threadid AND messageid > :lastid " . "WHERE threadid = :threadid AND messageid > :lastid "
. ($is_user ? "AND ikind <> " . self::KIND_FOR_AGENT : "") . ($is_user ? "AND ikind <> " . self::KIND_FOR_AGENT : "")
. " ORDER BY messageid"; . " ORDER BY messageid";
@ -891,8 +891,8 @@ class Thread
$db = Database::getInstance(); $db = Database::getInstance();
list($message_count) = $db->query( list($message_count) = $db->query(
("SELECT COUNT(*) FROM {chatmessage} " ("SELECT COUNT(*) FROM {message} "
. "WHERE {chatmessage}.threadid = :threadid AND ikind = :kind_user"), . "WHERE {message}.threadid = :threadid AND ikind = :kind_user"),
array( array(
':threadid' => $this->id, ':threadid' => $this->id,
':kind_user' => Thread::KIND_USER, ':kind_user' => Thread::KIND_USER,
@ -1076,7 +1076,7 @@ class Thread
$options['data'] = serialize((array) $options['data']); $options['data'] = serialize((array) $options['data']);
// Prepare query // Prepare query
$query = "INSERT INTO {chatmessage} (" $query = "INSERT INTO {message} ("
. "threadid, ikind, tmessage, tname, agentid, " . "threadid, ikind, tmessage, tname, agentid, "
. "dtmcreated, plugin, data" . "dtmcreated, plugin, data"
. ") VALUES (" . ") VALUES ("
@ -1109,7 +1109,7 @@ class Thread
protected static function nextRevision() protected static function nextRevision()
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query("UPDATE {chatrevision} SET id=LAST_INSERT_ID(id+1)"); $db->query("UPDATE {revision} SET id=LAST_INSERT_ID(id+1)");
$val = $db->insertedId(); $val = $db->insertedId();
return $val; return $val;

View File

@ -33,7 +33,7 @@ function group_by_id($id)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$group = $db->query( $group = $db->query(
"SELECT * FROM {chatgroup} WHERE groupid = ?", "SELECT * FROM {opgroup} WHERE groupid = ?",
array($id), array($id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -55,7 +55,7 @@ function group_by_name($name)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$group = $db->query( $group = $db->query(
"SELECT * FROM {chatgroup} WHERE vclocalname = ?", "SELECT * FROM {opgroup} WHERE vclocalname = ?",
array($name), array($name),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -95,7 +95,7 @@ function get_operator_groups_list($operator_id)
if (Settings::get('enablegroups') == '1') { if (Settings::get('enablegroups') == '1') {
$group_ids = array(0); $group_ids = array(0);
$all_groups = $db->query( $all_groups = $db->query(
"SELECT groupid FROM {chatgroupoperator} WHERE operatorid = ? ORDER BY groupid", "SELECT groupid FROM {operatortoopgroup} WHERE operatorid = ? ORDER BY groupid",
array($operator_id), array($operator_id),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -132,8 +132,8 @@ function get_available_parent_groups($skip_group)
$db = Database::getInstance(); $db = Database::getInstance();
$groups_list = $db->query( $groups_list = $db->query(
("SELECT {chatgroup}.groupid AS groupid, parent, vclocalname " ("SELECT {opgroup}.groupid AS groupid, parent, vclocalname "
. "FROM {chatgroup} ORDER BY vclocalname"), . "FROM {opgroup} ORDER BY vclocalname"),
null, null,
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -160,7 +160,7 @@ function group_has_children($group_id)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$children = $db->query( $children = $db->query(
"SELECT COUNT(*) AS count FROM {chatgroup} WHERE parent = ?", "SELECT COUNT(*) AS count FROM {opgroup} WHERE parent = ?",
array($group_id), array($group_id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -310,7 +310,7 @@ function create_group($group)
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("INSERT INTO {chatgroup} (" ("INSERT INTO {opgroup} ("
. "parent, vclocalname, vclocaldescription, vccommonname, " . "parent, vclocalname, vclocaldescription, vccommonname, "
. "vccommondescription, vcemail, vctitle, vcchattitle, vchosturl, " . "vccommondescription, vcemail, vctitle, vcchattitle, vchosturl, "
. "vclogo, iweight" . "vclogo, iweight"
@ -332,7 +332,7 @@ function create_group($group)
$id = $db->insertedId(); $id = $db->insertedId();
$new_group = $db->query( $new_group = $db->query(
"SELECT * FROM {chatgroup} WHERE groupid = ?", "SELECT * FROM {opgroup} WHERE groupid = ?",
array($id), array($id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -364,7 +364,7 @@ function update_group($group)
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("UPDATE {chatgroup} SET " ("UPDATE {opgroup} SET "
. "parent = ?, vclocalname = ?, vclocaldescription = ?, " . "parent = ?, vclocalname = ?, vclocaldescription = ?, "
. "vccommonname = ?, vccommondescription = ?, " . "vccommonname = ?, vccommondescription = ?, "
. "vcemail = ?, vctitle = ?, vcchattitle = ?, " . "vcemail = ?, vctitle = ?, vcchattitle = ?, "
@ -388,7 +388,7 @@ function update_group($group)
if ($group['parent']) { if ($group['parent']) {
$db->query( $db->query(
"UPDATE {chatgroup} SET parent = NULL WHERE parent = ?", "UPDATE {opgroup} SET parent = NULL WHERE parent = ?",
array($group['id']) array($group['id'])
); );
} }
@ -405,7 +405,7 @@ function get_group_members($group_id)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT operatorid FROM {chatgroupoperator} WHERE groupid = ?", "SELECT operatorid FROM {operatortoopgroup} WHERE groupid = ?",
array($group_id), array($group_id),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -421,13 +421,13 @@ function update_group_members($group_id, $new_value)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"DELETE FROM {chatgroupoperator} WHERE groupid = ?", "DELETE FROM {operatortoopgroup} WHERE groupid = ?",
array($group_id) array($group_id)
); );
foreach ($new_value as $operator_id) { foreach ($new_value as $operator_id) {
$db->query( $db->query(
"INSERT INTO {chatgroupoperator} (groupid, operatorid) VALUES (?, ?)", "INSERT INTO {operatortoopgroup} (groupid, operatorid) VALUES (?, ?)",
array($group_id, $operator_id) array($group_id, $operator_id)
); );
} }

View File

@ -34,7 +34,7 @@ function invitation_state($visitor_id)
$db = Database::getInstance(); $db = Database::getInstance();
$db_result = $db->query( $db_result = $db->query(
("SELECT t.threadid, t.invitationstate, t.istate " ("SELECT t.threadid, t.invitationstate, t.istate "
. "FROM {chatsitevisitor} v, {chatthread} t " . "FROM {sitevisitor} v, {thread} t "
. "WHERE visitorid = ? " . "WHERE visitorid = ? "
. "AND t.threadid = v.threadid"), . "AND t.threadid = v.threadid"),
array($visitor_id), array($visitor_id),
@ -106,7 +106,7 @@ function invitation_invite($visitor_id, $operator)
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("UPDATE {chatsitevisitor} set " ("UPDATE {sitevisitor} set "
. "invitations = invitations + 1, " . "invitations = invitations + 1, "
. "threadid = :thread_id " . "threadid = :thread_id "
. "WHERE visitorid = :visitor_id"), . "WHERE visitorid = :visitor_id"),
@ -156,7 +156,7 @@ function invitation_accept($visitor_id)
// Get thread related with the visitor // Get thread related with the visitor
$db = Database::getInstance(); $db = Database::getInstance();
$result = $db->query( $result = $db->query(
"SELECT threadid FROM {chatsitevisitor} WHERE visitorid = :visitor_id", "SELECT threadid FROM {sitevisitor} WHERE visitorid = :visitor_id",
array(':visitor_id' => $visitor_id), array(':visitor_id' => $visitor_id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -180,7 +180,7 @@ function invitation_accept($visitor_id)
// Update visitor info // Update visitor info
$db->query( $db->query(
("UPDATE {chatsitevisitor} SET chats = chats + 1 " ("UPDATE {sitevisitor} SET chats = chats + 1 "
. "WHERE visitorid = :visitor_id"), . "WHERE visitorid = :visitor_id"),
array(':visitor_id' => $visitor_id) array(':visitor_id' => $visitor_id)
); );
@ -208,7 +208,7 @@ function invitation_reject($visitor_id)
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("UPDATE {chatsitevisitor} v, {chatthread} t SET " ("UPDATE {sitevisitor} v, {thread} t SET "
. "v.threadid = NULL, " . "v.threadid = NULL, "
. "t.invitationstate = :invitation_rejected, " . "t.invitationstate = :invitation_rejected, "
. "t.istate = :state_closed, " . "t.istate = :state_closed, "
@ -233,7 +233,7 @@ function invitation_close_old()
// Get all threads to close // Get all threads to close
$threads = $db->query( $threads = $db->query(
("SELECT * FROM {chatthread} " ("SELECT * FROM {thread} "
. "WHERE istate = :state_invited " . "WHERE istate = :state_invited "
. "AND invitationstate = :invitation_wait " . "AND invitationstate = :invitation_wait "
. "AND (:now - dtmcreated) > :lifetime"), . "AND (:now - dtmcreated) > :lifetime"),
@ -248,7 +248,7 @@ function invitation_close_old()
// Remove old invitations // Remove old invitations
$db->query( $db->query(
("UPDATE {chatsitevisitor} v, {chatthread} t SET " ("UPDATE {sitevisitor} v, {thread} t SET "
. "t.invitationstate = :invitation_ignored, " . "t.invitationstate = :invitation_ignored, "
. "t.istate = :state_closed, " . "t.istate = :state_closed, "
. "t.dtmclosed = :now, " . "t.dtmclosed = :now, "

View File

@ -74,7 +74,7 @@ function update_operator_permissions($operator_id, $perm)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"UPDATE {chatoperator} SET iperm = ? WHERE operatorid = ?", "UPDATE {operator} SET iperm = ? WHERE operatorid = ?",
array($perm, $operator_id) array($perm, $operator_id)
); );
} }
@ -84,7 +84,7 @@ function operator_by_login($login)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT * FROM {chatoperator} WHERE vclogin = ?", "SELECT * FROM {operator} WHERE vclogin = ?",
array($login), array($login),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -95,7 +95,7 @@ function operator_by_email($mail)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT * FROM {chatoperator} WHERE vcemail = ?", "SELECT * FROM {operator} WHERE vcemail = ?",
array($mail), array($mail),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -106,7 +106,7 @@ function operator_by_id($id)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT * FROM {chatoperator} WHERE operatorid = ?", "SELECT * FROM {operator} WHERE operatorid = ?",
array($id), array($id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -124,7 +124,7 @@ function operator_by_code($code)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT * FROM {chatoperator} WHERE code = ?", "SELECT * FROM {operator} WHERE code = ?",
array($code), array($code),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -170,7 +170,7 @@ function get_operators_list($options = array())
} }
$query = "SELECT DISTINCT " $query = "SELECT DISTINCT "
. "{chatoperator}.operatorid, " . "{operator}.operatorid, "
. "vclogin, " . "vclogin, "
. "vclocalename, " . "vclocalename, "
. "vccommonname, " . "vccommonname, "
@ -178,16 +178,16 @@ function get_operators_list($options = array())
. "istatus, " . "istatus, "
. "idisabled, " . "idisabled, "
. "(:now - dtmlastvisited) AS time " . "(:now - dtmlastvisited) AS time "
. "FROM {chatoperator}" . "FROM {operator}"
. (empty($options['isolated_operator_id']) . (empty($options['isolated_operator_id'])
? "" ? ""
: ", {chatgroupoperator} " : ", {operatortoopgroup} "
. "WHERE {chatoperator}.operatorid = {chatgroupoperator}.operatorid " . "WHERE {operator}.operatorid = {operatortoopgroup}.operatorid "
. "AND {chatgroupoperator}.groupid IN (" . "AND {operatortoopgroup}.groupid IN ("
. "SELECT g.groupid FROM {chatgroup} g, " . "SELECT g.groupid FROM {opgroup} g, "
. "(SELECT DISTINCT parent FROM {chatgroup}, {chatgroupoperator} " . "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} "
. "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {chatgroupoperator}.operatorid = :operatorid) i " . "AND {operatortoopgroup}.operatorid = :operatorid) i "
. "WHERE g.groupid = i.parent OR g.parent = i.parent " . "WHERE g.groupid = i.parent OR g.parent = i.parent "
. ")") . ")")
. " ORDER BY " . $orderby; . " ORDER BY " . $orderby;
@ -222,7 +222,7 @@ function operator_get_all()
return $operators = $db->query( return $operators = $db->query(
("SELECT operatorid, vclogin, vclocalename, vccommonname, istatus, " ("SELECT operatorid, vclogin, vclocalename, vccommonname, istatus, "
. "code, idisabled, (:now - dtmlastvisited) AS time " . "code, idisabled, (:now - dtmlastvisited) AS time "
. "FROM {chatoperator} ORDER BY vclogin"), . "FROM {operator} ORDER BY vclogin"),
array(':now' => time()), array(':now' => time()),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -230,17 +230,17 @@ function operator_get_all()
function get_operators_from_adjacent_groups($operator) function get_operators_from_adjacent_groups($operator)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$query = "SELECT DISTINCT {chatoperator}.operatorid, vclogin, " $query = "SELECT DISTINCT {operator}.operatorid, vclogin, "
. "vclocalename,vccommonname, " . "vclocalename,vccommonname, "
. "istatus, idisabled, code, " . "istatus, idisabled, code, "
. "(:now - dtmlastvisited) AS time " . "(:now - dtmlastvisited) AS time "
. "FROM {chatoperator}, {chatgroupoperator} " . "FROM {operator}, {operatortoopgroup} "
. "WHERE {chatoperator}.operatorid = {chatgroupoperator}.operatorid " . "WHERE {operator}.operatorid = {operatortoopgroup}.operatorid "
. "AND {chatgroupoperator}.groupid IN (" . "AND {operatortoopgroup}.groupid IN ("
. "SELECT g.groupid from {chatgroup} g, " . "SELECT g.groupid from {opgroup} g, "
. "(SELECT DISTINCT parent FROM {chatgroup}, {chatgroupoperator} " . "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} "
. "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {chatgroupoperator}.operatorid = :operatorid) i " . "AND {operatortoopgroup}.operatorid = :operatorid) i "
. "WHERE g.groupid = i.parent OR g.parent = i.parent " . "WHERE g.groupid = i.parent OR g.parent = i.parent "
. ") ORDER BY vclogin"; . ") ORDER BY vclogin";
@ -315,7 +315,7 @@ function update_operator(
$values[':password'] = calculate_password_hash($login, $password); $values[':password'] = calculate_password_hash($login, $password);
} }
$db->query( $db->query(
("UPDATE {chatoperator} SET vclogin = :login, " ("UPDATE {operator} SET vclogin = :login, "
. ($password ? " vcpassword=:password, " : "") . ($password ? " vcpassword=:password, " : "")
. "vclocalename = :localname, vccommonname = :commonname, " . "vclocalename = :localname, vccommonname = :commonname, "
. "vcemail = :email, code = :code, vcjabbername= :jabbername " . "vcemail = :email, code = :code, vcjabbername= :jabbername "
@ -328,7 +328,7 @@ function update_operator_avatar($operator_id, $avatar)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"UPDATE {chatoperator} SET vcavatar = ? WHERE operatorid = ?", "UPDATE {operator} SET vcavatar = ? WHERE operatorid = ?",
array($avatar, $operator_id) array($avatar, $operator_id)
); );
} }
@ -357,7 +357,7 @@ function create_operator(
) { ) {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("INSERT INTO {chatoperator} (" ("INSERT INTO {operator} ("
. "vclogin, vcpassword, vclocalename, vccommonname, vcavatar, " . "vclogin, vcpassword, vclocalename, vccommonname, vcavatar, "
. "vcemail, code, vcjabbername " . "vcemail, code, vcjabbername "
. ") VALUES (" . ") VALUES ("
@ -379,7 +379,7 @@ function create_operator(
$id = $db->insertedId(); $id = $db->insertedId();
return $db->query( return $db->query(
"SELECT * FROM {chatoperator} WHERE operatorid = ?", "SELECT * FROM {operator} WHERE operatorid = ?",
array($id), array($id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -400,11 +400,11 @@ function delete_operator($operator_id)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"DELETE FROM {chatgroupoperator} WHERE operatorid = ?", "DELETE FROM {operatortoopgroup} WHERE operatorid = ?",
array($operator_id) array($operator_id)
); );
$db->query( $db->query(
"DELETE FROM {chatoperator} WHERE operatorid = ?", "DELETE FROM {operator} WHERE operatorid = ?",
array($operator_id) array($operator_id)
); );
@ -425,7 +425,7 @@ function notify_operator_alive($operator_id, $istatus)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("UPDATE {chatoperator} SET istatus = :istatus, dtmlastvisited = :now " ("UPDATE {operator} SET istatus = :istatus, dtmlastvisited = :now "
. "WHERE operatorid = :operatorid"), . "WHERE operatorid = :operatorid"),
array( array(
':istatus' => $istatus, ':istatus' => $istatus,
@ -450,19 +450,19 @@ function has_online_operators($group_id = "")
$db = Database::getInstance(); $db = Database::getInstance();
$query = "SELECT count(*) AS total, MIN(:now - dtmlastvisited) AS time " $query = "SELECT count(*) AS total, MIN(:now - dtmlastvisited) AS time "
. "FROM {chatoperator}"; . "FROM {operator}";
$values = array(':now' => time()); $values = array(':now' => time());
if ($group_id) { if ($group_id) {
$query .= ", {chatgroupoperator}, {chatgroup} " $query .= ", {operatortoopgroup}, {opgroup} "
. "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND ({chatgroup}.groupid = :groupid OR {chatgroup}.parent = :groupid) " . "AND ({opgroup}.groupid = :groupid OR {opgroup}.parent = :groupid) "
. "AND {chatoperator}.operatorid = {chatgroupoperator}.operatorid " . "AND {operator}.operatorid = {operatortoopgroup}.operatorid "
. "AND istatus = 0"; . "AND istatus = 0";
$values[':groupid'] = $group_id; $values[':groupid'] = $group_id;
} else { } else {
if (Settings::get('enablegroups') == 1) { if (Settings::get('enablegroups') == 1) {
$query .= ", {chatgroupoperator} " $query .= ", {operatortoopgroup} "
. "WHERE {chatoperator}.operatorid = {chatgroupoperator}.operatorid " . "WHERE {operator}.operatorid = {operatortoopgroup}.operatorid "
. "AND istatus = 0"; . "AND istatus = 0";
} else { } else {
$query .= " WHERE istatus = 0"; $query .= " WHERE istatus = 0";
@ -490,7 +490,7 @@ function is_operator_online($operator_id)
$row = $db->query( $row = $db->query(
("SELECT count(*) AS total, " ("SELECT count(*) AS total, "
. "MIN(:now - dtmlastvisited) AS time " . "MIN(:now - dtmlastvisited) AS time "
. "FROM {chatoperator} WHERE operatorid = :operatorid"), . "FROM {operator} WHERE operatorid = :operatorid"),
array( array(
':now' => time(), ':now' => time(),
':operatorid' => $operator_id, ':operatorid' => $operator_id,
@ -665,9 +665,9 @@ function get_all_groups()
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$groups = $db->query( $groups = $db->query(
("SELECT {chatgroup}.groupid AS groupid, parent, " ("SELECT {opgroup}.groupid AS groupid, parent, "
. "vclocalname, vclocaldescription " . "vclocalname, vclocaldescription "
. "FROM {chatgroup} ORDER BY vclocalname"), . "FROM {opgroup} ORDER BY vclocalname"),
null, null,
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -679,10 +679,10 @@ function get_all_groups_for_operator($operator)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$query = "SELECT g.groupid AS groupid, g.parent, g.vclocalname, g.vclocaldescription " $query = "SELECT g.groupid AS groupid, g.parent, g.vclocalname, g.vclocaldescription "
. "FROM {chatgroup} g, " . "FROM {opgroup} g, "
. "(SELECT DISTINCT parent FROM {chatgroup}, {chatgroupoperator} " . "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} "
. "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {chatgroupoperator}.operatorid = ?) i " . "AND {operatortoopgroup}.operatorid = ?) i "
. "WHERE g.groupid = i.parent OR g.parent = i.parent " . "WHERE g.groupid = i.parent OR g.parent = i.parent "
. "ORDER BY vclocalname"; . "ORDER BY vclocalname";
@ -737,10 +737,10 @@ function get_groups_($check_away, $operator, $order = null)
$orderby = "ilastseen"; $orderby = "ilastseen";
break; break;
default: default:
$orderby = "{chatgroup}.vclocalname"; $orderby = "{opgroup}.vclocalname";
} }
$orderby = sprintf( $orderby = sprintf(
" IF(ISNULL({chatgroup}.parent),CONCAT('_',%s),'') %s, {chatgroup}.iweight ", " IF(ISNULL({opgroup}.parent),CONCAT('_',%s),'') %s, {opgroup}.iweight ",
$orderby, $orderby,
($order['desc'] ? 'DESC' : 'ASC') ($order['desc'] ? 'DESC' : 'ASC')
); );
@ -751,35 +751,35 @@ function get_groups_($check_away, $operator, $order = null)
$values = array( $values = array(
':now' => time(), ':now' => time(),
); );
$query = "SELECT {chatgroup}.groupid AS groupid, " $query = "SELECT {opgroup}.groupid AS groupid, "
. "{chatgroup}.parent AS parent, " . "{opgroup}.parent AS parent, "
. "vclocalname, vclocaldescription, iweight, " . "vclocalname, vclocaldescription, iweight, "
. "(SELECT count(*) " . "(SELECT count(*) "
. "FROM {chatgroupoperator} " . "FROM {operatortoopgroup} "
. "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid" . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid"
. ") AS inumofagents, " . ") AS inumofagents, "
. "(SELECT MIN(:now - dtmlastvisited) AS time " . "(SELECT MIN(:now - dtmlastvisited) AS time "
. "FROM {chatgroupoperator}, {chatoperator} " . "FROM {operatortoopgroup}, {operator} "
. "WHERE istatus = 0 " . "WHERE istatus = 0 "
. "AND {chatgroup}.groupid = {chatgroupoperator}.groupid " . "AND {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {chatgroupoperator}.operatorid = {chatoperator}.operatorid" . . "AND {operatortoopgroup}.operatorid = {operator}.operatorid" .
") AS ilastseen" ") AS ilastseen"
. ($check_away . ($check_away
? ", (SELECT MIN(:now - dtmlastvisited) AS time " ? ", (SELECT MIN(:now - dtmlastvisited) AS time "
. "FROM {chatgroupoperator}, {chatoperator} " . "FROM {operatortoopgroup}, {operator} "
. "WHERE istatus <> 0 " . "WHERE istatus <> 0 "
. "AND {chatgroup}.groupid = {chatgroupoperator}.groupid " . "AND {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {chatgroupoperator}.operatorid = {chatoperator}.operatorid" . "AND {operatortoopgroup}.operatorid = {operator}.operatorid"
. ") AS ilastseenaway" . ") AS ilastseenaway"
: "") : "")
. " FROM {chatgroup} "; . " FROM {opgroup} ";
if ($operator) { if ($operator) {
$query .= ", (SELECT DISTINCT parent " $query .= ", (SELECT DISTINCT parent "
. "FROM {chatgroup}, {chatgroupoperator} " . "FROM {opgroup}, {operatortoopgroup} "
. "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid "
. "AND {chatgroupoperator}.operatorid = :operatorid) i " . "AND {operatortoopgroup}.operatorid = :operatorid) i "
. "WHERE {chatgroup}.groupid = i.parent OR {chatgroup}.parent = i.parent "; . "WHERE {opgroup}.groupid = i.parent OR {opgroup}.parent = i.parent ";
$values[':operatorid'] = $operator['operatorid']; $values[':operatorid'] = $operator['operatorid'];
} }
@ -814,7 +814,7 @@ function get_operator_group_ids($operator_id)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT groupid FROM {chatgroupoperator} WHERE operatorid = ?", "SELECT groupid FROM {operatortoopgroup} WHERE operatorid = ?",
array($operator_id), array($operator_id),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -928,13 +928,13 @@ function update_operator_groups($operator_id, $new_value)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"DELETE FROM {chatgroupoperator} WHERE operatorid = ?", "DELETE FROM {operatortoopgroup} WHERE operatorid = ?",
array($operator_id) array($operator_id)
); );
foreach ($new_value as $group_id) { foreach ($new_value as $group_id) {
$db->query( $db->query(
"INSERT INTO {chatgroupoperator} (groupid, operatorid) VALUES (?,?)", "INSERT INTO {operatortoopgroup} (groupid, operatorid) VALUES (?,?)",
array($group_id, $operator_id) array($group_id, $operator_id)
); );
} }

View File

@ -48,7 +48,7 @@ function get_by_date_statistics($start, $end)
. "usermessages AS users, " . "usermessages AS users, "
. "averagewaitingtime AS avgwaitingtime, " . "averagewaitingtime AS avgwaitingtime, "
. "averagechattime AS avgchattime " . "averagechattime AS avgchattime "
. "FROM {chatthreadstatistics} s " . "FROM {threadstatistics} s "
. "WHERE s.date >= :start " . "WHERE s.date >= :start "
. "AND s.date < :end " . "AND s.date < :end "
. "GROUP BY DATE(FROM_UNIXTIME(date)) " . "GROUP BY DATE(FROM_UNIXTIME(date)) "
@ -73,7 +73,7 @@ function get_by_date_statistics($start, $end)
. "SUM(usermessages) AS users, " . "SUM(usermessages) AS users, "
. "ROUND(SUM(averagewaitingtime * s.threads) / SUM(s.threads),1) AS avgwaitingtime, " . "ROUND(SUM(averagewaitingtime * s.threads) / SUM(s.threads),1) AS avgwaitingtime, "
. "ROUND(SUM(averagechattime * s.threads) / SUM(s.threads),1) AS avgchattime " . "ROUND(SUM(averagechattime * s.threads) / SUM(s.threads),1) AS avgchattime "
. "FROM {chatthreadstatistics} s " . "FROM {threadstatistics} s "
. "WHERE s.date >= :start " . "WHERE s.date >= :start "
. "AND s.date < :end"), . "AND s.date < :end"),
array( array(
@ -111,7 +111,7 @@ function get_by_operator_statistics($start, $end)
. "SUM(acceptedinvitations) AS acceptedinvitations, " . "SUM(acceptedinvitations) AS acceptedinvitations, "
. "SUM(rejectedinvitations) AS rejectedinvitations, " . "SUM(rejectedinvitations) AS rejectedinvitations, "
. "SUM(ignoredinvitations) AS ignoredinvitations " . "SUM(ignoredinvitations) AS ignoredinvitations "
. "FROM {chatoperatorstatistics} s, {chatoperator} o " . "FROM {operatorstatistics} s, {operator} o "
. "WHERE s.operatorid = o.operatorid " . "WHERE s.operatorid = o.operatorid "
. "AND s.date >= :start " . "AND s.date >= :start "
. "AND s.date < :end " . "AND s.date < :end "
@ -172,7 +172,7 @@ function calculate_thread_statistics()
// Get last record date // Get last record date
$result = $db->query( $result = $db->query(
"SELECT MAX(date) as start FROM {chatthreadstatistics}", "SELECT MAX(date) as start FROM {threadstatistics}",
array(), array(),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -196,12 +196,12 @@ function calculate_thread_statistics()
. "ABS(tmp.last_msg_time - t.dtmchatstarted) + " . "ABS(tmp.last_msg_time - t.dtmchatstarted) + "
. "(tmp.last_msg_time - t.dtmchatstarted) " . "(tmp.last_msg_time - t.dtmchatstarted) "
. ")/2,1) AS avg_chat_time " . ")/2,1) AS avg_chat_time "
. "FROM {chatthread} t, " . "FROM {thread} t, "
. "(SELECT SUM(m.ikind = :kind_agent) AS operator_msgs, " . "(SELECT SUM(m.ikind = :kind_agent) AS operator_msgs, "
. "SUM(m.ikind = :kind_user) AS user_msgs, " . "SUM(m.ikind = :kind_user) AS user_msgs, "
. "MAX(m.dtmcreated) as last_msg_time, " . "MAX(m.dtmcreated) as last_msg_time, "
. "threadid " . "threadid "
. "FROM {chatmessage} m " . "FROM {message} m "
// Calculate only users' and operators' messages // Calculate only users' and operators' messages
. "WHERE m.ikind = :kind_user " . "WHERE m.ikind = :kind_user "
. "OR m.ikind = :kind_agent " . "OR m.ikind = :kind_agent "
@ -240,7 +240,7 @@ function calculate_thread_statistics()
$db_results = $db->query( $db_results = $db->query(
("SELECT (FLOOR(dtmcreated / :interval) * :interval) AS date, " ("SELECT (FLOOR(dtmcreated / :interval) * :interval) AS date, "
. "COUNT(*) as missed_threads " . "COUNT(*) as missed_threads "
. "FROM {chatthread} " . "FROM {thread} "
. "WHERE (dtmcreated - :start) > :interval " . "WHERE (dtmcreated - :start) > :interval "
// Calculate statistics only for threads that older than // Calculate statistics only for threads that older than
// statistics_aggregation_interval // statistics_aggregation_interval
@ -270,7 +270,7 @@ function calculate_thread_statistics()
$db_results = $db->query( $db_results = $db->query(
("SELECT (FLOOR(dtmcreated / :interval) * :interval) AS date, " ("SELECT (FLOOR(dtmcreated / :interval) * :interval) AS date, "
. "ROUND(AVG(dtmchatstarted-dtmcreated),1) AS avg_waiting_time " . "ROUND(AVG(dtmchatstarted-dtmcreated),1) AS avg_waiting_time "
. "FROM {chatthread} " . "FROM {thread} "
. "WHERE (dtmcreated - :start) > :interval " . "WHERE (dtmcreated - :start) > :interval "
// Calculate statistics only for threads that older than // Calculate statistics only for threads that older than
// statistics_aggregation_interval // statistics_aggregation_interval
@ -303,7 +303,7 @@ function calculate_thread_statistics()
. "SUM(invitationstate = :invitation_accepted) AS invitations_accepted, " . "SUM(invitationstate = :invitation_accepted) AS invitations_accepted, "
. "SUM(invitationstate = :invitation_rejected) AS invitations_rejected, " . "SUM(invitationstate = :invitation_rejected) AS invitations_rejected, "
. "SUM(invitationstate = :invitation_ignored) AS invitations_ignored " . "SUM(invitationstate = :invitation_ignored) AS invitations_ignored "
. "FROM {chatthread} " . "FROM {thread} "
. "WHERE (dtmcreated - :start) > :interval " . "WHERE (dtmcreated - :start) > :interval "
// Calculate statistics only for threads that older than // Calculate statistics only for threads that older than
// statistics_aggregation_interval // statistics_aggregation_interval
@ -356,7 +356,7 @@ function calculate_thread_statistics()
// Store data in database // Store data in database
$db->query( $db->query(
("INSERT INTO {chatthreadstatistics} (" ("INSERT INTO {threadstatistics} ("
. "date, threads, missedthreads, sentinvitations, " . "date, threads, missedthreads, sentinvitations, "
. "acceptedinvitations, rejectedinvitations, " . "acceptedinvitations, rejectedinvitations, "
. "ignoredinvitations, operatormessages, usermessages, " . "ignoredinvitations, operatormessages, usermessages, "
@ -408,7 +408,7 @@ function calculate_operator_statistics()
// Get last record date // Get last record date
$result = $db->query( $result = $db->query(
"SELECT MAX(date) as start FROM {chatoperatorstatistics}", "SELECT MAX(date) as start FROM {operatorstatistics}",
array(), array(),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -424,10 +424,10 @@ function calculate_operator_statistics()
. "COUNT(distinct m.threadid) AS threads, " . "COUNT(distinct m.threadid) AS threads, "
. "COUNT(m.messageid) AS messages, " . "COUNT(m.messageid) AS messages, "
. "AVG(CHAR_LENGTH(m.tmessage)) AS avg_msg_length " . "AVG(CHAR_LENGTH(m.tmessage)) AS avg_msg_length "
// Use {chatmessage} as base table because of one thread can // Use {message} as base table because of one thread can
// be related with more than one operator (they can change each // be related with more than one operator (they can change each
// other during conversation). // other during conversation).
. "FROM {chatmessage} m, {chatthread} t " . "FROM {message} m, {thread} t "
. "WHERE m.ikind = :kind_agent " . "WHERE m.ikind = :kind_agent "
. "AND m.threadid = t.threadid " . "AND m.threadid = t.threadid "
. "AND (m.dtmcreated - :start) > :interval " . "AND (m.dtmcreated - :start) > :interval "
@ -464,7 +464,7 @@ function calculate_operator_statistics()
. "SUM(invitationstate = :invitation_accepted) AS invitations_accepted, " . "SUM(invitationstate = :invitation_accepted) AS invitations_accepted, "
. "SUM(invitationstate = :invitation_rejected) AS invitations_rejected, " . "SUM(invitationstate = :invitation_rejected) AS invitations_rejected, "
. "SUM(invitationstate = :invitation_ignored) AS invitations_ignored " . "SUM(invitationstate = :invitation_ignored) AS invitations_ignored "
. "FROM {chatthread} " . "FROM {thread} "
. "WHERE (dtmcreated - :start) > :interval " . "WHERE (dtmcreated - :start) > :interval "
// Calculate statistics only for threads that older than // Calculate statistics only for threads that older than
// statistics_aggregation_interval // statistics_aggregation_interval
@ -516,7 +516,7 @@ function calculate_operator_statistics()
} }
$db->query( $db->query(
("INSERT INTO {chatoperatorstatistics} (" ("INSERT INTO {operatorstatistics} ("
. "date, operatorid, threads, messages, averagelength, " . "date, operatorid, threads, messages, averagelength, "
. "sentinvitations, acceptedinvitations, " . "sentinvitations, acceptedinvitations, "
. "rejectedinvitations, ignoredinvitations " . "rejectedinvitations, ignoredinvitations "
@ -608,11 +608,11 @@ function calculate_page_statistics()
("SELECT FLOOR(p.visittime / :interval) * :interval AS date, " ("SELECT FLOOR(p.visittime / :interval) * :interval AS date, "
. "p.address AS address, " . "p.address AS address, "
. "COUNT(DISTINCT t.threadid) AS chats " . "COUNT(DISTINCT t.threadid) AS chats "
. "FROM {visitedpage} p, {chatthread} t, " . "FROM {visitedpage} p, {thread} t, "
. "(SELECT " . "(SELECT "
. "COUNT(*) AS msgs, " . "COUNT(*) AS msgs, "
. "m.threadid " . "m.threadid "
. "FROM {chatmessage} m " . "FROM {message} m "
. "WHERE m.ikind = :kind_user OR m.ikind = :kind_agent " . "WHERE m.ikind = :kind_user OR m.ikind = :kind_agent "
. "GROUP BY m.threadid) tmp " . "GROUP BY m.threadid) tmp "
. "WHERE t.referer = p.address " . "WHERE t.referer = p.address "
@ -651,7 +651,7 @@ function calculate_page_statistics()
("SELECT FLOOR(p.visittime / :interval) * :interval AS date, " ("SELECT FLOOR(p.visittime / :interval) * :interval AS date, "
. "p.address AS address, " . "p.address AS address, "
. "COUNT(DISTINCT t.threadid) AS invitations_accepted " . "COUNT(DISTINCT t.threadid) AS invitations_accepted "
. "FROM {visitedpage} p, {chatthread} t " . "FROM {visitedpage} p, {thread} t "
. "WHERE t.referer = p.address " . "WHERE t.referer = p.address "
. "AND p.calculated = 0 " . "AND p.calculated = 0 "
. "AND (p.visittime - :start) > :interval " . "AND (p.visittime - :start) > :interval "
@ -681,7 +681,7 @@ function calculate_page_statistics()
("SELECT FLOOR(p.visittime / :interval) * :interval AS date, " ("SELECT FLOOR(p.visittime / :interval) * :interval AS date, "
. "p.address AS address, " . "p.address AS address, "
. "COUNT(DISTINCT t.threadid) AS invitations_rejected " . "COUNT(DISTINCT t.threadid) AS invitations_rejected "
. "FROM {visitedpage} p, {chatthread} t " . "FROM {visitedpage} p, {thread} t "
. "WHERE t.referer = p.address " . "WHERE t.referer = p.address "
. "AND p.calculated = 0 " . "AND p.calculated = 0 "
. "AND (p.visittime - :start) > :interval " . "AND (p.visittime - :start) > :interval "
@ -711,7 +711,7 @@ function calculate_page_statistics()
("SELECT FLOOR(p.visittime / :interval) * :interval AS date, " ("SELECT FLOOR(p.visittime / :interval) * :interval AS date, "
. "p.address AS address, " . "p.address AS address, "
. "COUNT(DISTINCT t.threadid) AS invitations_ignored " . "COUNT(DISTINCT t.threadid) AS invitations_ignored "
. "FROM {visitedpage} p, {chatthread} t " . "FROM {visitedpage} p, {thread} t "
. "WHERE t.referer = p.address " . "WHERE t.referer = p.address "
. "AND p.calculated = 0 " . "AND p.calculated = 0 "
. "AND (p.visittime - :start) > :interval " . "AND (p.visittime - :start) > :interval "

View File

@ -31,7 +31,7 @@ function track_visitor($visitor_id, $entry, $referer)
} else { } else {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"UPDATE {chatsitevisitor} SET lasttime = :now WHERE visitorid = :visitorid", "UPDATE {sitevisitor} SET lasttime = :now WHERE visitorid = :visitorid",
array( array(
':visitorid' => $visitor['visitorid'], ':visitorid' => $visitor['visitorid'],
':now' => time(), ':now' => time(),
@ -49,7 +49,7 @@ function track_visitor_start($entry, $referer)
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
("INSERT INTO {chatsitevisitor} ( " ("INSERT INTO {sitevisitor} ( "
. "userid, username, firsttime, lasttime, entry,details " . "userid, username, firsttime, lasttime, entry,details "
. ") VALUES ( " . ") VALUES ( "
. ":userid, :username, :now, :now, :entry, :details " . ":userid, :username, :now, :now, :entry, :details "
@ -77,7 +77,7 @@ function track_get_visitor_by_id($visitor_id)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT * FROM {chatsitevisitor} WHERE visitorid = ?", "SELECT * FROM {sitevisitor} WHERE visitorid = ?",
array($visitor_id), array($visitor_id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -88,7 +88,7 @@ function track_get_visitor_by_thread_id($thread_id)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT * FROM {chatsitevisitor} WHERE threadid = ?", "SELECT * FROM {sitevisitor} WHERE threadid = ?",
array($thread_id), array($thread_id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -105,7 +105,7 @@ function track_get_visitor_by_user_id($user_id)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"SELECT * FROM {chatsitevisitor} WHERE userid = ?", "SELECT * FROM {sitevisitor} WHERE userid = ?",
array($user_id), array($user_id),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -183,17 +183,17 @@ function track_remove_old_visitors()
// Remove associations of visitors with closed threads // Remove associations of visitors with closed threads
$db->query( $db->query(
"UPDATE {chatsitevisitor} SET threadid = NULL " "UPDATE {sitevisitor} SET threadid = NULL "
. "WHERE threadid IS NOT NULL AND " . "WHERE threadid IS NOT NULL AND "
. "(SELECT count(*) FROM {chatthread} " . "(SELECT count(*) FROM {thread} "
. "WHERE threadid = {chatsitevisitor}.threadid " . "WHERE threadid = {sitevisitor}.threadid "
. "AND istate <> " . Thread::STATE_CLOSED . " " . "AND istate <> " . Thread::STATE_CLOSED . " "
. "AND istate <> " . Thread::STATE_LEFT . ") = 0 " . "AND istate <> " . Thread::STATE_LEFT . ") = 0 "
); );
// Remove old visitors // Remove old visitors
$db->query( $db->query(
("DELETE FROM {chatsitevisitor} " ("DELETE FROM {sitevisitor} "
. "WHERE (:now - lasttime) > :lifetime " . "WHERE (:now - lasttime) > :lifetime "
. "AND threadid IS NULL"), . "AND threadid IS NULL"),
array( array(
@ -216,7 +216,7 @@ function track_remove_old_tracks()
. "WHERE (:now - visittime) > :lifetime " . "WHERE (:now - visittime) > :lifetime "
// Remove only tracks that are included in statistics // Remove only tracks that are included in statistics
. "AND calculated = 1 " . "AND calculated = 1 "
. "AND visitorid NOT IN (SELECT visitorid FROM {chatsitevisitor}) "), . "AND visitorid NOT IN (SELECT visitorid FROM {sitevisitor}) "),
array( array(
':lifetime' => Settings::get('tracking_lifetime'), ':lifetime' => Settings::get('tracking_lifetime'),
':now' => time(), ':now' => time(),
@ -244,7 +244,7 @@ function track_get_user_id($visitor_id)
/** /**
* Bind chat thread with visitor * Bind chat thread with visitor
* *
* @param string $user_id User ID ({chatsitevisitor}.userid field) of the * @param string $user_id User ID ({sitevisitor}.userid field) of the
* visitor. * visitor.
* @param Thread $thread Chat thread object * @param Thread $thread Chat thread object
*/ */
@ -252,7 +252,7 @@ function track_visitor_bind_thread($user_id, $thread)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
('UPDATE {chatsitevisitor} ' ('UPDATE {sitevisitor} '
. 'SET threadid = :thread_id ' . 'SET threadid = :thread_id '
. 'WHERE userid = :user_id'), . 'WHERE userid = :user_id'),
array( array(