cf0c1133fd
Files correlati : Ricompilazione Demo : [ ] Commento : Versione FAD del 11/10/2001 git-svn-id: svn://10.65.10.50/trunk@9917 c028cbd2-c16b-5b4b-a496-9718f37d4682
460 lines
13 KiB
PHP
Executable File
460 lines
13 KiB
PHP
Executable File
<?php
|
|
|
|
// Controlla il login di un utente
|
|
function validazione($username, $psw)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
$criteri = "SELECT id FROM $tbl_utenti WHERE username = '$username' AND pass = '$psw'";
|
|
$result = mysql_query($criteri, $db);
|
|
$myrow = mysql_fetch_array($result);
|
|
if ($myrow)
|
|
return $myrow["id"];
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
// Restituisce il corso a cui un utente e' abilitato
|
|
function corso($utente)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
$criteri = "SELECT idcorso FROM $tbl_utenti WHERE (id = $utente)";
|
|
$result = mysql_query($criteri, $db);
|
|
$myrow = mysql_fetch_array($result);
|
|
if ($myrow)
|
|
return $myrow["idcorso"];
|
|
else
|
|
return "";
|
|
}
|
|
|
|
// Restituisce tutte le informazioni su un utente
|
|
function generale($id)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
$criteri = "SELECT * FROM $tbl_utenti WHERE id = $id ";
|
|
$result = mysql_query($criteri, $db);
|
|
$myrow = mysql_fetch_array($result);
|
|
return $myrow;
|
|
}
|
|
|
|
// Scrive il login di un utente nella tabella accessi
|
|
function login($idutente, $login)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
$sql = "INSERT INTO $tbl_accessi (idutente, login, descrizione, modifica) VALUES($idutente, '$login', 'ONLINE', 'no') ";
|
|
$ins = mysql_query($sql,$db);
|
|
if ($ins)
|
|
{
|
|
$criteri = "SELECT id FROM $tbl_accessi WHERE login = '$login' ";
|
|
$result = mysql_query($criteri, $db);
|
|
$myrow = mysql_fetch_array($result);
|
|
return $myrow["id"];
|
|
}
|
|
}
|
|
|
|
// Scrive il logout di un utente nella tabella accessi
|
|
function logout($id, $ora)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
$sql = "UPDATE $tbl_accessi SET logout = '$ora' WHERE id = $id ";
|
|
$ins = mysql_query($sql,$db);
|
|
}
|
|
|
|
// Restituisce la differenza tra due date in Ore:Minuti:Secondi
|
|
function differenza($periodo1, $periodo2)
|
|
{
|
|
//string substr(string string, int start, int [length]);
|
|
$giorno1 = substr($periodo1, 8, 2);
|
|
$giorno2 = substr($periodo2, 8, 2);
|
|
$ora1 = substr($periodo1, 11, 2);
|
|
$ora2 = substr($periodo2, 11, 2);
|
|
$min1 = substr($periodo1, 14, 2);
|
|
$min2 = substr($periodo2, 14, 2);
|
|
$sec1 = substr($periodo1, 17, 2);
|
|
$sec2 = substr($periodo2, 17, 2);
|
|
$diff = (($ora2-$ora1)*3600) + (($min2-$min1)*60) + ($sec2-$sec1);
|
|
if ($giorno1 != $giorno2)
|
|
$diff = $diff + (($giorno2-$giorno1)*3600*24);
|
|
$ore = $diff;
|
|
$O = 0;
|
|
while ($ore >= 3600):
|
|
$ore = ($ore-3600);
|
|
$O = $O + 1;
|
|
endwhile;
|
|
$resto = ($diff-($O*3600));
|
|
$min = $resto;
|
|
$M = 0;
|
|
while ($min >= 60):
|
|
$min = ($min-60);
|
|
$M = $M + 1;
|
|
endwhile;
|
|
$sec = ($resto-($M*60));
|
|
if (strlen($sec) < 2)
|
|
$sec = "0".$sec;
|
|
if (strlen($M) < 2)
|
|
$M = "0".$M;
|
|
$tempo = $O.":".$M.":".$sec;
|
|
return $tempo;
|
|
|
|
}
|
|
|
|
// Effettua la somma di due tempi in Ore:Minuti:Secondi
|
|
function somma_tempo($tempo1, $tempo2)
|
|
{
|
|
if (strlen($tempo1) < 8){
|
|
$ora1 = substr($tempo1, 0, 1);
|
|
$min1 = substr($tempo1, 2, 2);
|
|
$sec1 = substr($tempo1, 5, 2);
|
|
}else{
|
|
$ora1 = substr($tempo1, 0 ,2);
|
|
$min1 = substr($tempo1, 3, 2);
|
|
$sec1 = substr($tempo1, 6, 2);
|
|
}
|
|
if (strlen($tempo2) < 8){
|
|
$ora2 = substr($tempo2, 0, 1);
|
|
$min2 = substr($tempo2, 2, 2);
|
|
$sec2 = substr($tempo2, 5, 2);
|
|
}else{
|
|
$ora2 = substr($tempo2, 0 ,2);
|
|
$min2 = substr($tempo2, 3, 2);
|
|
$sec2 = substr($tempo2, 6, 2);
|
|
}
|
|
$orat = ($ora1+$ora2);
|
|
$mint = ($min1+$min2);
|
|
$sect = ($sec1+$sec2);
|
|
if ($sect >= 60){
|
|
$sect = ($sect-60);
|
|
$mint = $mint+1;
|
|
}
|
|
if ($mint >= 60){
|
|
$mint = ($mint-60);
|
|
$orat = $orat+1;
|
|
}
|
|
if (strlen($sect) < 2)
|
|
$sect = "0".$sect;
|
|
if (strlen($mint) < 2)
|
|
$mint = "0".$mint;
|
|
$somma = $orat.":".$mint.":".$sect;
|
|
return $somma;
|
|
}
|
|
|
|
// Stabilisce se l'utente e' abilitato a eseguire i moduli di un corso
|
|
function abilitato($utente, $corso)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
$criteri = "SELECT * FROM $tbl_utenti WHERE (id = $utente)";
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_fetch_array($result);
|
|
if ($myrow)
|
|
{
|
|
if ($myrow[idcorso] == $corso)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
|
|
// Restituisce 0 se non si deve effettuare il test iniziale del modulo altrimenti restituticse l'ID
|
|
function inizio($modulo, $utente)
|
|
{
|
|
include("required.php");
|
|
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
//$criteri = "SELECT moduli_righe.idmodulo, moduli_righe.iniziale, moduli_righe.idtest, prove.idutente ";
|
|
//$criteri .= "FROM moduli_righe INNER JOIN prove ON moduli_righe.idtest = prove.idtest ";
|
|
//$criteri .= "WHERE ($tbl_moduli.id = $modulo) AND (prove.idutente = $utente) AND (moduli_righe.iniziale = $s_vero)";
|
|
|
|
$criteri = "SELECT * FROM moduli_righe WHERE (idmodulo = $modulo) AND (iniziale = $s_vero)";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
if ($myrow = mysql_fetch_array($result))
|
|
{
|
|
$criteri1 = "SELECT prove.idutente, prove.idtest FROM prove WHERE (prove.idutente = $utente) AND (prove.idtest = $myrow[idtest])";
|
|
$result1 = mysql_query($criteri1,$db);
|
|
if ($myrow1 = mysql_fetch_array($result1))
|
|
return 0;
|
|
else
|
|
return $myrow[idtest];
|
|
}
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
|
|
// Restutuisce il test finale del corso se un utente puo' eseguirlo
|
|
function fine($utente)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$criteri = "SELECT $tbl_utenti.id, $tbl_test.posizione, $tbl_test.nome, $tbl_test.id as test, $tbl_test.idlezione as lezione ";
|
|
$criteri .= "FROM (($tbl_corsi LEFT JOIN $tbl_utenti ON $tbl_corsi.id = $tbl_utenti.idcorso) LEFT JOIN $tbl_lezioni ON $tbl_corsi.id = $tbl_lezioni.idcorso) LEFT JOIN $tbl_test ON $tbl_lezioni.id = $tbl_test.idlezione ";
|
|
$criteri .= "WHERE ($tbl_utenti.id = $utente) AND ($tbl_test.posizione = '$s_fine')";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_fetch_array($result);
|
|
if ($myrow)
|
|
{
|
|
$criteri1 = "SELECT * FROM $tbl_prove WHERE (idutente = $utente) AND (idtest = $myrow[test])";
|
|
//echo $criteri1;
|
|
$result1 = mysql_query($criteri1,$db);
|
|
$myrow1 = mysql_fetch_array($result1);
|
|
if ($myrow1)
|
|
return 0;
|
|
else
|
|
return $myrow[test];
|
|
}
|
|
}
|
|
|
|
|
|
// da il permesso di scaricare una lezione
|
|
// se test_prima controllando che sia stato effettuato il test iniziale
|
|
// altrimenti che sia stato effettuato il test finale della lezione precedente.
|
|
function controllo_download($lezione, $utente)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$modulo = getvar($tbl_moduli_righe, "idmodulo", "idlezione =".$lezione);
|
|
$t_prima = getvar($tbl_moduli, "test_prima", "id=".$modulo);
|
|
|
|
if ($t_prima == $s_vero)
|
|
{
|
|
$test = getvar($tbl_moduli_righe, "idtest", "idlezione = ".$lezione." AND posizione = ".$s_prima);
|
|
echo "qui";
|
|
if ($test > 0)
|
|
{
|
|
if (test_effettuato($test, $utente))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
$progressivo = getvar($tbl_moduli_righe, "progressivo", "idlezione =".$lezione." AND idmodulo = ".$modulo);
|
|
//echo $progressivo;
|
|
if ($progressivo != 0)
|
|
{
|
|
//$modulo = getvar($tbl_lezioni, "idmodulo", "id =".$lezione);
|
|
//echo $modulo;
|
|
if ($progressivo == $l_end)
|
|
$p_lez_prec = max_lezione($modulo);
|
|
else
|
|
$p_lez_prec = $progressivo - 1;
|
|
//echo $p_lez_prec;
|
|
//$lez_prec = getvar($tbl_lezioni, "id", "idmodulo =".$modulo." AND progressivo = ".$p_lez_prec);
|
|
//$lez_prec = getvar($tbl_moduli_righe, "idlezione", "idmodulo =".$modulo." AND progressivo = ".$p_lez_prec);
|
|
$test_prec = getvar($tbl_moduli_righe, "idtest", "idmodulo =".$modulo." AND progressivo = ".$p_lez_prec);
|
|
if ($test_prec > 0)
|
|
{
|
|
//echo $lez_prec;
|
|
//$test = max_test($lez_prec);
|
|
//if ($test > 0)
|
|
//{
|
|
if (test_effettuato($test_prec, $utente))
|
|
return true;
|
|
else
|
|
return false;
|
|
//}
|
|
//else
|
|
return false;
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
// Restituisce Vero se il test e' stato effettuato
|
|
function test_effettuato($test, $utente)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$criteri = "SELECT * FROM $tbl_prove WHERE (idtest = $test) AND (idutente = $utente) ";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_num_rows($result);
|
|
//echo $myrow;
|
|
if ($myrow > 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
|
|
}
|
|
|
|
// Da il permesso di effettuare un test se e' stato eseguito il test finale della lezione precedente
|
|
function test_prima($test, $utente)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$lezione = getvar($tbl_test, "idlezione", "id =".$test);
|
|
$progressivo = getvar($tbl_lezioni, "progressivo", "id =".$lezione);
|
|
if ($progressivo != 0)
|
|
{
|
|
$modulo = getvar($tbl_lezioni, "idmodulo", "id =".$lezione);
|
|
$lezione_prec = getvar($tbl_lezioni, "id", "idmodulo =".$modulo." AND progressivo =".($progressivo-1));
|
|
}
|
|
$criteri = "SELECT $tbl_moduli.test_prima ";
|
|
$criteri .= "FROM $tbl_moduli LEFT JOIN $tbl_lezioni ON $tbl_moduli.id = $tbl_lezioni.idmodulo ";
|
|
$criteri .= "WHERE $tbl_lezioni.id = $lezione ";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_fetch_array($result);
|
|
if ($myrow[test_prima] == $s_falso)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
|
|
// Da il permesso di effettuare un test se e' stata scaricata la lezione
|
|
function test_dopo($test, $utente)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$lezione = getvar($tbl_moduli_righe, "idlezione", "idtest =".$test);
|
|
//echo $lezione;
|
|
$criteri = "SELECT * FROM $tbl_download WHERE (idlezione = $lezione) AND (idutente = $utente) ";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_num_rows($result);
|
|
if ($myrow > 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
|
|
}
|
|
|
|
// Restituisce true se l'utente puo' effettuare l'ultimo test di un modulo
|
|
function fine_abilita($utente)
|
|
{
|
|
include("required.php");
|
|
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$criteri1 = "SELECT $tbl_lezioni.progressivo, $tbl_test.posizione, $tbl_prove.idutente ";
|
|
$criteri1 .= "FROM ($tbl_lezioni LEFT JOIN $tbl_test ON $tbl_lezioni.id = $tbl_test.idlezione) LEFT JOIN $tbl_prove ON $tbl_test.id = $tbl_prove.idtest ";
|
|
$criteri1 .= "WHERE ($tbl_lezioni.progressivo = $l_end) AND ($tbl_test.posizione = $s_dopo) AND ($tbl_prove.idutente = $utente) ";
|
|
//echo $criteri1;
|
|
$result1 = mysql_query($criteri1,$db);
|
|
if ($myrow1 = mysql_fetch_array($result1))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
// Restituisce il numero massimo di test di una lezione
|
|
function max_test($lezione)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
//$criteri1 = "SELECT COUNT($tbl_test.id) AS conto FROM $tbl_test WHERE $tbl_test.idlezione = $myrow[id]";
|
|
$criteri1 = "SELECT COUNT(*) AS conto FROM $tbl_moduli_righe WHERE $tbl_moduli_righe.idlezione = $lezione";
|
|
//echo $criteri1;
|
|
$result1 = mysql_query($criteri1,$db);
|
|
$myrow1 = mysql_fetch_array($result1);
|
|
return $myrow[conto];
|
|
}
|
|
|
|
// Restituisce il numero massimo di lezioni di un modulo
|
|
function max_lezione($modulo)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$max = 0;
|
|
//$criteri1 = "SELECT COUNT($tbl_test.id) AS conto FROM $tbl_test WHERE $tbl_test.idlezione = $myrow[id]";
|
|
//$criteri1 = "SELECT MAX(progressivo) AS alto FROM $tbl_lezioni WHERE $tbl_lezioni.idmodulo = $modulo HAVING progressivo <> $l_end";
|
|
//$criteri1 = "SELECT * FROM $tbl_lezioni WHERE $tbl_lezioni.idmodulo = $modulo";
|
|
$criteri1 = "SELECT * FROM $tbl_moduli_righe WHERE $tbl_moduli_righe.idmodulo = $modulo";
|
|
//echo $criteri1;
|
|
$result1 = mysql_query($criteri1,$db);
|
|
if ($myrow1 = mysql_fetch_array($result1))
|
|
{
|
|
do
|
|
{
|
|
if ($myrow1[progressivo] != $l_end)
|
|
if ($max < $myrow1[progressivo]) $max = $myrow1[progressivo];
|
|
|
|
}while ($myrow1 = mysql_fetch_array($result1));
|
|
}
|
|
return $max;
|
|
}
|
|
|
|
|
|
|
|
// Restituisce il massimo numero di test che ha una lezione di un modulo
|
|
function max_num_test($modulo)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$max = 0;
|
|
$criteri = "SELECT $tbl_lezioni.id FROM $tbl_lezioni WHERE $tbl_lezioni.idmodulo = $modulo";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
if ($myrow = mysql_fetch_array($result))
|
|
{
|
|
do
|
|
{
|
|
$num = max_test($myrow[id]);
|
|
if ($max < $num) $max = $num;
|
|
|
|
}while ($myrow = mysql_fetch_array($result));
|
|
}
|
|
return $max;
|
|
}
|
|
|
|
|
|
// DLOOKUP rudimentale
|
|
function getvar($tabella, $campo, $criteri)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$criteri = "SELECT $campo FROM $tabella WHERE $criteri";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
if ($myrow = mysql_fetch_array($result))
|
|
return $myrow[$campo];
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
|
|
?>
|