Codice PHP:
<script language=javascript>
//nella pagina presenza se nessun giorno viene aggiunto il tasto aggiorna è disabilitato
function array_checkbox(object)
{
mio[mio.length] = object;
var trovato = false;
for(var i=0; i < mio.length; i++)
{
if (mio[i].type == "checkbox" && mio[i].checked)
trovato=true;
}
if (trovato)
return true;
else
return false;
}
function attiva(form,check,text)
{
if (check)
{ form.elements[text].disabled=false;
form.elements[text].focus();
}
else
form.elements[text].disabled=true;
}
//funziona che accetta solo numeri nei text
function keyCheck(eventObj, obj)
{
var keyCode
// Check For Browser Type
if (document.all){
keyCode=eventObj.keyCode
}
else{
keyCode=eventObj.which
}
var str=obj.value
if(keyCode==46){
if (str.indexOf(".")>0){
return false
}
}
if((keyCode<48 || keyCode >58) && (keyCode != 46)) // Allow only integers and decimal points
{
return false;
}
return true;
}
</script>
<?
/*
--------------------------------------------------------------------------
ProGest - Professional Gestionale
Copyright (C) 2006 - Michele Scarso Cannizzaro Salvatore
(info@betasolution.it)
<[url]http://www.betasolution.it[/url]>
--------------------------------------------------------------------------*/
?>
<script type="text/javascript" src="supporto/calendario_presenze.js"></script>
<?
echo "<h1>Registro Presenze</h1>";
if (isset($_POST['aggiorna']))
{
unset($_POST['aggiorna']);
$data=$_POST['data_settimana'];
//preparo il form per rivisualizzare le modifiche
echo "<form name=f action=index.php?tipo=operai&op=pres method=post>";
echo "<input type=hidden name=data_settimana value=$data>";
unset($_POST['data_settimana']);
echo "<input type=hidden name=continua value=continua>";
unset($_POST['continua']);
if (isset($_POST['tipo'])) $tipo = $_POST['tipo'];
unset($_POST['tipo']);
echo "<input type=hidden name=tipo value=vis>";
$chiave = $_POST['chiave'];
unset($_POST['chiave']);
foreach($chiave as $key =>$value)
echo "<input type=hidden name=chiave[". $key ."] value=\"$value\">";
echo "</form>";
$query = "INSERT INTO registro_presenze values";
$query1="DELETE FROM registro_presenze WHERE data_inizio_settimana='$data' && ";
while (current($_POST))
{ $codice_fiscale = key($_POST);
$giornata = $_POST[$codice_fiscale]['giornata'];
//print_r($giornata);
$extra = $_POST[$codice_fiscale];
for($i=0; $i < count($giornata); $i++)
{
$query .= "($codice_fiscale,$giornata[$i],". $extra[$giornata[$i]] .",'$data','false'),";
}
$query1 .= "operai_id_operai = '$codice_fiscale' || ";
next($_POST);
}
$query = substr($query,0,strlen($query)-1); //query di inserimento
$query1 = substr($query1,0,strlen($query1)-3); //query di delete
echo $query;
if ($tipo == "modifica") //modifica effettuo delete
echo $result = mysql_query($query1) or die(mysql_error());
//query di inserimento
$result = mysql_query($query) or die(mysql_error());
echo "<script language=javascript>";
echo " document.f.submit();";
echo"</script>";
}
elseif (isset($_POST['continua']) && isset($_POST['tipo']))
{
$data=$_POST['data_settimana'];
if (isset($_POST['chiave']))
$operai_selezionati = $_POST['chiave'];
echo "<h2>Settimana del " . format_data($data) . "</h2>";
echo "
<table cellspacing=0 border=1 class=modifica align=center width=100%>\n";
$settimana = array("Sabato","Domenica","Lunedì","Martedì","Mercoledì","Giovedì","Venerdì");
$week = array("sab","do","lun","mar","mer","gio","ven");
$week_int = array(1,2,3,4,5,6,7);
echo "<tr>"; //riga intestazione
echo "<th>Operaio</th>";
for($i=0; $i < count($settimana); $i++)
echo "<th colspan=2>$settimana[$i]</th>";
echo "</tr>\n";
echo "<tr rowspan=2>"; //riga intestazione
echo "<th> </th>";
for($i=0; $i < count($settimana); $i++)
echo "<th>Giornata</th><th>Extra</th>";
echo "</tr>\n";
$j=0;
$disabled="disabled";
echo "<form name=f action=index.php?tipo=operai&op=pres method=post>";
foreach ($operai_selezionati as $key => $value)
{
echo "<input type=hidden name=chiave[". $key ."] value=\"$value\">";
//recupera presenze aggiornate
$query = "SELECT r.giornata,r.extra,r.data_inizio_settimana
FROM registro_presenze r, operai o
WHERE o.id_operai = '$key'
AND o.id_operai = r.operai_id_operai AND r.data_inizio_settimana='$data'
ORDER BY r.giornata";
$result = mysql_query($query) or die(mysql_error());
$alterna="";
if(($j % 2) == 0) $alterna="class=alterna";
$j++;
echo "<tr $alterna><td>$value</td>"; //nome operaio
$riga = mysql_fetch_row($result);
for($k=0; $k < count($week_int);$k++)
{ $stato="";
$valore="";
if ($riga[0] == $week_int[$k])
{ $stato="checked";
$valore=$riga[1];
if ($_POST['tipo'] == "vis") //non modificabile
echo "<td align=center>X</td><td align=center>$valore</td>\n";
else //in caso di modifica
{
echo "<td align=center><input type=checkbox $stato name=\"" . $key . "[giornata][]\" value=". $week_int[$k] ."></td>\n";
echo "<td align=center><input type=text name='" . $key ."[$week_int[$k]]' value=\"$valore\" size=1 onKeyPress=\"return keyCheck(event, this);\" onchange=\"document.f.aggiorna.disabled=false;\" ></td>\n";
}
$riga = mysql_fetch_row($result);
}
else
{
echo "<td align=center><input type=checkbox name=" . $key ."[giornata][] value=" . $week_int[$k] ." onclick=\"if (array_checkbox(this)) document.f.aggiorna.disabled=false; else document.f.aggiorna.disabled=true; attiva(document.f,this,'" .$key."_" .$week_int[$k]."');\" ></td>\n"; //enabled(document.f,this.checked,'" . $key. "[" . $week_int[$k] . "]');\"
echo "<td align=center><input type=text disabled name='" . $key . "_" . $week_int[$k] ."' size=1 value=0 onKeyPress=\"return keyCheck(event, this);\"></td>\n"; //onKeyPress=\"return keyCheck(event, this);\"
}
}
//non modificabile
//echo "<td align=center><button type=submit name=tipo value=modifica><img src=\"supporto/edit.png\" width=40px height=20px alt=\"Modifica\"></button><input type=hidden name=continua value=continua></td>";
//elseif ($_POST['tipo'] == "modifica")
//else echo "<input type=hidden name=tipo value=vis>";
echo "</tr>\n";
}
if ($_POST['tipo'] != "vis")
{ echo "<input type=hidden name=tipo value=modifica>";
$disabled="";
}
echo "<input type=hidden name=data_settimana value=\"$data\">";
echo "<tr><th colspan=15 align=center><input type=submit $disabled name=aggiorna value=Aggiorna><button type=submit name=tipo value=modifica><img src=\"supporto/edit.png\" width=40px height=20px alt=\"Modifica\" ALIGN=\"ABSMIDDLE\"></button><input type=hidden name=continua value=continua></th></tr>";
echo "</table></form>
";
}
else
{
$query = "SELECT distinct(data_inizio_settimana) from registro_presenze order by data_inizio_settimana desc LIMIT 0,4";
$result=mysql_query($query);
echo "<form name=form_data method=POST action=index.php?tipo=operai&op=pres >"; //onsubmit=\"return verifica();\"
echo "
<table cellspacing=0 border=1 class=modifica align=center>\n";
echo "<tr><td colspan=2 align=center>Settimana del:<select name=data_settimana onclick=\"javascript: if (this[this.selectedIndex].text == 'Nuova settimana') show_calendar('document.form_data.data_settimana.options['+this.selectedIndex+']',document.form_data.data_settimana.options[document.form_data.data_settimana.selectedIndex].value);\">";
while($riga = mysql_fetch_row($result))
echo "<option value=" . $riga[0] . ">" . format_data($riga[0]) ."</option>";
echo "<option value=\"null\">Nuova settimana</option>";
echo "</select></td></tr>";
echo "<tr><td colspan=2><hr></td></tr>";
//prima maschera visualizza i nomi degli operai
$query="SELECT id_operai, CONCAT(cognome, \" \",nome) FROM operai ORDER BY cognome,nome";
$result=mysql_query($query);
$intestazione_tabella = array("<input type=checkbox name=\"check_all\" onclick=\"SelezTT(true); return true;\"> ","Seleziona operai da aggiornare");
//crea tabella che seleziona gli operai da aggiornare
echo "<tr>";
for($i=0; $i < count($intestazione_tabella); $i++)
{
echo "<th>" . $intestazione_tabella[$i] . "</th>";
}
echo "</tr>\n";
$j=0;
while ($riga = mysql_fetch_row($result))
{
$alterna="";
if(($j % 2) == 0) $alterna="class=alterna";
$j++;
echo "<tr $alterna>";
echo "<td><input type=checkbox name=chiave[" . $riga[0] ."] value=\"". ucwords($riga[1]) ."\" /></td>";
echo "<td>" . ucwords($riga[1]) ."</td>";
echo "</tr>\n";
}
echo "<tr><td colspan=2 align=center><button type=submit name=continua onclick=\"return verifica();\"><img src=\"supporto/forward.png\" width=30px height=30px></button></td></tr>";
echo "</table><input type=hidden name=tipo value=vis>";
echo "</form>
";
}
?>