/**
  * Retrieves all mouse clicks/touch screen taps
  *
  * @since 1.0
  */
 public function retrieve_user_events()
 {
     $ajax_nonce = $_GET['nonce'];
     $response = array();
     if (wp_verify_nonce($ajax_nonce, HA_Common::PLUGIN_ID . '-nonce')) {
         $response = array('status' => 'OK', 'message' => '');
         // GET parameters
         $url = isset($_GET['url']) ? HA_Common::normalize_url(urldecode($_GET['url'])) : null;
         $ignore_width = isset($_GET['ignoreWidth']) && $_GET['ignoreWidth'] == "true" ? true : false;
         $width_allowance = isset($_GET['widthAllowance']) && is_numeric($_GET['widthAllowance']) ? intval($_GET['widthAllowance']) : null;
         $page_width = isset($_GET['pageWidth']) && is_numeric($_GET['pageWidth']) ? intval($_GET['pageWidth']) : null;
         $user_event_id = isset($_GET['userEventId']) && is_numeric($_GET['userEventId']) ? intval($_GET['userEventId']) : null;
         $ignore_device = isset($_GET['ignoreDevice']) && $_GET['ignoreDevice'] == "true" ? true : false;
         $device = isset($_GET['device']) && strlen(trim($_GET['device'])) > 0 ? urldecode($_GET['device']) : null;
         $ignore_os = isset($_GET['ignoreOs']) && $_GET['ignoreOs'] == "true" ? true : false;
         $os = isset($_GET['os']) && strlen(trim($_GET['os'])) > 0 ? urldecode($_GET['os']) : null;
         $ignore_browser = isset($_GET['ignoreBrowser']) && $_GET['ignoreBrowser'] == "true" ? true : false;
         $browser = isset($_GET['browser']) && strlen(trim($_GET['browser'])) > 0 ? urldecode($_GET['browser']) : null;
         $hide_roles = isset($_GET['hideRoles']) && is_array($_GET['hideRoles']) ? $_GET['hideRoles'] : array();
         $spot_radius = isset($_GET['spotRadius']) && is_numeric($_GET['spotRadius']) ? intval($_GET['spotRadius']) : null;
         $event_types = isset($_GET['eventTypes']) && is_array($_GET['eventTypes']) ? $_GET['eventTypes'] : array();
         // validate data
         if (!$url || !count($event_types) > 0) {
             $response['status'] = 'Error';
             $response['message'] = 'Required data missing from request';
             echo json_encode($response);
             return;
         }
         global $wpdb;
         // base query - all user events for a given url
         $query = 'SELECT u_event.' . HA_Common::ID_COLUMN . ', u_event.' . HA_Common::X_COORD_COLUMN . ', u_event.' . HA_Common::Y_COORD_COLUMN . ', u_event.' . HA_Common::URL_COLUMN . ', u_event.' . HA_Common::EVENT_TYPE_COLUMN . ', u_event.' . HA_Common::PAGE_WIDTH_COLUMN . ' FROM ' . $wpdb->prefix . HA_Common::USER_EVENT_TBL_NAME . ' AS u_event, ' . $wpdb->prefix . HA_Common::USER_ENV_TBL_NAME . ' AS u_env, ' . $wpdb->prefix . HA_Common::USER_TBL_NAME . ' AS u WHERE u.' . HA_Common::ID_COLUMN . ' = u_event.' . HA_Common::USER_ID_COLUMN . ' AND u.' . HA_Common::ID_COLUMN . ' = u_env.' . HA_Common::USER_ID_COLUMN . ' AND u_event.' . HA_Common::URL_COLUMN . ' = "' . $url . '"';
         $query_filters = array('ignore_width' => $ignore_width, 'width_allowance' => $width_allowance, 'page_width' => $page_width, 'user_event_id' => $user_event_id, 'ignore_device' => $ignore_device, 'device' => $device, 'ignore_os' => $ignore_os, 'os' => $os, 'ignore_browser' => $ignore_browser, 'browser' => $browser, 'hide_roles' => $hide_roles, 'event_types' => $event_types, 'exact_match' => false);
         $query = HA_Query_Helper::apply_query_filters($query, $query_filters);
         $rows = $wpdb->get_results($query);
         $index = 0;
         foreach ($rows as $row) {
             $user_event_id = $row->id;
             $x_coord = $row->x_coord;
             $y_coord = $row->y_coord;
             $url = HA_Common::normalize_url($row->url);
             $page_width = $row->page_width;
             $heat_value = HA_Common::calculate_heat_value($x_coord, $y_coord, $user_event_id, $rows, $spot_radius);
             $response[$index++] = array('user_event_id' => $user_event_id, 'x_coord' => $x_coord, 'y_coord' => $y_coord, 'page_width' => $page_width, 'url' => $url, 'heat_value' => $heat_value, 'event_type' => $row->event_type);
         }
     }
     echo json_encode($response);
     die;
 }
 private function event_totals_bar_graph_report_data($filters)
 {
     global $wpdb;
     // Counts data
     $query = 'SELECT count(*) as count, u_event.' . HA_Common::EVENT_TYPE_COLUMN . ' FROM ' . $wpdb->prefix . HA_Common::USER_TBL_NAME . ' AS u, ' . $wpdb->prefix . HA_Common::USER_EVENT_TBL_NAME . ' AS u_event, ' . $wpdb->prefix . HA_Common::USER_ENV_TBL_NAME . ' AS u_env WHERE u_event.' . HA_Common::USER_ENV_ID_COLUMN . ' = u_env.' . HA_Common::ID_COLUMN . ' AND u.' . HA_Common::ID_COLUMN . ' = u_event.' . HA_Common::USER_ID_COLUMN;
     $query = HA_Query_Helper::apply_query_filters($query, $filters);
     $query .= ' GROUP BY ' . HA_Common::EVENT_TYPE_COLUMN;
     $rows = $wpdb->get_results($query);
     $count_data = array();
     foreach ($rows as $row) {
         $event_type = $row->event_type;
         $count = $row->count;
         array_push($count_data, array($event_type, $count));
     }
     return json_decode(json_encode(array('count_data' => $count_data)), false);
 }