<?php
include "header.php";
$rec_users = gtAll("tks_users","","firstname ASC");
?>

<script type="text/javascript">
$(".newsmenutag").attr('aria-expanded',true);
$("#ursblg").parent().addClass('recent-submenu show');
$("#newsmenutag,#ursblg").addClass('active');
$("#mainhd").html('News');
$("#subhd").html("Manage Users");
</script>
<div id="content" class="main-content">

	<div class="layout-px-spacing">
		<div class="row layout-top-spacing" id="cancel-row">
  
			<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing m-auto">
			
			<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 ">
				<h1 class="title-4"> Post Users  </h1>
				<div class="btn-toolbar mb-2 mb-md-0">
					<div class="btn-group mr-2">
					
						<button type="button" class="btn btn-icon bg-danger text-white"  id="opencat">
						<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user-plus"><path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path><circle cx="8.5" cy="7" r="4"></circle><line x1="20" y1="8" x2="20" y2="14"></line><line x1="23" y1="11" x2="17" y2="11"></line></svg>
						&nbsp; Add User </button>
						
					</div>
				</div>
			</div>
	
			
			<div class="row">
				<div class="col-xl-12 col-lg-12 col-sm-12 m-auto">
							
				<div class="widget-content widget-content-area br-6">	
					
					<div class="table-responsive mb-4 mt-4">
						<table id="blgpost_recs" class="table table-stripped caption-top" style="width:100%">
							
							<thead>
									<tr>
										<th>Name</th>
										<th>Email</th>
										<th>Phone</th>
										<th>Date</th>
										<th>Action</th>
									</tr>
							</thead>
							<tbody>
								<?php
									if(!empty($rec_users))
									{
									foreach($rec_users as $usr)
									{
										$usrid = $usr['tus_id'];
									?>
									<tr>
										<td class="vertical-align">
											<div class="smlinf">
												<div class="prdinfo">
													<div class="content ml-0">
														<h5 class="name">
															<a href="javascript:void(0);" class="text-primary font-weight-bold"><?= $usr['firstname']." ".$usr['lastname']; ?></a>
															
														</h5>
														<span class="email text-dark font-weight-bold"><?= $usr['gender']; ?></span>
													</div>
												</div>
											</div>
										</td>
										
										<td class="vertical-align"><?= $usr['email']; ?></td>
										<td class="vertical-align"><?= $usr['phone']; ?></td>
										<td class="vertical-align"><?= date('M jS, Y', strtotime($usr['dated'])); ?></td>
										
										<td class="vertical-align">
											<div class="table-data-feature">
											    <?php
											    if($usr['tus_id'] == 2){
											        ?>
											     <button class="bg-secondary text-white bs-tooltip border-0 btn rounded-circle" disabled title="NO EDIT">
													<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-3">
													<path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg>
												</button>
												
												<button class="bg-danger text-white bs-tooltip border-0 btn rounded-circle" disabled title="CANT DELETE">
													<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2">
													<polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line>
													</svg>
												</button>
											        <?php
											    }else{
											    ?>
												<button class="recordedit bg-secondary text-white bs-tooltip border-0 btn rounded-circle" id="ed_<?= $usrid; ?>" title="Edit">
													<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-edit-3">
													<path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg>
												</button>
												
												<button class="bg-danger text-white bs-tooltip border-0 btn rounded-circle" id="del_<?= $usrid; ?>" onClick="takeoff(<?= $usrid; ?>,'ikmjg')"  title="Delete">
													<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2">
													<polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line>
													</svg>
												</button>
												<?php
											    }
												?>
											</div>
										</td>
									</tr>
									<?php
										}
									}
									?>
								
							</tbody>
						</table>
					</div>
					
						
				</div>
				</div>	
				</div>
		
			</div>

		</div>

	</div>

</div>

  <div class="modal animated fadeInUp custo-fadeInUp" id="users_Modal" tabindex="-1" role="dialog" aria-labelledby="catModalLabel" aria-hidden="true"  data-backdrop="static">
    <div class="modal-dialog modal-md" role="document">
    <form method="post" id="users_form">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="cthead">Add User</h5>
          <button class="close closecats" type="button" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
        <div class="modal-body">
				<div class="form-group">
					<label class="text-dark font-weight-bold">First Name <code>*</code></label>
					<input type="text" class="form-control" name="fname" id="fname" placeholder="first name" required="required" autofocus="autofocus" />
					<span id="" class="error_here text-left"></span>
				</div>
				
				<div class="form-group">
					<label class="text-dark font-weight-bold">Last Name <code>*</code></label>
					<input type="text" class="form-control" name="lname" id="lname" placeholder="last name" required="required"  />
					<span id="" class="error_here text-left"></span>
				</div>
				
				<div class="form-group">
					<label class="text-dark font-weight-bold">Email <code>*</code></label>
					<input type="email" class="form-control" name="email" id="email" placeholder="email address" required="required"  />
					<span id="emailtaken" class="error_here text-left"></span>
				</div>
				
				<div class="form-group">
					<label class="text-dark font-weight-bold">Mobile  No. <code>*</code></label>
					<input type="text" class="form-control" name="phonenum" id="phonenum" placeholder="phone number" required="required"  maxlength="20"/>
					<span class="donotphn"></span>
					<span id="" class="error_here text-left"></span>
				</div>
				
				<div class="form-group">
					<label class="text-dark font-weight-bold">Gender <code>*</code></label>
					<select name="genda" class="form-control" id="genda" required="required">
						<option value="Male">Male</option>
						<option value="Female">Female</option>
					</select>
					<span id="" class="error_here text-left"></span>
				</div>
			
		</div>
        <div class="modal-footer">
          <button class="btn btn-secondary closecats" type="button" data-dismiss="modal">Cancel</button>
		  <input type="hidden" name="catnumu" id="catnumu"  />
		  <button id="button_users" name="button_action"  type="submit" class="btn btn-primary"> Save </button>
        </div>
      </div>
	  
	  </form>
	  
    </div>
  </div>
  
<script type="text/javascript" language="javascript" >

$(document).ready(function(){

$(document).on('click', '#opencat', function(){ $('#users_form').trigger('reset');$('#catnumu').val('');$('#cthead').text('Add User');$('#button_users').attr('disabled',false);$('#users_Modal').modal('show');return; });

 $(document).on('click', '.recordedit', function(){
	var id = this.id;  var split_id = id.split("_"); var text = split_id[0]; var postid = split_id[1];
	$.ajax({
	type:'POST', url:'actions/users.php',
	data:{ 'fetch_rec_edit':1, 'postid':postid, }, dataType:"json",
	success:function(data) { $('#cthead').text('Edit User'); $('#fname').val(data.fname); 
	$('#lname').val(data.lname); $('#email').val(data.email); $('#phonenum').val(data.phone);$('#genda').html(data.genda); $('#catnumu').val(data.recid); $('#users_Modal').modal('show'); return;
	}
	});
});


$("#users_form").on('submit',function(e) {
e.preventDefault();	 

var rev = $('#users_form');
var mkst = $("#catnumu").val();
$.ajax({
url: 'actions/users.php',type: 'POST', data:  new FormData(this), contentType: false,
cache: false, processData:false, dataType:"json", beforeSend: function()
{$("#button_users").html('submiting <span class="spinner-grow-sm text-white ml-2 align-self-center loader-sm"></span>'); $("#button_users").attr('disabled', 'disabled'); },
success: function(data){ donejob(data.runstt,data.errorreason); $("#button_users").html('Submit'); $("#button_users").attr('disabled', false);
if(data.runstt == "grant" && mkst == ""){ rev.trigger('reset');	} }
});
});		
})

</script>	

<?php
include "footer.php"; 
?>
