<?php
include('session_validator.php');
?>
<!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>SMS Admin Subject Creation</title>
    <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">
    <script src="js/modernizr/modernizr.min.js"></script>
</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">
                <!-- ========== LEFT SIDEBAR ========== -->
                <?php include('includes/leftbar.php'); ?>
                <!-- /.left-sidebar -->

                <div class="main-page">
                    <div class="container-fluid">
                        <div class="row page-title-div">
                            <div class="col-md-6">
                                <h2 class="title">Subject Creation</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> Subjects </li>
                                    <li class="active">Create Subject</li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <div class="container-fluid">
                        <div class="row">
                            <!-- Form to enter subject data -->

                            <div class="col-md-6">
                                <div class="panel">
                                    <div class="panel-heading">
                                        <div class="panel-title">
                                            <h5>Create Subject</h5>
                                        </div>
                                    </div>
                                    <div class="panel-body">
                                        <!-- Your form goes here -->
                                        <form method="POST" action="process_subject.php">
                                          
            <div class="form-group">
                <label for="subjectCode">Subject Code:</label>
                <input type="text" id="subjectCode" name="subjectCode" class="form-control"style="width: 300px;" required > 

                <label for="subjectName">Subject Name:</label>
                <input type="text" id="subjectName" name="subjectName" class="form-control" style="width: 300px;" required>

                        <label for="theory_full_marks">Theory Full Marks:</label>
        <input type="number" step="0.01" id="theory_full_marks" name="theory_full_marks" class="form-control" style="width: 300px;" required>

        <label for="internal_full_marks">Internal Full Marks:</label>
        <input type="number" step="0.01" id="internal_full_marks" name="internal_full_marks" class="form-control" style="width: 300px;" required>

        <label for="theory_credit_hour">Theory Credit Hour:</label>
        <input type="number" step="0.01" id="theory_credit_hour" name="theory_credit_hour" class="form-control" style="width: 300px;" required>

        <label for="internal_credit_hour">Internal Credit Hour:</label>
        <input type="number" step="0.01" id="internal_credit_hour" name="internal_credit_hour" class="form-control" style="width: 300px;" required>
            </div>
            <button type="submit" class="btn btn-primary">Add Subject</button>
        </form>
                    </div>
                        </div>
                            </div>

                            <!-- Table to display saved subjects -->
                            <div class="col-md-6">
                                <div class="panel">
                                    <div class="panel-heading">
                                        <div class="panel-title">
                                            <h5>Subjects List</h5>
                                        </div>
                                    </div>
                                    <div class="panel-body">
                                        <!-- Your table goes here -->
                                        <table id="subjectsTable" class="display">
                                            <thead>
                                                <tr>
                                                    <th>ID</th>
                                                    <th>Subject Code</th>
                                                    <th>Subject Name</th>
                                                    <th>Edit</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                // Include the database configuration file
                                                include("includes/db.php");

                                                // Fetch subjects data from the 'subjects' table
                                                $query = "SELECT * FROM subjects";
                                                $result = $conn->query($query);

                                                // Populate the DataTable with subjects data
                                                while ($row = $result->fetch_assoc()) {
                                                    echo "<tr>
                                                            <td>{$row['id']}</td>
                                                            <td>{$row['subject_code']}</td>
                                                            <td>{$row['subject_name']}</td>
                                                            <td><button type='button' class='btn btn-success'><a style='color:white' href='edit_subject.php?subject_id=" . $row['id'] . "'>Edit </a></button></td>
                                                        </tr>";
                                                }

                                                // Close the database connection
                                                $conn->close();
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
             <!-- /.content-container -->
            </div>
            <!-- /.content-wrapper -->
        </div>
        <!-- /.main-wrapper -->
        <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/select2/select2.min.js"></script>
        <script src="js/main.js"></script>
        <script>
            $(function($) {
                $(".js-states").select2();
                $(".js-states-limit").select2({
                    maximumSelectionLength: 2
                });
                $(".js-states-hide").select2({
                    minimumResultsForSearch: Infinity
                });
            });
        </script>
    </body>
</html>
