diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index f512a585..0e928373 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -36,6 +36,7 @@ $dbtables = array( "agentName" => "varchar(64)", "agentId" => "int NOT NULL DEFAULT 0", "dtmcreated" => "datetime DEFAULT 0", + "dtmchatstarted" => "datetime DEFAULT 0", "dtmmodified" => "datetime DEFAULT 0", "lrevision" => "int NOT NULL DEFAULT 0", "istate" => "int NOT NULL DEFAULT 0", @@ -141,7 +142,7 @@ $dbtables_indexes = array( $memtables = array(); $dbtables_can_update = array( - "${mysqlprefix}chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "groupid"), + "${mysqlprefix}chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent", "groupid", "dtmchatstarted"), "${mysqlprefix}chatmessage" => array("agentId"), "${mysqlprefix}chatoperator" => array("vcavatar", "vcjabbername", "iperm", "istatus", "vcemail", "dtmrestore", "vcrestoretoken"), "${mysqlprefix}chatban" => array(), @@ -238,4 +239,4 @@ function get_columns($tablename, $link) } } -?> \ No newline at end of file +?> diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php index 9d091438..b0013e8e 100644 --- a/src/messenger/webim/install/dbperform.php +++ b/src/messenger/webim/install/dbperform.php @@ -87,6 +87,11 @@ if ($act == "silentcreateall") { runsql("update ${mysqlprefix}chatthread, ${mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link); } + if (in_array("${mysqlprefix}chatthread.dtmchatstarted", $absent)) { + runsql("ALTER TABLE ${mysqlprefix}chatthread ADD dtmchatstarted datetime DEFAULT 0 AFTER dtmcreated", $link); + runsql("update ${mysqlprefix}chatthread set dtmchatstarted = dtmcreated", $link); + } + if (in_array("${mysqlprefix}chatthread.agentTyping", $absent)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link); } diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 04071c89..1588a611 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -565,7 +565,7 @@ function thread_by_id_($id, $link) { global $mysqlprefix; return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping" . - ",unix_timestamp(dtmmodified) as modified, unix_timestamp(dtmcreated) as created" . + ",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 ${mysqlprefix}chatthread where threadid = " . $id, $link); } @@ -606,15 +606,18 @@ function create_thread($groupid, $username, $remoteHost, $referer, $lang, $useri return $newthread; } -function do_take_thread($threadid, $operatorId, $operatorName) +function do_take_thread($threadid, $operatorId, $operatorName, $chatstart = false) { global $state_chatting; $link = connect(); - commit_thread($threadid, - array("istate" => $state_chatting, - "nextagent" => 0, - "agentId" => $operatorId, - "agentName" => "'" . db_escape_string($operatorName, $link) . "'"), $link); + $params = array("istate" => $state_chatting, + "nextagent" => 0, + "agentId" => $operatorId, + "agentName" => "'" . db_escape_string($operatorName, $link) . "'"); + if ($chatstart){ + $params['dtmchatstarted'] = "CURRENT_TIMESTAMP"; + } + commit_thread($threadid, $params, $link); close_connection($link); } @@ -647,11 +650,12 @@ function take_thread($thread, $operator) $state = $thread['istate']; $threadid = $thread['threadid']; $message_to_post = ""; + $chatstart = $thread['chatstarted'] == 0; $operatorName = ($thread['locale'] == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname']; if ($state == $state_queue || $state == $state_waiting || $state == $state_loading) { - do_take_thread($threadid, $operator['operatorid'], $operatorName); + do_take_thread($threadid, $operator['operatorid'], $operatorName, $chatstart); if ($state == $state_waiting) { if ($operatorName != $thread['agentName']) { @@ -664,7 +668,7 @@ function take_thread($thread, $operator) } } else if ($state == $state_chatting) { if ($operator['operatorid'] != $thread['agentId']) { - do_take_thread($threadid, $operator['operatorid'], $operatorName); + do_take_thread($threadid, $operator['operatorid'], $operatorName, $chatstart); $message_to_post = getstring2_("chat.status.operator.changed", array($operatorName, $thread['agentName']), $thread['locale']); } } else { diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index bb1a717e..c7181f71 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -396,6 +396,8 @@ report.bydate.1=Date report.bydate.2=Chat threads report.bydate.3=Messages from operators report.bydate.4=Messages from visitors +report.bydate.5=Average waiting time (in seconds) +report.bydate.6=Average chat time (in seconds) report.bydate.title=Usage statistics for each date report.byoperator.1=Operator report.byoperator.2=Chat Threads diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index 6b860ee0..759930c0 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -394,6 +394,8 @@ report.bydate.1= report.bydate.2=Диалогов report.bydate.3=Сообщений операторов report.bydate.4=Сообщений посетителей +report.bydate.5=Среднее время ожидания (в секундах) +report.bydate.6=Среднее время диалога (в секундах) report.bydate.title=Использование мессенджера по дням report.byoperator.1=Оператор report.byoperator.2=Диалогов diff --git a/src/messenger/webim/operator/statistics.php b/src/messenger/webim/operator/statistics.php index 0c2a91dd..0c38a24a 100644 --- a/src/messenger/webim/operator/statistics.php +++ b/src/messenger/webim/operator/statistics.php @@ -70,11 +70,13 @@ if ($start > $end) { $link = connect(); -$page['reportByDate'] = select_multi_assoc("select DATE(dtmcreated) as date, COUNT(distinct threadid) as threads, SUM(${mysqlprefix}chatmessage.ikind = $kind_agent) as agents, SUM(${mysqlprefix}chatmessage.ikind = $kind_user) as users " . - "from ${mysqlprefix}chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by DATE(dtmcreated) order by dtmcreated desc", $link); +$page['reportByDate'] = select_multi_assoc("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 ${mysqlprefix}chatmessage m, ${mysqlprefix}chatthread t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM ${mysqlprefix}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(m.dtmcreated) >= $start AND unix_timestamp(m.dtmcreated) < $end group by DATE(m.dtmcreated) order by m.dtmcreated desc", $link); -$page['reportByDateTotal'] = select_one_row("select COUNT(distinct threadid) as threads, SUM(${mysqlprefix}chatmessage.ikind = $kind_agent) as agents, SUM(${mysqlprefix}chatmessage.ikind = $kind_user) as users " . - "from ${mysqlprefix}chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end", $link); +$page['reportByDateTotal'] = select_one_row("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 ${mysqlprefix}chatmessage m, ${mysqlprefix}chatthread t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM ${mysqlprefix}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(m.dtmcreated) >= $start AND unix_timestamp(m.dtmcreated) < $end", $link); $page['reportByAgent'] = select_multi_assoc("select vclocalename as name, COUNT(distinct threadid) as threads, SUM(ikind = $kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen " . "from ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator " . diff --git a/src/messenger/webim/view/statistics.php b/src/messenger/webim/view/statistics.php index ff8050cc..be1bd8bf 100644 --- a/src/messenger/webim/view/statistics.php +++ b/src/messenger/webim/view/statistics.php @@ -82,6 +82,10 @@ require_once('inc_errors.php'); + + + + @@ -92,6 +96,8 @@ require_once('inc_errors.php'); + + @@ -99,10 +105,12 @@ require_once('inc_errors.php'); + + - +