<?php

    ob_start();

    require_once ('../../../../wp-load.php');

    global $wpdb;

    if (isset($_GET['from']) && isset($_GET['to'])) {

        $where = " between '" . date ( 'Y-m-d' , strtotime($_GET['from']) ) . "  00:00:00' and '" . date ( 'Y-m-d' , strtotime($_GET['to'] )) . " 23:59:59' ";

        $dias = ( strtotime( date( 'Y-m-d' , strtotime($_GET['from']) ) ) - strtotime( date( 'Y-m-d' , strtotime($_GET['to']) ) ) ) / 86400;
        $dias = abs($dias);
        $dias = floor($dias);

        $from = $_GET['from'];
        $to = $_GET['to'];

    } else {

        $date = date('Y-m-d');

        $newdatee = strtotime ( '-1 month' , strtotime ( $date ) ) ;
        $newdate = date ( 'Y-m-d' , $newdatee );

        $where = " between '" . $newdate . " 00:00:00' and '" . $date . " 23:59:59' ";

        $dias = ( strtotime( date( 'Y-m-d' , strtotime($newdate) ) ) - strtotime( date( 'Y-m-d' , strtotime($date) ) ) ) / 86400;
        $dias = abs($dias);
        $dias = floor($dias);

        $from = date( 'd-m-Y', $newdatee);
        $to = date( 'd-m-Y');

    }

    if($_GET['registrosUsers'] == true) {
        
        header("Content-type: application/csv");
        header("Pragma: no-cache");
        header("Expires: 0");
        
        header("Content-Disposition: attachment; filename=registros.csv");
        
        $Registros = $wpdb->get_row('select
                                    (select count(*) from wp_users where user_status = 0 and user_registered ' . $where . ') as Activos,
                                    (select count(*) from wp_users where user_status = 2 and user_registered ' . $where . ') as Inactovos,
                                    (select count(*) from wp_users where user_status = 0 ) as TotalAc,
                                    (select count(*) from wp_users where user_status = 2 ) as TotalIn');

	ob_end_clean();
	ob_clean();
?>
,<?php echo 'Desde ' . $from . ' Hasta ' . $to ?>,Media,%,Total;
Activos,<?php echo $Registros->Activos ?>,<?php echo number_format(($Registros->Activos/$dias), 3) ?>,<?php echo number_format((($Registros->Activos/$dias)*100/$Registros->TotalAc), 3) ?>,<?php echo $Registros->TotalAc ?>;
Inactivos,<?php echo $Registros->Inactovos ?>,<?php echo number_format(($Registros->Inactovos/$dias), 3) ?>,<?php echo number_format((($Registros->Inactovos/$dias)*100/$Registros->TotalIn), 3) ?>,<?php echo $Registros->TotalIn ?>
<?php                    
die();
    }