<?php


$questionarr = array(
	"Respect for my opinion/preferences",				
	"Freshness and comfort of the room", 					
	"Feeling of Safety", 					
	"Confidence in our equipment",					
	"Support in moving around/on the bed", 					
	"Help with personal care and need",					
	"Were our Staff polite and courteous?", 					
	"Clear explanations of treatment processes and services received", 					
	"Treatment Outcome",			
	"Feeding"
);
$questionarr = array(
	"Were our Staff polite and courteous?", 					
);
$ratearr = array(
	5=>'Excellent',
	4=>'Very Good',
	3=>'Good',
	2=>'Poor',
	1=>'Very Poor'
);
// print_r($ratingarr);
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Website raiting form</title>
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
	<script>
	</script>
    <style>
      html, body {
      height: 100%;
      }
      body, h1, h3, input { 
      padding: 0;
      margin: 0;
      outline: none;
      font-family: Roboto, Arial, sans-serif;
      font-size: 16px;
      color: #666;
      }
      h1, h3 {
      padding: 12px 0;
      font-weight: 400;
      }
      h1 {
      font-size: 28px;
      }
      .main-block, .info {
      display: flex;
      flex-direction: column;
      }
      .main-block {
      justify-content: center;
      align-items: center;
      width: 100%;
      min-height: 100%;
      #background: url("/uploads/media/default/0001/01/49bff73f282c2c21f3341f1fe457fe35337b1792.jpeg") no-repeat center;
      background-size: cover;
      }
      form {
      width: 86%; 
      padding: 20px;
      margin-bottom: 20px;
      border-radius: 5px; 
      border: solid 1px #ccc;
      box-shadow: 1px 2px 5px rgba(0,0,0,.31); 
      background: #ebebeb; 
      }
      .info-item {
      width: 100%;
      }
      input {
      width: calc(100% - 57px);
      height: 36px;
      padding-left: 10px; 
      margin: 0 0 12px -5px;
      border-radius: 0 5px 5px 0;
      border: solid 1px #cbc9c9;
      box-shadow: 1px 2px 5px rgba(0,0,0,.09); 
      background: #fff; 
      }
      .icon {
      padding: 9px 15px;
      margin-top: -1px;
      border-radius: 5px 0 0 5px;
      border: solid 0px #cbc9c9;
      background: #666;
      color: #fff;
      }
      input[type=radio] {
      display: none;
      }
      label.radio {
      position: relative;
      display: inline-block;
      text-indent: 32px;
      cursor: pointer;
      }
      label.radio:before {
      content: "";
      position: absolute;
      left: 0;
      width: 18px;
      height: 18px;
      border-radius: 50%;
      border: 0.5px solid #8ebf42;
      background: #fff;
      }
      label.radio:after {
      content: "";
      position: absolute;
      width: 8px;
      height: 4px;
      top: 5px;
      left: 4px;
      border-bottom: 3px solid #8ebf42;
      border-left: 3px solid #8ebf42;
      transform: rotate(-45deg);
      opacity: 0;
      }
      input[type=radio]:checked + label:after {
      opacity: 1;
      }
      textarea {
      width: 99%;
      margin-bottom: 12px;
      }
      button {
      width: 100%;
      padding: 8px;
      border-radius: 5px; 
      border: none;
      background: #8ebf42; 
      font-size: 14px;
      font-weight: 600;
      color: #fff;
      }
      button:hover {
      background: #82b534;
      }
      .grade-type div {
      display: flex;
      margin: 6px 0;
      }
      @media (min-width: 568px) {
      .info {
      flex-flow: row wrap;
      justify-content: space-between;
      }
      .info-item {
      width: 48%;
      }
      }
    </style>
  </head>
  <body>
    <div class="main-block">
      <h1>Hospital Visit Feedback Form</h1>
	  
	  
      <form id="main-survey-form" method="post">
	  <!--
        <div class="info" style="display:none">
          <div class="info-item">
            <label class="icon" for="name"><i class="fas fa-user"></i></label>
            <input type="text" name="name" id="name" placeholder="Name" required/>
          </div>
          <div  class="info-item">
            <label class="icon" for="age"><i class="fas fa-calendar"></i></i></label>
            <input type="text" name="age" id="age" placeholder="Age" required/>
          </div>
          <div  class="info-item">
            <label class="icon" for="email"><i class="fas fa-envelope"></i></label>
            <input type="text" name="email" id="email" placeholder="Email" required/>
          </div>
          <div  class="info-item">
            <label class="icon" for="phone"><i class="fas fa-phone"></i></label>
            <input type="text" name="phone" id="phone" placeholder="Phone" required/>
          </div>
        </div>
		-->
		<div>
			<p>DIFF Medical Centre is dedicated to continuous improvement of the quality of clinical services provided. Please help us by taking a few moments to complete this questionnaire. Your participation is voluntary, and your responses will be treated with strict confidentiality. Thank you for participating!</p>
		</div>
		<input type="hidden" name="postdata" value="1"/>
        <div class="grade-type">
			<?php foreach($questionarr as $q=>$question):?>			
				  <h3><?=$question?></h3>
				  
				  <?php foreach($ratearr as $r=>$rate): ?>
				  <div> 
					<input type="radio" value="<?=$r?>" id="rate_<?=$q?>_<?=$r?>" name="rate[<?=$q?>]" />
					<label for="rate_<?=$q?>_<?=$r?>" class="radio"><?=$rate?></label>
				  </div>
				  <?php endforeach?>
			<?php endforeach?>
		  
		  
  		
        <h3>If your rating is 3 or below for any of the responses, would you like to share your experience with us?</h3>
        <textarea rows="4" name="comment_1"></textarea>
		
       <h3>Mention any other aspect of your experience with us that you like immediate improvement</h3>
        <textarea rows="4" name="comment_2"></textarea>
		
		
		
        <button type="submit" href="/">Submit</button>
      </form>
    </div>
	
	
	<script>
	document.addEventListener('DOMContentLoaded', function() {
		const f = document.querySelector('form#main-survey-form');
		// console.log(f);
		
		f.addEventListener('submit', function (e) {
			e.preventDefault();
			// console.log(e, this);
			// Get the form

			// Get all field data from the form
			let data = Object.fromEntries(new FormData(f));
		
			// Convert to an object
			console.log(data);
			
			
		});
		
	});
	
	// Example POST method implementation:
	async function postData(url = '', data = {}) {
	  // Default options are marked with *
	  const response = await fetch(url, {
		method: 'POST', // *GET, POST, PUT, DELETE, etc.
		
		mode: 'cors', // no-cors, *cors, same-origin
		cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
		credentials: 'same-origin', // include, *same-origin, omit
		
		headers: {
		  'Content-Type': 'application/json'
		  // 'Content-Type': 'application/x-www-form-urlencoded',
		},
		redirect: 'follow', // manual, *follow, error
		referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
		body: JSON.stringify(data) // body data type must match "Content-Type" header
	  });
	  return response.json(); // parses JSON response into native JavaScript objects
	}

	postData('survey-form-submit.php', { answer: 42 })
	  .then(data => {
		console.log(data); // JSON data parsed by `data.json()` call
	  });
	</script>
  </body>
</html>