<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head><script src="Js/html2canvas.js"></script></head>
<body>
<style>
  body {
  background-color: #e8dada;
  width: 100%;
  height: auto%;
}

.image1 {
  width: 100%;
  height: auto;
 
}
.image2 {
  width: 20%;
  height: auto;
 
}

.image3 {
  width: 10%;
  height: auto;

}
.image4 {
  width: 4%;
  height: auto;

}


div.relative {
  position: relative;
  width: 100%;
  height: auto;
  font-family:Courier New;
}

.label1{
  width: 100%;
  position: absolute;
  top: 23%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  font-weight:bold;
  font-size: 200%;
  text-align: center;
}
.label2{
  width: 100%;
  position: absolute;
  top: 26%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  font-weight:bold;
  font-size: 190%;
  text-align: center;
}
.label3{
  width: 100%;
  position: absolute;
  top: 31%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  font-weight:bold;
  font-size: 190%;
  text-align: center;
}
.label4{
  width: 100%;
  position: absolute;
  top: 36%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
   font-weight:bold;
  font-size: 190%;
  text-align: center;
}
.label5{
  width: 65%;
  height: auto;
  position: absolute;
  top: 41%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
   font-weight:bold;
  font-size: 190%;
  text-align: center;

}

.label6{
  width: 67%;
  height: auto;
  position: absolute;
  top: 46%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  font-size: 170%;

}

.label7{
  width: 73%;
  height: auto;
  position: absolute;
  top: 70%;
  left: 60%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  font-size: 170%;
  text-align: right;

}

.ok{
  width: 100%;
  position: absolute;
  top: 63%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.savepng{
  width: 85%;
  position: absolute;
  top: 65%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.round-button {
display:block;
width:100px;
height:100px;
line-height:100px;
border: 2px solid #f5f5f5;
border-radius: 50%;
color:#f5f5f5;
text-align:center;
text-decoration:none;
box-shadow: 0 0 3px gray;
font-size:20px;
font-weight:bold;
background: url(Image/savepng.png);
background-size: 100%; 
background-size: 100px; 
}
.round-button:hover {
background: url(Image/savepng_bk.png);
background-size: 100%; 
background-size: 100px; 
}

<?php include("conn.php"); ?>

</style>

<div class="relative">

<img class="image1" src="Image/covid it-01.png" >
<?php

$Page = $_COOKIE['Page'];

$Name1 = $_COOKIE['Name1'];

$Telephone1 = $_COOKIE['Telephone1'];

$Asw1 = $_COOKIE['chk1v'];
$Asw2 = $_COOKIE['chk2v'];
$Asw3 = $_COOKIE['chk3v'];
$Asw4 = $_COOKIE['chk4v'];
$Asw5 = $_COOKIE['chk5v'];
$Asw6 = $_COOKIE['chk6v'];


if($Page!='0'){

   $SqlawsID="";
   $SqlQusetionID="";
   $RiskAsw="";
date_default_timezone_set("Asia/Bangkok");
$DateAws=date('d/m/Y H:m:s');

if($Page=='1'){
  $SqlQusetionID="101TH";
$myFile = "Awstxt/".$Name1."_".date("dmY").".txt";
$fh = fopen($myFile, 'w+');

$labtopic="แบบบันทึกข้อมูลเชื้อไวรัสโคโรนา 2019";
?>

<label class="label1"><?php echo $labtopic; ?></label>
<label class="label2"><?php echo "วันที่ ".$DateAws; ?></label>
<?php

if ($Name1!=""){
$string = "ชื่อ-นามสกุล: ".$Name1."\n";
fwrite($fh, $string);
$labName=$Name1;
?>

<label class="label3"><?php echo $labName; ?></label>

<?php
}

if ($Telephone1!=""){
$string = "Telephone: ".$Telephone1."\n";
fwrite($fh, $string);
$labPhone="เบอร์โทรศัพท์: ".$Telephone1;
?>

<label class="label4"><?php echo $labPhone; ?></label>

<?php
}

$string = "ปัจจัยเสี่ยงที่เลือก\n";
fwrite($fh, $string);
$labRisk="ปัจจัยเสี่ยงที่เลือก";
?>
<label class="label5"><?php echo $labRisk; ?></label>
<?php

if ($Asw1!="none"){
$string = "-".$Asw1."\n";
fwrite($fh, $string);
$RiskAsw=$string;
$SqlawsID="101TH-1"; 
}

if ($Asw2!="none"){
$string = "-".$Asw2."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string; 
$SqlawsID=$SqlawsID.",101TH-2"; 
}

if ($Asw3!="none"){
$string = "-".$Asw3."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string;
$SqlawsID=$SqlawsID.",101TH-3"; 
}

if ($Asw4!="none"){
$string = "-".$Asw4."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string; 
$SqlawsID=$SqlawsID.",101TH-4";
}

if ($Asw5!="none"){
$string = "-".$Asw5."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string;
$SqlawsID=$SqlawsID.",101TH-5"; 
}

if ($Asw6!="none"){
$string = "-".$Asw6."\n";
fwrite($fh, $string);
$RiskAsw=$string; 
$SqlawsID="101TH-6";
}


}elseif ($Page=='2') {
  $SqlQusetionID="101EN";
$myFile = "Awstxt/".$Name1."_".date("dmY").".txt";
$fh = fopen($myFile, 'w+');

$labtopic="COVID19 Screening Form";
?>

<label class="label1"><?php echo $labtopic; ?></label>
<label class="label2"><?php echo "Date ".$DateAws; ?></label>

<?php

if ($Name1!=""){
$string = "Name-Surname: ".$Name1."\n";
fwrite($fh, $string);
$labName=$Name1;
?>

<label class="label3"><?php echo $labName; ?></label>

<?php
}

if ($Telephone1!=""){
$string = "Telephone: ".$Telephone1."\n";
fwrite($fh, $string);
$labPhone="Phone Number: ".$Telephone1;
?>

<label class="label4"><?php echo $labPhone; ?></label>

<?php
}

$string = "history of risk\n";
fwrite($fh, $string);
$labRisk="history of risk";
?>
<label class="label5"><?php echo $labRisk; ?></label>
<?php

if ($Asw1!="none"){
$string = "-".$Asw1."\n";
fwrite($fh, $string);
$RiskAsw=$string; 
$SqlawsID="101EN-1"; 
}

if ($Asw2!="none"){
$string = "-".$Asw2."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string; 
$SqlawsID=$SqlawsID.",101EN-2"; 
}

if ($Asw3!="none"){
$string = "-".$Asw3."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string; 
$SqlawsID=$SqlawsID.",101EN-3"; 
}

if ($Asw4!="none"){
$string = "-".$Asw4."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string; 
$SqlawsID=$SqlawsID.",101EN-4"; 
}

if ($Asw5!="none"){
$string = "-".$Asw5."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string; 
$SqlawsID=$SqlawsID.",101EN-5"; 
}

if ($Asw6!="none"){
$string = "-".$Asw6."\n";
fwrite($fh, $string);
$RiskAsw=$RiskAsw."<br>".$string; 
$SqlawsID="101EN-6"; 
}


}

fclose($fh);

?>

<label class="label6"><?php echo $RiskAsw; ?></label>

<?php
/*$sqlcode="SELECT COUNT(fullname) FROM covidaws WHERE fullname='".$Name1."' " or die(mysqli_error());
$builcode=mysqli_query($con,$sqlcode);
$sumcode=mysqli_fetch_array($builcode);

if($sumcode[0]==0){
*/if ($Name1!=""){
  $sqlcode="INSERT INTO `covidaws`(`fullname`, `phoneno`, `awsno`, `idqusetion`, `dateaws`) VALUES ('".$Name1."','".$Telephone1."','".$SqlawsID."','".$SqlQusetionID."','".$DateAws."')" or die(mysqli_error());
  $builcode=mysqli_query($con,$sqlcode); 
   }
/*}elseif ($sumcode[0]==1) {
  $sqlcode="UPDATE `covidaws` SET `phoneno`='".$Telephone1."',`awsno`='".$SqlawsID."',`idqusetion`='".$SqlQusetionID."',`dateaws`='".$DateAws."' WHERE fullname='".$Name1."' " or die(mysqli_error());
  $builcode=mysqli_query($con,$sqlcode); 
}*/

}elseif ($Page=='0') {
 echo "<script>window.location.href='index.php';</script>";
}

?>


<!--<label class="label7">IOS support on <img class="image4" src="Image/safari.png" > ,Android support on <img class="image4" src="Image/Chrome.png" ></label>-->
<div class="ok">
<center>
<img class="image2" src="Image/ok.png" >
</center>
</div>

<div class="savepng">

<button class="round-button" style="float:right" onclick='screenshot()' ></button>

</div>


</div>


  <script>

  document.cookie="Page="+encodeURIComponent('0');


  document.cookie="Name1="+encodeURIComponent('');

  document.cookie="Telephone1="+encodeURIComponent('');

  document.cookie="chk1v="+encodeURIComponent('none');
  document.cookie="chk2v="+encodeURIComponent('none');
  document.cookie="chk3v="+encodeURIComponent('none');
  document.cookie="chk4v="+encodeURIComponent('none');
  document.cookie="chk5v="+encodeURIComponent('none');
  document.cookie="chk6v="+encodeURIComponent('none');
</script>

<script type='text/javascript'>
  function screenshot(){
//var container = document.getElementById("image-wrap"); //specific element on page
      var container = document.body; // full page 
      html2canvas(container).then(function(canvas) {
                var link = document.createElement("a");
                document.body.appendChild(link);
                link.download = "html_image.jpg";
                link.href = canvas.toDataURL("image/jpeg");
                link.target = '_blank';
                link.click();
            });
  }
  </script>


</body>
</html>

