diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index bc32caab..e75b0b85 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -202,7 +202,11 @@ $dbtables = array( "date" => "int NOT NULL DEFAULT 0", "address" => "varchar(1024)", "visits" => "int NOT NULL DEFAULT 0", - "chats" => "int NOT NULL DEFAULT 0" + "chats" => "int NOT NULL DEFAULT 0", + "sentinvitations" => "int NOT NULL DEFAULT 0", + "acceptedinvitations" => "int NOT NULL DEFAULT 0", + "rejectedinvitations" => "int NOT NULL DEFAULT 0", + "ignoredinvitations" => "int NOT NULL DEFAULT 0" ), ); @@ -254,7 +258,7 @@ $dbtables_can_update = array( "${mysqlprefix}chatsitevisitor" => array(), "${mysqlprefix}requestcallback" => array("callbackid", "token", "function", "arguments"), "${mysqlprefix}visitedpage" => array(), - "${mysqlprefix}visitedpagestatistics" => array(), + "${mysqlprefix}visitedpagestatistics" => array("sentinvitations", "acceptedinvitations", "rejectedinvitations", "ignoredinvitations"), ); function show_install_err($text) diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php index f4a22249..96dcfe00 100644 --- a/src/messenger/webim/install/dbperform.php +++ b/src/messenger/webim/install/dbperform.php @@ -240,6 +240,22 @@ if ($act == "silentcreateall") { runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vchosturl varchar(255) DEFAULT ''", $link); } + if (in_array("${mysqlprefix}visitedpagestatistics.sentinvitations", $absent_columns)) { + runsql("ALTER TABLE ${mysqlprefix}visitedpagestatistics ADD sentinvitations int NOT NULL DEFAULT 0", $link); + } + + if (in_array("${mysqlprefix}visitedpagestatistics.acceptedinvitations", $absent_columns)) { + runsql("ALTER TABLE ${mysqlprefix}visitedpagestatistics ADD acceptedinvitations int NOT NULL DEFAULT 0", $link); + } + + if (in_array("${mysqlprefix}visitedpagestatistics.rejectedinvitations", $absent_columns)) { + runsql("ALTER TABLE ${mysqlprefix}visitedpagestatistics ADD rejectedinvitations int NOT NULL DEFAULT 0", $link); + } + + if (in_array("${mysqlprefix}visitedpagestatistics.ignoredinvitations", $absent_columns)) { + runsql("ALTER TABLE ${mysqlprefix}visitedpagestatistics ADD ignoredinvitations int NOT NULL DEFAULT 0", $link); + } + // Add absent indexes $absent_indexes = array(); foreach ($dbtables_indexes as $id => $indexes) { diff --git a/src/messenger/webim/libs/statistics.php b/src/messenger/webim/libs/statistics.php index 79a925b3..bdd046cd 100644 --- a/src/messenger/webim/libs/statistics.php +++ b/src/messenger/webim/libs/statistics.php @@ -427,30 +427,204 @@ function calculate_page_statistics() { $start = empty($result['start']) ? 0 : $result['start']; $today = floor(time() / (24*60*60)) * 24*60*60; + $statistics = array(); + // Calculate statistics - $db->query( - "INSERT INTO {visitedpagestatistics} (" . - "date, address, visits, chats" . - ") SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " . - "p.address AS address, " . - "COUNT(DISTINCT p.pageid) AS visittimes, " . - "COUNT(DISTINCT t.threadid) AS chattimes " . - "FROM {visitedpage} p " . - "LEFT OUTER JOIN {chatthread} t ON (" . - "p.address = t.referer " . - "AND DATE(FROM_UNIXTIME(p.visittime)) = " . - "DATE(FROM_UNIXTIME(t.dtmcreated))) " . - "WHERE p.calculated = 0 " . - "AND (p.visittime - :start) > 24*60*60 " . - "AND (:today - p.visittime) > 24*60*60 " . - "GROUP BY date, address " . - "ORDER BY date", + // Get main pages info + $db_results = $db->query( + "SELECT FLOOR(visittime / (24*60*60)) * 24*60*60 AS date, " . + "address, " . + "COUNT(DISTINCT pageid) AS visits " . + "FROM {visitedpage} ". + "WHERE calculated = 0 " . + "AND (visittime - :start) > 24*60*60 " . + "AND (:today - visittime) > 24*60*60 " . + "GROUP BY date, address", array( ':start' => $start, ':today' => $today - ) + ), + array('return_rows' => Database::RETURN_ALL_ROWS) ); + foreach($db_results as $result) { + $statistics[$result['date'] . '_' . $result['address']] = $result; + } + + // Get total chats count + $db_results = $db->query( + "SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " . + "p.address AS address, " . + "COUNT(DISTINCT t.threadid) AS chats " . + "FROM {visitedpage} p, {chatthread} t, " . + "(SELECT " . + "COUNT(*) AS msgs, " . + "m.threadid " . + "FROM {indexedchatmessage} m " . + "WHERE m.ikind = :kind_user OR m.ikind = :kind_agent " . + "GROUP BY m.threadid) tmp " . + "WHERE t.referer = p.address " . + "AND p.calculated = 0 " . + "AND t.threadid = tmp.threadid " . + "AND tmp.msgs > 0 " . + "AND t.dtmchatstarted <> 0 " . + "AND (p.visittime - :start) > 24*60*60 " . + "AND (:today - p.visittime) > 24*60*60 " . + "AND DATE(FROM_UNIXTIME(p.visittime)) " . + "= DATE(FROM_UNIXTIME(t.dtmcreated)) " . + "AND (t.invitationstate = :not_invited " . + "OR t.invitationstate = :invitation_accepted) " . + "GROUP BY date, address", + array( + ':start' => $start, + ':today' => $today, + ':not_invited' => Thread::INVITATION_NOT_INVITED, + ':invitation_accepted' => Thread::INVITATION_ACCEPTED, + ':kind_agent' => Thread::KIND_AGENT, + ':kind_user' => Thread::KIND_USER + ), + array('return_rows' => Database::RETURN_ALL_ROWS) + ); + + // Store info in statistics data + foreach($db_results as $result) { + $key = $result['date'] . '_' . $result['address']; + if (empty($statistics[$key])) { + $statistics[$key] = array(); + } + $statistics[$key] += $result; + } + + // Get info about accepted invitations + $db_results = $db->query( + "SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " . + "p.address AS address, " . + "COUNT(DISTINCT t.threadid) AS invitations_accepted " . + "FROM {visitedpage} p, {chatthread} t " . + "WHERE t.referer = p.address " . + "AND p.calculated = 0 " . + "AND (p.visittime - :start) > 24*60*60 " . + "AND (:today - p.visittime) > 24*60*60 " . + "AND DATE(FROM_UNIXTIME(p.visittime)) " . + "= DATE(FROM_UNIXTIME(t.dtmcreated)) " . + "AND t.invitationstate = :invitation_accepted " . + "GROUP BY date, address", + array( + ':start' => $start, + ':today' => $today, + ':invitation_accepted' => Thread::INVITATION_ACCEPTED + ), + array('return_rows' => Database::RETURN_ALL_ROWS) + ); + + // Store info in statistics data + foreach($db_results as $result) { + $key = $result['date'] . '_' . $result['address']; + if (empty($statistics[$key])) { + $statistics[$key] = array(); + } + $statistics[$key] += $result; + } + + // Get info about rejected invitations + $db_results = $db->query( + "SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " . + "p.address AS address, " . + "COUNT(DISTINCT t.threadid) AS invitations_rejected " . + "FROM {visitedpage} p, {chatthread} t " . + "WHERE t.referer = p.address " . + "AND p.calculated = 0 " . + "AND (p.visittime - :start) > 24*60*60 " . + "AND (:today - p.visittime) > 24*60*60 " . + "AND DATE(FROM_UNIXTIME(p.visittime)) " . + "= DATE(FROM_UNIXTIME(t.dtmcreated)) " . + "AND t.invitationstate = :invitation_rejected " . + "GROUP BY date, address", + array( + ':start' => $start, + ':today' => $today, + ':invitation_rejected' => Thread::INVITATION_REJECTED + ), + array('return_rows' => Database::RETURN_ALL_ROWS) + ); + + // Store info in statistics data + foreach($db_results as $result) { + $key = $result['date'] . '_' . $result['address']; + if (empty($statistics[$key])) { + $statistics[$key] = array(); + } + $statistics[$key] += $result; + } + + // Get info about ignored invitations + $db_results = $db->query( + "SELECT FLOOR(p.visittime / (24*60*60)) * 24*60*60 AS date, " . + "p.address AS address, " . + "COUNT(DISTINCT t.threadid) AS invitations_ignored " . + "FROM {visitedpage} p, {chatthread} t " . + "WHERE t.referer = p.address " . + "AND p.calculated = 0 " . + "AND (p.visittime - :start) > 24*60*60 " . + "AND (:today - p.visittime) > 24*60*60 " . + "AND DATE(FROM_UNIXTIME(p.visittime)) " . + "= DATE(FROM_UNIXTIME(t.dtmcreated)) " . + "AND t.invitationstate = :invitation_ignored " . + "GROUP BY date, address", + array( + ':start' => $start, + ':today' => $today, + ':invitation_ignored' => Thread::INVITATION_IGNORED + ), + array('return_rows' => Database::RETURN_ALL_ROWS) + ); + + // Store info in statistics data + foreach($db_results as $result) { + $key = $result['date'] . '_' . $result['address']; + if (empty($statistics[$key])) { + $statistics[$key] = array(); + } + $statistics[$key] += $result; + } + + // Sort statistics by date before save it in the database + ksort($statistics); + + foreach($statistics as $row) { + // Set default values + $row += array( + 'visits' => 0, + 'chats' => 0, + 'invitations_accepted' => 0, + 'invitations_rejected' => 0, + 'invitations_ignored' => 0 + ); + + $row['invitations_sent'] = $row['invitations_accepted'] + + $row['invitations_rejected'] + + $row['invitations_ignored']; + + // Prepare data for insert + $insert_data = array(); + foreach($row as $field_name => $field_value) { + $insert_data[':' . $field_name] = $field_value; + } + + $db->query( + "INSERT INTO {visitedpagestatistics} (" . + "date, address, visits, chats, " . + "sentinvitations, acceptedinvitations, " . + "rejectedinvitations, ignoredinvitations " . + ") VALUES (". + ":date, :address, :visits, :chats, :invitations_sent, " . + ":invitations_accepted, :invitations_rejected, " . + ":invitations_ignored " . + ")", + $insert_data + ); + } + // Mark all visited pages as 'calculated' $db->query( "UPDATE {visitedpage} SET calculated = 1 " . diff --git a/src/messenger/webim/locales/en/properties b/src/messenger/webim/locales/en/properties index dd73c426..904b919f 100644 --- a/src/messenger/webim/locales/en/properties +++ b/src/messenger/webim/locales/en/properties @@ -470,6 +470,10 @@ report.byoperator.title=Threads by operator report.bypage.1=Page report.bypage.2=View times report.bypage.3=Chat threads +report.bypage.4=Invitations sent +report.bypage.5=Invitations accepted +report.bypage.6=Invitations rejected +report.bypage.7=Invitations ignored report.bypage.title=Chat threads by page report.no_items=Not enough data report.total=Total: diff --git a/src/messenger/webim/locales/ru/properties b/src/messenger/webim/locales/ru/properties index 109b5a9f..c0207158 100644 --- a/src/messenger/webim/locales/ru/properties +++ b/src/messenger/webim/locales/ru/properties @@ -469,6 +469,10 @@ report.byoperator.title= report.bypage.1=Страница report.bypage.2=Просмотров report.bypage.3=Диалогов +report.bypage.4=Приглашений отправлено +report.bypage.5=Приглашений принято +report.bypage.6=Приглашений отклонено +report.bypage.7=Приглашений проигнорировано report.bypage.title=Статистика по страницам report.no_items=Мало данных report.total=Итого: diff --git a/src/messenger/webim/operator/statistics.php b/src/messenger/webim/operator/statistics.php index 376ef336..3d34daa0 100644 --- a/src/messenger/webim/operator/statistics.php +++ b/src/messenger/webim/operator/statistics.php @@ -154,7 +154,11 @@ if ($statisticstype == 'bydate') { $page['reportByPage'] = $db->query( "SELECT SUM(visits) as visittimes, " . "address, " . - "SUM(chats) as chattimes " . + "SUM(chats) as chattimes, " . + "SUM(sentinvitations) AS sentinvitations, " . + "SUM(acceptedinvitations) AS acceptedinvitations, " . + "SUM(rejectedinvitations) AS rejectedinvitations, " . + "SUM(ignoredinvitations) AS ignoredinvitations " . "FROM {visitedpagestatistics} " . "WHERE date >= :start " . "AND date < :end " . diff --git a/src/messenger/webim/view/statistics.php b/src/messenger/webim/view/statistics.php index 4796c911..d86c315d 100644 --- a/src/messenger/webim/view/statistics.php +++ b/src/messenger/webim/view/statistics.php @@ -221,7 +221,19 @@ require_once('inc_errors.php');