diff --git a/src/mibew/configs/database_schema.yml b/src/mibew/configs/database_schema.yml index 3c7d447b..da64fb30 100644 --- a/src/mibew/configs/database_schema.yml +++ b/src/mibew/configs/database_schema.yml @@ -1,8 +1,9 @@ # 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! -# Contains information about chat groups -chatgroup: +# Contains information about chat groups. This table cannot be named just +# "group" because it is reserved SQL word. +opgroup: fields: groupid: "int NOT NULL auto_increment PRIMARY KEY" parent: "int DEFAULT NULL" @@ -20,13 +21,13 @@ chatgroup: parent: [parent] # Contains info about chat threads -chatthread: +thread: fields: # ID of the thread. threadid: "int NOT NULL auto_increment PRIMARY KEY" # Name of the user in chat. 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)" # Name of the operator who took place in the chat. agentname: "varchar(64)" @@ -72,10 +73,10 @@ chatthread: # Total count of user's messages related with the thread. messagecount: "varchar(16)" # 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 -chatthreadstatistics: +threadstatistics: fields: statid: "int NOT NULL auto_increment PRIMARY KEY" date: "int NOT NULL DEFAULT 0" @@ -142,12 +143,12 @@ mailtemplate: body: "text" # Store chat thread messages -chatmessage: +message: fields: # Message ID. messageid: "int NOT NULL auto_increment PRIMARY KEY" # 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. ikind: "int NOT NULL" # ID of operator who sent the message. This value will be ignored for @@ -168,7 +169,7 @@ chatmessage: idx_agentid: [agentid] # Contains info about operators -chatoperator: +operator: fields: operatorid: "int NOT NULL auto_increment PRIMARY KEY" vclogin: "varchar(64) NOT NULL" @@ -190,7 +191,7 @@ chatoperator: code: "varchar(64) DEFAULT ''" # Contains "by operator" statistics -chatoperatorstatistics: +operatorstatistics: fields: statid: "int NOT NULL auto_increment PRIMARY KEY" date: "int NOT NULL DEFAULT 0" @@ -205,21 +206,21 @@ chatoperatorstatistics: indexes: operatorid: [operatorid] -chatrevision: +revision: fields: id: "INT NOT NULL" # Contains relations between operators and groups -chatgroupoperator: +operatortoopgroup: fields: - groupid: "int NOT NULL references {chatgroup}(groupid)" - operatorid: "int NOT NULL references {chatoperator}(operatorid)" + groupid: "int NOT NULL references {opgroup}(groupid)" + operatorid: "int NOT NULL references {operator}(operatorid)" indexes: groupid: [groupid] operatorid: [operatorid] # Contains banned visitors -chatban: +ban: fields: banid: "INT NOT NULL auto_increment PRIMARY KEY" dtmcreated: "int NOT NULL DEFAULT 0" @@ -229,22 +230,22 @@ chatban: blockedcount: "int DEFAULT 0" # Contains dynamic configs -chatconfig: +config: fields: id: "INT NOT NULL auto_increment PRIMARY KEY" vckey: "varchar(255)" vcvalue: "varchar(255)" # Contains canned messages -chatresponses: +cannedmessage: fields: id: "INT NOT NULL auto_increment PRIMARY KEY" locale: "varchar(8)" - groupid: "int references {chatgroup}(groupid)" + groupid: "int references {opgroup}(groupid)" vctitle: "varchar(100) NOT NULL DEFAULT ''" vcvalue: "varchar(1024) NOT NULL" -chatsitevisitor: +sitevisitor: fields: visitorid: "INT NOT NULL auto_increment PRIMARY KEY" userid: "varchar(255) NOT NULL" @@ -255,7 +256,7 @@ chatsitevisitor: details: "text NOT NULL" invitations: "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: threadid: [threadid] diff --git a/src/mibew/libs/canned.php b/src/mibew/libs/canned.php index 73a90225..f0d0d431 100644 --- a/src/mibew/libs/canned.php +++ b/src/mibew/libs/canned.php @@ -36,7 +36,7 @@ function load_canned_messages($locale, $group_id) } return $db->query( - ("SELECT id, vctitle, vcvalue FROM {chatresponses} " + ("SELECT id, vctitle, vcvalue FROM {cannedmessage} " . "WHERE locale = :locale AND (" . ($group_id ? "groupid = :groupid" : "groupid is NULL OR groupid = 0") . ") ORDER BY vcvalue"), @@ -57,7 +57,7 @@ function load_canned_message($key) { $db = Database::getInstance(); $result = $db->query( - "SELECT vctitle, vcvalue FROM {chatresponses} WHERE id = ?", + "SELECT vctitle, vcvalue FROM {cannedmessage} WHERE id = ?", array($key), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -76,7 +76,7 @@ function save_canned_message($key, $title, $message) { $db = Database::getInstance(); $db->query( - "UPDATE {chatresponses} SET vcvalue = ?, vctitle = ? WHERE id = ?", + "UPDATE {cannedmessage} SET vcvalue = ?, vctitle = ? WHERE id = ?", array($message, $title, $key) ); } @@ -93,7 +93,7 @@ function add_canned_message($locale, $group_id, $title, $message) { $db = Database::getInstance(); $db->query( - ("INSERT INTO {chatresponses} (locale,groupid,vctitle,vcvalue) " + ("INSERT INTO {cannedmessage} (locale,groupid,vctitle,vcvalue) " . "VALUES (?, ?, ?, ?)"), array( $locale, diff --git a/src/mibew/libs/chat.php b/src/mibew/libs/chat.php index a903d363..86e9ad3d 100644 --- a/src/mibew/libs/chat.php +++ b/src/mibew/libs/chat.php @@ -643,7 +643,7 @@ function ban_for_addr($addr) { $db = Database::getInstance(); 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( ':addr' => $addr, ':now' => time(), diff --git a/src/mibew/libs/classes/Mibew/Controller/BanController.php b/src/mibew/libs/classes/Mibew/Controller/BanController.php index 7cbf671a..55c38af8 100644 --- a/src/mibew/libs/classes/Mibew/Controller/BanController.php +++ b/src/mibew/libs/classes/Mibew/Controller/BanController.php @@ -46,7 +46,7 @@ class BanController extends AbstractController // Prepare list of all banned visitors $db = Database::getInstance(); $blocked_list = $db->query( - "SELECT banid, dtmtill AS till, address, comment FROM {chatban}", + "SELECT banid, dtmtill AS till, address, comment FROM {ban}", null, array('return_rows' => Database::RETURN_ALL_ROWS) ); @@ -80,7 +80,7 @@ class BanController extends AbstractController // Remove ban from database $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 return $this->redirect($this->generateUrl('bans')); @@ -119,7 +119,7 @@ class BanController extends AbstractController $db = Database::getInstance(); $ban = $db->query( ("SELECT banid, (dtmtill - :now) AS days, address, comment " - . "FROM {chatban} WHERE banid = :banid"), + . "FROM {ban} WHERE banid = :banid"), array( ':banid' => $ban_id, ':now' => time(), @@ -229,7 +229,7 @@ class BanController extends AbstractController $till_time = $now + $days * 24 * 60 * 60; if (!$ban_id) { $db->query( - ("INSERT INTO {chatban} (dtmcreated, dtmtill, address, comment) " + ("INSERT INTO {ban} (dtmcreated, dtmtill, address, comment) " . "VALUES (:now,:till,:address,:comment)"), array( ':now' => $now, @@ -240,7 +240,7 @@ class BanController extends AbstractController ); } else { $db->query( - ("UPDATE {chatban} SET dtmtill = :till, address = :address, " + ("UPDATE {ban} SET dtmtill = :till, address = :address, " . "comment = :comment WHERE banid = :banid"), array( ':till' => $till_time, diff --git a/src/mibew/libs/classes/Mibew/Controller/CannedMessageController.php b/src/mibew/libs/classes/Mibew/Controller/CannedMessageController.php index 69a47ca1..e7b2418a 100644 --- a/src/mibew/libs/classes/Mibew/Controller/CannedMessageController.php +++ b/src/mibew/libs/classes/Mibew/Controller/CannedMessageController.php @@ -123,7 +123,7 @@ class CannedMessageController extends AbstractController $db = Database::getInstance(); $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" // get params for the target URL. diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php index 55f81a69..ca12ada7 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php @@ -203,7 +203,7 @@ class RedirectController extends AbstractController $db = Database::getInstance(); list($groups_count) = $db->query( ("SELECT count(*) AS count " - . "FROM {chatgroupoperator} " + . "FROM {operatortoopgroup} " . "WHERE operatorid = ? AND groupid = ?"), array($operator_id, $thread->groupId), array( diff --git a/src/mibew/libs/classes/Mibew/Controller/Group/ManagementController.php b/src/mibew/libs/classes/Mibew/Controller/Group/ManagementController.php index 7c3b02dc..dd23ad2a 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Group/ManagementController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Group/ManagementController.php @@ -97,9 +97,9 @@ class ManagementController extends AbstractController // Remove the group and all its relations. $group_id = $request->attributes->getInt('group_id'); - $db->query("DELETE FROM {chatgroup} WHERE groupid = ?", array($group_id)); - $db->query("DELETE FROM {chatgroupoperator} WHERE groupid = ?", array($group_id)); - $db->query("UPDATE {chatthread} SET groupid = 0 WHERE groupid = ?", array($group_id)); + $db->query("DELETE FROM {opgroup} WHERE groupid = ?", array($group_id)); + $db->query("DELETE FROM {operatortoopgroup} 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 // "sortdirection" get params for the target URL. diff --git a/src/mibew/libs/classes/Mibew/Controller/HistoryController.php b/src/mibew/libs/classes/Mibew/Controller/HistoryController.php index 922a6fb6..6d32edf4 100644 --- a/src/mibew/libs/classes/Mibew/Controller/HistoryController.php +++ b/src/mibew/libs/classes/Mibew/Controller/HistoryController.php @@ -50,8 +50,8 @@ class HistoryController extends AbstractController if ($query !== false) { $db = Database::getInstance(); $groups = $db->query( - ("SELECT {chatgroup}.groupid AS groupid, vclocalname " . - "FROM {chatgroup} " . + ("SELECT {opgroup}.groupid AS groupid, vclocalname " . + "FROM {opgroup} " . "ORDER BY vclocalname"), null, array('return_rows' => Database::RETURN_ALL_ROWS) @@ -70,10 +70,10 @@ class HistoryController extends AbstractController $search_conditions = array(); if ($search_type == 'message' || $search_type == 'all') { - $search_conditions[] = "({chatmessage}.tmessage LIKE :query" + $search_conditions[] = "({message}.tmessage LIKE :query" . ($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) { $values[':kind_user'] = Thread::KIND_USER; @@ -81,20 +81,20 @@ class HistoryController extends AbstractController } } 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') { - $search_conditions[] = "({chatthread}.username LIKE :query)"; - $search_conditions[] = "({chatthread}.remote LIKE :query)"; + $search_conditions[] = "({thread}.username LIKE :query)"; + $search_conditions[] = "({thread}.remote LIKE :query)"; } // Load threads list($threads_count) = $db->query( - ("SELECT COUNT(DISTINCT {chatthread}.dtmcreated) " - . "FROM {chatthread}, {chatmessage} " - . "WHERE {chatmessage}.threadid = {chatthread}.threadid " - . "AND ({chatthread}.invitationstate = :invitation_accepted " - . "OR {chatthread}.invitationstate = :invitation_not_invited) " + ("SELECT COUNT(DISTINCT {thread}.dtmcreated) " + . "FROM {thread}, {message} " + . "WHERE {message}.threadid = {thread}.threadid " + . "AND ({thread}.invitationstate = :invitation_accepted " + . "OR {thread}.invitationstate = :invitation_not_invited) " . "AND (" . implode(' OR ', $search_conditions) . ")"), $values, array( @@ -112,13 +112,13 @@ class HistoryController extends AbstractController $limit_end = intval($pagination_info['end'] - $pagination_info['start']); $threads_list = $db->query( - ("SELECT DISTINCT {chatthread}.* " - . "FROM {chatthread}, {chatmessage} " - . "WHERE {chatmessage}.threadid = {chatthread}.threadid " - . "AND ({chatthread}.invitationstate = :invitation_accepted " - . "OR {chatthread}.invitationstate = :invitation_not_invited) " + ("SELECT DISTINCT {thread}.* " + . "FROM {thread}, {message} " + . "WHERE {message}.threadid = {thread}.threadid " + . "AND ({thread}.invitationstate = :invitation_accepted " + . "OR {thread}.invitationstate = :invitation_not_invited) " . "AND (" . implode(' OR ', $search_conditions) . ") " - . "ORDER BY {chatthread}.dtmcreated DESC " + . "ORDER BY {thread}.dtmcreated DESC " . "LIMIT " . $limit_start . ", " . $limit_end), $values, array('return_rows' => Database::RETURN_ALL_ROWS) @@ -219,8 +219,8 @@ class HistoryController extends AbstractController if (!empty($user_id)) { $db = Database::getInstance(); - $query = "SELECT {chatthread}.* " - . "FROM {chatthread} " + $query = "SELECT {thread}.* " + . "FROM {thread} " . "WHERE userid=:user_id " . "AND (invitationstate = :invitation_accepted " . "OR invitationstate = :invitation_not_invited) " diff --git a/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php b/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php index 61ab9674..6266df13 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php @@ -170,7 +170,7 @@ class ManagementController extends AbstractController // Disable the operator $db = Database::getInstance(); $db->query( - "update {chatoperator} set idisabled = ? where operatorid = ?", + "update {operator} set idisabled = ? where operatorid = ?", array('1', $operator_id) ); @@ -198,7 +198,7 @@ class ManagementController extends AbstractController $db = Database::getInstance(); $db->query( - "update {chatoperator} set idisabled = ? where operatorid = ?", + "update {operator} set idisabled = ? where operatorid = ?", array('0', $operator_id) ); diff --git a/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php b/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php index d7fa8369..b0d1be5b 100644 --- a/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php +++ b/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php @@ -72,7 +72,7 @@ class PasswordRecoveryController extends AbstractController $db = Database::getInstance(); $db->query( - ("UPDATE {chatoperator} " + ("UPDATE {operator} " . "SET dtmrestore = :now, vcrestoretoken = :token " . "WHERE operatorid = :operatorid"), array( @@ -178,7 +178,7 @@ class PasswordRecoveryController extends AbstractController $db = Database::getInstance(); $db->query( - ("UPDATE {chatoperator} " + ("UPDATE {operator} " . "SET vcpassword = ?, vcrestoretoken = '' " . "WHERE operatorid = ?"), array( diff --git a/src/mibew/libs/classes/Mibew/Installer.php b/src/mibew/libs/classes/Mibew/Installer.php index e9e0b483..d3b56021 100644 --- a/src/mibew/libs/classes/Mibew/Installer.php +++ b/src/mibew/libs/classes/Mibew/Installer.php @@ -217,7 +217,7 @@ class Installer try { $db->query( - 'UPDATE {chatoperator} SET vcpassword = :pass WHERE vclogin = :login', + 'UPDATE {operator} SET vcpassword = :pass WHERE vclogin = :login', array( ':login' => 'admin', ':pass' => calculate_password_hash('admin', $password) @@ -341,7 +341,7 @@ class Installer // Create The First Administrator if needed try { list($count) = $db->query( - 'SELECT COUNT(*) FROM {chatoperator} WHERE vclogin = :login', + 'SELECT COUNT(*) FROM {operator} WHERE vclogin = :login', array(':login' => 'admin'), array( 'return_rows' => Database::RETURN_ONE_ROW, @@ -350,7 +350,7 @@ class Installer ); if ($count == 0) { $db->query( - ('INSERT INTO {chatoperator} ( ' + ('INSERT INTO {operator} ( ' . 'vclogin, vcpassword, vclocalename, vccommonname, ' . 'vcavatar, vcemail, iperm ' . ') values ( ' @@ -379,7 +379,7 @@ class Installer // Initialize chat revision counter if it is needed try { list($count) = $db->query( - 'SELECT COUNT(*) FROM {chatrevision}', + 'SELECT COUNT(*) FROM {revision}', null, array( 'return_rows' => Database::RETURN_ONE_ROW, @@ -388,7 +388,7 @@ class Installer ); if ($count == 0) { $db->query( - 'INSERT INTO {chatrevision} VALUES (:init_revision)', + 'INSERT INTO {revision} VALUES (:init_revision)', array(':init_revision' => 1) ); } @@ -404,7 +404,7 @@ class Installer // Set correct database structure version if needed try { list($count) = $db->query( - 'SELECT COUNT(*) FROM {chatconfig} WHERE vckey = :key', + 'SELECT COUNT(*) FROM {config} WHERE vckey = :key', array(':key' => 'dbversion'), array( 'return_rows' => Database::RETURN_ONE_ROW, @@ -413,7 +413,7 @@ class Installer ); if ($count == 0) { $db->query( - 'INSERT INTO {chatconfig} (vckey, vcvalue) VALUES (:key, :value)', + 'INSERT INTO {config} (vckey, vcvalue) VALUES (:key, :value)', array( ':key' => 'dbversion', ':value' => DB_VERSION, @@ -538,7 +538,7 @@ class Installer try { $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('return_rows' => Database::RETURN_ONE_ROW) ); diff --git a/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php b/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php index 82d12c87..232e2e7a 100644 --- a/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php +++ b/src/mibew/libs/classes/Mibew/RequestProcessor/UsersProcessor.php @@ -179,7 +179,7 @@ class UsersProcessor extends ClientSideProcessor $query = "SELECT t.*, " . " g.vclocalname AS group_localname, " . " 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 " . " WHERE t.lrevision > :since " . " AND t.istate <> " . Thread::STATE_INVITED @@ -196,7 +196,7 @@ class UsersProcessor extends ClientSideProcessor // If groups are enabled select only threads with empty groupid // or groups related to current operator ? " 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)) " : "") . ") " : "" @@ -279,7 +279,7 @@ class UsersProcessor extends ClientSideProcessor $first_message = null; if ($thread->shownMessageId != 0) { $line = $db->query( - "SELECT tmessage FROM {chatmessage} WHERE messageid = ? LIMIT 1", + "SELECT tmessage FROM {message} WHERE messageid = ? LIMIT 1", array($thread->shownMessageId), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -398,8 +398,8 @@ class UsersProcessor extends ClientSideProcessor . "t.agentId AS invitedby, " . "v.invitations, " . "v.chats " - . "FROM {chatsitevisitor} v " - . "LEFT OUTER JOIN {chatthread} t " + . "FROM {sitevisitor} v " + . "LEFT OUTER JOIN {thread} t " . "ON t.threadid = v.threadid " . "WHERE v.threadid IS NULL " . "OR (t.istate = :state_invited " diff --git a/src/mibew/libs/classes/Mibew/Settings.php b/src/mibew/libs/classes/Mibew/Settings.php index dcf3003a..15896971 100644 --- a/src/mibew/libs/classes/Mibew/Settings.php +++ b/src/mibew/libs/classes/Mibew/Settings.php @@ -117,7 +117,7 @@ class Settings // Load values from database $db = Database::getInstance(); $rows = $db->query( - "SELECT vckey, vcvalue FROM {chatconfig}", + "SELECT vckey, vcvalue FROM {config}", null, array('return_rows' => Database::RETURN_ALL_ROWS) ); @@ -164,12 +164,12 @@ class Settings foreach ($instance->settings as $key => $value) { if (!isset($instance->settingsInDb[$key])) { $db->query( - "INSERT INTO {chatconfig} (vckey) VALUES (?)", + "INSERT INTO {config} (vckey) VALUES (?)", array($key) ); } $db->query( - "UPDATE {chatconfig} SET vcvalue=? WHERE vckey=?", + "UPDATE {config} SET vcvalue=? WHERE vckey=?", array($value, $key) ); } diff --git a/src/mibew/libs/classes/Mibew/Thread.php b/src/mibew/libs/classes/Mibew/Thread.php index 52425815..69ef0d56 100644 --- a/src/mibew/libs/classes/Mibew/Thread.php +++ b/src/mibew/libs/classes/Mibew/Thread.php @@ -129,7 +129,7 @@ class Thread /** * 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 * are stored in the Thread::$threadInfo array. * @@ -230,7 +230,7 @@ class Thread $thread = new self(); // Create thread - $db->query("insert into {chatthread} (threadid) values (NULL)"); + $db->query("insert into {thread} (threadid) values (NULL)"); // Set thread Id // In this case Thread::$threadInfo array use because id of a thread @@ -300,7 +300,7 @@ class Thread // Load thread $thread_info = $db->query( - "SELECT * FROM {chatthread} WHERE threadid = :threadid", + "SELECT * FROM {thread} WHERE threadid = :threadid", array(':threadid' => $id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -381,7 +381,7 @@ class Thread $db = Database::getInstance(); - $query = "UPDATE {chatthread} SET " + $query = "UPDATE {thread} SET " . "lrevision = :next_revision, " . "dtmmodified = :now, " . "dtmclosed = :now, " @@ -445,7 +445,7 @@ class Thread $db = Database::getInstance(); $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( $remote, Thread::STATE_CLOSED, @@ -547,7 +547,7 @@ class Thread { $db = Database::getInstance(); $db->query( - "DELETE FROM {chatthread} WHERE threadid = :id LIMIT 1", + "DELETE FROM {thread} WHERE threadid = :id LIMIT 1", array(':id' => $this->id) ); } @@ -672,7 +672,7 @@ class Thread $values[] = $this->threadInfo[$field_db_name]; } - $query = "UPDATE {chatthread} t SET " . implode(', ', $set_clause) + $query = "UPDATE {thread} t SET " . implode(', ', $set_clause) . " WHERE threadid = ?"; $values[] = $this->id; $db->query($query, $values); @@ -765,7 +765,7 @@ class Thread // Load messages $query = "SELECT messageid AS id, ikind AS kind, dtmcreated AS created, " . " tname AS name, tmessage AS message, plugin, data " - . "FROM {chatmessage} " + . "FROM {message} " . "WHERE threadid = :threadid AND messageid > :lastid " . ($is_user ? "AND ikind <> " . self::KIND_FOR_AGENT : "") . " ORDER BY messageid"; @@ -891,8 +891,8 @@ class Thread $db = Database::getInstance(); list($message_count) = $db->query( - ("SELECT COUNT(*) FROM {chatmessage} " - . "WHERE {chatmessage}.threadid = :threadid AND ikind = :kind_user"), + ("SELECT COUNT(*) FROM {message} " + . "WHERE {message}.threadid = :threadid AND ikind = :kind_user"), array( ':threadid' => $this->id, ':kind_user' => Thread::KIND_USER, @@ -1076,7 +1076,7 @@ class Thread $options['data'] = serialize((array) $options['data']); // Prepare query - $query = "INSERT INTO {chatmessage} (" + $query = "INSERT INTO {message} (" . "threadid, ikind, tmessage, tname, agentid, " . "dtmcreated, plugin, data" . ") VALUES (" @@ -1109,7 +1109,7 @@ class Thread protected static function nextRevision() { $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(); return $val; diff --git a/src/mibew/libs/groups.php b/src/mibew/libs/groups.php index e08a520c..b4d5dfbc 100644 --- a/src/mibew/libs/groups.php +++ b/src/mibew/libs/groups.php @@ -33,7 +33,7 @@ function group_by_id($id) { $db = Database::getInstance(); $group = $db->query( - "SELECT * FROM {chatgroup} WHERE groupid = ?", + "SELECT * FROM {opgroup} WHERE groupid = ?", array($id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -55,7 +55,7 @@ function group_by_name($name) { $db = Database::getInstance(); $group = $db->query( - "SELECT * FROM {chatgroup} WHERE vclocalname = ?", + "SELECT * FROM {opgroup} WHERE vclocalname = ?", array($name), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -95,7 +95,7 @@ function get_operator_groups_list($operator_id) if (Settings::get('enablegroups') == '1') { $group_ids = array(0); $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('return_rows' => Database::RETURN_ALL_ROWS) ); @@ -132,8 +132,8 @@ function get_available_parent_groups($skip_group) $db = Database::getInstance(); $groups_list = $db->query( - ("SELECT {chatgroup}.groupid AS groupid, parent, vclocalname " - . "FROM {chatgroup} ORDER BY vclocalname"), + ("SELECT {opgroup}.groupid AS groupid, parent, vclocalname " + . "FROM {opgroup} ORDER BY vclocalname"), null, array('return_rows' => Database::RETURN_ALL_ROWS) ); @@ -160,7 +160,7 @@ function group_has_children($group_id) { $db = Database::getInstance(); $children = $db->query( - "SELECT COUNT(*) AS count FROM {chatgroup} WHERE parent = ?", + "SELECT COUNT(*) AS count FROM {opgroup} WHERE parent = ?", array($group_id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -310,7 +310,7 @@ function create_group($group) $db = Database::getInstance(); $db->query( - ("INSERT INTO {chatgroup} (" + ("INSERT INTO {opgroup} (" . "parent, vclocalname, vclocaldescription, vccommonname, " . "vccommondescription, vcemail, vctitle, vcchattitle, vchosturl, " . "vclogo, iweight" @@ -332,7 +332,7 @@ function create_group($group) $id = $db->insertedId(); $new_group = $db->query( - "SELECT * FROM {chatgroup} WHERE groupid = ?", + "SELECT * FROM {opgroup} WHERE groupid = ?", array($id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -364,7 +364,7 @@ function update_group($group) $db = Database::getInstance(); $db->query( - ("UPDATE {chatgroup} SET " + ("UPDATE {opgroup} SET " . "parent = ?, vclocalname = ?, vclocaldescription = ?, " . "vccommonname = ?, vccommondescription = ?, " . "vcemail = ?, vctitle = ?, vcchattitle = ?, " @@ -388,7 +388,7 @@ function update_group($group) if ($group['parent']) { $db->query( - "UPDATE {chatgroup} SET parent = NULL WHERE parent = ?", + "UPDATE {opgroup} SET parent = NULL WHERE parent = ?", array($group['id']) ); } @@ -405,7 +405,7 @@ function get_group_members($group_id) { $db = Database::getInstance(); return $db->query( - "SELECT operatorid FROM {chatgroupoperator} WHERE groupid = ?", + "SELECT operatorid FROM {operatortoopgroup} WHERE groupid = ?", array($group_id), array('return_rows' => Database::RETURN_ALL_ROWS) ); @@ -421,13 +421,13 @@ function update_group_members($group_id, $new_value) { $db = Database::getInstance(); $db->query( - "DELETE FROM {chatgroupoperator} WHERE groupid = ?", + "DELETE FROM {operatortoopgroup} WHERE groupid = ?", array($group_id) ); foreach ($new_value as $operator_id) { $db->query( - "INSERT INTO {chatgroupoperator} (groupid, operatorid) VALUES (?, ?)", + "INSERT INTO {operatortoopgroup} (groupid, operatorid) VALUES (?, ?)", array($group_id, $operator_id) ); } diff --git a/src/mibew/libs/invitation.php b/src/mibew/libs/invitation.php index 7f13e923..19d4aee0 100644 --- a/src/mibew/libs/invitation.php +++ b/src/mibew/libs/invitation.php @@ -34,7 +34,7 @@ function invitation_state($visitor_id) $db = Database::getInstance(); $db_result = $db->query( ("SELECT t.threadid, t.invitationstate, t.istate " - . "FROM {chatsitevisitor} v, {chatthread} t " + . "FROM {sitevisitor} v, {thread} t " . "WHERE visitorid = ? " . "AND t.threadid = v.threadid"), array($visitor_id), @@ -106,7 +106,7 @@ function invitation_invite($visitor_id, $operator) $db = Database::getInstance(); $db->query( - ("UPDATE {chatsitevisitor} set " + ("UPDATE {sitevisitor} set " . "invitations = invitations + 1, " . "threadid = :thread_id " . "WHERE visitorid = :visitor_id"), @@ -156,7 +156,7 @@ function invitation_accept($visitor_id) // Get thread related with the visitor $db = Database::getInstance(); $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('return_rows' => Database::RETURN_ONE_ROW) ); @@ -180,7 +180,7 @@ function invitation_accept($visitor_id) // Update visitor info $db->query( - ("UPDATE {chatsitevisitor} SET chats = chats + 1 " + ("UPDATE {sitevisitor} SET chats = chats + 1 " . "WHERE visitorid = :visitor_id"), array(':visitor_id' => $visitor_id) ); @@ -208,7 +208,7 @@ function invitation_reject($visitor_id) $db = Database::getInstance(); $db->query( - ("UPDATE {chatsitevisitor} v, {chatthread} t SET " + ("UPDATE {sitevisitor} v, {thread} t SET " . "v.threadid = NULL, " . "t.invitationstate = :invitation_rejected, " . "t.istate = :state_closed, " @@ -233,7 +233,7 @@ function invitation_close_old() // Get all threads to close $threads = $db->query( - ("SELECT * FROM {chatthread} " + ("SELECT * FROM {thread} " . "WHERE istate = :state_invited " . "AND invitationstate = :invitation_wait " . "AND (:now - dtmcreated) > :lifetime"), @@ -248,7 +248,7 @@ function invitation_close_old() // Remove old invitations $db->query( - ("UPDATE {chatsitevisitor} v, {chatthread} t SET " + ("UPDATE {sitevisitor} v, {thread} t SET " . "t.invitationstate = :invitation_ignored, " . "t.istate = :state_closed, " . "t.dtmclosed = :now, " diff --git a/src/mibew/libs/operator.php b/src/mibew/libs/operator.php index fbb02d2a..98d08794 100644 --- a/src/mibew/libs/operator.php +++ b/src/mibew/libs/operator.php @@ -74,7 +74,7 @@ function update_operator_permissions($operator_id, $perm) { $db = Database::getInstance(); $db->query( - "UPDATE {chatoperator} SET iperm = ? WHERE operatorid = ?", + "UPDATE {operator} SET iperm = ? WHERE operatorid = ?", array($perm, $operator_id) ); } @@ -84,7 +84,7 @@ function operator_by_login($login) $db = Database::getInstance(); return $db->query( - "SELECT * FROM {chatoperator} WHERE vclogin = ?", + "SELECT * FROM {operator} WHERE vclogin = ?", array($login), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -95,7 +95,7 @@ function operator_by_email($mail) $db = Database::getInstance(); return $db->query( - "SELECT * FROM {chatoperator} WHERE vcemail = ?", + "SELECT * FROM {operator} WHERE vcemail = ?", array($mail), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -106,7 +106,7 @@ function operator_by_id($id) $db = Database::getInstance(); return $db->query( - "SELECT * FROM {chatoperator} WHERE operatorid = ?", + "SELECT * FROM {operator} WHERE operatorid = ?", array($id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -124,7 +124,7 @@ function operator_by_code($code) $db = Database::getInstance(); return $db->query( - "SELECT * FROM {chatoperator} WHERE code = ?", + "SELECT * FROM {operator} WHERE code = ?", array($code), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -170,7 +170,7 @@ function get_operators_list($options = array()) } $query = "SELECT DISTINCT " - . "{chatoperator}.operatorid, " + . "{operator}.operatorid, " . "vclogin, " . "vclocalename, " . "vccommonname, " @@ -178,16 +178,16 @@ function get_operators_list($options = array()) . "istatus, " . "idisabled, " . "(:now - dtmlastvisited) AS time " - . "FROM {chatoperator}" + . "FROM {operator}" . (empty($options['isolated_operator_id']) ? "" - : ", {chatgroupoperator} " - . "WHERE {chatoperator}.operatorid = {chatgroupoperator}.operatorid " - . "AND {chatgroupoperator}.groupid IN (" - . "SELECT g.groupid FROM {chatgroup} g, " - . "(SELECT DISTINCT parent FROM {chatgroup}, {chatgroupoperator} " - . "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " - . "AND {chatgroupoperator}.operatorid = :operatorid) i " + : ", {operatortoopgroup} " + . "WHERE {operator}.operatorid = {operatortoopgroup}.operatorid " + . "AND {operatortoopgroup}.groupid IN (" + . "SELECT g.groupid FROM {opgroup} g, " + . "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} " + . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid " + . "AND {operatortoopgroup}.operatorid = :operatorid) i " . "WHERE g.groupid = i.parent OR g.parent = i.parent " . ")") . " ORDER BY " . $orderby; @@ -222,7 +222,7 @@ function operator_get_all() return $operators = $db->query( ("SELECT operatorid, vclogin, vclocalename, vccommonname, istatus, " . "code, idisabled, (:now - dtmlastvisited) AS time " - . "FROM {chatoperator} ORDER BY vclogin"), + . "FROM {operator} ORDER BY vclogin"), array(':now' => time()), array('return_rows' => Database::RETURN_ALL_ROWS) ); @@ -230,17 +230,17 @@ function operator_get_all() function get_operators_from_adjacent_groups($operator) { $db = Database::getInstance(); - $query = "SELECT DISTINCT {chatoperator}.operatorid, vclogin, " + $query = "SELECT DISTINCT {operator}.operatorid, vclogin, " . "vclocalename,vccommonname, " . "istatus, idisabled, code, " . "(:now - dtmlastvisited) AS time " - . "FROM {chatoperator}, {chatgroupoperator} " - . "WHERE {chatoperator}.operatorid = {chatgroupoperator}.operatorid " - . "AND {chatgroupoperator}.groupid IN (" - . "SELECT g.groupid from {chatgroup} g, " - . "(SELECT DISTINCT parent FROM {chatgroup}, {chatgroupoperator} " - . "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " - . "AND {chatgroupoperator}.operatorid = :operatorid) i " + . "FROM {operator}, {operatortoopgroup} " + . "WHERE {operator}.operatorid = {operatortoopgroup}.operatorid " + . "AND {operatortoopgroup}.groupid IN (" + . "SELECT g.groupid from {opgroup} g, " + . "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} " + . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid " + . "AND {operatortoopgroup}.operatorid = :operatorid) i " . "WHERE g.groupid = i.parent OR g.parent = i.parent " . ") ORDER BY vclogin"; @@ -315,7 +315,7 @@ function update_operator( $values[':password'] = calculate_password_hash($login, $password); } $db->query( - ("UPDATE {chatoperator} SET vclogin = :login, " + ("UPDATE {operator} SET vclogin = :login, " . ($password ? " vcpassword=:password, " : "") . "vclocalename = :localname, vccommonname = :commonname, " . "vcemail = :email, code = :code, vcjabbername= :jabbername " @@ -328,7 +328,7 @@ function update_operator_avatar($operator_id, $avatar) { $db = Database::getInstance(); $db->query( - "UPDATE {chatoperator} SET vcavatar = ? WHERE operatorid = ?", + "UPDATE {operator} SET vcavatar = ? WHERE operatorid = ?", array($avatar, $operator_id) ); } @@ -357,7 +357,7 @@ function create_operator( ) { $db = Database::getInstance(); $db->query( - ("INSERT INTO {chatoperator} (" + ("INSERT INTO {operator} (" . "vclogin, vcpassword, vclocalename, vccommonname, vcavatar, " . "vcemail, code, vcjabbername " . ") VALUES (" @@ -379,7 +379,7 @@ function create_operator( $id = $db->insertedId(); return $db->query( - "SELECT * FROM {chatoperator} WHERE operatorid = ?", + "SELECT * FROM {operator} WHERE operatorid = ?", array($id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -400,11 +400,11 @@ function delete_operator($operator_id) { $db = Database::getInstance(); $db->query( - "DELETE FROM {chatgroupoperator} WHERE operatorid = ?", + "DELETE FROM {operatortoopgroup} WHERE operatorid = ?", array($operator_id) ); $db->query( - "DELETE FROM {chatoperator} WHERE operatorid = ?", + "DELETE FROM {operator} WHERE operatorid = ?", array($operator_id) ); @@ -425,7 +425,7 @@ function notify_operator_alive($operator_id, $istatus) { $db = Database::getInstance(); $db->query( - ("UPDATE {chatoperator} SET istatus = :istatus, dtmlastvisited = :now " + ("UPDATE {operator} SET istatus = :istatus, dtmlastvisited = :now " . "WHERE operatorid = :operatorid"), array( ':istatus' => $istatus, @@ -450,19 +450,19 @@ function has_online_operators($group_id = "") $db = Database::getInstance(); $query = "SELECT count(*) AS total, MIN(:now - dtmlastvisited) AS time " - . "FROM {chatoperator}"; + . "FROM {operator}"; $values = array(':now' => time()); if ($group_id) { - $query .= ", {chatgroupoperator}, {chatgroup} " - . "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " - . "AND ({chatgroup}.groupid = :groupid OR {chatgroup}.parent = :groupid) " - . "AND {chatoperator}.operatorid = {chatgroupoperator}.operatorid " + $query .= ", {operatortoopgroup}, {opgroup} " + . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid " + . "AND ({opgroup}.groupid = :groupid OR {opgroup}.parent = :groupid) " + . "AND {operator}.operatorid = {operatortoopgroup}.operatorid " . "AND istatus = 0"; $values[':groupid'] = $group_id; } else { if (Settings::get('enablegroups') == 1) { - $query .= ", {chatgroupoperator} " - . "WHERE {chatoperator}.operatorid = {chatgroupoperator}.operatorid " + $query .= ", {operatortoopgroup} " + . "WHERE {operator}.operatorid = {operatortoopgroup}.operatorid " . "AND istatus = 0"; } else { $query .= " WHERE istatus = 0"; @@ -490,7 +490,7 @@ function is_operator_online($operator_id) $row = $db->query( ("SELECT count(*) AS total, " . "MIN(:now - dtmlastvisited) AS time " - . "FROM {chatoperator} WHERE operatorid = :operatorid"), + . "FROM {operator} WHERE operatorid = :operatorid"), array( ':now' => time(), ':operatorid' => $operator_id, @@ -665,9 +665,9 @@ function get_all_groups() { $db = Database::getInstance(); $groups = $db->query( - ("SELECT {chatgroup}.groupid AS groupid, parent, " + ("SELECT {opgroup}.groupid AS groupid, parent, " . "vclocalname, vclocaldescription " - . "FROM {chatgroup} ORDER BY vclocalname"), + . "FROM {opgroup} ORDER BY vclocalname"), null, array('return_rows' => Database::RETURN_ALL_ROWS) ); @@ -679,10 +679,10 @@ function get_all_groups_for_operator($operator) { $db = Database::getInstance(); $query = "SELECT g.groupid AS groupid, g.parent, g.vclocalname, g.vclocaldescription " - . "FROM {chatgroup} g, " - . "(SELECT DISTINCT parent FROM {chatgroup}, {chatgroupoperator} " - . "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " - . "AND {chatgroupoperator}.operatorid = ?) i " + . "FROM {opgroup} g, " + . "(SELECT DISTINCT parent FROM {opgroup}, {operatortoopgroup} " + . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid " + . "AND {operatortoopgroup}.operatorid = ?) i " . "WHERE g.groupid = i.parent OR g.parent = i.parent " . "ORDER BY vclocalname"; @@ -737,10 +737,10 @@ function get_groups_($check_away, $operator, $order = null) $orderby = "ilastseen"; break; default: - $orderby = "{chatgroup}.vclocalname"; + $orderby = "{opgroup}.vclocalname"; } $orderby = sprintf( - " IF(ISNULL({chatgroup}.parent),CONCAT('_',%s),'') %s, {chatgroup}.iweight ", + " IF(ISNULL({opgroup}.parent),CONCAT('_',%s),'') %s, {opgroup}.iweight ", $orderby, ($order['desc'] ? 'DESC' : 'ASC') ); @@ -751,35 +751,35 @@ function get_groups_($check_away, $operator, $order = null) $values = array( ':now' => time(), ); - $query = "SELECT {chatgroup}.groupid AS groupid, " - . "{chatgroup}.parent AS parent, " + $query = "SELECT {opgroup}.groupid AS groupid, " + . "{opgroup}.parent AS parent, " . "vclocalname, vclocaldescription, iweight, " . "(SELECT count(*) " - . "FROM {chatgroupoperator} " - . "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid" + . "FROM {operatortoopgroup} " + . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid" . ") AS inumofagents, " . "(SELECT MIN(:now - dtmlastvisited) AS time " - . "FROM {chatgroupoperator}, {chatoperator} " + . "FROM {operatortoopgroup}, {operator} " . "WHERE istatus = 0 " - . "AND {chatgroup}.groupid = {chatgroupoperator}.groupid " - . "AND {chatgroupoperator}.operatorid = {chatoperator}.operatorid" . + . "AND {opgroup}.groupid = {operatortoopgroup}.groupid " + . "AND {operatortoopgroup}.operatorid = {operator}.operatorid" . ") AS ilastseen" . ($check_away ? ", (SELECT MIN(:now - dtmlastvisited) AS time " - . "FROM {chatgroupoperator}, {chatoperator} " + . "FROM {operatortoopgroup}, {operator} " . "WHERE istatus <> 0 " - . "AND {chatgroup}.groupid = {chatgroupoperator}.groupid " - . "AND {chatgroupoperator}.operatorid = {chatoperator}.operatorid" + . "AND {opgroup}.groupid = {operatortoopgroup}.groupid " + . "AND {operatortoopgroup}.operatorid = {operator}.operatorid" . ") AS ilastseenaway" : "") - . " FROM {chatgroup} "; + . " FROM {opgroup} "; if ($operator) { $query .= ", (SELECT DISTINCT parent " - . "FROM {chatgroup}, {chatgroupoperator} " - . "WHERE {chatgroup}.groupid = {chatgroupoperator}.groupid " - . "AND {chatgroupoperator}.operatorid = :operatorid) i " - . "WHERE {chatgroup}.groupid = i.parent OR {chatgroup}.parent = i.parent "; + . "FROM {opgroup}, {operatortoopgroup} " + . "WHERE {opgroup}.groupid = {operatortoopgroup}.groupid " + . "AND {operatortoopgroup}.operatorid = :operatorid) i " + . "WHERE {opgroup}.groupid = i.parent OR {opgroup}.parent = i.parent "; $values[':operatorid'] = $operator['operatorid']; } @@ -814,7 +814,7 @@ function get_operator_group_ids($operator_id) $db = Database::getInstance(); return $db->query( - "SELECT groupid FROM {chatgroupoperator} WHERE operatorid = ?", + "SELECT groupid FROM {operatortoopgroup} WHERE operatorid = ?", array($operator_id), array('return_rows' => Database::RETURN_ALL_ROWS) ); @@ -928,13 +928,13 @@ function update_operator_groups($operator_id, $new_value) { $db = Database::getInstance(); $db->query( - "DELETE FROM {chatgroupoperator} WHERE operatorid = ?", + "DELETE FROM {operatortoopgroup} WHERE operatorid = ?", array($operator_id) ); foreach ($new_value as $group_id) { $db->query( - "INSERT INTO {chatgroupoperator} (groupid, operatorid) VALUES (?,?)", + "INSERT INTO {operatortoopgroup} (groupid, operatorid) VALUES (?,?)", array($group_id, $operator_id) ); } diff --git a/src/mibew/libs/statistics.php b/src/mibew/libs/statistics.php index 12160840..aad9be8c 100644 --- a/src/mibew/libs/statistics.php +++ b/src/mibew/libs/statistics.php @@ -48,7 +48,7 @@ function get_by_date_statistics($start, $end) . "usermessages AS users, " . "averagewaitingtime AS avgwaitingtime, " . "averagechattime AS avgchattime " - . "FROM {chatthreadstatistics} s " + . "FROM {threadstatistics} s " . "WHERE s.date >= :start " . "AND s.date < :end " . "GROUP BY DATE(FROM_UNIXTIME(date)) " @@ -73,7 +73,7 @@ function get_by_date_statistics($start, $end) . "SUM(usermessages) AS users, " . "ROUND(SUM(averagewaitingtime * s.threads) / SUM(s.threads),1) AS avgwaitingtime, " . "ROUND(SUM(averagechattime * s.threads) / SUM(s.threads),1) AS avgchattime " - . "FROM {chatthreadstatistics} s " + . "FROM {threadstatistics} s " . "WHERE s.date >= :start " . "AND s.date < :end"), array( @@ -111,7 +111,7 @@ function get_by_operator_statistics($start, $end) . "SUM(acceptedinvitations) AS acceptedinvitations, " . "SUM(rejectedinvitations) AS rejectedinvitations, " . "SUM(ignoredinvitations) AS ignoredinvitations " - . "FROM {chatoperatorstatistics} s, {chatoperator} o " + . "FROM {operatorstatistics} s, {operator} o " . "WHERE s.operatorid = o.operatorid " . "AND s.date >= :start " . "AND s.date < :end " @@ -172,7 +172,7 @@ function calculate_thread_statistics() // Get last record date $result = $db->query( - "SELECT MAX(date) as start FROM {chatthreadstatistics}", + "SELECT MAX(date) as start FROM {threadstatistics}", array(), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -196,12 +196,12 @@ function calculate_thread_statistics() . "ABS(tmp.last_msg_time - t.dtmchatstarted) + " . "(tmp.last_msg_time - t.dtmchatstarted) " . ")/2,1) AS avg_chat_time " - . "FROM {chatthread} t, " + . "FROM {thread} t, " . "(SELECT SUM(m.ikind = :kind_agent) AS operator_msgs, " . "SUM(m.ikind = :kind_user) AS user_msgs, " . "MAX(m.dtmcreated) as last_msg_time, " . "threadid " - . "FROM {chatmessage} m " + . "FROM {message} m " // Calculate only users' and operators' messages . "WHERE m.ikind = :kind_user " . "OR m.ikind = :kind_agent " @@ -240,7 +240,7 @@ function calculate_thread_statistics() $db_results = $db->query( ("SELECT (FLOOR(dtmcreated / :interval) * :interval) AS date, " . "COUNT(*) as missed_threads " - . "FROM {chatthread} " + . "FROM {thread} " . "WHERE (dtmcreated - :start) > :interval " // Calculate statistics only for threads that older than // statistics_aggregation_interval @@ -270,7 +270,7 @@ function calculate_thread_statistics() $db_results = $db->query( ("SELECT (FLOOR(dtmcreated / :interval) * :interval) AS date, " . "ROUND(AVG(dtmchatstarted-dtmcreated),1) AS avg_waiting_time " - . "FROM {chatthread} " + . "FROM {thread} " . "WHERE (dtmcreated - :start) > :interval " // Calculate statistics only for threads that older than // statistics_aggregation_interval @@ -303,7 +303,7 @@ function calculate_thread_statistics() . "SUM(invitationstate = :invitation_accepted) AS invitations_accepted, " . "SUM(invitationstate = :invitation_rejected) AS invitations_rejected, " . "SUM(invitationstate = :invitation_ignored) AS invitations_ignored " - . "FROM {chatthread} " + . "FROM {thread} " . "WHERE (dtmcreated - :start) > :interval " // Calculate statistics only for threads that older than // statistics_aggregation_interval @@ -356,7 +356,7 @@ function calculate_thread_statistics() // Store data in database $db->query( - ("INSERT INTO {chatthreadstatistics} (" + ("INSERT INTO {threadstatistics} (" . "date, threads, missedthreads, sentinvitations, " . "acceptedinvitations, rejectedinvitations, " . "ignoredinvitations, operatormessages, usermessages, " @@ -408,7 +408,7 @@ function calculate_operator_statistics() // Get last record date $result = $db->query( - "SELECT MAX(date) as start FROM {chatoperatorstatistics}", + "SELECT MAX(date) as start FROM {operatorstatistics}", array(), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -424,10 +424,10 @@ function calculate_operator_statistics() . "COUNT(distinct m.threadid) AS threads, " . "COUNT(m.messageid) AS messages, " . "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 // other during conversation). - . "FROM {chatmessage} m, {chatthread} t " + . "FROM {message} m, {thread} t " . "WHERE m.ikind = :kind_agent " . "AND m.threadid = t.threadid " . "AND (m.dtmcreated - :start) > :interval " @@ -464,7 +464,7 @@ function calculate_operator_statistics() . "SUM(invitationstate = :invitation_accepted) AS invitations_accepted, " . "SUM(invitationstate = :invitation_rejected) AS invitations_rejected, " . "SUM(invitationstate = :invitation_ignored) AS invitations_ignored " - . "FROM {chatthread} " + . "FROM {thread} " . "WHERE (dtmcreated - :start) > :interval " // Calculate statistics only for threads that older than // statistics_aggregation_interval @@ -516,7 +516,7 @@ function calculate_operator_statistics() } $db->query( - ("INSERT INTO {chatoperatorstatistics} (" + ("INSERT INTO {operatorstatistics} (" . "date, operatorid, threads, messages, averagelength, " . "sentinvitations, acceptedinvitations, " . "rejectedinvitations, ignoredinvitations " @@ -608,11 +608,11 @@ function calculate_page_statistics() ("SELECT FLOOR(p.visittime / :interval) * :interval AS date, " . "p.address AS address, " . "COUNT(DISTINCT t.threadid) AS chats " - . "FROM {visitedpage} p, {chatthread} t, " + . "FROM {visitedpage} p, {thread} t, " . "(SELECT " . "COUNT(*) AS msgs, " . "m.threadid " - . "FROM {chatmessage} m " + . "FROM {message} m " . "WHERE m.ikind = :kind_user OR m.ikind = :kind_agent " . "GROUP BY m.threadid) tmp " . "WHERE t.referer = p.address " @@ -651,7 +651,7 @@ function calculate_page_statistics() ("SELECT FLOOR(p.visittime / :interval) * :interval AS date, " . "p.address AS address, " . "COUNT(DISTINCT t.threadid) AS invitations_accepted " - . "FROM {visitedpage} p, {chatthread} t " + . "FROM {visitedpage} p, {thread} t " . "WHERE t.referer = p.address " . "AND p.calculated = 0 " . "AND (p.visittime - :start) > :interval " @@ -681,7 +681,7 @@ function calculate_page_statistics() ("SELECT FLOOR(p.visittime / :interval) * :interval AS date, " . "p.address AS address, " . "COUNT(DISTINCT t.threadid) AS invitations_rejected " - . "FROM {visitedpage} p, {chatthread} t " + . "FROM {visitedpage} p, {thread} t " . "WHERE t.referer = p.address " . "AND p.calculated = 0 " . "AND (p.visittime - :start) > :interval " @@ -711,7 +711,7 @@ function calculate_page_statistics() ("SELECT FLOOR(p.visittime / :interval) * :interval AS date, " . "p.address AS address, " . "COUNT(DISTINCT t.threadid) AS invitations_ignored " - . "FROM {visitedpage} p, {chatthread} t " + . "FROM {visitedpage} p, {thread} t " . "WHERE t.referer = p.address " . "AND p.calculated = 0 " . "AND (p.visittime - :start) > :interval " diff --git a/src/mibew/libs/track.php b/src/mibew/libs/track.php index 1fbaf5ba..293ea34d 100644 --- a/src/mibew/libs/track.php +++ b/src/mibew/libs/track.php @@ -31,7 +31,7 @@ function track_visitor($visitor_id, $entry, $referer) } else { $db = Database::getInstance(); $db->query( - "UPDATE {chatsitevisitor} SET lasttime = :now WHERE visitorid = :visitorid", + "UPDATE {sitevisitor} SET lasttime = :now WHERE visitorid = :visitorid", array( ':visitorid' => $visitor['visitorid'], ':now' => time(), @@ -49,7 +49,7 @@ function track_visitor_start($entry, $referer) $db = Database::getInstance(); $db->query( - ("INSERT INTO {chatsitevisitor} ( " + ("INSERT INTO {sitevisitor} ( " . "userid, username, firsttime, lasttime, entry,details " . ") VALUES ( " . ":userid, :username, :now, :now, :entry, :details " @@ -77,7 +77,7 @@ function track_get_visitor_by_id($visitor_id) $db = Database::getInstance(); return $db->query( - "SELECT * FROM {chatsitevisitor} WHERE visitorid = ?", + "SELECT * FROM {sitevisitor} WHERE visitorid = ?", array($visitor_id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -88,7 +88,7 @@ function track_get_visitor_by_thread_id($thread_id) $db = Database::getInstance(); return $db->query( - "SELECT * FROM {chatsitevisitor} WHERE threadid = ?", + "SELECT * FROM {sitevisitor} WHERE threadid = ?", array($thread_id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -105,7 +105,7 @@ function track_get_visitor_by_user_id($user_id) $db = Database::getInstance(); return $db->query( - "SELECT * FROM {chatsitevisitor} WHERE userid = ?", + "SELECT * FROM {sitevisitor} WHERE userid = ?", array($user_id), array('return_rows' => Database::RETURN_ONE_ROW) ); @@ -183,17 +183,17 @@ function track_remove_old_visitors() // Remove associations of visitors with closed threads $db->query( - "UPDATE {chatsitevisitor} SET threadid = NULL " + "UPDATE {sitevisitor} SET threadid = NULL " . "WHERE threadid IS NOT NULL AND " - . "(SELECT count(*) FROM {chatthread} " - . "WHERE threadid = {chatsitevisitor}.threadid " + . "(SELECT count(*) FROM {thread} " + . "WHERE threadid = {sitevisitor}.threadid " . "AND istate <> " . Thread::STATE_CLOSED . " " . "AND istate <> " . Thread::STATE_LEFT . ") = 0 " ); // Remove old visitors $db->query( - ("DELETE FROM {chatsitevisitor} " + ("DELETE FROM {sitevisitor} " . "WHERE (:now - lasttime) > :lifetime " . "AND threadid IS NULL"), array( @@ -216,7 +216,7 @@ function track_remove_old_tracks() . "WHERE (:now - visittime) > :lifetime " // Remove only tracks that are included in statistics . "AND calculated = 1 " - . "AND visitorid NOT IN (SELECT visitorid FROM {chatsitevisitor}) "), + . "AND visitorid NOT IN (SELECT visitorid FROM {sitevisitor}) "), array( ':lifetime' => Settings::get('tracking_lifetime'), ':now' => time(), @@ -244,7 +244,7 @@ function track_get_user_id($visitor_id) /** * 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. * @param Thread $thread Chat thread object */ @@ -252,7 +252,7 @@ function track_visitor_bind_thread($user_id, $thread) { $db = Database::getInstance(); $db->query( - ('UPDATE {chatsitevisitor} ' + ('UPDATE {sitevisitor} ' . 'SET threadid = :thread_id ' . 'WHERE userid = :user_id'), array(