<?php 
 include('nf_config.php');
// include('menu_side.php');
?>
<!doctype html>
<html lang="en-US" class="no-js">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<title><?php echo $nusers ?></title>
	
    <link rel="stylesheet" href="./bootstrap/css/bootstrap.css" >
    <link rel="stylesheet" href="./fontawesome/css/all.css" >

<?php include('menu_side_css.php'); ?>
<?php include('nf_chosen01.php'); ?>
	
</head>

<body>
	
<?php include('menu_side_body.php'); ?>

	
	<?php
	$condition	=	'';
	if(isset($_REQUEST['username']) and $_REQUEST['username']!=""){
		$condition	.=	' AND username LIKE "%'.$_REQUEST['username'].'%" ';
	}
	if(isset($_REQUEST['user_description']) and $_REQUEST['user_description']!=""){
		$condition	.=	' AND user_description LIKE "%'.$_REQUEST['user_description'].'%" ';
	}	
		// $condition = $condition." AND pid = '".$pid."'";
	
	//Main queries
    $pages->default_ipp  =   $f_pagesize; //total records show on per page
    $sql    = $db->getRecFrmQry("SELECT * FROM members_det WHERE 1 ".$condition."");
    $pages->items_total  =   count($sql);
    $pages->mid_range    =   9;
    $pages->paginate(); 
      
    $userData   =   $db->getRecFrmQry("SELECT * FROM members_det WHERE 1 ".$condition." ORDER BY username ".$pages->limit."");	
	
	
		
	?>
   	<div class="container">
		<h1><?php echo $nusers ?></h1>
		<div class="card">
		
			<div class="card-header"><i class="fa fa-fw fa-globe"></i> <strong><?php echo $nusers ?></strong> 
					<?php if ($gcrud == "CRUD") { ?>		
					<a href="nf_users_add.php?pid=<?php echo $pid ?>&xuid=<?php echo $xuid ?>&lang=<?php echo $lang ?>" class="float-end btn btn-dark btn-sm"><i class="fa fa-fw fa-plus-circle"></i><?php echo $nadd." ".$n_username;  ?></a>
					<?php } ?>
			</div>
			<div class="card-body">
				<?php
				if(isset($_REQUEST['msg']) and $_REQUEST['msg']=="rds"){
					echo	'<div class="alert alert-success"><i class="fa fa-thumbs-up"></i>'.$recdel.'</div>';
				}elseif(isset($_REQUEST['msg']) and $_REQUEST['msg']=="rus"){
					echo	'<div class="alert alert-success"><i class="fa fa-thumbs-up"></i>'.$recupd.'</div>';
				}elseif(isset($_REQUEST['msg']) and $_REQUEST['msg']=="rnu"){
					echo	'<div class="alert alert-warning"><i class="fa fa-exclamation-triangle"></i>'.$recnochange.'</div>';
				}elseif(isset($_REQUEST['msg']) and $_REQUEST['msg']=="rna"){
					echo	'<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i>'.$recwrong.' <strong>'.$rectry.'</strong></div>';
				}
				?>
				<div class="col-sm-12">
					<h5 class="card-title"><i class="fa fa-fw fa-search"></i><?php echo $nfind." ".$nusers ?></h5>
					<form method="get"  >
						<div class="row">
							<div class="col-sm-4">
								<div class="mb-3">
									<label><?php echo $n_username ?></label>

									<?php
									echo "<select name='username' id='username' class='form-select' > ";
									printf ("<option value = >Enter $n_username</option>");
									include('r_dbc.php');
											$sql = "select username
											from members											
											order by 1";
									$result = mysqli_query($conn, $sql);
									if (mysqli_num_rows($result) > 0) {
										  while($row = mysqli_fetch_assoc($result)) {
											printf ("<option value = %s > %s </option>", $row["username"], $row["username"]);
											}
										}
									mysqli_close($conn);
									echo "</select>";
									?>

								</div>
							</div>
							<div class="col-sm-4">
								<div class="mb-3">
									<label><?php echo $ndesc ?></label>
									<input type="text" name="user_description" id="user_description" class="form-control" value="<?php echo isset($_REQUEST['user_description'])?$_REQUEST['user_description']:''?>" placeholder="<?php echo $nenter." ".$ndesc; ?>">
								</div>
							</div>
							
							<input type="hidden" id="pid" name="pid" value="<?php echo $pid ?>" >
							<input type="hidden" id="xuid" name="xuid" value="<?php echo $xuid ?>" >
							<input type="hidden" id="lang" name="lang" value="<?php echo $lang ?>" >

							<div class="col-sm-4">
								<div class="mb-3">
									<label>&nbsp;</label>
									<div>
										<button type="submit" name="submit" value="search" id="submit" class="btn btn-primary"><i class="fa fa-fw fa-search"></i><?php echo $nsearch ?></button>
										<a href="<?php echo $_SERVER['PHP_SELF']; ?>?pid=<?php echo $pid ?>&xuid=<?php echo $xuid ?>&lang=<?php echo $lang ?>" class="btn btn-danger"><i class="fa fa-fw fa-sync"></i> <?php echo $nclear ?></a>
									</div>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<hr>



		<div class="clearfix"></div>
     
		<div class="row marginTop">
			<div class="col-sm-12 paddingLeft pagerfwt">
				<?php if($pages->items_total > 0) { ?>
					<?php echo $pages->display_pages();?>
					<?php echo $pages->display_items_per_page();?>
					<?php echo $pages->display_jump_menu(); ?>
				<?php }?>
			</div>
			<div class="clearfix"></div>
		</div>
	 
		<div class="clearfix"></div>




		
		<div>
			<table class="table table-striped table-bordered">
				<thead>
					<tr class="bg-primary text-white">
						<th><?php echo $n_username ?></th>
						<th><?php echo $ndesc ?></th>						
						<th class="text-center" ><?php echo $ndemo_user ?></th>						
						<th class="text-center" ><?php echo $nlang ?></th>						
						<th class="text-center"><?php echo $naction ?></th>
					</tr>
				</thead>
				<tbody>
					<?php 
					$s	=	'';
					foreach($userData as $val){
						$s++;
					?>
<?php 						

$usernamex = $val['username'];

include('r_dbc.php');
 		$sql = "select username,email as usermail
		from members
		where username = '".$usernamex."'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
      while($row = mysqli_fetch_assoc($result)) {
		$usernameg = $row["username"];
		$usermailg = $row["usermail"];
		}
	}
mysqli_close($conn);		
		
		
		$demo_user 	= $val['demo_user'];
		$ulang		= $val['lang'];
		
					if ($demo_user == 0) 	{ $demo_yes_no = $nnocap; }
					if ($demo_user == 1) 	{ $demo_yes_no = "<b>".$nyescap."</b>"; }

					if ($ulang == 1) 		{ $lang_flag = "<img src='flag_en_anim.gif' width=30 height=auto border=0 />"; }
					if ($ulang == 2) 		{ $lang_flag = "<img src='flag_el_anim.gif' width=30 height=auto border=0 />"; }

		
		
?>


					<tr>
						<td><?php echo $val['username']." - ".$usermailg; ?></td>
						<td><?php echo $val['user_description']; ?></td>						
						<td class="text-center" ><?php echo $demo_yes_no ?></td>						
						<td class="text-center" ><?php echo $lang_flag ?></td>						
						<td align="center">
						<?php if ($gcrud == "CRUD" || $gcrud == "CRU") { ?>						
							<a href="nf_users_edit.php?editId=<?php echo $val['cid']; ?>&pid=<?php echo $pid ?>&xuid=<?php echo $xuid ?>&lang=<?php echo $lang ?>" class="text-primary"><i class="fa fa-fw fa-edit"></i><?php echo $nedit ?></a>
						<?php } 
						if ($gcrud == "CRUD") { ?>						
						|
							<a href="nf_users_delete.php?delId=<?php echo $val['cid']; ?>&pid=<?php echo $pid ?>&xuid=<?php echo $xuid ?>&lang=<?php echo $lang ?>" class="text-danger" onClick="return confirm('<?php echo $areyousure ?>');"><i class="fa fa-fw fa-trash"></i> <?php echo $ndelete ?></a>
						<?php } ?>
						</td>
					</tr>
					<?php } ?>
				</tbody>
			</table>
		</div> <!--/.col-sm-12-->
		
		
		<div class="clearfix"></div>
     
		<div class="row marginTop">
			<div class="col-sm-12 paddingLeft pagerfwt">
				<?php if($pages->items_total > 0) { ?>
					<?php echo $pages->display_pages();?>
					<?php echo $pages->display_items_per_page();?>
					<?php echo $pages->display_jump_menu(); ?>
				<?php }?>
			</div>
			<div class="clearfix"></div>
		</div>
	 
		<div class="clearfix"></div>		
		
	</div>
	
    <script src="./jquery-3.4.1.js"></script>
    <script src="popper.min.js" ></script>
    <script src="./bootstrap/js/bootstrap.min.js" ></script>
    
</body>
</html>
