diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php
index 79a2208e..f1671f6e 100644
--- a/src/messenger/webim/install/dbinfo.php
+++ b/src/messenger/webim/install/dbinfo.php
@@ -37,9 +37,9 @@ $dbtables = array(
"userid" => "varchar(255)",
"agentName" => "varchar(64)",
"agentId" => "int NOT NULL DEFAULT 0",
- "dtmcreated" => "datetime DEFAULT 0",
- "dtmchatstarted" => "datetime DEFAULT 0",
- "dtmmodified" => "datetime DEFAULT 0",
+ "dtmcreated" => "int NOT NULL DEFAULT 0",
+ "dtmchatstarted" => "int NOT NULL DEFAULT 0",
+ "dtmmodified" => "int NOT NULL DEFAULT 0",
"lrevision" => "int NOT NULL DEFAULT 0",
"istate" => "int NOT NULL DEFAULT 0",
"ltoken" => "int NOT NULL",
@@ -47,8 +47,8 @@ $dbtables = array(
"referer" => "text",
"nextagent" => "int NOT NULL DEFAULT 0",
"locale" => "varchar(8)",
- "lastpinguser" => "datetime DEFAULT 0",
- "lastpingagent" => "datetime DEFAULT 0",
+ "lastpinguser" => "int NOT NULL DEFAULT 0",
+ "lastpingagent" => "int NOT NULL DEFAULT 0",
"userTyping" => "int DEFAULT 0",
"agentTyping" => "int DEFAULT 0",
"shownmessageid" => "int NOT NULL DEFAULT 0",
@@ -63,7 +63,7 @@ $dbtables = array(
"ikind" => "int NOT NULL",
"agentId" => "int NOT NULL DEFAULT 0",
"tmessage" => "text NOT NULL",
- "dtmcreated" => "datetime DEFAULT 0",
+ "dtmcreated" => "int NOT NULL DEFAULT 0",
"tname" => "varchar(64)"
),
@@ -74,13 +74,13 @@ $dbtables = array(
"vclocalename" => "varchar(64) NOT NULL",
"vccommonname" => "varchar(64) NOT NULL",
"vcemail" => "varchar(64)",
- "dtmlastvisited" => "datetime DEFAULT 0",
+ "dtmlastvisited" => "int NOT NULL DEFAULT 0",
"istatus" => "int DEFAULT 0", /* 0 - online, 1 - away */
"idisabled" => "int DEFAULT 0",
"vcavatar" => "varchar(255)",
"vcjabbername" => "varchar(255)",
"iperm" => "int DEFAULT 65535",
- "dtmrestore" => "datetime DEFAULT 0",
+ "dtmrestore" => "int NOT NULL DEFAULT 0",
"vcrestoretoken" => "varchar(64)",
),
@@ -95,8 +95,8 @@ $dbtables = array(
"${mysqlprefix}chatban" => array(
"banid" => "INT NOT NULL auto_increment PRIMARY KEY",
- "dtmcreated" => "datetime DEFAULT 0",
- "dtmtill" => "datetime DEFAULT 0",
+ "dtmcreated" => "int NOT NULL DEFAULT 0",
+ "dtmtill" => "int NOT NULL DEFAULT 0",
"address" => "varchar(255)",
"comment" => "varchar(255)",
"blockedCount" => "int DEFAULT 0"
@@ -120,12 +120,12 @@ $dbtables = array(
"visitorid" => "INT NOT NULL auto_increment PRIMARY KEY",
"userid" => "varchar(64) NOT NULL",
"username" => "varchar(255)",
- "firsttime" => "datetime NOT NULL DEFAULT 0",
- "lasttime" => "datetime NOT NULL DEFAULT 0",
+ "firsttime" => "int NOT NULL DEFAULT 0",
+ "lasttime" => "int NOT NULL DEFAULT 0",
"entry" => "text NOT NULL",
"details" => "text NOT NULL",
"invited" => "tinyint(1) NOT NULL DEFAULT 0",
- "invitationtime" => "datetime",
+ "invitationtime" => "int NOT NULL DEFAULT 0",
"invitedby" => "INT references ${mysqlprefix}chatoperator(operatorid) on delete set null",
"invitations" => "INT NOT NULL DEFAULT 0",
"chats" => "INT NOT NULL DEFAULT 0",
@@ -135,14 +135,14 @@ $dbtables = array(
"${mysqlprefix}visitedpage" => array(
"pageid" => "INT NOT NULL auto_increment PRIMARY KEY",
"address" => "varchar(1024)",
- "visittime" => "datetime NOT NULL DEFAULT 0",
+ "visittime" => "int NOT NULL DEFAULT 0",
"visitorid" => "INT",
),
"${mysqlprefix}visitedpagestatistics" => array(
"pageid" => "INT NOT NULL auto_increment PRIMARY KEY",
"address" => "varchar(1024)",
- "visittime" => "datetime NOT NULL DEFAULT 0"
+ "visittime" => "int NOT NULL DEFAULT 0"
),
);
diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php
index 598bcd8e..579d87e0 100644
--- a/src/messenger/webim/install/dbperform.php
+++ b/src/messenger/webim/install/dbperform.php
@@ -86,7 +86,7 @@ if ($act == "silentcreateall") {
}
if (in_array("${mysqlprefix}chatthread.dtmchatstarted", $absent_columns)) {
- runsql("ALTER TABLE ${mysqlprefix}chatthread ADD dtmchatstarted datetime DEFAULT 0 AFTER dtmcreated", $link);
+ runsql("ALTER TABLE ${mysqlprefix}chatthread ADD dtmchatstarted int NOT NULL DEFAULT 0 AFTER dtmcreated", $link);
runsql("update ${mysqlprefix}chatthread set dtmchatstarted = dtmcreated", $link);
}
@@ -142,7 +142,7 @@ if ($act == "silentcreateall") {
}
if (in_array("${mysqlprefix}chatoperator.dtmrestore", $absent_columns)) {
- runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD dtmrestore datetime DEFAULT 0", $link);
+ runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD dtmrestore int NOT NULL DEFAULT 0", $link);
}
if (in_array("${mysqlprefix}chatoperator.vcrestoretoken", $absent_columns)) {
diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php
index 3742728b..b1a6e529 100644
--- a/src/messenger/webim/libs/chat.php
+++ b/src/messenger/webim/libs/chat.php
@@ -64,20 +64,21 @@ function next_revision()
function post_message_($threadid, $kind, $message, $from = null, $utime = null, $opid = null)
{
$db = Database::getInstance();
+
$query = "insert into {chatmessage} " .
"(threadid,ikind,tmessage,tname,agentId,dtmcreated) " .
- "values (?,?,?,?,?,".($utime?"FROM_UNIXTIME(?)":"CURRENT_TIMESTAMP").")";
+ "values (:threadid,:kind,:message,:name,:agentid,:created)";
+
$values = array(
- $threadid,
- $kind,
- $message,
- ($from ? $from : "null"),
- ($opid ? $opid : 0)
+ ':threadid' => $threadid,
+ ':kind' => $kind,
+ ':message' => $message,
+ ':name' => ($from ? $from : "null"),
+ ':agentid' => ($opid ? $opid : 0),
+ ':created' => ($utime ? $utime : time())
);
- if ($utime) {
- $values[] = $utime;
- }
- $db->query($query, $values);
+
+ $db->query($query, $values);
return $db->insertedId();
}
@@ -135,7 +136,7 @@ function get_messages($threadid, $meth, $isuser, &$lastid)
$db = Database::getInstance();
$msgs = $db->query(
- "select messageid,ikind,unix_timestamp(dtmcreated) as created,tname,tmessage from {chatmessage} " .
+ "select messageid,ikind,dtmcreated as created,tname,tmessage from {chatmessage} " .
"where threadid = :threadid and messageid > :lastid " .
($isuser ? "and ikind <> {$kind_for_agent} " : "") .
"order by messageid",
@@ -177,7 +178,7 @@ function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agen
{
global $webim_encoding, $webimroot, $connection_timeout;
$threadid = $thread['threadid'];
- $istyping = abs($thread['current'] - $thread[$isuser ? "lpagent" : "lpuser"]) < $connection_timeout
+ $istyping = abs(time() - $thread[$isuser ? "lpagent" : "lpuser"]) < $connection_timeout
&& $thread[$isuser ? "agentTyping" : "userTyping"] == "1" ? "1" : "0";
if ($format == "xml") {
@@ -532,11 +533,10 @@ function ping_thread($thread, $isuser, $istyping)
$db = Database::getInstance();
- $params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP",
+ $params = array(($isuser ? "lastpinguser" : "lastpingagent") => time(),
($isuser ? "userTyping" : "agentTyping") => ($istyping ? "1" : "0"));
$lastping = $thread[$isuser ? "lpagent" : "lpuser"];
- $current = $thread['current'];
if ($thread['istate'] == $state_loading && $isuser) {
$params['istate'] = $state_queue;
@@ -544,7 +544,7 @@ function ping_thread($thread, $isuser, $istyping)
return;
}
- if ($lastping > 0 && abs($current - $lastping) > $connection_timeout) {
+ if ($lastping > 0 && abs(time() - $lastping) > $connection_timeout) {
$params[$isuser ? "lastpingagent" : "lastpinguser"] = "0";
if (!$isuser) {
$message_to_post = getstring_("chat.status.user.dead", $thread['locale']);
@@ -566,12 +566,8 @@ function ping_thread($thread, $isuser, $istyping)
if (strlen($clause) > 0) {
$clause .= ", ";
}
- if (($k == 'lastpinguser' || $k == 'lastpingagent') && $v == 'CURRENT_TIMESTAMP') {
- $clause .= $k . " = CURRENT_TIMESTAMP";
- }else{
- $clause .= $k . "=?";
- $values[] = $v;
- }
+ $clause .= $k . "=?";
+ $values[] = $v;
}
$values[] = $thread['threadid'];
@@ -585,24 +581,18 @@ function commit_thread($threadid, $params)
{
$db = Database::getInstance();
- $timestamp_allowed_for = array(
- 'dtmcreated',
- 'dtmchatstarted',
- 'dtmmodified',
- 'lastpinguser',
- 'lastpingagent'
- );
$query = "update {chatthread} t " .
- "set lrevision = ?, dtmmodified = CURRENT_TIMESTAMP";
- $values = array(next_revision());
- foreach ($params as $k => $v) {
- if (in_array($k, $timestamp_allowed_for) && strcasecmp($v,'CURRENT_TIMESTAMP')) {
- $query .= ", " . $k . " = CURRENT_TIMESTAMP";
- } else {
- $query .= ", " . $k . "=?";
- $values[] = $v;
- }
+ "set lrevision = ?, dtmmodified = ?";
+
+ $values = array();
+ $values[] = next_revision();
+ $values[] = time();
+
+ foreach ($params as $name => $value) {
+ $query .= ", {$name} = ?" ;
+ $values[] = $value;
}
+
$query .= " where threadid = ?";
$values[] = $threadid;
@@ -659,21 +649,22 @@ function close_old_threads()
$db = Database::getInstance();
$query = "update {chatthread} set lrevision = :next_revision, " .
- "dtmmodified = CURRENT_TIMESTAMP, istate = :state_closed " .
+ "dtmmodified = :now, istate = :state_closed " .
"where istate <> :state_closed and istate <> :state_left " .
"and ((lastpingagent <> 0 and lastpinguser <> 0 and " .
- "(ABS(UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lastpinguser)) > ".
+ "(ABS(:now - lastpinguser) > ".
":thread_lifetime and " .
- "ABS(UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lastpingagent)) > ".
+ "ABS(:now - lastpingagent) > ".
":thread_lifetime)) or " .
"lastpingagent = 0 and lastpinguser <> 0 and " .
- "ABS(UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lastpinguser)) > ".
+ "ABS(:now - lastpinguser) > ".
":thread_lifetime)";
$db->query(
$query,
array(
':next_revision' => next_revision(),
+ ':now' => time(),
':state_closed' => $state_closed,
':state_left' => $state_left,
':thread_lifetime' => Settings::get('thread_lifetime')
@@ -686,13 +677,16 @@ function thread_by_id($id)
$db = Database::getInstance();
return $db->query(
"select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping, " .
- "agentTyping,unix_timestamp(dtmmodified) as modified, " .
- "unix_timestamp(dtmcreated) as created, " .
- "unix_timestamp(dtmchatstarted) as chatstarted,remote,referer,locale," .
- "unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent," .
- "unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent,shownmessageid,userid, " .
- "userAgent,groupid from {chatthread} where threadid = ?",
- array($id),
+ "agentTyping,dtmmodified as modified, " .
+ "dtmcreated as created, " .
+ "dtmchatstarted as chatstarted,remote,referer,locale," .
+ "lastpinguser as lpuser,lastpingagent as lpagent," .
+ "nextagent,shownmessageid,userid, " .
+ "userAgent,groupid from {chatthread} where threadid = :threadid",
+ array(
+ ':threadid' => $id,
+ ':now' => time()
+ ),
array('return_rows' => Database::RETURN_ONE_ROW)
);
}
@@ -702,8 +696,11 @@ function ban_for_addr($addr)
$db = Database::getInstance();
return $db->query(
"select banid,comment from {chatban} " .
- "where unix_timestamp(dtmtill) > unix_timestamp(CURRENT_TIMESTAMP) AND address = ?",
- array($addr),
+ "where dtmtill > :now AND address = :addr",
+ array(
+ ':addr' => $addr,
+ ':now' => time()
+ ),
array('return_rows' => Database::RETURN_ONE_ROW)
);
}
@@ -712,26 +709,49 @@ function create_thread($groupid, $username, $remoteHost, $referer, $lang, $useri
{
$db = Database::getInstance();
- $query = "insert into {chatthread} (userName,userid,ltoken,remote,referer, " .
- "lrevision,locale,userAgent,dtmcreated,dtmmodified,istate" .
- ($groupid ? ",groupid" : "") . ") values " .
- "(?,?,?,?,?,?,?,?,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,?" .
- ($groupid ? ", ?" : "") . ")";
+ $query = "insert into {chatthread} (" .
+ "userName, " .
+ "userid, " .
+ "ltoken, " .
+ "remote, " .
+ "referer, " .
+ "lrevision, " .
+ "locale, " .
+ "userAgent, " .
+ "dtmcreated, " .
+ "dtmmodified, " .
+ "istate" .
+ ($groupid ? ", groupid" : "") .
+ ") values (" .
+ ":username, " .
+ ":userid, " .
+ ":ltoken, " .
+ ":remote," .
+ ":referer, " .
+ ":lrevision, " .
+ ":locale, " .
+ ":useragent, " .
+ ":now, " .
+ ":now, " .
+ ":istate" .
+ ($groupid ? ", :groupid" : "") .
+ ")";
$values = array(
- $username,
- $userid,
- next_token(),
- $remoteHost,
- $referer,
- next_revision(),
- $lang,
- $userbrowser,
- $initialState
+ ':username' => $username,
+ ':userid' => $userid,
+ ':ltoken' => next_token(),
+ ':remote' => $remoteHost,
+ ':referer' => $referer,
+ ':lrevision' => next_revision(),
+ ':locale' => $lang,
+ ':useragent' => $userbrowser,
+ ':now' => time(),
+ ':istate' => $initialState
);
if ($groupid) {
- $values[] = $groupid;
+ $values[':groupid'] = $groupid;
}
$db->query($query, $values);
@@ -749,7 +769,7 @@ function do_take_thread($threadid, $operatorId, $operatorName, $chatstart = fals
"agentId" => $operatorId,
"agentName" => $operatorName);
if ($chatstart){
- $params['dtmchatstarted'] = "CURRENT_TIMESTAMP";
+ $params['dtmchatstarted'] = time();
}
commit_thread($threadid, $params);
}
diff --git a/src/messenger/webim/libs/invitation.php b/src/messenger/webim/libs/invitation.php
index a9749ca6..ae9058c2 100644
--- a/src/messenger/webim/libs/invitation.php
+++ b/src/messenger/webim/libs/invitation.php
@@ -35,9 +35,13 @@ function invitation_invite($visitorid, $operatorid)
if (!invitation_check($visitorid)) {
$db = Database::getInstance();
$db->query(
- "update {chatsitevisitor} set invited = 1, invitedby = ?, " .
- "invitationtime = now(), invitations = invitations + 1 where visitorid = ?",
- array($operatorid, $visitorid)
+ "update {chatsitevisitor} set invited = 1, invitedby = :operatorid, " .
+ "invitationtime = :now, invitations = invitations + 1 where visitorid = :visitorid",
+ array(
+ ':operatorid' => $operatorid,
+ ':visitorid' => $visitorid,
+ ':now' => time()
+ )
);
return invitation_check($visitorid);
} else {
diff --git a/src/messenger/webim/libs/operator.php b/src/messenger/webim/libs/operator.php
index a6631aa1..5bea5698 100644
--- a/src/messenger/webim/libs/operator.php
+++ b/src/messenger/webim/libs/operator.php
@@ -97,7 +97,7 @@ function get_operators_list($options)
$orderby = "vclogin";
}
- $query = "select distinct {chatoperator}.operatorid, vclogin, vclocalename, vccommonname, istatus, idisabled, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
+ $query = "select distinct {chatoperator}.operatorid, vclogin, vclocalename, vccommonname, istatus, idisabled, (:now - dtmlastvisited) as time " .
"from {chatoperator}" .
(
empty($options['isolated_operator_id']) ? "" :
@@ -111,13 +111,17 @@ function get_operators_list($options)
) .
" order by " . $orderby;
+ $values = array(
+ ':now' => time()
+ );
+
+ if (! empty($options['isolated_operator_id'])) {
+ $values[':operatorid'] = $options['isolated_operator_id'];
+ }
+
$operators = $db->query(
$query,
- (
- empty($options['isolated_operator_id'])
- ? array()
- : array(':operatorid' => $options['isolated_operator_id'])
- ),
+ $values,
array('return_rows' => Database::RETURN_ALL_ROWS)
);
@@ -129,9 +133,9 @@ function operator_get_all()
$db = Database::getInstance();
return $operators = $db->query(
"select operatorid, vclogin, vclocalename, vccommonname, istatus, idisabled, " .
- "(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
+ "(:now - dtmlastvisited) as time " .
"from {chatoperator} order by vclogin",
- NULL,
+ array(':now' => time()),
array('return_rows' => Database::RETURN_ALL_ROWS)
);
}
@@ -141,21 +145,24 @@ function get_operators_from_adjacent_groups($operator)
$db = Database::getInstance();
$query = "select distinct {chatoperator}.operatorid, vclogin, vclocalename,vccommonname, " .
"istatus, idisabled, " .
- "(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
+ "(: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 = ?) i " .
+ "and {chatgroupoperator}.operatorid = :operatorid) i " .
"where g.groupid = i.parent or g.parent = i.parent " .
") order by vclogin";
return $db->query(
$query,
- array($operator['operatorid']),
+ array(
+ ':operatorid' => $operator['operatorid'],
+ ':now' => time()
+ ),
array('return_rows' => Database::RETURN_ALL_ROWS)
);
}
@@ -245,9 +252,13 @@ function notify_operator_alive($operatorid, $istatus)
{
$db = Database::getInstance();
$db->query(
- "update {chatoperator} set istatus = ?, dtmlastvisited = CURRENT_TIMESTAMP " .
- "where operatorid = ?",
- array($istatus, $operatorid)
+ "update {chatoperator} set istatus = :istatus, dtmlastvisited = :now " .
+ "where operatorid = :operatorid",
+ array(
+ ':istatus' => $istatus,
+ ':now' => time(),
+ ':operatorid' => $operatorid
+ )
);
}
@@ -255,7 +266,7 @@ function has_online_operators($groupid = "")
{
$db = Database::getInstance();
- $query = "select count(*) as total, min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time from {chatoperator}";
+ $query = "select count(*) as total, min(:now - dtmlastvisited) as time from {chatoperator}";
if ($groupid) {
$query .= ", {chatgroupoperator}, {chatgroup} where {chatgroup}.groupid = {chatgroupoperator}.groupid and " .
"({chatgroup}.groupid = :groupid or {chatgroup}.parent = :groupid) and {chatoperator}.operatorid = " .
@@ -271,7 +282,10 @@ function has_online_operators($groupid = "")
$row = $db->query(
$query,
- array(':groupid'=>$groupid),
+ array(
+ ':groupid'=>$groupid,
+ ':now' => time()
+ ),
array('return_rows' => Database::RETURN_ONE_ROW)
);
return $row['time'] < Settings::get('online_timeout') && $row['total'] > 0;
@@ -282,9 +296,12 @@ function is_operator_online($operatorid)
$db = Database::getInstance();
$row = $db->query(
"select count(*) as total, " .
- "min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
- "from {chatoperator} where operatorid = ?",
- array($operatorid),
+ "min(:now - dtmlastvisited) as time " .
+ "from {chatoperator} where operatorid = :operatorid",
+ array(
+ ':now' => time(),
+ ':operatorid' => $operatorid
+ ),
array('return_rows' => Database::RETURN_ONE_ROW)
);
@@ -548,28 +565,32 @@ function get_groups_($checkaway, $operator, $order = NULL)
$orderby = "iweight, vclocalname";
}
- $values = array();
+ $values = array(
+ ':now' => time()
+ );
$query = "select {chatgroup}.groupid as groupid, {chatgroup}.parent as parent, vclocalname, vclocaldescription, iweight" .
", (SELECT count(*) from {chatgroupoperator} where {chatgroup}.groupid = " .
"{chatgroupoperator}.groupid) as inumofagents" .
- ", (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
+ ", (SELECT min(:now - dtmlastvisited) as time " .
"from {chatgroupoperator}, {chatoperator} where istatus = 0 and " .
"{chatgroup}.groupid = {chatgroupoperator}.groupid " .
"and {chatgroupoperator}.operatorid = {chatoperator}.operatorid) as ilastseen" .
($checkaway
- ? ", (SELECT min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " .
+ ? ", (SELECT min(:now - dtmlastvisited) as time " .
"from {chatgroupoperator}, {chatoperator} where istatus <> 0 and " .
"{chatgroup}.groupid = {chatgroupoperator}.groupid " .
"and {chatgroupoperator}.operatorid = {chatoperator}.operatorid) as ilastseenaway"
: ""
) .
" from {chatgroup} ";
+
if ($operator) {
$query .= ", (select distinct parent from {chatgroup}, {chatgroupoperator} " .
- "where {chatgroup}.groupid = {chatgroupoperator}.groupid and {chatgroupoperator}.operatorid = ?) i " .
+ "where {chatgroup}.groupid = {chatgroupoperator}.groupid and {chatgroupoperator}.operatorid = :operatorid) i " .
"where {chatgroup}.groupid = i.parent or {chatgroup}.parent = i.parent ";
- $values[] = $operator['operatorid'];
+ $values[':operatorid'] = $operator['operatorid'];
}
+
$query .= " order by " . $orderby;
$groups = $db->query(
$query,
diff --git a/src/messenger/webim/libs/track.php b/src/messenger/webim/libs/track.php
index a2437cb5..e0b97b81 100644
--- a/src/messenger/webim/libs/track.php
+++ b/src/messenger/webim/libs/track.php
@@ -27,9 +27,12 @@ function track_visitor($visitorid, $entry, $referer)
} else {
$db = Database::getInstance();
$db->query(
- "update {chatsitevisitor} set lasttime = CURRENT_TIMESTAMP " .
- "where visitorid=?",
- array($visitor['visitorid'])
+ "update {chatsitevisitor} set lasttime = :now " .
+ "where visitorid = :visitorid",
+ array(
+ ':vidsitorid' => $visitor['visitorid'],
+ ':now' => time()
+ )
);
track_visit_page($visitor['visitorid'], $referer);
return $visitor['visitorid'];
@@ -43,12 +46,13 @@ function track_visitor_start($entry, $referer)
$db = Database::getInstance();
$db->query(
"insert into {chatsitevisitor} (userid,username,firsttime,lasttime,entry,details) ".
- "values (?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?)",
+ "values (:userid, :username, :now, :now, :entry, :details)",
array(
- $visitor['id'],
- $visitor['name'],
- $entry,
- track_build_details()
+ ':userid' => $visitor['id'],
+ ':username' => $visitor['name'],
+ ':now' => time(),
+ ':entry' => $entry,
+ ':details' => track_build_details()
)
);
@@ -97,13 +101,20 @@ function track_visit_page($visitorid, $page)
if ( $lastpage['address'] != $page ) {
$db->query(
"insert into {visitedpage} (visitorid, address, visittime) " .
- "values (?, ?, CURRENT_TIMESTAMP)",
- array($visitorid, $page)
+ "values (:visitorid, :page, :now)",
+ array(
+ ':visitorid' => $visitorid,
+ ':page' => $page,
+ ':now' => time()
+ )
);
$db->query(
"insert into {visitedpagestatistics} (address, visittime) " .
- "values (?, CURRENT_TIMESTAMP)",
- array($page)
+ "values (:page, :now)",
+ array(
+ ':page' => $page,
+ ':now' => time()
+ )
);
}
}
@@ -112,7 +123,7 @@ function track_get_path($visitor)
{
$db = Database::getInstance();
$query_result = $db->query(
- "select address, UNIX_TIMESTAMP(visittime) as visittime from {visitedpage} " .
+ "select address, visittime from {visitedpage} " .
"where visitorid = ?",
array($visitor['visitorid']),
array('return_rows' => Database::RETURN_ALL_ROWS)
diff --git a/src/messenger/webim/operator/ban.php b/src/messenger/webim/operator/ban.php
index 29b0d2dd..3fe35b22 100644
--- a/src/messenger/webim/operator/ban.php
+++ b/src/messenger/webim/operator/ban.php
@@ -55,26 +55,28 @@ if (isset($_POST['address'])) {
if (count($errors) == 0) {
$db = Database::getInstance();
- $utime = time() + $days * 24 * 60 * 60;
+ $now = time();
+ $till_time = $now + $days * 24 * 60 * 60;
if (!$banId) {
$db->query(
"insert into {chatban} (dtmcreated,dtmtill,address,comment) " .
- "values (CURRENT_TIMESTAMP,FROM_UNIXTIME(?),?,?)",
+ "values (:now,:till,:address,:comment)",
array(
- $utime,
- $address,
- $comment
+ ':now' => $now,
+ ':till' => $till_time,
+ ':address' => $address,
+ ':comment' => $comment
)
);
} else {
$db->query(
- "update {chatban} set dtmtill = FROM_UNIXTIME(?),address = ?, " .
- "comment = ? where banid = ?",
+ "update {chatban} set dtmtill = :till,address = :address, " .
+ "comment = :comment where banid = :banid",
array(
- $utime,
- $address,
- $comment,
- $banId
+ ':till' => $till_time,
+ ':address' => $address,
+ ':comment' => $comment,
+ ':banid' => $banId
)
);
}
@@ -97,9 +99,12 @@ if (isset($_POST['address'])) {
$banId = verifyparam('id', "/^\d{1,9}$/");
$db = Database::getInstance();
$ban = $db->query(
- "select banid,(unix_timestamp(dtmtill)-unix_timestamp(CURRENT_TIMESTAMP))" .
- " as days,address,comment from {chatban} where banid = ?",
- array($banId),
+ "select banid,(dtmtill - :now)" .
+ " as days,address,comment from {chatban} where banid = :banid",
+ array(
+ ':banid' => $banId,
+ ':now' => time()
+ ),
array('return_rows' => Database::RETURN_ONE_ROW)
);
diff --git a/src/messenger/webim/operator/blocked.php b/src/messenger/webim/operator/blocked.php
index 62b727e4..c653412d 100644
--- a/src/messenger/webim/operator/blocked.php
+++ b/src/messenger/webim/operator/blocked.php
@@ -43,7 +43,7 @@ if (isset($_GET['act']) && $_GET['act'] == 'del') {
}
$blockedList = $db->query(
- "select banid,unix_timestamp(dtmtill) as till,address,comment from {chatban}",
+ "select banid, dtmtill as till,address,comment from {chatban}",
NULL,
array('return_rows' => Database::RETURN_ONE_ROW)
);
diff --git a/src/messenger/webim/operator/history.php b/src/messenger/webim/operator/history.php
index 3c0a6bb7..79ba4460 100644
--- a/src/messenger/webim/operator/history.php
+++ b/src/messenger/webim/operator/history.php
@@ -47,6 +47,8 @@ if ($query !== false) {
}
$page['groupName'] = $groupName;
+ $escapedQuery = $escapedQuery?$escapedQuery:'';
+
$values = array(
':query' => "%{$escapedQuery}%"
);
@@ -66,8 +68,8 @@ if ($query !== false) {
$searchConditions[] = "({chatthread}.userName LIKE :query)";
$searchConditions[] = "({chatthread}.remote LIKE :query)";
}
- select_with_pagintation("DISTINCT unix_timestamp({chatthread}.dtmcreated) as created, " .
- "unix_timestamp({chatthread}.dtmmodified) as modified, {chatthread}.threadid, " .
+ select_with_pagintation("DISTINCT {chatthread}.dtmcreated as created, " .
+ "{chatthread}.dtmmodified as modified, {chatthread}.threadid, " .
"{chatthread}.remote, {chatthread}.agentName, {chatthread}.userName, groupid, " .
"messageCount as size",
"{chatthread}, {chatmessage}",
@@ -75,7 +77,7 @@ if ($query !== false) {
"{chatmessage}.threadid = {chatthread}.threadid",
"(" . implode(' or ', $searchConditions) . ")"
),
- "order by created DESC",
+ "order by {chatthread}.dtmcreated DESC",
"DISTINCT {chatthread}.dtmcreated", $values);
$page['formq'] = topage($query);
diff --git a/src/messenger/webim/operator/restore.php b/src/messenger/webim/operator/restore.php
index b47737bd..c5dc2412 100644
--- a/src/messenger/webim/operator/restore.php
+++ b/src/messenger/webim/operator/restore.php
@@ -42,9 +42,13 @@ if (isset($_POST['loginoremail'])) {
$db = Database::getInstance();
$db->query(
- "update {chatoperator} set dtmrestore = CURRENT_TIMESTAMP, " .
- "vcrestoretoken = ? where operatorid = ?",
- array($token, $torestore['operatorid'])
+ "update {chatoperator} set dtmrestore = :now, " .
+ "vcrestoretoken = :token where operatorid = :operatorid",
+ array(
+ ':now' => time(),
+ ':token' => $token,
+ ':operatorid' => $torestore['operatorid']
+ )
);
$href = get_app_location(true, false) . "/operator/resetpwd.php?id=" . $torestore['operatorid'] . "&token=$token";
diff --git a/src/messenger/webim/operator/statistics.php b/src/messenger/webim/operator/statistics.php
index 4c71c643..79136dd7 100644
--- a/src/messenger/webim/operator/statistics.php
+++ b/src/messenger/webim/operator/statistics.php
@@ -74,9 +74,9 @@ $activetab = 0;
$db = Database::getInstance();
if ($statisticstype == 'bydate') {
$page['reportByDate'] = $db->query(
- "select DATE(t.dtmcreated) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = :kind_agent) as agents, SUM(m.ikind = :kind_user) as users, ROUND(AVG(unix_timestamp(t.dtmchatstarted)-unix_timestamp(t.dtmcreated)),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - unix_timestamp(t.dtmchatstarted)),1) as avgchattime " .
- "from {chatmessage} m, {chatthread} t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM {chatmessage} i WHERE (ikind = :kind_user OR ikind = :kind_agent) GROUP BY i.threadid) tmp " .
- "where m.threadid = t.threadid AND tmp.threadid = t.threadid AND unix_timestamp(t.dtmchatstarted) <> 0 AND unix_timestamp(m.dtmcreated) >= :start AND unix_timestamp(m.dtmcreated) < :end group by DATE(m.dtmcreated) order by m.dtmcreated desc",
+ "select DATE(FROM_UNIXTIME(t.dtmcreated)) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = :kind_agent) as agents, SUM(m.ikind = :kind_user) as users, ROUND(AVG(t.dtmchatstarted-t.dtmcreated),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - t.dtmchatstarted),1) as avgchattime " .
+ "from {chatmessage} m, {chatthread} t, (SELECT i.threadid, MAX(i.dtmcreated) AS lastmsgtime FROM {chatmessage} i WHERE (ikind = :kind_user OR ikind = :kind_agent) GROUP BY i.threadid) tmp " .
+ "where m.threadid = t.threadid AND tmp.threadid = t.threadid AND t.dtmchatstarted <> 0 AND m.dtmcreated >= :start AND m.dtmcreated < :end group by DATE(FROM_UNIXTIME(m.dtmcreated)) order by m.dtmcreated desc",
array(
':kind_agent' => $kind_agent,
':kind_user' => $kind_user,
@@ -87,9 +87,9 @@ if ($statisticstype == 'bydate') {
);
$page['reportByDateTotal'] = $db->query(
- "select DATE(t.dtmcreated) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = :kind_agent) as agents, SUM(m.ikind = :kind_user) as users, ROUND(AVG(unix_timestamp(t.dtmchatstarted)-unix_timestamp(t.dtmcreated)),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - unix_timestamp(t.dtmchatstarted)),1) as avgchattime " .
- "from {chatmessage} m, {chatthread} t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM {chatmessage} i WHERE (ikind = :kind_user OR ikind = :kind_agent) GROUP BY i.threadid) tmp " .
- "where m.threadid = t.threadid AND tmp.threadid = t.threadid AND unix_timestamp(t.dtmchatstarted) <> 0 AND unix_timestamp(m.dtmcreated) >= :start AND unix_timestamp(m.dtmcreated) < :end",
+ "select DATE(FROM_UNIXTIME(t.dtmcreated)) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = :kind_agent) as agents, SUM(m.ikind = :kind_user) as users, ROUND(AVG(t.dtmchatstarted-t.dtmcreated),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - t.dtmchatstarted),1) as avgchattime " .
+ "from {chatmessage} m, {chatthread} t, (SELECT i.threadid, MAX(i.dtmcreated) AS lastmsgtime FROM {chatmessage} i WHERE (ikind = :kind_user OR ikind = :kind_agent) GROUP BY i.threadid) tmp " .
+ "where m.threadid = t.threadid AND tmp.threadid = t.threadid AND t.dtmchatstarted <> 0 AND m.dtmcreated >= :start AND m.dtmcreated < :end",
array(
':kind_agent' => $kind_agent,
':kind_user' => $kind_user,
@@ -104,8 +104,8 @@ if ($statisticstype == 'bydate') {
"select vclocalename as name, COUNT(distinct threadid) as threads, " .
"SUM(ikind = :kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen " .
"from {chatmessage}, {chatoperator} " .
- "where agentId = operatorid AND unix_timestamp(dtmcreated) >= :start " .
- "AND unix_timestamp(dtmcreated) < :end group by operatorid",
+ "where agentId = operatorid AND dtmcreated >= :start " .
+ "AND dtmcreated < :end group by operatorid",
array(
':kind_agent' => $kind_agent,
':start' => $start,
@@ -117,8 +117,8 @@ if ($statisticstype == 'bydate') {
} elseif($statisticstype == 'bypage') {
$page['reportByPage'] = $db->query(
"SELECT COUNT(DISTINCT p.pageid) as visittimes, p.address, COUNT(DISTINCT t.threadid) as chattimes " .
- "FROM {visitedpagestatistics} p LEFT OUTER JOIN {chatthread} t ON (p.address = t.referer AND DATE(p.visittime) = DATE(t.dtmcreated)) " .
- "WHERE unix_timestamp(p.visittime) >= :start AND unix_timestamp(p.visittime) < :end GROUP BY p.address",
+ "FROM {visitedpagestatistics} p LEFT OUTER JOIN {chatthread} t ON (p.address = t.referer AND DATE(FROM_UNIXTIME(p.visittime)) = DATE(FROM_UNIXTIME(t.dtmcreated))) " .
+ "WHERE p.visittime >= :start AND p.visittime < :end GROUP BY p.address",
array(':start' => $start, ':end' => $end),
array('return_rows' => Database::RETURN_ALL_ROWS)
);
diff --git a/src/messenger/webim/operator/threadprocessor.php b/src/messenger/webim/operator/threadprocessor.php
index a33f668d..35994f43 100644
--- a/src/messenger/webim/operator/threadprocessor.php
+++ b/src/messenger/webim/operator/threadprocessor.php
@@ -31,7 +31,7 @@ function thread_info($id)
$db = Database::getInstance();
return $db->query(
"select userName,agentName,remote,userAgent," .
- "unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created," .
+ "dtmmodified as modified, dtmcreated as created," .
"vclocalname as groupName " .
"from {chatthread} left join {chatgroup} on {chatthread}.groupid = {chatgroup}.groupid " .
"where threadid = ?",
diff --git a/src/messenger/webim/operator/update.php b/src/messenger/webim/operator/update.php
index cc71a711..eb6ca428 100644
--- a/src/messenger/webim/operator/update.php
+++ b/src/messenger/webim/operator/update.php
@@ -88,8 +88,8 @@ function thread_to_xml($thread)
$result .= htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'], $thread['remote'], $thread['userid']))) . "";
$result .= "" . htmlspecialchars(get_user_addr($thread['remote'])) . "";
$result .= "" . htmlspecialchars(htmlspecialchars($threadoperator)) . "";
- $result .= "";
- $result .= "" . $thread['unix_timestamp(dtmmodified)'] . "000";
+ $result .= "";
+ $result .= "" . $thread['dtmmodified'] . "000";
if ($banForThread) {
$result .= "" . $banForThread['comment'] . "";
@@ -119,8 +119,8 @@ function print_pending_threads($groupids, $since)
$db = Database::getInstance();
$revision = $since;
- $query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), userTyping, " .
- "unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId, " .
+ $query = "select threadid, userName, agentName, dtmcreated, userTyping, " .
+ "dtmmodified, lrevision, istate, remote, nextagent, agentId, " .
"userid, shownmessageid, userAgent, (select vclocalname from {chatgroup} where {chatgroup}.groupid = {chatthread}.groupid) as groupname " .
"from {chatthread} where lrevision > :since " .
($since <= 0
@@ -181,8 +181,8 @@ function visitor_to_xml($visitor)
// $result .= "" . htmlspecialchars($visitor['userid']) . "";
$result .= "" . htmlspecialchars($visitor['username']) . "";
- $result .= "";
- $result .= "" . $visitor['unix_timestamp(lasttime)'] . "000";
+ $result .= "";
+ $result .= "" . $visitor['lasttime'] . "000";
// $result .= "" . htmlspecialchars($visitor['entry']) . "";
// $result .= "";
@@ -203,7 +203,7 @@ function visitor_to_xml($visitor)
$result .= "";
if ($visitor['invited']) {
- $result .= "" . $visitor['unix_timestamp(invitationtime)'] . "000";
+ $result .= "" . $visitor['invitationtime'] . "000";
$operator = get_operator_name(operator_by_id($visitor['invitedby']));
$result .= "" . htmlspecialchars(htmlspecialchars($operator)) . "";
}
@@ -222,18 +222,24 @@ function print_visitors()
// Remove old visitors
$db->query(
"DELETE FROM {chatsitevisitor} " .
- "WHERE (UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lasttime)) > ? ".
+ "WHERE (:now - lasttime) > :lifetime ".
"AND (threadid IS NULL OR " .
"(SELECT count(*) FROM {chatthread} WHERE threadid = {chatsitevisitor}.threadid " .
"AND istate <> {$state_closed} AND istate <> {$state_left}) = 0)",
- array(Settings::get('tracking_lifetime'))
+ array(
+ ':lifetime' => Settings::get('tracking_lifetime'),
+ ':now' => time()
+ )
);
// Remove old invitations
$db->query(
"UPDATE {chatsitevisitor} SET invited = 0, invitationtime = NULL, invitedby = NULL".
- " WHERE threadid IS NULL AND (UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(invitationtime)) > ?",
- array(Settings::get('invitation_lifetime'))
+ " WHERE threadid IS NULL AND (:now - invitationtime) > :lifetime",
+ array(
+ ':lifetime' => Settings::get('invitation_lifetime'),
+ ':now' => time()
+ )
);
// Remove associations of visitors with closed threads
@@ -245,13 +251,16 @@ function print_visitors()
// Remove old visitors' tracks
$db->query(
- "DELETE FROM {visitedpage} WHERE (UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(visittime)) > ? " .
+ "DELETE FROM {visitedpage} WHERE (:now - visittime) > :lifetime " .
" AND visitorid NOT IN (SELECT visitorid FROM {chatsitevisitor})",
- array(Settings::get('tracking_lifetime'))
+ array(
+ ':lifetime' => Settings::get('tracking_lifetime'),
+ ':now' => time()
+ )
);
- $query = "SELECT visitorid, userid, username, unix_timestamp(firsttime), unix_timestamp(lasttime), " .
- "entry, details, invited, unix_timestamp(invitationtime), invitedby, invitations, chats " .
+ $query = "SELECT visitorid, userid, username, firsttime, lasttime, " .
+ "entry, details, invited, invitationtime, invitedby, invitations, chats " .
"FROM {chatsitevisitor} " .
"WHERE threadid IS NULL " .
"ORDER BY invited, lasttime DESC, invitations";
diff --git a/src/messenger/webim/operator/userhistory.php b/src/messenger/webim/operator/userhistory.php
index c25bb2ed..e8cdfddf 100644
--- a/src/messenger/webim/operator/userhistory.php
+++ b/src/messenger/webim/operator/userhistory.php
@@ -40,8 +40,8 @@ function threads_by_userid($userid)
}
return $db->query(
- "select unix_timestamp(dtmcreated) as created, " .
- "unix_timestamp(dtmmodified) as modified, threadid, remote, agentName, userName " .
+ "select dtmcreated as created, " .
+ "dtmmodified as modified, threadid, remote, agentName, userName " .
"from {chatthread} " .
"where userid=? order by created DESC",
array($userid),