<?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('submission', 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>Submissions</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>Uzvārds </label>
                                    <input type="text" placeholder="" value="<?php echo htmlspecialchars($od['surname']); ?>" readonly />
                                </div>
								 <div class="col-md-12">
                                	<label>Vēlamais norises datums</label>
                                    <input type="text"  value="<?php echo htmlspecialchars($od['preferred_date']); ?>" readonly />
                                </div>
                            	<div class="col-md-12">
                                	<label>E-pasts </label>
                                    <input type="text" placeholder="Phone Number"  value="<?php echo htmlspecialchars($od['email']); ?>" 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">
                                	<label>Jūsu piezīmes </label>
                                    <textarea  placeholder="Message" class="form-control" readonly style="background-color:white"><?php echo htmlspecialchars($od['message']); ?></textarea>
                                </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');
        $('#submission-menu').addClass('activ-cat');
    }); 

    $(document).on('click', '.btn-delete', function(res){
         var conf = confirm("Are you sure you want to delete this submission?");
            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('submission_delete', {id:id}, function(){
            alert('Submission Deleted Successfully');
            $(parent).remove();
        },'json').fail(function(xhr){
           alert(xhr.responseJSON);
           $(current).removeAttr('disabled').text('Delete');
        },'json');
    });
</script>

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