<div class="container-fluid">
    <div>
        <h3>Invitation Codes</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Tools</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Invitation Codes</li>
            </ol>
        </nav>
    </div>
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="card-body">
					<form id="add-invitation" class="pull-right"><button type="submit" class="btn btn-warning waves-effect waves-light m-t-20">Generate New Code</button></form>
                  <h6 class="card-title">Manage Invitation Codes</h6>
                  
                     <div>This system is used to invite users to your site if the registration system is turned off.</div>
                     <br>
                   <div class="table-responsive1">
                        <table class="table table-bordered table-striped table-hover">
                            <thead>
                                <tr>
                                  <th><input type="checkbox" id="check-all" class="filled-in check-all" ><label for="check-all"></label></th>
                                   <th>ID</th>
                                   <th>Created</th>
					               <th>Invitation Code</th>
					               <th>Status</th>
					               <th>Action</th>
                                </tr>
                            </thead>
                            <tbody class="manage-invitation-list">
                                <?php 
				                foreach (GetAdminInvitation() as $wo['invitation']) {
				                    echo Wo_LoadAdminPage('manage-invitation-keys/list');
				                }
				                ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="clearfix"></div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3">
                                <span>&nbsp;</span>
                                <button type="button" class="btn btn-primary waves-effect delete-selected d-block" disabled>Delete Selected<span></span></button>
                            </div>
                        </div>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    </div>
    <!-- #END# Vertical Layout -->
<div class="modal fade" id="DeleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModal1Label" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModal1Label">Delete Code?</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Are you sure you want to delete this Code?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">Delete</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="SelectedDeleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModal1Label" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModal1Label">Delete Code?</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Are you sure that you want to remove the selected Code?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" onclick="DeleteSelected()" data-dismiss="modal">Submit</button>
            </div>
        </div>
    </div>
</div>
<script>
$('.check-all').on('click', function(event) {
    $('input:checkbox').not(this).prop('checked', this.checked);
});
$('.delete-checkbox, .check-all').change(function(event) {
    $('.delete-selected').attr('disabled', false);
    $('.delete-selected').find('span').text(' (' + $('.delete-checkbox:checked').length + ')');
});

$('.delete-selected').on('click', function(event) {
    event.preventDefault();
    $('#SelectedDeleteModal').modal('show');
});
function DeleteSelected() {
    data = new Array();
    $('td input:checked').parents('tr').each(function () {
        data.push($(this).attr('data_selected'));
    });
    $('.delete-selected').attr('disabled', true);
    $('.delete-selected').text('Please wait..');
    $.post(Wo_Ajax_Requests_File()+"?f=admin_setting&s=remove_multi_code", {ids: data}, function () {
        $.each( data, function( index, value ){
            $("tr[data-invitation='"+value+"']").remove();
        });
        $('.delete-selected').text('Delete Selected');
    });
}
function DeleteBan(id,type = 'show') {
  if (type == 'hide') {
      $('#DeleteModal').find('.btn-primary').attr('onclick', "DeleteBan('"+id+"')");
      $('#DeleteModal').modal('show');
      return false;
    }
 $("tr[data-invitation='"+id+"']").remove();
 $.ajax({
    url:  Wo_Ajax_Requests_File(),
    type: 'GET',
    dataType: 'json',
    data: {f: 'admin_setting',s:'rm-invitation',id:id},
 })
 .done(function(data) {
    if (data.status == 200) {
       
    }
 })
 .fail(function() {
    console.log("error");
 })
}
jQuery(document).ready(function($) {
      $('#add-invitation').ajaxForm({
      url: Wo_Ajax_Requests_File(),
      type:'GET',
      dataType:'json',
      data: {f: 'admin_setting',s:'insert-invitation'},
      beforeSend: function() {
        $('#add-invitation').find('button').text('Please wait..');
      },
      success: function(data) {
        if (data.status == 200) {
            if ($('tr.setting-invitation').length > 0) {
               $('.manage-invitation-list').prepend(data.html);            
            }
            else{
               $('.manage-invitation-list').html(data.html); 
            }
        } 
        $('#add-invitation').find('button').text('Generate New Code');
      }});

      $(document).on('click', '.copy-invitation-url', function(event) {
         event.preventDefault();
           var $temp = $("<input>");
           $("body").append($temp);
           $temp.val($(this).attr('data-link')).select();
           document.execCommand("copy");
           $temp.remove();
           $(this).addClass('main');
      });

   });
</script>