<?php include('../config/setup.php');?>
<?php 

if($_SERVER['REQUEST_METHOD'] == 'POST'){
    
    $action = $_POST['action'];

// social_media_master
    // social_media update query starts
    if($action == 'sm_edit'){
        $sm_facebook_link = $_POST['sm_facebook_link'];
        $sm_instagram_link = $_POST['sm_instagram_link'];
        $sm_youtube_link = $_POST['sm_youtube_link'];
        $sm_whatsapp = $_POST['sm_whatsapp'];
        $sm_status = $_POST['sm_status'];
        
        $sql = "UPDATE social_media_master SET sm_facebook_link = '$sm_facebook_link' , sm_instagram_link = '$sm_instagram_link' , sm_youtube_link = '$sm_youtube_link' , sm_whatsapp = '$sm_whatsapp', sm_status = '$sm_status' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Updated successfully" ;
            $_SESSION['alert'] = "success" ;
        }else{
            $_SESSION['status'] = "Update Failed" ;
            $_SESSION['alert'] = "success" ;
        }
    }
    // social_media update query ends

}


?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title></title>
	<meta content='width=device-width, initial-scale=1.0, shrink-to-fit=no' name='viewport' />
	<link rel="icon" href="" type="image/x-icon"/>
	
	<!-- Fonts and icons -->
	<script src="../assets/js/plugin/webfont/webfont.min.js"></script>
	<script>
		WebFont.load({
			google: {"families":["Lato:300,400,700,900"]},
			custom: {"families":["Flaticon", "Font Awesome 5 Solid", "Font Awesome 5 Regular", "Font Awesome 5 Brands", "simple-line-icons"], urls: ['../assets/css/fonts.min.css']},
			active: function() {
				sessionStorage.fonts = true;
			}
		});
	</script>
	<!-- Fontawesome 6.1 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" />

	<!-- CSS Files -->
	<link rel="stylesheet" href="../assets/css/bootstrap.min.css">
	<link rel="stylesheet" href="../assets/css/atlantis.min.css">
	<!-- CSS Just for demo purpose, don't include it in your project -->
	<link rel="stylesheet" href="../assets/css/demo.css">
	<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
</head>
<body>
	<div class="wrapper">
		<div class="main-header">
			<!-- Logo Header -->
			<?php include('logo.php');?>
			<!-- End Logo Header -->

			<!-- Navbar Header -->
			<?php include('topbar.php');?>
			 <!-- End Navbar -->
		</div>
		<!-- Sidebar -->
		<?php include('sidebar.php');?>
		
		
		<div class="main-panel">
			<div class="content">
				<div class="page-inner">
					<div class="page-header">
						<h4 class="page-title">Social Media Links</h4> 
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="card">
								<div class="card-body">
									<div class="table-responsive">
										<table id="basic-datatables" class="display table table-striped table-hover" >
											<thead>
												<tr>
													<th>S.No</th>
													<th>Facebook Link</th>
													<th>Instagram Link</th>
													<th>Youtube Link</th>
													<th>Whatsapp</th>
													<th>Status</th>
													<th>Action</th>
												</tr>
											</thead>
											<tbody>
												<?php 
												    $sno = 1;
													$sql = "SELECT * FROM social_media_master ";
													$res = $config->query($sql);
													$row = $res->fetch_assoc();
													$name_status = $row['logo_name_status'];
													$status = $row['sm_status'];
												?>
												<tr>
													<td><?= $sno; ?></td>
													<td><?= $row['sm_facebook_link'] ?></td>
													<td><?= $row['sm_instagram_link'] ?></td>
													<td><?= $row['sm_youtube_link'] ?></td>
													<td><?= $row['sm_whatsapp'] ?></td>
													<td>
													    <?php if($status == 1){ ?>
													    <button class="btn btn-success">Active</button>
													    <?php }else{ ?>
													        <button class="btn btn-danger">In-Active</button>
													    <?php } ?>
                                                    </td>
													<td>
													    <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#social"> <i class="fas fa-pencil-alt"></i>  </a>
                                                    </td>

                                                    <!-- Modal -->
                                                    <div class="modal fade" id="social" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                        <div class="modal-dialog" role="document">
                                                            <div class="modal-content">
                                                                <div class="modal-header">
                                                                    <h5 class="modal-title" id="exampleModalLabel">Social Media Edit</h5>
                                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                        <span aria-hidden="true">&times;</span>
                                                                    </button>
                                                                </div>
                                                                <div class="modal-body">
                                                            	    <form method="post" enctype="multipart/form-data">
                                                                        <div class="form-group">
                                                            			    <label for="sm_facebook_link">Facebook Link</label>
                                                            			    <input type="text" class="form-control" id="sm_facebook_link" name="sm_facebook_link"  value="<?= $row['sm_facebook_link'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="sm_instagram_link">Instagram Link</label>
                                                            			    <input type="text" class="form-control" id="sm_instagram_link" name="sm_instagram_link"  value="<?= $row['sm_instagram_link'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="sm_youtube_link">Youtube Link</label>
                                                            			    <input type="text" class="form-control" id="sm_youtube_link" name="sm_youtube_link"  value="<?= $row['sm_youtube_link'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="sm_whatsapp">Whatsapp </label>
                                                            			    <input type="text" class="form-control" id="sm_whatsapp" name="sm_whatsapp"  value="<?= $row['sm_whatsapp'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                        												    <label for="sm_status">Status</label>
                        												    <select class="form-control" id="sm_status" name="sm_status">
                        												    <?php if($status == 1){ ?>
                            													<option value="1" >Active</option>
                            													<option value="0">In-Active</option>
                        													<?php }else{ ?>
                            													<option value="0" >In-Active</option>
                            													<option value="1" >Active</option>
                        													<?php } ?>
                            												</select>
                            											</div>	
                                                                        <div class="form-group">
                                        									<input type="hidden" name="action" value="sm_edit">
                                        									<button class="btn btn-warning" type="submit" name="submit">Submit</button>
                                         								</div>
                                                        		    </form>	
                                                                </div>
                                                                <div class="modal-footer">
                                                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
	                </div>
				</div>
			</div>
		<?php include('footer.php');?>	
		 
		</div>
		<!-- End Custom template -->
	</div>
	<script>
	<?php if(isset($_SESSION['status']) && !empty($_SESSION['status'])){ ?>
	    swal({
          title: "<?= $_SESSION['status'] ?>",
          text: "",
          icon: "<?= $_SESSION['alert'] ?>",
        });
    <?php unset($_SESSION['status']); } ?>
	</script>
	<!--   Core JS Files   -->
	<script src="../assets/js/core/jquery.3.2.1.min.js"></script>
	<script src="../assets/js/core/popper.min.js"></script>
	<script src="../assets/js/core/bootstrap.min.js"></script>
	<!-- jQuery UI -->
	<script src="../assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
	<script src="../assets/js/plugin/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>
	
	<!-- jQuery Scrollbar -->
	<script src="../assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
	<!-- Datatables -->
	<script src="../assets/js/plugin/datatables/datatables.min.js"></script>
	<!-- Atlantis JS -->
	<script src="../assets/js/atlantis.min.js"></script>
	<!-- Atlantis DEMO methods, don't include it in your project! -->
	<script src="../assets/js/setting-demo2.js"></script>
	<script >
		$(document).ready(function() {
			$('#basic-datatables').DataTable({
			});

		 
 
			 
		});
	</script>
</body>
</html>