<?php
include('includes/session.php');
include('includes/config.php');
date_default_timezone_set('Asia/Kolkata'); 
if(isset($_POST['submit']))
{
$servername = "localhost";
$username = "avitac_user26";
$password = "h5*4ge2HToIK";
$dbname = "avitac_cms";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
if(! get_magic_quotes_gpc())
{	
$uid=$_SESSION['id'];
$name=$_POST['name'];
$designation=$_POST['designation'];
$department=$_POST['department'];
$eventname=$_POST['eventname'];
$eventdate=$_POST['eventdate'];
$eventtime=$_POST['eventtime'];
$details=$_POST['details'];
$rdate=$_POST['rdate'];		
}
else
{
$uid=$_SESSION['id'];
$name=$_POST['name'];
$designation=$_POST['designation'];
$department=$_POST['department'];
$eventname=$_POST['eventname'];
$eventdate=$_POST['eventdate'];
$eventtime=$_POST['eventtime'];
$details=$_POST['details'];
$rdate=$_POST['rdate'];	
			 }
$date=date("d/m/Y");
$dateindia = date("d/m/Y h:i:s");
	//SELECT
$query1= "SELECT * from users WHERE id='$uid'";
$result= mysqli_query($conn,$query1);
while($row = mysqli_fetch_array($result))
{
	$uname= $row['fullName'];
	$uemail= $row['userEmail'];
}
//Insert Query of SQL
$query="INSERT INTO eventform ". "(EventNo,userId,userName,userEmail,Name,Designation,Department,EventName,EventDate,EventTime,RequestingDetails,RequestingDate,Date)". " values('1','$uid','$uname','$uemail','$name','$designation','$department','$eventname','$eventdate','$eventtime','$details','$rdate','$date')";
if (mysqli_query($conn , $query)) 
{
    $last_id = mysqli_insert_id($conn);
    $in="E-" . $last_id;
	$sql1="UPDATE eventform SET EventNo='$in' WHERE id='$last_id'";
	$retval=mysqli_query($conn, $sql1);

			}
}
	
//create html of the data
ob_start();
?>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th {
text-align: center;
padding: 5px;
font-size:15px;
font-weight:bold;
}
	
td {
padding: 5px;
font-size:15px;
}
	h1, h2, h3, h4, h5, h6, td, th, table, p, ul, li, label 
{
	font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", Monaco, "Courier New", "monospace";
}
</style>
<div style="margin: 40px; padding:10px; margin-top: 15px;">
<p align="center"><img src="avit_logo.jpg"></p>
<hr style="border: 1px solid black;" />
<p align="center" style="font-size: 18px; margin-bottom: 2px !important; margin-top: 4px !important;"><strong>EVENT APPROVAL FORM</strong></p>
<div class="clear" style="clear: both;"></div>
<p align="right" style="font-size: 14px; margin-bottom: 2px !important; margin-top: 4px !important;">Faculty: <?php echo "$uname"."/ $uemail" ?></p>
<p align="right" style="text-align: right; float: right; font-size: 15px;">Event No:<?php echo("$in"); ?>&nbsp;/ Date: <?php echo("$dateindia"); ?></p>
<div width="100%" style="float: left">
<table>
	<tr><th align="left">Name</th><td>:</td><td><?php echo"$name"; ?></td></tr>
	<tr><th align="left">Designation</th><td>:</td><td><?php echo"$designation"; ?></td></tr>
	<tr><th align="left">Department</th><td>:</td><td><?php echo"$department"; ?></td></tr>
	<tr><th align="left">Event Name</th><td>:</td><td><?php echo"$eventname"; ?></td></tr>
	<tr><th align="left">Event Date & Time</th><td>:</td><td><?php echo"$eventdate"; ?></td></tr>
	<tr><th align="left">Requesting Details</th><td>:</td><td><?php echo"$details"; ?></td></tr>
	<tr><th align="left">Requesting Date & Time</th><td>:</td><td><?php echo"$rdate"; ?></td></tr>
	</table>
	</div>
	<div style="margin-top: 70px;" width="100%">
	<div style="float: left; width: 33.3%">
		<p align="center" style="font-size: 14px; padding: 0px; margin: 0px;"><strong>HOD</strong></p>
	</div>
	<div style="float: left; width: 33.3%">
		<p align="center" style="font-size: 14px; padding: 0px; margin: 0px;"><strong>Principal</strong></p>
	</div>
	<div style="float: left; width: 33.3%">
		<p align="center" style="font-size: 14px; padding: 0px; margin: 0px;"><strong>Facility Manager</strong></p>
	</div>
	<hr style="border: 1px dashed #000000;"/>
</div>
</div>

        <?php 
        $body = ob_get_clean();

        $body = iconv("UTF-8","UTF-8//IGNORE",$body);

        include("../mpdf/mpdf.php");
        $mpdf=new \mPDF('c','A4','','' , 0, 0, 0, 0, 0, 0); 

        //write html to PDF
        $mpdf->WriteHTML($body);
 
        //output pdf
        $mpdf->Output($in.'.pdf','D');
?> 
