<?php

	require_once("connectDB.php");
	
	if (isset($action) == isset($_GET['login'])) {
		if (isset($_POST['fuser']) && isset($_POST['fpass'])) {
			$fuser = $_POST['fuser'];
			$fpass = $_POST['fpass'];
			// $faccount = $_POST['account'];
			$part_user = explode('_',$fuser);
			session_start();

			// if ($faccount == '') {
			// 	header('Location: ./');
			// 	exit;
			// }
			
			switch ($part_user[0]) {
				case "admin":
					if ($fpass =="admin") {
						$_SESSION['login_user'] = $fuser;
						header('Location: UsersLog.php');
					} else {
						header('Location: ./');
					}
				break;
				default:
					// $query = $conn->query("SELECT * FROM users WHERE username = '$fuser'");
					// $data = $query->fetch_assoc();

					if ($fpass =="user") {
						$_SESSION['login_user'] = $fuser;
						$_SESSION['user_id'] = $data['id'];
						header('Location: UsersLog.php');
					} else {
						header('Location: ./');
					}
				break;
			}	
		}
		exit;
	}

?>
