@link http://blog.idleman.fr @licence CC by nc sa @version 1.0.0 @description Visualisation en streaming de camera(s) IP */ function ipcam_action(){ global $_,$conf; switch($_['action']){ case 'ipcam_save_camera': Action::write( function($_,&$response){ require_once('Camera.class.php'); $camera = new Camera(); if(empty($_['labelCamera'])) throw new Exception("Le nom est obligatoire"); if(empty($_['ipCamera'])) throw new Exception("L'IP est obligatoire"); $camera = !empty($_['id']) ? $camera->getById($_['id']): new Camera(); $camera->label = $_['labelCamera']; $camera->location = $_['locationCamera']; $camera->pattern = $_['patternCamera']; $camera->ip = $_['ipCamera']; $camera->login = $_['loginCamera']; $camera->password = $_['passwordCamera']; $camera->save(); $response['message'] = 'Caméra enregistrée avec succès'; }, array('ipcam'=>'c') ); break; case 'ipcam_delete_camera': Action::write( function($_,$response){ require_once('Camera.class.php'); $camera = new Camera(); $camera->delete(array('id'=>$_['id'])); }, array('ipcam'=>'d') ); break; case 'ipcam_load_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); Action::write( function($_,&$response){ $widget = new Widget(); $widget = $widget->getById($_['id']); $parameters = $widget->data(); if(empty($parameters['camera'])){ $content = 'Choisissez une camera en cliquant sur l \'icone de la barre du widget'; }else{ global $conf; require_once('Camera.class.php'); $camera = new Camera(); $camera = $camera->getById($parameters['camera']); $room = new Room(); $room = $room->getById($camera->location); $response['title'] = 'Sonde '.$camera->label.' ('.$room->getName().')'; $content = ' '; $url = str_replace(array( '{{login}}', '{{password}}', '{{ip}}' ),array( $camera->login, $camera->password, $camera->ip ),$camera->pattern); ///pour ma cam, a la fin de l'ip : http://{{login}}:{{password}}@{{ip}}/videostream.cgi $content .= '
'; $content .= '
'; $content .= ' '; } $response['content'] = $content; } ); break; case 'ipcam_edit_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); require_once(dirname(__FILE__).'/Camera.class.php'); $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $camera = new Camera(); $cameras = $camera->populate(); $content = '

Choix de la camera

'; if(count($cameras) == 0): $content = 'Aucune camera enregistrée,enregistrer une camera'; else : $content .= ''; endif; echo $content; break; case 'ipcam_save_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $data['camera'] = $_['camera']; $widget->data($data); $widget->save(); echo $content; break; } } function ipcam_plugin_setting_page(){ global $_,$myUser,$conf; if(isset($_['section']) && $_['section']=='ipcam' ){ require_once('Camera.class.php'); if(!$myUser) throw new Exception('Vous devez être connecté pour effectuer cette action'); $cameraManager = new Camera(); $cameras = $cameraManager->populate(); $roomManager = new Room(); $rooms = $roomManager->loadAll(array('state'=>'0')); $selected = new Camera(); $selected->pattern = 'http://{{login}}:{{password}}@{{ip}}/videostream.cgi'; //Si on est en mode modification if (isset($_['id'])) $selected = $cameraManager->getById($_['id']); ?>

Camera

Gestion des cameras IP

Ajouter/Modifier une camera
Adresse complète vers le streaming de votre camera, les balises entre {{}} seront remplacée par les valeurs des champs ci dessus.


Consulter les sondes existants load(array('id'=>$camera->location)); ?>
Nom IP Pièce
label; ?> ip; ?> getName(); ?>
Caméra IP'; } function ipcam_plugin_widget(&$widgets){ $widgets[] = array( 'uid' => 'dash_ipcam', 'icon' => 'fa fa-video-camera', 'label' => 'Camera', 'background' => '#C511D6', 'color' => '#fffffff', 'onLoad' => 'action.php?action=ipcam_load_widget', 'onEdit' => 'action.php?action=ipcam_edit_widget', 'onSave' => 'action.php?action=ipcam_save_widget', ); } Plugin::addJs("/js/main.js"); //Lie wireRelay_plugin_setting_page a la zone réglages Plugin::addHook("setting_bloc", "ipcam_plugin_setting_page"); //Lie wireRelay_plugin_setting_menu au menu de réglages Plugin::addHook("setting_menu", "ipcam_plugin_setting_menu"); Plugin::addHook("action_post_case", "ipcam_action"); Plugin::addHook("widgets", "ipcam_plugin_widget"); ?>