<script type="text/javascript">
	$(document).ready(function(){
		
		$("#checkall").click(function(){
			if(this.checked){
				$(".check_class").attr("checked",true);					
			}else{
				$(".check_class").attr("checked",false);					
			}
		});
		
		$.tablesorter.defaults.sortList = [[1,0]];
		$(".tablesorter").tablesorter({
			headers: {
				0: { sorter: false },
				7: { sorter: false },
				8: { sorter: false }
			}
		});
		
		$(".tablesorter").tablesorterPager({container: $("#pager")}); 
		
	});
	
function change_status(admin_id,status){
	showLoader(1);	
	$.ajax({
	  url: "adminlist.php",
	  data: 'act=change_status&admin_id='+admin_id+'&status='+status,
	  success: function(msg){
	  		showLoader(0);	
		  	$(".info").html(msg);
		  	$("#status_msg").show();
		  	$("#status_msg").html(msg);
		  	
		  	if(status==0){
			  	$("#td_status_"+admin_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+admin_id+"','1')\" ><img src=\"images/publish.gif\" alt=\"Publish\" width=\"14\" height=\"15\" border=\"0\" /></a>");
		  	}else{
			  	$("#td_status_"+admin_id).html("<a href=\"javascript:void(0)\" onclick=\"change_status('"+admin_id+"','0')\" ><img src=\"images/unpublish.gif\" alt=\"Unpublish\" width=\"14\" height=\"15\" border=\"0\" /></a>");
		  	}
	  }
	});
}

function validate_all(){
	if($("#action_val").val()==''){
		$("#msg_select_action").html('Please Select action');
		$("#select_action").addClass('jquery_err');
		$("#select_action").focus();
		return false;
	}else{
		$("#msg_select_action").html('');
		$("#select_action").removeClass('jquery_err');
	}	

	if($(".check_class:checked").length == 0){
		$("#msg_select_action").html('Please Select atleast one checkbox');
		return false;
	}else{
		$("#msg_select_action").html('');
	}	
}
	
</script>

<div id="content" class="box">

	<h1>Administrator &raquo; Administrator List</h1>

	<?php if(isset($successMsg) && $successMsg!=''){ ?>
		<p class="msg done"><?php echo $successMsg; ?></p>
	<?php } ?>
	
	<?php if(isset($failedMsg) && $failedMsg!=''){ ?>
		<p class="msg error"><?php echo $failedMsg; ?></p>
	<?php } ?>

	<p id="status_msg" class="msg done" style="display:none">&nbsp;</p>
	
	<div class="loading_image" style="display:none"><img src="images/loading.gif" > </div>

    <form id="select_all_frm" name="select_all_frm" method="post" action="" onsubmit="return validate_all();">

		<table class="tablesorter" width="100%"> <!-- Sort this TABLE -->
			<thead>
				<tr>
					<th style="text-align:center"><input type="checkbox" id="checkall" name="checkall" > </th>
					<th>Name</th>
					<th>Email Address</th>
					<th>Role</th>
					<th>Created Date</th>
					<th>Last Login Date</th>
					<th>Last Login IP</th>
					<th style="text-align:center">Status</th>
					<th style="text-align:center">Action</th>
				</tr>
			</thead>
			<tfoot>
				<tr class="bg">
				    <td colspan="5" class="arrow-01" style="border-right:0px none">
							<select name="action_val" id="action_val" class="input-text">
							    <?php if($DELETE_ACCESS && $EDIT_ACCESS){ ?>
								    <option value="">Select Action</option>
								    <option value="delete_all">Delete selected</option>
								    <option value="activate_all">Activate selected</option>
								    <option value="inactivate_all">Inactivate selected</option>
								    
								<?php }else if($DELETE_ACCESS){ ?>
								    <option value="">Select Action</option>
								    <option value="delete_all">Delete selected</option>
								    
								<?php } else if ($EDIT_ACCESS){ ?>
								    <option value="activate_all">Activate selected</option>
								    <option value="inactivate_all">Inactivate selected</option>
								
								<?php } ?>
							</select>&nbsp;
							<input type="submit" value="OK" id="submit" name="submit" />&nbsp;
							<span id="msg_select_action" class="message">&nbsp;</span>
					</td>
					
				    <td colspan="4" class="arrow-01" style="border-left:0px none" align="right" >
						<div id="pager" class="pager">
							<img src="images/first.png" class="first"/>
							<img src="images/prev.png" class="prev"/>
							<input type="text" disabled="disabled" class="pagedisplay"/>
							<img src="images/next.png" class="next"/>
							<img src="images/last.png" class="last"/>
							<select class="pagesize">
								<option selected="selected" value="20">20</option>
								<option value="50">50</option>
								<option  value="100">100</option>
								<option  value="150">150</option>
							</select>
						</div>
					</td>
				</tr>
	
			</tfoot>
			<tbody>
				
				<?php if($adminDetails && count($adminDetails) > 0 ){ 
						foreach ($adminDetails as $admin){  ?>
						<tr>
							<td class="t-center"><input type="checkbox" name="check[]" id="check[]" value="<?php echo $admin->admin_id; ?>" class="check_class" /></td>

							<?php if($EDIT_ACCESS){ ?>	
								<td><a href="addadmin.php?act=edit&admin_id=<?php echo $admin->admin_id; ?>" class="edit"><?php echo $admin->admin_fname.' '.$admin->admin_mname.' '.$admin->admin_lname;  ?></a></td>
							<?php }else { ?>	
								<td><?php echo $admin->admin_fname.' '.$admin->admin_mname.' '.$admin->admin_lname;  ?></td>
							<?php } ?>
							
							<td><?php echo $admin->admin_email_address;  ?></td>
							<td><?php echo ($admin->admin_id==1) ? 'Super Administrator' : 'Moderator' ;  ?></td>
							<td class="t-center"><?php echo date('d-m-Y | h:i:s a',strtotime($admin->admin_created_date));  ?></td>
							<td class="t-center"><?php echo date('d-m-Y | h:i:s a',strtotime($admin->admin_last_login_date));  ?></td>
							<td class="t-center"><?php echo $admin->admin_last_login_ip; ?></td>
							<td style="text-align:center" id="td_status_<?php echo $admin->admin_id ?>">

								<?php if($admin->admin_id!=1 && $EDIT_ACCESS){ ?>
									<?php if($admin->admin_status=='1'){?><a href="javascript:void(0)" onclick="change_status('<?php echo $admin->admin_id ?>','1')" ><img src="images/publish.gif" alt="Publish" width="14" height="15" border="0" /></a> <?php }else{?><a href="javascript:void(0)" onclick="change_status('<?php echo $admin->admin_id ?>','0')" ><img src="images/unpublish.gif" alt="Publish" width="14" height="15" border="0" /></a><?php }?>	
								<?php }else{ ?>
									<?php if($admin->admin_status=='1'){?><img src="images/publish.gif" alt="Publish" width="14" height="15" border="0" /> <?php }else{?><img src="images/unpublish.gif" alt="Publish" width="14" height="15" border="0" /><?php }?>	
								<?php } ?>
									
							</td>
							<td class="t-center">
								
								<?php if($EDIT_ACCESS){ ?>	
									<a href="addadmin.php?act=edit&admin_id=<?php echo $admin->admin_id; ?>" class="edit"><img src="images/edit.png" alt="Edit" border="0" title="Edit Record" /></a> 
								<?php } ?>
								
								<a href="changepassword.php?admin_id=<?php echo $admin->admin_id; ?>"><img src="images/cpassword.gif" alt="Change Password"  border="0" title="Change Password" /></a>
								
								<?php if($DELETE_ACCESS && $admin->admin_id!=1){ ?>
									<a onclick="javascript:if(confirm('Are you sure to delete ? ')){location.href='adminlist.php?act=delete&admin_id=<?php echo $admin->admin_id; ?>'}"><img src="images/delete.gif" alt="Delete"  border="0" title="Delete Record" /></a>
								<?php } ?>	
							</td>
						</tr>
				
				<?php } }else { ?>
						<tr>
							<td colspan="8" align="center">No Record Found</td>
						</tr>
				<?php } ?>
			</tbody>
			
		</table>
		
	</form>

</div> <!-- /content -->