<?php
include "include/db.php";
include "include/auth.php";
if(isset($_REQUEST['cl_id'])){
  if(strlen($_REQUEST['cl_id']) > 0){
    $cl_id = $_REQUEST['cl_id'];
  }else{
    exit;
  }
}else{
  exit;
}
$query_check_client = "SELECT * FROM client WHERE client_id = $cl_id AND is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";
$run_check_client = mysqli_query($conn, $query_check_client);
if(mysqli_num_rows($run_check_client)!=1){
  if($cl_id != 0){
  exit;}
}
if($user_type == 'admin'){     
    
?>

 <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                <!-- <div class="col-lg-12"> -->
                <h3>
       <a href="MAPS-sheet.php?new=&cl_id=<?php echo$cl_id; ?>" class="btn btn-success" role="button">Add Product</a>&nbsp &nbsp<a href="MAPS-sheet.php?group=&cl_id=<?php echo $cl_id; ?>" class="btn btn-success" role="button">Product Groups</a>&nbsp &nbsp<a href="MAPS-sheet.php?cat=&cl_id=<?php echo$cl_id; ?>" class="btn btn-success" role="button">Manage Categories</a></h3>
        </div>                                                     
   <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz<?php echo "old".$cl_id.$cl_id; ?>">
                                    <thead>
                                        <tr>
                                        <th>
                                                   Edit / Delete Row
                                                </th>
                                                <th>
                                                Job Task     
                                                </th>
                                                <th>
                                                Reference Photo
                                                </th>
                                                <th>
                                                Category

                                                </th>
                                               
                                                <th>
                                                Description
                                                </th>
                                                <th>
Client Allowable Price                                                </th>
                                               
                                            <th>Minimum Bid Price</th>
                                            <th>Crew Pay</th>
                                            <th>UOM</th>
                                            <th>Photo Requirements</th>
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){
        
       $query = "SELECT * FROM maps LEFT JOIN category
        ON maps.cat_id = category.cat_id  WHERE maps.maps_is_delete IS NULL AND maps.maps_approved = 1 AND maps.client_id = $cl_id ORDER BY category.cat_name"; 
        $run = mysqli_query($conn, $query);

        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){    


                $maps_id = $row['maps_id'];
                $ref_photo = $row['maps_ref_pic'];
                $cat_name = $row['cat_name'];
                $maps_name = $row['maps_name'];
                $description = $row['maps_desc'];
                $client_allow_price = $row['maps_client_allow_price'];
                $min_bid_price = $row['maps_min_bid_price'];
                $crew_pay = $row['maps_crew_pay'];
                $photo_req = $row['maps_photo_req'];
                $maps_uom =$row['maps_crew_unit_uom_id'];
if($maps_uom == NULL){

}else{
    $query22 = "SELECT uom_name FROM uom WHERE uom_id = $maps_uom";
                
    $run22 = mysqli_query($conn, $query22);
if(mysqli_num_rows($run22)==1){
$row22 = mysqli_fetch_array($run22);

$maps_uom = $row22['uom_name'];}
}                                    
                

                echo '<tr class="odd gradeX">';
                echo '<td><a href="MAPS-sheet.php?edit='.$maps_id.'&cl_id='.$cl_id.'">Edit</a><br><a href="MAPS-sheet.php?delete='.$maps_id.'&cl_id='.$cl_id.'">Delete</a></td>'; 
                echo '<td>' .$maps_name. '</td>';
                echo '<td><img src = "maps_ref_image.php?i='.$ref_photo.'" height = "80px" width = "120px">'. '</td>';
                echo '<td>' .$cat_name. '</td>';
             
                echo '<td>' .$description. '</td>';
                echo '<td>' .$client_allow_price. '</td>';
                echo '<td>' .$min_bid_price. '</td>';
                echo '<td>' .$crew_pay. '</td>';
                echo '<td>' .$maps_uom. '</td>';
                 echo '<td>' .$photo_req. '</td>';
                echo '</tr>';
            }
        }

    }

?>
                                            
                                            </tbody>
                                    
                                    </table>
                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->
        
        <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz<?php echo "new".$cl_id.$cl_id; ?>">
                                    <thead>
                                        <tr>
                                        <th>
                                                   Approve / Decline
                                                </th>
                                                <th>
                                                Job Task     
                                                </th>
                                                <th>
                                                Reference Photo
                                                </th>
                                                <th>
                                                Category

                                                </th>
                                              
                                                <th>
                                                Description
                                                </th>
                                                <th>
Client Allowable Price                                                </th>
                                               
                                            <th>Minimum Bid Price</th>
                                            <th>Crew Pay</th>
                                            <th>UOM</th>
                                            <th>Photo Requirements</th>
                                            <th>
Added by                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){        
       $query = "SELECT * FROM maps LEFT JOIN category
        ON maps.cat_id = category.cat_id  WHERE maps.maps_is_delete IS NULL AND maps.maps_approved = 0 AND maps.client_id = $cl_id ORDER BY category.cat_name"; 
        $run = mysqli_query($conn, $query);
        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){
                $maps_id = $row['maps_id'];
                $ref_photo = $row['maps_ref_pic'];
                $cat_name = $row['cat_name'];
                $maps_name = $row['maps_name'];
                $description = $row['maps_desc'];
                $client_allow_price = $row['maps_client_allow_price'];
                $min_bid_price = $row['maps_min_bid_price'];
                $crew_pay = $row['maps_crew_pay'];
                $photo_req = $row['maps_photo_req'];
                $maps_uom =$row['maps_crew_unit_uom_id'];
                $query_emp = "SELECT * FROM maps WHERE maps_id = $maps_id"; 
                $run_emp = mysqli_query($conn, $query_emp);
                $row_emp = mysqli_fetch_array($run_emp);
                $empl_id =  $row_emp['employee_id'];
                $query111 = "SELECT employee_fname,employee_lname FROM employee WHERE employee_id = $empl_id";
                $run111 = mysqli_query($conn, $query111);
                if(mysqli_num_rows($run111) >0){
                    $row111 = mysqli_fetch_array($run111);
                
                    $emp_name = $row111['employee_fname'] .' '.$row111['employee_lname'];
                   
                }  
if($maps_uom == NULL){

}else{
    $query22 = "SELECT uom_name FROM uom WHERE uom_id = $maps_uom";
                
    $run22 = mysqli_query($conn, $query22);
if(mysqli_num_rows($run22)==1){
$row22 = mysqli_fetch_array($run22);

$maps_uom = $row22['uom_name'];
}

}
                          
                
                

                echo '<tr class="odd gradeX" style = "background-color:#ffbb96">';
                echo '<td><a href="MAPS-sheet.php?addmapsapprove='.$maps_id.'" class = "btn btn-success">Approve</a><br><a href="MAPS-sheet.php?addmapsdecline='.$maps_id.'" class = "btn btn-danger">Decline&nbsp</a></td>'; 
                echo '<td>' .$maps_name. '</td>';

                echo '<td><img src = "maps_ref_image.php?i='.$ref_photo.'" height = "80px" width = "120px">'. '</td>';
                echo '<td>' .$cat_name. '</td>';
                echo '<td>' .$description. '</td>';
                echo '<td>' .$client_allow_price. '</td>';
                echo '<td>' .$min_bid_price. '</td>';
                echo '<td>' .$crew_pay. '</td>';
                echo '<td>' .$maps_uom. '</td>';
                 echo '<td>' .$photo_req. '</td>';
                 echo '<td>' .$emp_name. '</td>'; 
                echo '</tr>';
            }
        }

    }

?>
                                            
                                            </tbody>
                                    
                                    </table>
                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->
<?php

}else if($user_type == 'staff'){     
 ?>
<div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                <!-- <div class="col-lg-12"> -->
                <h3>
       <a href="MAPS-main.php?new=&cl_id=<?php echo$cl_id; ?>" class="btn btn-success" role="button">Add Product</a>&nbsp &nbsp<a href="MAPS-main.php?group=&cl_id=<?php echo$cl_id; ?>" class="btn btn-success" role="button">Product Groups</a>&nbsp &nbsp<a href="MAPS-main.php?cat=&cl_id=<?php echo$cl_id; ?>" class="btn btn-success" role="button">Manage Categories</a></h3>
        </div>                                                     
   <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz<?php echo "old".$cl_id.$cl_id; ?>">
                                    <thead>
                                        <tr>
                                      
                                                <th>
                                                Job Task     
                                                </th>
                                                <th>
                                                Reference Photo
                                                </th>
                                                <th>
                                                Category

                                                </th>
                                               
                                                <th>
                                                Description
                                                </th>
                                                <th>
Client Allowable Price                                                </th>
                                               
                                            <th>Minimum Bid Price</th>
                                            <th>Crew Pay</th>
                                            <th>UOM</th>
                                            <th>Photo Requirements</th>
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){
        
       $query = "SELECT * FROM maps LEFT JOIN category
        ON maps.cat_id = category.cat_id  WHERE maps.maps_is_delete IS NULL AND maps.maps_approved = 1 AND maps.client_id = $cl_id ORDER BY category.cat_name"; 
        $run = mysqli_query($conn, $query);

        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){    


                $maps_id = $row['maps_id'];
                $ref_photo = $row['maps_ref_pic'];
                $cat_name = $row['cat_name'];
                $maps_name = $row['maps_name'];
                $description = $row['maps_desc'];
                $client_allow_price = $row['maps_client_allow_price'];
                $min_bid_price = $row['maps_min_bid_price'];
                $crew_pay = $row['maps_crew_pay'];
                $photo_req = $row['maps_photo_req'];
                $maps_uom =$row['maps_crew_unit_uom_id'];
if($maps_uom == NULL){

}else{
    $query22 = "SELECT uom_name FROM uom WHERE uom_id = $maps_uom";
                
    $run22 = mysqli_query($conn, $query22);
if(mysqli_num_rows($run22)==1){
$row22 = mysqli_fetch_array($run22);

$maps_uom = $row22['uom_name'];}
}                                    
                

                echo '<tr class="odd gradeX">';
            
                echo '<td>' .$maps_name. '</td>';
                echo '<td><img src = "maps_ref_image.php?i='.$ref_photo.'" height = "80px" width = "120px">'. '</td>';
                echo '<td>' .$cat_name. '</td>';             
                echo '<td>' .$description. '</td>';
                echo '<td>' .$client_allow_price. '</td>';
                echo '<td>' .$min_bid_price. '</td>';
                echo '<td>' .$crew_pay. '</td>';
                echo '<td>' .$maps_uom. '</td>';
                 echo '<td>' .$photo_req. '</td>';
              
                echo '</tr>';
            }
        }

    }

?>
                                            
                                            </tbody>
                                    
                                    </table>
                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->
        
        <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz<?php echo "new".$cl_id.$cl_id; ?>">
                                    <thead>
                                        <tr>
                                      
                                                <th>
                                                Job Task     
                                                </th>
                                                <th>
                                                Reference Photo
                                                </th>
                                                <th>
                                                Category

                                                </th>
                                              
                                                <th>
                                                Description
                                                </th>
                                                <th>
Client Allowable Price                                                </th>
                                               
                                            <th>Minimum Bid Price</th>
                                            <th>Crew Pay</th>
                                            <th>UOM</th>
                                            <th>Photo Requirements</th>
                                           
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){        
       $query = "SELECT * FROM maps LEFT JOIN category
        ON maps.cat_id = category.cat_id  WHERE maps.maps_is_delete IS NULL AND maps.maps_approved = 0 AND maps.client_id = $cl_id AND maps.employee_id = $employee_id ORDER BY category.cat_name"; 
        $run = mysqli_query($conn, $query);
        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){
                $maps_id = $row['maps_id'];
                $ref_photo = $row['maps_ref_pic'];
                $cat_name = $row['cat_name'];
                $maps_name = $row['maps_name'];
                $description = $row['maps_desc'];
                $client_allow_price = $row['maps_client_allow_price'];
                $min_bid_price = $row['maps_min_bid_price'];
                $crew_pay = $row['maps_crew_pay'];
                $photo_req = $row['maps_photo_req'];
                $maps_uom =$row['maps_crew_unit_uom_id'];
                  
if($maps_uom == NULL){

}else{
    $query22 = "SELECT uom_name FROM uom WHERE uom_id = $maps_uom";
                
    $run22 = mysqli_query($conn, $query22);
if(mysqli_num_rows($run22)==1){
$row22 = mysqli_fetch_array($run22);

$maps_uom = $row22['uom_name'];
}

}
if($row['maps_approved'] == 1){
    $cell_color = '';    
  }else{
    $cell_color = '#ff976e';
  }    
                echo '<tr class="odd gradeX" style = "background-color:#ff976e">';
                
                echo '<td>' .$maps_name. '</td>';

                echo '<td><img src = "maps_ref_image.php?i='.$ref_photo.'" height = "80px" width = "120px">'. '</td>';
                echo '<td>' .$cat_name. '</td>';
                echo '<td>' .$description. '</td>';
                echo '<td>' .$client_allow_price. '</td>';
                echo '<td>' .$min_bid_price. '</td>';
                echo '<td>' .$crew_pay. '</td>';
                echo '<td>' .$maps_uom. '</td>';
                 echo '<td>' .$photo_req. '</td>';              
                echo '</tr>';
            }
        }

    }

?>
                                            
                                            </tbody>
                                    
                                    </table>
                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->




<?php
}
?>