-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_booking_pdf.php
More file actions
84 lines (65 loc) · 2.28 KB
/
generate_booking_pdf.php
File metadata and controls
84 lines (65 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "university_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
require_once __DIR__ . '/room_booking_functions.php';
require_once __DIR__ . '/fpdf/fpdf.php';
if (!isset($_GET['id'])) {
die('Missing booking id');
}
$booking_id = (int)$_GET['id'];
$booking = rb_get_booking($conn, $booking_id);
if (!$booking) {
die('Booking not found');
}
$user_type = isset($_SESSION['user_type']) ? $_SESSION['user_type'] : '';
$user_id = isset($_SESSION['user_id']) ? (int)$_SESSION['user_id'] : 0;
if ($user_type === 'faculty' && $booking['faculty_id'] !== $user_id) {
die('Access denied');
}
class BookingPDF extends FPDF
{
}
$pdf = new BookingPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(0, 10, 'Room Booking Request', 0, 1, 'C');
$pdf->Ln(5);
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(50, 8, 'Faculty Name:', 0, 0);
$pdf->Cell(0, 8, $booking['first_name'] . ' ' . $booking['last_name'], 0, 1);
$pdf->Cell(50, 8, 'Department:', 0, 0);
$pdf->Cell(0, 8, $booking['department_name'] ? $booking['department_name'] : 'N/A', 0, 1);
$pdf->Cell(50, 8, 'Room:', 0, 0);
$pdf->Cell(0, 8, $booking['room_name'], 0, 1);
$pdf->Cell(50, 8, 'Location:', 0, 0);
$pdf->Cell(0, 8, $booking['location'], 0, 1);
$pdf->Cell(50, 8, 'Date:', 0, 0);
$pdf->Cell(0, 8, $booking['booking_date'], 0, 1);
$pdf->Cell(50, 8, 'Time Slot:', 0, 0);
$pdf->Cell(0, 8, $booking['time_slot'], 0, 1);
$pdf->Cell(50, 8, 'Event Title:', 0, 0);
$pdf->Cell(0, 8, $booking['event_title'], 0, 1);
$pdf->Cell(50, 8, 'Number of Persons:', 0, 0);
$pdf->Cell(0, 8, (string)$booking['num_persons'], 0, 1);
$pdf->Cell(50, 8, 'Status:', 0, 0);
$pdf->Cell(0, 8, $booking['status'], 0, 1);
$dir = __DIR__ . '/uploads/booking_pdfs';
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$file_name = 'booking_' . $booking_id . '.pdf';
$file_path = $dir . '/' . $file_name;
$file_url = 'uploads/booking_pdfs/' . $file_name;
$pdf->Output('F', $file_path);
rb_set_booking_pdf_path($conn, $booking_id, $file_url);
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="' . $file_name . '"');
readfile($file_path);
exit;