<?php
include("common/connection.php");
login_check();
?>
<!doctype html>
<html class="no-js" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>To be Called Leads | Buurtzorg</title>
    <script>
	function delete_lead(per) 
	{
	  var response = confirm("Are You Sure to Delete Lead!");
	  if (response == true) 
	  {
		$.ajax({
		url:"ajax_delete_lead.php",
		type:"POST",
		data:{'per':per},
		success:function(data)
		{
 			//alert('Lead '+data+' Deleted Successfully');
		}
		});
	  } 
	  else 
	  {
		alert('Lead Not Deleted');
	  }
	}
	</script>
    <script>
	function update_callconnect(Status,Lead_Id)
	{
	 //alert(Status);
	 
	 $.ajax({
		url:"ajax_updatecall_lead.php",
		type:"POST",
		data:{'Status':Status,'Lead_Id':Lead_Id},
		success:function(data)
		{
		//alert(data)
			if(Status=='Call Connected')
			{
			
			  window.location.href='call_connected.php?Lid='+Lead_Id;
			}
			else
			{
			  window.location.href='current_leads.php';
			}
		}
		})
	}
	</script>
    <?php include("headerlink.php"); ?>
    <?php
		//---------user type check-------// 
		$user_sql="select User_Type as type from user_master where User_Name='".$_SESSION['user']."'";
		$user_query=mysqli_query($con,$user_sql);
		$user=mysqli_fetch_array($user_query);
		
		//---------all leads fetching by condition-------// 
		$all_leads_sql="select count(Lead_ID) as total_leads from lead_master";
		
		if($user['type']!='Super Admin')
		{
		$all_leads_sql.=" where Lead_Referred_To='".$_SESSION['user']."'";
		}
		$all_leads_query=mysqli_query($con,$all_leads_sql);
		$all_leads=mysqli_fetch_array($all_leads_query);
		
		
		//---------fresh leads fetching by condition-------// 
		$fresh_leads_sql="select count(Lead_ID) as fresh_leads from lead_master where Status ='Yet to be Called'";
		
		if($user['type']!='Super Admin')
		{
		$fresh_leads_sql.=" and Lead_Referred_To='".$_SESSION['user']."'";
		}
		
		$fresh_leads_query=mysqli_query($con,$fresh_leads_sql);
		$fresh_leads=mysqli_fetch_array($fresh_leads_query);
		
		//---------fresh leads fetching by condition-------// 
		$progress_leads_sql="select count(Lead_ID) as progress_leads from lead_master where (Status !='Yet to be Called' and Status !='')";
		
		if($user['type']!='Super Admin')
		{
		$progress_leads_sql.=" and Lead_Referred_To='".$_SESSION['user']."'";
		}
		
		$progress_leads_query=mysqli_query($con,$progress_leads_sql);
		$progress_leads=mysqli_fetch_array($progress_leads_query);
		
		//---------today leads fetching by condition-------// 
		$today_leads_sql="select count(Lead_ID) as today_leads from communication_master where (Status !='Yet to be Called' and Status !='') and Date_Of_Communication LIKE'".date('Y-m-d')."%'";
		
		if($user['type']!='Super Admin')
		{
		$today_leads_sql.=" and Communicator_ID='".$_SESSION['user']."'";
		}
		//echo $today_leads_sql;
		$today_leads_query=mysqli_query($con,$today_leads_sql);
		$today_leads=mysqli_fetch_array($today_leads_query);		
		?>
     	<link rel="stylesheet" href="css/data-table/bootstrap-table.css">
    	<link rel="stylesheet" href="css/data-table/bootstrap-editable.css">
        
        
        <style>
		table {overflow:inherit !important}
		table thead {overflow:inherit !important}
		table thead tr {overflow:inherit !important}
		
		table tbody {overflow:inherit !important}
		table tbody tr {overflow:inherit !important; }
		table tbody tr td {overflow:inherit !important}
		
		
		.fixed-table-body {overflow:inherit !important}
		.action_dropdown {padding:0 !important; min-width:460px !important;  left:-258px; background-color:rgba(0,0,0,0) !important;
		 box-shadow:none !important; border:none !important; margin-top:-70px}
										
		 .action_dropdown:after {
			  content:'';
			  width: 0;
			  height: 0;
			  border-left: 7px solid transparent;
			  border-right: 7px solid transparent;
			  border-top: 12px solid #337ab7;
			  margin-top:40px;
			  position:absolute;
			  top:-10px;
			  margin-left:-190px;
		}
		
		
		 .bgcolor_1 { background-color:#f2dede; color:#a94442 !important }
		 .bgcolor_2 { xbackground-color:white !important }
		 .bgcolor_3 { background-color:#dff0d8; color:#3c763d !important }
		
		</style>
</head>

<body>
    <!--[if lt IE 8]>
		<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
	<![endif]-->
    <!-- Start Left menu area -->
    
    
    
    <?php include("left-menu.php"); ?>
    
    
    
    <!-- End Left menu area -->
    <!-- Start Welcome area -->
    <div class="all-content-wrapper">
        
        
       <?php include("header-menu.php"); ?> 
        
        
        <!-- Static Table Start -->
        <div class="static-table-area">
        
        <div class="analytics-sparkle-area" style="margin-bottom:30px;">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
                        <div class="analytics-sparkle-line reso-mg-b-30">
                            <div class="analytics-content">
                                <h5>ALL LEADS</h5>
                                <h2><?php echo $all_leads['total_leads'];?></h2>
                               
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
                        <div class="analytics-sparkle-line reso-mg-b-30">
                            <div class="analytics-content">
                                <h5>FRESH LEADS</h5>
                                <h2><?php echo $fresh_leads['fresh_leads'];?></h2>
                               
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
                        <div class="analytics-sparkle-line reso-mg-b-30">
                            <div class="analytics-content">
                                <h5>IN-PROGRESS LEADS</h5>
                                <h2><?php echo $progress_leads['progress_leads'];?></h2>
                               
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">
                        <div class="analytics-sparkle-line reso-mg-b-30">
                            <div class="analytics-content">
                                <h5>TODAY'S CALLS</h5>
                                <h2><?php echo $today_leads['today_leads'];?></h2>
                               
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        
        
            <div class="container-fluid">
                <div class="row">
                    
                    <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12">
                        <div class="sparkline9-list mt-b-30 res-mg-t-30 analysis-progrebar-ctn">
                            <div class="sparkline9-hd">
                                <div class="main-sparkline9-hd">
                                    <h1>TO BE CALLED LEADS</h1>
                                </div>
                            </div>
                            
                            
                            <div class="sparkline13-graph">
                                <div class="datatable-dashv1-list custom-datatable-overright">
                                    <div id="toolbar">
                                        <select class="form-control dt-tb" style="width:150px">
											<option value="">Export Basic</option>
											<option value="all">Export All</option>
											<option value="selected">Export Selected</option>
										</select>
                                        
                                        <div class="col-sm-12" style="width:195px; padding-left:0; padding-top:05px">
                                        <div class="bgcolor_1" style="height:10px; width:10px; background-color:#3c763d; float:left; margin-top:12px; margin-right:10px"></div>
                                        <span>For High Priority Leads</span>
                                        </div>
                                        
                                        <div class="col-sm-12" style="width:210px; padding-top:05px">
                                        <div class="bgcolor_1" style="height:10px; width:10px; background-color:#a94442; float:left; margin-top:12px; margin-right:10px"></div>
                                        <span>For Low Priority Leads</span>
                                        </div>
                                    </div>
                                    
                                    
 										

                                    <table id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="true" data-key-events="true" data-show-toggle="true" data-resizable="true" data-cookie="true"
                                        data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar" class="textcenter">
                                        <thead>
                                        
                                            <tr align="center">
                                                <!--<th data-field="state" data-checkbox="false"></th>-->
                                                <th  data-field="Lead ID" data-editable="false">Lead ID</th>
                                                <th data-field="Lead Name" data-editable="false"> Lead Name</th>
                                                <th data-field="Phone No" data-editable="false">Phone No</th>
                                                <th data-field="email" data-editable="false">Email</th>
                                                <!--<th data-field="No Of Enquiry" data-editable="false">No Of Enquiry</th>-->
                                                <th data-field="Course Name" data-editable="false">Service Name</th>
                                                
                                                <th data-field="Priority" data-editable="false">Priority</th>
                                                <th data-field="Centre" data-editable="false"><div align="center">Activity</div></th> 
                                                <th style="text-align:center" data-field="action"><div align="center">Action</div></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <?php
										//$leads_table_sql="select SLN,Lead_ID,Lead_Name,Phone,Email,No_of_Enquiry,Course_Name,Center,Priority from lead_master where Active='Yes'";
										$leads_table_sql="select lm.*,cm.* from lead_master lm inner join communication_master cm on lm.Lead_ID=cm.Lead_ID where lm.Active='Yes' and lm.Status='Call Later' and cm.Next_Callback_Date>='".date('Y-m-d')."'";
										if($user['type']!='Super Admin')
										{
										$leads_table_sql.=" and lm.Lead_Referred_To='".$_SESSION['user']."'";
										}
										$leads_table_sql.=" order by lm.Lead_ID ASC";
										//echo $leads_table_sql;
										$leads_table_query=mysqli_query($con,$leads_table_sql);
										$i=1;
										while($leads_datas=mysqli_fetch_array($leads_table_query))
										{
																				
										?>
                                        
                                            <tr class="
                                           <?php  if ($leads_datas['Priority']<=2){ echo 'bgcolor_1' ;}
										 else if ($leads_datas['Priority']<=3){echo 'bgcolor_2';}
										 else if($leads_datas['Priority']>3){echo 'bgcolor_3';} ; ?> 
                                            
                                            " style="background-color:xxred !important<?php /* if ($leads_datas['Priority']<=2){echo 'red';}
												else if ($leads_datas['Priority']<=3){echo 'Yellow';}
												else if($leads_datas['Priority']>3){echo 'Green';} */ ?>">
                                                <!--<td></td>-->
                                                <td ><?php echo $leads_datas['Lead_ID']; ?></td>
                                                <td><?php echo $leads_datas['Lead_Name']; ?></td>
                                                <td><?php echo $leads_datas['Phone']; ?></td>
                                                <td><?php echo $leads_datas['Email']; ?></td>
                                                <!--<td class="datatable-ct"><span class="pie">1/6</span>
                                                </td>-->
                                                <!--<td><?php echo $leads_datas['No_of_Enquiry']; ?></td>-->
                                              
                                                
                                                <td><?php echo $leads_datas['Course_Name']; ?></td>
                                                <td><?php if ($leads_datas['Priority']<=2){echo 'Low';}
												else if ($leads_datas['Priority']<=3){echo 'Moderate';}
												else if($leads_datas['Priority']>3){echo 'High';} ?></td>
                                                
                                                  
                                                
                                              <td>
                                              <div class="action_icon" style="display:inline-block;  ">
                                                    <a  data-toggle="tooltip" title="Lead Activity" class="various" data-fancybox-type="iframe" href="lead_activity.php?Lid=<?php echo base64_encode($leads_datas['Lead_ID']); ?>">
                                                    <img src="img/index.png" width=""  > 
                                                     <div class="activity_txt"><?php echo $leads_datas['No_of_Enquiry']; ?></div></a>
                                                </div>
                                                
                                                <?php
												$communication_query="select count(SLN) as com_act from communication_master where Lead_ID='".$leads_datas['Lead_ID']."'";
												$communication_sql=mysqli_query($con,$communication_query);
												$communication=mysqli_fetch_array($communication_sql);
												?>
                                                <div class="action_icon" style="display:inline-block; margin-left:8px">
                                                    <a  data-toggle="tooltip" title="Communication Activity" class="various" data-fancybox-type="iframe" href="communication_activity.php?Lid=<?php echo base64_encode($leads_datas['Lead_ID']); ?>"><img src="img/index1.png"> 
                                                     <div class="activity_txt_1"><?php echo $communication['com_act']; ?></div></a>
                                                </div>
                                              
                                              </td>
                                                
                                                
                                                <td class="datatable-ct" >
                                                
                                                  
                                                <div class="dropdown action_icon" style="display:inline-block; margin-left:8px">
                                                    <a data-toggle="dropdown" role="button" aria-expanded="false" class="nav-link dropdown-toggle"> <i class="fa fa-phone"  style="font-size:18px; color:#333" aria-hidden="true" title="Call" data-toggle="tooltip"></i></a>
                                                    <div role="menu" class="dropdown-menu animated action_dropdown"  >
                                                        
                                                        <div class="btn-group btn-custom-groups btn-custom-groups-one">
                                                        
                                   <div class="btn-group btn-custom-groups btn-custom-groups-one btn-mg-b-10">
                       <?php
					    $call_status_sql="select Status_Name from status_master where Communication_Medium ='Call' and Show_Screen ='First' and Active='Yes'";
						$call_status_query=mysqli_query($con,$call_status_sql);
						while($call_status=mysqli_fetch_array($call_status_query))
						{
					   ?>           
                                    <button type="button" class="btn btn-primary" onClick="update_callconnect('<?php echo $call_status['Status_Name']; ?>','<?php echo $leads_datas['Lead_ID']; ?>')"><!--<i class="fa fa-check edu-home-admin" aria-hidden="true" >--></i> <?php echo $call_status['Status_Name']; ?></button> 
                                    <?php
									}
									?>
                                    <!--<button type="button" class="btn btn-primary" onClick="update_callconnect('Phone Busy','<?php echo $leads_datas['Lead_ID']; ?>')"><i class="fa fa-info-circle edu-informatio" aria-hidden="true"></i> Busy</button>
                                    <button type="button" class="btn btn-primary" onClick="update_callconnect('Not Reachable/Switched Off','<?php echo $leads_datas['Lead_ID']; ?>')"><i class="fa fa-exclamation-triangle edu-checked-pro" aria-hidden="true"></i> Not Reachable</button>
                                    <button type="button" class="btn btn-primary" onClick="update_callconnect('Not Answered','<?php echo $leads_datas['Lead_ID']; ?>')"><i class="fa fa-times edu-warning-danger" aria-hidden="true"></i> Not Answered</button>-->
                                    
                                </div>
                                     
                                     
                                </div>
                                                    </div>
                                                </div>
                                                
                                                
                                                
                                                <a href="" style="margin-left:8px"  data-toggle="tooltip" title="" >
                                                <i class="fa fa-envelope "  style="font-size:18px; color:#333" aria-hidden="true" title="Email" data-toggle="tooltip"></i>
                                                </a>
                                                
                                                
                                                
                                               <!-- <a href="" style="margin-left:8px"  data-toggle="tooltip" title="" >
                                                <i class="fa fa-whatsapp"  style="font-size:19px; color:#333" aria-hidden="true" title="Whatsapp" data-toggle="tooltip"></i>
                                                </a>-->
                                                
                                                
                                                
                                                
                                                <a href="" style="margin-left:8px"  data-toggle="tooltip" title=""  >
                                                <i class="fa fa-comments"  style="font-size:20px; color:#333" aria-hidden="true" title="SMS" data-toggle="tooltip"></i>
                                                </a>
                                                
                                                          <a  data-toggle="tooltip" title="View Communication History" class="various" data-fancybox-type="iframe" href="communication_activity.php?Lid=<?php echo base64_encode($leads_datas['Lead_ID']); ?>">    
                                       <i class="fa fa-file-text" style="font-size:18px; margin-left:8px" title="View Communication History" data-toggle="tooltip"></i></a>
                                        <?php if($user['type']=='Super Admin')
		{
		
		?>
                                        <a href="" style="margin-left:8px"  data-toggle="tooltip" title="">
                                                <i class="fa fa-trash-o"  style="font-size:20px; color:#B1272B" aria-hidden="true" title="Delete" data-toggle="tooltip" onClick="delete_lead('<?php echo $leads_datas['Lead_ID']; ?>');"></i>
                                                </a>
                                              <?php
											  }?>  
                                                </td>
                                            </tr>
                                          <?php
										  $i++;
										  }
										  ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                
            </div>
        </div>
        <!-- Static Table End -->
        <div class="footer-copyright-area">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="footer-copy-right">
                            <p>Copyright © 2019. All rights reserved.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- jquery
		============================================ -->
    <script src="js/vendor/jquery-1.12.4.min.js"></script>
    <!-- bootstrap JS
		============================================ -->
    <script src="js/bootstrap.min.js"></script>
    <!-- wow JS
		============================================ -->
    <script src="js/wow.min.js"></script>
    <!-- price-slider JS
		============================================ -->
    <script src="js/jquery-price-slider.js"></script>
    <!-- meanmenu JS
		============================================ -->
    <script src="js/jquery.meanmenu.js"></script>
    <!-- owl.carousel JS
		============================================ -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- sticky JS
		============================================ -->
    <script src="js/jquery.sticky.js"></script>
    <!-- scrollUp JS
		============================================ -->
    <script src="js/jquery.scrollUp.min.js"></script>
    
    
    <!-- data table JS
		============================================ -->
    <script src="js/data-table/bootstrap-table.js"></script>
    <script src="js/data-table/tableExport.js"></script>
    <script src="js/data-table/data-table-active.js"></script>
    <script src="js/data-table/bootstrap-table-editable.js"></script>
    <script src="js/data-table/bootstrap-editable.js"></script>
    <script src="js/data-table/bootstrap-table-resizable.js"></script>
    <script src="js/data-table/colResizable-1.5.source.js"></script>
    <script src="js/data-table/bootstrap-table-export.js"></script>
    
    
    
    <!-- mCustomScrollbar JS
		============================================ -->
    <script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/scrollbar/mCustomScrollbar-active.js"></script>
    <!-- metisMenu JS
		============================================ -->
    <script src="js/metisMenu/metisMenu.min.js"></script>
    <script src="js/metisMenu/metisMenu-active.js"></script>
    <!-- peity JS
		============================================ -->
    <script src="js/peity/jquery.peity.min.js"></script>
    <script src="js/peity/peity-active.js"></script>
    <!-- sparkline JS
		============================================ -->
    <script src="js/sparkline/jquery.sparkline.min.js"></script>
    <script src="js/sparkline/sparkline-active.js"></script>
    <!-- tab JS
		============================================ -->
    <script src="js/tab.js"></script>
    <!-- plugins JS
		============================================ -->
    <script src="js/plugins.js"></script>
    <!-- main JS
		============================================ -->
    <script src="js/main.js"></script>
    <!-- tawk chat JS
		============================================ -->
        
         <script>
$(document).ready(function() {
   $("body").tooltip({ 
   	selector: '[data-toggle=tooltip]' 
	 });
});
 
</script>
<!------------------------Fancybox---------------------------------->
 
 <script type="text/javascript" src="lib/jquery.mousewheel.pack.js"></script>

<script type="text/javascript" src="source/jquery.fancybox.pack.js?v=2.1.5"></script>
	<link rel="stylesheet" type="text/css" href="source/jquery.fancybox.css" media="screen" />

<style type="text/css">
	.fancybox-custom .fancybox-skin {
		box-shadow: 0 0 50px #222;
	}
</style> 
<script>
$(document).ready(function() {
	$(".various").fancybox({
		maxWidth	: 380,
		maxHeight	: 410,
		fitToView	: true,
		width		: '100%',
		height		: '100%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
		
		
		
		
	});
	
 
});

</script>
<!--    <script src="js/tawk-chat.js"></script>-->
</body>

</html>