<?php 
 include ('../includes/connection.php'); 
 // code for block exam   

if(isset($_GET['Id_2']))
{
 $id2=$_GET['Id_2'];   
 $student_id=$user_row['student_id'];
 $invoice= mysqli_query($conn,"SELECT * FROM student_soes 
    INNER JOIN exam_invoice 
          ON exam_invoice.student_id = student_soes.student_id  WHERE exam_invoice.course_code ='$id2' AND exam_invoice.student_id='$student_id' ")or die(mysqli_error());
  $invoice2 = mysqli_fetch_array($invoice); 
  if ($invoice2["invoice_status"] == 'Enable'){
     ?>
      <script type="text/javascript"> 
           window.location.href = 'admin.php?page=edr6728sr624gtt5678532srr5568exRestt578jjhggfr448w2&Id_2=<?php echo $id2?>';
        </script>
        <?php  
      
  }
 }
 $id=$_GET['Id_2'];
 
 if (isset($_POST['update'])){ 
$course = $_POST['course']; 
$Email = $user_row['student_email_id'];
$company = $user_row['company'];
$student_contact_no = $user_row['student_contact_no'];

if(!empty($student_contact_no)){ 

  $update = mysqli_query($conn,"UPDATE `student_soes` SET `course`='$course' WHERE student_email_id='$Email'"); 
   if($update){ 
  
         ?>
         <script type="text/javascript">
             alert("Your Success Fully Enroll to the course");
             window.location.href = 'admin.php?page=dashboard&Id_2=<?php echo $id?>';
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Sorry Failed to Enroll to the course Try Again");
        </script>
        <?php
    }
}  
      else{
          ?>
         <script type="text/javascript">
             alert("Please update your profile detail");
         </script>
        <?php 
          
      }
  } 
?>
<style>
    
    .reactive-table {
      width: 100%; 
      box-shadow: 0 0 0 transparent; /* No outer border */
    }

    .reactive-table th,
    .reactive-table td {
      padding: 12px 15px;
      border-bottom: 1px solid #ddd;
      text-align: left;
    }

    .reactive-table tr {
      transition: background-color 0.3s ease, transform 0.2s ease;
    }

    /* Hover Effect */
    .reactive-table tr:hover {
      background-color: #f1f1f1;
      transform: scale(1.08);
      cursor: pointer;
    }

    .reactive-table th {
      background-color: #f9f9f9;
      font-weight: bold;
    }
    
     .animated-button-invoice {
  background-color: #0aaefa;
  color: white;
  padding: 15px 30px;
  border: none;
  border-radius: 5px;
  font-size: 18px;
  cursor: pointer;
  animation: pulses 2s infinite alternate; /* Apply a pulsing animation */
}
 @keyframes pulses {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(10, 170, 254, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 20px 5px rgba(10, 170, 254, 0.7);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(10, 170, 254, 0.7);
  }
}  
    .animated-button {
  background-color: #e74c3c;
  color: white;
  padding: 15px 30px;
  border: none;
  border-radius: 5px;
  font-size: 18px;
  cursor: pointer;
  animation: pulse 2s infinite alternate; /* Apply a pulsing animation */
}


@keyframes pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 20px 5px rgba(231, 76, 60, 0.7);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7);
  }
}

    
 
  </style>
      
 <div class="container">
  <div class="page-inner">
    <div
      class="d-flex align-items-left align-items-md-center flex-column flex-md-row pt-2 pb-4"
    >
      <div>
        <h3 class="fw-bold mb-3">Dashboard</h3>
        <h6 class="op-7 mb-2">Welcome to Cybercode Academy <?php echo date('Y'); ?></h6>
      </div>
      <div class="ms-md-auto py-2 py-md-0"> 
        <?php
          if ($user_row['course']=="$id") {
             
            $query1= mysqli_query($conn,"SELECT course_code,subject_id FROM subject_soes WHERE course_code='$id'")or die(mysqli_error());
            $row = mysqli_fetch_array($query1);
            $subject_id=$row['subject_id'];
            $student_id=$user_row['student_id'];
            
            $invoice= mysqli_query($conn,"SELECT * FROM student_soes 
            INNER JOIN exam_invoice 
            ON exam_invoice.student_id = student_soes.student_id  WHERE exam_invoice.course_code ='$id' AND exam_invoice.student_id='$student_id' ")or die(mysqli_error());
            $invoice2 = mysqli_fetch_array($invoice); 
            
            $check_q_marks= mysqli_query($conn,"SELECT * FROM `user_progress` WHERE subject_id='$subject_id' AND student_id='$student_id'")or die(mysqli_error());
            $check_q_marks1 = mysqli_fetch_array($check_q_marks);
            $q_marks=$check_q_marks1['q_marks'];
            
            if($check_q_marks1['q_marks']==Null){?> 
            
            <?php 
            } else if($check_q_marks1['q_marks']<=50){?>
            <a href="#" onclick="return confirm('Make  sure your clear the Quiz per each Sub Topics provided in your course with pass mark ?');" class="btn btn-success btn-round">Take examination</a>
            <?php 
            } else{
            $check= mysqli_query($conn,"SELECT student_id,subject_id,booking_id FROM student_to_class_soes WHERE student_id='$student_id' AND subject_id='$subject_id'")or die(mysqli_error());
            $check_1= mysqli_fetch_array($check); 
            $check_student_id=$check_1['student_id'];
            $check_subject_id=$check_1['subject_id'];
            $book_id=$check_1['booking_id'];
            if(empty($check_1)){ 
          ?>
          <a href="admin.php?page=booking&Id_2=<?php echo $user_row['course']; ?>" class="btn btn-secondary btn-round"><i class="fas fa-address-book"></i>  Schedule examination</a>
            
          <?php }else{ 
          
                    if (!$invoice2){?>
                    <a href="admin.php?page=fgtt5678532srr5568exMadt578jjhggfr448w2&Id_2=<?php echo $user_row['course']; ?>&book_id=<?php echo $book_id; ?>" class="animated-button-invoice btn-round"> Take Invoice</a>
                      <?php }else if ($invoice2["invoice_status"] == 'Disable'){?>
 
                      	<a href="admin.php?page=payment_code&Id_2=<?php echo $user_row['course']; ?>&book_id=<?php echo $book_id; ?>" class="animated-button btn-round"> <i class="fas fa-address-alert"></i> Payment Code Progress......</a> 
                     <?php }  
                } 
            }
            
            
            
            
            
          }
           else{ ?>
                   <form action=" " method="post">  
                      <input type="hidden" name="course"  class="form-control" value="<?php echo $id?>">   
                      <button type="submit" name="update" class="btn btn-danger btn-round"><i class="fa fa far fa-unlock"></i> Enroll to the course</button> 
                   </form> 
          <?php }?>
        
      </div>
    </div>
    
   <div class="row">
    <div class="col-md-6">
      <div class="row">
      <div class="col-md-6">
        <div class="card card-stats card-round">
          <div class="card-body">
            <div class="row align-items-center">
              <div class="col-icon">
                <a href="https://tms.cybershield.co.tz"> 
                <div  class="icon-big text-center icon-primary bubble-shadow-small"  >
                  <i class="fas fa-address-book"></i>
                </div>
              </a>
              </div>
              <div class="col col-stats ms-3 ms-sm-0">
                <div class="numbers"> 
                  <h4 class="card-title">eVUE</h4>
                </div>
              </div>
            </div>
          </div>
        </div>
        </div>
      <div class="col-md-6">
        <div class="card card-stats card-round">
          <div class="card-body">
            <div class="row align-items-center">
              <div class="col-icon">
                <a href="http://simulations.h4k-it.com">
                <div class="icon-big text-center icon-info bubble-shadow-small"  >
                  <i class="fas fa-th-list"></i>
                </div>
              </a>
              </div>
              <div class="col col-stats ms-3 ms-sm-0">
                <div class="numbers"> 
                  <h4 class="card-title">Cybercode Labs</h4>
                </div>
              </div>
            </div>
          </div>
        </div>
        </div> 
       <div class="col-md-6">
        <div class="card card-stats card-round">
          <div class="card-body">
            <div class="row align-items-center">
              <div class="col-icon">
                <a href="#">
                <div class="icon-big text-center icon-success bubble-shadow-small"
                > 
                <i class="fas fa-unlock"></i>
                </div>
              </a>
              </div>
              <div class="col col-stats ms-3 ms-sm-0">
                <div class="numbers"> 
                  <h4 class="card-title">Phishing Simulator</h4>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="col-md-6">
        <div class="card card-stats card-round">
          <div class="card-body">
            <div class="row align-items-center">
              <div class="col-icon">
                <a href="https://community.cybershield.co.tz">
                <div  class="icon-big text-center icon-secondary bubble-shadow-small"  >
                  <i class="fas fa-users"></i>
                </div>
              </a>
              </div>
              <div class="col col-stats ms-3 ms-sm-0">
                <div class="numbers"> 
                  <h4 class="card-title">Cybercode Community</h4>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      </div>
      <div class="col-md-12">
        <div class="card card-round">
          <div class="card-header">
            <div class="card-head-row">
              <div class="card-title">Course Overview</div> 
            </div>
          </div>
          <div class="card-body">
            <div class="chart-container" style="min-height: 375px">
             <div class="embed-responsive embed-responsive-16by9">
               <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/S7smySFl3xY" style="height: 500px; width: 100%;" allowfullscreen></iframe> 
             </div> 
            </div>
            <div id="myChartLegend"></div>
          </div>
        </div>
      </div>
      </div>
     <div class="col-md-6">
    <div class="card">
      <div class="card-header">
        <h4 class="card-title">Your Progress on <?php echo $user_row['course']; ?></h4>
      </div>
      <div class="card-body">  
      <div class="table-responsive">
    <table class="reactive-table" id="myTable">
    <thead>
      <tr>
        <th>#</th>
        <th>Sub Course</th>
        <th>Progress</th> 
        <th>Q-Marks</th>
        <th>Remark</th>
      </tr>
    </thead>
    <tbody>
         <?php
          $i = 1;
          $course1=$user_row['course']; 
          $student_id=$user_row['student_id'];
          $school_query = mysqli_query($conn,"SELECT DISTINCT module_soes.code,user_progress.module_id,user_progress.q_marks,user_progress.student_id,user_progress.subject_id,user_progress.progress_percent,module_soes.course_code FROM module_soes,user_progress WHERE module_soes.module_id = user_progress.module_id AND module_soes.course_code='$id' AND user_progress.student_id='$student_id'");
          while($row2 = mysqli_fetch_array($school_query)){  
          $subject_id=$row2['subject_id'];
          $module_id=$row2['module_id']; 
          $q_marks_1=$row2['q_marks'];
        ?>
      <tr>
        <td><?php echo $i++ ?></td>
        <td><a href="admin.php?page=fgtt5678532srr5567yfsszadt578jjhggfr443w2&Id_2=<?php echo $user_row['course']; ?>&Id_3=<?php echo $row2['code']; ?>" style="color: black;"><?php echo $row2['code']; ?></a></td>
        <?php if ($row2['progress_percent'] < 100) { ?>
        <td><span class="badge badge-danger"><?php echo $row2['progress_percent']; ?> %</span></td> 
        <?php } else{?>
        <td><span class="badge badge-info"><?php echo $row2['progress_percent']; ?> %</span></td>
        <?php }  
            $quiz = mysqli_query($conn,"SELECT SUM(marks) AS T_MARKS 
                                        FROM `quiz_subject_question_answer` 
                                        WHERE subject_id='$subject_id' 
                                          AND student_id='$student_id' 
                                          AND module_id='$module_id'");
            $quiz_r = mysqli_fetch_array($quiz); 
            $q_marks = $quiz_r['T_MARKS'];
            ?>
            
            <!-- DISPLAY MARKS -->
            <?php if($q_marks !== NULL) { ?>
                <td><?php echo $q_marks; ?> %</td>
            <?php } else { ?>
                <td><i>--NIL--</i></td>
            <?php } ?>
            
            <!-- DISPLAY STATUS -->
            <?php if($q_marks !== NULL) { 
                if ($q_marks <= 50) { ?>
                    <td style="color: red;">
                        <a href="orbital/update_quiz_exam.php?Id_2=<?php echo $module_id; ?>">Retake Quiz</a>
                    </td>
                <?php } else { ?>
                    <td>Pass</td>
                <?php } 
            } else { ?>
                <td><i>--NIL--</i></td>
            <?php } ?>

        </tr>
      <?php } ?> 
    </tbody>
  </table>
  </div>
</div>
</div>  
 
</div>
    </div>
     <h5 class="fw-bold mb-3">Sub Topics</h5>
     <hr>
      <div class="row">
        <?php
          $course1=$user_row['course'];
          if ($user_row['course']=="$id") {
          $school_query = mysqli_query($conn,"SELECT DISTINCT module_soes.code,student_soes.course,module_soes.course_code FROM module_soes,subject_soes,student_soes WHERE module_soes.course_code = subject_soes.course_code AND module_soes.course_code = student_soes.course AND student_soes.course='$id'");
         while($row1 = mysqli_fetch_array($school_query)){  
        ?>
        <div class="col-sm-6 col-md-3">
          <div class="card card-stats card-secondary card-round">
            <div class="card-body">
              <div class="row">
                <div class="col-2">
                  <div class="icon-big text-center">
                    <i class="fas fa-book"></i>
                  </div>
                </div> 
                <div class="col-10 col-stats">
                  <a href="admin.php?page=fgtt5678532srr5567yfsszadt578jjhggfr443w2&Id_2=<?php echo $user_row['course']; ?>&Id_3=<?php echo $row1['code']; ?>">
                  <div class="numbers">
                    <p class="card-category">Start <?php echo $user_row['course']; ?></p>
                    <h4 class="card-title"><?php echo $row1['code']; ?></h4>
                  </div>
                 </a>
                </div>
              </div>
            </div>
          </div>
        </div>
        <?php }}?> 
      </div>  
    </div>
</div> 
 
  