<?php
include('../db.php');

if(isset($_POST['liveclass_id']))
{
    // print_r($_POST);
    $id = $_POST['liveclass_id'];
    $aryData = array(
            "name" => "$_POST[name]",
            "detail"    => "$_POST[detail]",
            "status"    => $_POST["status$id"],
        );
    $flgIn=$db->updateAry("liveclass",$aryData, "where id='$_POST[liveclass_id]' ");

    if($flgIn > 0){
	       // echo "success";
	   }else{
	       //echo "error";
	        //echo $db->getErMsg()."||".$db->getLastQuery();
	   }
    
}
?>

<!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>Previous Video</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;">
                    
                    <!--<h2 class="bg-dark text-white text-center p-2">LIVE PREVIOUS VIDEOS</h2>-->
                    <h4 class="bg-info text-white text-center p-2">LIVE PREVIOUS VIDEOS</h4>

                            <table class="table table-sm table-hover table-striped">
                                <tr>
                                    <th>S.No.</th>
                                    <th>Video</th>
                                    <th>Chapter</th>
                                    <th>Topic</th>
                                    <th>URL</th>
                                    <th>Status</th>
                                    <th>Actions</th>
                                </tr>

                                <?php $previousvideos = $db->getRows("select * from liveclass order by id DESC ");
                                $i = 0;
                                    foreach($previousvideos as $video){ $i++;
                                        
                        			    $url_string = "$video[video_url]";
                                        $filepath = str_replace('watch?v=','embed/', $url_string);
                                        ?>
                                        <form method="post" action="">
                                            <input type="hidden" name="liveclass_id" value="<?php echo $video[id]; ?>" />
                                        <tr>
                                            <td><?php echo $i; ?></td>
                                            <td>
                                                <iframe width="140" height="140" src="<?php echo $filepath; ?>"></iframe>
                                            </td>
                                            <td><input type="text" name="name" value="<?php echo $video[name]; ?>" class="form-control"></td>
                                            <td><input type="text" name="detail" value="<?php echo $video[detail]; ?>" class="form-control"></td>
                                            <td><?php echo $video[video_url]; ?></td>
                                            <td style="width:90px;">
                                                <label style="color:blue;font-weight:bold;"><input type="radio" name="status<?php echo $video[id]; ?>" value="1" <?php if($video['status']==1)echo "checked"; ?> /> Initiate </label><br>
                                                <label style="color:green;font-weight:bold;"><input type="radio" name="status<?php echo $video[id]; ?>" value="2"<?php if($video['status']==2)echo "checked"; ?>> Live </label><br>
                                                <label style="color:red;font-weight:bold;"><input type="radio" name="status<?php echo $video[id]; ?>" value="3" <?php if($video['status']==3)echo "checked"; ?>> Offline </label>
                                            </td>
                                            <td>
                                                <button type="submit" class="btn btn-success" style="padding:5px;width:80px;">Save</button>
                                                <button onclick="delete_previouslive('<?php echo $video[id]; ?>')" class="btn btn-danger" style="padding:5px;width:80px;margin-top:10px;">Delete</button>
                                            </td>
                                        </tr>
                                        </form>
                                        <?php
                                    }
                                ?>
                

                            </table>


                </div>

                          </div>
                        </div>
                      </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>
//$(document).ready(function(){

function delete_previouslive(id){
    // alert(id);
    var r = confirm("Are you sure want to delete?");
  if (r == true) {
    $.post("ajax.php", { type: "delete_previouslive" , id: id } , function( data ) {

// alert(data);

    });
  }
}

// });



</script>


  </body>
</html>