LIKE sur recherche connexions
This commit is contained in:
parent
29e740a66b
commit
01f005f384
@ -8,31 +8,8 @@ $username = Username();
|
||||
$profil = Profil($username);
|
||||
FiltreProfil($profil);
|
||||
|
||||
$db = db_connect();
|
||||
|
||||
$objet = $_POST["objet"];
|
||||
$liste_const = ""; // variable globale
|
||||
|
||||
switch ($objet) {
|
||||
case "connexions":
|
||||
$donnees = RechercheConnexions($db);
|
||||
break;
|
||||
|
||||
case "utilisateurs":
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!$donnees) {
|
||||
$resultats = "Vous devez saisir au moins un critère.";
|
||||
}
|
||||
else {
|
||||
$resultats = FormatteResultats($db, $donnees);
|
||||
}
|
||||
|
||||
|
||||
// fonction RechercheConnexions() : renvoie un tableau de résultats
|
||||
// fonction RechercheConnexions() : renvoie un tableau de résultats contenant les connexions demandées
|
||||
function RechercheConnexions(&$db) {
|
||||
global $_POST;
|
||||
global $liste_const;
|
||||
@ -50,25 +27,25 @@ function RechercheConnexions(&$db) {
|
||||
if ($salle != "") {
|
||||
$req_connexions = $req_connexions.", machines";
|
||||
$req_total_connexions = $req_total_connexions.", machines";
|
||||
$where = $where . "hote = machine_id AND salle = \"$salle\" ";
|
||||
$where = $where . "hote = machine_id AND salle LIKE \"$salle\" ";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "salle = <i>$salle</i><br/>";
|
||||
}
|
||||
if ($machine != "") {
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$where = $where . $and . "hote = \"{$machine}\"";
|
||||
$where = $where . $and . "hote LIKE \"{$machine}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "machine = <i>$machine</i><br/>";
|
||||
}
|
||||
if ($compte != "") {
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$where = $where . $and . "username = \"{$compte}\"";
|
||||
$where = $where . $and . "username LIKE \"{$compte}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "compte = <i>$compte</i><br/>";
|
||||
}
|
||||
if ($ip != "") {
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$where = $where . $and . " ip = \"{$ip}\"";
|
||||
$where = $where . $and . " ip LIKE \"{$ip}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "ip = <i>$ip</i><br/>";
|
||||
}
|
||||
@ -76,25 +53,29 @@ function RechercheConnexions(&$db) {
|
||||
// transformation de la date JJ/MM/AAAA en date iso AAAA-MM-JJ
|
||||
$tab_deb = explode("/", $date_debut);
|
||||
$tab_fin = explode("/", $date_fin);
|
||||
$isodate_d = sprintf( "%04d-%02d-%02d", (int)trim($tab_deb[2]), (int)trim($tab_deb[1]), (int)trim($tab_deb[0]) );
|
||||
$isodate_f = sprintf( "%04d-%02d-%02d", (int)trim($tab_fin[2]), (int)trim($tab_fin[1]), (int)trim($tab_fin[0]) );
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$date_debut_00 = "$isodate_d 00:00:00";
|
||||
$date_fin_24 = "$isodate_f 23:59:59";
|
||||
$where = $where . $and . " debut_con >= \"{$date_debut_00}\" AND fin_con <= \"{$date_fin_24}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "du <i>$date_debut</i> au <i>$date_fin</i><br/>";
|
||||
if (isset($tab_deb[2]) && isset($tab_fin[2])) {
|
||||
$isodate_d = sprintf( "%04d-%02d-%02d", (int)trim($tab_deb[2]), (int)trim($tab_deb[1]), (int)trim($tab_deb[0]) );
|
||||
$isodate_f = sprintf( "%04d-%02d-%02d", (int)trim($tab_fin[2]), (int)trim($tab_fin[1]), (int)trim($tab_fin[0]) );
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$date_debut_00 = "$isodate_d 00:00:00";
|
||||
$date_fin_24 = "$isodate_f 23:59:59";
|
||||
$where = $where . $and . " debut_con >= \"{$date_debut_00}\" AND fin_con <= \"{$date_fin_24}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "du <i>$date_debut</i> au <i>$date_fin</i><br/>";
|
||||
}
|
||||
}
|
||||
elseif ($date_debut != "") {
|
||||
// transformation de la date JJ/MM/AAAA en date iso AAAA-MM-JJ
|
||||
$tab_deb = explode("/", $date_debut);
|
||||
$isodate_d = sprintf( "%04d-%02d-%02d", (int)trim($tab_deb[2]), (int)trim($tab_deb[1]), (int)trim($tab_deb[0]) );
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$date_debut_00 = "$isodate_d 00:00:00";
|
||||
$date_debut_24 = "$isodate_d 23:59:59";
|
||||
$where = $where . $and . " debut_con >= \"{$date_debut_00}\" AND fin_con <= \"{$date_debut_24}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "date : <i>$date_debut</i><br/>";
|
||||
if (isset($tab_deb[2])) {
|
||||
$isodate_d = sprintf( "%04d-%02d-%02d", (int)trim($tab_deb[2]), (int)trim($tab_deb[1]), (int)trim($tab_deb[0]) );
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$date_debut_00 = "$isodate_d 00:00:00";
|
||||
$date_debut_24 = "$isodate_d 23:59:59";
|
||||
$where = $where . $and . " debut_con >= \"{$date_debut_00}\" AND fin_con <= \"{$date_debut_24}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "date : <i>$date_debut</i><br/>";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$contrainte) {
|
||||
@ -106,6 +87,54 @@ function RechercheConnexions(&$db) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
// fonction RechercheUtilisateurs : renvoie un tableau de résultats contenant les utilisateurs demandés
|
||||
function RechercheUtilisateurs(&$db) {
|
||||
global $_POST;
|
||||
global $liste_const;
|
||||
|
||||
$compte = db_escape_string($db, $_POST["compte"]);
|
||||
$nom = db_escape_string($db, $_POST["nom"]);
|
||||
$prenom = db_escape_string($db, $_POST["prenom"]);
|
||||
$groupe = db_escape_string($db, $_POST["groupe"]);
|
||||
|
||||
$req_utilisateurs = "SELECT username AS 'Compte', prenom AS 'Prénom', nom AS 'Nom', groupe AS 'Groupe', compte_id AS 'Id' FROM comptes";
|
||||
$where = " WHERE ";
|
||||
$contrainte = false;
|
||||
if ($compte != "") {
|
||||
$where = $where . "compte LIKE \"$compte\" ";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "compte = <i>$compte</i><br/>";
|
||||
}
|
||||
if ($nom != "") {
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$where = $where . $and . "nom LIKE \"{$nom}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "machine = <i>$nom</i><br/>";
|
||||
}
|
||||
if ($prenom != "") {
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$where = $where . $and . "prenom LIKE \"{$prenom}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "prenom = <i>$prenom</i><br/>";
|
||||
}
|
||||
if ($groupe != "") {
|
||||
$and = ($contrainte) ? " AND " : "";
|
||||
$where = $where . $and . "groupe LIKE \"{$groupe}\"";
|
||||
$contrainte = true;
|
||||
$liste_const = $liste_const. "groupe = <i>$groupe</i><br/>";
|
||||
}
|
||||
|
||||
if (!$contrainte) {
|
||||
return false;
|
||||
}
|
||||
$req = "($req_utilisateurs $where) ORDER BY username DESC";
|
||||
$res = db_query($db, $req);
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// fonction AfficheResultats($tab) : formatte l'affichage d'un jeu de résultats
|
||||
function FormatteResultats(&$db, &$res) {
|
||||
$r = "<th>n°</th>";
|
||||
@ -131,6 +160,33 @@ function FormatteResultats(&$db, &$res) {
|
||||
}
|
||||
return $resultats;
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Programme principal
|
||||
|
||||
$db = db_connect();
|
||||
|
||||
$objet = $_POST["objet"];
|
||||
$liste_const = ""; // variable globale
|
||||
switch ($objet) {
|
||||
case "connexions":
|
||||
$donnees = RechercheConnexions($db);
|
||||
break;
|
||||
|
||||
case "utilisateurs":
|
||||
$donnees = RechercheUtilisateurs($db);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!$donnees) {
|
||||
$resultats = "Vous devez saisir au moins un critère.";
|
||||
}
|
||||
else {
|
||||
$resultats = FormatteResultats($db, $donnees);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="fr">
|
||||
|
Loading…
x
Reference in New Issue
Block a user