Viewing file: generate_certificate.php (9.09 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<!DOCTYPE html> <html lang="en">
<?php include 'head.php';?>
<body>
<!-- ======= Header ======= --> <?php include 'menubar.php';?>
<?php include 'sidebar.php';?>
<main id="main" class="main">
<div class="pagetitle"> <h1>Dashboard</h1> <nav> <ol class="breadcrumb"> <li class="breadcrumb-item"><a href="index.html">Home</a></li> <li class="breadcrumb-item active">Dashboard</li> </ol> </nav> </div><!-- End Page Title --> <section class="section dashboard">
<?php include 'connect.php';
$sql = "SELECT * FROM certificate ORDER BY ID DESC";
if ($result = mysqli_query($link, $sql)) { $output = ""; $sr = 0;
$output .= "<style> table { width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; margin-top: 20px; } th, td { border: 1px solid #ccc; padding: 10px; text-align: center; } th { background-color: #004080; color: white; } tr:nth-child(even) { background-color: #f9f9f9; } tr:hover { background-color: #eef; } img.student-photo { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; border: 2px solid #ccc; } .btn-link { color: #0066cc; text-decoration: none; font-weight: bold; } .btn-link:hover { text-decoration: underline; } .edit-btn, .delete-btn { padding: 5px 10px; border-radius: 4px; border: none; cursor: pointer; color: white; } .edit-btn { background-color: #007bff; } .edit-btn:hover { background-color: #0056b3; } .delete-btn { background-color: #dc3545; } .delete-btn:hover { background-color: #a71d2a; } .modal-photo { width: 100px; height: 100px; object-fit: cover; border-radius: 8px; display: block; margin-bottom: 15px; } </style>";
// Search Filter $output .= ' <div style="text-align:center; margin-top:20px;"> <input type="text" id="filterInput" onkeyup="filterTable()" placeholder="Search by Name, Enrollment, or Course" style="padding:10px; width:300px; border-radius:6px; border:1px solid #ccc;"> </div>';
// Edit Modal $output .= ' <div id="editModal" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background-color:rgba(0,0,0,0.6); z-index:999;"> <div style="background:#fff; max-width:500px; margin:5% auto; padding:20px; border-radius:8px; position:relative;"> <h3>Edit Certificate Details</h3> <form id="editForm" action="update_certificate.php" method="post" enctype="multipart/form-data"> <img id="editPhotoPreview" class="modal-photo" src="" alt="Student Photo"> <input type="hidden" name="enrollment" id="editEnrollment">
<label for="editPhoto">Change Photo (optional):</label> <input type="file" name="photo" id="editPhoto" accept="image/*" style="margin-bottom:15px;"><br>
<label for="editName">Name:</label> <input type="text" name="name" id="editName" required style="width:100%; padding:8px; margin-bottom:10px;">
<label for="editCourse">Course:</label> <input type="text" name="course" id="editCourse" required style="width:100%; padding:8px; margin-bottom:10px;">
<label for="editCertificateNo">Certificate No:</label> <input type="text" name="certificate_no" id="editCertificateNo" required style="width:100%; padding:8px; margin-bottom:10px;">
<label for="editIssueDate">Issue Date:</label> <input type="date" name="issue_date" id="editIssueDate" required style="width:100%; padding:8px; margin-bottom:10px;">
<div style="margin-top:15px;"> <button type="submit" style="padding:8px 16px;">Update</button> <button type="button" onclick="closeEditModal()">Cancel</button> </div> </form> </div> </div>';
$output .= "<h2 style='text-align:center;'>Issued Certificates</h2>"; $output .= "<table id='certTable'>"; $output .= "<tr> <th>Serial</th> <th>Photo</th> <th>Roll/Reg No</th> <th>Certificate No</th> <th>Name</th> <th>Course</th> <th>Issue Date</th> <th>Print</th> <th>Edit</th> <th>Delete</th> </tr>";
while ($row = mysqli_fetch_array($result)) { $certi_no = $row['CertificateNo']; if ($certi_no !== 'Not_Alloted') { $sr++; $photo = $row['photo']; $photoUrl = 'http://itce.co.in/data/files/' . str_replace(' ', '%20', $photo); $enroll = htmlspecialchars($row['enrollment'], ENT_QUOTES); $name = htmlspecialchars($row['Name'], ENT_QUOTES); $course = htmlspecialchars($row['Course'], ENT_QUOTES); $certNo = htmlspecialchars($row['CertificateNo'], ENT_QUOTES); $issueDate = htmlspecialchars($row['certifcate_issue_date'], ENT_QUOTES); $ids=$row['ID'];
$output .= "<tr> <td>$sr</td> <td><img src='$photoUrl' class='student-photo'></td> <td>$enroll</td> <td>$certNo</td> <td>$name</td> <td>$course</td> <td>$issueDate</td> <td><a class='btn-link' href='certificateprint.php?ID=$certNo' target='_blank'>Print</a></td> <td> <button class='edit-btn' onclick='openModal(this)' data-enrollment='$enroll' data-name=\"$name\" data-course=\"$course\" data-certno=\"$certNo\" data-issuedate=\"$issueDate\" data-photo=\"$photoUrl\" >Edit</button> </td> <td> <button class='delete-btn' onclick='deleteCertificate(\"$ids\")'>Delete</button> </td> </tr>"; } }
$output .= "</table>"; echo $output;
mysqli_free_result($result); } else { echo "<p style='color:red; text-align:center;'>Database error: " . mysqli_error($link) . "</p>"; }
mysqli_close($link); ?>
<!-- JavaScript --> <script> function openModal(button) { const enrollment = button.getAttribute("data-enrollment"); const name = button.getAttribute("data-name"); const course = button.getAttribute("data-course"); const certNo = button.getAttribute("data-certno"); const issueDate = button.getAttribute("data-issuedate"); const photo = button.getAttribute("data-photo");
document.getElementById("editEnrollment").value = enrollment; document.getElementById("editName").value = name; document.getElementById("editCourse").value = course; document.getElementById("editCertificateNo").value = certNo; document.getElementById("editIssueDate").value = issueDate; document.getElementById("editPhotoPreview").src = photo;
document.getElementById("editModal").style.display = "block"; }
function closeEditModal() { document.getElementById("editModal").style.display = "none"; }
window.onclick = function(event) { const modal = document.getElementById("editModal"); if (event.target === modal) { closeEditModal(); } };
function filterTable() { const input = document.getElementById("filterInput").value.toLowerCase(); const rows = document.querySelectorAll("#certTable tr");
rows.forEach((row, index) => { if (index === 0) return; // Skip header const cols = row.getElementsByTagName("td"); const enroll = cols[2].textContent.toLowerCase(); const name = cols[4].textContent.toLowerCase(); const course = cols[5].textContent.toLowerCase();
if (enroll.includes(input) || name.includes(input) || course.includes(input)) { row.style.display = ""; } else { row.style.display = "none"; } }); }
function deleteCertificate(enrollment) { if (confirm("Are you sure you want to delete this certificate?")) { window.location.href = "delete_certificate.php?enrollment=" + encodeURIComponent(enrollment); } } </script>
</section>
</main><!-- End #main -->
<?php include 'footer.php';?>
</body>
</html>
|