<?php
include('conexao.php');
session_start();

	if(!isset($_SESSION["login"]) || !isset($_SESSION["senha"])){
		header("Location: cuide.php");
		exit;	
	}
	
if(isset($_COOKIE['login']) && ($_COOKIE['login']<>""))
{
$login_cookie = $_COOKIE['login']; 
$sql = mysqli_query($mysqli,"SELECT * FROM login where login like '$login_cookie'");
$linha = mysqli_fetch_array($sql);
$Nome				= $linha["funcionario"];
}
?> 
	<?php
	$cod = $_GET['cod'];
	
	if($cod=='msing'){
		$id     = $_POST['id'];
	$taxa 	= $_POST['taxa'];
	$multa 	= $_POST['multa'];
	$pago 	= $_POST['pago'];
	$dia 	= date('d');
	$mes 	= date('m');
	$ano 	= date('Y');
	$data 	= date('Y-m-d');
	$mercado = $_POST['mercado'];
	$Nome = $_POST['agente'];
	$h = date('H');
	$m  = date('i');
	$s = date('s');
	$hora 	= ($h.':'.$m.':'.$s);
	
	$stmt = $mysqli->prepare("INSERT INTO pagtomresgistado(municipe,mercado, taxa, multa, pago, datapagto, hora,dia, mes, ano, agente) VALUES 
	('$id','$mercado','$taxa','$multa','$pago','$data','$hora','$dia','$mes','$ano','$Nome')");
		
		$stmt2 = $mysqli->prepare("INSERT INTO receitas VALUES (NULL,'$dia','$mes','$ano','1142','114205','$pago')");
    	if(!$stmt->execute())
    		{
    			echo("<script>alert('Erro!');</script>");
    		}
    	if(!$stmt2->execute())
    		{
    			echo("<script>alert('Erro!');</script>");
    		}
			else
			{
				echo("<script>alert('Registado com sucesso!');window.location.href='printscrean.php?&cod=msing';</script>");
			}
		}
	else if($cod=='drivers')
		{
		$id     = $_POST['id'];
		$taxa 	= $_POST['taxa'];
		$multa 	= $_POST['multa'];
		$pago 	= $_POST['pago'];
		$dia 	= $_POST['dia'];
		$mes 	= $_POST['mes'];
		$ano 	= $_POST['ano'];
		$parque = $_POST['parque'];
		$agente = $_POST['agente'];
		$data = date('Y-m-d');
		$hora = date('H:i:s');
		
		$stmt = $mysqli->prepare("INSERT INTO pagtodrivers 
							(veiculo, paragem, taxa, multa, pago, datapagto, hora, dia, mes, ano, agente ) VALUES
							('$id','$parque','$taxa','$multa','$pago','$data', '$hora','$dia','$mes','$ano','$agente')");
		 
		if(!$stmt->execute())
			{
				echo("<script>alert('Erro!');</script>");
			}
			else
			{
				echo("<script>alert('Registado com sucesso!');window.location.href='printscrean.php?&cod=drivers';</script>");
			}
		}
	?>