<?php
    
    include("../include/header.php");
    if ( isset( $_POST['newsSubmitBtn'] ) ) {
        
        $url = mysqli_real_escape_string($conn,$_POST['txtname']);
        
        preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);
        
          $youtube_id = $match[1];
          
          $query=mysqli_query($conn,"insert into `youtube`(`url`)values('$youtube_id')");
          if($query){
              
              echo "<script>alert('youtube added successfully');
                    window.location.href='';
              </script>";
              
              
          }else{
              
               echo "<script>alert('youtube added failed');
                    
              </script>";
          }
    }
    
?>

<style>
.user_detils_footer{
    display:none;
}
	#testimonials ul li:nth-child(3) {
		background-color: #eb6a4e;
	}

	#testimonials ul li:nth-child(3) a {
		color: #fff;
	}

	#testimonials ul li:nth-child(3) a:hover {
		background-color: #eb6a4e;
	}

	#testimonials .course-detailsa img{
		width: 100% !important;
		max-height: 250px !important;
	}
</style>
<script>
	window.onload = function() {
		document.getElementById('testimonials1').classList.add("active");
		document.getElementById('testimonials2').classList.add("in");
	};

</script>

<div class="small-header">
	<div class="hpanel">
		<div class="panel-body">
			<div id="hbreadcrumb" class="pull-right">
				<ol class="hbreadcrumb breadcrumb">
					<li><a href="<?php echo $admin_baseurl . 'dashboard.php';?>">Dashboard</a></li>
					<li class="active">
						<span>Youtbe</span>
					</li>
				</ol>
			</div>
			<h2 class="font-light m-b-xs">
				Youtube Details
			</h2>

		</div>
	</div>
</div>


<div class="content">
	<div class="hpanel">
		<div class="hpanel">
			<div class="panel-heading hbuilt">
				<div class="panel-tools">
					<a class="showhide"><i class="fa fa-chevron-up"></i></a>
					<a class="fullscreen"><i class="fa fa-expand"></i></a>
				</div>
				Add News Youtube
			</div>
			<div class="panel-body">
				<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
					<div class="form-group">
						<div class="col-md-12">
							<label class="control-label">Youtube Url</label>
							<input type="url" name="txtname" class="form-control" placeholder="Enter Youtbe Url" required>
						</div>
						

					
					
					


						<div class="col-md-12">
							<div class="form-group" style="padding:0 20px;">
								<br>
								<div class="text-right">
									<button type="reset" class="btn btn-default">Cancel</button>
									<button type="submit" name="newsSubmitBtn" class="btn btn-primary">Submit</button>
								</div>
							</div>
						</div>
					</div>


				</form>
			</div>

		</div>
	</div>
</div>




<br>
<!--show news-->
        <div class="content">



	<div class="hpanel">
		<div class="panel-heading hbuilt">
			<div class="panel-tools">
				<a class="showhide"><i class="fa fa-chevron-up"></i></a>
				<a class="fullscreen"><i class="fa fa-expand"></i></a>
			</div>
			View All youtube url
		</div>
		<div class="panel-body">
			<div class="table-responsive">
				<table id="userPermission_dataTable11" class="table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th>#</th>
						
							    <th>Youtube Video</th>
								<th>Action</th>
						</tr>
					</thead>
				<tbody>
				    
				    <?php
				    $fetch=mysqli_query($conn,"select * from `youtube` ");
				    $i=0;
				    while($data=mysqli_fetch_assoc($fetch)){
				        $i++;
				        
				        $id=$data['id'];
				        ?>
				        <tr>
				            
				            <td><?php echo $i; ?></td>
				             <td><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal<?php echo $id;?>">Show video</button></td>
				              <td><a href="delete-youtube.php?id=<?php echo $id; ?>" class="btn btn-danger" onclick="return confirm('Are you sure want to delete?')">Delete</a></td>
				        </tr>
				        
				        				        
				        <div class="modal" id="myModal<?php echo $id;?>">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
       
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
       <object width="420" height="315"
data="https://www.youtube.com/embed/<?php echo $data['url'];?>">
</object>
      </div>

      <!-- Modal footer -->
    

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

	</div>
	</div>

<!--show news end -->
<?php 
    include('../include/footer.php');
?>
 
       
