@link http://blog.idleman.fr
@licence CC by nc sa
@version 1.0.0
@type module
@description Plugin de gestion d'une porte bluetooth, accès par code + conditions fixées ans les réglages (cf tuto 22 blog.idleman.fr)
*/
if(isset($_GET['argv'])){
$argv = explode('|',$_GET['argv']);
}
if(isset($argv)){
require_once(dirname(__FILE__).'/../../constant.php');
$db = new SQLite3(dirname(__FILE__).'/../../'.DB_NAME);
$execQuery = $db->query('SELECT * FROM '.MYSQL_PREFIX.'plugin_door');
while($queryReturn = $execQuery->fetchArray() ){
$allowed_badges[] = $queryReturn['code'];
$badges[$queryReturn['code']] = $queryReturn;
}
$response = 0;
if(count($argv)>1){
list($me,$badge) = $argv;
$badge = trim(substr($badge,2,4));
$user = 0;
if(in_array($badge, $allowed_badges)){
$response = 1;
$user = $badges[$badge]['user'];
}
$execQuery = $db->exec('INSERT INTO '.MYSQL_PREFIX.'plugin_door_log(time,code,user,success)VALUES("'.time().'","'.$badge.'",'.$user.','.$response.')');
}
$db->close();
echo $response;
exit();
}
require_once(dirname(__FILE__).'/DoorAccess.class.php');
require_once(dirname(__FILE__).'/DoorLog.class.php');
function dash_domodoor_plugin_menu(&$widgets){
$widgets[] = array(
'uid' => 'dash_domodoor',
'icon' => 'fa fa-key',
'label' => 'Porte d\'entréé',
'background' => '#50597B',
'color' => '#fffffff',
'onLoad' => 'action.php?action=domodoor_get_history',
'onDelete' => 'action.php?action=dash_domodoor_plugin_delete',
);
}
function domodoor_plugin_setting_menu(){
global $_;
echo '
Porte domotique';
}
function domodoor_plugin_setting_page(){
global $myUser,$_;
if(isset($_['section']) && $_['section']=='domodoor' ){
if($myUser!=false){
$doorAccessManager = new doorAccess();
$accesses = $doorAccessManager->populate();
$current = isset($_['id'])?$doorAccessManager->getById($_['id']): $doorAccessManager;
$users = User::getAllUsers();
?>
Porte bluetooth
Gestion des accès à la porte
Utilisateur |
Code |
|
getById($access->user);
?>
getGravatarImg(30); ?> |
getFullName(); ?> |
code; ?> |
|
can('door','c')) exit('permission denied');
$doorAccessManager = new DoorAccess();
$doorAccess = new DoorAccess();
$doorAccess = $_['id']!='' ? $doorAccessManager->getById($_['id']) : $doorAccess ;
$doorAccess->user = $_['user'];
$doorAccess->code = str_pad($_['code'],4, "0");
$doorAccess->save();
header('location:setting.php?section=domodoor');
break;
case 'domodoor_get_history':
header('content-type: application/json');
$response['title'] = 'Entrees porte';
$doorAccessManager = new DoorLog();
$morning = mktime (0, 0, 0, date("n") , date("j") , date("Y"));
$entries = $doorAccessManager->loadAll(array('time'=>$morning),'time DESC',10,$operation=">");
$response['content'] ='';
$userManager = new User();
foreach($entries as $entry){
$user = new User();
if($entry->user!=0){
$user = $userManager->getById($entry->user);
}
$response['content'] .='- '.$user->getGravatarImg(50).'
'.$user->getFullName().'
'.date('à H:i \l\e d/m ',$entry->time).'
';
}
$response['content'] .= '
';
echo json_encode($response);
exit(0);
break;
case 'domodoor_delete_domodoor':
if($myUser->can('door','d')){
$doorAccessManager = new DoorAccess();
$doorAccessManager->delete(array('id'=>$_['id']));
header('location:setting.php?section=domodoor');
}
else
{
header('location:setting.php?section=domodoor&error=Vous n\'avez pas le droit de faire ça!');
}
break;
}
}
function domodoor_dashboard(){
global $_,$myUser;
if($myUser->can('door','r')){
?>