<?php
if(!defined('ABSPATH')){
    exit; // Exit if accessed directly
}

global $wp;
$myurl = admin_url( "admin.php?page=easy-photo-sell_orders");

$page_links = "";

$pagenum = isset( $_GET['pg'] ) ? absint( sanitize_text_field($_GET['pg']) ) : 1;


    $total = EgpsDatabase::egps_count_table_rows_distinct("orders", "order_items");
        
    $limit = 50; // number of rows in page
    $offset = ( $pagenum - 1 ) * $limit;

    $num_of_pages = ceil( $total / $limit );

    $all_orders = EgpsDatabase::egps_get_table_rows_where_limit(
            "egps_photos", 
            "egps_purchase_count",
            "not_equal",
            "0", 
            "egps_purchase_count", 
            "DESC", 
            $offset, $limit
    );

    $page_links = paginate_links( array(
        'base' => add_query_arg( 'pg', '%#%' ),
        'format' => '',
        'prev_text' => __( '&laquo;', 'egps-easy-sell-for-google-photo' ),
        'next_text' => __( '&raquo;', 'egps-easy-sell-for-google-photo' ),
        'total' => $num_of_pages,
        'current' => $pagenum
    ) );


    echo '<table class="table table-striped">
    <thead>
        <tr>
            <th scope="col">#</th>
            <th scope="col">order count</th>
            <th scope="col">photo</th>
        </tr>
    </thead>
    <tbody>';

    
    $in = 1; 

    foreach($all_orders as $ord){

        echo '
        <tr>
        <th scope="row">' . esc_html($in++) . '</th>
        <th scope="row">' . esc_html($ord->egps_purchase_count) . '</th>
        <td>';
            
            echo '<img src="' . esc_url(get_site_url() . '/wp-content/uploads/egps/photos/' . $ord->egps_id . '.jpg') . '" width="100" />';

            echo '</td>
        </tr>';
    }

    if ( $page_links != "" ) {
        echo '<tr><th scope="row"></th><td>' . esc_html($page_links) . '</td></tr>';
    }

    echo '
    </tbody>
    </table>';



