<?php
defined('BASEPATH') OR exit('No direct script access allowed');?>
<!DOCTYPE html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- bootstrap-css -->
<link rel="stylesheet" href="<?php echo base_url();?>/assets/css/bootstrap.min.css" />
<!-- //bootstrap-css -->
<!-- Custom CSS -->
<link href="<?php echo base_url();?>/assets/css/style.css" rel='stylesheet' type='text/css' />
<link href="<?php echo base_url();?>/assets/css/style-responsive.css" rel="stylesheet"/>
<!-- font CSS -->
<link href='//fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<!-- font-awesome icons -->
<link rel="stylesheet" href="<?php echo base_url;?>/assets/css/font.css" type="text/css"/>
<link href="<?php echo base_url();?>/assets/css/font-awesome.css" rel="stylesheet"/> 
<link href="<?php echo base_url();?>/assets/css/datetimepicker.min.css" rel="stylesheet"/>
<!-- //font-awesome icons -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<section id="container">
<!--header start-->
<header class="header fixed-top clearfix">
<!--logo start-->
<div class="brand">
    <a href="<?php echo base_url();?>home/dashboard" class="logo">
        <img src="" style="  display: block;  margin-left: auto;  margin-right: auto;  width: 80%;margin-top: -22px;"/>
    </a>
    <div class="sidebar-toggle-box">
        <div class="fa fa-bars"></div>
    </div>
</div>
<!--logo end-->
<?php include_once 'common/notification_bar.php';?>
<?php include_once 'common/aside.php';?>

<section id="main-content">
	<section class="wrapper">
		<div class="table-agile-info">
  <div class="panel panel-default">
  <div id="studentInfo" style="border:0px solid;z-index:999999"></div>
    <div class="panel-heading">
 My Team<span style="float:right">Total : <?php echo $counts;?></span>
    </div>
    <div class="row">
	<form method="post" action="<?php echo base_url();?>home/my_team">
      <div class="col-sm-12 m-b-xs">
	  <input type="text" name="name" style="margin:5px;" placeholder="By Name" class="col-sm-4 input-sm form-control w-sm inline v-middle" value="<?php if($filter_data['name']!=''){echo $filter_data['name'];}?>"/>
	  <!--<input type="email" name="email" style="margin:5px;" placeholder="By Email" class="col-sm-4 input-sm form-control w-sm inline v-middle" value="<?php if($filter_data['email']!=''){echo $filter_data['email'];}?>"/>-->
	  <input type="text" name="phone" maxlength="10" pattern="[0-9]+" onkeypress="return numbersonly(this, event)" style="margin:5px;" placeholder="By Phone" class="col-sm-4 input-sm form-control w-sm inline v-middle" value="<?php if($filter_data['phone']!=''){echo $filter_data['phone'];}?>"/>
	  <!--<input type="text" name="added_on" style="margin:5px;" placeholder="by created date" class="col-sm-4 input-sm form-control datepicker1 w-sm inline v-middle" value="<?php if($filter_data['added_on']!=''){echo $filter_data['added_on'];}?>"/>-->
	  <input type="text" name="followup_date" style="margin:5px;" placeholder="By Follow Up" class="col-sm-4 input-sm form-control datepicker1 w-sm inline v-middle" value="<?php if($filter_data['followup_date']!=''){echo $filter_data['followup_date'];}?>"/>
        <select class="col-sm-4 input-sm form-control w-sm inline v-middle" name="city" style="margin:5px;">
         <option value="">Select City</option>
		<?php foreach(getCity() as $get){?>
		<option <?php if($filter_data['city']==$get->id){echo "selected";}?> value="<?php echo $get->id;?>"><?php echo $get->city_name;?></option>
		<?php } ?>
		</select>
		<select name="lead_status" class="col-sm-4 input-sm form-control w-sm inline v-middle" style="margin:5px;">
         <option  value="">Select Lead Status</option>
											<?php foreach(getStatus() as $get){?>
											<option <?php if($filter_data['lead_status']==$get->id){echo "selected";}?> value="<?php echo $get->id;?>"><?php echo $get->status;?></option>
											<?php } ?>
											</select>
		<?php if(($user_data[0]['user_type']!=3)){?>
		<select name="source_id" class="col-sm-4 input-sm form-control w-sm inline v-middle" style="margin:5px;">
          <option value="">Select Source</option>
											<?php foreach(getSource() as $get){?>
											<option <?php if($filter_data['source_id']==$get->id){echo "selected";}?> value="<?php echo $get->id;?>"><?php echo $get->source;?></option>
											<?php } ?>
											</select>
		<?php } ?>
		
		<select name="caller_id" class="col-sm-4 input-sm form-control w-sm inline v-middle" style="margin:5px;">
         <option value="">Select Caller</option>
											<?php $userid=$this->session->userdata('user_login');
											if($user_data[0]['user_type']==2){$caller=getCallerLists($userid[0]['id']);}
											foreach($caller as $get){?>
											<option <?php if($filter_data['caller_id']==$get->cl_id){echo "selected";}?> value="<?php echo $get->cl_id;?>"><?php echo $get->username;?></option>
											<?php } ?>
											</select>
										
     	<select name="site_visit_verify" class="col-sm-4 input-sm form-control w-sm inline v-middle" style="margin:5px;">
         <option value="">Site visit verify</option>
		<option <?php if($filter_data['site_visit_verify']=='Y'){echo "selected";}?> value="Y">Y</option>
		<option <?php if($filter_data['site_visit_verify']=='N'){echo "selected";}?> value="N">N</option>
		</select>
		
		 <input type="date" name="from_date1" style="margin:5px;" placeholder="by created date" class="col-sm-4 input-sm form-control w-sm inline v-middle" value="<?php if($filter_data['from_date1']!=''){echo $filter_data['from_date1'];}?>"/>
		 
		  <input type="date" name="to_date1" style="margin:5px;" placeholder="by created date" class="col-sm-4 input-sm form-control w-sm inline v-middle" value="<?php if($filter_data['to_date1']!=''){echo $filter_data['to_date1'];}?>"/>
		
		<div class="clearfix"></div>
        <button class="btn btn-sm btn-primary" name="submit" >Apply</button>                
        <a href="<?php echo base_url();?>home/reset" class="btn btn-sm btn-default">Reset</a>                
      </div>
      </form>
    </div>
    <div class="table-responsive"><p id="msg"></p>
	<p id="student_succ"></p>
	<?php echo $this->session->flashdata('msg'); ?> <br/>
      <table class="table table-striped b-t b-light">
        <thead>
          <tr>
            <th style="width:20px;">
              <label class="i-checks m-b-none">
                <input type="checkbox" class="assignmentAll"><i></i>
              </label>
            </th>
            <th>Name</th>
            <th>Email</th>
            <th>Phone</th>
            <th>Lead Status</th>
            <th>Date</th>
            <th style="width:7%;">Caller</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
		<?php
		foreach($leads as $get){?>
          <tr <?php if($get->lead_status==1){echo "style='background-color:#daf7df'";}?>>
            <td><label class="i-checks m-b-none"><input type="checkbox" type="checkbox" name="select_<?php echo $get->id ?>" class="assignment <?php echo $get->phone; ?>" id="select_<?php echo $get->id ?>" value="<?php echo $get->id; ?>" ><i></i></label></td>
            <td><input type="text" style="width: 200px !important;" value="<?php echo $get->name;?>" class="form-control ctrl" name="username" id="username_<?php echo $get->id;?>"/>
			<b style="font-size:10px;color:#000"><?php echo $get->source;?> | <?php $dt=$get->added_on;$dt1=explode(' ',$dt);echo $dt1[0];?></b>
			</td>
            <td><input type="email" style="width:40px !important;" value="<?php echo $get->email;?>" class="form-control ctrl" name="email" id="email_<?php echo $get->id;?>"/></td>
            <td><a href="tel:0<?php echo $get->phone;?>"><i class="fa fa-phone" style="position: absolute;margin-left: -4px;margin-top: -6px;padding:2px 4px;border:1px solid #ccc;border-radius:5px;z-index:1;"></i></a><input type="text" style="width: 120px !important;" value="<?php echo $get->phone;?>" class="form-control ctrl" name="phone" id="phone_<?php echo $get->id;?>" maxlength="10" pattern="[0-9]+" onkeypress="return numbersonly(this, event)" readonly="true"/></td>
           
            <td><select class="form-control ctrl" style="width: 120px !important;" name="status" required="" id="status_<?php echo $get->id;?>">
											<option value="">Select Status</option>
											<?php foreach(getStatus() as $gets){?>
											<option  <?php if($gets->id==$get->lead_status){echo "selected";}?> value="<?php echo $gets->id;?>"><?php echo $gets->status;?></option>
											<?php } ?>
											</select></td>
            <td>
			<div class='input-group date datetimepicker1' id='datetimepicker1'>
                    <input type='text' class="form-control ctrl" style="width: 120px !important;" value="<?php echo $get->followup_date;?>" name="follow_up" id="followup_<?php echo $get->id;?>"/>
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
				<a id="remark_<?php echo $get->id;?>" class="remark btn btn-primary" style="padding: 0px;float: right;margin-top: -20px !important;font-size:11px;cursor:pointer;">Add Remark</a>
				<textarea id="remarks_<?php echo $get->id;?>" style="display:none;width: 120px !important;" placeholder="Enter Remark"></textarea>
				</td>
		<td style="font-size:12px;"><?php echo "<i class='fa fa-dot-circle-o' style='color:green'>".substr($get->username,0,10)."</i>";?>
				<?php $fet=getCallers($get->parent_caller_id);echo "<br/><i class='fa fa-dot-circle-o' style='color:red'>".substr($fet[0]['username'],0,10)."</i>";?></td>
            <td>
              <a title="Save Now" id="updaterow_<?php echo $get->id;?>" class="active updaterow" style="cursor:pointer" ui-toggle-class=""><i class="fa fa-save text-success text-active btnh"></i></a>
			   <a  title="More Info" href="javascript:void(0)" onClick="getmoreinfo(<?php echo $get->id;?>)" class="active" style="cursor:pointer" ui-toggle-class=""><i class="fa fa-info text-success text-active btnh"></i></a>
			   <?php if($get->whatsapp_no!=0){?>
			   <a title="Send Msg to whatsapp" href="https://api.whatsapp.com/send?phone=91<?php echo $get->whatsapp_no; ?>&text=HI" target="_blank" class="active updaterow" style="cursor:pointer" ui-toggle-class=""><i class="fa fa-whatsapp text-success text-active btnh"></i></a><?php } else{?>
			   <a title="Send Msg to whatsapp" href="https://api.whatsapp.com/send?phone=91<?php echo $get->phone; ?>&text=HI" target="_blank" class="active updaterow" style="cursor:pointer" ui-toggle-class=""><i class="fa fa-whatsapp text-success text-active btnh"></i></a>
			   <?php } ?>
			   
			   <a title="Send SMS" class="active" href="javascript:void(0)" onClick="getcommunication(<?php echo $get->id;?>)" style="cursor:pointer" ui-toggle-class=""><i class="fa fa-envelope text-danger text btnh"></i></a>
			  <?php if($user_data[0]['user_type']!='3'){?><a title="Check History" class="active" href="javascript:void(0)" onClick="getBacktrack(<?php echo $get->id;?>)" style="cursor:pointer" ui-toggle-class=""><i class="fa fa-step-backward text-danger text btnh"></i></a><?php } ?>
            </td>
          </tr>
		<?php } ?>
        </tbody>
      </table>
	  

	  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
	  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>
	  <script src="<?php echo base_url();?>/assets/js/datetimepicker.min.js"></script>
	  <script type="text/javascript">
	  $("body").on("click", ".datetimepicker1", function(){
    $(this).datetimepicker({
    timezone: 'Asia/Kolkata',
    format: 'yyyy-mm-dd hh:ii:ss',
	startDate: '-0m',
    autoclose: true
    }); });
	$('.datepicker1').datepicker({
    format: 'yyyy-mm-dd',
    autoclose: true
    });
   
/*$("body").on("focus", ".datetimepicker1", function(){
	$(this).datetimepicker({
	timezone: 'Asia/Kolkata',
    format: 'yyyy-m-dd hh:ii:ss',
	startDate: '-0m',
    autoclose: true
});});*/
$(document).on("click",'.remark',function(){
	var idf=$(this).attr('id');
	var str=idf.split('_');
	$("#remarks_"+str[1]).show();
});
        </script>
    </div>
    <footer class="panel-footer">
      <div class="row">
        
        <div class="col-sm-6 text-center">
         	<?php if($user_data[0]['user_type']!=3){?>
			<p id="error_msg" class="color:red"></p>
			<label class="col-sm-3">Assign Leads</label>
		<select name="caller_id" id="caller_id" class="col-sm-4 input-sm form-control w-sm inline v-middle caller_id" style="margin:5px;">
         <option value="">Select Caller</option>
		 
		                                   <?php $userid=$this->session->userdata('user_login');
											if($user_data[0]['user_type']==2){$caller=getCallerLists($userid[0]['id']);}
											foreach($caller as $get){?>
											<option <?php if($filter_data['caller_id']==$get->id){echo "selected";}?> value="<?php echo $get->cl_id;?>"><?php echo $get->username;?></option>
											<?php } ?>
		 
											</select>
											<input class="col-sm-2 btn btn-success dropdown-toggle assign" type="submit" value="Confirm" />
											<?php } ?>  </div>
        <div class="col-sm-6 ">          
           <ul class="pagi-nation" style="float: right;">
			<li><?php echo $links; ?></li>
		</ul>
		  
        </div>
      </div>
	  
	 	
    </footer>
  </div>
</div>
</section>
<style>
.pagi-nation {
    width: 100%;
    float: left;
    margin: 0px;
    padding: 0px;
    list-style-type: none;
    text-align: center;
}
ul, li, li a {
    list-style: none;
        list-style-type: none;
    margin: 0;
    padding: 0;
}
.pagi-nation li strong {
    background-color: #086099;
    border: 1px solid;
    border-radius: 5px;
    padding: 0.1em 0.5em;
    color: #fff;
}

element {

}
.pagi-nation li a {

    background-color: #ccc;
    border: 1px solid #7A7878;
    border-radius: 5px;
    padding: 0.1em 0.5em;
    color: #000;

}
</style>

<style>
.footnav{display:none;}
@media(max-width:750px){
.footnav{display:block;}	
}
</style>

<div style="width:100%;padding:16px;background:#1a20c3;color:#fff;position:fixed;bottom:0px;border-top:3px solid #d01525" class="footnav">
<?php if($userid[0]['user_type']==1){?>
<a href="<?php echo base_url();?>home/dashboard" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-dashboard" > Dashboard</i></a>
<a href="<?php echo base_url();?>home/lead_info" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-list-alt" > Leads</i></a>
<a href="<?php echo base_url();?>home/report" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-bar-chart" > Report</i></a>
<a href="<?php echo base_url();?>home/logout" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-sign-out" > logout</i></a>
<?php } ?>
<?php if($userid[0]['user_type']==2){?>
<a href="<?php echo base_url();?>home/dashboard" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-dashboard" > Dashboard</i></a>
<a href="<?php echo base_url();?>home/lead_info" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-list-alt" > Leads</i></a>
<a href="<?php echo base_url();?>home/my_team" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-list" > My Team</i></a>
<a href="<?php echo base_url();?>home/logout" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-sign-out" > logout</i></a>
<?php } ?>
<?php if($userid[0]['user_type']==3){?>
<a href="<?php echo base_url();?>home/dashboard" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-dashboard" > Dashboard</i></a>
<a href="<?php echo base_url();?>home/lead_info" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-list-alt" > Leads</i></a>
<a href="<?php echo base_url();?>home/logout" style="color:#fff;margin:0 15px 0 15px;"><i class="fa fa-sign-out" > logout</i></a>
<?php } ?>
</div>
 <!-- footer -->
		  <div class="footer">
			<div class="wthree-copyright">
			 	<p >Develped by <a href="https://www.tenacioushub.com/" target="_blank"><img src="<?php echo base_url;?>/assets/images/logo.png" style="height:25px;"/></a></p>
			</div>
		  </div>
  <!-- / footer -->
</section>
<style>
.btnh{border: 1px solid #ccc;
padding: 5px;
border-radius: 100%;}
</style>
<!--main content end-->
</section>

<script src="<?php echo base_url();?>/assets/js/bootstrap.js"></script>
<script src="<?php echo base_url();?>/assets/js/jquery.dcjqaccordion.2.7.js"></script>
<script src="<?php echo base_url();?>/assets/js/scripts.js"></script>
<script src="<?php echo base_url();?>/assets/js/jquery.slimscroll.js"></script>
<script src="<?php echo base_url();?>/assets/js/jquery.nicescroll.js"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot-chart/excanvas.min.js"></script><![endif]-->
<script src="<?php echo base_url();?>/assets/js/jquery.scrollTo.js"></script>

<script>
$(document).on("click",".updaterow",function(){
 var rowid=$(this).attr('id');
 var str = rowid.split('_');
var username = $("#username_"+str[1]).val(); 
var email = $("#email_"+str[1]).val(); 
var phone = $("#phone_"+str[1]).val(); 
var followup = $("#followup_"+str[1]).val(); 
var status = $("#status_"+str[1]).val(); 
var remark = $("#remarks_"+str[1]).val(); 
if(phone==''){
$("#msg").addClass("alert alert-danger").text('Enter Phone No');
	$("#phone_"+str[1]).focus();	
	return false;
}
if((phone.length < 10) || (phone.length > 10)){
$("#msg").addClass("alert alert-danger").text('Phone no need to be 10 digit');
	$("#phone_"+str[1]).focus();	
	return false;
}
else{
	$("#msg").removeClass("alert alert-danger").text('');
}
if(status==1){
$("#msg").addClass("alert alert-danger").text('Change Status First');
	$("#status_"+str[1]).focus();	
	return false;
}else{
	$("#msg").removeClass("alert alert-danger").text('');
}
if(followup=='0000-00-00 00:00:00'){
$("#msg").addClass("alert alert-danger").text('Change Date First');
	$("#remarks_"+str[1]).focus();	
	return false;
}else{
	$("#msg").removeClass("alert alert-danger").text('');
}
if(remark==''){
$("#msg").addClass("alert alert-danger").text('Plz add remark');
	$("#remarks_"+str[1]).show();
	$("#remarks_"+str[1]).focus();	
	return false;
}else{
	$("#msg").removeClass("alert alert-danger").text('');
}
 generate_log(str[1],'update');
$.ajax({
									type: "POST",
									url:window.location.origin+"/leadmanagementcrm/index.php/home/updatelead/",
									data:{"id":str[1],"username":username,"email":email,"phone":phone,"followup":followup,"status":status,"remark":remark},
									success: function(data){
										$("#remarks_"+str[1]).hide(); 
									$("#msg").addClass("alert alert-success").text('User Updated');	
										 $("#remarks_"+str[1]).val(''); 
									}
									});	
});

function getmoreinfo(id){
	var dataString = "section=studentData&id="+ id;
		$.ajax({
		type: "POST",
		async:false,
		url: window.location.origin+'/leadmanagementcrm/index.php/home/InfoEdit/',
		data:dataString,
		cache: false,
		success: function(data){
			$("#studentInfo").html(data);
			$("#myModal").css('display','block');
			$("#studentInfo").show();
		  }
		});
}
function getcommunication(id){
	var dataString = "section=studentData&id="+ id;
		$.ajax({
		type: "POST",
		async:false,
		url: window.location.origin+'/leadmanagementcrm/index.php/home/Communication/',
		data:dataString,
		cache: false,
		success: function(data){
			$("#studentInfo").html(data);
			$("#myModals").css('display','block');
			$("#studentInfo").show();
		  }
		});	
}

function getBacktrack(id){
	var dataString = "section=studentData&id="+ id;
		$.ajax({
		type: "POST",
		async:false,
		url: window.location.origin+'/leadmanagementcrm/index.php/home/backtrack/',
		data:dataString,
		cache: false,
		success: function(data){
			$("#studentInfo").html(data);
			$("#myModalsw").css('display','block');
			$("#studentInfo").show();
		  }
		});	
}

$(document).on('click','#closeblock',function(){
$("#studentInfo").html("");
$("#myModal").css('display','none');
			$("#studentInfo").hide();	
});
function generate_log(studentId ,operation){
	console.log(studentId);
       var data = "section=studentData&student_id="+studentId+"&operation="+operation;
            $.ajax({
			   type:'POST',
			   url: window.location.origin+'/leadmanagementcrm/index.php/home/generate_log/',
			   data : data,
			   dataType: 'json',
			   success: function(data) {
			   }
			  }); 
}

function update_student_info(id){	
 var interestedin=$("#interestedin"+id).val();	
 var city=$("#city"+id).val();	
 var lookingfor=$("#lookingfor"+id).val();	
 var whatsapp_no=$("#whatsapp_no"+id).val();	
 var site_visit_date=$("#site_visit_date"+id).val();	
 var feedback=$("#feedback"+id).val();
  generate_log(id,'update');
$.ajax({
									type: "POST",
									url:window.location.origin+"/leadmanagementcrm/index.php/home/updatemoreinfo/",
									data:{"id":id,"city":city,"whatsapp_no":whatsapp_no,"site_visit_date":site_visit_date,"feedback":feedback,"interestedin":interestedin,"lookingfor":lookingfor},
									success: function(data){
									$("#studentInfo").html("");
                                    $("#myModal").css('display','none');
			                        $("#studentInfo").hide();	
									$("#msg").addClass("alert alert-success").text('User Updated');							
									}
									});	
}

$(document).ready(function(){
$(".assignmentAll").click(function(){
         if(this.checked){
   $(".assignment").prop('checked', true);   
        }else{
 $(".assignment").prop('checked', false); 
        }
    });
	 });
	$(".assign").click(function(){
	 var leads = [];
    $(".assignment:checked").each(function(){            
     leads.push($(this).val());
    });
	if(leads.length==0){
		$("#error_msg").show().text('select leads to assign');
	}else{$("#error_msg").show().text('');}
	var counsellor=$(".caller_id").val();
	if(counsellor==''){
		$("#error_msg").show().text('select caller to assign');
	}else{$("#error_msg").show().text();}
	if($("#error_msg").show().text()==''){
		  $.ajax({
			   type:'POST',
			   url: window.location.origin+'/leadmanagementcrm/index.php/home/AssignLeadsCounsellor/',
			   data : {'counsellor':counsellor,'leads':leads},
			   dataType:'json',
			   success: function(data){	
			   	$("#student_succ").html(data.message);					
                    window.location.reload();
				
				  }
	});
	//ConfirmDialog('Are you sure','Assign Confirmation',counsellor,leads);	
	}
});
function ConfirmDialog(message,header,counsellor,leads){
    $('<div></div>').appendTo('body')
     .html('<div><h6>'+message+'?</h6></div>')
     .dialog({
       modal: true, title: header, zIndex: 10000, autoOpen: true,
       width: 'auto', resizable: false,
       buttons: {
       Yes: function () {
                                      
       $(this).dialog("close");
	   for(var i=0;i<leads.length;i++){
		 generate_student_log(leads[i],'update');   
	   }
	   			  $.ajax({
			   type:'POST',
			   url: window.location.origin+'/leadmanagementcrm/index.php/home/AssignLeadsCounsellor/',
			   data : {'counsellor':counsellor,'leads':leads},
			   dataType:'json',
			   success: function(data){	
			   if(data.status == 1)
					{
					$("#student_succ").html(data.message);					
                    window.location.reload();
					}
				  }
	});
        },
      No: function () {
	                             
      $(this).dialog("close");
	  $("#assign_status").val('no');
     }
     }
    });
   };
   
   function getTemplate(id,temp){
	var set=id;   
	var template=temp.value;
	  $.ajax({
			   type:'POST',
			   url: window.location.origin+'/leadmanagementcrm/index.php/home/getTemplate/',
			   data : {'id':id,'template':template},
			   success: function(data){
				$("#getsmsinbox_"+set).val(data);
				  }
	  })
   }
   
   function update_sent(id,phone){
	var msg=$("#getsmsinbox_"+id).val(); 
    $.ajax({
			   type:'POST',
			   url: window.location.origin+'/leadmanagementcrm/index.php/home/sendSMS/',
			   data : {'id':id,'msg':msg,'phone':phone},
			   success: function(data){	
				$("#showmsg_"+id).html(data);
				  }
	  })	
   }
   function numbersonly(myfield, e, dec)
			{
			var key;
			var keychar;

			if (window.event)
			   key = window.event.keyCode;
			else if (e)
			   key = e.which;
			else
			   return true;
			keychar = String.fromCharCode(key);

			// control keys
			if ((key==null) || (key==0) || (key==8) || 
				(key==9) || (key==13) || (key==27) )
			   return true;

			// numbers
			else if ((("0123456789").indexOf(keychar) > -1))
			   return true;

			// decimal point jump
			else if (dec && (keychar == "."))
			   {
			   myfield.form.elements[dec].focus();
			   return false;
			   }
			else
			   return false;
		}
</script>
</body>
</html>
