<?php
include("common/connection.php");
login_check();

$Lead_Req_Id=$_REQUEST['Lid'];
$user_type_sql="select User_Type from user_master where User_Name='".$_SESSION['user']."'";
$user_type_query=mysqli_query($con,$user_type_sql);
$user_type=mysqli_fetch_array($user_type_query);
?>

<!doctype html>
<html class="no-js" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Current Leads | Buurtzorg</title>
    <?php include("headerlink.php"); ?> 
     <link rel="stylesheet" href="css/form/all-type-forms.css">
    <!-- x-editor CSS
		============================================ -->
    <link rel="stylesheet" href="css/editor/select2.css">
    <link rel="stylesheet" href="css/editor/datetimepicker.css">
    <link rel="stylesheet" href="css/editor/bootstrap-editable.css">
    <link rel="stylesheet" href="css/editor/x-editor-style.css">

    
    <script>
	function unlock_form() {
	 
	$('#edit_c_form  input'). prop("disabled", false);
	//$('#not_editable  input'). prop("disabled", true);
	$('#edit_c_form  textarea'). prop("disabled", false);
	$('#edit_c_form  select'). prop("disabled", false);
	$('#update_btn').show();
	$('#edit_btn_1').hide();
	
 
	}
	</script>
    
    <script>
	function call_status(per) {
	 
	// alert(per);
	if(per=='Call Later') {
	$('#call_later').show();
	$('#call_later_time').show();
	
	} 	
	else{
	
	  $('#call_later').hide();
	  $('#call_later_time').hide();
	}
 
	}
	
 
	</script> 
    <?php
	 $lead_basic_sql="select * from lead_master where Lead_ID='".$Lead_Req_Id."'";
	 $lead_basic_query=mysqli_query($con,$lead_basic_sql);
	 $lead_details=mysqli_fetch_array($lead_basic_query);
	?>    
</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="container-fluid">
                <div class="row">
                    
                    <div class="col-lg-8 col-md-6 col-sm-6 col-xs-12" >
                        <div class="sparkline9-list mt-b-30 res-mg-t-30 analysis-progrebar-ctn" style="background-color:#FFFFFF">
                            <div class="sparkline9-hd">
                                <div class="main-sparkline9-hd">
                                    <h1 style="margin-bottom:15px">LEAD DETAILS</h1>
                                   
                                    
                                    
                                          <div class="row" style="padding:0; background-color:#FFFFFF">
                                           <form action="" class="dropzone dropzone-custom needsclick add-professors dz-clickable" id="edit_c_form">
                                                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                    <div class=" "><label for="">Name &nbsp; :</label> 
                                                        <input disabled class="lebel_input" placeholder="Mobile No" value="<?php echo $lead_details['Lead_Name']; ?>" type="text" name="lead_name">
                                                    </div>
                                                     
                                                    
                                                    <div class=" ">
                                                    	<label for="">Mob No. &nbsp; :</label>
                                                        <input disabled class="lebel_input" placeholder="Mobile No" value="<?php echo $lead_details['Phone']; ?>" type="text" name="lead_mob">
                                                    </div>
                                                    <div class=" ">
                                                        <label for="">Course Name  &nbsp; :</label>
                                                            <select disabled class="lebel_input" name="lead_course">
                                                            	<option><?php echo $lead_details['Course_Name']; ?></option>
                                                                <option>Option 2</option>
                                                            </select>
                                                                
                                                    </div>
                                                    
                                                    
                                                    
                                                    <div class=" ">
                                                    	<label for="">Zone  &nbsp; :</label>
                                                        <input disabled class="lebel_input" placeholder="Zone" value="<?php echo $lead_details['Zone']; ?>" type="text" name="lead_zone">
                                                    </div>
                                                     
                                                </div>
                                                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                                                    <div class=" ">
                                                    	<label for="">Email &nbsp; :</label>
                                                        <input disabled class="lebel_input" placeholder="Email Id" value="<?php echo $lead_details['Email']; ?>" type="email" name="lead_email" style="width:235px">
                                                    </div>
                                                    
                                                    <div class=" ">
                                                    	<label for="">City &nbsp; :</label>
                                                        <input disabled class="lebel_input" placeholder="City Name" value="<?php echo $lead_details['City']; ?>" type="text" name="lead_city">
                                                    </div>
                                                    
                                                    <div class=" ">
                                                    	<label for="">Center &nbsp; :</label>
                                                        <input disabled class="lebel_input" placeholder="Center Name" value="<?php echo $lead_details['Center']; ?>" type="text" name="lead_center">
                                                    </div>
                                                    
                                                    
                                                    
                                                    <div class=" ">
                                                        <label for="">Refer To  &nbsp; :</label>
                                                            <select disabled class="lebel_input" name="lead_counselor">
                                                            <?php
															$user_refer_sql="select User_Name,User_Type from user_master where Active='Yes'";
															$user_refer_query=mysqli_query($con,$user_refer_sql);
															while($user_refer=mysqli_fetch_array($user_refer_query))
															{
															?>
                                                                <option  value="<?php echo $$user_refer['User_Name']; ?>"<?php if($user_refer['User_Name']==$lead_details['Lead_Referred_To']){ echo 'selected';}?>><?php echo $user_refer['User_Name']; ?></option>
                                                             <?php
															 }
															 ?>
                                                            </select>
                                                                
                                                    </div>
                                                    
                                                     
                                                </div>
                                                
                                                 
                                                 <div align="left" class="col-lg-12">
                                                    <div align="left" class="col-lg-6" style="text-align:left; padding-left:0; padding-top:20px">
                                                    <?php if($user_type['User_Type']=='Super Admin')
													{
													?>                                                
                                                        <button type="submit" class="btn btn-primary waves-effect waves-light" 
                                                        style="width:100px; display:none" onClick="" id="update_btn">Update</button>
                                                        <?php
													}
													?>
                                                    </div>
                                                    
                                                    
                                                   
                                                </div>
                                                    </form>
                                              
                                
                                  <form method="post" action="">
                                      <!--<input id="hidden_call_box" name="call_status" value="" style="width:100%" type="hidden">-->
                                      
                                      <div class="col-sm-12" id="call_later_div" style="padding-top:25px; max-width:300px">
                                      <div class="form-group"><label>SELECT CALL STATUS</label>
                                            <select name="lead_call_status" id="lead_call_status" class="form-control" style=" width:100%;" onChange="call_status(this.value)">
                                            
                                            <option value="">Select Status</option>
                                            <?php
                                           $call_status_sql="select Status_Name from status_master where Communication_Medium ='Call' and Show_Screen ='Second' and Active='Yes'";
                                           $call_status_query=mysqli_query($con,$call_status_sql);
                                           while($call_status=mysqli_fetch_array($call_status_query))
                                            {
                                           
                                            ?>
                                            <option value="<?php echo $call_status['Status_Name']; ?>"><?php echo $call_status['Status_Name'];?></option>
                                            <?php
                                            }
                                            ?>
                                            
                                            
                                            </select>
                                                   </div>
                                                </div>
                                      
                                      <div class="col-sm-12" id="call_later_div" style="padding-top:25px; max-width:300px">
                                      <div class="form-group"><label>&nbsp;</label>
                                           <input name="dummy" id="" type="text" class="form-control" 
                                                      placeholder="Call Back Date" style="opacity:0;">
                                                   </div>
                                                </div>
                                                
                                                <div class="col-sm-12" id="call_later" style="padding-top:25px; display:none; max-width:300px">
                                                   <div class="form-group"><label>Set Call Back Date</label>
                                                      <input name="call_new_date" id="finish" type="text" class="form-control" 
                                                      placeholder="Call Back Date">
                                                   </div>
                                                </div>
                                                
                                                 <div class="col-sm-12" id="call_later_time" style="padding-top:25px; display:none; max-width:300px">
                                                   <div class="form-group"><label>Set Call Back Time</label>
                                                      <input name="call_new_time" id="single-input" type="text" class="form-control" 
                                                      placeholder="Call Back Time">
                                                   </div>
                                                </div>
                                                
                                                
                                                
                                                <div class="col-sm-12" id=" " style="padding-top:05px; ">
                                                   <div class="form-group">
                                                        <label for="">Response</label>                                                     
                                                        <textarea name="call_response" style="resize:none; height:70px" id="response"> </textarea>
                                                   </div>
                                                </div>
                                               
                                                
                                                
                                                <div class="col-sm-4">
                                                 <input type="submit" class="btn btn-custon-rounded-three
                                    				btn-primary" name="update_status" value="Update">
                                    			
                                                </div>
                                              
                                        </form>
                                          <?php
								  if(isset($_REQUEST['update_status']))
								  {
								  //------- fetch sln from communication master-------//
								  $desc_cmnctn_sln_sql="select SLN from communication_master where Lead_ID='".$Lead_Req_Id."' and Status='Call Connected' and Communicator_ID='".$_SESSION['user']."' order by SLN DESC limit 1";
								  $desc_cmnctn_sln_query=mysqli_query($con,$desc_cmnctn_sln_sql);
								  $desc_sln=mysqli_fetch_array($desc_cmnctn_sln_query);
								  
								   //------- update call status from communication master-------//
								 $update_cmnctn_sql="update communication_master set Status='".$_REQUEST['lead_call_status']."', Date_Of_Communication='".date('Y-m-d H:i:s')."', Response='".mysqli_real_escape_string($con,$_REQUEST['call_response'])."'";
								  if($_REQUEST['call_new_date']!='')
								  {
								  	$update_cmnctn_sql.=", Next_Callback_Date='".date('Y-m-d',strtotime($_REQUEST['call_new_date']))."', Next_Callback_Time='".$_REQUEST['call_new_time']."'";
								  }
								  $update_cmnctn_sql.=" where SLN='".$desc_sln['SLN']."'";	
								  
								  // echo	 $update_cmnctn_sql;						  
								  $update_cmnctn_query=mysqli_query($con,$update_cmnctn_sql);
								  
								  //------- fetch sln from calllog master-------//
								  $desc_calllog_sln_sql="select SLN from call_log_master where Lead_ID='".$Lead_Req_Id."' and Status='Call Connected' and Caller_ID='".$_SESSION['user']."' order by SLN DESC limit 1";
								  $desc_calllog_sln_query=mysqli_query($con,$desc_calllog_sln_sql);
								  $desc_calllog_sln=mysqli_fetch_array($desc_calllog_sln_query);
								  
								   //------- update status calllog master-------//
								  $update_call_log_sql="update call_log_master set Datetime_of_Response='".date('Y-m-d H:i:s')."',Status='".$_REQUEST['lead_call_status']."', Comments='".mysqli_real_escape_string($con,$_REQUEST['call_response'])."'";
								  if($_REQUEST['call_new_date']!='')
								  {
								  	$update_call_log_sql.=", Next_Contact_Date='".date('Y-m-d',strtotime($_REQUEST['call_new_date']))."'";
								  }
								  $update_call_log_sql.=" where SLN='".$desc_calllog_sln['SLN']."'";
								  
								  $update_call_log_query=mysqli_query($con,$update_call_log_sql);
								  
								   //------- update status lead master-------//
								  $update_lead_sql="update lead_master set Status='".$_REQUEST['lead_call_status']."',Remarks='".mysqli_real_escape_string($con,$_REQUEST['call_response'])."' where Lead_ID='".$Lead_Req_Id."'";
								  $update_lead_query=mysqli_query($con,$update_lead_sql);
									  
									  ?>
                                      <script>
									  alert('Status Updated Successfully');
									  window.location.href='current_leads.php';
									  </script>
									  <?php
								
								  }
								  ?>
                                        
                                        
                                        
                                        
                                        
                                            </div>
                                        
                                          
                                         
                                         
                                         
                                         
                                           
                                </div>
                            </div>
                             
                         </div>
                         
                    </div> 
                    
                    
                     <div class="col-lg-4 col-xs-12" >
                     <div class="sparkline9-list mt-b-30 res-mg-t-30 analysis-progrebar-ctn" style="background-color:#FFFFFF;padding-left: 0; padding-right:0; padding-bottom:0">
                            <div class="sparkline9-hd">
                                <div class="main-sparkline9-hd" style="padding-left:20px">
                                    <h1>COMMUNICATION HISTORY</h1>
                                 </div>  
                                     
                                     
                                <div class="main-sparkline9-hd" style="height:450px; overflow-y:auto; margin-top:25px;padding-right:10px; background-color:#e7eff9; padding-left:10px">     
                              	 
                                 <?php
								 $communicated_sql="select * from communication_master where Lead_ID='".$Lead_Req_Id."' order by Date_Of_Communication desc";
								 $communicated_query=mysqli_query($con,$communicated_sql);
								 while($communicate=mysqli_fetch_array($communicated_query))
								 {
								 if($communicate['Communication_Type']=='Call')
								 {
								  $icon="fa fa-phone";
								  $title='CALL';
								 }
								 else if($communicate['Communication_Type']=='Email')
								 {
								  $icon="fa fa-envelope icon_fix_1";
								  $title='EMAIL';
								 }
								 else if($communicate['Communication_Type']=='Whatsapp')
								 {
								  $icon="fa fa-whatsapp";
								  $title='WHATSAPP';
								 }
								  else if($communicate['Communication_Type']=='Sms')
								 {
								  $icon="fa fa-comments";
								  $title='SMS';
								 }
								 ?>
                                 <div class="single-review-st-text">      
                               		 <div class="social-media-in side_icon" style="padding-top:10px; margin-right:15px">
                                    <a href="#"  style="height:32px; width:32px">
                                    <i class="<?php echo $icon; ?>" style="font-size:20px; line-height:32px" title="<?php echo $title; ?>" data-toggle="tooltip"></i></a> 
                                 </div>
                                
                                
                               		 <div class="review-ctn-hf"  style="margin-left:0; background-color:#FFFFFF;
                                border-radius:18px; padding:15px">
                                    <P>
                                    <i class="fa fa-clock-o" aria-hidden="true" style="font-size:16px; margin-right:2px"></i>
                                    <span style="color:rgba(0,0,0,0.65)"><?php echo date('M d,Y h:i a',strtotime($communicate['Date_Of_Communication'])); ?></span></p>
                                    
                                    
                                    <P><strong>Status : </strong><?php echo $communicate['Status']; ?></p>
                                    <?php if($communicate['Status']=='Call Later')
										{
										?>
										<P><strong>Next Callback Date : </strong><?php echo date('M d,Y',strtotime($communicate['Next_Callback_Date'])); ?></p>
                                        <P><strong>Next Callback Time : </strong><?php echo $communicate['Next_Callback_Time']; ?></p>
										<?php
										}
									
									if($communicate['Communication_Type']=='Call')
									{
										$sub_msg='Response';
										if($communicate['Response']=='')
											{ $msg="No Response";}
										else
										{ $msg=$communicate['Response'];}									
									}
									else
									{
										$sub_msg='Content';
										if($communicate['Content']=='')
										{ $msg="No Content";}
										else
										{ $msg=$communicate['Content'];}
									} 
									?>
                                    <div align="justify" class="heide_1" ><strong><?php echo $sub_msg; ?>  : </strong><span  style="color:rgba(0,0,0,.6)">
                                    <?php echo $msg; ?></span></div>
                                                                                                                                               
                                </div>
                                                               
                                 </div>
                                 <?php
								 }
								 ?>
                                 
                                
                                 
                          
                                 
                                 
                            	</div>
                                
                                
                                
                            </div>
                             
                         </div>
                     
                     
                     
                     
                     
                     </div>
                    
                    
                      
                    	
                              <div class="sparkline9-hd" style="padding-bottom: 0px;">
                              
                              
                                <div class="review-content-section">
                                    <div id="" class="pro-ad addcoursepro">
                                        
                                          
                                            
                                            
                                           
                                        
                                    </div>
                                </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>
    
    <script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/scrollbar/mCustomScrollbar-active.js"></script>

     
    
     <!--  editable JS
		============================================ -->
    <script src="js/editable/jquery.mockjax.js"></script>
    <script src="js/editable/mock-active.js"></script>
    <script src="js/editable/select2.js"></script>
    <script src="js/editable/moment.min.js"></script>
    <script src="js/editable/bootstrap-datetimepicker.js"></script>
    <script src="js/editable/bootstrap-editable.js"></script>
    <script src="js/editable/xediable-active.js"></script>
 <!-- datepicker JS
		============================================ -->
    <script src="js/datepicker/jquery-ui.min.js"></script>
    <script src="js/datepicker/datepicker-active.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 src="js/tawk-chat.js"></script>
   <!-- form validate JS
		============================================ -->
    <script src="js/form-validation/jquery.form.min.js"></script>
    <script src="js/form-validation/jquery.validate.min.js"></script>
    <script src="js/form-validation/form-active.js"></script>
    
    <script>
$(document).ready(function() {
   $("body").tooltip({ 
   	selector: '[data-toggle=tooltip]' 
	 });
});
 
</script> 
  
               
                                               <script>
 
$('button.call_btn_1').click(function() {
    //var text = $(this).text();
	var text = $(this).data('value_santanu');
	//alert(text)
	$('#hidden_call_box').val(text);
	$('#response').val(text);
    // do something with the text
});
												</script> 
                                                
                                                
                                                
                                                
       <!-- bootstrap-clockpicker -->
      <link rel="stylesheet" type="text/css" href="css/bootstrap-clockpicker.min.css">
    <script type="text/javascript" src="js/bootstrap-clockpicker.min.js"></script>


 <script type="text/javascript">
$('.clockpicker').clockpicker()
	.find('input').change(function(){
		console.log(this.value);
	});
var input = $('#single-input').clockpicker({
	placement: 'bottom',
	align: 'left',
	autoclose: true,
	'default': 'now'
});

$('.clockpicker-with-callbacks').clockpicker({
		donetext: 'Done',
		init: function() { 
			console.log("colorpicker initiated");

		},
		beforeShow: function() {
			console.log("before show");
		},
		afterShow: function() {
			console.log("after show");
		},
		beforeHide: function() {
			console.log("before hide");
		},
		afterHide: function() {
			console.log("after hide");
		},
		beforeHourSelect: function() {
			console.log("before hour selected");
		},
		afterHourSelect: function() {
			console.log("after hour selected");
		},
		beforeDone: function() {
			console.log("before done");
		},
		afterDone: function() {
			console.log("after done");
		}
	})
	.find('input').change(function(){
		console.log(this.value);
	});

// Manually toggle to the minutes view
$('#check-minutes').click(function(e){
	// Have to stop propagation here
	e.stopPropagation();
	input.clockpicker('show')
			.clockpicker('toggleView', 'minutes');
});
if (/mobile/i.test(navigator.userAgent)) {
	$('input').prop('readOnly', true);
}
</script>                                          
                                                
                                                
                                                
                                                
    
</body>

</html>