<?php
error_reporting(E_ALL);
//ini_set('display_errors', 1);

include "db-con.php";
include "session.php";
?>


<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Certificate</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
     
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
              
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script> -->
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.2/html2pdf.bundle.js"></script> 

    <link rel="stylesheet" type="text/css" href="https://ais.org.in/digitalcertificate/css/master.css">

   
  </head>

  <body>
      
  <?php  
     
      if (isset($_SESSION['login_email']) && $_SESSION['login_email'] == true) {
        
        $get_user_login = "SELECT email, role FROM admin_user WHERE email = '$sess_userid'";
        $get_result = $con->query($get_user_login);

        while($row = mysqli_fetch_assoc($get_result )){
           $useremail=$row['email'];
           $userrole=$row['role'];
        }
       echo "&nbsp;&nbsp;";
       ?>     
      

<div class="full btnContainer">
  <div class="cerBtns">
    <button id="button" class="genPdf">Generate PDF</button>
    <a href="https://ais.org.in/digitalcertificate/dashboard_participation.php" class="btn btn-md btn-primary">Back to Dashboard</a>
  </div>

    
 
</div>
  <?php 
  	    include "db-con.php"; 

		$member_id = $_GET['id'];

		$sql = "SELECT * FROM `participant` WHERE participant_id='$member_id'";
        $result = $con->query($sql) or die("error");
    
        if ($result->num_rows > 0) {
              while($row = mysqli_fetch_array($result)) {    
              $event_id = $row["event_id"];    
              $trainee_id = $row["trainee_id"];    


          // Event data start	

					$event_Query = "SELECT * FROM `event` WHERE event_id='$event_id'";
			    $event_result = $con->query($event_Query) or die("error");

			    if ($event_result->num_rows > 0) {
          while($row_event = mysqli_fetch_array($event_result)) {    
          $event_name = $row_event["name"];    
          $event_type = $row_event["event_type"];
          $event_location = $row_event["address_one"];
          


 					// Event data end	


          // Trainee data start	

          $trainee_Query = "SELECT * FROM `trainee` WHERE trainee_id='$trainee_id'";
			    $trainee_result = $con->query($trainee_Query) or die("error");

			    if ($trainee_result->num_rows > 0) {
          while($row_trainee = mysqli_fetch_array($trainee_result)) {    
          $trainee_name = $row_trainee["name"]; 
          $trainee_designation = $row_trainee["designation"];  
          $trainee_signature = $row_trainee["signature_name"];  
          $trainee_location = $row_trainee["location"];  
              
 	
 					// Trainee data end	

		?>
<div class="full">
    <div id="makepdf" class="certificateSec" style="text-align: center;">
      <h3>OF PARTICIPATION </h3>
    	<h1><?php echo $row["name"]; ?></h1>
      <?php 
      if($event_type == "Online"){
      ?>
      <p>for successfully attending online webinar on </p>

      <?php
      }else if($event_type == "Offline"){
      ?>  
        <p>for successfully completing the workshop on </p>
      <?php  
      }else{
        //echo "test";
      };

      ?>

<!--     	<p>for successfully completing the workshop on </p> -->
    	<h2>“<?php echo $event_name;?>”</h2>  
    	
      <?php 
      if($event_type == "Online"){
      ?>
       <p>organised by Association of Indian Schools (AIS).</p>

      <?php
      }else if($event_type == "Offline"){
      ?>  
        <p>conducted at <?php echo $event_location; ?></p>

      <?php  
      }else{
        
        //echo "test";
      };


      ?>

    	<p class="date">Date : <?php echo $row_event["date"]; ?> | Time: <?php echo $row_event["start_time"]; ?> to <?php echo $row_event["end_time"]; ?> </p>
    
        <div class="signature"><!----signature start-->
        	<div class="col_sig chairmanSign">
            <div class="signbox">
          		<img src="https://ais.org.in/digitalcertificate/images/vispi_sir_signature.png">
            </div>
        		<p>VISPI VESUNA 
        		<span>Chairman</span>	
        		</p>
        
        	</div>
        	<div class="col_sig traineeSign">
            <div class="signbox">
        	     <img src="https://ais.org.in/digitalcertificate/images/signature/<?php echo $trainee_signature; ?>">
            </div>
        		<p> <?php echo $trainee_name; ?>
        		<span><?php echo $trainee_designation; ?><br>       
            <?php echo $trainee_location; ?> 
            </span>	
        		</p>
        
        	</div>
        </div><!----signature end-->
 

    </div><!----pdf end-->

</div>




	<script>
	        let button = document.getElementById("button");
	        let makepdf = document.getElementById("makepdf");
	        var opt = {
			  margin:       0.1,
			  filename:     '<?php echo $row["name"]; ?>.pdf',
			  image:        { type: 'jpeg', quality: 0.98 },
			  html2canvas:  { scale: 2 },
			  jsPDF:        { unit: 'in', format: 'A4', orientation: 'Landscape' }
			};
	 
	        button.addEventListener("click", function () {
	      //   	 $html2pdf = new HTML2PDF('L', 'A4', 'en');
			    // $html2pdf->setDefaultFont('Arial');
			    // $html2pdf->writeHTML($html, false);
			    // $html2pdf->Output('output.pdf', 'D');
	        	// $html2pdf = new HTML2PDF('L', 'A4', 'en');
	            html2pdf().set(opt).from(makepdf).save();
	        });
	 </script>

   
<?php
 }

 }//trainee close
 }

 }//event close

 }

 }//participation close
 $con->close();   

?>


<div class="row">
<?php
} else {

echo "data 0 results";
?>
<a href="https://ais.org.in/digitalcertificate/">Back to login</a>                     
<?php
//   header("Location: https://ais.org.in/digitalcertificate/admin_login.php");

}
?>    
</div>   


  </body>
</html>
