<?php
/*include_once "../ichat/admin/route.php";
require_once 'database.php';
if(isset($_SESSION[$elhash]) && $_SESSION[$elhash] != "") { 
    $random_hash = $_SESSION[$elhash];
} else {
    $random_hash = uniqid();
    $_SESSION[$elhash] = $random_hash;
}
session_start();

if(!isset($_SESSION['id']) || $_SESSION['id']=='')
    {
            header('Location: index.php');
    }
    if(!isset($_SESSION['user_type']) || ($_SESSION['user_type'] != 'admin'))
    {
           // header('Location:index.php');
    }*/


session_start();
require_once "check_admin.php";
require_once 'database.php';

class submissions extends database
	{
		public function index($page)
		{
			$start = $page - 1;
			return $this->fetchAll('new_submit', null, 'created_at', 'DESC', ($start * 20), 20);
		}
		
	}
if(isset($_GET['message']))
{
	$msg=$_GET['message'];
}

$page = 1;
if(isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 1)
{
    $page = htmlspecialchars($_GET['page']);
}

$sub = new submissions();
$res = $sub->index($page);
include 'header.php';
?>
<div class="ordes-content">
    <div class="container midle-order">
        <div class="row">
        	<?php include 'menu.php'; ?>
            <div class="col-md-9">
                <div class="order-wraper">
                	<div class="col-md-12">
                    	<h1>Reservations</h1>
                    </div>
                    <div class="clearfix"></div>
					<?php
					foreach($res as $od)
					{
					?>
                    <div class="col-sm-6 submission-container">
                    	<div class="order-contact">
                        	<h2>ID: #<?php echo $od['id'];?></h2>
                            <div class="row">
                            	<div class="col-md-12">
                                	<label>Vārds</label>
                                    <input type="text" placeholder="" value="<?php echo htmlspecialchars($od['name']); ?>" readonly />
                                </div>
                            	 <div class="col-md-12">
                                	<label>Kontakttālrunis</label>
                                    <input type="text"  value="<?php echo htmlspecialchars($od['phone']); ?>" readonly />
                                </div>
								 <div class="col-md-12">
                                	<label>Vēlamais norises datums</label>
                                    <input type="text"  value="<?php echo htmlspecialchars(date("d M Y", strtotime($od['preferred_date']))) . ' ' . htmlspecialchars($od['preffered_time']); ?>" readonly />
                                </div>
                            
                                <div class="col-md-12">
                                	<label>Cilvēku skaits</label>
                                    <input type="text" placeholder="Phone Number"  value="<?php echo htmlspecialchars($od['no_of_persons']); ?>" readonly />
                                </div>
                               
                            	<div class="col-md-12 botm-cont">
                                    <button type="button" class="btn btn-danger pull-left btn-delete" data-id="<?php echo htmlspecialchars($od['id'])?>">Delete</button>
                                </div>
                            	
                              <!--  <div class="col-md-12 botm-cont">
                                	<button type="submit" class="track-btn">Approve</button>
                                </div>-->
                                
                            </div>
                        </div>
                    </div>
					<?php
					}
					?>
                    <div class="pull-right col-xs-12 top-margin">
                         <?php
                        if($page > 1)
                        {
                        ?>
                        <a href="?page=<?php echo htmlspecialchars($page) - 1 ?>" class="track-btn">
                            Previous
                        </a>
                        <?php
                        }
                        if(count($res) == 20)
                        {
                        ?>
                            <a href="?page=<?php echo htmlspecialchars($page) + 1 ?>" class="track-btn">
                                Next
                            </a>
                        <?php
                        }
                        ?>
                    </div>
                </div>
                
            </div>
        </div>
	</div>
</div>

<script>
    $(document).ready(function(){
        $('.activ-cat').removeClass('activ-cat');
        $('#reservation-menu').addClass('activ-cat');
    }); 

    $(document).on('click', '.btn-delete', function(res){
         var conf = confirm("Are you sure you want to delete this reservation?");
            if(!conf)
            {
                return;
            }
        $(this).attr('disabled', 'disabled').text('Deleting......');

        var current = $(this);
        var id = $(this).attr('data-id');
        var parent = $(this).parents('.submission-container').first();
        $.post('reservation_delete', {id:id}, function(){
            alert('Reservation Deleted Successfully');
            $(parent).remove();
        },'json').fail(function(xhr){
           alert(xhr.responseJSON);
           $(current).removeAttr('disabled').text('Delete');
        },'json');
    });
</script>

<?php include 'footer.php';?>