public function show_stats_page() { require_once MC4WP_PLUGIN_DIR . 'includes/class-statistics.php'; $statistics = new MC4WP_Statistics(); // set default range or get range from URL $range = isset($_GET['range']) ? $_GET['range'] : 'last_week'; // get data if ($range != 'custom') { $args = $statistics->get_range_times($range); } else { // construct timestamps from given date in select boxes $start = strtotime(implode('-', array($_GET['start_year'], $_GET['start_month'], $_GET['start_day']))); $end = strtotime(implode('-', array($_GET['end_year'], $_GET['end_month'], $_GET['end_day']))); // calculate step size $step = $statistics->get_step_size($start, $end); $given_day = $_GET['start_day']; $args = compact("step", "start", "end", "given_day"); } // check if start timestamp comes after end timestamp if ($args['start'] >= $args['end']) { $args = $statistics->get_range_times('last_week'); add_settings_error('mc4wp-statistics-error', 'invalid-range', "End date can't be before the start date"); } // setup statistic settings $ticksizestep = $args['step'] == 'week' ? 'month' : $args['step']; $statistics_settings = $this->statistics_settings = array('ticksize' => array(1, $ticksizestep)); $statistics_data = $this->statistics_data = $statistics->get_statistics($args); //$totals = $statistics->get_total_signups( $args ); // add scripts // use wp_localize_script only if WP version >= 3.3 global $wp_version; if (version_compare($wp_version, 3.3, ">=")) { wp_localize_script('mc4wp-statistics', 'mc4wp_statistics_data', $statistics_data); wp_localize_script('mc4wp-statistics', 'mc4wp_statistics_settings', $statistics_settings); } else { add_action('admin_print_footer_scripts', array($this, 'print_statistics_data')); } $start_day = isset($_GET['start_day']) ? $_GET['start_day'] : 0; $start_month = isset($_GET['start_month']) ? $_GET['start_month'] : 0; $start_year = isset($_GET['start_year']) ? $_GET['start_year'] : 0; $end_day = isset($_GET['end_day']) ? $_GET['end_day'] : 0; $end_month = isset($_GET['end_month']) ? $_GET['end_month'] : 0; $end_year = isset($_GET['end_year']) ? $_GET['end_year'] : 0; $tab = 'statistics'; include_once MC4WP_PLUGIN_DIR . 'includes/views/admin-reports.php'; }
/** * Show reports (stats) page */ public function show_stats_page() { $statistics = new MC4WP_Statistics($_GET); $statistics_settings = array('ticksize' => array(1, $statistics->step_size)); $statistics_data = $statistics->get_statistics(); // add scripts wp_localize_script('mc4wp-statistics', 'mc4wp_statistics_data', $statistics_data); wp_localize_script('mc4wp-statistics', 'mc4wp_statistics_settings', $statistics_settings); $start_day = isset($_GET['start_day']) ? $_GET['start_day'] : 0; $start_month = isset($_GET['start_month']) ? $_GET['start_month'] : 0; $start_year = isset($_GET['start_year']) ? $_GET['start_year'] : 0; $end_day = isset($_GET['end_day']) ? $_GET['end_day'] : 0; $end_month = isset($_GET['end_month']) ? $_GET['end_month'] : 0; $end_year = isset($_GET['end_year']) ? $_GET['end_year'] : 0; $tab = 'statistics'; $range = $statistics->range; include_once MC4WP_PLUGIN_DIR . 'includes/views/pages/admin-reports.php'; }