<?php 
include('../db.php');
date_default_timezone_set('Asia/Kolkata'); 

if(isset($_POST['update_channelid']))
{   $i = 0;
    foreach($_POST[idno] as $idno){

        $aryData = array( 
            "channel_id"=> $_POST[channel_id][$i],
            );

   $update=$db->updateAry("staff",$aryData,"where idno=".$idno);
   if($update>0){
//	        echo "ok";
	   }else{
//	        echo $db->getErMsg()."||".$db->getLastQuery();
	   }

        $i++;
    }
}
?>
<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css" integrity="sha256-uXf0U0UCIqBp2J3S53b28h+fpC9uFcA8f+b/NNmiwVk=" crossorigin="anonymous" />
    <title>Update Channel Id</title>

  </head>
  <body>
    <div class="container-fluid">
        <div class="row">

            <?php include('sidebar.php'); ?>
            
            <div class="col-md-10">
                
                <div style="box-shadow:0px 0px 8px #555;margin:20px;padding:20px;border-radius:5px;min-height:600px;">

                <h4 class="bg-info text-white text-center p-1">UPDATE CHANNEL ID</h4>

                <form method="post" action="">
                <div id="upcomingclassrecord">
                <input type="hidden" name="update_channelid" />
                <table class="table table-sm table-striped table-hover">
                    <tr>
                        <th>S.No.</th>
                        <th>Image</th>
                        <th>Teacher Name</th>
                        <th>Mobile</th>
                        <th>Subject</th>
                        <th>Channel Id</th>
                    </tr>
                    <?php $allteachers = $db->getRows("select * from staff where session='".$_SESSION["admin"]["session"]."' ");

                                $current_date = date('Y-m-d');
                                $current_time = date('H:i');
                                foreach($allteachers as $teacher){
                                $i++;

                                    ?>
                                    <input type="hidden" name="idno[]" value="<?php echo $teacher['idno']; ?>"
                                    <tr>
                                        <td><?php echo $i; ?></td>
                                        <td><?php if($teacher['photo']!=""){?><img src="../media/photo/<?php echo $teacher['photo']; ?>" class="img-thumbnail" style="width:60px;height:80px;"/><?php } ?></td>
                                        <td><?php echo $teacher[name]; ?></td>
                                        <td><?php echo $teacher[mobile]; ?></td>
                                        <td><?php echo $teacher[experience]; ?></td>
                                        <td><textarea name="channel_id[]" class="form-control"><?php echo $teacher[channel_id]; ?></textarea></td>
                                    </tr>
                                    <?php
                                }
                    ?>

                </table>
                </div>
                <input type="submit" class="btn btn-info" value="UPDATE" />
                </form>

                </div>

            </div>

        </div>
    </div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(function(){
       $("#updateChannelidForm").submit(function(event){
           event.preventDefault();
           $.ajax({
               method: 'POST',
               url: 'ajax.php',
               data : $('#updateChannelidForm').serialize(),
               success: function( response ){
                alert(response);
//                filter_upcomingclass();

                        // Swal.fire({
                        //   position: 'top-end',
                        //   icon: 'success',
                        //   title: 'Data saved successfully',
                        //   showConfirmButton: false,
                        //   timer: 2000
                        // }),


               },
               error: function(xhr, desc, err){
                        Swal.fire({
                          position: 'top-end',
                          icon: 'error',
                          title: 'something went wrong. Please try again',
                          showConfirmButton: false,
                          timer: 2000
                        })
               }
           });
       });
    });
    

    
});

function edit(id){
    $.post("ajax.php", { type: "editclass" , id: id } , function( data ) {
        document.documentElement.scrollTop = 0;
        document.getElementById('editform').innerHTML = data;
    });
}

function delete_upcomingclass(id){
    var r = confirm("Are you sure want to delete?");
  if (r == true) {
    $.post("ajax.php", { type: "delete_upcomingclass" , id: id } , function( data ) {
        filter_upcomingclass();
        
                        Swal.fire({
                          position: 'top-end',
                          icon: 'success',
                          title: 'Record Deleted successfully.',
                          showConfirmButton: false,
                          timer: 1500
                        });
        
    });
  }
}

function filter_upcomingclass(id){
    $.post("ajax.php", { type: "filter_upcomingclass" , id: id } , function( data ) {
      document.getElementById('upcomingclassrecord').innerHTML = data;
    });
}

</script>

  </body>
</html>