360 lines
8.5 KiB
PHP
Executable File
360 lines
8.5 KiB
PHP
Executable File
<?php
|
|
|
|
require_once 'include/Modele.php';
|
|
|
|
// require_once 'include/Modele.php';
|
|
// require_once '../Framework/Modele.php';
|
|
|
|
class fingertable extends Modele
|
|
{
|
|
public function getPerifique()
|
|
{
|
|
$sql = "SELECT * FROM device ORDER BY device_name ASC";
|
|
$liste = $this->executerRequete($sql);
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function getPerifiqueAcSn($vc)
|
|
{
|
|
$sql = "SELECT * FROM device WHERE (vc=?)";
|
|
$liste = $this->executerRequete($sql, array($vc));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function getPerifiqueBySn($sn)
|
|
{
|
|
$sql = "SELECT * FROM device WHERE (sn=?)";
|
|
$liste = $this->executerRequete($sql, array($sn));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
public function ajouterPerifique($device_name, $sn, $vc, $ac, $vkey)
|
|
{
|
|
$sql = "insert into device (device_name, sn, vc, ac, vkey) values (?, ?, ?, ?, ?)";
|
|
$result = $this->executerRequete($sql, array($device_name, $sn, $vc, $ac, $vkey));
|
|
return $result;
|
|
}
|
|
|
|
public function supprimerPerifique($sn)
|
|
{
|
|
$sql = 'DELETE FROM device WHERE (sn=?)';
|
|
$result = $this->executerRequete($sql, array($sn));
|
|
return $result;
|
|
}
|
|
|
|
public function ajouterUtilisateur($user_name)
|
|
{
|
|
$sql = "insert into user (user_name) values (?)";
|
|
$result = $this->executerRequete($sql, array($user_name));
|
|
return $result;
|
|
}
|
|
|
|
public function supprimerUtilisateur($user_id)
|
|
{
|
|
$sql = 'DELETE FROM user WHERE (user_id=?)';
|
|
$result = $this->executerRequete($sql, array($user_id));
|
|
return $result;
|
|
}
|
|
|
|
public function supprimerEmpreinte($user_id)
|
|
{
|
|
$sql = 'DELETE FROM finger WHERE (user_id=?)';
|
|
$result = $this->executerRequete($sql, array($user_id));
|
|
return $result;
|
|
}
|
|
|
|
function getUtilisateur()
|
|
{
|
|
$sql = 'SELECT * FROM user ORDER BY user_name ASC';
|
|
$liste = $this->executerRequete($sql);
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function getSubstituts($user_id)
|
|
{
|
|
$sql = "call sp_p_get_substituts_finger(?);";
|
|
$liste = $this->executerRequete($sql, array($user_id));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function getUtilisateurId($user_id)
|
|
{
|
|
$sql = 'SELECT * FROM user WHERE (user_id=?)';
|
|
$liste = $this->executerRequete($sql, array($user_id));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function getListeUtilisateur()
|
|
{
|
|
$sql = 'SELECT a.* FROM user AS a JOIN finger AS b ON a.user_id=b.user_id';
|
|
$liste = $this->executerRequete($sql);
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function periferiqueCheckSn($sn)
|
|
{
|
|
$sql = "SELECT count(sn) as ct FROM device WHERE (sn=?)";
|
|
$liste = $this->executerRequete($sql, array($sn));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function checkNomUser($user_name)
|
|
{
|
|
$sql = "SELECT user_name FROM user WHERE (user_name=?)";
|
|
$liste = $this->executerRequete($sql, array($user_name));
|
|
// $arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
// return $arr;
|
|
return $liste;
|
|
}
|
|
|
|
function getEmpreinteUtilisateur($user_id)
|
|
{
|
|
$sql = "SELECT * FROM finger WHERE (user_id=?)";
|
|
$liste = $this->executerRequete($sql, array($user_id));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function getNbEmpreinteUtilisateur($user_id)
|
|
{
|
|
$sql = "SELECT count(finger_id) as ct FROM finger WHERE (user_id=?)";
|
|
$liste = $this->executerRequete($sql, array($user_id));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function ObtenirLog()
|
|
{
|
|
$sql = 'SELECT * FROM log ORDER BY log_time DESC';
|
|
$liste = $this->executerRequete($sql);
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
function creerLog($user_name, $time, $sn)
|
|
{
|
|
$sql = "insert into log (user_name, data) values (?, ?)";
|
|
$data = date('d/m/Y H:i:s', strtotime($time))." (Heure locale) | ".$sn." (SN)";
|
|
$result = $this->executerRequete($sql, array($user_name, $data));
|
|
return $result;
|
|
}
|
|
|
|
function ajouterEmpreinte($user_id, $finger_data)
|
|
{
|
|
$sql = "insert into finger (user_id, finger_data) values (?,?)";
|
|
$result = $this->executerRequete($sql, array($user_id, $finger_data));
|
|
return $result;
|
|
}
|
|
|
|
function ObtenirEmpreinteId($user_id)
|
|
{
|
|
$sql = 'SELECT MAX(finger_id) as fid FROM finger WHERE (user_id=?)';
|
|
$liste = $this->executerRequete($sql, array($user_id));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
|
|
|
|
function initialiserJeton($user_id)
|
|
{
|
|
// $idJeton = uniqid();
|
|
|
|
$sql = "call sp_p_init_finger(?);";
|
|
$this->executerRequete($sql, array($user_id));
|
|
}
|
|
|
|
function majJeton($user_id, $succes)
|
|
{
|
|
$sql = "call sp_p_maj_finger(?, ?);";
|
|
$this->executerRequete($sql, array($user_id, $succes));
|
|
}
|
|
|
|
function verifierFinger($user_id)
|
|
{
|
|
$sql = "call sp_p_check_finger(?);";
|
|
$liste = $this->executerRequete($sql, array($user_id));
|
|
$arr = $liste->fetchAll(PDO::FETCH_ASSOC);
|
|
return $arr;
|
|
}
|
|
} // FIN CLASS fingertable
|
|
|
|
// Début fonctions
|
|
|
|
function getDevice() {
|
|
$fingertable = new fingertable();
|
|
return $fingertable->getPerifique();
|
|
}
|
|
|
|
function getDeviceAcSn($vc) {
|
|
$fingertable = new fingertable();
|
|
return $fingertable->getPerifiqueAcSn($vc);
|
|
}
|
|
|
|
function getDeviceBySn($sn) {
|
|
$fingertable = new fingertable();
|
|
return $fingertable->getPerifiqueBySn($sn);
|
|
}
|
|
|
|
function getUser() {
|
|
$fingertable = new fingertable();
|
|
return $fingertable->getUtilisateur();
|
|
}
|
|
|
|
|
|
function getSurrogates($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
return $fingertable->getSubstituts($user_id);
|
|
}
|
|
|
|
function getUserId($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
return $fingertable->getUtilisateurId($user_id);
|
|
}
|
|
|
|
function deviceCheckSn($sn) {
|
|
$fingertable = new fingertable();
|
|
$data = $fingertable->periferiqueCheckSn($sn);
|
|
|
|
$ct=$data['0']['ct'];
|
|
|
|
if (($ct!='0') && ($ct!=''))
|
|
{
|
|
return "Ce N° de série existe déjà!";
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
function checkUserName($user_name)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$_user = $fingertable->checkNomUser($user_name);
|
|
$row = $_user->rowCount();
|
|
|
|
if ($row>0) {
|
|
return "Cet utilisateur existe déjà!";
|
|
} else {
|
|
return "1";
|
|
}
|
|
}
|
|
|
|
function getUserFinger($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
return $fingertable->getEmpreinteUtilisateur($user_id);
|
|
}
|
|
|
|
function getLog()
|
|
{
|
|
$fingertable = new fingertable();
|
|
return $fingertable->ObtenirLog();
|
|
}
|
|
|
|
function createLog($user_name, $time, $sn)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result1 = $fingertable->creerLog($user_name, $time, $sn);
|
|
|
|
if ($result1) {
|
|
return 1;
|
|
} else {
|
|
return "Error insert log data!";
|
|
}
|
|
}
|
|
|
|
function addDevice($device_name, $sn, $vc, $ac, $vkey)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->ajouterPerifique($device_name, $sn, $vc, $ac, $vkey);
|
|
return $result;
|
|
}
|
|
|
|
function deleteDevice($sn)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->supprimerPerifique($sn) ;
|
|
return $result;
|
|
|
|
}
|
|
|
|
function addUser($user_name)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->ajouterUtilisateur($user_name) ;
|
|
return $result;
|
|
}
|
|
|
|
|
|
function deleteUser($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->supprimerUtilisateur($user_id) ;
|
|
return $result;
|
|
}
|
|
|
|
function deleteFinger($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->supprimerEmpreinte($user_id);
|
|
return $result;
|
|
}
|
|
|
|
function getListUsers()
|
|
{
|
|
$fingertable = new fingertable();
|
|
return $fingertable->getListeUtilisateur();
|
|
}
|
|
|
|
function addFinger($user_id, $finger_data)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->ajouterEmpreinte($user_id, $finger_data);
|
|
return $result;
|
|
}
|
|
|
|
function getFingerId($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->ObtenirEmpreinteId($user_id) ;
|
|
return $result;
|
|
}
|
|
|
|
function getFingerCountUser($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->getNbEmpreinteUtilisateur($user_id);
|
|
return $result;
|
|
}
|
|
|
|
function initJeton($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$fingertable->initialiserJeton($user_id);
|
|
}
|
|
|
|
function updateJeton($user_id, $succes)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$fingertable->majJeton($user_id, $succes);
|
|
}
|
|
|
|
function checkFinger($user_id)
|
|
{
|
|
$fingertable = new fingertable();
|
|
$result = $fingertable->verifierFinger($user_id);
|
|
return $result;
|
|
}
|
|
|
|
?>
|