function tracking_fetch_filtered_events($community_id, $filters = array(), $paginate = true, $page = 1)
{
    global $db, $ENTRADA_ACL;
    $results_per_page = 25;
    $count = "\tSELECT COUNT(*) AS `count`\n\t\t\t\tFROM `statistics` AS a\n\t\t\t\tJOIN `" . AUTH_DATABASE . "`.`user_data` AS b\n\t\t\t\tON a.`proxy_id` = b.`id`\n\t\t\t\tWHERE `module` LIKE('community:" . $community_id . ":%')";
    $query = "\tSELECT CONCAT_WS(' ',b.`firstname`,b.`lastname`) AS `fullname`,b.`id` AS `user_id`, a.*\n\t\t\t\tFROM `statistics` AS a\n\t\t\t\tJOIN `" . AUTH_DATABASE . "`.`user_data` AS b\n\t\t\t\tON a.`proxy_id` = b.`id`\n\t\t\t\tWHERE `module` LIKE('community:" . $community_id . ":%')";
    $date_query = "\tSELECT MIN(timestamp) AS 'start_date', MAX(timestamp) AS 'end_date'\n\t\t\t\t\tFROM `statistics` AS a\n\t\t\t\t\tJOIN `" . AUTH_DATABASE . "`.`user_data` AS b\n\t\t\t\t\tON a.`proxy_id` = b.`id`\n\t\t\t\t\tWHERE `module` LIKE('community:" . $community_id . ":%')";
    $where = "";
    if (isset($filters) && !empty($filters)) {
        foreach ($filters as $type => $filter) {
            if (is_array($filter) && !empty($filter)) {
                switch ($type) {
                    case 'members':
                        $where .= " AND a.`proxy_id` IN (" . implode(',', $filter) . ")";
                        break;
                    case 'module':
                        //converts each array element to lower case and then finds modules containing the value
                        $where .= " AND a.`module` REGEXP " . $db->qstr(implode('|', unserialize(strtolower(serialize($filter)))));
                        break;
                    case 'action':
                        $search_filter = str_replace("-", "_", $filter);
                        $where .= " AND a.`action` REGEXP " . $db->qstr(implode("|", $search_filter));
                        break;
                    case 'page':
                        $where .= "AND (";
                        $first = true;
                        foreach ($filter as $key => $filter_instance) {
                            $raw_filter = explode("-", $filter_instance);
                            $field = $raw_filter[0] . "_id";
                            $value = $raw_filter[2];
                            $where .= (!$first ? " OR" : "") . " (a.`action_field` = " . $db->qstr($field) . " AND a.`action_value` = " . $db->qstr($value) . ")";
                            $first = false;
                        }
                        $where .= ")";
                        break;
                }
            }
        }
    }
    $count .= $where;
    $query .= $where . " ORDER BY a.`timestamp` DESC";
    $date_query .= $where . " ORDER BY a.`timestamp` DESC";
    $num_results = $db->GetOne($count);
    if ($paginate) {
        $num_pages = ceil($num_results / $results_per_page);
        if ($num_pages > 1 && $page > 1 && $page <= $num_pages) {
            $lower_limit = ($page - 1) * $results_per_page;
            $upper_limit = $results_per_page;
        } else {
            $lower_limit = 0;
            $upper_limit = $results_per_page;
        }
        $limit = " LIMIT " . $lower_limit . "," . $upper_limit;
        $query .= $limit;
        $date_query .= $limit;
    }
    $statistics = $db->GetAll($query);
    $dates = $db->GetRow($date_query);
    if ($statistics) {
        foreach ($statistics as $key => $statistic) {
            $page = get_page_for_statistic($statistic["action_field"], $statistic["action_value"]);
            if ($page) {
                $statistics[$key]['page'] = $page;
            }
        }
    }
    return array($statistics, $dates, $num_pages);
}
Example #2
0
    $ERRORSTR[] = "You do not have the permissions required to use this module.<br /><br />If you believe you are receiving this message in error please contact <a href=\"mailto:" . html_encode($AGENT_CONTACTS["administrator"]["email"]) . "\">" . html_encode($AGENT_CONTACTS["administrator"]["name"]) . "</a> for assistance.";
    echo display_error();
    application_log("error", "Group [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["group"] . "] and role [" . $_SESSION["permissions"][$ENTRADA_USER->getAccessId()]["role"] . "] do not have access to this module [" . $MODULE . "]");
} else {
    if ($MAILING_LISTS["active"]) {
        require_once "Entrada/mail-list/mail-list.class.php";
    }
    /**
     * Add PlotKit to the beginning of the $HEAD array.
     */
    array_unshift($HEAD, "<script type=\"text/javascript\" src=\"" . ENTRADA_RELATIVE . "/javascript/MochiKit/MochiKit.js\"></script>", "<script type=\"text/javascript\" src=\"" . ENTRADA_RELATIVE . "/javascript/PlotKit/excanvas.js\"></script>", "<script type=\"text/javascript\" src=\"" . ENTRADA_RELATIVE . "/javascript/PlotKit/Base.js\"></script>", "<script type=\"text/javascript\" src=\"" . ENTRADA_RELATIVE . "/javascript/PlotKit/Layout.js\"></script>", "<script type=\"text/javascript\" src=\"" . ENTRADA_RELATIVE . "/javascript/PlotKit/Canvas.js\"></script>", "<script type=\"text/javascript\" src=\"" . ENTRADA_RELATIVE . "/javascript/PlotKit/SweetCanvas.js\"></script>");
    if (isset($_GET["page"]) && ($tmp = clean_input($_GET["page"], array("notags", "trim")))) {
        $page_info = explode("-", $tmp);
    }
    if ($page_info) {
        $page = get_page_for_statistic($page_info[0], $page_info[1]);
        $BREADCRUMB[] = array("url" => ENTRADA_URL . "/" . $MODULE, "title" => "Report for page `" . $page . "'");
        echo "<h1>Community Usage Report for Page '" . $page . "'</h1>";
        $query = "\tSELECT DISTINCT `proxy_id` \n\t\t\t\t\tFROM `statistics` WHERE `module` \n\t\t\t\t\tLIKE 'community:" . $COMMUNITY_ID . ":%' \n\t\t\t\t\tAND `action_field` = " . $db->qstr($page_info[0]) . " \n\t\t\t\t\tAND `action_value` = " . $db->qstr($page_info[1]);
        $active_users = $db->GetAll($query);
        if ($active_users) {
            foreach ($active_users as $user) {
                $userlist[] = $user["proxy_id"];
            }
        }
        $query = "\tSELECT `proxy_id` \n\t\t\t\t\tFROM `community_members` \n\t\t\t\t\tWHERE `community_id` = " . $db->qstr($COMMUNITY_ID) . " \n\t\t\t\t\tAND `proxy_id` NOT IN(" . implode(",", $userlist) . ")";
        $inactive_users = $db->GetAll($query);
        $STATISTICS["labels"][1] = "Active Users";
        $STATISTICS["legend"][1] = "Active Users";
        $STATISTICS["display"][1] = count($active_users);
        $STATISTICS["labels"][2] = "Inactive Users";
Example #3
0
				</colgroup>
				<thead>
					<tr>
						<td class="modified">&nbsp;</td>
						<td class="module">Module Type</td>
						<td class="field">Page</td>
						<td class="action">Action</td>
						<td class="count">Count</td>
						<td class="attachment">&nbsp;</td>
					</tr>
				</thead>
				<tbody>
			<?php 
                $total = 0;
                foreach ($results as $result) {
                    $page = get_page_for_statistic($result["action_field"], $result["action_value"]);
                    $module = explode(":", $result["module"]);
                    $action_info = explode("_", $result["action"]);
                    if (count($action_info) == 1) {
                        $action = $result["action"];
                    } else {
                        $action = $action_info[1];
                    }
                    if ($page) {
                        ?>
						<tr><td>&nbsp;</td>
							<td><?php 
                        echo "<a href=\"" . ENTRADA_URL . "/communities/reports?section=type&community=" . $COMMUNITY_ID . "&type=" . $module[2] . "\">" . ucwords($module[2]) . "</a>";
                        ?>
</td>
							<td><?php