<!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>SRMS Admin Edit Student</title>
    <!-- Include necessary stylesheets -->
    <link rel="stylesheet" href="css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" href="css/font-awesome.min.css" media="screen">
    <link rel="stylesheet" href="css/animate-css/animate.min.css" media="screen">
    <link rel="stylesheet" href="css/lobipanel/lobipanel.min.css" media="screen">
    <link rel="stylesheet" href="css/prism/prism.css" media="screen">
    <link rel="stylesheet" href="css/select2/select2.min.css">
    <link rel="stylesheet" href="css/main.css" media="screen">
    <link rel="stylesheet" href="css/admitcard.css" media="screen">
    <script src="js/sweetalret.js"></script>
    <style>
 
        /* Additional styling for the "Print All Admit Cards" button */
        .print-btn {
            position: fixed;
            bottom: 20px;
            right: 20px;
        }

        
    </style>
</head>

<body class="top-navbar-fixed">
   
    <div class="main-wrapper">
        <!-- ========== TOP NAVBAR ========== -->
        <?php include('includes/topbar.php'); ?>
        <!-- ========== WRAPPER FOR BOTH SIDEBARS & MAIN CONTENT ========== -->
        <div class="content-wrapper">
            <div class="content-container">
                <?php include('includes/leftbar.php'); ?>
                <div class="main-page">
                    <div class="container-fluid">
                        <div class="row page-title-div">
                            <div class="col-md-6">
                                <h2 class="title">Edit Student</h2>
                            </div>
                        </div>
                        <div class="row breadcrumb-div">
                            <div class="col-md-6">
                                <ul class="breadcrumb">
                                    <li><a href="dashboard.php"><i class="fa fa-home"></i> Home</a></li>
                                    <li> Student</li>
                                    <li class="">Edit Student</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <section class="section">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="panel">
                                        <div class="panel-heading">
                                            <div class="panel-title">
                                                <h5>Edit Student</h5>
                                            </div>
                                        </div>
                                        <div class="panel-body">



    <?php include('includes/db.php'); 

        // Check if student_id is provided in the query parameters
        if (isset($_GET['student_id'])) {
            $studentId = $_GET['student_id'];

            // Fetch existing student details from the database
            $query = "SELECT * FROM students WHERE student_id = $studentId";
            $result = $conn->query($query);

            if ($result->num_rows > 0) {
                $studentDetails = $result->fetch_assoc();

                // Check if a picture already exists for the student
                $picturePath = "uploads/" . $studentDetails['photo'];
                $existingPicture = file_exists($picturePath);
        ?>

                <form action="process_edit_student.php" method="post" enctype="multipart/form-data">
                    <input type="hidden" name="student_id" value="<?php echo $studentDetails['student_id']; ?>">

                    <div class="form-row">
                        <div class="form-group col-md-3">
                            <label for="regd_id">Registration ID:[Iemis]</label>
                            <input type="text" id="regd_id" name="regd_id" value="<?php echo $studentDetails['regd_id']; ?>" class="form-control" required>
                        </div>
                        <div class="form-group col-md-3">
                            <label for="regd_id">Symbol No:</label>
                            <input type="text" id="symbol_no" name="symbol_no" value="<?php echo $studentDetails['symbol_no']; ?>" class="form-control" required>
                        </div>
                         <div class="form-group col-md-3">
                            <label for="name">Name:</label>
                            <input type="text" id="name" name="name" value="<?php echo $studentDetails['name']; ?>" class="form-control" required>
                        </div>

                        <div class="form-group col-md-3">
                            <label for="dob">Date of Birth:</label>
                            <input type="date" id="dob" name="dob" value="<?php echo $studentDetails['dob']; ?>" class="form-control" required>
                        </div>

                        <div class="form-group col-md-3">
                            <label for="gender">Gender:</label>
                            <select id="gender" name="gender" class="form-control" required>
                                <option value="Male" <?php if ($studentDetails['gender'] == 'Male') echo 'selected'; ?>>MALE</option>
                                <option value="Female" <?php if ($studentDetails['gender'] == 'Female') echo 'selected'; ?>>FEMALE</option>
                                <option value="Others" <?php if ($studentDetails['gender'] == 'Others') echo 'selected'; ?>>OTHERS</option>
                            </select>
                        </div>

                        <div class="form-group col-md-3">
                            <label for="group">Ethnic Group:</label>
                            <select id="group" name="group" class="form-control"  required>
                               
                                <?php
                                // Fetch group options from the 'ent_group' table
                                $query_group = "SELECT * FROM ent_group";
                                $result_group = $conn->query($query_group);

                                // Populate the dropdown with group options
                                while ($row_group = $result_group->fetch_assoc()) {
                                    echo "<option value='" . $row_group['id'] . "'";
                                    if ($studentDetails['std_group'] == $row_group['id']) echo 'selected';
                                    echo ">" . $row_group['group_name'] . "</option>";
                                }
                                ?>
                            </select>
                        </div>

                        <div class="form-group col-md-3">
                            <label for="address">Address:</label>
                            <input type="text" id="address" name="address" value="<?php echo $studentDetails['address']; ?>" class="form-control" required>
                        </div>

                        <div class="form-group col-md-3">
                            <label for="phone">Phone:</label>
                            <input type="text" id="phone" name="phone" value="<?php echo $studentDetails['phone']; ?>" class="form-control" required>
                        </div>

                        <div class="form-group col-md-3">
                            <label for="email">Email:</label>
                            <input type="email" id="email" name="email" value="<?php echo $studentDetails['email']; ?>" class="form-control" required>
                        </div>

                        <div class="form-group col-md-3">
                            <label for="parent_name">Parent Name:</label>
                            <input type="text" id="parent_name" name="parent_name" value="<?php echo $studentDetails['parent_name']; ?>" class="form-control" required>
                        </div>

                        <div class="form-group col-md-3">
                            <label for="parent_phone">Parent Phone:</label>
                            <input type="text" id="parent_phone" name="parent_phone" value="<?php echo $studentDetails['parent_phone']; ?>" class="form-control" required>
                        </div>

                        <input type="hidden" id="class" name="class" value="<?php echo $studentDetails['class']; ?>" class="form-control" readonly>

                        <div class="form-group col-md-3">
                            <label for="studentClass">Class:</label>
                            <select id="studentClass" name="studentClass" class="form-control" required>
                                <option value="">Select Class</option>
                                <?php
                                // Fetch class names from the 'classes' table
                                $query_class = "SELECT class_id, class_name, section FROM classes";
                                $result_class = $conn->query($query_class);

                                // Populate the dropdown with class names and sections
                                while ($row_class = $result_class->fetch_assoc()) {
                                    echo "<option value='" . $row_class['class_id'] . "'";
                                    if ($studentDetails['Class_id'] == $row_class['class_id']) echo 'selected';
                                    echo ">" . $row_class['class_name'] . " - " . $row_class['section'] . "</option>";
                                }
                                ?>
                            </select>
                        </div>

                        <input type="hidden" id="Class_id" name="Class_id" value="<?php echo $studentDetails['Class_id']; ?>" class="form-control" required>
                    </div>


                        <div class="form-group col-md-3">
                            <label for="photo">Student Photo:</label>
                            <?php if ($existingPicture) : ?>
                                <input type="hidden" name="existing_photo" value="<?php echo $studentDetails['photo']; ?>">
                                <input type="file" id="photo" name="photo" class="form-control">
                                Existing Photo
                                <!-- Display existing picture if available -->
                                <img src="<?php echo $picturePath; ?>" alt="Student Photo" style="width:80px; height:80px" class="existing-photo">
                                
                            <?php endif; ?>
                            
                        </div>
                    </div>

                    <div class="form-group">
                        <button class="btn btn-primary" type="submit">Update</button>
                    </div>
                </form>

        <?php
            } else {
                echo "Student not found.";
            }
        } else {
            echo "Student ID not provided.";
        }
        ?>
</div>
              <!-- Include necessary scripts -->
                                            <script src="js/jquery/jquery-2.2.4.min.js"></script>
                                            <script src="js/bootstrap/bootstrap.min.js"></script>
                                            <script src="js/pace/pace.min.js"></script>
                                            <script src="js/lobipanel/lobipanel.min.js"></script>
                                            <script src="js/iscroll/iscroll.js"></script>
                                            <script src="js/prism/prism.js"></script>
                                            <script src="js/waypoint/waypoints.min.js"></script>
                                            <script src="js/counterUp/jquery.counterup.min.js"></script>
                                            <script src="js/toastr/toastr.min.js"></script>
                                            <script src="js/icheck/icheck.min.js"></script>
                                            <script src="js/main.js"></script>
                                            <script src="js/production-chart.js"></script>
                                            <script src="js/traffic-chart.js"></script>
                                            <script src="js/task-list.js"></script>
                                           

                       </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </div>
    </div>

</body>

</html>

