<?php  require_once('../auth/auth.php'); ?>
<?php 
$chartacsu = $_GET['lang_type'];
if ($chartacsu =="1") {
  $tatus = language(1);
} else if ($chartacsu =="2") {
  $tatus =  language(1);
} else if ($chartacsu =="3") {
  $tatus =  language(1);
} else if ($chartacsu =="4") {
  $tatus =  language(1);
}else if ($chartacsu =="5") {
  $tatus =  language(1);
}
?>
<?php
if(isset($_GET['lang_id'])){
   $lang_id= $_GET['lang_id'];
   $areaquery= mysqli_query($conn,"SELECT * FROM language WHERE lang_id='$lang_id' LIMIT 1 ") or die (mysqli_error($conn));
  $rowarea= mysqli_fetch_assoc($areaquery);
   $bangla=$rowarea['bangla'];  
   $english=$rowarea['english'];
   $arabic=$rowarea['arabic'];
   $hindi=$rowarea['hindi'];
   $china=$rowarea['china'];
   $malaysia=$rowarea['malaysia'];

}
  ?>
<section class="content">
   <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
               <div class="card card-secondary card-outline direct-chat direct-chat-secondary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
                    <div class="card-header" style="padding: 5px 8px;"><h3 class="card-title"><i class="fa fa-language"></i>   Language</h3> <div class="card-tools"> <button type="button" class="btn btn-tool" data-card-widget="remove"> <i class="fas fa-times"></i>  </button> </div>
                   </div>
                    <form id="language_from" action="#" method="post" class="form"  autocomplete="off"   >
                          <?php if(isset($_GET['lang_id'])){  ?>
                     <input type="hidden" name="l_submit" id="l_submit" value="<?php echo @$lang_id ;?>"/>
                  <?php }else{?>
                     <input type="hidden" name="l_submit" id="l_submit" value="0"/>
                  <?php } ?>

                    <input type="hidden" id="lang" name="lang" value="<?php echo $chartacsu;?>">
                    <div class="card-body">
                        <div class="col-md-12">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                     <label>Bangla<b class="text-danger"> *</b></label>
                                     <input type="text" id="bangla" name="bangla" value="<?php echo  @$bangla ?>"  class="form-control form-control-sm inputselect" placeholder="Bangla " style="text-align:center;" required="true">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                       <label>English<b class="text-danger"> *</b></label>
                                       <input type="text" id="english" name="english" value="<?php echo  @$english ?>" class="form-control form-control-sm inputselect" placeholder="english " style="text-align:center;" required="true">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                       <label>Arabic<b class="text-danger"> *</b></label>
                                       <input type="text" id="arabic" name="arabic" value="<?php echo  @$arabic ?>" class="form-control form-control-sm inputselect" placeholder="arabic " style="text-align:center;" required="true">
                                   </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                     <label>Hindi<b class="text-danger"> *</b></label>
                                     <input type="text" id="hindi" name="hindi" value="<?php echo  @$hindi ?>" class="form-control form-control-sm inputselect" placeholder="hindi " style="text-align:center;" required="true">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                     <label>chaina<b class="text-danger"> *</b></label>
                                     <input type="text" id="chaina" name="chaina" value="<?php echo  @$china ?>" class="form-control form-control-sm inputselect" placeholder="Chaina " style="text-align:center;" required="true">
                                    </div>
                                </div>
                                <div class="col-md-4">
                                    <div class="form-group">
                                     <label>malaysia<b class="text-danger"> *</b></label>
                                     <input type="text" id="malaysia" name="malaysia" value="<?php echo  @$malaysia ?>" class="form-control form-control-sm inputselect" placeholder="Malaysia " style="text-align:center;" required="true">
                                    </div>
                                </div>
                                
                            </div>
                            <center>
                               <div class="card-footer" style="padding: 8px 5px;">
                                <button type="submit" id="save" class="btn btn-success btn-xs"><?php if (@$_GET['lang_id']) {echo 'update ';}else{echo 'Save Info';}?></button>
                                <button type="reset" class="btn btn-secondary btn-xs">Reset</button>
                               </div>
                            </center>
                        </div>
                    </div>
                    </form>

                    <div class="card-body p-1">
                        <tr>
                            <th rowspan="3"  class="text-center" >
                                <input type="text" id="search" class="form-control form-control-sm search"  placeholder="searching" required="true" style="border-radius: ;border:1px solid primary;width:100%; text-align:center; ">
                            </th>
                        </tr>
                        <table id="trbl_table" class="searchtable ttable" cellpadding="0" cellspacing="0">
                            <thead>
                                <tr class="sticky-top">
                                    <th>Id</th>
                                    <th>Bangla </th>
                                    <th>English </th>
                                    <th>Arabic </th>
                                    <th>Hindi </th>
                                    <th>Chaina </th>
                                    <th> Malaysia </th>
                                </tr>
                            </thead>
                                <tbody id="colview">
                                  <?php
                                  $i=0;
                                  $group= mysqli_query($conn,"SELECT * FROM language WHERE lang_type='$chartacsu' ORDER BY lang_id DESC ") or die (mysql_error());
                                  while ($rowg= mysqli_fetch_array ($group) ){
                                      ?>
                                        <tr class="tr-hover delete_op<?php echo $rowg['lang_id'];?>"  onclick="pagecall('../lang_setting/menu_setting.php?lang_id='+'<?php echo $rowg['lang_id'];?>'+'&lang_type=<?php echo $chartacsu  ?>','#languageview')">
                                          <td  class="text-center"><?php echo $rowg['lang_id'];?></td>
                                          <td ><?php echo $rowg['bangla'];?></td>

                                          <td><?php echo $rowg['english'];?></td>
                                          <td><?php echo $rowg['arabic'];?></td>
                                          <td><?php echo $rowg['hindi'];?></td>
                                          <td><?php echo $rowg['china'];?></td>
                                          <td><?php echo $rowg['malaysia'];?></td>

                                        </tr>
                                        <?php } ?>
                                </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>


<script>
 $(document).ready(function() {
   $('#language_from').on('submit', function(e){
     $('#save').prop('disabled', true);
     $('#save').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...');
     e.preventDefault();  
     $.post("../lang_setting/menu_setting_db.php",$(this).serialize(),function(data){
      $('#language_from')[0].reset();
      $('#save').prop('disabled', false);
      $('#save').html('Save');
      var l_submit = $("#l_submit").val();

        if (l_submit ==0) {
           $.post('../lang_setting/menu_setting.php?lang_type='+'<?php echo $chartacsu ?>',{},function(res){
              $('#languageview').html(res);
           }); 
           toastr.success(Showing, '<?php echo "New language Add Successful" ?>');
        }else if(l_submit >0){
              $.post('../lang_setting/menu_setting.php?lang_type='+'<?php echo $chartacsu ?>',{},function(res){
              $('#languageview').html(res);
        }); 
          toastr.success(Showing, '<?php echo "New Update Successful" ?>');
       }


    });
   });

    $('.search').on('keyup',function(){
      var searchTerm = $(this).val().toLowerCase();
      $('.searchtable tr').each(function(){
        var lineStr = $(this).text().toLowerCase();
        if(lineStr.indexOf(searchTerm) === -1){
          $(this).hide();
        }else{
          $(this).show();
        }
      });
    });

    
  });
</script>
