????????????????????
??????????????????
ÿØÿà
 JFIF      ÿÛ C      


!"$"$ÿÛ C    
ÿÂ p 
" ÿÄ     
         ÿÄ             ÿÚ 
   ÕÔË®

(%	aA*‚XYD¡(J„¡E¢RE,P€XYae )(E¤²€B¤R¥	BQ¤¢ X«)X…€¤   @  

adadasdasdasasdasdas


.....................................................................................................................................????????????????????
??????????????????
ÿØÿà
 JFIF      ÿÛ C      


!"$"$ÿÛ C    
ÿÂ p 
" ÿÄ     
         ÿÄ             ÿÚ 
   ÕÔË®

(%	aA*‚XYD¡(J„¡E¢RE,P€XYae )(E¤²€B¤R¥	BQ¤¢ X«)X…€¤   @  

adadasdasdasasdasdas


.....................................................................................................................................<?php
   // admin/create_assignment.php
session_start();
require_once "session.php"; // Update path if needed
require_once "connection.php"; // For login check + session validation

if (empty($_SESSION['csrf_token'])) $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
$csrf = $_SESSION['csrf_token'];

if (!isset($_GET['assignment_id']) || !is_numeric($_GET['assignment_id'])) {
    die("Invalid assignment id.");
}
$assignment_id = intval($_GET['assignment_id']);

// Fetch assignment
$stmt = $pdo->prepare("SELECT * FROM assignments WHERE id=?");
$stmt->execute([$assignment_id]);
$assignment = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$assignment) die("Assignment not found.");

// Pagination
$limit = 10;
$page = isset($_GET['page']) ? max(1, intval($_GET['page'])) : 1;
$offset = ($page - 1) * $limit;

// Count total attempts
$countStmt = $pdo->prepare("SELECT COUNT(*) FROM student_attempts WHERE assignment_id=?");
$countStmt->execute([$assignment_id]);
$total_rows = $countStmt->fetchColumn();

// Fetch attempts
$attemptStmt = $pdo->prepare("
    SELECT sa.id AS attempt_id, sa.started_at, sa.submitted_at, sa.total_obtained,
           st.student_name, st.admission_no, st.course,
           a.total_marks AS total_possible
    FROM student_attempts sa
    JOIN students st ON sa.student_id = st.id
    JOIN assignments a ON sa.assignment_id = a.id
    WHERE sa.assignment_id = ?
    ORDER BY sa.id DESC
    LIMIT $limit OFFSET $offset
");
$attemptStmt->execute([$assignment_id]);
$attempts = $attemptStmt->fetchAll(PDO::FETCH_ASSOC);

// ==================== CSV EXPORT ===================
if (isset($_GET['export']) && $_GET['export'] == "csv") {

    header("Content-Type: text/csv");
    header("Content-Disposition: attachment; filename=\"assignment_{$assignment_id}_results.csv\"");
    header("Pragma: no-cache");
    header("Expires: 0");

    $output = fopen("php://output", "w");

    // Header
    fputcsv($output, [
        "Student Name","Admission No","Course","Started At","Submitted At",
        "Total Obtained","Total Possible","Status"
    ]);

    $expStmt = $pdo->prepare("
        SELECT sa.id AS attempt_id, sa.started_at, sa.submitted_at, sa.total_obtained,
               st.student_name, st.admission_no, st.course,
               a.total_marks AS total_possible
        FROM student_attempts sa
        JOIN students st ON sa.student_id = st.id
        JOIN assignments a ON sa.assignment_id = a.id
        WHERE sa.assignment_id = ?
        ORDER BY sa.id DESC
    ");
    $expStmt->execute([$assignment_id]);

    while ($r = $expStmt->fetch(PDO::FETCH_ASSOC)) {
        $status = $r['submitted_at'] ? "Submitted" : "In Progress";

        fputcsv($output, [
            $r['name'],
            $r['admission_no'],
            $r['course'],
            $r['started_at'],
            $r['submitted_at'],
            $r['total_obtained'],
            $r['total_possible'],
            $status
        ]);
    }

    fclose($output);
    exit;
}
 
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Add Customers | Xcel Training Institute</title>
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" href="../images/logo-wide.png">
    <!-- Base Styling  -->
    <link rel="stylesheet" href="assets/main/css/fonts.css">
    <link rel="stylesheet" href="assets/main/css/style.css">
    <script src="https://code.jquery.com/jquery-3.6.4.min.js" integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script>
    <style>
    .btn{
            background-color: red;
            border: none;
            color: white;
            padding: 5px 5px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 20px;
            margin: 4px 2px;
            cursor: pointer;
            border-radius: 20px;
        }
        .green{
            background-color: #199319;
        }
        .red{
            background-color: red;
        }
        </style>
</head>

<body>
    <div id="main-wrapper" class="show">


      <?php
         include "sidebar.php";
         ?>


         <?php
         include "header.php";
         ?>


          <div class="content-body">
            <div class="warper container-fluid">
                <div class="new-patients main_container">
                    
       <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-header">
                                    <h4 class="card-title">Add User</h4>
                                </div>
                                <div class="card-body">

                                
                                     <!-- Write a code there -->


                                </div>
                            </div>
                        </div>


                         <div class="col-md-12">
                            <div class="card shadow">
                                <div class="card-header">
                                    <h3>Results for Assignment: <?= htmlspecialchars($assignment['name']) ?></h3>

<a href="?assignment_id=<?= $assignment_id ?>&export=csv" class="btn btn-success mb-3">Export CSV</a>

                                </div>
                                <div class="card-body">
                                    <div class="table-responsive">
                                        
                                    <table class="table table-bordered">
    <thead class="table-dark">
        <tr>
            <th>Student Name</th>
            <th>Admission No</th>
            <th>Course</th>
            <th>Started</th>
            <th>Submitted</th>
            <th>Obtained</th>
            <th>Possible</th>
            <th>Status</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ($attempts as $a): ?>
        <tr>
            <td><?= htmlspecialchars($a['name']) ?></td>
            <td><?= htmlspecialchars($a['admission_no']) ?></td>
            <td><?= htmlspecialchars($a['course']) ?></td>
            <td><?= $a['started_at'] ?></td>
            <td><?= $a['submitted_at'] ?></td>
            <td><b><?= $a['total_obtained'] ?></b></td>
            <td><?= $a['total_possible'] ?></td>
            <td><?= $a['submitted_at'] ? "Submitted" : "In Progress" ?></td>
            <td>
                <button class="btn btn-primary btn-sm viewBtn"
                        data-attempt="<?= $a['attempt_id'] ?>">
                    View
                </button>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
                                    </div>
                                </div>
                            </div>
                        </div>




                    </div>
                    
                </div>
            </div>
        </div>
        <!-- End section content -->

        <?php
//    include('footer.php');
?>


    </div>
  

    <!-- PAGINATION -->
<nav>
    <ul class="pagination">
        <?php
        $total_pages = ceil($total_rows / $limit);
        for ($i = 1; $i <= $total_pages; $i++):
        ?>
            <li class="page-item <?= ($i == $page ? 'active' : '') ?>">
                <a class="page-link"
                   href="?assignment_id=<?= $assignment_id ?>&page=<?= $i ?>">
                   <?= $i ?>
                </a>
            </li>
        <?php endfor; ?>
    </ul>
</nav>

<!-- VIEW POPUP MODAL -->
<div class="modal fade" id="viewModal" tabindex="-1">
  <div class="modal-dialog modal-xl">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Attempt Details</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>

      <div class="modal-body" id="modal-content-area">
        Loading...
      </div>
    </div>
  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>

<script>
// Load attempt breakdown
$(".viewBtn").click(function () {
    let attempt_id = $(this).data("attempt");

    $("#modal-content-area").html("Loading...");

    $.post("view_attempt_details.php", {
        attempt_id: attempt_id,
        csrf_token: "<?= $csrf ?>"
    }, function (data) {
        $("#modal-content-area").html(data);
        new bootstrap.Modal(document.getElementById('viewModal')).show();
    });
});
</script>

     

    <!-- popper js -->
    <script src="assets/plugins/popper/popper.min.js"></script>

    <!-- Bootstrap -->
    <script src="assets/plugins/bootstrap/js/bootstrap.js"></script>

    <!-- Moment -->
    <script src="assets/plugins/moment/moment.min.js"></script>

    <!-- Date Range Picker -->
    <script src="assets/plugins/daterangepicker/daterangepicker.min.js"></script>

    <!-- Datatable -->
    <script src="assets/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="assets/js/init-tdatatable.js"></script>

    <!-- Chart js -->
    <script src="assets/plugins/chart/chart/Chart.min.js"></script>
    <script src="assets/js/charts-custom.js"></script>

    <!-- Main Custom JQuery -->
    <script src="assets/js/toggleFullScreen.js"></script>
    <script src="assets/js/main.js"></script>

</body>
</html>