79 lines
1.3 KiB
PHP
79 lines
1.3 KiB
PHP
<?php
|
|
|
|
function presence($argList)
|
|
{
|
|
global $presence;
|
|
|
|
if(array_key_exists("nom", $argList))
|
|
{
|
|
$name = $argList["nom"];
|
|
}else
|
|
{
|
|
return "Le paramètre 'nom' est obligatoire\npresent&nom=<nom>&presence=<true/false>" . EOLH;
|
|
}
|
|
if(array_key_exists("presence", $argList))
|
|
{
|
|
$key= $argList["presence"];
|
|
}else
|
|
{
|
|
return "Le paramètre 'presence' est obligatoire\npresent&nom=<nom>&presence=<true/false>" . EOLH;
|
|
}
|
|
$key = $argList["presence"];
|
|
if (!array_key_exists($name, $presence))
|
|
{
|
|
$presence[] = $name;
|
|
$presence[$name] = false;
|
|
}
|
|
|
|
if ($key === true)
|
|
{
|
|
if ($presence[$name] === false)
|
|
{
|
|
logger(ALERT, $name . _(" est présent"), null, $device);
|
|
//echo $name . " est présent";
|
|
$presence[$name] = true;
|
|
}
|
|
}elseif ($presence[$name] === true)
|
|
{
|
|
$presence[$name] = false;
|
|
logger(ALERT, $name . _(" est présent"), null, $device);
|
|
}
|
|
}
|
|
|
|
|
|
function isPresent($name = false, $returnNames = false)
|
|
{
|
|
global $presence;
|
|
|
|
$r = false;
|
|
$list = "";
|
|
|
|
if ($name === false)
|
|
{
|
|
foreach($presence as $name => $value)
|
|
{
|
|
if ($value === true)
|
|
{
|
|
$r &= true;
|
|
$liste .= $name . EOLH;
|
|
}
|
|
}
|
|
}elseif (array_key_exists($name, $presence))
|
|
{
|
|
$r = $presence[$name];
|
|
}else
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
if ($returnNames and !empty($liste))
|
|
{
|
|
return $liste;
|
|
}else
|
|
{
|
|
return $r;
|
|
}
|
|
|
|
}
|
|
?>
|