Пример #1
0
        exit;
    } else {
        // delete sensor and deactivate policy
        require_once 'classes/Policy.inc';
        foreach ($list_policy_sensor_reference as $policy_sensor_reference) {
            Policy::activate($conn, $policy_sensor_reference->get_policy_id(), '0');
        }
    }
}
//
if ($sensor_interface_list = Sensor_interfaces::get_list($conn, $name)) {
    foreach ($sensor_interface_list as $s_int) {
        Sensor_interfaces::delete_interfaces($conn, $name, $s_int->get_interface());
    }
}
Sensor::delete($conn, $name);
$db->close($conn);
Util::clean_json_cache_files("sensors");
?>

    <p> <?php 
echo gettext("Sensor deleted");
?>
 </p>
    <script>document.location.href="sensor.php"</script>
	
	<?php 
// update indicators on top frame*/
$OssimWebIndicator->update_display();
?>
Пример #2
0
function propise_action()
{
    global $_, $conf;
    switch ($_['action']) {
        case 'propise_save_sensor':
            Action::write(function ($_, &$response) {
                require_once 'Sensor.class.php';
                $sensor = new Sensor();
                if (empty($_['labelSensor'])) {
                    throw new Exception("Le nom est obligatoire");
                }
                if (empty($_['uidSensor'])) {
                    throw new Exception("L'UID est obligatoire");
                }
                $sensor = !empty($_['id']) ? $sensor->getById($_['id']) : new Sensor();
                $sensor->label = $_['labelSensor'];
                $sensor->location = $_['locationSensor'];
                $sensor->uid = $_['uidSensor'];
                $sensor->save();
                //Reference device for other plugins
                $device = new Device();
                $device->label = $sensor->label;
                $device->plugin = 'propise';
                $device->type = Device::CAPTOR;
                $device->location = $sensor->location;
                $device->icon = 'fa-heartbeat';
                $device->setValue('humidity', 0);
                $device->setValue('temperature', 0);
                $device->setValue('light', 0);
                $device->setValue('mouvment', 0);
                $device->setValue('sound', 0);
                $device->state = 1;
                $device->uid = $sensor->id;
                $device->save();
                $response['message'] = 'Sonde enregistrée avec succès';
            }, array('propise' => 'c'));
            break;
        case 'propise_delete_sensor':
            Action::write(function ($_, $response) {
                require_once 'Sensor.class.php';
                $sensor = new Sensor();
                $sensor->delete(array('id' => $_['id']));
            }, array('propise' => 'd'));
            break;
        case 'propise_add_data':
            /*for($i=0;$i<60;$i++){
            		$_ = array(
            		'uid'=>'sensor-2',
            		'humidity'=>rand(0,100),
            		'temperature'=>rand(0,100),
            		'light'=>rand(0,100),
            		'mouvment'=>rand(0,1),
            		'sound'=>rand(0,1)
            		);*/
            require_once 'Sensor.class.php';
            require_once 'Data.class.php';
            $sensor = new Sensor();
            $data = new Data();
            $sensor = $sensor->load(array('uid' => $_['uid']));
            if ($sensor == null || $sensor->id == 0) {
                return;
            }
            $data->time = time();
            //$data->time = strtotime(date('Ymd H:').$i.':00');
            $data->humidity = $_['humidity'];
            $data->temperature = $_['temperature'];
            $data->light = $_['light'];
            $data->mouvment = $_['mouvment'];
            $data->sound = $_['sound'];
            $data->sensor = $sensor->id;
            $data->save();
            //}
            break;
        case 'propise_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['sensor'])) {
                    $content = 'Choisissez une localisation en cliquant sur l \'icone <i class="fa fa-wrench"></i> de la barre du widget';
                } else {
                    global $conf;
                    require_once 'Data.class.php';
                    require_once 'Sensor.class.php';
                    $sensor = new Sensor();
                    $data = new Data();
                    $sensor = $sensor->getById($parameters['sensor']);
                    $datas = $data->loadAll(array('sensor' => $sensor->id), 'time DESC', 1);
                    $response['title'] = 'Sonde ' . $sensor->label . ' (' . $sensor->uid . ')';
                    $content = '
						<!-- CSS -->
						<style>
							.propise_view{
								background:#36B3E1;
								color:#ffffff;
								margin:0px;
								padding:10px;
								width:100%;
								list-style-type:none;
								transition:all 0.2s ease-in-out;
								box-sizing: border-box;
							}
							.propise_menu{
								margin:0;
							}
							.propise_menu li{
								cursor: pointer;
								display: inline-block;
								font-size: 20px;
								height: 25px;
								margin-top: 3px;
								padding: 5px;
								text-align: center;
								transition: all 0.2s ease-in-out 0s;
								width: 30px;
								border-top:4px solid #cecece;
							}
							
							color: #cecece;
    
							
							.propise_menu li:hover{
								background:#222222;
								color:#ffffff;
							}
							
							.propise_view li{
								display:none;
								font-family: "Open Sans Light",sans-serif;
								text-align:center;
								padding:15px 0;
								font-weight:300;
								font-size:60px;
							}
							
							.propise_view li.propise_temperature{
								display:block;
							}
							
							.propise_menu li.propise_temperature{
								border-color:#36B3E1;
							}
							.propise_menu li.propise_humidity{
								border-color:#50597B;
							}
							.propise_menu li.propise_light{
								border-color:#EF4D66;
							}
							.propise_menu li.propise_mouvment{
								border-color:#FFBF4C;
							}
							.propise_menu li.propise_sound{
								border-color:#84C400;
							}
							.propise_menu li.propise_stats{
								border-color:#C1004F;
							}
						</style>
						
						<!-- HTML -->
						';
                    $content .= '<div class="propise_widget"><ul class="propise_view">';
                    $content .= '<li class="propise_temperature"><i class="fa fa-fire"></i> ' . round($datas[0]->temperature, 1) . '°</li>';
                    $content .= '<li class="propise_humidity"><i class="fa fa-tint"></i> ' . round($datas[0]->humidity, 1) . '%</li>';
                    $content .= '<li class="propise_light"><i class="fa fa-sun-o"></i> ' . round($datas[0]->light, 1) . '%</li>';
                    $content .= '<li class="propise_mouvment"><i class="fa fa-eye' . ($datas[0]->mouvment == 1 ? '' : '-slash') . '"></i></li>';
                    $content .= '<li class="propise_sound"><i class="fa fa-bell' . ($datas[0]->sound == 1 ? '' : '-slash') . '"></i></li>';
                    $content .= '</ul><ul class="propise_menu">';
                    $content .= '<li class="propise_temperature" onclick="propise_menu(this)" data-view="temperature"><i class="fa fa-fire"></i></li>';
                    $content .= '<li class="propise_humidity" onclick="propise_menu(this)" data-view="humidity"><i class="fa fa-tint"></i></li>';
                    $content .= '<li class="propise_light" onclick="propise_menu(this)" data-view="light"><i class="fa fa-sun-o"></i></li>';
                    $content .= '<li class="propise_mouvment" onclick="propise_menu(this)" data-view="mouvment"><i class="fa fa-eye"></i></li>';
                    $content .= '<li class="propise_sound" onclick="propise_menu(this)" data-view="sound"><i class="fa fa-bell"></i></li>';
                    $content .= '<li class="propise_stats" onclick="window.open(\'index.php?module=propise\')"><i class="fa fa-line-chart"></i></li>';
                    $content .= '</ul>';
                    $content .= '</div>';
                    $content .= '
						<!-- JS -->
						<script type="text/javascript">
							function propise_menu(element){
								var container = $(element).closest(".propise_widget");
								$(".propise_view li",container).hide();
								$(".propise_view").css("background-color",$(element).css("border-top-color"));
								$(".propise_view li.propise_"+$(element).data("view"),container).fadeIn();
							};
							
						</script>
						';
                }
                $response['content'] = $content;
            });
            break;
        case 'propise_edit_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            require_once dirname(__FILE__) . '/Sensor.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $sensor = new Sensor();
            $sensors = $sensor->populate();
            $content = '<h3>Choix de la sonde</h3>';
            if (count($sensors) == 0) {
                $content = 'Aucune sonde enregistrée,<a href="setting.php?section=propise">enregistrer une sonde<a>';
            } else {
                $content .= '<select id="sensor">';
                foreach ($sensors as $sensor) {
                    $content .= '<option ' . ($sensor->id == $data['sensor'] ? 'selected="selected"' : '') . ' value="' . $sensor->id . '">' . $sensor->label . ' (' . $sensor->uid . ')</option>';
                }
                $content .= '</select>';
            }
            echo $content;
            break;
        case 'propise_save_widget':
            require_once dirname(__FILE__) . '/../dashboard/Widget.class.php';
            $widget = new Widget();
            $widget = $widget->getById($_['id']);
            $data = $widget->data();
            $data['sensor'] = $_['sensor'];
            $widget->data($data);
            $widget->save();
            echo $content;
            break;
    }
}
function sensor_action_sensor()
{
    global $_, $conf, $myUser;
    //Mise à jour des droits
    $myUser->loadRight();
    switch ($_['action']) {
        case 'sensor_delete_sensor':
            if ($myUser->can('sensor', 'd')) {
                $sensorManager = new Sensor();
                $sensorManager->delete(array('id' => $_['id']));
                header('location:setting.php?section=sensor');
            } else {
                header('location:setting.php?section=sensor&error=Vous n\'avez pas le droit de faire ça!');
            }
            break;
        case 'sensor_plugin_setting':
            $conf->put('plugin_sensor_receptor_pin', $_['receptorPin']);
            header('location: setting.php?section=preference&block=sensor');
            break;
        case 'sensor_add_sensor':
            //Vérifie si on veut modifier ou ajouter un capteur
            $right_toverify = isset($_['id']) ? 'u' : 'c';
            if ($myUser->can('sensor', $right_toverify)) {
                $sensor = new Sensor();
                //Si modification on charge la ligne au lieu de la créer
                if ($right_toverify == "u") {
                    $sensor = $sensor->load(array("id" => $_['id']));
                }
                $sensor->setName($_['nameSensor']);
                $sensor->setDescription($_['descriptionSensor']);
                $sensor->setRadioCode($_['radioCodeSensor']);
                $sensor->setRoom($_['roomSensor']);
                $sensor->setType($_['typeSensor']);
                $sensor->save();
                header('location:setting.php?section=sensor');
            } else {
                header('location:setting.php?section=sensor&error=Vous n\'avez pas le droit de faire ça!');
            }
            break;
        case 'sensor_delete_type':
            if ($myUser->can('sensortypes', 'd')) {
                $sensorTypeManager = new SensorType();
                $sensorTypeManager->delete(array('id' => $_['id']));
                header('location:setting.php?section=sensortypes');
            } else {
                header('location:setting.php?section=sensortypes&error=Vous n\'avez pas le droit de faire ça!');
            }
            break;
        case 'sensor_add_type':
            //Vérifie si on veut modifier ou ajouter un capteur
            $right_toverify = isset($_['id']) ? 'u' : 'c';
            if ($myUser->can('sensortypes', $right_toverify)) {
                $sensorType = new SensorType();
                //Si modification on charge la ligne au lieu de la créer
                if ($right_toverify == "u") {
                    $sensorType = $sensorType->load(array("id" => $_['id']));
                }
                $sensorType->setName($_['nameSensorType']);
                $sensorType->save();
                header('location:setting.php?section=sensortypes');
            } else {
                header('location:setting.php?section=sensortypes&error=Vous n\'avez pas le droit de faire ça!');
            }
            break;
        case 'UPDATE_ENGINE_STATE':
            $sensor = new Sensor();
            $sensor = $sensor->load(array("radioCode" => $_SERVER['argv'][2]));
            $sensor->setValue($_SERVER['argv'][3]);
            $sensor->setPositive($_SERVER['argv'][4]);
            $sensor->setLastrcv(time());
            $sensor->save();
            break;
        case 'sensor_change_state':
            global $_, $myUser;
            if ($myUser->can('sensor', 'u')) {
                $sensor = new Sensor();
                $sensor = $sensor->getById($_['engine']);
                Event::emit('sensor_change_state', array('sensor' => $sensor, 'state' => $_['state']));
                if (!isset($_['webservice'])) {
                    header('location:index.php?module=room&id=' . $sensor->getRoom());
                } else {
                    $affirmations = array('A vos ordres!', 'Bien!', 'Oui commandant!', 'Avec plaisir!', 'J\'aime vous obéir!', 'J\'y cours !', 'Certainement!', 'Je fais ça sans tarder!', 'oui maîtresse !', 'Oui chef!');
                    $affirmation = $affirmations[rand(0, count($affirmations) - 1)];
                    $response = array('responses' => array(array('type' => 'talk', 'sentence' => $affirmation)));
                    $json = json_encode($response);
                    echo $json == '[]' ? '{}' : $json;
                }
            } else {
                $response = array('responses' => array(array('type' => 'talk', 'sentence' => 'mais t\'es qui toi ?, je refuse de faire ça!')));
                echo json_encode($response);
            }
            break;
    }
}