<?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=strtoupper($_POST['name']);
$regno=strtoupper($_POST['regno']);
$period=strtoupper($_POST['period']);
$department=strtoupper($_POST['department']);
$batch1=strtoupper($_POST['batch1']);
$batch2=strtoupper($_POST['batch2']);
$date=strtoupper($_POST['date']);
$month=strtoupper($_POST['month']);
$year=strtoupper($_POST['year']);
$blood=strtoupper($_POST['blood']);
$address1=strtoupper($_POST['address1']);
$address2=strtoupper($_POST['address2']);
$address3=strtoupper($_POST['address3']);
$address4=strtoupper($_POST['address4']);
$phone=strtoupper($_POST['phone']);
$ephone=strtoupper($_POST['ephone']);
$hostel=strtoupper($_POST['hostel']);			
}
else
{
$uid=$_SESSION['id'];	
$name=strtoupper($_POST['name']);
$regno=strtoupper($_POST['regno']);
$period=strtoupper($_POST['period']);
$department=strtoupper($_POST['department']);
$batch1=strtoupper($_POST['batch1']);
$batch2=strtoupper($_POST['batch2']);
$date=strtoupper($_POST['date']);
$month=strtoupper($_POST['month']);
$year=strtoupper($_POST['year']);
$blood=strtoupper($_POST['blood']);
$address1=strtoupper($_POST['address1']);
$address2=strtoupper($_POST['address2']);
$address3=strtoupper($_POST['address3']);
$address4=strtoupper($_POST['address4']);
$phone=strtoupper($_POST['phone']);
$ephone=strtoupper($_POST['ephone']);
$hostel=strtoupper($_POST['hostel']);
			 }
$batch="$batch1"."-"."$batch2";
$dob="$date"."."."$month"."."."$year";
$date=date("d/m/Y");
$address= $address1.$address2.$address3.$address4;
//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'];
}

     $errors     = array();
     $maxsize    = 2097152;
     $acceptable = array('image/jpeg', 'image/jpg', 'image/png');
      $file_name = $_FILES['image']['name'];
      $file_size =$_FILES['image']['size'];
      $file_tmp =$_FILES['image']['tmp_name'];
      $file_type=$_FILES['image']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
      $final_file=str_replace($file_name,$phone.".jpg",$file_name);
      //$final_file=str_replace($new_file_name,$phone.".jpg",$new_file_name);
      $extensions= array("jpg","png");
if(move_uploaded_file($file_tmp,"photos/".$final_file))
{	
//Insert Query of SQL
$query="INSERT INTO idform ". "(idNo,userId,userName,userEmail,Name,RegisterNo,Period,Department,Batch,Dob,Blood,Address1,Address2,Address3,Address4,Phone,EmergencyPhone,Hostel,Photo,Date)". " values('1','$uid','$uname','$uemail','$name','$regno','$period','$department','$batch','$dob','$blood','$address1','$address2','$address3','$address4','$phone','$ephone','$hostel','$final_file','$date')";

}
if (mysqli_query($conn , $query)) 
{
    $last_id = mysqli_insert_id($conn);
    $in="ID-" . $last_id;
	$sql1="UPDATE idform SET idNo='$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:14px;
font-weight:bold;
}
	
td {
padding: 5px;
font-size:14px;
}
	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: 20px; padding:5px; margin-top: 15px;">
<p align="center"><img src="avit_logo.jpg"></p>
<hr style="padding: 0 !important; margin: 0 !important; border: 1px solid black;" />
	<p align="center" style="font-size: 18px; margin-bottom: 2px !important; margin-top: 4px !important;"><strong>STUDENT IDENTITY CARD</strong></p>
<p align="left" style="font-size: 14px; margin-bottom: 2px !important; margin-top: 4px !important;">Faculty: <?php echo "$uname"."/ $uemail" ?></p>
<div class="clear" style="clear: both;"></div>
<div width="80%" style="float: left">
<table>
	<tr><th align="left">Name</th><td>:</td><td><?php echo"$name"; ?></td></tr>
	<tr><th align="left">Register No</th><td>:</td><td><?php echo"$regno"; ?></td></tr>
	<tr><th align="left">Batch</th><td>:</td><td><?php echo"$batch"; ?></td></tr>
	<tr><th align="left">Department</th><td>:</td><td><?php echo"$department"." / $period"; ?></td></tr>
	<tr><th align="left">Date of Birth</th><td>:</td><td><?php echo"$dob"; ?></td></tr>
	<tr><th align="left">Blood Group</th><td>:</td><td><?php echo"$blood"; ?></td></tr>
	<tr><th align="left">Communication Address</th><td>:</td><td><?php echo"$address"; ?></td></tr>
	<tr><th align="left">Phone Number</th><td>:</td><td><?php echo"$phone"; ?></td></tr>
	<tr><th align="left">Emergency Contact No</th><td>:</td><td><?php echo"$ephone"; ?></td></tr>
	<tr><th align="left">Hostel/ College Bus/ Day Scholar</th><td>:</td><td><?php echo"$hostel"; ?></td></tr>
	</table>
	</div>
	<div width="18%" style="float: right">
	<p align="right" style="text-align: right; float: right; font-size: 12px;">ID No: <?php echo("$in"); ?></p>
	<p align="right" style="text-align: right; float: right; font-size: 12px;">Date: <?php echo("$date"); ?></p>
		<img src="photos/<?php echo $final_file; ?>" width="120px" height="130px"/>
    </div>
	<div style="margin-top: 30px;" width="100%">
	<div style="float: left; width: 48.3%">
		<p align="center" style="font-size: 14px; padding: 0px; margin: 0px;"><strong>HOD</strong></p>
	</div>
	<div style="float: left; width: 48.3%">
		<p align="center" style="font-size: 14px; padding: 0px; margin: 0px;"><strong>Principal</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');
?> 
