<?php
include('../conn.php');
if(isset($_POST['submit'])){

    $id=$_POST['id'];
    $date=$_POST['date'];
    $by=$_POST['by'];
    
// sanitize the value
$p_o = filter_input(INPUT_POST, 'p_order', FILTER_SANITIZE_STRING);
$p_o_b = filter_input(INPUT_POST, 'p_o_b', FILTER_SANITIZE_STRING);
$p_o_r = filter_input(INPUT_POST, 'p_o_r', FILTER_SANITIZE_STRING);
$m_user = filter_input(INPUT_POST, 'm_user', FILTER_SANITIZE_STRING);
$m_menu_bar = filter_input(INPUT_POST, 'm_menu_bar', FILTER_SANITIZE_STRING);
$m_menu_rest = filter_input(INPUT_POST, 'm_menu_rest', FILTER_SANITIZE_STRING);
$analytics = filter_input(INPUT_POST, 'analytics', FILTER_SANITIZE_STRING);
$settings = filter_input(INPUT_POST, 'settings', FILTER_SANITIZE_STRING);
$customer = filter_input(INPUT_POST, 'customer', FILTER_SANITIZE_STRING);
$order = filter_input(INPUT_POST, 'order', FILTER_SANITIZE_STRING);
$facility = filter_input(INPUT_POST, 'facility', FILTER_SANITIZE_STRING);
$user_role = filter_input(INPUT_POST, 'user_role', FILTER_SANITIZE_STRING);
$inventory = filter_input(INPUT_POST, 'inventory', FILTER_SANITIZE_STRING);
$view_cash = filter_input(INPUT_POST, 'view_cash', FILTER_SANITIZE_STRING);
$hotel_m = filter_input(INPUT_POST, 'hotel_m', FILTER_SANITIZE_STRING);


// check against the valid value
if ($p_o) {
	$p_o_v= 1;
} else {
	$p_o_v=0;
}

if ($p_o_b) {
	$p_o_b_v= 1;
} else {
	$p_o_b_v=0;
}

if ($p_o_r) {
	$p_o_r_v= 1;
} else {
	$p_o_r_v=0;
}

if ($m_user) {
	$m_user_v= 1;
} else {
	$m_user_v=0;
}

if ($m_menu_bar) {
	$m_menu_bar_v= 1;
} else {
	$m_menu_bar_v=0;
}

if ($m_menu_rest) {
	$m_menu_rest_v= 1;
} else {
	$m_menu_rest_v=0;
}


if ($analytics) {
	$analytics_v= 1;
} else {
	$analytics_v=0;
}

if ($settings) {
	$settings_v= 1;
} else {
	$settings_v=0;
}

if ($customer) {
	$customer_v= 1;
} else {
	$customer_v=0;
}

if ($order) {
	$order_v= 1;
} else {
	$order_v=0;
}

if ($facility) {
	$facility_v= 1;
} else {
	$facility_v=0;
}

if ($user_role) {
	$user_role_v= 1;
} else {
	$user_role_v=0;
}

if ($inventory) {
	$inventory_v= 1;
} else {
	$inventory_v=0;
}
if ($view_cash) {
	$view_cash_v= 1;
} else {
	$view_cash_v=0;
}

if ($hotel_m) {
	$hotel_m_v= 1;
} else {
	$hotel_m_v=0;
}



$sql = "UPDATE `user_role` SET`dashboard`='$p_o_v',`prepare_order_b`='$p_o_b_v',`prepare_order_r`='$p_o_r_v',`m_user`='$m_user_v',`m_menu_bar`='$m_menu_bar_v',`m_menu_rest`='$m_menu_rest_v',`analytics`='$analytics_v',`settings`='$settings_v',`view_amount`='$view_cash_v',`hotel_m`='$hotel_m_v',`customer`='$customer_v',`order`='$order_v',`facility`='$facility_v',`user_role`='$user_role_v',`inventory`='$inventory_v',`date`='$date',`by`='$by' WHERE userid=$id";
if(mysqli_query($conn,$sql)){

echo"<script>alert('User role edited succefully'); window.location.href='../user_role'</script>";
}
else{
  echo 'Error: '.mysqli_error($conn);
}

}
?>
