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

	if(!isset($_SESSION["login"]) || !isset($_SESSION["senha"])){
		header("Location: cuide.php");
		exit;	
	}
	

?> 
	<?php
	$cod = $_GET['cod'];
	
	if($cod=='msing'){
	$id     = $_POST['id'];
	$taxa 	= $_POST['taxa'];
	$multa 	= $_POST['multa'];
	$pago 	= $_POST['pago'];
	$ref 	= $_POST['refer'];
	$dia 	= date('d');
	$mes 	= date('m');
	$ano 	= date('Y');
	$data 	= date('Y-m-d');
	$mercado = $_POST['mercado'];
	$Nome   = $_POST['agente'];
	$h 	    = date('H');
	$mi 	= date('i');
	$seg 	= date('s');
	$hora   = ($h+2).''.$mi.''.$seg;
	
	$stmt = $mysqli->prepare("INSERT INTO pagtomresgistado(municipe,mercado, taxa, multa, pago, datapagto, hora,dia, mes, ano, mes_ref,agente) VALUES 
	('$id','$mercado','$taxa','$multa','$pago','$data','$hora','$dia','$mes','$ano','$ref','$Nome')");
		
		if(!$stmt->execute())
			{
				echo("<script>alert('Erro!');</script>");
			}
			else
			{
				echo("<script>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>");
			}
		}
	?>