<?php 
$id=$_GET['Id_3'];
$query= mysqli_query($conn,"SELECT * FROM subject_soes 
 INNER JOIN module_soes 
      ON module_soes.course_code = subject_soes.course_code WHERE module_soes.code='$id'")or die(mysqli_error());
$row = mysqli_fetch_array($query);   
?> 
<style>
#progressBarContainer { 
  position: fixed;
  top: 0;
  left: 0;
  height: 7px;
  width: 100%;
  background: #ddd;
  z-index: 9999;
  font-family: Arial, sans-serif;
}

#progressBar {
  height: 100%;
  width: 0%;
  background: #4caf50;
  color: white;
  text-align: center;
  line-height: 8px;
  font-weight: bold;
  transition: width 0.2s ease-in-out;
}

#progressText {
  display: inline-block;
}
</style>
   <div class="container">
      <div class="page-inner">
            <div class="page-header">
              <h3 class="fw-bold mb-3"><?php echo $user_row['course']; ?></h3>
              <ul class="breadcrumbs mb-3">
                <li class="nav-home">
                  <a href="admin.php?page=dashboard&Id_2=<?php echo $user_row['course']; ?>">
                    <i class="icon-home"></i>
                  </a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="admin.php?page=dashboard&Id_2=<?php echo $user_row['course']; ?>"><?php echo $row['subject_name']; ?> -<?php echo $user_row['student_id']; ?></a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="admin.php?page=dashboard&Id_2=<?php echo $user_row['course']; ?>"><?php echo $row['code']; ?></a>
                </li>
              </ul>
            </div>
            <div class="row">
              <div class="col-md-12">
                <div class="card">
                  <div class="card-header">
                    <h4 class="card-title"><?php echo $row['subject_name']; ?>(<?php echo $user_row['course']; ?>)</h4>
                  </div>
                  
                  <div id="progressBarContainer"  >
                      <div id="progressBar" class="bg-secondary"><span id="progressText">0%</span></div>
                    </div>
                  <div class="card-body">
                      <div class="card-body">
                    <ul
                      class="nav nav-pills nav-secondary"
                      id="pills-tab"
                      role="tablist"
                    >
                      <li class="nav-item">
                        <a
                          class="nav-link active"
                          id="pills-home-tab"
                          data-bs-toggle="pill"
                          href="#pills-home"
                          role="tab"
                          aria-controls="pills-home"
                          aria-selected="true"
                          ><?php echo $row['code']; ?></a
                        >
                      </li> 
                    </ul>
                    
                    <div class="tab-content mt-2 mb-3" id="pills-tabContent">
                      <div
                        class="tab-pane fade show active"
                        id="pills-home"
                        role="tabpanel"
                        aria-labelledby="pills-home-tab"
                      >
                        <?php echo $row['description']; ?>
                      </div> 
                    </div>
                    </div>
                  </div>
                  <div class="card-footer"> 
                  	<div class="row">
                  	<div class="col-md-6"> 
          			     </div> 
                          <div class="col-md-6"  style="text-align: right"> 
                          <?php  
                          $s_id=$user_row['student_id']; 
                          $m_id=$row['module_id']; 
                          $check_query = mysqli_query($conn,"SELECT module_id FROM  quiz_subject_question_answer WHERE student_id='$s_id' AND module_id='$m_id'");
                          $check = mysqli_fetch_array($check_query);
                               if ($check) {
                                ?>
                                 <p>You are done with this quiz</p>
                            <?php }else{ 
                              $p_query = mysqli_query($conn,"SELECT quiz_subject_id FROM quiz_subject_question_soes WHERE quiz_subject_id='$m_id'");
                              $check_q = mysqli_fetch_array($p_query);
                               if ($check_q) {?> 
                                <a href="orbital/quiz_exam.php?Id_2=<?php echo $row['module_id']; ?>" class="btn btn-success btn-round"><i class="fas fa-angle-double-right"></i> Take a Quiz</a>
                             <?php }} ?>
                          </div>
                      </div> 
				           </div>
                  </div>
                </div>
              </div> 
            </div>
          </div> 
          


<script>
document.addEventListener("scroll", function () {
  const scrollTop = window.scrollY;
  const docHeight = document.documentElement.scrollHeight - window.innerHeight;
  const scrolled = Math.round((scrollTop / docHeight) * 100);
  
  const bar = document.getElementById("progressBar");
  const text = document.getElementById("progressText");
  bar.style.width = scrolled + "%";
  text.textContent = scrolled + "%";

  // Save every 10% progress
  if (scrolled > 0 && scrolled % 10 === 0) {
    sendProgress(scrolled);
  }
});

let lastSent = 0;
function sendProgress(percent) {
  if (percent === lastSent) return;
  lastSent = percent;

  fetch("orbital/save_progress.php", {
    method: "POST",
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: `progress=${percent}&user_id=<?php echo $user_row['student_id']; ?>&course_id=<?php echo $row['subject_id']; ?>&sub_course_id=<?php echo $row['module_id']; ?>`
  });
}
</script>
 
 
