
<?php
require('db.php');
session_start();
require('fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',22);
$pdf->Cell(100,10,"PRAYATNA'23 - Event Attendance Sign");
$pdf->Ln(10);
$pdf->Cell(100,20,'Event');	

$cmobile=$_SESSION['mobile'];

if(isset($_POST['submitprintattendees'])){
  if(isset($_POST['selectprintattendees'])){
    foreach($_POST['selectprintattendees'] as $eventid){
	  $ecode = stripslashes($eventid);    // removes backslashes
      $ecode = mysqli_real_escape_string($con, $ecode);
	  //**************************************
	  	// Connect to database - here $con
		//$link = mysqli_connect('server','login','password','db');

		// First table: output all columns
		$sql="SELECT * FROM `event` where ecode=left('$eventid',5)";

		
		$width_cell=array(25,55,30,30,30,20);
		$pdf->SetFont('Arial','B',11);
		
		//Background color of header//
		$pdf->SetFillColor(193,229,252);

		//Line Break
		$pdf->Ln(20);
		
		// Header starts /// 
		//First header column //
		$pdf->Cell($width_cell[0],10,'Event Code',1,0,'C',true);
		//Second header column//
		$pdf->Cell($width_cell[1],10,'Event Name',1,0,'C',true);
		//Third header column//
		$pdf->Cell($width_cell[2],10,'Venue',1,0,'C',true); 
		//Fourth header column//
		$pdf->Cell($width_cell[3],10,'Date',1,0,'C',true);
		//Fifth header column//
		$pdf->Cell($width_cell[4],10,'Start Time',1,0,'C',true); 
		//Sixth header column//
		$pdf->Cell($width_cell[5],10,'Duration',1,1,'C',true); 
		//// header ends ///////
		
		$pdf->SetFont('Arial','',11);
		//Background color of header//
		$pdf->SetFillColor(235,236,236); 
		//to give alternate background fill color to rows// 
		$fill=false;


		foreach ($con->query($sql) as $row) {
		$pdf->Cell($width_cell[0],10,$row['ecode'],1,0,'C',$fill);
		$pdf->Cell($width_cell[1],10,$row['ename'],1,0,'C',$fill);
		$pdf->Cell($width_cell[2],10,$row['venue'],1,0,'C',$fill);
		$pdf->Cell($width_cell[3],10,$row['edate'],1,0,'C',$fill);
		$pdf->Cell($width_cell[4],10,$row['stime'],1,0,'C',$fill);
		$pdf->Cell($width_cell[5],10,$row['duration'],1,1,'C',$fill);
		//to give alternate background fill  color to rows//
		$fill = !$fill;
		}

		$pdf->Ln(5);
		$pdf->SetFont('Arial','B',22);		
		$pdf->Cell(100,10,'Attendees are listed below:');	
 
		$width_cell=array(50,20,20,50,25,25);
		$pdf->SetFont('Arial','B',11);
		
		//Background color of header//
		$pdf->SetFillColor(193,229,252);

		$pdf->Ln(10);

		// Header starts /// 
		//First header column //
		$pdf->Cell($width_cell[0],10,'Participant Name',1,0,'C',true);
		//Second header column//
		$pdf->Cell($width_cell[1],10,'Year',1,0,'C',true);
		//Third header column//
		$pdf->Cell($width_cell[2],10,'College',1,0,'C',true); 
		//Fourth header column//
		$pdf->Cell($width_cell[3],10,'Department',1,0,'C',true);
		//Fifth header column//
		$pdf->Cell($width_cell[4],10,'Mobile',1,0,'C',true); 
		$pdf->Cell($width_cell[5],10,'Signature',1,1,'C',true); 
		//// header ends ///////
		
		$pdf->SetFont('Arial','',11);
		//Background color of header//
		$pdf->SetFillColor(235,236,236); 
		//to give alternate background fill color to rows// 
		$fill=false;
		
		$sql1="SELECT * FROM `participant` where ecode=left('$eventid',5)";
		$result1 = mysqli_query($con, $sql1) or die(mysql_error());
        $rows1 = mysqli_num_rows($result1);
		//$mobile=$_SESSION['mobile'];
        if ($rows1 > 0) {
			while($record1 = mysqli_fetch_array($result1))
			{
				$sql2    = "SELECT * FROM `user` WHERE mobile='$record1[umobile]'" ;
				foreach ($con->query($sql2) as $row1) {
				$blank = " ";
				$pdf->Cell($width_cell[0],10,$row1['uname'],1,0,'L',$fill);
				$pdf->Cell($width_cell[1],10,$row1['year'],1,0,'C',$fill);
				$pdf->Cell($width_cell[2],10,substr($row1['college'],20),1,0,'L',$fill);
				$pdf->Cell($width_cell[3],10,substr($row1['dept'],0,22),1,0,'L',$fill);
				$pdf->Cell($width_cell[4],10,$row1['mobile'],1,0,'L',$fill);
				$pdf->Cell($width_cell[5],10,$blank,1,1,'C',$fill);
				//to give alternate background fill  color to rows//
				$fill = !$fill;
				}
			}
		}
				

		$pdf->Output();
		
	  //**************************************

 }
 }
}



$pdf->Output();
?>