function radioRelay_action_radioRelay() { global $_, $conf, $myUser; //Mise à jour des droits $myUser->loadRight(); switch ($_['action']) { case 'radioRelay_delete_radioRelay': if ($myUser->can('radio relais', 'd')) { $radioRelayManager = new RadioRelay(); $radioRelayManager->delete(array('id' => $_['id'])); header('location:setting.php?section=radioRelay'); } else { header('location:setting.php?section=radioRelay&error=Vous n\'avez pas le droit de faire ça!'); } break; case 'radioRelay_plugin_setting': $conf->put('plugin_radioRelay_emitter_pin', $_['emiterPin']); $conf->put('plugin_radioRelay_emitter_code', $_['emiterCode']); header('location: setting.php?section=preference&block=radioRelay'); break; case 'radioRelay_add_radioRelay': //Vérifie si on veut modifier ou ajouter un relai $right_toverify = isset($_['id']) ? 'u' : 'c'; if ($myUser->can('radio relais', $right_toverify)) { $radioRelay = new RadioRelay(); //Si modification on charge la ligne au lieu de la créer if ($right_toverify == "u") { $radioRelay = $radioRelay->load(array("id" => $_['id'])); } $radioRelay->setName($_['nameRadioRelay']); $radioRelay->setDescription($_['descriptionRadioRelay']); $radioRelay->setRadioCode($_['radioCodeRadioRelay']); $radioRelay->setRoom($_['roomRadioRelay']); $radioRelay->setPulse($_['pulseRadioRelay']); $radioRelay->save(); header('location:setting.php?section=radioRelay'); } else { header('location:setting.php?section=radioRelay&error=Vous n\'avez pas le droit de faire ça!'); } break; case 'radioRelay_change_state': global $_, $myUser; if ($myUser->can('radio relais', 'u')) { $radioRelay = new RadioRelay(); $radioRelay = $radioRelay->getById($_['engine']); Event::emit('relay_change_state', array('relay' => $radioRelay, 'state' => $_['state'])); if ($radioRelay->getPulse() == 0) { $cmd = dirname(__FILE__) . '/radioEmission ' . $conf->get('plugin_radioRelay_emitter_pin') . ' ' . $conf->get('plugin_radioRelay_emitter_code') . ' ' . $radioRelay->getRadioCode() . ' ' . $_['state']; } else { $cmd = dirname(__FILE__) . '/radioEmission ' . $conf->get('plugin_radioRelay_emitter_pin') . ' ' . $conf->get('plugin_radioRelay_emitter_code') . ' ' . $radioRelay->getRadioCode() . ' pulse ' . $radioRelay->getPulse(); } //TODO change bdd state Functions::log('Launch system command : ' . $cmd); system($cmd, $out); if (!isset($_['webservice'])) { header('location:index.php?module=room&id=' . $radioRelay->getRoom()); } else { $affirmations = array('A vos ordres!', 'Bien!', 'Oui commandant!', 'Avec plaisir!', 'J\'aime vous obéir!', 'Avec plaisir!', 'Certainement!', 'Je fais ça sans tarder!', 'Avec plaisir!', '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' => 'Je ne vous connais pas, je refuse de faire ça!'))); echo json_encode($response); } break; } }
/** * Issue a redirect to the user agent * * @param string $url * @param array $params */ public static function redirect($url, array $params = NULL) { list($url, $params) = Event::emit('response.redirect', $url, $params); Response::send(Response::REDIRECT, '', array('Location' => site_url($url, $params))); }
<?php # *** You do not need to edit this file *** # # This file is a mock application used to simulate a real-world # application that uses the event client, a class called Event located in ./client.php # # Just as our real web application would emit the 'Order.Created' # event when a customer clicks the 'Place Order' button on checkout, # the code below emits three events for three mock orders. # # To run the mock application: # $ php application.php require './client.php'; Event::emit('Order.Created', array('order_id' => 1, 'email_address' => '*****@*****.**')); Event::emit('Order.Created', array('order_id' => 2, 'email_address' => '*****@*****.**')); Event::emit('Order.Created', array('order_id' => 3, 'email_address' => '*****@*****.**')); ?>
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; } }