<?php 
 include('nf_config.php');
 // include('menu_side.php');
 include('nf_order.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 $n_categs ?></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['code_categ_group']) and $_REQUEST['code_categ_group']!=""){
		$condition	.=	' AND code_categ_group LIKE "%'.$_REQUEST['code_categ_group'].'%" ';
	}
	if(isset($_REQUEST['code_categ']) and $_REQUEST['code_categ']!=""){
		$condition	.=	' AND code_categ LIKE "%'.$_REQUEST['code_categ'].'%" ';
	}	
	if(isset($_REQUEST['desc_categ']) and $_REQUEST['desc_categ']!=""){
		$condition	.=	' AND desc_categ LIKE "%'.$_REQUEST['desc_categ'].'%" ';
	}
	if(isset($_REQUEST['um']) and $_REQUEST['um']!=""){
		$condition	.=	' AND um LIKE "%'.$_REQUEST['um'].'%" ';
	}
	if(isset($_REQUEST['comm_categ']) and $_REQUEST['comm_categ']!=""){
		$condition	.=	' AND comm_categ LIKE "%'.$_REQUEST['comm_categ'].'%" ';
	}
	if(isset($_REQUEST['isgroup']) and $_REQUEST['isgroup']!=""){
		$condition	.=	' AND isgroup LIKE "%'.$_REQUEST['isgroup'].'%" ';
	}		
	$condition = $condition." AND pid = '".$pid."'";
	
	//Main queries
    $pages->default_ipp  =   $f_pagesize; //total records show on per page
    $sql    = $db->getRecFrmQry("SELECT * FROM categs WHERE 1 ".$condition."");
    $pages->items_total  =   count($sql);
    $pages->mid_range    =   9;
    $pages->paginate(); 
      
    $userData   =   $db->getRecFrmQry("SELECT * FROM categs WHERE 1 ".$condition." ORDER BY ".$ordr_qry." ".$pages->limit."");	
	
	
		
	?>
   	<div class="container-fluid">
		<h1><?php echo $n_categs ?></h1>
		<div class="card">
			<div class="card-header"><i class="fa fa-fw fa-globe"></i> <strong><?php echo $n_categs ?></strong> 
					<?php if ($gcrud == "CRUD" || $gcrud == "CRU") { ?>			
				<a href="nf_categs_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_categ;  ?></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." ".$n_categ ?></h5>
					<form method="get"  >
						<div class="row">
							<div class="col-sm-2">
								<div class="mb-3">
									<label><?php echo $n_categ_group ?></label>
									<!-- input type="text" name="code_categ_group" id="code_categ_group" class="form-control" value="<?php echo isset($_REQUEST['code_categ_group'])?$_REQUEST['code_categ_group']:''?>" placeholder="<?php echo $nenter." ".$n_categ_group; ?>" -->

									<?php
									echo "<select name='code_categ_group' id='code_categ_group' class='chosen form-control' > ";
									printf ("<option value = >Enter Group</option>");
									include('r_dbc.php');
											$sql = "select code_categ_group,desc_categ_group
											from categs_groups c
											where pid = '".$pid."'
											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 %s </option>", $row["code_categ_group"],$row["code_categ_group"],$row["desc_categ_group"]);
											}
										}
									mysqli_close($conn);
									echo "</select>";
									?>

								</div>
							</div>
							<div class="col-sm-1">
								<div class="mb-3">
									<label><?php echo $n_categ ?></label>
									<input type="text" name="code_categ" id="code_categ" class="form-control" value="<?php echo isset($_REQUEST['code_categ'])?$_REQUEST['code_categ']:''?>" placeholder="<?php echo $nenter." ".$n_categ; ?>">
								</div>
							</div>							
							<div class="col-sm-2">
								<div class="mb-3">
									<label><?php echo $ndesc ?></label>
									<input type="text" name="desc_categ" id="desc_categ" class="form-control" value="<?php echo isset($_REQUEST['desc_categ'])?$_REQUEST['desc_categ']:''?>" placeholder="<?php echo $nenter." ".$ndesc; ?>">
								</div>
							</div>
							<div class="col-sm-1">
								<div class="mb-3">
									<label><?php echo $num ?></label>
									<?php
									echo "<select name='um' id='um' class='form-control' > ";
									printf ("<option value = >Enter UM</option>");
									include('r_dbc.php');
											$sql = "select um
											from um
											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["um"],$row["um"]);
											}
										}
									mysqli_close($conn);
									echo "</select>";
									?>

								</div>
							</div>							
							
							<div class="col-sm-2">
								<div class="mb-3">
									<label><?php echo $ncomms ?></label>
									<input type="text" name="comm_categ" id="comm_categ" class="form-control" value="<?php echo isset($_REQUEST['comm_categ'])?$_REQUEST['comm_categ']:''?>" placeholder="<?php echo $nenter." ".$ncomms; ?>">
								</div>
							</div>							

							<div class="col-sm-2">
								<div class="mb-3">
									<label><?php echo $ngroupd ?></label>
									<?php
									echo "<select name='isgroup' id='isgroup'  class='chosen form-control' > ";
									printf ("<option value = >Enter $nsubgroupd </option>");
									include('r_dbc.php');
											$sql = "select 'GRP0' as code_categ,upper('".$nnot." ".$nsubgroupd."') as desc_categ
											UNION
											SELECT 'GRP1' as code_categ,upper('".$nsubgroupd."') as desc_categ
											UNION
											select code_categ,concat(code_categ,' ',desc_categ) as desc_categ
											from categs
											where pid = '".$pid."'
											and isgroup = 'GRP1'
											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["code_categ"],$row["desc_categ"]);
											}
										}
									mysqli_close($conn);
									echo "</select>";
									?>
								</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-2">
								<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_categ_group ?>
						<a href="nf_categs.php?pid=<?php echo $pid ?>&xuid=<?php echo $xuid ?>&lang=<?php echo $lang ?>&ordr=acode_categ_group" />
						<i class="fas fa-sort-up" style="color:#ffffff;"></i>
						</a>
						<a href="nf_categs.php?pid=<?php echo $pid ?>&xuid=<?php echo $xuid ?>&lang=<?php echo $lang ?>&ordr=dcode_categ_group" />
						<i class="fas fa-sort-down" style="color:#ffffff;"></i>
						</a>						
						</th>
						<th><?php echo $n_categ ?>
						<a href="nf_categs.php?pid=<?php echo $pid ?>&xuid=<?php echo $xuid ?>&lang=<?php echo $lang ?>&ordr=acode_categ" />
						<i class="fas fa-sort-up" style="color:#ffffff;"></i>
						</a>
						<a href="nf_categs.php?pid=<?php echo $pid ?>&xuid=<?php echo $xuid ?>&lang=<?php echo $lang ?>&ordr=dcode_categ" />
						<i class="fas fa-sort-down" style="color:#ffffff;"></i>
						</a>						
						</th>
						<th><?php echo $ndesc ?></th>
						<th><?php echo $num ?></th>						
						<th><?php echo $ncomms ?></th>		
						<th><?php echo $nsubgroupd ?></th>												
						<th class="text-center"><?php echo $naction ?></th>
					</tr>
				</thead>
				<tbody>
					<?php 
					$s	=	'';
					foreach($userData as $val){
						$s++;
					?>
<?php 						

$code_categ_group = $val['code_categ_group'];

include('r_dbc.php');
 		$sql = "select desc_categ_group
		from categs_groups
		where pid = '".$pid."'
		and code_categ_group = '".$code_categ_group."'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
      while($row = mysqli_fetch_assoc($result)) {
		$desc_categ_group = $row["desc_categ_group"];
		}
	}
mysqli_close($conn);		

$isgroup 			= $val['isgroup'];
// GET ISGROUP
if ($isgroup == 'GRP0') 
	{ 
		$desc_center_isgroup = mb_strtoupper($nsubgroupd.": ".$nnocap); 
		$isgroupcolor = "tomato"; 
	}
else if (
			$isgroup == 'GRP1') { $desc_center_isgroup = mb_strtoupper($nsubgroupd.": ".$nyescap);
		$isgroupcolor = "lawngreen"; 
		}
else {
		$isgroupcolor = "lightgreen"; 	
include('r_dbc.php');
 		$sql = "select code_categ,desc_categ
				from categs
				where pid = '".$pid."'
				and code_categ = '".$isgroup."'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
      while($row = mysqli_fetch_assoc($result)) {
		$desc_center_isgroup = mb_strtoupper($ngroupd).": ".$row["code_categ"]."-".$row["desc_categ"];
		}
	}
mysqli_close($conn);		
}		
		
?>


					<tr>
						<td><?php echo $val['code_categ_group']." - ".$desc_categ_group; ?></td>
						<td><?php echo $val['code_categ'];?></td>						
						<td><?php echo $val['desc_categ'];?></td>
						<td><?php echo $val['um'];?></td>
						<td><?php echo $val['comm_categ'];?></td>	
						<td bgcolor="<?php echo $isgroupcolor ?>" ><?php echo $desc_center_isgroup ?></td>						
						<td class="text-center">
						<?php if ($gcrud == "CRUD" || $gcrud == "CRU") { ?>																		
							<a href="nf_categs_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_categs_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>
<?php include('nf_chosen02.php'); ?>
</html>
