<style>
/* 
Max width before this PARTICULAR table gets nasty
This query will take effect for any screen smaller than 760px
and also iPads specifically.
*/
@media only screen and (max-width: 560px), (min-device-width: 568px) and (max-device-width: 1024px) {
/* Force table to not be like tables anymore */
table, thead, tbody, th, td, tr {display: block;}
/* Hide table headers (but not display: none;, for accessibility) */
thead tr {position: absolute;top: -9999px;left: -9999px;}
tr {border: 0px solid #ccc;}
td {
	/* Behave  like a "row" */
	border: none;
	/*border-bottom: 1px solid #eee; */
	position: relative;
	padding-left: 50%;
}
td:before {
	/* Now like a table header */
	position: unset; /*absolute causing issues*/
	/* Top/left values mimic padding */
	top: 6px;
	left: 6px;
	width: 45%;
	padding-right: 10px;
	white-space: nowrap;
}
/*Label the data*/
td:nth-of-type(1):before {content: "Technician";}
td:nth-of-type(2):before {content: "Client";}
td:nth-of-type(3):before {content: "Description";}
td:nth-of-type(4):before {content: "Assignor";}
td:nth-of-type(5):before {content: "Assignee";}
td:nth-of-type(6):before {content: "Assign";}
td:nth-of-type(7):before {content: "Actions";}
.table-checkable tr > td:first-child, .table-checkable tr > th:first-child { max-width: 20%; }
}
@media only screen and (max-width: 480px), (min-device-width: 300px) and (max-device-width: 480px) {
	.table-checkable tr > td:first-child, .table-checkable tr > th:first-child { max-width: 100%; }
	td:nth-of-type(1)::before { content: "";}
}
.card-body {
  padding: 10px 7px 14px;
  position: relative;
}
.table td, .card .table td, .card .dataTable td {
  padding: 0 4px;  
}
.client_rec{
	padding:0;
	margin:0;
	line-height: 20px;
}
</style>
<script src="assets/plugins/jquery/jquery.min.js" ></script>
<script>
function setAssignee(leadsid){
	var assignee = $('#assignee'+leadsid).val();
	if(assignee!='' && assignee!='undefined'){
		$.ajax({url:"ajax/ajax.php?action=set_assignee&admin_id="+assignee+"&leads_id="+leadsid,success:function(result){								
				if(result=='success'){
					$("#ajax_result-"+leadsid).html('<span style="color:green;">Assigned</span>');			
					setTimeout(function() {
					    location.reload();
					}, 1000);		
				} else {					
					$("#ajax_result-"+leadsid).html('<span style="color:red;">'+result+'</span>');					
				}													
		}});
	}
}
</script>
<div class="page-content-wrapper">
                <div class="page-content">
                    <div class="page-bar">
                        <div class="page-title-breadcrumb">
                            <div class=" pull-left">
                                <div class="page-title">Tech Leads</div>
                            </div>
                            <ol class="breadcrumb page-breadcrumb pull-right">
                                <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item" href="index.php?page=home">Home</a>&nbsp;<i class="fa fa-angle-right"></i>
                                </li>
                                <li><a class="parent-item" href="index.php?page=manage_technician">Manage Technician</a>&nbsp;<i class="fa fa-angle-right"></i></li><li class="active">Leads</li>
                            </ol>
                        </div>
                    </div>
                    
	 <div class="row">
                        <div class="col-md-12 pl-0 pr-0">
                            <div class="card card-topline-red">
                                <div class="card-head">
                                    <header>Leads</header>
                                    <div class="tools">
                                        <!--<a class="fa fa-repeat btn-color box-refresh" href="javascript:;"></a>-->
	                                    <a class="t-collapse btn-color fa fa-chevron-down" href="javascript:;"></a>
	                                    <a class="t-close btn-color fa fa-times" href="javascript:;"></a>
                                    </div>
                                </div>     
                                                           
                                <div class="card-body ">  
                                	<div class="row p-b-20 text-left">                                  		
	                                		<div class="col-md-2 col-sm-12 col-12">
	                                            <div class="btn-group">
	                                                <button onclick="location.href = 'index.php?page=add_leads';" id="addRow1" class="btn btn-info">
	                                                    Add Leads <i class="fa fa-plus"></i>
	                                                </button>
	                                            </div>	                                            
	                                        </div>
	                                        <div class="col-md-10 text-right">	
	                                        	<form name="form" id="form" action="" method="post">		                                	                                		                                		
			                                        <div class="col-12 pl-0 pr-0" style="min-width:425px">
			                                        	<input type="text" class="form-control col-4" style="margin-right: 8px;float:left;" name="searchvalue" id="searchvalue" placeholder="Search Client"  value="<?php if(isset($_POST['searchvalue'])) { echo $_POST['searchvalue']; }  ?>" /> 
					                                	<select class="form-control col-3 mr-2" style="float: left;" name="search_assignee" id="search_assignee">
					                                		<option value="">--- Select Assignee --</option>
					                                		<?php if(mysqli_num_rows($assigneeRs)>0){
			                                                	while($assigneeRec = mysqli_fetch_array($assigneeRs)){ ?>
			                                                				<option <?php if(isset($_REQUEST['search_assignee']) && $_REQUEST['search_assignee']==$assigneeRec['admin_id']){ echo 'selected'; }?> value="<?php echo $assigneeRec['admin_id'];?>"><?php echo $assigneeRec['ad_username'];?></option>
			                                                <?php } }?>		                                		
					                                	</select>	
					                                	<select class="form-control col-2" style="float: left;" name="search_status" id="search_status">
					                                		<option value="">Select Status</option>
					                                		<?php if(mysqli_num_rows($statusRs)>0){
			                                                	while($statusRec = mysqli_fetch_array($statusRs)){ ?>
			                                                		<option <?php if(isset($_REQUEST['search_status']) && $_REQUEST['search_status']==$statusRec['status']){ echo 'selected'; }?> value="<?php echo $statusRec['status'];?>"><?php echo $statusRec['status'];?></option>
			                                                <?php } }?>		                                		
					                                	</select>	                                										
														<button style="float: left; margin-left: 5px;" class="btn mr-2" name="search">Search</button>&nbsp;
														<button style="float: left; " class="btn" name="clear">Clear</button>	
													</div>	
												</form>									
											</div>										
                                     </div>                                
                                    <?php if(isset($_REQUEST['success'])){ ?><div class="alert alert-success"><?php echo urldecode($_REQUEST['success']); ?></div></div><?php } ?>
                                    <?php if(isset($execDetails) && mysqli_num_rows($execDetails)>0) { ?>
                                    <table class="table table-striped table-bordered table-hover table-checkable order-column" style="width: 100%" id="example4">
                                        <thead>
                                            <tr>                                                
                                                <th width="10%"> From </th>
                                                <th width="20%"> Client </th>
                                                <th width="12%"> Description </th>                                                
                                                <th width="10%"> Assignor </th>  
                                                <th width="10%"> Assignee </th>
                                                <th width="10%"> Assign </th>  
                                                <th width="12%"> 
                                                	<?php if(isset($_REQUEST['sort']) && $_REQUEST['sort']=='asc'){ ?>
                                                		<a href="index.php?page=tech_leads&sort=dsc">Delivery Date</a> 
                                                	<?php } else { ?>
                                                		<a href="index.php?page=tech_leads&sort=asc">Delivery Date</a> 
                                                	<?php } ?>
                                                </th>                                                                                            
                                                <th width="10%"> Status </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        	<?php
                                        	if(isset($_GET['p']) && is_numeric($_GET['p']) && ($_GET['p'] > 1)) {
												$slNo = ($_GET['p']*30-29);
											} else {
												$slNo = 1;
											}
											while($resDetails = mysqli_fetch_array($execDetails)) {
												//get list of admin users
												
												//get last dilivery date from tbl_leads_notes if added
												$leadsNotesRs = mysqli_query($con, "SELECT delivery_date FROM tbl_leads_notes WHERE leads_id = '".$resDetails['id']."' AND delivery_date != '0000-00-00' ORDER BY id DESC LIMIT 1");
												if(mysqli_num_rows($leadsNotesRs)>0){
													$hasDeliveryDate = TRUE;
													$leadsNotesRec = mysqli_fetch_array($leadsNotesRs);
													$deliveryDate = $leadsNotesRec['delivery_date'];
												} else {
													$hasDeliveryDate = FALSE;
													$deliveryDate = '';
												}
												
											?>
                                            <tr class="odd gradeX">                                                
                                                <td style="max-width:250px;">
                                                	<?php if($resDetails['added_by']=='admin'){ ?>
                                                		<?php echo getAdminUserName($resDetails['admin_id']); ?> (Admin)
                                                	<?php } else { ?>
                                                		<a target="_blank" href="index.php?page=view_technician&id=<?php echo $resDetails['technician_id']; ?>"><?php echo getTechnicianName($resDetails['technician_id']); ?></a>
                                                		(Tech)
                                                	<?php } ?>
                                                </td>
                                                <td>
                                                	<p class="client_rec"><b><?php echo $resDetails['client_name']; ?></b></p>
												  	<p class="client_rec"><?php echo 'Phone: '.$resDetails['phone']; ?></p>
												  	<p class="client_rec"><?php echo $resDetails['location']; ?></p>
												  	<p class="client_rec"><?php echo getFormattedDate($resDetails['date']); ?></p>                                               	
                                                </td>
                                                <td><?php echo $resDetails['details']; ?></td>                                                
                                                <td><?php if($resDetails['assigned_by']>0){ echo getAdminUserName($resDetails['assigned_by']); } ?></td>
                                                <td><?php if($resDetails['assignee']>0){ echo getAdminUserName($resDetails['assignee']); } ?></td>
                                                <td>
                                                	<?php
                                                	$adminUserRs = mysqli_query($con, "SELECT admin_id, ad_username FROM tbl_admin WHERE role != 'super_admin' AND status = 'Active' AND admin_id != '".$resDetails['assignee']."' ORDER BY ad_username");
                                                	?>
                                                	<select name="assignee" id="assignee<?php echo $resDetails['id'];?>" onchange="setAssignee(<?php echo $resDetails['id'];?>);" >
                                                		<option value="">--Select--</option>
                                                		<?php if(mysqli_num_rows($adminUserRs)>0){
                                                			while($adminUserRec = mysqli_fetch_array($adminUserRs)){ ?>
                                                				<option value="<?php echo $adminUserRec['admin_id'];?>"><?php echo $adminUserRec['ad_username'];?></option>
                                                		<?php }
                                                		}?>
                                                	</select>
                                                	<div id="ajax_result-<?php echo $resDetails['id'];?>"></div>
                                                	<?php //echo $resDetails['assignee']; ?>
                                                </td>
                                                <td>
                                                	<?php //if($hasDeliveryDate){ echo getFormattedDate($deliveryDate); } else { echo 'Not available'; } ?>
                                                	<?php if($resDetails['delivery_date']!='0000-00-00'){ echo getFormattedDate($resDetails['delivery_date']); } else { echo 'Date not added'; } ?>
                                                </td>                                                                                                                                            
                                                <td class="valigntop text-left">
                                                	                                                	
                                                		
                                                    <div class="btn-group mb-2">
                                                    	<?php if($resDetails['status']=='Pending'){ ?>
	                                                		<span class="label label-sm label-warning"> Pending </span>
	                                                	<?php } else if($resDetails['status']=='Accepted'){ ?>
	                                                		<span class="label label-sm label-success"> Accepted </span>
	                                                	<?php } else if($resDetails['status']=='Rejected'){ ?>
	                                                		<span class="label label-sm label-danger"> Rejected </span>
	                                                	<?php } else if($resDetails['status']=='Processing'){ ?>
	                                                		<span class="label label-sm label-success"> Under Process </span>
	                                                	<?php } else if($resDetails['status']=='Completed'){ ?>
	                                                		<span class="label label-sm label-success"> Completed </span>
	                                                	<?php } ?>
                                                	</div><br>

                                                    <div class="btn-group">              
                                                        <button class="btn btn-xs deepPink-bgcolor dropdown-toggle no-margin" type="button" data-toggle="dropdown" aria-expanded="false"> Actions
                                                            <i class="fa fa-angle-down"></i>
                                                        </button>
                                                        <ul class="dropdown-menu pull-left" role="menu"> 
                                                        	<?php if($resDetails['status']=='Pending'){ ?>
                                                        	<li>
                                                                <a href="index.php?page=tech_leads&action=accept&id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> Accept </a>
                                                            </li> 
                                                            <?php } ?>
                                                            <?php if($resDetails['status']!='Rejected'){ ?>
                                                            <li>
                                                                <a href="index.php?page=tech_leads&action=reject&id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> Reject </a>
                                                            </li>
                                                            <?php } ?>
                                                            <?php if($resDetails['status']!='Processing'){ ?>
                                                            <li>
                                                                <a href="index.php?page=tech_leads&action=processing&id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> Under Process </a>
                                                            </li>
                                                            <?php } ?>
                                                            <?php if($resDetails['status']!='Completed'){ ?>
                                                            <li>
                                                                <a href="index.php?page=tech_leads&action=completed&id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> Completed </a>
                                                            </li>  
                                                            <?php } ?>
                                                            <?php if($resDetails['status']!='Pending'){ ?>
                                                            <li>
                                                                <a href="index.php?page=tech_leads&action=pending&id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> Pending </a>
                                                            </li>  
                                                            <?php } ?>
                                                            <li>
                                                                <a target="_blank" href="index.php?page=leads_note&id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> View Details </a>
                                                            </li>                                                     	                 
															 <li>
                                                                <a target="_blank" href="index.php?page=tech_leads_edit&id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> Edit </a>
                                                            </li>    
                                                            <li>
                                                                <a  onclick="return confirm('Are you sure to delete this item?');" href="index.php?page=tech_leads&action=delete&del_id=<?php echo $resDetails['id']; ?>&p=<?php echo $p; ?>">
                                                                    <i class="icon-docs"></i> Delete </a>
                                                            </li>                                                          
                                                        </ul>
                                                    </div>
                                                </td>
                                            </tr>
                                            <?php ++$slNo; } ?>                                            
                                        </tbody>
                                    </table>
                                    <div style="float: left;"> <?php echo $pageNums; ?> </div>
                                    <?php } else { ?>
                                    	<div class="alert alert-danger">Sorry! No Results Found.</div>					        		
					        		<?php }	?> 
                                </div>
                            </div>
                        </div>
                    </div>
                    

</div>
</div>