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

$Lead_Va_Id=base64_decode($_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>View Service | Buurtzorg</title>
    <?php include("headerlink.php"); ?> 
    
    
   
    
    
    
    <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;
		}
		
		
		
		
		</style>
    
    <?php
	//------------- Patient ID -------------//
/* $seq_sln_sql="select max(SLN) as total_leads from patient_master ";
	$seq_sln_qry=mysqli_query($con,$seq_sln_sql);
	$seq_sln=mysqli_fetch_array($seq_sln_qry);
    $Max_Sln=$seq_sln['total_leads']; 

		if($seq_sln['total_leads']!='')
		{			 
		    
			$Sql_PrjId="Select * From patient_master Where SLN='".$Max_Sln."'";
			$Qry_PrjId=mysqli_query($con,$Sql_PrjId);
			$Result_PrjId=mysqli_fetch_array($Qry_PrjId);
			$Max_PrjId=$Result_PrjId['Patient_Id'];
			$Id=explode("PID",$Max_PrjId);
			$New_PrjId=$Id[1]+1;								
			$Cln_Id="PID".$New_PrjId; 
		}
		else
		{
			$Cln_Id="PID10001";
		}*/

	//------------- Patient ID -------------//
		?>
    
    
    
     <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">

</head>

<body onLoad="showbutton('<?php echo $Lead_Va_Id; ?>')">
 <?php 
  if (isset($_REQUEST['upld_agreement']))
  	{ 
	$flag=0;
$fileName1 = $_FILES["agreement"]["name"]; // The file name
$fileTmpLoc1 = $_FILES["agreement"]["tmp_name"]; // File in the PHP tmp folder
$fileType1 = $_FILES["agreement"]["type"]; // The type of file it is
$fileSize1 = $_FILES["agreement"]["size"]; // File size in bytes
$fileErrorMsg1 = $_FILES["agreement"]["error"]; // 0 for false... and 1 for true

$name1=time() . '_' .$fileName1;
$target1=$target1.basename($name1);
$type1=pathinfo($target1,PATHINFO_EXTENSION);
	$mimeArray1 = array('image/jpeg','image/png','application/pdf');
		
			if (!in_array($fileType1, $mimeArray1)) 
			
			{
            $msg='Only jpg,jpeg,pdf files format are allowed to Upload';
			$flag=1;
			}
			else if ($fileSize1 > 10240000) 
  			{
				
       		$msg='File is too large. File must be less than 1 MB';
           	$flag=1;
 			}
			
			if($flag==0)
			{
			move_uploaded_file($fileTmpLoc1, "uploadfile/$name1");

  		$upload="update `patient_agreement` set `Signed_Agreement`='".$name1."' where Lead_ID='".$Lead_Va_Id."'";
		$upload_query=mysqli_query($con,$upload);
		
		$uploadcomplete="update `lead_contact_details` set `Signed_Agreement`='1' where Lead_ID='".$Lead_Va_Id."'";
		$uploadcomplete_query=mysqli_query($con,$uploadcomplete);
		
		$CheckPatientMaster=Numrow_Chk($con,'patient_master','Lead_ID',base64_decode($_REQUEST['Lid'])); 
		  
		  if($CheckPatientMaster==0)
			{
		  
		  $patient_master="insert into patient_master(Lead_ID,Patient_Id,Patient_Name,Gender,DOB,Age,Mobile,Email,Adhar_No,Address,Landmark,State,Pin_Code,Reffered_Buurtzorg_From,Other_FM_Staying_With_Patient,Doctor_Name,Patient_Creation_Date)values('".base64_decode($_REQUEST['Lid'])."','".$Cln_Id."','".$_REQUEST['Patient_Name']."','".$_REQUEST['Gender']."','".$_REQUEST['DOB']."','".$_REQUEST['Age']."','".$_REQUEST['Mobile']."','".$_REQUEST['Email']."','".$_REQUEST['Adhar_No']."','".mysql_real_escape_string($_REQUEST['Address'])."','".$_REQUEST['Landmark']."','".$_REQUEST['State']."','".$_REQUEST['Pin_Code']."','".$_REQUEST['Reffered_Buurtzorg_From']."','".$_REQUEST['Other_FM_Staying_With_Patient']."','".($_REQUEST['Doctor_Name'])."','".date('Y-m-d')."')";
           mysqli_query($con,$patient_master);
		   
		   }
		   else
		   {
			   $UpdatePatMas="update patient_master set Patient_Name='".$_REQUEST['Patient_Name']."', Gender='".$_REQUEST['Gender']."', DOB='".$_REQUEST['DOB']."',Age='".$_REQUEST['Age']."',Mobile='".$_REQUEST['Mobile']."',Email='".$_REQUEST['Email']."',Adhar_No='".$_REQUEST['Adhar_No']."',Address='".mysql_real_escape_string($_REQUEST['Address'])."',Landmark='".$_REQUEST['Landmark']."',State='".$_REQUEST['State']."',Pin_Code='".$_REQUEST['Pin_Code']."',Reffered_Buurtzorg_From='".$_REQUEST['Reffered_Buurtzorg_From']."',Other_FM_Staying_With_Patient='".$_REQUEST['Other_FM_Staying_With_Patient']."' where Lead_ID='".base64_decode($_REQUEST['Lid'])."' and Patient_Creation_Date='".date('Y-m-d')."'";
				 mysqli_query($con,$UpdatePatMas);
				 //NewLead($con,$_REQUEST['Patient_Name']);
		   }
		?>
        <script>
     			alert('Agreement uploaded Successsfully');
						setTimeout( function() {
			
						window.parent.location.href="Pending_Agreement.php";
						},500);
     		</script>
        <?php
		}
		}
		
		 //$FetchPatientMaster=FetchData($con,'lead_contact_details','Lead_ID',$_REQUEST['Lid']);
		   //query for lead_contact_details//
		   $fetch="select * from lead_contact_details where Lead_ID='".$Lead_Va_Id."'";
		   $fetch_query=mysqli_query($con,$fetch);
		   $fetch_fetch=mysqli_fetch_array($fetch_query);
		   //patient_agreement//
		   $fetch2="select * from lead_master where Lead_ID='".$Lead_Va_Id."'";
		   $fetch2_query=mysqli_query($con,$fetch2);
		   $fetch_fetch2=mysqli_fetch_array($fetch2_query)
		?>
        <br />
        <br />
	<div style="text-align:center;">
    <h4>Upload Scan Copy of Physically Signed Agreement</h4>
    </div>
    <br />
    <form action="#" name="Product" method="post"  enctype="multipart/form-data" onSubmit="return ValidateProduct()" style="text-align:center;">
    <div id="prnt_btn">
   <center> <input type="file" autocomplete="off" name="agreement" id="agreement" class="txtbox" placeholder="Upload Agreement" style="margin-bottom:5px; padding-top:3px; padding-bottom:3px; background-color:#CCCCCC; margin:20px 0px;" onClick="ActiveColour('agreement')"></center> 
    <input name="upld_agreement" id="upld_agreement" type="submit" value="Upload Agreement" class="btn btn-success" style="margin-bottom:20px;" />
    <!--<div style="display:none;">
    <input name="Patient_Name" id="Patient_Name" type="text" value="<?php echo $fetch_fetch['Patient_Name']; ?>">
    
     			 <select name="Gender" id="Gender" class="form-control" style="" >
                 <option value="" selected hidden>-- Select --</option>
                 <option value="Male" <?php if($fetch_fetch['Patient_Gender']=="M"){echo "selected";}?>>Male</option>
                 <option value="Female" <?php if($fetch_fetch['Patient_Gender']=="F"){echo "selected";}?>>Female</option> 
                 </select> 
                 
     <input name="DOB" id="from_Date" type="text" value="<?php echo $fetch_fetch['DOB']; ?>">
     
     <input name="Age" id="Age" type="text"  value="<?php echo $fetch_fetch['Patient_Age']; ?>"
     
     <input name="Mobile" id="Mobile" type="text" value="<?php echo $fetch_fetch['Contactperson_Phno']; ?>">
     
      <input name="Email" id="Email" type="text" value="<?php echo $fetch_fetch['Contact_Person_Email']; ?>">
      
      <input name="Adhar_No" id="Adhar_No" type="text" value="<?php echo $fetch_fetch['Adhar_No']; ?>">
      
      <textarea name="Address" id="Address"><?php echo $fetch_fetch['Patient_Address1']; ?></textarea>
      
       <input name="Landmark" id="Landmark" type="text"  value="<?php echo $fetch_fetch['Landmark']; ?>">
       
        <select name="State" class="form-control" id="pState"  data-rule-required="true" data-msg-required="Please select state">
                      <option value="">Select State</option>
                                              <?php
											   $SqlLoc="select SLN, State_Name from state_master";
                                               $RsLoc= mysqli_query($con,$SqlLoc);
                                               while($RowSt=mysqli_fetch_array($RsLoc))
											   {
											 ?>
                                              <option value="<?php echo $RowSt['State_Name']; ?>" <?php if($RowSt['State_Name']==$fetch_fetch['Patient_State']){echo "selected";} ?>><?php echo $RowSt['State_Name']; ?></option>
                                                <?php
												}
												?>
                 </select>
                 
                 <input name="Pin_Code" id="Pin_Code" value="<?php echo $fetch_fetch['Patient_Pincode']; ?>">
                 
                  <select name="Reffered_Buurtzorg_From" id="Reffered_Buurtzorg_From" class="form-control" onChange="Reffered_opt_function()">
                 <option value="" selected>Select reffered from</option>
                 <option value="Doctor" <?php if($fetch_fetch2['Lead_Referred_To']=="Doctor"){echo "selected";} ?>>Doctor</option>
                 <option value="Family" <?php if($fetch_fetch2['Lead_Referred_To']=="Family"){echo "selected";} ?> >Family</option>
                 <option value="Friend" <?php if($fetch_fetch2['Lead_Referred_To']=="Friend"){echo "selected";} ?>>Friend</option>  
                 <option value="Close_to_home_work" <?php if($fetch_fetch2['Lead_Referred_To']=="Close_to_home_work"){echo "selected";} ?>>Close to home/work</option>
                 <option value="Yellow_Pages" <?php if($fetch_fetch2['Lead_Referred_To']=="Yellow_Pages"){echo "selected";} ?>>Yellow Pages</option>
                 <option value="Other" <?php if($fetch_fetch2['Lead_Referred_To']=="Other"){echo "selected";} ?>>Other</option>
                 </select>
                 
                 <input name="Doctor_Name" id="Doctor_Name" value="<?php $fetch_fetch2['Allocated_Doctor']; ?>">
                 
                 <input name="Other_FM_Staying_With_Patient" id="Other_FM_Staying_With_Patient"s value="<?php echo $fetch_fetch['Other_FM_Staying_With_Patient']; ?>">
    </div>-->
    </form>
    <span style="color:#FF0000;  font-size:12px; text-align:center; display:block"><?php echo $msg;?></span>
   	 
    </div>   
       
       
       </body>

</html>