<?php 
    include("../db.php");
    
    //insert
   
  
       
        if($_POST){
          
    
            $_POST['type']='submenu';
        $_POST['status']=1;
            $db->insertAry("extra_menu", $_POST);
              header("Location: extra");
            
        }

      
    
    //end
if($_GET['action']=="delete" && isset($_GET['id']) && trim($_GET['id'])!=''){
    
   
 	$res=$db->delete("extra_menu","where id='".$_GET['id']."' ");
     header("Location: extra");
}
    
    
   
?>

<!DOCTYPE html>
<html>
<head>
      <title>Admin Dashboard</title>
    <?php include("meta.php"); ?>

</head>
<body> 
 
<?php include("header.php"); ?>

<?php include("sidebar.php"); 

    $data = $db->getRows("select * from extra_menu  ");

?>

<div class="main">
    
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="content-div">
                    <h2>EXTRA MENUS</h2>
                    <div>
                    <button  style="background: #007bff;color: white;font-size: 20px;margin-bottom:4px; " data-toggle="modal" data-target="#exampleModal"><i class="fa fa-plus-circle"></i>Add New Submenu</button>
                    </div>
                    <table class="table table-hover">
  <thead class="bg-black text-white font-weight-bold ml-3" style="font-size: 15px;">
    <tr>
            <th scope="col">S.no</th>

      <th scope="col">Link Name</th>
      <th scope="col">Heading</th>
      <th scope="col">Type</th>
       <th scope="col">Action</th>
    </tr>
  </thead>
  <tbody>
      <?php 
      $i=0;
      foreach($data as $res){$i++
          
          ?>
           <tr >
                <th  style="font-weight: 600; color: green;padding: 0.75rem;" ><?php echo $i;?></th>
      <th  style="font-weight: 600; color: green;padding: 0.75rem;" ><?php echo $res['linkname'];?></th>
      <th style="padding: 0.75rem;" ><?php echo $res['heading'];?></th>
       <th style="padding: 0.75rem;" ><?php echo $res['type'];?></th>
     <td>
         <a style="background: #28a745;color:white" class="btn btn-primary edit_data" href="sub_menu.php?id=<?php echo $res['id']; ?>"" ><i class="fa fa-eye"></i>View</a>
         <a class="btn btn-primary edit_data" href="edit_extra?action=delete&id=<?php echo $res['id']; ?>" ><i class="fa fa-edit"></i></a>
     <a href="extra?action=delete&id=<?php echo $res['id']; ?>" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i></a></td>
    </tr>
    <?php  }?>
   
  
  </tbody>
</table>
<!-- Button trigger modal -->


 <!--Modal add -->
<div class="modal fade " id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add New Menu</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 action="" method="post" >
    <div class="form-group">
    <label for="exampleInputEmail1">Link Name</label>
    <input type="text" class="form-control" name="linkname" required  placeholder="Enter link name">
    
  </div>
  <div class="form-group mt-3">
    <label for="exampleInputPassword1">Heading</label>
    <input type="text" class="form-control" name="heading" required placeholder="heading">
  </div>

  <button type="submit"  class="btn btn-success mt-4">Save</button>
</form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
       
      </div>
    </div>
  </div>
</div>
 
                    
                </div>

            </div>   
        </div>
    </div>
    
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
     <script>  
 
function edit(id){
	 
	$.post( "ajax.php", { type:"edit", id: id } , function( data ) {
	    let value=$.parseJSON(data);
	   // alert(value.id);
$('#id').val(value.id);  
                     $('#service').val(value.service);  
                     $('#desc').val(value.description); 
                     var imgHtml = "<img src='../uploads/"+ value.image+"' alt='something'id='ig' value='"+value.image+"' style='width: 100px;'>";
                    
                       $("#img").html(imgHtml);
                     $('#editmodal').modal('show');  
	});
}
function update(){
	 var str = $("#id").val();
	  var service = $("#service").val();
	  var desc = $("#desc").val();
	  
	  var pic = $("#pic").val();
	 
	$.post( "ajax.php", { type:"update", id: str, service:service,desc:desc,pic:pic} , function( data ) {
	    
	});
}
 </script>
</body>
</html> 
