<?php
session_name('super_admin_session');
if (!is_dir(dirname(__DIR__) . '/session_data/super')) { mkdir(dirname(__DIR__) . '/session_data/super', 0700, true); } session_save_path(dirname(__DIR__) . '/session_data/super');
session_set_cookie_params(['path' => '/', 'httponly' => true, 'samesite' => 'Strict']);
session_start();
error_reporting(0);
include('includes/dbconnection.php');
include('includes/flash.php');
if (isset($_POST['update'])) {
  $sid = $_SESSION['edid'];
  $Subjectname = $_POST['subject'];
  $Class = $_POST['class'];
  $Arm = $_POST['arm'];
  $subject_type = $_POST['subject_type'];
  $sql = "update subjectcombination set Class=:Class,Subject_name=:Subject_name, section=:section, subject_type=:subject_type where id='$sid'";
  $query = $dbh->prepare($sql);
  $query->bindParam(':Class', $Class, PDO::PARAM_STR);
  $query->bindParam(':Subject_name', $Subjectname, PDO::PARAM_STR);
  $query->bindParam(':section', $Arm, PDO::PARAM_STR);
  $query->bindParam(':subject_type', $subject_type, PDO::PARAM_STR);


  $query->execute();
  if ($query->execute()) {
    echo "<script>alert('updated successfully.');window.location.href='add_subject.php';</script>"; exit;
  } else {
    flash_alert('something went wrong, please try again later');
  }
}

?>


<!-- Content Wrapper. Contains page content -->
<div class="card-body">
  <!-- Main content -->
  <section class="content">
    <div class="container-fluid">
      <div class="row">
        <?php
        $eid = $_POST['edit_id'];
        $ret = mysqli_query($con, "select * from  subjectcombination where id='$eid'");
        $cnt = 1;
        while ($row = mysqli_fetch_array($ret)) {
          $_SESSION['edid'] = $row['id'];
        ?>

          <!-- /.col -->
          <div class="col-md-12">
            <div class="card card-primary">
              <div class="card-header">
                <h5>Class & Subject Details</h5>
              </div><!-- /.card-header -->
              <div class="card-body">
                <div class="tab-content">
                  <div class="active tab-pane" id="companydetail">
                    <form role="form" id="" method="POST" enctype="multipart/form-data">
                      <div class="row">
                        <div class="form-group col-md-12">
                          <label for="companyname">Subject</label>
                          <input class="form-control" name="subject" id="subject" value="<?php echo $row['Subject_name']; ?>" required>
                        </div>
                        <div class="form-group col-md-12">
                          <label>Class</label>
                          <input class="form-control" name="class" id="class" value="<?php echo $row['Class']; ?>" required>
                        </div>
                        <div class="form-group col-md-12">
                          <label>Arm</label>
                          <input class="form-control" name="arm" id="arm" value="<?php echo $row['section']; ?>" required>
                        </div>
                        <div class="form-group col-md-12">
                          <label for="subject_type">Subject Type</label>
                          <select name="subject_type" id="subject_type" class="form-control" required>
                            <option value="">Select Type</option>
                            <option value="Compulsory" <?php if (($row['subject_type'] ?? '') == 'Compulsory') echo 'selected'; ?>>Compulsory Subject</option>
                            <option value="Elective" <?php if (($row['subject_type'] ?? '') == 'Elective') echo 'selected'; ?>>Elective Subject</option>
                          </select>
                        </div>



                        <!-- /.card-body -->
                        <div class="modal-footer text-center">
                          <button type="submit" name="update" class="btn btn-primary">Update</button>
                        </div>
                      </div>
                    </form>
                  </div>



                  <!-- /.tab-pane -->
                <?php
              } ?>
                </div>
                <!-- /.tab-content -->
              </div><!-- /.card-body -->
  </section>
  <!-- /.content -->
</div>
<!-- /.content-wrapper -->