<?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);


if ($_REQUEST["SubmitCsv"] != "") { 
$row = 0;

$DelSql="delete from temp_lead_master";
mysqli_query($con,$DelSql);

$tempFileName = time().".csv";
if ( is_uploaded_file( $_FILES["uploadFile"]['tmp_name']) ) {
	$fileCopied = copy( $_FILES["uploadFile"]['tmp_name'], $tempFileName);
	
	if($fileCopied)  {
				
		if (($handle = fopen($tempFileName, "r")) !== FALSE) {
			while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
				
				$num = count($data);
				for ($c=0; $c < $num; $c++)
							 {
								 $arr[$row][$c] = $data[$c];
								 //echo $data[$c];
							}
				$row++;
				}
			

							$Lead_Source=$_REQUEST['source'];
							$Lead_Campaign=$_REQUEST['campaign'];
							$Service=$_REQUEST['service'];
							$Control_Location=$_REQUEST['location'];

				
					//echo $arr[1][0];
			for($i=1; $i<$row; $i++)
			{
			
				$Name=$arr[$i][0];
				
				$Phone=$arr[$i][1];
				$Email=$arr[$i][2];
				$City=$arr[$i][3];
				$form_source='Import Lead';
				$cmnts=mysqli_real_escape_string($con,$arr[$i][5]);
				//$Control_Location=$arr[$i][6];
//$location_SLN=mysqli_fetch_array(mysqli_query($con,"select SLN from location_master where Location_Name='".$Control_Location."'"));
			
				$date=date('Y-m-d');
				
				
				//$sql = "INSERT INTO temp_member_master(Contact_Name, Contact_Email, Contact_Phone, M_Category, M_Group, Entry_Date) values('".mysqli_real_escape_string($conn,$Contact_Name)."','".mysqli_real_escape_string($conn,$Contact_Email)."','".mysqli_real_escape_string($conn,$Contact_Phone)."','".$Mem_Category."','".$Mem_Group."','".date('Y-m-d H:i:s')."') ";
				
				$Sql_Ins_QueryM="insert into temp_lead_master
			(Lead_ID,Lead_Creation_Date,Lead_Name,No_of_Enquiry,Phone,Email,City,Zone,Course_Name,Campaign,Priority,Form_Source,Allocation_Sequence,Lead_Referred_To,Remarks,Status,Active,Control_Location,Source)
			values ('".$Cln_Id."','".$date."','".$Name."','1','".$Phone."','".$Email."','".$City."','".$Zone."','".$Service."','".$Lead_Campaign."','1','".$form_source."','".$new_seq."','".$user."','".$cmnts."','','Yes','".$Control_Location."','".$Lead_Source."')";
				
				$q=mysqli_query($con,$Sql_Ins_QueryM) or die(mysqli_error());
				$r=mysqli_affected_rows($q);
				$rslt=$rslt+$q;
			

			}
			fclose($handle);
			@unlink($tempFileName);
			//$echo="File Upload Completed. See The Result.";
			
			?>
			<script>divHide();</script>
			<?php
			
		}
	}
	?>
	<script>window.location.href="preview_lead.php"</script>
	<?php

}

}
?>

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

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Import Lead | Buurtzorg</title>
    <?php include("headerlink.php"); ?> 
    
    
    <script src="https://cdn.ckeditor.com/4.10.0/standard/ckeditor.js"></script>
    
    
    
    
    
    
    
    
    
     <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 personaliz_label(per) {
	 
	
	 $('#ps').text(per);
	
	}
	
 
	</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);
	?>   
    
    <script type="text/javascript">
	function ShowPersonalize()
	{
	   if(document.getElementById("personalize").checked==true)
	   {
	   
	      $('#personalize_div').show();
	   }
	   else
	   {
	      $('#personalize_div').hide();
	   }
	
	}
	</script> 
    
<script>
function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
    {
        return false;
    }
    else
    {
        return true;
    }
}

</script> 

 <script>
	function GetCampagin()
	{
	 var a=$('#campaign-search-box').val();

	 $.ajax({
		type: "POST",
		url: "./common/get_campaign_list.php",
		data:'keyword='+a,
		success: function(data){
			//alert(data);
			$("#suggesstion-box").show();
			$("#suggesstion-box").html(data);
			
		}
		});
	}
	</script>
    
    
<script>

function GetBlog(val) {

$("#campaign-search-box").val(val);
$("#suggesstion-box").hide();
}
</script>

<style type="text/css">
/*======================Search================================*/

#country-list{float:left;list-style:none; margin:0; padding:0; width:95%; position:absolute; z-index:1800; margin-top:0%; margin-left:0px;}
#country-list li{padding:2%; background:#FAFAFA; border-bottom:#F0F0F0 1px solid; font-size:11px; font-family: 'Hind', sans-serif;}
#country-list li:hover{background:#F0F0F0;}
#search-box{/*padding:0%;*/ width:88%; height:30px; float:left;  background-color:#FFFFFF; position:relative;}
/*==========================================================================*/
</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="container-fluid">
                <div class="row">
                
                
                    
                    <div class="col-lg-12 col-md-12 col-sm-12 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; text-transform:uppercase">Import</h1>
                                   
                                    
                                          <div class="row" style="padding:0; background-color:#FFFFFF">
                                           
                                              
                                
                                  <form method="post" action="#" id="add_lead" enctype="multipart/form-data">
                                   
                                      <div class="col-sm-12" style="padding:0">
                                      <div class="col-sm-3" id="call_later_div">
                                      
                                    
                                      
                                      
                                      <div class="form-group"><label>UPLOAD FILE <span style="color:#FF0000;">*</span></label>
                                           
                                             <input name="uploadFile" id="UPLOAD_FILE" type="file"  placeholder="UPLOAD_FILE" data-rule-required="true" data-msg-required="Please enter upload file">
                                                     
                                                   </div>
                                                  
                                                   
                                                </div>
                                    </div>
                                      
                                      
                                                
                                                
                                                
                                                
                                                
                                                
                                                
                                                
                                                
                                       
                                               
                                               
                                               <div class="col-sm-3">
                                     
                                      			<div class="form-group"><label>SOURCE <span style="color:#FF0000;">*</span></label>
                                           
                                            <select name="source" class="form-control" id="source" data-rule-required="true" data-msg-required="Please select source">
                                            
                                               <option value="">Select Source</option>
                                             <?php
											  $SqlLoc="select SLN, Source_Name from source_master";
                                               $RsLoc= mysqli_query($con,$SqlLoc);
                                               while($RowLoc=mysqli_fetch_array($RsLoc))
											   {
											 ?>
                                              <option value="<?php echo $RowLoc['Source_Name']; ?>"><?php echo $RowLoc['Source_Name']; ?></option>
                                                <?php
												}
												?>
                                             </select>
                                                      
                                                   </div>
                                                   
                                                </div>
                                                
                                                
                                                 <div class="col-sm-3">
                                                <div class="form-group"><label>CAMPAIGN <span style="color:#FF0000;">*</span></label>
                                           
                                             <input name="campaign" id="campaign-search-box" type="text" class="form-control"  placeholder="Campaign"  onKeyUp="GetCampagin()" data-rule-required="true" data-msg-required="Please insert campaign">
                                              
                                                      <div id="suggesstion-box"></div>
                                                   </div>
                                                   </div>
                                                   
                                                  
                                                  <div class="col-sm-3">
                                     
                                      			<div class="form-group"><label>CONTROL LOCATION</label>
                                           
                                            <select name="location" class="form-control" id="location">
                                             <option value="">Select Location</option>
                                             <?php
											  $SqlLoc="select SLN, Location_Name from location_master";
                                               $RsLoc= mysqli_query($con,$SqlLoc);
                                               while($RowLoc=mysqli_fetch_array($RsLoc))
											   {
											 ?>
                                              <option value="<?php echo $RowLoc['SLN']; ?>"><?php echo $RowLoc['Location_Name']; ?></option>
                                                <?php
												}
												?>
                                             </select>
                                                      
                                                   </div>
                                                   
                                                </div>
                                                   
                                                   <div class="col-sm-3">
                                     
                                      			<div class="form-group"><label>SERVICES</label>
                                           
                                            <select name="service" class="form-control" id="service">
                                             <option value="">Select Service</option>
                                             <?php
											  $SqlLoc="select SLN,Service from service_master";
                                               $RsLoc= mysqli_query($con,$SqlLoc);
                                               while($RowLoc=mysqli_fetch_array($RsLoc))
											   {
											 ?>
                                              <option value="<?php echo $RowLoc['Service']; ?>"><?php echo $RowLoc['Service']; ?></option>
                                                <?php
												}
												?>
                                             </select>
                                                      
                                                   </div>
                                                   
                                                </div>
                                                   
                                                   
                                                
                                                
                                                <div class="col-sm-3">
                                              <div class="form-group">  <label></label>
                                                 <input type="submit" class="btn btn-custon-rounded-three
                                    				btn-primary" name="SubmitCsv" value="Upload File" style="margin-top:30px; float:left;"></div>
                                    			
                                                </div>
                                                
                                                <label class=" form-control-label" style="padding-left:15px; color:#FF0000; width:100%; margin-top:10px;">
                                                *Only csv files allowed.</label>
                                                
                                                
                                                 
                                                 <label class=" form-control-label" style="padding-left:15px; color:#333333; width:100%; margin-top:10px;">
                                                  <a href="demo_lead_master.csv">View Sample File </a></label>
                                              
                                              
                                        </form>
                               
                                       
                               
                                        
                                        
                                        
                                        
                                            </div>
                                        
                                          
                                         
                                         
                                         
                                         
                                           
                                </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>   



<script type="text/javascript">
$("#add_lead").validate({
          
      showErrors: function(errorMap, errorList) {
          // Clean up any tooltips for valid elements
          $.each(this.validElements(), function (index, element) {
              var $element = $(element);
              $element.data("title", "") // Clear the title - there is no error associated anymore
                  .removeClass("error")
                  .tooltip("destroy");
          });
          // Create new tooltips for invalid elements
          $.each(errorList, function (index, error) {
              var $element = $(error.element);

              $element.tooltip("destroy") // Destroy any pre-existing tooltip so we can repopulate with new tooltip content
                  .data("title", error.message)
                  .addClass("error")
                  .tooltip(); // Create a new tooltip based on the error messsage we just set in the title
          });
      },

     
	  
});
</script>                                          
                                                
                                                
 <!-- <script>
		CKEDITOR.replace( 'editor1', {
			height: 150,
			width: 700,
		} );
	</script> -->                                             
                                                
    
</body>

</html>