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
370 lines
12 KiB
PHP
Executable File
370 lines
12 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 0;
|
|
}
|
|
|
|
// 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 le lezioni 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 il test iniziale del modulo
|
|
function inizio($modulo, $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 ";
|
|
//$criteri .= "FROM (($tbl_moduli 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_inizio')";
|
|
$criteri = "SELECT $tbl_moduli.id, $tbl_test.posizione, $tbl_test.nome, $tbl_test.id as test ";
|
|
$criteri .= "FROM ($tbl_moduli LEFT JOIN $tbl_lezioni ON $tbl_moduli.id = $tbl_lezioni.idmodulo) LEFT JOIN $tbl_test ON $tbl_lezioni.id = $tbl_test.idlezione ";
|
|
$criteri .= "WHERE ($tbl_moduli.id = $modulo) AND ($tbl_test.posizione = '$s_inizio')";
|
|
echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
//$num_rows = mysql_num_rows($result);
|
|
$myrow = mysql_fetch_array($result);
|
|
if ($myrow)
|
|
//if ($num_rows != 0)
|
|
{
|
|
$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];
|
|
}
|
|
}
|
|
|
|
|
|
// Restutuisce il test finale del modulo
|
|
function fine($utente, $modulo)
|
|
{
|
|
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')";
|
|
|
|
$criteri = "SELECT $tbl_test.posizione, $tbl_test.id as test, $tbl_test.idlezione as lezione ";
|
|
$criteri .= "FROM $tbl_lezioni ON $tbl_moduli.id = $tbl_lezioni.idmodulo) LEFT JOIN $tbl_test ON $tbl_lezioni.id = $tbl_test.idlezione ";
|
|
$criteri .= "WHERE ($tbl_moduli.id = $modulo) 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
|
|
// Verificando, qualora fosse abilitato $test_prima, che sia stato effettuato il test iniziale della lezione,
|
|
// 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);
|
|
if ($test_prima == 'Vero')
|
|
{
|
|
$criteri = "SELECT * FROM $tbl_lezioni WHERE (id = $lezione) ";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_fetch_array($result);
|
|
if ($myrow[progressivo] != 0)
|
|
{
|
|
if ($myrow[progressivo] >= 1)
|
|
{
|
|
//$cur = $myrow[progressivo] - 1;
|
|
$cur = $myrow[progressivo];
|
|
$criteri1 = "SELECT $tbl_lezioni.progressivo, $tbl_lezioni.nome, $tbl_test.nome, $tbl_test.posizione, $tbl_prove.id ";
|
|
$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 = $cur) AND ($tbl_test.posizione = '$s_prima') AND ($tbl_prove.idutente = $utente)";
|
|
//echo $criteri1;
|
|
$result1 = mysql_query($criteri1,$db);
|
|
if ($myrow1 = mysql_fetch_array($result1))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
return true;
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
$criteri = "SELECT * FROM $tbl_lezioni WHERE (id = $lezione) ";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_fetch_array($result);
|
|
//echo $myrow[progressivo];
|
|
if ($myrow[progressivo] != 0)
|
|
{
|
|
if ($myrow[progressivo] >= 1)
|
|
{
|
|
$cur = $myrow[progressivo] - 1;
|
|
$criteri1 = "SELECT $tbl_lezioni.progressivo, $tbl_lezioni.nome, $tbl_test.nome, $tbl_test.posizione, $tbl_prove.id ";
|
|
$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 = $cur) 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;
|
|
}
|
|
else
|
|
return true;
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Da il permesso di effettuare un test
|
|
// Verificando che sia stato effettuato il test finale della lezione precedente
|
|
function controllo_test($lezione, $utente)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
$criteri = "SELECT * FROM $tbl_lezioni WHERE (id = $lezione) ";
|
|
//echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_fetch_array($result);
|
|
//echo $myrow[progressivo];
|
|
if ($myrow[progressivo] != 0)
|
|
{
|
|
if ($myrow[progressivo] > 1)
|
|
{
|
|
$cur = $myrow[progressivo] - 1;
|
|
$criteri1 = "SELECT $tbl_lezioni.progressivo, $tbl_lezioni.nome, $tbl_test.nome, $tbl_test.posizione, $tbl_prove.id ";
|
|
$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 = $cur) 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;
|
|
}
|
|
else
|
|
return true;
|
|
}
|
|
else
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
function fine_abilita($utente, $modulo)
|
|
{
|
|
include("required.php");
|
|
$db = mysql_connect($ip, $user, $password);
|
|
mysql_select_db($dataname,$db);
|
|
|
|
//$criteri ="SELECT utenti.id, Max(lezioni.progressivo) AS ultimo ";
|
|
//$criteri .= "FROM utenti LEFT JOIN lezioni ON utenti.idcorso = lezioni.idcorso ";
|
|
//$criteri .= "GROUP BY utenti.id HAVING (utenti.id = $utente) ";
|
|
|
|
$criteri ="SELECT Max(lezioni.progressivo) AS ultimo ";
|
|
//$criteri .= "FROM $tbl_moduli LEFT JOIN $tbl_lezioni ON $tbl_moduli.id = $tbl_lezioni.idmodulo ";
|
|
//$criteri .= "GROUP BY $tbl_moduli.id HAVING (utenti.id = $utente) ";
|
|
$criteri .= "FROM $tbl_lezioni WHERE $tbl_lezioni.idmodulo = $modulo ";
|
|
echo $criteri;
|
|
$result = mysql_query($criteri,$db);
|
|
$myrow = mysql_fetch_array($result);
|
|
echo $myrow["ultimo"];
|
|
$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 = $myrow[ultimo]) 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;
|
|
|
|
}
|
|
|
|
|
|
?>
|