<?php

include('includes/session.php');

error_reporting(0);

include('includes/dbconnection.php');
require_once 'includes/session_term_helper.php';
$stResult = resolveCurrentSessionTerm($con);
$currentSessionName = $stResult['session_name'];
$currentTermName    = $stResult['term_name'];




$clss = $_SESSION['class'];

require_once 'vendor/autoload.php';



use Dotenv\Dotenv;



// Load environment variables

$dotenv = Dotenv::createImmutable(__DIR__);

$dotenv->load();

$url = $_ENV['BASE_URL'];

?>

<!DOCTYPE html>

<html>

<?php @include("includes/head.php"); ?>



<body class="hold-transition sidebar-mini layout-fixed">

  <div class="wrapper">

    <!-- Navbar -->

    <?php @include("includes/headerstd.php"); ?>

    <!-- /.navbar -->



    <!-- Main Sidebar Container -->

    <?php @include("includes/sidebarstdboard.php"); ?>



    <!-- Content Wrapper. Contains page content -->

    <div class="content-wrapper">

      <!-- Content Header (Page header) -->

<section class="content-header premium-header">

    <div class="container-fluid">

        <div class="header-glass-card">

            <div class="row align-items-center">

                <div class="col-md-8">

                    <div class="title-section">

                        <div class="icon-box bg-primary-gradient shadow-sm">

                            <i class="fas fa-folder-open"></i>

                        </div>

                        <div>

                            <h1 class="premium-title text-primary">

                                Document Management

                                <span class="premium-subtitle text-secondary">Document Download</span>

                            </h1>
                            <div class="mt-1">
                              <?php if ($currentSessionName): ?>
                                <span class="badge badge-primary mr-1">
                                  <i class="fas fa-calendar-alt"></i>
                                  <?= htmlspecialchars($currentSessionName) ?>
                                </span>
                              <?php endif; ?>
                              <?php if ($currentTermName): ?>
                                <span class="badge badge-success">
                                  <i class="fas fa-bookmark"></i>
                                  <?= htmlspecialchars($currentTermName) ?>
                                </span>
                              <?php else: ?>
                                <span class="badge badge-warning">
                                  <i class="fas fa-exclamation-triangle"></i> No active term
                                </span>
                              <?php endif; ?>
                            </div>

                        </div>

                    </div>

                </div>

                <div class="col-md-4">

                    <nav aria-label="breadcrumb">

                        <ol class="breadcrumb premium-breadcrumb">

                            <li class="breadcrumb-item"><a href="newstdboard.php" class="text-primary">Home</a></li>

                            <li class="breadcrumb-item active" aria-current="page">Download</li>

                        </ol>

                    </nav>

                </div>

            </div>

        </div>

    </div>

</section> 



      <!-- Main content -->

      <section class="content">

        <div class="container-fluid">

          <div class="row">

            <div class="col-12">

              <div class="card card-primary">

                <div class="card-header">

                  <h5 class="card-title font-weight-bold"> <i class="fas fa-folder"></i> School Document</h5>

                </div>

                <!-- /.card-header -->



                <div class="card-body mt-2 ">

                  <table id="example1" class="table table-bordered table-hover">

                    <thead>

                      <tr>

                        <th>#</th>

                        <th>File Name</th>

                        <th>Term</th>

                        <th>Session</th>

                        <th>Class </th>

                        <th>Upload Date</th>

                        <th>Action</th>

                      </tr>

                    </thead>

                    <tbody>



                      <?php

                      $std = "New Student (Boarding)";

                      $query = mysqli_query($con, "select * from document where (class ='$clss' OR class = 'All Students') AND student_type = '$std' order by Date desc");

                      $cnt = 1;

                      while ($row = mysqli_fetch_array($query)) {

                      ?>

                        <tr>

                          <td><?php echo htmlentities($cnt); ?></td>

                          <td><?php echo htmlentities($row['File_Name']); ?></td>

                          <td><?php echo htmlentities($row['Term']); ?></td>

                          <td><?php echo htmlentities($row['session']); ?></td>

                          <td><?php echo htmlentities($row['class']); ?></td>

                          <td><?php echo htmlentities($row['Date']); ?></td>

                          <td>

<a href="https://docs.google.com/viewerng/viewer?url=<?php echo rawurlencode($url.'/downloadv.php?id=' . $row['id']); ?>"

   target="_blank" 

   class="btn btn-info btn-xs" 

   title="Preview">

   <i class="fa fa-eye"></i>

</a>



<a href="download.php?id=<?php echo $row['id']?>" 

   class="btn btn-success btn-xs" 

   title="Download">

   <i class="fa fa-download"></i>

</a>

                          </td>

                        </tr>

                      <?php $cnt = $cnt + 1;

                      } ?>

                    </tbody>

                  </table>

                </div>

                <!-- /.card-body -->

              </div>

              <!-- /.card -->

            </div>

            <!-- /.col -->

          </div>

          <!-- /.row -->

        </div>

        <!-- /.container-fluid -->

      </section>

      <!-- /.content -->



    </div>

    <!-- /.content-wrapper -->

    <?php @include("includes/footer.php"); ?>



    <!-- Control Sidebar -->

    <aside class="control-sidebar control-sidebar-dark">

      <!-- Control sidebar content goes here -->

    </aside>

    <!-- /.control-sidebar -->

  </div>



  <!-- ./wrapper -->

  <?php @include("includes/foot.php"); ?>



</body>



</html>