affichage ping formaté
This commit is contained in:
parent
08c55abf15
commit
786a2fee32
@ -318,5 +318,61 @@ function ArchiveConnexions() {
|
||||
return $nb_archivables;
|
||||
}
|
||||
|
||||
// Fonction PingTimestamp() :
|
||||
// Renvoie un tableau du timestamp de la dernière réponse au ping des machines
|
||||
// ping_timestamps["machine_id"] = time_stamp
|
||||
function PingTimestamps() {
|
||||
$db = db_connect();
|
||||
|
||||
$ping_timestamps = array();
|
||||
$req_timestamp = "SELECT machine_id, ping_timestamp FROM ping;";
|
||||
$res = db_query($db, $req_timestamp);
|
||||
while ($ts = db_fetch_row($res)) {
|
||||
$ping_timestamps[$ts[0]] = $ts[1];
|
||||
}
|
||||
db_free($res);
|
||||
return $ping_timestamps;
|
||||
}
|
||||
|
||||
// Fonction DateDiff(date1, date2)
|
||||
// date1 et date2 sont des objets timestamp
|
||||
// Renvoie un objet $delta :
|
||||
// $delta['second'] = nb de secondes du delta
|
||||
// $delta['minute'] = nb de minutes du delta
|
||||
// $delta['hour'] = nb d'heures du delta
|
||||
// $delta['day'] = nb de jours du delta
|
||||
function DateDiff($date1, $date2){
|
||||
$diff = abs($date1 - $date2); // abs pour avoir la valeur absolute, ainsi éviter d'avoir une différence négative
|
||||
$delta = array();
|
||||
|
||||
$tmp = $diff;
|
||||
$delta['second'] = $tmp % 60;
|
||||
|
||||
$tmp = floor( ($tmp - $delta['second']) /60 );
|
||||
$delta['minute'] = $tmp % 60;
|
||||
|
||||
$tmp = floor( ($tmp - $delta['minute'])/60 );
|
||||
$delta['hour'] = $tmp % 24;
|
||||
|
||||
$tmp = floor( ($tmp - $delta['hour']) /24 );
|
||||
$delta['day'] = $tmp;
|
||||
|
||||
return $delta;
|
||||
}
|
||||
|
||||
// Fonction FormateDelta(&delta)
|
||||
// Retourne une chaîne de caractère du delta entre deux dates arrondi à la seconde, à la minute, à l'heure ou au jour
|
||||
function FormateDelta(&$delta) {
|
||||
if ($delta['day'] != 0) {
|
||||
return (string)$delta['day']." jours";
|
||||
}
|
||||
if ($delta['hour'] != 0) {
|
||||
return (string)$delta['hour']." heures";
|
||||
}
|
||||
if ($delta['minute'] != 0) {
|
||||
return (string)$delta['minute']." minutes";
|
||||
}
|
||||
return (string)$delta['second']." secondes";
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -14,6 +14,7 @@ if ($trombino_url != "") {
|
||||
$username = Username();
|
||||
$profil = Profil($username);
|
||||
FiltreProfil($profil);
|
||||
$now = time();
|
||||
|
||||
$machines = Machines(); // récupération de toutes les machines connues
|
||||
$machines_de_salle = Machines_de_salle($machines); // range les machines dans le tableau $machines_de_salle
|
||||
@ -31,6 +32,10 @@ Function Get_salles_bloquees($url) {
|
||||
return $salles_bloquees;
|
||||
};
|
||||
|
||||
// Timestamps de ping
|
||||
if ($mode_ping) {
|
||||
$ping_timestamps = PingTimestamps();
|
||||
}
|
||||
|
||||
// connexions dans les salles
|
||||
$salles_bloquees = Get_salles_bloquees($url_salles_bloquees);
|
||||
@ -100,8 +105,19 @@ while ($mdc = current($machines_de_salle)) {
|
||||
$style = "<b>";
|
||||
$fin_style="</b>";
|
||||
}
|
||||
|
||||
$ping_info = "";
|
||||
if ($mode_ping) {
|
||||
$ping_delta = "indisponible";
|
||||
if (array_key_exists($mac, $ping_timestamps)) {
|
||||
$ping_ts = strtotime($ping_timestamps[$mac]);
|
||||
$ping_delta = "il y a ".FormateDelta(DateDiff($ping_ts, $now));
|
||||
}
|
||||
$ping_info = "ping : ".$ping_delta;
|
||||
}
|
||||
|
||||
echo "<tr class=\"connexion\" id=\"".str_replace('.','-',$connexion_machine[$mac]["ip"])."\">";
|
||||
echo "<td><a href=\"machine.php?id=".$mac."\" target=\"blank\">".$style.$mac.$fin_style."</a></td>";
|
||||
echo "<td><a href=\"machine.php?id=".$mac."\" target=\"blank\" title=\"$ping_info\">".$style.$mac.$fin_style."</a></td>";
|
||||
echo "<td>".$style.date("H:i:s",$connexion_machine[$mac]["stamp"]).$fin_style."</td>";
|
||||
echo "<td>".$style.$connexion_machine[$mac]["ip"].$fin_style."</td>";
|
||||
echo "<td>".$div_trombi.$style.$username.$fin_style.$fin_div."</td>";
|
||||
|
@ -52,6 +52,12 @@ function Affiche_plan_salle(&$machines_de_la_salle, &$portes) {
|
||||
global $trombino_url;
|
||||
global $trombino_defaut_url;
|
||||
global $trombino_extension_fichier;
|
||||
global $mode_ping;
|
||||
|
||||
// Timestamps du ping
|
||||
if ($mode_ping) {
|
||||
$ping_timestamps = PingTimestamps();
|
||||
}
|
||||
|
||||
echo('<div id="plan">');
|
||||
|
||||
@ -74,8 +80,19 @@ function Affiche_plan_salle(&$machines_de_la_salle, &$portes) {
|
||||
if ($nb_jours >= $j20) { $class_jour = ' j20'; }
|
||||
if ($nb_jours >= $j30) { $class_jour = ' j30'; }
|
||||
|
||||
|
||||
$ping_info = "";
|
||||
if ($mode_ping) {
|
||||
$ping_delta = "indisponible";
|
||||
if (array_key_exists($machine, $ping_timestamps)) {
|
||||
$ping_ts = strtotime($ping_timestamps[$machine]);
|
||||
$ping_delta = "il y a ".FormateDelta(DateDiff($ping_ts, $date_now));
|
||||
}
|
||||
$ping_info = "ping : ".$ping_delta;
|
||||
}
|
||||
|
||||
$class_connexion='';
|
||||
$link = '<a href=../machine.php?id='.$machine.' target="blank">';
|
||||
$link = '<a href=../machine.php?id='.$machine.' target="blank" title="'.$ping_info.'">';
|
||||
$username = '';
|
||||
$ip = IP_machine($machine);
|
||||
// s'il existe une connexion sur la machine
|
||||
|
Loading…
x
Reference in New Issue
Block a user