<?php
/*-----------------------------------------------------------------------------------*/
// Classiera PayPal Payments List
/*-----------------------------------------------------------------------------------*/
if( !function_exists( 'classiera_register_properties_payments_page' ) ){
    function classiera_register_properties_payments_page(){       
		add_theme_page('Transaction', 'Transaction', 'manage_options', 'ads-payments', 'classiera_display_properties_payments');
    }
}
add_action('admin_menu', 'classiera_register_properties_payments_page');
if( !function_exists( 'classiera_display_properties_payments' ) ){
    function classiera_display_properties_payments(){
        ?>
		<h2><?php esc_html_e('User_id 1 is admins id and 0 ads means unlimited ads.','classiera');?></h2>
        <table id="payments-table" cellpadding="10px">
            <tr>
                <th><?php esc_html_e('Transaction ID','classiera');?></th>
                <th><?php esc_html_e('Purchase Date','classiera');?></th>
				<th><?php esc_html_e('User ID','classiera');?></th>
                <th><?php esc_html_e('Name','classiera');?></th>
                <th><?php esc_html_e('Email','classiera');?></th>
                <th><?php esc_html_e('Plan Name','classiera');?></th>
                <th><?php esc_html_e('Amount','classiera');?></th>
                <th><?php esc_html_e('Ads','classiera');?></th>
                <th><?php esc_html_e('Ads used','classiera');?></th>
                <th><?php esc_html_e('Status','classiera');?></th>
                <th><?php esc_html_e('Activated By','classiera');?></th>
            </tr>
            <?php
			global $wpdb;
			$result = $wpdb->get_results( "SELECT * FROM wpcads_paypal ORDER BY main_id DESC" );
			if (!empty($result )){
					
					foreach ( $result as $key => $row ) {	
					$user_info = get_userdata($row->user_id);
			
			?>
                    <tr>
                        <td><?php echo $row->transaction_id; ?></td>
                        <td><?php echo $row->date; ?></td>
                        <td><?php echo $row->user_id; ?></td>
                        <td><?php echo $user_info->first_name .' ' .$user_info->last_name; ?></td>
                        <td><?php echo $row->email; ?></td>
                        <td><?php echo $row->name; ?></td>
                        <td><?php echo $row->price; ?></td>
                        <td><?php echo $row->ads; ?></td>
                        <td><?php echo $row->used; ?></td>
                        <td><?php echo $row->status; ?></td>
                        <td><?php if(!empty($row->transaction_id)){ echo 'Paypal';}else{ echo 'Admin';}; ?></td>
                    </tr>
                    <?php
					
					}
				}else{
                ?>
                <tr>
                    <td colspan="11"><?php esc_html_e('No Completed Payment Found!','classiera'); ?></td>
                </tr>
                <?php
            }
            ?>
        </table>
        <?php
    }
}