<div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>
                   Manage Subadmins
                </h1>
              <ol class="breadcrumb">
                    <li><a href="<?php echo base_url();?>admin"><i class="fa fa-home"></i>Home</a></li>
                    <li class="active">Manage Subadmins</li><li class="active">All Subadmins</li>
                </ol>
            </section>
            <!-- Main content -->
            <div class="content">
           
                <div class="container-fluid">
                 
                    <!-- Tabs -->
                    <!-- third row  -->
                    <div class="row"> 
                        <div class="col-md-4 col-sm-12">
                        <?php if($this->session->flashdata("msg")!==""){ echo $this->session->flashdata("msg");}?>
                        <div class="panel panel-primary">
                              <div class="panel-heading">Add New Subadmin</div>
                              <div class="panel-body">
                                <?php if($this->uri->segment(3)){?>

                                <form action="<?php echo base_url();?>admin/update_subadmin" method="post" enctype="multipart/form-data">
        
                                      <input type="hidden" name="subadmin_id" value="<?php echo $edit->subadmin_id;?>" />                              
        
                                      <div class="form-group "> <label for="email">Name</label>
        
                                        <input type="text" required class="form-control" value="<?php echo $edit->subadmin_name;?>" name="subadmin_name">
        
                                      </div
        
                                      ><div class="form-group">
        
                                        <label for="email">Mobile</label>
        
                                        <input type="text"  class="form-control" maxlength="10" onkeypress="return isNumberKey(event);" value="<?php echo $edit->subadmin_phone;?>" name="subadmin_phone" required>
        
                                       
        
                                      </div>
        
                                      <div class="form-group ">
        
                                        <label for="email">Username</label>
        
                                        <input type="text"  class="form-control" value="<?php echo $edit->subadmin_username;?>"  required name="subadmin_username">
        
                                      </div>
                                      <div class="form-group ">
        
                                        <label for="email">Email</label>
        
                                        <input type="text"  class="form-control" value="<?php echo $edit->subadmin_email;?>"  required name="subadmin_email">
        
                                      </div>
                                      
                                      <button type="submit" class="btn btn-success">Update Subadmin</button>
        
                                    </form>
        
                                <?php }else{?>
        
                                <form action="<?php echo base_url();?>admin/add_subadmin" method="post" enctype="multipart/form-data">
        
        
                                      <div class="form-group "> <label for="email">Name</label>
        
                                        <input type="text" required class="form-control" name="subadmin_name">
        
                                      </div>
        
        
                                      <div class="row">
        
                                          <div class="form-group col-md-6">
        
                                            <label for="email">Username</label>
        
                                            <input type="text"  class="form-control" required name="subadmin_username">
        
                                          </div>
        
                                          <div class="form-group col-md-6">
        
                                            <label for="email">Password</label>
        
                                            <input type="password"  class="form-control" required name="subadmin_pass">
        
                                          </div>
        
                                      </div>
        
                                      <div class="form-group">
        
                                        <label for="email">Mobile</label>
        
                                        <input type="text"  class="form-control" maxlength="10" onkeypress="return isNumberKey(event);" name="subadmin_phone" required>
        
                                      </div>
                                      <div class="form-group">
        
                                        <label for="email">Email</label>
        
                                        <input type="email"  class="form-control" name="subadmin_email" required>
        
                                      </div>
                                      
        
                                      <button type="submit" class="btn btn-success">Add Subadmin</button>
        
                                    </form>
        
                                <?php }?>
                              </div>
                            </div>
                        </div>
                        <div class="col-md-8 col-sm-12">
                        <div class="panel panel-primary">
                              <div class="panel-heading">Listed Subadmin</div>
                              <div class="panel-body">
                                <table class="table table-condensed table-bordered" id="default-datatable">

                            <thead><tr><th>S.No.</th><th> Name</th><th>Contact</th><th>Action</th></tr></thead>

                            <tbody>

                                <?php $i=1;foreach($emps as $c){?>

                            	<tr><td><?php echo $i;?></td>

                                <td><?php echo $c->subadmin_name;?><br/>

                                <label class="badge badge-success"><?php echo $c->subadmin_username;?></label></td>


                                <td><i class="fa fa-phone"></i> <?php echo $c->subadmin_phone;?><br/>
                                	<i class="fa fa-envelope"></i> <?php echo $c->subadmin_email;?></td>

                                <td>

                                

                                 <a href="#" class="btn btn-sm btn-dark change_pass" data-toggle="modal" data-target="#myModalp" id="<?php echo $c->subadmin_id;?>"><i class="fa fa-lock"></i></a>

                                  <a href="#" id="<?php echo $c->subadmin_id;?>" class="btn btn-sm btn-danger staff_delete"><i class="fa fa-trash-o"></i></a>

                                <a href="<?php echo base_url().'admin/subadmins/'.$c->subadmin_id;?>" class="btn btn-sm btn-warning"><i class="fa fa-edit"></i></a>

                                <?php if($c->subadmin_status==""){$st="Disable";}else{$st="Enable";}?>

                                    <a href="<?php echo $c->subadmin_id;?>" class="btn btn-sm btn-default enable"><?php echo $st;?></a>

                                </td></tr>

                            	<?php $i++;}?>

                            </tbody>

                        </table>
                              </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>
            <!-- /.content -->
        </div>
        <div id="myModalp" class="modal fade" role="dialog">

                          <div class="modal-dialog modal-sm">

                            <!-- Modal content-->

                            <div class="modal-content">

                              <div class="modal-header">

                                <h4 class="modal-title">Change Password</h4>

                                <button type="button" class="close" data-dismiss="modal">&times;</button>

                              </div>

                              <div class="modal-body">

                                <form action="" method="post" id="update_password">

                                    <input type="hidden" name="emp_id" id="emp_id" value="" />

                                    <div class="form-group">

                                        <label>New Password</label>

                                        <input type="password" name="pass" id="pass" class="form-control" />

                                    </div>

                                    <div class="form-group">

                                        <label>Confirm Password</label>

                                        <input type="password" name="cpass" id="cpass" class="form-control" />

                                    </div>

                                    <button type="submit" class="btn btn-warning">Change Password</button>

                                    <button type="button" class="btn btn-light pull-right" data-dismiss="modal">Close</button>

                                </form>

                              </div>

                            </div>

                        

                          </div>

                        </div>
  <footer class="main-footer">
            <!-- To the right -->
           <!-- <div class="pull-right hidden-xs">
                Developed by <i class="fa fa-heart"></i> Floatin
            </div>-->
            <!-- Default to the left -->
            <strong>Copyright &copy; 2022 <a href="#">Money Forex </a>.</strong> All rights reserved.
        </footer>
    </div>
	<script>
    $(document).ready(function(){
        $("#update_password").submit(function(e){e.preventDefault();

			var pass=$("#pass").val();

			var cpass=$("#cpass").val();

			if(pass.length<6 || pass!=cpass){alert("Please Enter Same Password and must be of atleast 6 characters.");return false;}

			var formdata=$(this).serialize();

			$.ajax({

				 type: "POST",

				 url: '<?php echo base_url();?>admin/ajax_update_subadmin_password',

				 data: {formdata:formdata},

				 success: function(res){//alert(res);

				 	alert(res);

					//$("#emps_list").html(res);

				 }

			 });

		});

	$(".enable").click(function(e){e.preventDefault();

			var st=$(this).text();

			var id=$(this).attr("href");

			if(st=="Enable"){

			$(this).text("Disable");

			}else{

			$(this).text("Enable");	

			}

			$.ajax({

							 type: "POST",

							 url: '<?php echo base_url();?>admin/subadmin_enable',

							 data: {id:id,st:st},

							 success: function(response){

								 //alert(response);

							 }

							 });

		});

	$(".change_pass").click(function(e){e.preventDefault();

			var id=$(this).attr("id");

			$("#emp_id").val(id);

	});

	$(".staff_delete").click(function(e){e.preventDefault();

	if(!confirm("Sure you want to delete?")){

		  return false;

		}

		var id=$(this).attr("id");$(this).closest("tr").remove();

		$.ajax({

			 type: "POST",

			 url: '<?php echo base_url();?>admin/ajax_subadmin_delete',

			 data: {id:id},

			 success: function(response){

				 //alert(response);

			 }

		});

	});
    });
    </script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/jquery-3.1.1.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/bootstrap.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/material.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/ripples.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/plugins/js/jquery.slimscroll.min.js"></script>
    <script src="<?php echo base_url();?>newadminassets/js/app.js"></script>
</body>

