1
0
moha/presence.php

79 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2022-08-28 23:44:21 +02:00
function presence($argList)
2022-08-28 23:44:21 +02:00
{
global $presence;
2022-08-28 23:44:21 +02:00
if(array_key_exists("nom", $argList))
2022-08-28 23:44:21 +02:00
{
$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;
}
2022-08-28 23:44:21 +02:00
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);
2022-08-28 23:44:21 +02:00
}
}
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;
}
}
2022-08-28 23:44:21 +02:00
?>