<?php 
include "header_with_out_nav.php"; 
$college_id=$_GET['college_id'];
$course_name=$_GET['course_name'];
$subject=$_GET['subject'];
$college_type=$_GET['college_type'];
$Course_Details=$_GET['Course_Details'];
$day=$_GET['day'];
$month=$_GET['month'];
$year=$_GET['year'];
?>

<!doctype html>
<html>
    <head>
        <title>Autosave data after specific time with jQuery and AJAX</title>
     
        <!-- Script -->
        <script src='jquery-3.1.1.min.js' type='text/javascript'></script>
   
        
        <script type='text/javascript'>
        $(document).ready(function(){
           var timer;
           var timeout = 300;  // Timout duration
           $('#postTitle,#postContent').keyup(function(){
                
                if(timer) {
                    clearTimeout(timer);
                }
                timer = setTimeout(saveData, timeout); 
             
           });
                  
           $('#submit').click(function(){
               saveData();
           });
        });

        // Save data
        function saveData(){
            
            var postid = $('#postid').val();
            var title = $('#postTitle').val().trim();
           // var content = $('#postContent').val().trim();
			
			var month = $('#month').val().trim();
			var day = $('#day').val().trim();
			var year = $('#year').val().trim();
			var college_id = $('#college_id').val().trim();
			var college_type = $('#college_type').val().trim();
			var course_name = $('#course_name').val().trim();
			var Course_Details = $('#Course_Details').val().trim();
			var subject = $('#subject').val().trim();
			

            if(title != '' && month != '' && day != '' && year != '' && college_id != '' && college_type != '' && course_name != '' && Course_Details != '' && subject != ''){
                // AJAX request
                $.ajax({
                    url: 'autosave.php',
                    type: 'post',
                    data: {postid:postid,title:title,day:day,month:month,year:year,college_id:college_id,college_type:college_type,course_name:course_name,Course_Details:Course_Details,subject:subject},
                    success: function(response){
                        $('#postid').val(response);
						window.location.href = "scanbarcode.php?college_id=<?php echo $_GET['college_id']; ?>&course_name=<?php echo $_GET['course_name']; ?>
&subject=<?php echo $_GET['subject']; ?>&college_type=<?php echo $_GET['college_type']; ?>&Course_Details=<?php echo $_GET['Course_Details']; ?>&day=<?php echo $_GET['day']; ?>&month=<?php echo $_GET['month']; ?>&year=<?php echo $_GET['year'];?>";
						//alert("Hello! I am an alert box!!");
                    }      
                }
				);
            }
            
        }
        
        </script>
</head>
    <body >
    
<center><h1>Barcode Attendance System</h1><input type='text' id='postTitle'  autofocus style="height:60px; width:210px; font-size:36px; margin-top:25px;" autocomplete="off"></center>      <?php /*?><textarea id='postContent' placeholder='Enter content'></textarea><br><br>    <?php */?>
        
        <input name="day" id="day" type="hidden" value="<?php echo $day; ?>"/>
<input name="month" id="month" type="hidden" value="<?php echo $month; ?>"/>
<input name="year" id="year" type="hidden" value="<?php echo $year; ?>"/>
<input name="college_id" id="college_id" type="hidden" value="<?php echo $college_id; ?>"/>
<input name="college_type" id="college_type" type="hidden" value="<?php echo $college_type; ?>"/>
<input name="course_name" id="course_name" type="hidden" value="<?php echo $course_name; ?>"/>
<input name="Course_Details" id="Course_Details" type="hidden" value="<?php echo $Course_Details; ?>"/>
<input name="subject" id="subject" type="hidden" value="<?php echo $subject; ?>"/>
        
        <?php /*?><input type='button' id='submit' value='Submit'>
        <input type='text' id='postid' value='0' >    <?php */?>
        
        <?php /*?><form action="autosave.php" method="post" >
        <input type='text' name="title" id='postTitle'  autofocus><br><br>
         <input name="day" id="day" type="hidden" value="<?php echo $day; ?>"/>
<input name="month" id="month" type="hidden" value="<?php echo $month; ?>"/>
<input name="year" id="year" type="hidden" value="<?php echo $year; ?>"/>
<input name="college_id" id="college_id" type="hidden" value="<?php echo $college_id; ?>"/>
<input name="college_type" id="college_type" type="hidden" value="<?php echo $college_type; ?>"/>
<input name="course_name" id="course_name" type="hidden" value="<?php echo $course_name; ?>"/>
<input name="Course_Details" id="Course_Details" type="hidden" value="<?php echo $Course_Details; ?>"/>
<input name="subject" id="subject" type="hidden" value="<?php echo $subject; ?>"/>
        
        <input type='submit' id='submit' value='Submit'>
        <input type='text' id='postid' value='0' >
        </form><?php */?>
        
        <?php
		
		
		
$query = "SELECT * FROM att where session='$session' and code='$code'ORDER BY id DESC LIMIT 1";
$numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
 $a_rowwx = mysql_fetch_array( $result );
 $rsid=$a_rowwx['sid'];
 
 
 if($rsid!=""){
 $check_exist_qry2="select * from class2 where college_roll='$rsid' and session='$session' and code='$code'";
$run_qry2=mysql_query($check_exist_qry2);
$total_found2=mysql_num_rows($run_qry2);
$row = mysql_fetch_array($run_qry2, MYSQL_BOTH);
 }
?>
<table width="90%" border="1" cellspacing="2" cellpadding="2" align="center">
  <tr>
    <td><div align="center"><strong>Photo</strong></div></td>
    <td><div align="center"><strong>Student Name</strong></div></td>
    <td><div align="center"><strong>College Roll No</strong></div></td>
    <td><div align="center"><strong>Class</strong></div></td>
    <td><div align="center"><strong>Subject</strong></div></td>
    <td><div align="center"><strong>Date</strong></div></td>
    <td><div align="center"><strong>Attdent Class</strong></div></td>
  </tr>
  <?php if($total_found2!=""){?>
  <tr>
    <td><div align="center"><img src="../uploads/<?php echo $row['class_std_ing'];?>" width="97" height="100" id="ImgPhoto" style="height:100px;width:90px;border-width:0px;"></div></td>
    <td><div align="center"><?php echo $row['StudentName'];?></div></td>
    <td><div align="center"><?php echo $rsid;?></div></td>
    <td><div align="center">
      <?php 
	$Course=$row['Course'];
	$queryy = "SELECT * FROM course_name where id='$Course' and session='$session' and code='$code'";
$numresultsy=mysql_query($queryy);
$resulty= mysql_query($queryy) or die("Couldn't execute query");
 ?>
      <?php
while ( $a_roww = mysql_fetch_row( $resulty ) )
 {?>
      
      
      <?php echo $a_roww[1];?>
      <?php } ?>
      
    ( <?php echo $row['Course_Details']; ?>)</div></td>
    <td><div align="center"><?php echo $row['class_app'];?></div></td>
    <td><div align="center"><?php echo $a_rowwx['date'];?></div></td>
    <td><div align="center"><?php echo $a_rowwx['subject'];?></div></td>
  </tr>
  <?php }else{ ?>
  <tr><td colspan="7" style="color:#FF0000; font-size:14px; font-weight:bold"><div align="center">No Record Found</div></td></tr>
  <?php }?>
</table>

</body>
</html>