
<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>
            <!-- TOP Nav Bar END -->
            <div class="container-fluid">
               <div class="row">
                  <div class="col-sm-12">
                     <div class="iq-card">
                        <div class="iq-card-header d-flex justify-content-between">
                           <div class="iq-header-title">
                              <h4 class="card-title">Doctors Category</h4>
                           </div>
                           <span class="table-add float-right mb-3 mr-2">
                              <a href="javascript:void(0)" class="btn btn-sm iq-bg-success" data-toggle="modal" data-target="#catAdd_popup"><i
                                 class="ri-add-fill"><span class="pl-1">Add New</span></i>
                              </a>
                              </span>
                        </div>
                        <div class="iq-card-body">
                           <div id="table" class="table-editable">
                              
                              
             <table id="myTable" class="display table" style="width:100%">
              <thead>
                <tr>
                  <th>SL. No.</th>
                  <th>Doctor Category</th>              
                  <th>Status</th>                
                  <th>Action</th>
                </tr>
              </thead>
              <tbody>
                <?php  
                $start=0;
                for($i=0;$i<count($recordSet);$i++)
                   { $start++;
                ?>
                <tr class="trBack">
                  <td scope="row"><?php echo $start; ?></td>
                  <td><?php echo $recordSet[$i]['dcat_name']; ?></td>
                  <td><button type="button" class="btn <?php if($recordSet[$i]['dcat_status']=='1'){ ?> btn-success <?php } else { ?> btn-danger <?php } ?> btn-xs" onclick="status_change(<?php echo  $recordSet[$i]['dcat_id']; ?>,<?php echo  $recordSet[$i]['dcat_status']; ?>);"><?php if($recordSet[$i]['dcat_status']=='1'){ ?> Active <?php } else { ?> Inactive <?php } ?></button></td>


                  <td><a href="javascript:void(0)" onclick="delete_function(<?php echo $recordSet[$i]['dcat_id']; ?>);" class="delete remScnt" title="Delete"><i class="fa fa-trash" style="color:red;" aria-hidden="true" title="Delete"></i> </a>&nbsp;<a href="javascript:void(0)" onclick="edit_modal('<?php echo $recordSet[$i]['dcat_id']; ?>');" class="delete remScnt" title="Delete"><i class="fa fa-pencil" style="color:green;" aria-hidden="true" title="Edit"></i> </a></td>
                </tr>

              <?php } ?>
              </tbody>
            </table>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
            <!-- Footer -->
      

<style type="text/css">
  table.dataTable thead .sorting, 
table.dataTable thead .sorting_asc, 
table.dataTable thead .sorting_desc {
    background : none;
}
</style>
<script type="text/javascript">
function edit_modal(dcat_id)

  { 

     $('#CatEdit').modal('show');
     $.post('<?php echo base_url();?>DoctorCategory/cat_edit_details/', {'dcat_id':dcat_id}, function(data) {

   $("#EditData").html(data);
})
  }
  function delete_function(id) {

$.confirm({
    title: 'Delete!',
    content: 'Are you want to delete this data?',
    type: 'red',
    typeAnimated: true,
    buttons: {
        tryAgain: {
            text: 'Yes',
            btnClass: 'btn-red',
            action: function(){
              
              $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>DoctorCategory/Delete/",
          data: {id : id }, 
          success: function(html) {
            $.alert("Your data has been successfully deleted");
            setInterval(function(){
              location.reload();
            }, 3000);
            }
          });
            }
        },
        close: function () {
        }
    }
 });
}

function status_change(id,status){
if (status=='1') {
  var new_status='0';
$.confirm({
    title: 'Change Status!',
    content: 'Are you want to inactive?',
    type: 'red',
    typeAnimated: true,
    buttons: {
        tryAgain: {
            text: 'Yes',
            btnClass: 'btn-red',
            action: function(){
              
              $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>DoctorCategory/status_change/",
          data: {id : id, new_status: new_status }, 
          success: function(html) {
            $.alert("Your Status has been Changed");
            setInterval(function(){
              location.reload();
            }, 3000);
            }
          });
            }
        },
        close: function () {
        }
    }
 });



}
else {
  var new_status='1';

$.confirm({
    title: 'Change Status!',
    content: 'Are you want to active?',
    type: 'green',
    typeAnimated: true,
    buttons: {
        tryAgain: {
            text: 'Yes',
            btnClass: 'btn-green',
            action: function(){
              
              $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>DoctorCategory/status_change/",
          data: {id : id, new_status: new_status }, 
          success: function(html) {
            $.alert("Your Status has been Changed");
            setInterval(function(){
              location.reload();
            }, 3000);
            }
          });
            }
        },
        close: function () {
        }
    }
 });
}
}
</script>
<!-- /////////////////////////////Add Category//////////////////////////////////////////////// -->
<div class="modal fade" id="catAdd_popup">
  <div class="modal-dialog">
    <div class="modal-content">
      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Category Add</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
        <div class="alert alert-success Addmsg" style="display: none;">
          <strong>Successfully Added Your Data!</strong>
        </div>
        <div class="alert alert-danger Adderror" style="display: none;">
            <strong>Duplicate Entry!</strong>
        </div>
      <form id="addfrm" method="post">
        <!-- Modal body -->
        <div class="modal-body">
          <div class="row">
          <div class="form-group">
              <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                  <label>Category Name</label>
                  <input type="text" name="dcat_name" id="dcat_name" class="form-control" required=""  aria-required="true">
                  <br>
              </div>
          </div>
          </div>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
          <button type="submit" class="btn btn-primary">Save</button>
        </div>
      </form>
    </div>
  </div>
</div>
<script>
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
success: "valid"
});
$("#addfrm").validate({
rules: {
cat_name: {
required: true
}
}
});
</script>
<script>
$(document).ready(function(e) {
$("#addfrm").on('submit', function(e) {
e.preventDefault();
var formStatus = $('#addfrm').validate().form();
if (true == formStatus) {
$.ajax({
type: 'POST',
url: '<?php echo base_url(); ?>DoctorCategory/save',
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
beforeSend: function() {
$('.addbtn').hide();
$('.addload').show();
},
success: function(msg) {
if(msg=='success')
{
$(".Addmsg").show();
$('.Addmsg').delay(3000).hide(200);
$('.addbtn').show();
$('.addload').hide();
setInterval(function() {
location.reload();
}, 3000);
}
else
{
$(".Adderror").show();
$('.Adderror').delay(3000).hide(200);
$('.addbtn').show();
$('.addload').hide();

}
}
});
}
});
});
</script>
<!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////// -->
<!-- /////////////////////////////Edit Category//////////////////////////////////////////////// -->
<div class="modal fade" id="CatEdit">
  <div class="modal-dialog">
    <div class="modal-content">
      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Category Edit</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
        <div class="alert alert-success Addmsg" style="display: none;">
          <strong>Successfully Edited Your Data!</strong>
        </div>
        <div class="alert alert-danger Adderror" style="display: none;">
            <strong>Duplicate Entry!</strong>
        </div>
      <form id="Editfrm" method="post">
        <!-- Modal body -->
        <div class="modal-body" id="EditData">
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
          <button type="submit" class="btn btn-primary">Save</button>
        </div>
      </form>
    </div>
  </div>
</div>
<script>
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
success: "valid"
});
$("#Editfrm").validate({
rules: {
dcat_name: {
required: true
}
}
});
</script>
<script>
$(document).ready(function(e) {
$("#Editfrm").on('submit', function(e) {
e.preventDefault();
var formStatus = $('#Editfrm').validate().form();
if (true == formStatus) {
$.ajax({
type: 'POST',
url: '<?php echo base_url(); ?>DoctorCategory/Edit_data',
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
beforeSend: function() {
$('.addbtn').hide();
$('.addload').show();
},
success: function(msg) {
if(msg=='success')
{
$(".Addmsg").show();
$('.Addmsg').delay(3000).hide(200);
$('.addbtn').show();
$('.addload').hide();
setInterval(function() {
location.reload();
}, 3000);
}
else
{
$(".Adderror").show();
$('.Adderror').delay(3000).hide(200);
$('.addbtn').show();
$('.addload').hide();

}
}
});
}
});
});
</script>
<!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////// -->
<div class="modal fade" id="import_popup">
  <div class="modal-dialog">
    <div class="modal-content">
      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Import Data</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <div class="alert alert-success Addmsg" style="display: none;">
          <strong>Successfully Imported Your Data!</strong>
        </div>
        <div class="alert alert-danger statusfailed" style="display: none;">
          <strong>Please Try Again </strong>
        </div>
      </div>
      <form id="import_form" method="post">
        <!-- Modal body -->
        <div class="modal-body">
          <div class="row">
          <div class="form-group">
              <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                  <label>Import Data</label>
                  <input type="file" name="import_data" id="import_data" class="form-control" required=""  aria-required="true">
                  <br>
              </div>
          </div>
          <div class="form-group">
              <a href="<?php echo base_url(); ?>img/demo/employee.csv" style="margin-left: 10px;"><i class="fa fa-download" aria-hidden="true"></i> &nbsp; Download CSV Format</a>
          </div>
          </div>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
          <button type="submit" class="btn btn-primary">Save</button>
        </div>
      </form>
    </div>
  </div>
</div>
<script>
// just for the demos, avoids form submit
jQuery.validator.setDefaults({
success: "valid"
});
$("#import_form").validate({
rules: {
import_file: {
required: true
}
}
});
</script>
<script>
$(document).ready(function(e) {
$("#import_form").on('submit', function(e) {
e.preventDefault();
var formStatus = $('#import_form').validate().form();
if (true == formStatus) {
$.ajax({
type: 'POST',
url: '<?php echo base_url(); ?>category/import/',
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
beforeSend: function() {
$('.addbtn').hide();
$('.addload').show();
},
success: function(msg) {
$(".Addmsg").show();
$('.Addmsg').delay(3000).hide(200);
$('.addbtn').show();
$('.addload').hide();
setInterval(function() {
location.reload();
}, 3000);
}
});
}
});
});
</script>