....il codice è parecchio complesso e incasinato, ci provo ad inviarlo...
Sono tre file: entrate.php è quello che contiene il form, l'invio dei dati è verso index_entrate.php che contiene il file testa.php in cui si valuta il tipo di utente in funzione del quale stabilisce un tipo di pagina (testaX) che è tutto codice html come anche home.php....
Grazie mille per la gentile disponibilità.
Mic speranzosa:crying:
ENTRATE.PHP
<?
session_start();
include("connessione.php");
// qui inserisco nuove entrate
?>
<form action="index_entrate.php" method="post" align="center">
<div id="inserimento" style="margin-left:auto; margin-right:auto;width:800px;">
<table width="800px" class="generale">
<tr><td colspan="6"><h2>Nuovo inserimento</h2></td></tr>
<tr>
<td align="center" ><b><font size="2">Data</font></b> </td>
<td align="center" ><b><font size="2">Descrizione</font></b> </td>
<td align="center" ><b><font size="2">Contanti</font></b> </td>
<td align="center" ><b><font size="2">Assegni</font></b></td>
<td align="center" ><b><font size="2">Pos</font></b> </td>
<td align="center" ><b><font size="2">Bonifico</font></b> </td>
</tr>
<tr>
<td align="center" ><input size="8" name="data" id="data" type="text" onclick="return showCalendar('data', '%d/%m/%Y');" value="<? echo $_POST['data'];?>"><input type="image" id="bottone" value=""></td>
<td align="center" ><input size="30" name="descrizione" type="text" value="<? echo $_POST['descrizione'];?>"></td>
<td align="center" ><input size="8" name="contanti" type="text" onkeyup="verif_nombre(this);" value="<? echo $_POST['contanti'];?>"></td>
<td align="center" ><input size="8" name="assegni" type="text" onkeyup="verif_nombre(this);" value="<? echo $_POST['assegni'];?>"></td>
<td align="center" ><input size="8" name="pos" type="text" onkeyup="verif_nombre(this);" value="<? echo $_POST['pos'];?>"></td>
<td align="center" ><input size="8" name="bonifico" type="text" onkeyup="verif_nombre(this);" value="<? echo $_POST['bonifico'];?>"></td>
</tr><tr><br></tr>
<tr>
<td colspan="7" align="center"><input align="center" type="submit" name="aggiorna" id="aggiorna" value="Aggiorna"></td>
</tr>
<tr><br><br></tr>
</table>
</div>
</form>
<?
// qui finisce nuove entrate
if($_POST['aggiorna']=='Aggiorna'){
$sw=array();
$data=$_POST['data'];
$descrizione=$_POST['descrizione'];
$contanti=$_POST['contanti'];
$assegni=$_POST['assegni'];
$pos=$_POST['pos'];
$bonifico=$_POST['bonifico'];
if(empty($data) or empty($descrizione)){
$sw[0]=1;
$ver=1;}
if(empty($contanti) and empty($assegni) and empty($pos) and empty($bonifico)){
$sw[1]=1;
$ver=1;}
if((!empty($contanti) and (!empty($assegni) or !empty($pos) or !empty($bonifico))) or (!empty($assegni) and (!empty($contanti) or !empty($pos) or !empty($bonifico))) or (!empty($pos) and (!empty($assegni) or !empty($contanti) or !empty($bonifico))) or (!empty($bonifico) and (!empty($assegni) or !empty($contanti) or !empty($pos)))){
$sw[3]=1;
$ver=1;}
if(isset($ver) and $ver==1){
if($sw[0]==1){echo "<p style='text-align: center; color: red;font-size:14px;'>* ATTENZIONE! I campi 'Data'e 'Descrizione' non possono essere contemporaneamente vuoti</p>";}
if($sw[1]==1){echo "<p style='text-align: center; color: red;font-size:14px;'>* ATTENZIONE! Inserimento di un importo obbligatorio</p>";}
/* if($sw[2]==1){echo "<p style='text-align: center; color: red;font-size:14px;'>* ATTENZIONE! Tipo di assegno obbligatorio</p>";}*/
if($sw[3]==1){echo "<p style='text-align: center; color: red;font-size:14px;'>* ATTENZIONE! Deve essere inserita soltanto una tipologia di importo</p>";}
}
else{
if(!empty($contanti)){
$tipologia=0;
$importo=$contanti;}
if(!empty($assegni)){
$tipologia=1;
$importo=$assegni;}
if(!empty($pos)){
$tipologia=2;
$importo=$pos;}
if(!empty($bonifico)){
$tipologia=3;
$importo=$bonifico;}
$query="insert into entrate (data, descrizione, tipologia, importo) value ('$data','$descrizione','$tipologia','$importo')";
$result=mysql_query($query) or die("<br> Errore di inserimento pagamenti finanziaria: ".mysql_error());
mysql_close($connessione);
unset($_POST);
//echo "questo il valore dopo unset inserimento ".var_dump($_POST);
//echo $_POST['aggiorna'];
echo "<p style='text-align: center; color: green;font-size:14px;'>Inserimento eseguito con successo</p>";
//include('entrate.php');?>
<script language="Javascript">
location.href='http://localhost/GAGGIOLI_SIST/index_entrate.php';
</script><?
}
}
// query iniziale
$query="select * from entrate";
$result=mysql_query($query) or die("Errore select: <br>".mysql_error()."<br>".mysql_errno());
$totale=mysql_num_rows($result);
if($totale!=0){
$indice_mese=array('/01/','/02/','/03/','/04/','/05/','/06/','/07/','/08/','/09/','/10/','/11/','/12/');
$mese[0]="GENNAIO";
$mese[1]="FEBBRAIO";
$mese[2]="MARZO";
$mese[3]="APRILE";
$mese[4]="MAGGIO";
$mese[5]="GIUGNO";
$mese[6]="LUGLIO";
$mese[7]="AGOSTO";
$mese[8]="SETTEMBRE";
$mese[9]="OTTOBRE";
$mese[10]="NOVEMBRE";
$mese[11]="DICEMBRE";
?><h1>Entrate</h1><?
for($i=0;$i<12;$i++){
$query="select * from entrate where data like '%".$indice_mese[$i]."%' order by data";
$result=mysql_query($query) or die("Errore select: <br>".mysql_error()."<br>".mysql_errno());
$tot=mysql_num_rows($result);
// fine query iniziale
if($tot!=0){
$tot_cont=0;
$tot_ass=0;
$tot_post=0;
$tot_bon=0;
?>
<table border="1" width="800px" class="generale"><caption></caption>
<tr><td colspan="6" border="0">Mese di: <b><? echo $mese[$i];?></b></td></tr>
<tr>
<td align="center" width="10"><b><font size="2"><em>Data</em></font></b> </td>
<td align="center" width="10"><b><font size="2"><em>Descrizione</em></font></b> </td>
<td align="center" width="10"><b><font size="2"><em>Contanti</em></font></b> </td>
<td align="center" width="10"> <b><font size="2"><em>Assegni</em></font></b></td>
<td align="center" width="10"><b><font size="2"><em>Pos</em></font></b> </td>
<td align="center" width="10"><b><font size="2"><em>Bonifico</em></font></b> </td>
</tr>
<?
while($risultato=mysql_fetch_array($result)){?>
<tr>
<td size="10">
<? echo $risultato['data'];?>
</td>
<td size="10">
<? echo $risultato['descrizione'];?>
</td>
<? if($risultato['tipologia']==0){?>
<td size="10" align="right">
<? echo $risultato['importo'];?>
</td>
<?}else{?>
<td size="10" align="right"></td>
<?}
if($risultato['tipologia']==1){?>
<td size="10" align="right">
<? echo $risultato['importo'];?>
</td>
<?}else{?>
<td size="10" align="right"></td>
<?}
if($risultato['tipologia']==2){?>
<td size="10" align="right">
<? echo $risultato['importo'];?>
</td>
<?}else{?>
<td size="10" align="right"></td>
<?}
if($risultato['tipologia']==3){?>
<td size="10" align="right">
<? echo $risultato['importo'];?>
</td>
<?}else{?>
<td size="10" align="right"></td>
<?}
?></tr><?
switch($risultato['tipologia']){
case 0: $tot_cont=$tot_cont+$risultato['importo'];
break;
case 1: $tot_ass=$tot_ass+$risultato['importo'];
break;
case 2: $tot_post=$tot_post+$risultato['importo'];
break;
case 3: $tot_bon=$tot_bon+$risultato['importo'];
break;
}
}?>
<?}
if($tot!=0){?>
<tr><td colspan="2"><b><em>Totali del mese: </em></b></td><td align="right"><b><? echo $tot_cont;?></b></td><td align="right"><b><? echo $tot_ass;?></b></td><td align="right"><b><? echo $tot_post;?></b></td><td align="right"><b><? echo $tot_bon;?></b></td></tr>
</table><?}
}
}else{?>
<table id="db_empty">
<tr><br><br></tr>
<tr>
<td><h1>Entrate</h1></td>
</tr>
<tr>
<td><em>Nessun dato è presente nel database<em></td>
</tr>
</table>
<?}
mysql_close($connessione);?>
INDEX_ENTRATE.PHP
<?
session_start();
include("connessione.php");
include("testa.php");?>
<div name="principale" id="principale"><?include('entrate.php');?></div>
</body>
</html>
TESTA.PHP
<?
session_start();
if(isset($_SESSION['utente'])){
if($_GET['PHPSID']!=$_SESSION['login']){
include('home.php');
include('testa4.php');
die("<p style='text-align: center; color: red;font-size:14px;'>* ATTENZIONE! Sessione già aperta.<br>Se si vuole proseguire fare prima il logout dalla sessione precedente</p>");}
$utente=$_SESSION['utente'];
if(!isset($utente)){
$sw=2;}
else{
$query="select * from utenti where utente='$utente'";
$result=mysql_query($query) or die("Errore select: ".mysql_error());
$tot=mysql_num_rows($result);
if($tot!=0){
while($risultato=mysql_fetch_array($result)){
$utente=$risultato['utente'];
$admin=$risultato['admin'];}
if($admin==1){
$sw=0;}
else{
$sw=1;}}
else{
$sw=2;}}
}
else{$sw=2;}
include('home.php');
switch($sw){
case 0: include('testa1.php');
break;
case 1: include('testa2.php');
break;
case 2: include('testa3.php');
break;
}