<?php
 session_start();
require_once('operations.php');

$db = new Operations();

if (!isset($_SESSION['user'])) {
   header( "Location: index.php" );
}

$month = date("n");
$year = date("Y");

if($month == 19 || $month == 10 || $month == 11 || $month == 12){

$session1 = $year . "/". ($year + 1);
$term1 = "First";
//$term1 = "Third";
}


else if($month == 1 || $month == 2 || $month == 3 || $month == 4){
$session1 = ($year-1)."/".$year;
$term1 = "Second";

//$term1 = "First";
}

else if($month == 5 || $month == 6 || $month == 7 || $month == 9){
$session1 = ($year-1)."/".$year;
$term1 = "Third";
//$term1 = "Second";
//$term1 = "First";
}	

$statement = $db->getAllSubject();
//$last_id = "";






if(isset($_POST['submit111'])){

 // $examcode = $code1;
  $class = $_POST['class'];
   $subject_id =  $_POST['subject_id'];
   $title = $_POST['title'];
   $date = date("Y-m-d");
  

  // $time1 = $date." ".$time;


 	
  

  

  $countTopic = $db->checkTopic($title,$class);


  
  if($countTopic > 0){
  
  ?>
      
<script>alert('Error, topic code already added for class');

</script>	        
      
      <?php
  
  }
   else {
//addSchedule($examcode,$subject_id,$class,$time,$duration,$date,$questions,$term,$year,$total
//,$increment)
  if(!$db->addTopic($subject_id,$title,$date,$class)) {
      
      ?>
      <script>alert('Topic added Successfully'); 
      
      
   </script>
       <?php 
  }

  else {

      ?>
      <script>alert('Error adding subject');</script>    
          <?php 
  }

   }  

  }


?>
<!--
=========================================================
* Argon Dashboard - v1.2.0
=========================================================
* Product Page: https://www.creative-tim.com/product/argon-dashboard


* Copyright  Creative Tim (http://www.creative-tim.com)
* Coded by www.creative-tim.com



=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-->
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="Start your development with a Dashboard for Bootstrap 4.">
  <meta name="author" content="Creative Tim">
  <title>Exam App</title>
  <!-- Favicon 
  <link rel="icon" href="assets/img/brand/favicon.png" type="image/png">
  -->
  <!-- Fonts -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700">
  <!-- Icons -->
  <link rel="stylesheet" href="assets/vendor/nucleo/css/nucleo.css" type="text/css">
  <link rel="stylesheet" href="assets/vendor/@fortawesome/fontawesome-free/css/all.min.css" type="text/css">
  <!-- Page plugins -->
  <!-- Argon CSS -->
  <link rel="stylesheet" href="assets/css/argon.css?v=1.2.0" type="text/css">
 
  <!-- date picker -->

  
  

  


  <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">

</head>

<body >
  <!-- Sidenav -->
  <nav class="sidenav navbar navbar-vertical  fixed-left  navbar-expand-xs navbar-light bg-white" id="sidenav-main">
    <div class="scrollbar-inner">
      <!-- Brand -->
      <div class="sidenav-header  align-items-center">
        <a class="navbar-brand" href="javascript:void(0)">
          <h4>Exam App</h4>
        </a>
      </div>
      <div class="navbar-inner">
        <!-- Collapse -->
        <div class="collapse navbar-collapse" id="sidenav-collapse-main">
          <!-- Nav items -->
          <?php include('staffmenu.html')  ?>
          <!-- Divider -->
          <hr class="my-3">
          <!-- Heading -->
          
        </div>
      </div>
    </div>
  </nav>
  <!-- Main content -->
  <div class="main-content" id="panel">
    <!-- Topnav -->
    <nav class="navbar navbar-top navbar-expand navbar-dark bg-primary border-bottom">
      <div class="container-fluid">
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <!-- Search form -->
          <form class="navbar-search navbar-search-light form-inline mr-sm-3" id="navbar-search-main">
            <div class="form-group mb-0">
              <div class="input-group input-group-alternative input-group-merge">
                <div class="input-group-prepend">
                  <span class="input-group-text"><i class="fas fa-search"></i></span>
                </div>
                <input class="form-control" placeholder="Search" type="text">
              </div>
            </div>
            <button type="button" class="close" data-action="search-close" data-target="#navbar-search-main" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </form>
          <!-- Navbar links -->
          
          
        </div>
      </div>
    </nav>
    <!-- Header -->
    <!-- Header -->
    <div class="header bg-primary pb-12">
      <div class="container-fluid">
        <div class="header-body">
          <div class="row align-items-center py-4">
            
          
          </div>
          <!-- Card stats -->
         
          <!-- put content  -->




         



          <div class="container-fluid mt--12">
      
       
      <div class="row">
        <div class="col-xl-12">
          <div class="card">
            <div class="card-header border-0">
              <div class="row align-items-center">
                <div class="col">
                  <h3 class="mb-0">Select Subject and class</h3>
                </div>
                <div class="col text-right">
                  
                </div>
              </div>
            </div>
            <div class="table-responsive">
              <!-- Projects table -->
              <div class="card-body" style = "width:900px">
              <form method = "post" action = "">
                
               
             
               

                  <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Select Subject</label>
                        <select class="form-control" id = "subject_id" name = "subject_id" required>

  <option></option>
  <?php 
  while ($row = $statement->fetch(PDO::FETCH_ASSOC)){
            extract($row);
            ?>
             <option value = "<?php echo $row['id'] ?>"><?php echo $row['title'] ?></option>
            <?php
  }
            ?>
</select>
                      </div>
                    </div>
                    </div>



                    <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Class</label>
                        <select class="form-control" id = "class1" name = "class1" required>
  <option></option>
  <option>JS1</option>
  <option>JS2</option>
  <option>JS3</option>
  <option>SS1</option>
  <option>SS2</option>
  <option>SS3</option>
</select>
                      </div>
                    </div>
                    </div>
                 

                  <!--
                    
                    <div class="row">
                    <div class="col-lg-12">
                      <div class="form-group" id = "response">
                       
                      </div>
                    </div>
                    </div>
-->
 
                
                  <div class="text-center">
                  <button type="submit" name = "submit" class="btn btn-primary my-4">Get Topics</button>
                </div>
                  </form>
                  <?php  

if(isset($_POST['submit'])){

  // $examcode = $code1;
   $class = $_POST['class1'];
    $subject_id =  $_POST['subject_id'];

                  ?>

                  <table class="table table-striped table-bordered table-hover" id="example">

    <thead>

        <tr>

            <th>SN</th>

          <th>CLASS</th>  

            <th>TOPIC</th>

           
         
            <th>ADD QUESTION</th>
           
        </tr>

    </thead>

    <tbody>
        <?php 
       $statement = $db->findTopicBySubjectIDandClass($subject_id,$class);
        $rowCount1 = 0;
        while ($row = $statement->fetch(PDO::FETCH_ASSOC)){
                extract($row);
            $rowCount1++;	
        ?>
        <tr>
            <td><?php  echo $rowCount1 ?></td>
            <td><?php echo $row['class'] ?></td>
            <td><?php echo $row['title'] ?></td>
          
            

            <td><a href="ediQuestionBankListStaff.php?id=<?php echo $row['id'] ;?>&class=<?php echo $row['class'] ;?>&subject_id=<?php echo $row['subject_id'] ;?>&title=<?php echo $row['title'] ;?>" class="btn btn-success ">EDIT QUESTION</a></td>
            
           
</tr> 
<?php
        }
?>

</tbody>
</table>
<?php
}
?>
              <!-- end -->
            </div>
          </div>
        </div>
        
            </div>
          </div>
        </div>
      </div>


          <!-- put content --->

          
          
        </div>
      </div>
    </div>
    <!-- Page content -->

    <div class="container-fluid mt--6">
    
    
      
        </div>
      </div>
      <!-- Footer -->
      <footer class="footer pt-0">
        <div class="row align-items-center justify-content-lg-between">
          <div class="col-lg-6">
            
          </div>
          <div class="col-lg-6">
            
          </div>
        </div>
      </footer>
    </div>
  </div>
  <!-- Argon Scripts -->
  <!-- Core -->

   <script src="assets/vendor/jquery/dist/jquery.min.js"></script> 
  <script src="assets/vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/js-cookie/js.cookie.js"></script>
  <script src="assets/vendor/jquery.scrollbar/jquery.scrollbar.min.js"></script>
  <script src="assets/vendor/jquery-scroll-lock/dist/jquery-scrollLock.min.js"></script>
  <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

  <script src ="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>  

<script src ="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>  
  <!-- Optional JS -->
  <script src="assets/vendor/chart.js/dist/Chart.min.js"></script>
  <script src="assets/vendor/chart.js/dist/Chart.extension.js"></script>
  <!-- Argon JS -->
  <script src="js/argon.js?v=1.2.0"></script>

  <script>
    // WRITE THE VALIDATION SCRIPT.
    function isNumber(evt) {
        var iKeyCode = (evt.which) ? evt.which : evt.keyCode
        if (iKeyCode != 46 && iKeyCode > 31 && (iKeyCode < 48 || iKeyCode > 57))
            return false;

        return true;
    }    
</script>

<script>
         $(function() {
			  
            $( "#datepicker-13" ).datepicker(
			{dateFormat: 'yy-mm-dd',minDate:0}).datepicker("setDate", new Date());
           
			
			
         });
      </script>
    
      <script>
          $("#class1").on('change',function(){
              
          var class1 =   $("#class1").val();
          var subject_id =   $("#subject_id").val();  
         

          $.ajax({  
			url: "getTopics.php", 
			method:"POST",  
			data:{class1:class1, subject_id:subject_id,
                dataType : "json"},  
			success:function(data){  
                $("#response").html(data);
			}  
	   });  

         
            });
   $("#subject_id").on('change',function(){
    
   // var class1 =   $("#class1").val();
        //  var subject_id =   $("#subject_id").val();  
          $("#response").empty();
          $('#class1').prop('selectedIndex',0);
          /*

          $.ajax({  
			url: "getTopics.php", 
			method:"POST",  
			data:{class1:class1, subject_id:subject_id,
                dataType : "json"},  
			success:function(data){  
                $("#response").html(data);
			}  
	   });  
    */
            });  
          </script>

<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
  <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
  <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.24/js/dataTables.bootstrap4.min.js"></script>
<script>
  $(document).ready(function() {
	$('#example').DataTable();
} );

	</script>  
</body>

</html>