<?php
$page           = (!empty($_GET['page-id']) && is_numeric($_GET['page-id'])) ? Secure($_GET['page-id']) : 1;
$db->pageLimit  = 20;
$mediafiles = $db->objectbuilder()->orderBy('id', 'DESC')->paginate('mediafiles', $page);

if (($page > $db->totalPages) && !empty($_GET['page-id'])) {
    header("Location: " . Wo_LoadAdminLinkSettings('manage-photos'));
    exit();
}
$db->where('recipient_id',0)->where('admin',1)->where('seen',0)->where('type','image')->update('notifications',array('seen' => time()));

?>
<div class="container-fluid">
    <div>
        <h3>Manage Photos & Videos</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Photos</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Manage Photos & Videos</li>
            </ol>
        </nav>
    </div>
    <!-- Vertical Layout -->
		<div class="clearfix"></div>
		<?php if ($wo['config']['review_media_files'] == 1) {?>
			<button onclick="Wo_ApproveAllPhoto('hide');" type="button" class="btn btn-success waves-effect waves-light">Approve All</button> <button onclick="Wo_DisApproveAllPhoto('hide');" type="button" class="btn btn-warning waves-effect waves-light">Disapprove All</button><br><br>
		<?php } ?>
		<div class="row">
			<?php
			foreach ($mediafiles as $mediafilelist) {
				$wo['mediafilelist'] = $mediafilelist;
				$wo['mediafilelist']->user = $db->where('id', $mediafilelist->user_id)->objectbuilder()->getOne('users',array('username','avater'));
				$wo['mediafilelist']->user->avater = GetMedia($wo['mediafilelist']->user->avater);
				echo Wo_LoadAdminPage('manage-photos/list');
			}
			?>
		</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-photos?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-photos?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-photos?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-photos?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-photos?page-id=' . ($db->totalPages)); ?>" class="waves-effect" title='Last Page'>
								<i class="material-icons">last_page</i>
							</a>
						</li>
					</ul>
				</nav>
			</div>
		</div>
    <div class="clearfix"></div>
</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 Photo?</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 Photo?
            </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 Photo?</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 all media files?
            </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>
<div class="modal fade" id="DeleteModal3" 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">DisApprove Photo?</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 DisApprove all media files?
            </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">DisApprove</button>
            </div>
        </div>
    </div>
</div>


<script>
    $('.image-popup').magnificPopup({
        type: 'image',
        zoom: {
            enabled: true,
            duration: 300,
            easing: 'ease-in-out',
            opener: function(openerElement) {
                return openerElement.is('img') ? openerElement : openerElement.find('img');
            }
        }
    });

    function Wo_DeletePhoto(photo_id,photo_file,type = 'show') {
        if (type == 'hide') {
            $('#DeleteModal').find('.btn-primary').attr('onclick', "Wo_DeletePhoto('"+photo_id+"','"+photo_file+"')");
            $('#DeleteModal').modal('show');
            return false;
        }
        hash_id = '<?php echo Wo_CreateSession();?>';
        $('#PhotoID_' + photo_id).fadeOut(300, function() {
            $(this).remove();
        });
        $.get(Wo_Ajax_Requests_File(),{f:'admin_setting', s:'delete_photo', p: 'manage-photos', photo_id: photo_id, photo_file: photo_file, hash_id: hash_id});
    }

    function Wo_ApprovePhoto(photo_id,photo_file) {
        hash_id = '<?php echo Wo_CreateSession();?>';
        $('#mediafile_' + photo_id).fadeOut(300, function() {
            $(this).remove();
        });
        $.get(Wo_Ajax_Requests_File(),{f:'admin_setting', s:'approve_photo', p: 'manage-photos', photo_id: photo_id, photo_file: photo_file, hash_id: hash_id}, function (data) {
            if(data.status == 200){
                window.location.reload();
            }
        });
    }

    function Wo_DisApprovePhoto(photo_id,photo_file) {
        hash_id = '<?php echo Wo_CreateSession();?>';
        $('#mediafile_' + photo_id).fadeOut(300, function() {
            $(this).remove();
        });
        $.get(Wo_Ajax_Requests_File(),{f:'admin_setting', s:'disapprove_photo', p: 'manage-photos', photo_id: photo_id, photo_file: photo_file, hash_id: hash_id}, function (data) {
            if(data.status == 200){
                window.location.reload();
            }
        });
    }


    function Wo_ApproveAllPhoto(type = 'show') {
        if (type == 'hide') {
            $('#DeleteModal2').find('.btn-primary').attr('onclick', "Wo_ApproveAllPhoto()");
            $('#DeleteModal2').modal('show');
            return false;
        }
        hash_id = '<?php echo Wo_CreateSession();?>';
        $.get(Wo_Ajax_Requests_File(),{f:'admin_setting', s:'approve_all_photo', p: 'manage-photos', hash_id: hash_id}, function (data) {
            if(data.status == 200){
                window.location.reload();
            }
        });
    }

    function Wo_DisApproveAllPhoto(type = 'show') {
        if (type == 'hide') {
            $('#DeleteModal3').find('.btn-primary').attr('onclick', "Wo_DisApproveAllPhoto()");
            $('#DeleteModal3').modal('show');
            return false;
        }
        hash_id = '<?php echo Wo_CreateSession();?>';
        $.get(Wo_Ajax_Requests_File(),{f:'admin_setting', s:'disapprove_all_photo', p: 'manage-photos', hash_id: hash_id}, function (data) {
            if(data.status == 200){
                window.location.reload();
            }
        });
    }




</script>