<?php 
include('nf_config.php');
include('menu_side.php');

if(isset($_REQUEST['submit']) and $_REQUEST['submit']!=""){
	extract($_REQUEST);
	if($mid==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=un');
		exit;
	}
	elseif($desc_manager==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}
	elseif($budget==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}		
	elseif($expenses==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}	
	elseif($rep_column==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}
	elseif($desc_rep==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}
	elseif($desc_rep_stock==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}	
	/*elseif($delta_col==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}*/
	/*elseif($delta_calc==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}*/		
	elseif($menu_order==""){
		header('location:'.$_SERVER['PHP_SELF'].'?msg=ue');
		exit;
	}		
	else{
		
		$userCount	=	$db->getQueryCount('ccmanager_id','cid');
		if($userCount[0]['total']<2000000){
			$data	=	array(
							'pid'=>$pid,
							'mid'=>$mid,
							'desc_manager'=>$desc_manager,
							'budget'=>$budget,														
							'expenses'=>$expenses,							
							'rep_column'=>$rep_column,							
							'desc_rep'=>$desc_rep,
							'desc_rep_stock'=>$desc_rep_stock,							
							'delta_col'=>$delta_col,
							'delta_pm'=>$delta_pm,							
							'delta_calc'=>$delta_calc,
							'delta_perc'=>$delta_perc,							
							'menu_order'=>$menu_order
						);
			$insert	=	$db->insert('ccmanager_id',$data);
			if($insert){
				header('location:nf_manid.php?msg=ras&pid='.$pid.'&xuid='.$xuid.'&lang='.$lang);
				exit;
			}else{
				header('location:nf_manid.php?msg=rna&pid='.$pid.'&xuid='.$xuid.'&lang='.$lang);
				exit;
			}
		}else{
			header('location:'.$_SERVER['PHP_SELF'].'?msg=dsd&pid='.$pid.'&xuid='.$xuid.'&lang='.$lang);
			exit;
		}
	}
}
?>

<!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 $nmanagers ?></title>

	

    <link rel="stylesheet" href="./bootstrap/css/bootstrap.css" >
    <link rel="stylesheet" href="./fontawesome/css/all.css" >

	
	

</head>



<body>

	

  	<div class="container">


		<?php

		if(isset($_REQUEST['msg']) and $_REQUEST['msg']=="un"){

			echo	'<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> $field_mand </div>';

		}elseif(isset($_REQUEST['msg']) and $_REQUEST['msg']=="ue"){

			echo	'<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> $field_mand </div>';

		}elseif(isset($_REQUEST['msg']) and $_REQUEST['msg']=="up"){

			echo	'<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> $field_mand </div>';

		}elseif(isset($_REQUEST['msg']) and $_REQUEST['msg']=="ras"){

			echo	'<div class="alert alert-success"><i class="fa fa-thumbs-up"></i> $recadded </div>';

		}elseif(isset($_REQUEST['msg']) and $_REQUEST['msg']=="rna"){

			echo	'<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> $recaddedno <strong> $tryagain </strong></div>';

		}elseif(isset($_REQUEST['msg']) and $_REQUEST['msg']=="dsd"){

			echo	'<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> Please delete a user and then try again <strong>We set limit for security reasons!</strong></div>';

		}

		?>

		<div class="card">

			<div class="card-header"><i class="fa fa-fw fa-plus-circle"></i> <strong><?php echo $nadd." ".$nmanager;  ?></strong> <a href="nf_manid.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-globe"></i> <?php echo $nbrowse." ".$nmanagers;  ?></a></div>

			<div class="card-body">

				

				<div class="col-sm-6">

					<h6 class="card-title"><?php echo $nfields_with ?> <span class="text-danger">*</span> <?php echo $nmandatory ?></h6>

					<form method="post">
					

						<div class="mb-3">
							<label><?php echo $nmanager_id ?><span class="text-danger">*</span></label>
							<input type="number" min="0" max="10" name="mid" id="mid" class="form-control" placeholder="<?php echo $nenter." ".$nmanager_id ?>" required>
						</div>						

						<div class="mb-3">
							<label><?php echo $ndesc ?><span class="text-danger">*</span></label>
							<input type="text" name="desc_manager" id="desc_manager" class="form-control" placeholder="<?php echo $nenter." ".$ndesc ?>" required>
						</div>

						<div class="mb-3">
							<label><?php echo $n_budget ?></label>
							<input type="number" min="0" max="1" name="budget" id="budget" class="form-control" placeholder="<?php echo $nenter." ".$n_budget ?>">
						</div>												
						
						<div class="mb-3">
							<label><?php echo $n_expenses ?></label>
							<input type="number" min="0" max="2" name="expenses" id="expenses" class="form-control" placeholder="<?php echo $nenter." ".$n_expenses ?>">
						</div>												
						
						<div class="mb-3">
							<label><?php echo $n_rep_column ?><span class="text-danger">*</span></label>
							<input type="text" name="rep_column" id="rep_column" pattern="[A-Z]{1}" class="form-control" placeholder="<?php echo $nenter." ".$n_rep_column ?>" required>
						</div>						
						
						<div class="mb-3">
							<label><?php echo $n_desc_rep ?><span class="text-danger">*</span></label>
							<input type="text" name="desc_rep" id="desc_rep" class="form-control" placeholder="<?php echo $nenter." ".$n_desc_rep ?>" required>
						</div>												

						<div class="mb-3">
							<label><?php echo $n_desc_rep_stock ?><span class="text-danger">*</span></label>
							<input type="text" name="desc_rep_stock" id="desc_rep_stock" class="form-control" placeholder="<?php echo $nenter." ".$n_desc_rep_stock ?>" required>
						</div>
						
						<div class="mb-3">
							<label><?php echo $n_delta_col ?><span class="text-danger">*</span></label>
							<input type="text" name="delta_col" id="delta_col" class="form-control" placeholder="<?php echo $nenter." ".$n_delta_col ?>" required >
						</div>																		
						
						<div class="mb-3">
							<label><?php echo $n_delta_pm ?></label>
							<input type="text" name="delta_pm" id="delta_pm" class="form-control" placeholder="<?php echo $nenter." ".$n_delta_pm ?>" >
						</div>																								
						
						<div class="mb-3">
							<label><?php echo $n_delta_calc ?></label>
							<input type="text" name="delta_calc" id="delta_calc" class="form-control" placeholder="<?php echo $nenter." ".$n_delta_calc ?>">
						</div>																								
						
						<div class="mb-3">
							<label><?php echo $n_delta_perc ?></label>
							<input type="text" name="delta_perc" id="delta_perc" class="form-control" placeholder="<?php echo $nenter." ".$n_delta_perc ?>" >
						</div>																								
						
						<div class="mb-3">
							<label><?php echo $n_menu_order ?><span class="text-danger">*</span></label>
							<input type="number" min="0" max="10" name="menu_order" id="menu_order" class="form-control" placeholder="<?php echo $nenter." ".$n_menu_order ?>" required>
						</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>
							<button type="submit" name="submit" value="submit" id="submit" class="btn btn-primary"><i class="fa fa-fw fa-plus-circle"></i><?php echo $nadd." ".$nmanager ?></button>

						</div>

					</form>

				</div>

			</div>

		</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>