<?php
global $wpdb;
$entry = giveasap_get_user_by_id( $entry_id );
$meta  = giveasap_get_meta( $entry_id );
$data  = isset( $_GET['data'] ) ? \Simple_Giveaways\Helpers::unslash_and_clean( $_GET['data'] ) : 'single';
?>
<h3><?php echo esc_html( sprintf( __( 'Email: %s', 'giveasap' ), $entry->email ) ); ?></h3>
<div id="poststuff">
	<?php
		require 'data.php';
	if ( 'all' === $data ) {
		$entries = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->giveasap_entries WHERE email=%s", $entry->email ) );
		if ( $entries ) {
			$primary_entry_id = $entry_id;
			foreach ( $entries as $entry ) {
				if ( $primary_entry_id === $entry->id ) {
					continue;
				}
				$entry_id = $entry->id;
				$meta     = giveasap_get_meta( $entry_id );
				include 'data.php';
			}
		}
	}
	?>
</div>
<?php
if ( 'single' === $data ) {
	?>
	<a class="button" href="<?php echo esc_url_raw( admin_url( 'edit.php?post_type=giveasap&page=giveasap-users&user=' . absint( $entry_id ) . '&action=view&data=all' ) ); ?>"><?php esc_html_e( 'Load all Giveaways for this email', 'giveasap' ); ?></a>
	<?php
}
