<html>
<head>
    <meta charset="utf-8"/>
    <title>PRAYATNA - Admin - Approve User DB</title>
	<link rel="stylesheet" href="admin_table.css">
	<link href="https://fonts.googleapis.com/css2?family=Asap+Condensed&display=swap" rel="stylesheet">
	<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@500&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Arizonia&display=swap" rel="stylesheet">
</head>
<body>
<?php
		  use PHPMailer\PHPMailer\PHPMailer;
		  use PHPMailer\PHPMailer\Exception;
    require('db.php');
		require 'PHPMailer-master/src/Exception.php';
		  require 'PHPMailer-master/src/PHPMailer.php';
		  require 'PHPMailer-master/src/SMTP.php';
    session_start();
    // When form submitted, check and create user session.
        // Check user is exist in the database
		//$selectedRow=$_POST['selectdelete'];
		//$query    = "DELETE FROM coord WHERE cid='$selectedRow'";
if(isset($_POST['submitapprove'])){
//echo implode(", ",$selectdelete);
//echo $selectdelete[0];
  if(isset($_POST['selectapprove'])){
	  //echo $selectdelete[0];
    foreach($_POST['selectapprove'] as $approveid){
      //echo "id ".$deleteid." ";
      //$deleteUser = "DELETE from user WHERE userid='$deleteid'";
	  $updateUser = "UPDATE user SET accept=1 WHERE userid='$approveid'";
      $result=mysqli_query($con,$updateUser) or die(mysql_error());
	  
	  //=======================
	  
	  $fetchemail = "SELECT * from user WHERE userid='$approveid'";
	  $result1=mysqli_query($con,$fetchemail) or die(mysql_error());
	  $record1= mysqli_fetch_array($result1);
		  //use PHPMailer\PHPMailer\PHPMailer;
		  //use PHPMailer\PHPMailer\Exception;
		  //require 'PHPMailer-master/src/Exception.php';
		  //require 'PHPMailer-master/src/PHPMailer.php';
		  //require 'PHPMailer-master/src/SMTP.php';

		  $mail = new PHPMailer();
		  $mail->IsSMTP();

		  $mail->SMTPDebug  = 0;  
		  $mail->SMTPAuth   = TRUE;
		  $mail->SMTPSecure = "tls";
		  $mail->Port       = 587;
		  $mail->Host       = "smtp.gmail.com";
		  $mail->Username   = "besandhiya2003@gmail.com";
		  $mail->Password   = "vtbkrjffrnbmpfct";

		  $mail->IsHTML(true);
		  $mail->AddAddress($record1['email'], $record1['uname']);
		  $mail->SetFrom("besandhiya2003@gmail.com", "Prayatna23 Event");
		  $mail->AddCC("sandhiya949@gmail.com", "Sandhiya");
		  $mail->Subject = "Event Registration Accepted Intimation";
		  $content = "<b>Dear ". $record1['uname'] . "\n\n Your registration with Prayatna-23 Event is accepted; Now you can register for events.\n Happy to see in Prayatna Venue.\n\nRegards,\n\nEvent Admin</b>";

		  $mail->MsgHTML($content); 
		  if(!$mail->Send()) {
			echo "Error while sending Email.";
			var_dump($mail);
		  } else {
			echo "Email sent successfully";
		  }
	  //=======================
    }
					header("Location: admin_dashboard.php");

  }
 }
            echo "<div class='admin_login_form'>
                  <h3>No User to Approve</h3><br/>
				  </div>";
?>
<p></p>
<a href="admin_dashboard.php"> <input type = "button" value = "ADMIN DASHBOARD" class="add_button"></a>

</body>
</html>