<?php
$page           = (!empty($_GET['page-id']) && is_numeric($_GET['page-id'])) ? Secure($_GET['page-id']) : 1;
$db->pageLimit  = 20;
//
if(isset($_GET['approved'])){
    $db->where("approved_at", "0", ">")->where('snapshot', '', '!=');
}else{
    $db->where("approved_at", "0", "=")->where('snapshot', '', '!=');
}

$mediafiles = $db->objectbuilder()->orderBy('id', 'DESC')->paginate('users', $page);

//$mediafiles = $db->rawQuery('SELECT * FROM `users` WHERE `status` = 1 AND `snapshot` IS NOT NULL ORDER BY `id` DESC')->paginate('users', $page);

if (($page > $db->totalPages) && !empty($_GET['page-id'])) {
    header("Location: " . Wo_LoadAdminLinkSettings('manage-user-verification'));
    exit();
}


$approved_count = $db->where("approved_at", "0", ">")->where('snapshot', '', '!=')->getValue('users','count(id)');
$disapproved_count =$db->where("approved_at", "0", "=")->where('snapshot', '', '!=')->getValue('users','count(id)');

?>
<div class="container-fluid">
    <div>
        <h3>Manage user verification</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Users</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Manage user verification</li>
            </ol>
        </nav>
    </div>

    <div class="row clearfix">
        <div class="col-md-6">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Approved</h6>
                    <div class="d-flex align-items-center mb-3">
                        <div>
                            <div class="avatar">
                                <span class="avatar-title bg-info-bright text-info rounded-pill">
                                    <i class="material-icons">check</i>
                                </span>
                            </div>
                        </div>
                        <div class="font-weight-bold ml-1 font-size-30 ml-3"><?php echo $approved_count; ?></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Disapproved</h6>
                    <div class="d-flex align-items-center mb-3">
                        <div>
                            <div class="avatar">
                                <span class="avatar-title bg-primary-bright text-primary rounded-pill">
                                    <i class="material-icons">clear</i>
                                </span>
                            </div>
                        </div>
                        <div class="font-weight-bold ml-1 font-size-30 ml-3"><?php echo $disapproved_count; ?></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Manage user verifications</h6>
                    <div class="clearfix"></div>
                    <div class="table-responsive1">
                        <table class="table table-bordered table-striped table-hover">
							<thead>
								<tr>
									<th>User</th>
									<th>Created</th>
									<th>Info</th>
									<th>Action</th>
								</tr>
							</thead>
                            <tbody>
                            <?php
                            if( count($mediafiles) === 0 ){
                                //echo '<tr><td style="padding: 200px;text-align: center;">No data available in table</td></tr>';
                            }else {
                                foreach ($mediafiles as $mediafilelist) {
                                    $wo['mediafilelist'] = $mediafilelist;
                                    echo Wo_LoadAdminPage('manage-user-verification/list');
                                }
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="wo-admincp-feturepager" style="width: 98%;margin: 0 auto;">
                        <div class="pull-left">
                            <span>
                              <?php echo "Showing $page out of " . $db->totalPages; ?>
                            </span>
                        </div>
                        <div class="pull-right">
                            <nav>
                                <ul class="pagination">
                                    <li>
                                        <a href="<?php echo Wo_LoadAdminLinkSettings('manage-user-verification?page-id=1'); ?>" class="waves-effect" title='First Page'>
                                            <i class="material-icons">first_page</i>
                                        </a>
                                    </li>
                                    <?php if ($page > 1) {  ?>
                                        <li>
                                            <a href="<?php echo Wo_LoadAdminLinkSettings('manage-user-verification?page-id=' . ($page - 1)); ?>" class="waves-effect" title='Previous Page'>
                                                <i class="material-icons">chevron_left</i>
                                            </a>
                                        </li>
                                    <?php  } ?>

                                    <?php
                                    $nums       = 0;
                                    $nums_pages = ($page > 4) ? ($page - 4) : $page;

                                    for ($i=$nums_pages; $i <= $db->totalPages; $i++) {
                                        if ($nums < 20) {
                                            ?>
                                            <li class="<?php echo ($page == $i) ? 'active' : ''; ?>">
                                                <a href="<?php echo Wo_LoadAdminLinkSettings('manage-user-verification?page-id=' . ($i)); ?>" class="waves-effect">
                                                    <?php echo $i ?>
                                                </a>
                                            </li>

                                        <?php } $nums++; }?>

                                    <?php if ($db->totalPages > $page) { ?>
                                        <li>
                                            <a href="<?php echo Wo_LoadAdminLinkSettings('manage-user-verification?page-id=' . ($page + 1)); ?>" class="waves-effect" title="Next Page">
                                                <i class="material-icons">chevron_right</i>
                                            </a>
                                        </li>
                                    <?php } ?>
                                    <li>
                                        <a href="<?php echo Wo_LoadAdminLinkSettings('manage-user-verification?page-id=' . ($db->totalPages)); ?>" class="waves-effect" title='Last Page'>
                                            <i class="material-icons">last_page</i>
                                        </a>
                                    </li>
                                </ul>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="clearfix"></div>
</div>
<div class="modal fade" id="DeleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModal1Label" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModal1Label">Delete Receipt?</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Are you sure you want to delete this Receipt?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">Delete</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="DeleteModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModal1Label" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModal1Label">Approve User?</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Are you sure you want to approve this user?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">Approve</button>
            </div>
        </div>
    </div>
</div>
<script>

    function Wo_DeleteUser(user_id,photo_file,type = 'show') {
        if (type == 'hide') {
            $('#DeleteModal').find('.btn-primary').attr('onclick', "Wo_DeleteUser('"+user_id+"','"+photo_file+"')");
            $('#DeleteModal').modal('show');
            return false;
        }
        hash_id = '<?php echo Wo_CreateSession();?>';

        $.get(Wo_Ajax_Requests_File(),{f:'admin_setting', s:'delete_user', user_id: user_id, p: 'manage-user-verification', receipt_file: photo_file, hash_id: hash_id})
        .done(function( data ) {
            $('#ReceiptID_' + user_id).fadeOut(300, function() {
                window.location = window.location.href ;
            });
        });
    }

    function Wo_ApproveUser(receipt_id,photo_file,type = 'show') {
        if (type == 'hide') {
            $('#DeleteModal2').find('.btn-primary').attr('onclick', "Wo_ApproveUser('"+receipt_id+"','"+photo_file+"')");
            $('#DeleteModal2').modal('show');
            return false;
        }
        hash_id = '<?php echo Wo_CreateSession();?>';
        $('#ReceiptID_' + receipt_id).fadeOut(300, function() {
            $(this).remove();
        });
        $.get(Wo_Ajax_Requests_File(),{f:'admin_setting', s:'approve_user', user_id: receipt_id, receipt_file: photo_file, p: 'manage-user-verification', hash_id: hash_id})
        .done(function( data ) {
            window.location = window.location.href + '?approved=true';
        });

    }

</script>