<?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['submit'])) {
    $sid = $_SESSION['edid']; 
    $name = mysqli_real_escape_string($con, $_POST['name']);
    $term = mysqli_real_escape_string($con, $_POST['term']);
    $session = mysqli_real_escape_string($con, $_POST['session']);
    $class = mysqli_real_escape_string($con, $_POST['class']);
    $student_type = mysqli_real_escape_string($con, $_POST['std']);

    // Update query with proper syntax
    $query = "UPDATE document SET 
                File_Name = '$name',
                Term = '$term',
                session = '$session',
                class = '$class',
                student_type = '$student_type'
              WHERE id = '$sid'"; // Use 'id' or appropriate primary key to identify the record

    if (mysqli_query($con, $query)) {
        echo "<script>alert('Updated successfully.');window.location.href='document_list.php';</script>"; exit;
    } else {
        echo "<script>alert('Something went wrong, please try again later.');</script>";
    }
}
?>


<!-- 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  document where id='$eid'");
       $cnt=1;
       while ($row=mysqli_fetch_array($ret))
       {
         $_SESSION['edid']=$row['id']; 
         ?>

        <!-- /.col -->
        <div class="col-md-9">
          <div class="card">
            <div class="card-header p-2">
              <ul class="nav nav-pills">
                <li class="nav-item"><a class="nav-link active" href="#companydetail" data-toggle="tab">Document Details</a></li>
               
              </ul>
            </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" class="form-horizontal" >
                    <div class="row">
                      <div class="col-md-12">
                        <div class="form-group">
                         <label for="companyname">Document Name</label>
                         <input name="name" class="form-control" name="name" id="name" value="<?php  echo $row['File_Name'];?>" required>
                       </div>
                       <!-- /.form-group -->
                     </div>

                    <!-- /.col -->
                  </div><!-- ./row -->

                  <div class="row">
                   
                   
                    <div class="col-md-6">
                      <div class="form-group">
                        <label>Class</label>
                        <input class="form-control" name="class" value="<?php  echo $row['class'];?>" required>
                      </div>        
                    </div>
                    <!-- /.col -->
                    

                    <div class="col-md-6">
                      <div class="form-group">
                        <label>Student Type</label>
                        <input class="form-control" name="std" value="<?php  echo $row['student_type'];?>" required>
                      </div>        
                    </div>

                    <div class="col-md-6">
                      <div class="form-group">
                        <label>Term</label>
                        <input type = "text" class="form-control" name="term" value="<?php  echo $row['Term'];?>" required>
                      </div>        
                    </div>

                    <div class="col-md-6">
                      <div class="form-group">
                        <label>Session</label>
                        <input class="form-control" name="session" value="<?php  echo $row['session'];?>" required>
                      </div>        
                    </div>

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

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