All columns in the databse with 'datetime' type were changed to integer type

This commit is contained in:
Dmitriy Simushev 2012-09-05 12:46:15 +00:00
parent e5ed85ed3f
commit 57f1b175b1
14 changed files with 248 additions and 172 deletions

View File

@ -37,9 +37,9 @@ $dbtables = array(
"userid" => "varchar(255)", "userid" => "varchar(255)",
"agentName" => "varchar(64)", "agentName" => "varchar(64)",
"agentId" => "int NOT NULL DEFAULT 0", "agentId" => "int NOT NULL DEFAULT 0",
"dtmcreated" => "datetime DEFAULT 0", "dtmcreated" => "int NOT NULL DEFAULT 0",
"dtmchatstarted" => "datetime DEFAULT 0", "dtmchatstarted" => "int NOT NULL DEFAULT 0",
"dtmmodified" => "datetime DEFAULT 0", "dtmmodified" => "int NOT NULL DEFAULT 0",
"lrevision" => "int NOT NULL DEFAULT 0", "lrevision" => "int NOT NULL DEFAULT 0",
"istate" => "int NOT NULL DEFAULT 0", "istate" => "int NOT NULL DEFAULT 0",
"ltoken" => "int NOT NULL", "ltoken" => "int NOT NULL",
@ -47,8 +47,8 @@ $dbtables = array(
"referer" => "text", "referer" => "text",
"nextagent" => "int NOT NULL DEFAULT 0", "nextagent" => "int NOT NULL DEFAULT 0",
"locale" => "varchar(8)", "locale" => "varchar(8)",
"lastpinguser" => "datetime DEFAULT 0", "lastpinguser" => "int NOT NULL DEFAULT 0",
"lastpingagent" => "datetime DEFAULT 0", "lastpingagent" => "int NOT NULL DEFAULT 0",
"userTyping" => "int DEFAULT 0", "userTyping" => "int DEFAULT 0",
"agentTyping" => "int DEFAULT 0", "agentTyping" => "int DEFAULT 0",
"shownmessageid" => "int NOT NULL DEFAULT 0", "shownmessageid" => "int NOT NULL DEFAULT 0",
@ -63,7 +63,7 @@ $dbtables = array(
"ikind" => "int NOT NULL", "ikind" => "int NOT NULL",
"agentId" => "int NOT NULL DEFAULT 0", "agentId" => "int NOT NULL DEFAULT 0",
"tmessage" => "text NOT NULL", "tmessage" => "text NOT NULL",
"dtmcreated" => "datetime DEFAULT 0", "dtmcreated" => "int NOT NULL DEFAULT 0",
"tname" => "varchar(64)" "tname" => "varchar(64)"
), ),
@ -74,13 +74,13 @@ $dbtables = array(
"vclocalename" => "varchar(64) NOT NULL", "vclocalename" => "varchar(64) NOT NULL",
"vccommonname" => "varchar(64) NOT NULL", "vccommonname" => "varchar(64) NOT NULL",
"vcemail" => "varchar(64)", "vcemail" => "varchar(64)",
"dtmlastvisited" => "datetime DEFAULT 0", "dtmlastvisited" => "int NOT NULL DEFAULT 0",
"istatus" => "int DEFAULT 0", /* 0 - online, 1 - away */ "istatus" => "int DEFAULT 0", /* 0 - online, 1 - away */
"idisabled" => "int DEFAULT 0", "idisabled" => "int DEFAULT 0",
"vcavatar" => "varchar(255)", "vcavatar" => "varchar(255)",
"vcjabbername" => "varchar(255)", "vcjabbername" => "varchar(255)",
"iperm" => "int DEFAULT 65535", "iperm" => "int DEFAULT 65535",
"dtmrestore" => "datetime DEFAULT 0", "dtmrestore" => "int NOT NULL DEFAULT 0",
"vcrestoretoken" => "varchar(64)", "vcrestoretoken" => "varchar(64)",
), ),
@ -95,8 +95,8 @@ $dbtables = array(
"${mysqlprefix}chatban" => array( "${mysqlprefix}chatban" => array(
"banid" => "INT NOT NULL auto_increment PRIMARY KEY", "banid" => "INT NOT NULL auto_increment PRIMARY KEY",
"dtmcreated" => "datetime DEFAULT 0", "dtmcreated" => "int NOT NULL DEFAULT 0",
"dtmtill" => "datetime DEFAULT 0", "dtmtill" => "int NOT NULL DEFAULT 0",
"address" => "varchar(255)", "address" => "varchar(255)",
"comment" => "varchar(255)", "comment" => "varchar(255)",
"blockedCount" => "int DEFAULT 0" "blockedCount" => "int DEFAULT 0"
@ -120,12 +120,12 @@ $dbtables = array(
"visitorid" => "INT NOT NULL auto_increment PRIMARY KEY", "visitorid" => "INT NOT NULL auto_increment PRIMARY KEY",
"userid" => "varchar(64) NOT NULL", "userid" => "varchar(64) NOT NULL",
"username" => "varchar(255)", "username" => "varchar(255)",
"firsttime" => "datetime NOT NULL DEFAULT 0", "firsttime" => "int NOT NULL DEFAULT 0",
"lasttime" => "datetime NOT NULL DEFAULT 0", "lasttime" => "int NOT NULL DEFAULT 0",
"entry" => "text NOT NULL", "entry" => "text NOT NULL",
"details" => "text NOT NULL", "details" => "text NOT NULL",
"invited" => "tinyint(1) NOT NULL DEFAULT 0", "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", "invitedby" => "INT references ${mysqlprefix}chatoperator(operatorid) on delete set 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",
@ -135,14 +135,14 @@ $dbtables = array(
"${mysqlprefix}visitedpage" => array( "${mysqlprefix}visitedpage" => array(
"pageid" => "INT NOT NULL auto_increment PRIMARY KEY", "pageid" => "INT NOT NULL auto_increment PRIMARY KEY",
"address" => "varchar(1024)", "address" => "varchar(1024)",
"visittime" => "datetime NOT NULL DEFAULT 0", "visittime" => "int NOT NULL DEFAULT 0",
"visitorid" => "INT", "visitorid" => "INT",
), ),
"${mysqlprefix}visitedpagestatistics" => array( "${mysqlprefix}visitedpagestatistics" => array(
"pageid" => "INT NOT NULL auto_increment PRIMARY KEY", "pageid" => "INT NOT NULL auto_increment PRIMARY KEY",
"address" => "varchar(1024)", "address" => "varchar(1024)",
"visittime" => "datetime NOT NULL DEFAULT 0" "visittime" => "int NOT NULL DEFAULT 0"
), ),
); );

View File

@ -86,7 +86,7 @@ if ($act == "silentcreateall") {
} }
if (in_array("${mysqlprefix}chatthread.dtmchatstarted", $absent_columns)) { 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); runsql("update ${mysqlprefix}chatthread set dtmchatstarted = dtmcreated", $link);
} }
@ -142,7 +142,7 @@ if ($act == "silentcreateall") {
} }
if (in_array("${mysqlprefix}chatoperator.dtmrestore", $absent_columns)) { 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)) { if (in_array("${mysqlprefix}chatoperator.vcrestoretoken", $absent_columns)) {

View File

@ -64,19 +64,20 @@ function next_revision()
function post_message_($threadid, $kind, $message, $from = null, $utime = null, $opid = null) function post_message_($threadid, $kind, $message, $from = null, $utime = null, $opid = null)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$query = "insert into {chatmessage} " . $query = "insert into {chatmessage} " .
"(threadid,ikind,tmessage,tname,agentId,dtmcreated) " . "(threadid,ikind,tmessage,tname,agentId,dtmcreated) " .
"values (?,?,?,?,?,".($utime?"FROM_UNIXTIME(?)":"CURRENT_TIMESTAMP").")"; "values (:threadid,:kind,:message,:name,:agentid,:created)";
$values = array( $values = array(
$threadid, ':threadid' => $threadid,
$kind, ':kind' => $kind,
$message, ':message' => $message,
($from ? $from : "null"), ':name' => ($from ? $from : "null"),
($opid ? $opid : 0) ':agentid' => ($opid ? $opid : 0),
':created' => ($utime ? $utime : time())
); );
if ($utime) {
$values[] = $utime;
}
$db->query($query, $values); $db->query($query, $values);
return $db->insertedId(); return $db->insertedId();
} }
@ -135,7 +136,7 @@ function get_messages($threadid, $meth, $isuser, &$lastid)
$db = Database::getInstance(); $db = Database::getInstance();
$msgs = $db->query( $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 " . "where threadid = :threadid and messageid > :lastid " .
($isuser ? "and ikind <> {$kind_for_agent} " : "") . ($isuser ? "and ikind <> {$kind_for_agent} " : "") .
"order by messageid", "order by messageid",
@ -177,7 +178,7 @@ function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agen
{ {
global $webim_encoding, $webimroot, $connection_timeout; global $webim_encoding, $webimroot, $connection_timeout;
$threadid = $thread['threadid']; $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"; && $thread[$isuser ? "agentTyping" : "userTyping"] == "1" ? "1" : "0";
if ($format == "xml") { if ($format == "xml") {
@ -532,11 +533,10 @@ function ping_thread($thread, $isuser, $istyping)
$db = Database::getInstance(); $db = Database::getInstance();
$params = array(($isuser ? "lastpinguser" : "lastpingagent") => "CURRENT_TIMESTAMP", $params = array(($isuser ? "lastpinguser" : "lastpingagent") => time(),
($isuser ? "userTyping" : "agentTyping") => ($istyping ? "1" : "0")); ($isuser ? "userTyping" : "agentTyping") => ($istyping ? "1" : "0"));
$lastping = $thread[$isuser ? "lpagent" : "lpuser"]; $lastping = $thread[$isuser ? "lpagent" : "lpuser"];
$current = $thread['current'];
if ($thread['istate'] == $state_loading && $isuser) { if ($thread['istate'] == $state_loading && $isuser) {
$params['istate'] = $state_queue; $params['istate'] = $state_queue;
@ -544,7 +544,7 @@ function ping_thread($thread, $isuser, $istyping)
return; return;
} }
if ($lastping > 0 && abs($current - $lastping) > $connection_timeout) { if ($lastping > 0 && abs(time() - $lastping) > $connection_timeout) {
$params[$isuser ? "lastpingagent" : "lastpinguser"] = "0"; $params[$isuser ? "lastpingagent" : "lastpinguser"] = "0";
if (!$isuser) { if (!$isuser) {
$message_to_post = getstring_("chat.status.user.dead", $thread['locale']); $message_to_post = getstring_("chat.status.user.dead", $thread['locale']);
@ -566,13 +566,9 @@ function ping_thread($thread, $isuser, $istyping)
if (strlen($clause) > 0) { if (strlen($clause) > 0) {
$clause .= ", "; $clause .= ", ";
} }
if (($k == 'lastpinguser' || $k == 'lastpingagent') && $v == 'CURRENT_TIMESTAMP') {
$clause .= $k . " = CURRENT_TIMESTAMP";
}else{
$clause .= $k . "=?"; $clause .= $k . "=?";
$values[] = $v; $values[] = $v;
} }
}
$values[] = $thread['threadid']; $values[] = $thread['threadid'];
$db->query( $db->query(
@ -585,24 +581,18 @@ function commit_thread($threadid, $params)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$timestamp_allowed_for = array(
'dtmcreated',
'dtmchatstarted',
'dtmmodified',
'lastpinguser',
'lastpingagent'
);
$query = "update {chatthread} t " . $query = "update {chatthread} t " .
"set lrevision = ?, dtmmodified = CURRENT_TIMESTAMP"; "set lrevision = ?, dtmmodified = ?";
$values = array(next_revision());
foreach ($params as $k => $v) { $values = array();
if (in_array($k, $timestamp_allowed_for) && strcasecmp($v,'CURRENT_TIMESTAMP')) { $values[] = next_revision();
$query .= ", " . $k . " = CURRENT_TIMESTAMP"; $values[] = time();
} else {
$query .= ", " . $k . "=?"; foreach ($params as $name => $value) {
$values[] = $v; $query .= ", {$name} = ?" ;
} $values[] = $value;
} }
$query .= " where threadid = ?"; $query .= " where threadid = ?";
$values[] = $threadid; $values[] = $threadid;
@ -659,21 +649,22 @@ function close_old_threads()
$db = Database::getInstance(); $db = Database::getInstance();
$query = "update {chatthread} set lrevision = :next_revision, " . $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 " . "where istate <> :state_closed and istate <> :state_left " .
"and ((lastpingagent <> 0 and lastpinguser <> 0 and " . "and ((lastpingagent <> 0 and lastpinguser <> 0 and " .
"(ABS(UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lastpinguser)) > ". "(ABS(:now - lastpinguser) > ".
":thread_lifetime and " . ":thread_lifetime and " .
"ABS(UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lastpingagent)) > ". "ABS(:now - lastpingagent) > ".
":thread_lifetime)) or " . ":thread_lifetime)) or " .
"lastpingagent = 0 and lastpinguser <> 0 and " . "lastpingagent = 0 and lastpinguser <> 0 and " .
"ABS(UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lastpinguser)) > ". "ABS(:now - lastpinguser) > ".
":thread_lifetime)"; ":thread_lifetime)";
$db->query( $db->query(
$query, $query,
array( array(
':next_revision' => next_revision(), ':next_revision' => next_revision(),
':now' => time(),
':state_closed' => $state_closed, ':state_closed' => $state_closed,
':state_left' => $state_left, ':state_left' => $state_left,
':thread_lifetime' => Settings::get('thread_lifetime') ':thread_lifetime' => Settings::get('thread_lifetime')
@ -686,13 +677,16 @@ function thread_by_id($id)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping, " . "select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping, " .
"agentTyping,unix_timestamp(dtmmodified) as modified, " . "agentTyping,dtmmodified as modified, " .
"unix_timestamp(dtmcreated) as created, " . "dtmcreated as created, " .
"unix_timestamp(dtmchatstarted) as chatstarted,remote,referer,locale," . "dtmchatstarted as chatstarted,remote,referer,locale," .
"unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent," . "lastpinguser as lpuser,lastpingagent as lpagent," .
"unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent,shownmessageid,userid, " . "nextagent,shownmessageid,userid, " .
"userAgent,groupid from {chatthread} where threadid = ?", "userAgent,groupid from {chatthread} where threadid = :threadid",
array($id), array(
':threadid' => $id,
':now' => time()
),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
} }
@ -702,8 +696,11 @@ function ban_for_addr($addr)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"select banid,comment from {chatban} " . "select banid,comment from {chatban} " .
"where unix_timestamp(dtmtill) > unix_timestamp(CURRENT_TIMESTAMP) AND address = ?", "where dtmtill > :now AND address = :addr",
array($addr), array(
':addr' => $addr,
':now' => time()
),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
} }
@ -712,26 +709,49 @@ function create_thread($groupid, $username, $remoteHost, $referer, $lang, $useri
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$query = "insert into {chatthread} (userName,userid,ltoken,remote,referer, " . $query = "insert into {chatthread} (" .
"lrevision,locale,userAgent,dtmcreated,dtmmodified,istate" . "userName, " .
($groupid ? ",groupid" : "") . ") values " . "userid, " .
"(?,?,?,?,?,?,?,?,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,?" . "ltoken, " .
($groupid ? ", ?" : "") . ")"; "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( $values = array(
$username, ':username' => $username,
$userid, ':userid' => $userid,
next_token(), ':ltoken' => next_token(),
$remoteHost, ':remote' => $remoteHost,
$referer, ':referer' => $referer,
next_revision(), ':lrevision' => next_revision(),
$lang, ':locale' => $lang,
$userbrowser, ':useragent' => $userbrowser,
$initialState ':now' => time(),
':istate' => $initialState
); );
if ($groupid) { if ($groupid) {
$values[] = $groupid; $values[':groupid'] = $groupid;
} }
$db->query($query, $values); $db->query($query, $values);
@ -749,7 +769,7 @@ function do_take_thread($threadid, $operatorId, $operatorName, $chatstart = fals
"agentId" => $operatorId, "agentId" => $operatorId,
"agentName" => $operatorName); "agentName" => $operatorName);
if ($chatstart){ if ($chatstart){
$params['dtmchatstarted'] = "CURRENT_TIMESTAMP"; $params['dtmchatstarted'] = time();
} }
commit_thread($threadid, $params); commit_thread($threadid, $params);
} }

View File

@ -35,9 +35,13 @@ function invitation_invite($visitorid, $operatorid)
if (!invitation_check($visitorid)) { if (!invitation_check($visitorid)) {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"update {chatsitevisitor} set invited = 1, invitedby = ?, " . "update {chatsitevisitor} set invited = 1, invitedby = :operatorid, " .
"invitationtime = now(), invitations = invitations + 1 where visitorid = ?", "invitationtime = :now, invitations = invitations + 1 where visitorid = :visitorid",
array($operatorid, $visitorid) array(
':operatorid' => $operatorid,
':visitorid' => $visitorid,
':now' => time()
)
); );
return invitation_check($visitorid); return invitation_check($visitorid);
} else { } else {

View File

@ -97,7 +97,7 @@ function get_operators_list($options)
$orderby = "vclogin"; $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}" . "from {chatoperator}" .
( (
empty($options['isolated_operator_id']) ? "" : empty($options['isolated_operator_id']) ? "" :
@ -111,13 +111,17 @@ function get_operators_list($options)
) . ) .
" order by " . $orderby; " order by " . $orderby;
$values = array(
':now' => time()
);
if (! empty($options['isolated_operator_id'])) {
$values[':operatorid'] = $options['isolated_operator_id'];
}
$operators = $db->query( $operators = $db->query(
$query, $query,
( $values,
empty($options['isolated_operator_id'])
? array()
: array(':operatorid' => $options['isolated_operator_id'])
),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
@ -129,9 +133,9 @@ function operator_get_all()
$db = Database::getInstance(); $db = Database::getInstance();
return $operators = $db->query( return $operators = $db->query(
"select operatorid, vclogin, vclocalename, vccommonname, istatus, idisabled, " . "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", "from {chatoperator} order by vclogin",
NULL, array(':now' => time()),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
} }
@ -141,21 +145,24 @@ function get_operators_from_adjacent_groups($operator)
$db = Database::getInstance(); $db = Database::getInstance();
$query = "select distinct {chatoperator}.operatorid, vclogin, vclocalename,vccommonname, " . $query = "select distinct {chatoperator}.operatorid, vclogin, vclocalename,vccommonname, " .
"istatus, idisabled, " . "istatus, idisabled, " .
"(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " . "(:now - dtmlastvisited) as time " .
"from {chatoperator}, {chatgroupoperator} " . "from {chatoperator}, {chatgroupoperator} " .
"where {chatoperator}.operatorid = {chatgroupoperator}.operatorid " . "where {chatoperator}.operatorid = {chatgroupoperator}.operatorid " .
"and {chatgroupoperator}.groupid in " . "and {chatgroupoperator}.groupid in " .
"(select g.groupid from {chatgroup} g, " . "(select g.groupid from {chatgroup} g, " .
"(select distinct parent from {chatgroup}, {chatgroupoperator} " . "(select distinct parent from {chatgroup}, {chatgroupoperator} " .
"where {chatgroup}.groupid = {chatgroupoperator}.groupid " . "where {chatgroup}.groupid = {chatgroupoperator}.groupid " .
"and {chatgroupoperator}.operatorid = ?) i " . "and {chatgroupoperator}.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";
return $db->query( return $db->query(
$query, $query,
array($operator['operatorid']), array(
':operatorid' => $operator['operatorid'],
':now' => time()
),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );
} }
@ -245,9 +252,13 @@ function notify_operator_alive($operatorid, $istatus)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"update {chatoperator} set istatus = ?, dtmlastvisited = CURRENT_TIMESTAMP " . "update {chatoperator} set istatus = :istatus, dtmlastvisited = :now " .
"where operatorid = ?", "where operatorid = :operatorid",
array($istatus, $operatorid) array(
':istatus' => $istatus,
':now' => time(),
':operatorid' => $operatorid
)
); );
} }
@ -255,7 +266,7 @@ function has_online_operators($groupid = "")
{ {
$db = Database::getInstance(); $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) { if ($groupid) {
$query .= ", {chatgroupoperator}, {chatgroup} where {chatgroup}.groupid = {chatgroupoperator}.groupid and " . $query .= ", {chatgroupoperator}, {chatgroup} where {chatgroup}.groupid = {chatgroupoperator}.groupid and " .
"({chatgroup}.groupid = :groupid or {chatgroup}.parent = :groupid) and {chatoperator}.operatorid = " . "({chatgroup}.groupid = :groupid or {chatgroup}.parent = :groupid) and {chatoperator}.operatorid = " .
@ -271,7 +282,10 @@ function has_online_operators($groupid = "")
$row = $db->query( $row = $db->query(
$query, $query,
array(':groupid'=>$groupid), array(
':groupid'=>$groupid,
':now' => time()
),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
return $row['time'] < Settings::get('online_timeout') && $row['total'] > 0; return $row['time'] < Settings::get('online_timeout') && $row['total'] > 0;
@ -282,9 +296,12 @@ function is_operator_online($operatorid)
$db = Database::getInstance(); $db = Database::getInstance();
$row = $db->query( $row = $db->query(
"select count(*) as total, " . "select count(*) as total, " .
"min(unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time " . "min(:now - dtmlastvisited) as time " .
"from {chatoperator} where operatorid = ?", "from {chatoperator} where operatorid = :operatorid",
array($operatorid), array(
':now' => time(),
':operatorid' => $operatorid
),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );
@ -548,28 +565,32 @@ function get_groups_($checkaway, $operator, $order = NULL)
$orderby = "iweight, vclocalname"; $orderby = "iweight, vclocalname";
} }
$values = array(); $values = array(
':now' => time()
);
$query = "select {chatgroup}.groupid as groupid, {chatgroup}.parent as parent, vclocalname, vclocaldescription, iweight" . $query = "select {chatgroup}.groupid as groupid, {chatgroup}.parent as parent, vclocalname, vclocaldescription, iweight" .
", (SELECT count(*) from {chatgroupoperator} where {chatgroup}.groupid = " . ", (SELECT count(*) from {chatgroupoperator} where {chatgroup}.groupid = " .
"{chatgroupoperator}.groupid) as inumofagents" . "{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 " . "from {chatgroupoperator}, {chatoperator} where istatus = 0 and " .
"{chatgroup}.groupid = {chatgroupoperator}.groupid " . "{chatgroup}.groupid = {chatgroupoperator}.groupid " .
"and {chatgroupoperator}.operatorid = {chatoperator}.operatorid) as ilastseen" . "and {chatgroupoperator}.operatorid = {chatoperator}.operatorid) as ilastseen" .
($checkaway ($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 " . "from {chatgroupoperator}, {chatoperator} where istatus <> 0 and " .
"{chatgroup}.groupid = {chatgroupoperator}.groupid " . "{chatgroup}.groupid = {chatgroupoperator}.groupid " .
"and {chatgroupoperator}.operatorid = {chatoperator}.operatorid) as ilastseenaway" "and {chatgroupoperator}.operatorid = {chatoperator}.operatorid) as ilastseenaway"
: "" : ""
) . ) .
" from {chatgroup} "; " from {chatgroup} ";
if ($operator) { if ($operator) {
$query .= ", (select distinct parent from {chatgroup}, {chatgroupoperator} " . $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 "; "where {chatgroup}.groupid = i.parent or {chatgroup}.parent = i.parent ";
$values[] = $operator['operatorid']; $values[':operatorid'] = $operator['operatorid'];
} }
$query .= " order by " . $orderby; $query .= " order by " . $orderby;
$groups = $db->query( $groups = $db->query(
$query, $query,

View File

@ -27,9 +27,12 @@ function track_visitor($visitorid, $entry, $referer)
} else { } else {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"update {chatsitevisitor} set lasttime = CURRENT_TIMESTAMP " . "update {chatsitevisitor} set lasttime = :now " .
"where visitorid=?", "where visitorid = :visitorid",
array($visitor['visitorid']) array(
':vidsitorid' => $visitor['visitorid'],
':now' => time()
)
); );
track_visit_page($visitor['visitorid'], $referer); track_visit_page($visitor['visitorid'], $referer);
return $visitor['visitorid']; return $visitor['visitorid'];
@ -43,12 +46,13 @@ function track_visitor_start($entry, $referer)
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"insert into {chatsitevisitor} (userid,username,firsttime,lasttime,entry,details) ". "insert into {chatsitevisitor} (userid,username,firsttime,lasttime,entry,details) ".
"values (?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?)", "values (:userid, :username, :now, :now, :entry, :details)",
array( array(
$visitor['id'], ':userid' => $visitor['id'],
$visitor['name'], ':username' => $visitor['name'],
$entry, ':now' => time(),
track_build_details() ':entry' => $entry,
':details' => track_build_details()
) )
); );
@ -97,13 +101,20 @@ function track_visit_page($visitorid, $page)
if ( $lastpage['address'] != $page ) { if ( $lastpage['address'] != $page ) {
$db->query( $db->query(
"insert into {visitedpage} (visitorid, address, visittime) " . "insert into {visitedpage} (visitorid, address, visittime) " .
"values (?, ?, CURRENT_TIMESTAMP)", "values (:visitorid, :page, :now)",
array($visitorid, $page) array(
':visitorid' => $visitorid,
':page' => $page,
':now' => time()
)
); );
$db->query( $db->query(
"insert into {visitedpagestatistics} (address, visittime) " . "insert into {visitedpagestatistics} (address, visittime) " .
"values (?, CURRENT_TIMESTAMP)", "values (:page, :now)",
array($page) array(
':page' => $page,
':now' => time()
)
); );
} }
} }
@ -112,7 +123,7 @@ function track_get_path($visitor)
{ {
$db = Database::getInstance(); $db = Database::getInstance();
$query_result = $db->query( $query_result = $db->query(
"select address, UNIX_TIMESTAMP(visittime) as visittime from {visitedpage} " . "select address, visittime from {visitedpage} " .
"where visitorid = ?", "where visitorid = ?",
array($visitor['visitorid']), array($visitor['visitorid']),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)

View File

@ -55,26 +55,28 @@ if (isset($_POST['address'])) {
if (count($errors) == 0) { if (count($errors) == 0) {
$db = Database::getInstance(); $db = Database::getInstance();
$utime = time() + $days * 24 * 60 * 60; $now = time();
$till_time = $now + $days * 24 * 60 * 60;
if (!$banId) { if (!$banId) {
$db->query( $db->query(
"insert into {chatban} (dtmcreated,dtmtill,address,comment) " . "insert into {chatban} (dtmcreated,dtmtill,address,comment) " .
"values (CURRENT_TIMESTAMP,FROM_UNIXTIME(?),?,?)", "values (:now,:till,:address,:comment)",
array( array(
$utime, ':now' => $now,
$address, ':till' => $till_time,
$comment ':address' => $address,
':comment' => $comment
) )
); );
} else { } else {
$db->query( $db->query(
"update {chatban} set dtmtill = FROM_UNIXTIME(?),address = ?, " . "update {chatban} set dtmtill = :till,address = :address, " .
"comment = ? where banid = ?", "comment = :comment where banid = :banid",
array( array(
$utime, ':till' => $till_time,
$address, ':address' => $address,
$comment, ':comment' => $comment,
$banId ':banid' => $banId
) )
); );
} }
@ -97,9 +99,12 @@ if (isset($_POST['address'])) {
$banId = verifyparam('id', "/^\d{1,9}$/"); $banId = verifyparam('id', "/^\d{1,9}$/");
$db = Database::getInstance(); $db = Database::getInstance();
$ban = $db->query( $ban = $db->query(
"select banid,(unix_timestamp(dtmtill)-unix_timestamp(CURRENT_TIMESTAMP))" . "select banid,(dtmtill - :now)" .
" as days,address,comment from {chatban} where banid = ?", " as days,address,comment from {chatban} where banid = :banid",
array($banId), array(
':banid' => $banId,
':now' => time()
),
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );

View File

@ -43,7 +43,7 @@ if (isset($_GET['act']) && $_GET['act'] == 'del') {
} }
$blockedList = $db->query( $blockedList = $db->query(
"select banid,unix_timestamp(dtmtill) as till,address,comment from {chatban}", "select banid, dtmtill as till,address,comment from {chatban}",
NULL, NULL,
array('return_rows' => Database::RETURN_ONE_ROW) array('return_rows' => Database::RETURN_ONE_ROW)
); );

View File

@ -47,6 +47,8 @@ if ($query !== false) {
} }
$page['groupName'] = $groupName; $page['groupName'] = $groupName;
$escapedQuery = $escapedQuery?$escapedQuery:'';
$values = array( $values = array(
':query' => "%{$escapedQuery}%" ':query' => "%{$escapedQuery}%"
); );
@ -66,8 +68,8 @@ if ($query !== false) {
$searchConditions[] = "({chatthread}.userName LIKE :query)"; $searchConditions[] = "({chatthread}.userName LIKE :query)";
$searchConditions[] = "({chatthread}.remote LIKE :query)"; $searchConditions[] = "({chatthread}.remote LIKE :query)";
} }
select_with_pagintation("DISTINCT unix_timestamp({chatthread}.dtmcreated) as created, " . select_with_pagintation("DISTINCT {chatthread}.dtmcreated as created, " .
"unix_timestamp({chatthread}.dtmmodified) as modified, {chatthread}.threadid, " . "{chatthread}.dtmmodified as modified, {chatthread}.threadid, " .
"{chatthread}.remote, {chatthread}.agentName, {chatthread}.userName, groupid, " . "{chatthread}.remote, {chatthread}.agentName, {chatthread}.userName, groupid, " .
"messageCount as size", "messageCount as size",
"{chatthread}, {chatmessage}", "{chatthread}, {chatmessage}",
@ -75,7 +77,7 @@ if ($query !== false) {
"{chatmessage}.threadid = {chatthread}.threadid", "{chatmessage}.threadid = {chatthread}.threadid",
"(" . implode(' or ', $searchConditions) . ")" "(" . implode(' or ', $searchConditions) . ")"
), ),
"order by created DESC", "order by {chatthread}.dtmcreated DESC",
"DISTINCT {chatthread}.dtmcreated", $values); "DISTINCT {chatthread}.dtmcreated", $values);
$page['formq'] = topage($query); $page['formq'] = topage($query);

View File

@ -42,9 +42,13 @@ if (isset($_POST['loginoremail'])) {
$db = Database::getInstance(); $db = Database::getInstance();
$db->query( $db->query(
"update {chatoperator} set dtmrestore = CURRENT_TIMESTAMP, " . "update {chatoperator} set dtmrestore = :now, " .
"vcrestoretoken = ? where operatorid = ?", "vcrestoretoken = :token where operatorid = :operatorid",
array($token, $torestore['operatorid']) array(
':now' => time(),
':token' => $token,
':operatorid' => $torestore['operatorid']
)
); );
$href = get_app_location(true, false) . "/operator/resetpwd.php?id=" . $torestore['operatorid'] . "&token=$token"; $href = get_app_location(true, false) . "/operator/resetpwd.php?id=" . $torestore['operatorid'] . "&token=$token";

View File

@ -74,9 +74,9 @@ $activetab = 0;
$db = Database::getInstance(); $db = Database::getInstance();
if ($statisticstype == 'bydate') { if ($statisticstype == 'bydate') {
$page['reportByDate'] = $db->query( $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 " . "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, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM {chatmessage} i WHERE (ikind = :kind_user OR ikind = :kind_agent) GROUP BY i.threadid) tmp " . "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 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", "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( array(
':kind_agent' => $kind_agent, ':kind_agent' => $kind_agent,
':kind_user' => $kind_user, ':kind_user' => $kind_user,
@ -87,9 +87,9 @@ if ($statisticstype == 'bydate') {
); );
$page['reportByDateTotal'] = $db->query( $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 " . "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, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM {chatmessage} i WHERE (ikind = :kind_user OR ikind = :kind_agent) GROUP BY i.threadid) tmp " . "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 unix_timestamp(t.dtmchatstarted) <> 0 AND unix_timestamp(m.dtmcreated) >= :start AND unix_timestamp(m.dtmcreated) < :end", "where m.threadid = t.threadid AND tmp.threadid = t.threadid AND t.dtmchatstarted <> 0 AND m.dtmcreated >= :start AND m.dtmcreated < :end",
array( array(
':kind_agent' => $kind_agent, ':kind_agent' => $kind_agent,
':kind_user' => $kind_user, ':kind_user' => $kind_user,
@ -104,8 +104,8 @@ if ($statisticstype == 'bydate') {
"select vclocalename as name, COUNT(distinct threadid) as threads, " . "select vclocalename as name, COUNT(distinct threadid) as threads, " .
"SUM(ikind = :kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen " . "SUM(ikind = :kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen " .
"from {chatmessage}, {chatoperator} " . "from {chatmessage}, {chatoperator} " .
"where agentId = operatorid AND unix_timestamp(dtmcreated) >= :start " . "where agentId = operatorid AND dtmcreated >= :start " .
"AND unix_timestamp(dtmcreated) < :end group by operatorid", "AND dtmcreated < :end group by operatorid",
array( array(
':kind_agent' => $kind_agent, ':kind_agent' => $kind_agent,
':start' => $start, ':start' => $start,
@ -117,8 +117,8 @@ if ($statisticstype == 'bydate') {
} elseif($statisticstype == 'bypage') { } elseif($statisticstype == 'bypage') {
$page['reportByPage'] = $db->query( $page['reportByPage'] = $db->query(
"SELECT COUNT(DISTINCT p.pageid) as visittimes, p.address, COUNT(DISTINCT t.threadid) as chattimes " . "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)) " . "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 unix_timestamp(p.visittime) >= :start AND unix_timestamp(p.visittime) < :end GROUP BY p.address", "WHERE p.visittime >= :start AND p.visittime < :end GROUP BY p.address",
array(':start' => $start, ':end' => $end), array(':start' => $start, ':end' => $end),
array('return_rows' => Database::RETURN_ALL_ROWS) array('return_rows' => Database::RETURN_ALL_ROWS)
); );

View File

@ -31,7 +31,7 @@ function thread_info($id)
$db = Database::getInstance(); $db = Database::getInstance();
return $db->query( return $db->query(
"select userName,agentName,remote,userAgent," . "select userName,agentName,remote,userAgent," .
"unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created," . "dtmmodified as modified, dtmcreated as created," .
"vclocalname as groupName " . "vclocalname as groupName " .
"from {chatthread} left join {chatgroup} on {chatthread}.groupid = {chatgroup}.groupid " . "from {chatthread} left join {chatgroup} on {chatthread}.groupid = {chatgroup}.groupid " .
"where threadid = ?", "where threadid = ?",

View File

@ -88,8 +88,8 @@ function thread_to_xml($thread)
$result .= htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'], $thread['remote'], $thread['userid']))) . "</name>"; $result .= htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'], $thread['remote'], $thread['userid']))) . "</name>";
$result .= "<addr>" . htmlspecialchars(get_user_addr($thread['remote'])) . "</addr>"; $result .= "<addr>" . htmlspecialchars(get_user_addr($thread['remote'])) . "</addr>";
$result .= "<agent>" . htmlspecialchars(htmlspecialchars($threadoperator)) . "</agent>"; $result .= "<agent>" . htmlspecialchars(htmlspecialchars($threadoperator)) . "</agent>";
$result .= "<time>" . $thread['unix_timestamp(dtmcreated)'] . "000</time>"; $result .= "<time>" . $thread['dtmcreated'] . "000</time>";
$result .= "<modified>" . $thread['unix_timestamp(dtmmodified)'] . "000</modified>"; $result .= "<modified>" . $thread['dtmmodified'] . "000</modified>";
if ($banForThread) { if ($banForThread) {
$result .= "<reason>" . $banForThread['comment'] . "</reason>"; $result .= "<reason>" . $banForThread['comment'] . "</reason>";
@ -119,8 +119,8 @@ function print_pending_threads($groupids, $since)
$db = Database::getInstance(); $db = Database::getInstance();
$revision = $since; $revision = $since;
$query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), userTyping, " . $query = "select threadid, userName, agentName, dtmcreated, userTyping, " .
"unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId, " . "dtmmodified, lrevision, istate, remote, nextagent, agentId, " .
"userid, shownmessageid, userAgent, (select vclocalname from {chatgroup} where {chatgroup}.groupid = {chatthread}.groupid) as groupname " . "userid, shownmessageid, userAgent, (select vclocalname from {chatgroup} where {chatgroup}.groupid = {chatthread}.groupid) as groupname " .
"from {chatthread} where lrevision > :since " . "from {chatthread} where lrevision > :since " .
($since <= 0 ($since <= 0
@ -181,8 +181,8 @@ function visitor_to_xml($visitor)
// $result .= "<userid>" . htmlspecialchars($visitor['userid']) . "</userid>"; // $result .= "<userid>" . htmlspecialchars($visitor['userid']) . "</userid>";
$result .= "<username>" . htmlspecialchars($visitor['username']) . "</username>"; $result .= "<username>" . htmlspecialchars($visitor['username']) . "</username>";
$result .= "<time>" . $visitor['unix_timestamp(firsttime)'] . "000</time>"; $result .= "<time>" . $visitor['firsttime'] . "000</time>";
$result .= "<modified>" . $visitor['unix_timestamp(lasttime)'] . "000</modified>"; $result .= "<modified>" . $visitor['lasttime'] . "000</modified>";
// $result .= "<entry>" . htmlspecialchars($visitor['entry']) . "</entry>"; // $result .= "<entry>" . htmlspecialchars($visitor['entry']) . "</entry>";
// $result .= "<path>"; // $result .= "<path>";
@ -203,7 +203,7 @@ function visitor_to_xml($visitor)
$result .= "<invitation>"; $result .= "<invitation>";
if ($visitor['invited']) { if ($visitor['invited']) {
$result .= "<invitationtime>" . $visitor['unix_timestamp(invitationtime)'] . "000</invitationtime>"; $result .= "<invitationtime>" . $visitor['invitationtime'] . "000</invitationtime>";
$operator = get_operator_name(operator_by_id($visitor['invitedby'])); $operator = get_operator_name(operator_by_id($visitor['invitedby']));
$result .= "<operator>" . htmlspecialchars(htmlspecialchars($operator)) . "</operator>"; $result .= "<operator>" . htmlspecialchars(htmlspecialchars($operator)) . "</operator>";
} }
@ -222,18 +222,24 @@ function print_visitors()
// Remove old visitors // Remove old visitors
$db->query( $db->query(
"DELETE FROM {chatsitevisitor} " . "DELETE FROM {chatsitevisitor} " .
"WHERE (UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(lasttime)) > ? ". "WHERE (:now - lasttime) > :lifetime ".
"AND (threadid IS NULL OR " . "AND (threadid IS NULL OR " .
"(SELECT count(*) FROM {chatthread} WHERE threadid = {chatsitevisitor}.threadid " . "(SELECT count(*) FROM {chatthread} WHERE threadid = {chatsitevisitor}.threadid " .
"AND istate <> {$state_closed} AND istate <> {$state_left}) = 0)", "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 // Remove old invitations
$db->query( $db->query(
"UPDATE {chatsitevisitor} SET invited = 0, invitationtime = NULL, invitedby = NULL". "UPDATE {chatsitevisitor} SET invited = 0, invitationtime = NULL, invitedby = NULL".
" WHERE threadid IS NULL AND (UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - UNIX_TIMESTAMP(invitationtime)) > ?", " WHERE threadid IS NULL AND (:now - invitationtime) > :lifetime",
array(Settings::get('invitation_lifetime')) array(
':lifetime' => Settings::get('invitation_lifetime'),
':now' => time()
)
); );
// Remove associations of visitors with closed threads // Remove associations of visitors with closed threads
@ -245,13 +251,16 @@ function print_visitors()
// Remove old visitors' tracks // Remove old visitors' tracks
$db->query( $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})", " 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), " . $query = "SELECT visitorid, userid, username, firsttime, lasttime, " .
"entry, details, invited, unix_timestamp(invitationtime), invitedby, invitations, chats " . "entry, details, invited, invitationtime, invitedby, invitations, chats " .
"FROM {chatsitevisitor} " . "FROM {chatsitevisitor} " .
"WHERE threadid IS NULL " . "WHERE threadid IS NULL " .
"ORDER BY invited, lasttime DESC, invitations"; "ORDER BY invited, lasttime DESC, invitations";

View File

@ -40,8 +40,8 @@ function threads_by_userid($userid)
} }
return $db->query( return $db->query(
"select unix_timestamp(dtmcreated) as created, " . "select dtmcreated as created, " .
"unix_timestamp(dtmmodified) as modified, threadid, remote, agentName, userName " . "dtmmodified as modified, threadid, remote, agentName, userName " .
"from {chatthread} " . "from {chatthread} " .
"where userid=? order by created DESC", "where userid=? order by created DESC",
array($userid), array($userid),