<?php
session_start();
ob_start();
if (isset($_SESSION['us_name']) AND isset($_SESSION['us_password']) AND $_SESSION['admin']==1){
	require_once("db_connect.php");
	$id=htmlspecialchars($_GET["id"]);
	$change=htmlspecialchars($_GET["change"]);
	$from=htmlspecialchars($_GET["from"]);

	if($change=="admin"){
			$admin=$from==1?0:1;;
			$sql="UPDATE users SET admin='$admin' WHERE id='$id'";
			if ($conn->query($sql) === TRUE) {
				$_SESSION['error']="Změněno";
				header("Location: all_users.php");
			}else{
				$_SESSION['error']="Chyba";
				header("Location: all_users.php");
			} 
	}elseif ($change =="mail") {
			$send_mail=$from==1?0:1;;
			$sql="UPDATE users SET send_mail='$send_mail' WHERE id='$id'";
			if ($conn->query($sql) === TRUE) {
				$_SESSION['error']="Změněno";
				header("Location: all_users.php");
			}else{
				$_SESSION['error']="Chyba";
				header("Location: all_users.php");
			} 
	}else{
		$_SESSION['error']="Chyba";
		header("Location: all_users.php");
	}


}else{
  header ("Location: index.php"); 
}
ob_end_flush();
?>