<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<!-- Styles -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <title>Exam Fee</title>
    <style type="text/css">
@font-face {
  font-family: 'Bangla';
  src: url('dist/fonts/SutonnyOMJ.ttf');
  font-weight: normal;
  font-style: normal;
}
@font-face{
  font-family: bangla;
  text-align: center;
  src: url(dist/fonts/SutonnyMJ.ttf);
}
.Bangla{font-family: Bangla;}
.Bangla{font-family: Bangla;}
.btn{font-family: Bangla;} 
#font{font-family: Bangla; font-size: 18px; text-align: center;}
#center{ text-align: center;}
#s_font{font-family: Bangla; font-size: 18px;}
</style>
  <body>
    <div class="col-md-12">
<?php 
$ljlj="";
$class        ="";
$obosisto='';
$month_si='';
//error_reporting(0);
?>

    <div>
        <form class="form-horizontal" action="" method="post">
    <div class="row">
        <div class="col-md-12">
                                                                
<form class="form-horizontal" action="" method="post">
<div class="">
          
<div class="form-group">
  <label for="inputEmail3" class="col-sm-2 control-label">মাস </label>
    <div class="col-sm-10">
       <select class="form-control" name="month_si" required="" onchange="document.location.href=this.value">
            <option value="?p=teacher_info&do=08">মাস </option>
      <?php $month_Sql=mysqli_query($con,"SELECT * FROM `month` ORDER BY month_si ASC");
      while($row_month = mysqli_fetch_assoc($month_Sql)){ ?>
      <option value="?p=teacher_info&do=08&month_si=<?php echo  $row_month['month_si'] ?>"<?php if(isset($_GET["month_si"]) && $_GET["month_si"]==$row_month['month_si']){echo 'selected';} ?>>
            <?php echo $row_month['month_english'] ?></option>
      <?php }
      ?>
      </select> 
      </div></div>
<?php  ?>
                <div class="form-group">
      <label for="inputEmail3" class="col-sm-2 control-label">বছর</label>
      <div class="col-sm-10">
        <select class="form-control" name="year_name" onchange="document.location.href=this.value">
          <option value="?p=teacher_info&do=08">বছর সিলেক্ট করুন</option> 

          <option value="?p=teacher_info&do=08&month_si=<?php if(isset($_GET["month_si"]) && $_GET["month_si"]!=""){echo  $_GET["month_si"];}  ?>&year_name=2022">2022</option>    
    </select>
  <?php 
if(isset($_GET["year_name"]) && $_GET["year_name"]!=""){$year= $_GET["year_name"];}
 if(isset($_GET["month_si"]) && $_GET["month_si"]!=""){$month_si= $_GET["month_si"];}

$month      =  'month_'.$month_si.'_m';
$final_mont = $month_si.'-'.$year;
//update
if(isset($_POST['submit'])){
$id        = $_POST['id'];
$mon        = $_POST['mon'];
$number    = count($_POST["id"]);

          $sql_selete = $con->query("SELECT * FROM teacher_tk WHERE teacher_tk.year='$final_mont' ");
if($number>0){
  for($i=0; $i<$number; $i++)
  {
    if($_POST["id"][$i] !=''){
      if ($_POST["id"][$i] !='' || $_POST["id"][$i] > 0) {

        

      if ($sql_selete->num_rows > 0) {
          $second_sql=$con->query("UPDATE teacher_tk SET 
            teacher_idf='".mysqli_real_escape_string($con, $_POST["id"][$i])."',
            year='".mysqli_real_escape_string($con, $_POST["mon"][$i])."',
            tk_haolad='".mysqli_real_escape_string($con, $_POST["tk_haolad"][$i])."'

           WHERE teacher_tk.teacher_idf='".mysqli_real_escape_string($con, $_POST["id"][$i])."' AND teacher_tk.year='".mysqli_real_escape_string($con, $_POST["mon"][$i])."'");
        }else{
         $second_sql=$con->query("INSERT INTO teacher_tk (teacher_tk.teacher_idf, teacher_tk.year, teacher_tk.tk_haolad) VALUES ('".mysqli_real_escape_string($con, $_POST["id"][$i])."', '".mysqli_real_escape_string($con, $_POST["mon"][$i])."', '".mysqli_real_escape_string($con, $_POST["tk_haolad"][$i])."')");

    
 }}}}     
}
if (mysqli_query($con,$second_sql)===TRUE){

  echo '<div class="alert alert-danger" role="alert">সংরক্ষণ হয় নাই</div>';
}else {
    echo '<div class="alert alert-success" role="alert"><center>সফলভাবে সম্পাদন হয়েছে!</center></div>';
}
if($second_sql==true){  
echo '<meta http-equiv="refresh" content="1">';     
      }}
?> 
<?php $sl=1;
//ছাত্র তথ্য
$sql_stu= mysqli_query($con, "SELECT * FROM teacher_tk 
LEFT JOIN teacher ON teacher_tk.teacher_idf=teacher.teacher_id 
  WHERE year='$final_mont' ");
$teacher= mysqli_query($con, "SELECT * FROM teacher ");
$count= mysqli_num_rows($sql_stu);

if($count >0){
  echo'<a target="_blank" href="hifz_para_print.php?year=" class="btn btn-success pull-right"><i class="fa fa-fw fa-print"></i> প্রিন্ট</a>'; 

echo '<table class="table table-hover">
<tr style="background-color: #00ff9599;">
  <th id="center">ক্রমিক</th>
  <th id="center">শিক্ষক আইডি</th>
  <th id="center">নাম</th>
  <th id="center">বেতন</th>
  <th id="center">হাওলাদ</th>
  <th id="center">অবসিষ্ট</th>
</tr>
';
while($stu_row=mysqli_fetch_assoc($sql_stu)){
$tk_haolad= $stu_row['tk_haolad'];
$salary= $stu_row['salary'];
$obosisto= $salary-$tk_haolad;
echo '
<tr>
  <td id="font">'.$sl++.'</td>
  <td id="font">'.$stu_row['teacher_idf'].'</td>
  <td id="font">'.$stu_row['name'].'</td>
  <input type="hidden" class="form-control" name="id[]" id="focusedInput" value="'.$stu_row['teacher_idf'].'">
  <input type="hidden" class="form-control" name="mon[]" id="mon" value="'.$final_mont.'">
  <td id="font"><input id="font" type="text" class="form-control" name="salary[]" id="numberbox" value="'.$stu_row['salary'].'"onkeypress="isInputNumber(event)" autocomplete="off" maxlength="1" tabindex="1"></td>

  <td><input id="font" type="text" class="form-control" name="tk_haolad[]" id="numberbox" value="'.$stu_row['tk_haolad'].'"onkeypress="isInputResult(event)" autocomplete="off" tabindex="2"></td>

  <td><input id="font" type="text" class="form-control" name="totalpara[]" id="numberbox" value="'.$obosisto.'" onkeypress="isInputNumber(event)" autocomplete="off" maxlength="2" tabindex="3"></td>

</tr>
';}
echo '
<td></td>
<td></td>
<td></td>
  <td colspan="3"> <button type="submit" name="submit" class="btn btn-md btn btn-info btn-block text-uppercase" tabindex="1"></i> '._save.'</button> </td>';

}else{ 
  echo'<a target="_blank" href="hifz_para_print.php?year=" class="btn btn-success pull-right"><i class="fa fa-fw fa-print"></i> প্রিন্ট</a>'; 

  echo '<table class="table table-hover">
<tr style="background-color: #00ff9599;">
  <th id="center">ক্রমিক</th>
  <th id="center">শিক্ষক আইডি</th>
  <th id="center">নাম</th>
  <th id="center">বেতন</th>
  <th id="center">হাওলাদ</th>
  <th id="center">অবসিষ্ট</th>
</tr>
';
while($te_row=mysqli_fetch_assoc($teacher)){
echo '
<tr>
  <td id="font">'.$sl++.'</td>
  <td id="font">'.$te_row['teacher_id'].'</td>
  <td id="font">'.$te_row['name'].'</td>
  <input type="hidden" class="form-control" name="id[]" id="focusedInput" value="'.$te_row['teacher_id'].'">
  <input type="hidden" class="form-control" name="mon[]" value="'.$final_mont.'">
  <td><input id="font" type="text" class="form-control" name="salary[]" id="numberbox" value="'.$te_row['salary'].'"></td>

  <td><input id="font" type="text" class="form-control" name="tk_haolad[]" id="numberbox" onkeypress="isInputResult(event)" autocomplete="off" tabindex="2"></td>

  <td><input id="font" type="text" class="form-control" name="totalpara[]" id="numberbox" value="'.$obosisto.'" ></td>

</tr>
';}

echo '
<td></td>
<td></td>
<td></td>
  <td colspan="3"> <button type="submit" name="submit" class="btn btn-md btn btn-info btn-block text-uppercase" tabindex="1"></i> '._save.'</button> </td>';}

?>
</table>
     </div>
  </body>

        <script>  
            function isInputNumber(evt){               
                var ch = String.fromCharCode(evt.which);         
                if(!(/[0-7]/.test(ch))){
                    evt.preventDefault();
                }             
            }
            function isInputResult(evt){          
                var ch = String.fromCharCode(evt.which); 
                if(!(/[0-9 , -]/.test(ch))){
                    evt.preventDefault();
                }                
            }
        </script>
</head>
