<?php session_start();
require_once 'config.php';
$PageName = "Survey / Task"; ?>
<!doctype html>
<html lang="en" class="h-100">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="generator" content="">
     <title><?php echo $Proj_Title; ?></title>

    <!-- manifest meta -->
    <meta name="apple-mobile-web-app-capable" content="yes">

    <!-- Favicons -->
    <link rel="apple-touch-icon" href="img/favicon180.png" sizes="180x180">
    <link rel="icon" href="img/favicon32.png" sizes="32x32" type="image/png">
    <link rel="icon" href="img/favicon16.png" sizes="16x16" type="image/png">

    <!-- Material icons-->
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    <!-- Google fonts-->
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&amp;display=swap" rel="stylesheet">

    <!-- swiper CSS -->
    <link href="vendor/swiper/css/swiper.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/style.css" rel="stylesheet" id="style">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert-dev.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css">
</head>

<body class="body-scroll d-flex flex-column h-100 menu-overlay">
    <!-- screen loader -->
   
<?php
$Survey_Id = $_GET['id'];
$User_Id = $_SESSION['User']['id'];
$sql33 = "SELECT * FROM tbl_given_survey_details WHERE UserId='$User_Id' AND SurveyId='$Survey_Id'";
$rncnt33 = getRow($sql33);
if($rncnt33 > 0){
    ?>
          <script type="text/javascript">
    setTimeout(function () { 
swal({
  title: "",
  text: "You already have given this survey!",
  type: "warning",
  confirmButtonText: "OK"
},
function(isConfirm){
  if (isConfirm) {
   window.location.href="my-survey.php";
  }
}); });</script>
  <?php
}
if(isset($_POST['submit'])){
$keys = $_POST['id'];
$option1 = $_POST['option1'];
$option2 = $_POST['option2'];
$option3 = $_POST['option3'];
$option4 = $_POST['option4'];
$SurveyId = $_POST['SurveyId'];
$CourseId = $_POST['CourseId'];
$BatchId = $_POST['BatchId'];
$CollegeId = $_POST['CollegeId'];
$UserId = $_POST['UserId'];
$Answer = $_POST['Option'];

 $result = array();
      foreach ($keys as $id => $key) {
          $result[$key] = array(
              '0' => $keys[$id],  
              '1' => $option1[$id], 
              '2' => $option2[$id],
              '3' => $option3[$id],  
              '4' => $option4[$id], 
              '5'  => $Answer[$id], 
          ); 
      }
//echo "<pre>";print_r($result);


        $CreatedDate = date('Y-m-d');
        $CreatedTime = date('h:i a');
        if(is_array($result))
          {
              foreach($result as $row => $value)
              {
                $QuesId = $value[0];
                $Option1 = $value[1];
                $Option2 = $value[2];
                $Option3 = $value[3];
                $Option4 = $value[4];
                $Answer = $value[5];

               $sql22 = "INSERT INTO tbl_given_survey_details SET UserId='$UserId',SurveyId='$SurveyId',CourseId='$CourseId',BatchId='$BatchId',CollegeId='$CollegeId',QuesId='$QuesId',Option1='$Option1',Option2='$Option2',Option3='$Option3',Option4='$Option4',Answer='$Answer',CreatedDate='$CreatedDate',CreatedTime='$CreatedTime'";
                $conn->query($sql22);
               }
          }      
      ?>
              <script type="text/javascript">
    setTimeout(function () { 
      swal({
    title: "Thank You For Giving Survey",
     type: "success",
  showCancelButton: false,
  confirmButtonColor: "#a5dc86",
  confirmButtonText: "Ok",
  closeOnConfirm: false,
  closeOnCancel: false
},
function(isConfirm){
  if (isConfirm) {
   window.location.href = "my-survey.php";
  }
  else {
     window.location.href = "my-survey.php";
  }
});
      });
    </script>
          <?php    
        


}
?>


    <!-- Begin page content -->
    <main class="flex-shrink-0 main">
        <!-- Fixed navbar -->
        <?php include_once 'back-header.php'; ?>
        <!-- page content start -->
        <div class="main-container">
            <div class="container">
                <form action="#" method="POST">
                    <input type="hidden" name="SurveyId" id="SurveyId" value="<?php echo $_GET['id']; ?>">
    <input type="hidden" name="CourseId" id="CourseId" value="<?php echo $Course; ?>">
     <input type="hidden" name="BatchId" id="BatchId" value="<?php echo $BatchId; ?>">
     <input type="hidden" name="CollegeId" id="CollegeId" value="<?php echo $CollegeId; ?>">
     <input type="hidden" name="UserId" id="UserId" value="<?php echo $_SESSION['User']['id']; ?>">
                <?php 
                    $id = $_GET['id'];
                    $i = 1;
                    $sql44 = "SELECT * FROM tbl_survey_tasks_details WHERE Status=1 AND TaskId='$id'";
                    $row44 = getList($sql44);
                    foreach($row44 as $result){
                 ?>
                <div class="card mb-4">
                    <div class="card-header">
                        <h6 class="mb-0"><small class="text-secondary">Q<?php echo $i;?>. <?php echo $result['Question']; ?></small></h6>
                    </div>
                     <input type="hidden" name="id[<?php echo $result["id"]; ?>]" value="<?php echo $result["id"]; ?>">
                    <div class="card-body">
                        <div class="custom-control custom-switch">
                            <input type="radio" name="Option[<?php echo $result['id']; ?>]" class="custom-control-input" id="customSwitch1<?php echo $result['id']; ?>"  value="<?php echo $result['Answer1']; ?>">
                            <label class="custom-control-label" for="customSwitch1<?php echo $result['id']; ?>"><?php echo $result['Answer1']; ?></label>
                         <input type="hidden" name="option1[<?php echo $result["id"]; ?>]" value="<?php echo $result["Answer1"]; ?>">    
                        </div>
                        <div class="custom-control custom-switch">
                            <input type="radio" name="Option[<?php echo $result['id']; ?>]" class="custom-control-input" id="customSwitch2<?php echo $result['id']; ?>" value="<?php echo $result['Answer2']; ?>">
                            <label class="custom-control-label" for="customSwitch2<?php echo $result['id']; ?>"><?php echo $result['Answer2']; ?></label>
                      <input type="hidden" name="option2[<?php echo $result["id"]; ?>]" value="<?php echo $result["Answer2"]; ?>">       
                        </div>
                         <div class="custom-control custom-switch">
                            <input type="radio" name="Option[<?php echo $result['id']; ?>]" class="custom-control-input" id="customSwitch3<?php echo $result['id']; ?>"  value="<?php echo $result['Answer3']; ?>">
                            <label class="custom-control-label" for="customSwitch3<?php echo $result['id']; ?>"><?php echo $result['Answer3']; ?></label>
                    <input type="hidden" name="option3[<?php echo $result["id"]; ?>]" value="<?php echo $result["Answer3"]; ?>">         
                        </div>
                         <div class="custom-control custom-switch">
                            <input type="radio" name="Option[<?php echo $result['id']; ?>]" class="custom-control-input" id="customSwitch4<?php echo $result['id']; ?>"  value="<?php echo $result['Answer4']; ?>">
                            <label class="custom-control-label" for="customSwitch4<?php echo $result['id']; ?>"><?php echo $result['Answer4']; ?></label>
                     <input type="hidden" name="option4[<?php echo $result["id"]; ?>]" value="<?php echo $result["Answer4"]; ?>">        
                        </div>
                    </div>
                </div>
            <?php $i++;} ?>
             <div class="form-row" style="padding-left: 10px;">
                      <button type="submit" name="submit" class="mb-2 btn btn-success">Submit</button>&nbsp;&nbsp;&nbsp;
                        <button type="reset" class="mb-2 btn btn-primary">Reset</button>
      </div>
        </form>
            <br><br><br><br>
            </div>
        </div>
    </main>


    <!-- Required jquery and libraries -->
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- cookie js -->
    <script src="js/jquery.cookie.js"></script>

    <!-- Swiper slider  js-->
    <script src="vendor/swiper/js/swiper.min.js"></script>

    <!-- Customized jquery file  -->
    <script src="js/main.js"></script>
    <script src="js/color-scheme-demo.js"></script>


    <!-- page level custom script -->
    <script src="js/app.js"></script>
    
</body>

</html>
