<?php 
require_once('includes/check-login.php');
require_once('includes/header.php'); 
require_once('includes/menu.php'); 
require_once('includes/config.php'); 
$tablename="save_order";	
$addurl="service-view.php";
$order_date=date("Y-m-d");          
if($_SESSION['role_id']==1){
$sql = "SELECT * from ".$tablename." WHERE order_date='$order_date' and job_status='0' order by id desc";
}else{
$sql="SELECT * from ".$tablename." WHERE order_date='$order_date' and job_status='0' and vendor_id='".$_SESSION['userid']."'";    
}
$result=$con->query($sql);
?>
<!-- Datatable CSS -->
<link href='data_tables/datatables.min.css' rel='stylesheet' type='text/css' />     <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">                                
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>                    
                        <li class="active"><a href="#">Pending Job Request</a></li>           
                    </ol>                
            </section>

            <!-- Main content -->
            <section class="content">                
                <!-- Default box -->
                <div class="box box-form">
                    <div class="box-header with-border">
                        <h3 class="box-title">Pending Job Request</h3>
                        <div class="box-tools pull-right">
                            <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                                <i class="fa fa-minus"></i></button>
                            <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                                <i class="fa fa-times"></i></button>
                        </div>
				<header class="box-typical-header"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
				</header>	
                    </div>
                    <div class="box-body">    
                        <!-- Table -->
                        <table id='workapp' class='display dataTable table table-bordered table-hover'>
                            <thead>
                            <tr>
                                <th>Order ID</th>                    
                                <th>Vendor Name</th>  
                                <th>Vendor Phone</th> 
                                <th>Job Date & Time</th>
                                <th>Status</th>
                                <th>Action</th>                                 
                            </tr>
                            </thead> 
                              <tbody>
							<?php $i=1;
							if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                            $tamp=intval($row['created_time']);
                            $vendor_id=$row['vendor_id'];
                            $vensql=$con->query("SELECT name,phone from user_details WHERE user_id='$vendor_id'");
                            $vendorrow=mysqli_fetch_array($vensql);
                            if(time() - $tamp > 1800){ 
                            $status=$row['job_status'];
                            if($status==0){
                               $stacom="Pending"; 
                            }else if($status==1){
                               $stacom="Approved";  
                            }else if($status==2){
                               $stacom="Completed";  
                            }else{
                               $stacom="Canceled";  
                            }?>
						   <tr>
						   <td><?php echo $row['id'];?></td>
						   <td><?php echo $vendorrow['name'];?></td>
						   <td><?php echo $vendorrow['phone'];?></td>
						   <td><?php echo $row['job_date'];?> & <?php echo $row['job_time'];?></td>
						   <td><?php echo $stacom;?></td>
						   <td><a href="<?php echo $base_url.$addurl;?>?id=<?php echo $row['id'];?>&vendor_id=<?php echo $row['vendor_id'];?>&expired='expired' class="tabledit-edit-button btn btn-sm btn-primary" title="View"><span class="glyphicon glyphicon-eye-open"></span></a></td>
						    </tr>								  
							 <?php $i++;}}}?>
                           </tbody>							
                        </table>

                    </div>
                    
                    <!-- /.box-footer-->                    
                </div>
                <!-- /.box -->

            </section>
            <!-- /.content -->                                        
        </div>
        <!-- /.content-wrapper -->        
<script src="js/common.js"></script>  
<script src="js/datatables.js"></script>    
<script src="<?php echo $base_url;?>js/lobibox.js"></script>  
<?php require_once('includes/footer.php'); ?>