<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.js"></script>
<main class="main-content bgc-grey-100">
  <div id="mainContent">
    <div id="snackbar">Banner Status Successfully Changed!</div>
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-12">
          <div class="bgc-white bd bdrs-3 p-20 mB-20">
          <div><span class="icon-holder"><i class="c-pink-500 ti-link"></i> </span><a href="<?php echo base_url(); ?>AdminDashboard/">Dashboard</a> / <a href="">Show All Events</a> 
            <div class="clearfix"></div></div>
          </div>
        </div>
        
        <div class="col-md-12">
          <div class="bgc-white bd bdrs-3 p-20 mB-20">
            <h4 class="c-grey-900 mB-20">All Events</h4>
            <table class="table table-striped" id="example">
              <thead>
                <tr>
                  <th scope="col">SL. No.</th>
                  <th scope="col">Name</th>
                  <th scope="col">Email</th>
                  <th scope="col">Mobile</th>
                  <th scope="col">Action</th>
                </tr>
              </thead>
              <tbody>
                <?php  
                $start=0;
                for($i=0;$i<count($recordSet);$i++)
                   { $start++;
                    $datetime = $this->db->select('*')->where('event_id', $recordSet[$i]['event_id'])->get('event_datetime')->result_array();
                    $banner = $this->db->select('*')->where('type_id', $recordSet[$i]['event_id'])->where('type', 'Event')->get('banner')->result_array();
                ?>
                <tr>
                  <th scope="row"><?php echo $start; ?></th>
                  <td><?php echo $recordSet[$i]['event_title']; ?></td>
                  <td><?php echo $datetime[0]['event_date']; ?></td>
                  <td><?php echo $datetime[0]['event_time']; ?></td>
                  <td><?php echo $recordSet[$i]['event_type']; ?></td>
                  <td><img src="<?php echo base_url(); ?>uploads/event_image/<?php echo $recordSet[$i]['event_image']; ?>" class="img-responsive" width="100px" height="100px"></td>
                  <td><?php echo $recordSet[$i]['event_duration_from'].' To '.$recordSet[$i]['event_duration_to']; ?></td>
                  <td><?php if($banner[0]['type_id']==$recordSet[$i]['event_id']){ ?><button class="btn btn-success" onclick="return show_banner_modal(<?php echo $recordSet[$i]['event_id'];?>);" type="button">In Banner</button><?php } else{?><button class="btn btn-primary" onclick="return show_banner_modal(<?php echo $recordSet[$i]['event_id'];?>);" type="button">Push Banner</button><?php } ?></td>
                  <td><a href="javascript:void(0)" onclick="return show_modal(<?php echo $recordSet[$i]['event_id'];?>);" title="Delete"><i class="ti-eye" style="color:blue;" aria-hidden="true" title="Delete"></i> </a>&nbsp;<a href="javascript:void(0)" id="DelData<?php echo  $recordSet[$i]['event_id']; ?>" class="delete remScnt" title="Delete"><i class="ti-trash" style="color:red;" aria-hidden="true" title="Delete"></i> </a>&nbsp;<a href="<?php echo base_url().'Events/Edit/'.$recordSet[$i]['event_id']; ?>" class="delete remScnt" title="Delete"><i class="ti-pencil" style="color:green;" aria-hidden="true" title="Edit"></i> </a></td>
                </tr>
<script type="text/javascript">
  $("#DelData<?php echo  $recordSet[$i]['event_id']; ?>").click(function (){
  $.confirm({
    title: 'Delete!',
    content: 'Are you want to delete this data?',
    type: 'red',
    typeAnimated: true,
    buttons: {
        tryAgain: {
            text: 'Yes',
            btnClass: 'btn-red',
            action: function(){
              var id ="<?php echo $recordSet[$i]['event_id']; ?>";
              $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>Events/Delete/",
          data: {id : id }, 
          success: function(html) {
            $.alert("Your data has been successfully deleted");
            setInterval(function(){
              location.reload();
            }, 3000);
            }
          });
            }
        },
        close: function () {
        }
    }
 });
});
</script>
              <?php } ?>
              </tbody>
            </table>
         
          </div>
        </div>
      </div>
    </div>
  </div>
</main>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script> -->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
  $(document).ready( function () {
    $('#example').DataTable({
      "ordering": false,
      // "processing": true,
      // "serverSide": true,
      // "ajax": "<?php echo base_url(); ?>/Events/data_table/"
    });
} );
</script>
<script type="text/javascript">
  function show_modal(event_id){
    // $("#basicExampleModal").modal('show');
      $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>Events/details_show/",
          data: "event_id=" + event_id,
          cache: false,
          success: function(html) {
            $("#basicExampleModal").modal('show');
             $("#DynamicData").html(html);
          }
      });
    }
</script>

<script type="text/javascript">
  function show_banner_modal(event_id){
    // $("#basicExampleModal").modal('show');
      $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>Events/banner_show/",
          data: "event_id=" + event_id,
          cache: false,
          success: function(html) {
            $("#BannerModal").modal('show');
             $("#BannerData").html(html);
          }
      });
    }
</script>

<script>
$(document).ready(function(e){
    $("#BannerForm").on('submit', function(e){
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: '<?php echo base_url(); ?>Events/banner_set/',
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
            beforeSend: function(){
                $('.login_button').attr("disabled","disabled");
                $('#BannerForm').css("opacity",".5");
            },
            success: function(msg){
                  $(".SuccMsg").show();
                  $('.SuccMsg').delay(3000).hide(300);
                  $('#BannerForm').css("opacity","");
                  $(".login_button").removeAttr("disabled");
                   setInterval(function(){ 
                   location.reload();
                  }, 3000);
               
            }
        });
    });
});
</script>