<?php
include("../sessionreserved.php");
include("../../db.php");

//elimino visite effettuate
if(!empty($_GET['id']))
	mysql_query("DELETE FROM visite WHERE MD5(idvisita) = '".$_GET['id']."' AND cpt=1");

//prossime visite
$result = mysql_query("SELECT *, DATE_FORMAT(data_prossvisita,'%d/%m/%Y') AS datavisita FROM visite WHERE userid = ".$_SESSION['user']['id']." AND data_prossvisita <> '0000-00-00' ORDER BY data_prossvisita ASC");
if(mysql_num_rows($result) > 0){
	while($row = mysql_fetch_array($result)){
		$proxvisite .= '
		<li>
			Visita prevista il '.$row['datavisita'].' alle ore '.substr($row['ora'],0,5).' 
			&raquo; <a href="visita_add.php?id='.$row['idvisita'].'">compila modulo</a>
			<!--&raquo; <a href="index.php?id='.md5($row['idvisita']).'">elimina visita</a>-->
		</li>';
	}
	
}else{
	$proxvisite = "<i>- Nessuna visita prevista</i>";
}
//elenco visite incomplete
$result = mysql_query("
	SELECT *, DATE_FORMAT(dataora,'%d/%m/%Y') AS datains
	FROM visite WHERE userid = ".$_SESSION['user']['id']." AND completata = 0
	ORDER BY dataora ASC
");
if(mysql_num_rows($result) > 0){
	while($row = mysql_fetch_array($result)){
		//moduli incompleti
		if($row['completata'] == 0){
			$incompleti .= '<li>Visita inserita il '.$row['datains'].' &raquo; <a href="visita_edit.php?id='.$row['idvisita'].'">visualizza</a> </li>';
		}
	
	}
}else{
	$incompleti = "<i>- Nessun modulo incompleto</i>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Osservatorio Edile Biella - C.P.T.</title>
<script language="javascript" src="js/rlst.js"></script>
<script language="javascript" src="../js/script.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="../css/reserved.css" />
</head>

<body>

<div id="header"></div>

<div id="container">
	<div id="mainHeader" class="clearfix"><?php include("mainHeader.php");?></div>
	<?php include("mainMenu.php");?>
   
    <div id="mainContainer">
        <span class="mainContentTitle">Benvenuto nel programma inserimento e gestione visite C.P.T.</span>
        <div id="mainContent" class="clearfix">
        	<div class="subTitle">Prossime visite da effettuare:</div>
    		<ul class="homelist">
			<?php echo $proxvisite;?>
        	</ul>
            
            <div class="sep"></div>
            
            <div class="subTitle">Moduli incompleti:</div>
    		<ul class="homelist">
    		<?php echo $incompleti;?>
			</ul>
        </div>
    </div>
    
</div>

<div id="footer"></div>

</body>
</html>