<?php
include_once ("../core/config.php");
include_once ("funzioni.php");
$UTENTE = login();
$DIRITTI = diritti('Utente');
view_top();

if (isset($_POST['id'])) {
	$post = addslashes_array ($_POST);
	extract($post);

	if ($op == "nuovo" ) {
		$query = "	INSERT INTO
					wf_storico
					(id_iscritto, peso, altezza, data)
				VALUES
					($id,0,0,NOW())
		";
		$res = mysql_query( $query, $DB_ID );
	} else if ($op == "salva") {
		$data = sistemadata($data);

		$query = "	UPDATE
					wf_storico
				SET
					data = STR_TO_DATE('$data', '%d.%m.%Y'),
					peso = $peso,
					altezza = $altezza,
					cooper = $cooper,
					sargeant = $sargeant,
					slungo = $slungo,
					pallaav = $pallaav,
					pallaind = $pallaind,
					mobart = $mobart,
					flesstro = $flesstro,
					cingolo = $cingolo,
					calcisx = $calcisx,
					calcidx = $calcidx,
					commenti = '$commenti'
				WHERE
					id = $storico
		";
		$res = mysql_query( $query, $DB_ID );
	}

} else if (isset($_GET['id'])) {
	$id = $_GET['id'];
}

$query = "	SELECT
			nome,
			cognome
		FROM
			wf_iscritto
		WHERE
			id = $id
	";
$res = mysql_query( $query, $DB_ID );
$atleta = mysql_fetch_array ( $res );

$query = "	SELECT 
			wf_storico.id,
			DATE_FORMAT(wf_storico.data, '%d.%m.%Y') AS data,
			wf_storico.peso,
			wf_storico.altezza,
			wf_storico.cooper,
			wf_storico.sargeant,
			wf_storico.slungo,
			wf_storico.pallaav,
			wf_storico.pallaind,
			wf_storico.mobart,
			wf_storico.flesstro,
			wf_storico.cingolo,
			wf_storico.calcisx,
			wf_storico.calcidx,
			wf_storico.commenti
		FROM
			wf_storico
		WHERE
			wf_storico.id_iscritto = $id
		ORDER BY
			wf_storico.id DESC,
			wf_storico.data DESC
";
$res = mysql_query( $query, $DB_ID );

$tabella = new html (0,"90%",array(5,15,5,30,30,15,0));
$tabella->intestazione (array("","Nuova Rilevazione","","","","Scheda anagrafica",""), array("","textc","","","","textc",""));
?>
<form name="" method="post">
<input type="hidden" name="id" value="<?php print $id ?>">
<input type="hidden" name="op" value="nuovo">
<tr>
	<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	<td class="textc"><input type="image" src="<?php print $CONF['base_url'] ?>/img/addresource.png"></input></td>
	<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	<td class="colipb"><?php print $atleta[cognome]." ".$atleta[nome] ?></td>
	<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	<td class="textc"><a href="iscritti_edit.php?id=<?php print $id ?>"><img src="<?php print $CONF['base_url'] ?>/img/redx.png"></a></td>
	<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
</tr>
</form>
<?php

$st = array ();
$rilevazioni = 0;
while ($dato = mysql_fetch_array ( $res )) {
	$st[$rilevazioni++] = $dato;
}
$ultimo = $st[$rilevazioni-1];

$tabella->riga(20);
$tabella->close();

for ($conta=0;$conta<$rilevazioni;$conta++) {
	$dato = $st[$conta];
	$tipo = "readonly";
	if ($conta == 0 && ($op == "nuovo" || $op == "modifica")) {
		$tipo = "";
		$img = "<input type=\"image\" src=\"$CONF[base_url]/img/applica.png\"></input>";
		$operazione = "salva";
	} else if ($conta == 0) {
		$img = "<input type=\"image\" src=\"$CONF[base_url]/img/modify.gif\"></input>";
		$operazione = "modifica";
	} else {
		$img = "<img src=\"$CONF[base_url]/img/spazio.gif\">";
	}

	if ($conta == 0) { 
?>
	<form name="" method="post">
	<input type="hidden" name="id" value="<?php print $id ?>">
	<input type="hidden" name="storico" value="<?php print $dato[id] ?>">
	<input type="hidden" name="op" value="<?php print $operazione ?>">
<?php	}

	$tabella = new html (0,"90%",array(5,40,10,40,5));
?>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td><hr align="center" size="2" width="100%" color="#FFC350"></td>
		<td class="textc"><input id="data" <?php if ($tipo == "") { print "class=\"data\""; } ?> type="text" size="8" name="data" value="<?php print $dato[data] ?>" <?php print $tipo ?>></input></td>
		<td><hr align="center" size="2" width="100%" color="#FFC350"></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
<?php
	$tabella->close();

	$tabella = new html (0,"90%",array(2,7,1,7,1,6,1,7,1,7,1,5,1,5,1,7,1,7,1,7,1,6,1,6,2,4,0));
	$tabella->intestazione (array("","Peso","","Altezza","","Cooper","","Sargeant","","Fles. Tr.","","Calci SX","","Calci DX","","S. Lungo","","Arti S. Av","","Arti S. Ind","","Mob. Art.","","Cingolo","","",""));
?>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="peso" value="<?php print $dato[peso] ?>" <?php print $tipo ?>> Kg</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="2" name="altezza" value="<?php print $dato[altezza] ?>" <?php print $tipo ?>> cm</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="cooper" value="<?php print $dato[cooper] ?>" <?php print $tipo ?>> m</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="sargeant" value="<?php print $dato[sargeant] ?>" <?php print $tipo ?>> cm</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="flesstro" value="<?php print $dato[flesstro] ?>" <?php print $tipo ?>> cm</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="calcisx" value="<?php print $dato[calcisx] ?>" <?php print $tipo ?>></input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="calcidx" value="<?php print $dato[calcidx] ?>" <?php print $tipo ?>></input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="slungo" value="<?php print $dato[slungo] ?>" <?php print $tipo ?>> cm</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="pallaav" value="<?php print $dato[pallaav] ?>" <?php print $tipo ?>> cm</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="pallaind" value="<?php print $dato[pallaind] ?>" <?php print $tipo ?>> cm</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="mobart" value="<?php print $dato[mobart] ?>" <?php print $tipo ?>> &#176</input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><input size="3" name="cingolo" value="<?php print $dato[cingolo] ?>" <?php print $tipo ?>></input></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="spazioh"><?php print $img ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
	</tr>
<?php if (($conta+1 < $rilevazioni) && ($op != "nuovo") && ($op != "modifica")) { ?>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[peso], $st[$conta+1][peso], 1); print differenza ($dato[peso], $ultimo[peso], 1) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[altezza], $st[$conta+1][altezza]); print differenza ($dato[altezza], $ultimo[altezza]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[cooper], $st[$conta+1][cooper]); print differenza ($dato[cooper], $ultimo[cooper]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[sargeant], $st[$conta+1][sargeant]); print differenza ($dato[sargeant], $ultimo[sargeant]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[flesstro], $st[$conta+1][flesstro]); print differenza ($dato[flesstro], $ultimo[flesstro]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[calcisx], $st[$conta+1][calcisx]); print differenza ($dato[calcisx], $ultimo[calcisx]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[calcidx], $st[$conta+1][calcidx]); print differenza ($dato[calcidx], $ultimo[calcidx]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[slungo], $st[$conta+1][slungo]); print differenza ($dato[slungo], $ultimo[slungo]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[pallaav], $st[$conta+1][pallaav]); print differenza ($dato[pallaav], $ultimo[pallaav]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[pallaind], $st[$conta+1][pallaind]); print differenza ($dato[pallaind], $ultimo[pallaind]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[mobart], $st[$conta+1][mobart]); print differenza ($dato[mobart], $ultimo[mobart]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="colip"><?php print differenza ($dato[cingolo], $st[$conta+1][cingolo]); print differenza ($dato[cingolo], $ultimo[cingolo]) ?></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
		<td class="spazioh"><div align="left" style="font-size: 10px">Precedente</div><div align="left" style="font-size: 10px">Prima</div></td>
		<td class="spazioh"><img src="<?php print $CONF[base_url] ?>/img/spazio.gif"></td>
	</tr>
<?php
	}
	$tabella->riga(5);
	$tabella->close();

	$tabella = new html (0,"90%",array(2,96,0));
	$tabella->intestazione (array("","Commenti",""));
?>
	<tr>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td><textarea name="commenti" rows="2" cols="118" <?php print $tipo ?>><?php print $dato[commenti]?></textarea></td>
		<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
<?php
	$tabella->riga(20);
	$tabella->close();

	if ($conta == 0) { ?>
	</form>
<?php	}

}
view_footer(); ?>
