$return = utils::o2a($widget); $return['logicalId'] = $widget->getLogicalId(); $return['status'] = market::getInfo($widget->getLogicalId()); ajax::success($return); } if (init('action') == 'save') { $widget_ajax = json_decode(init('widget'), true); if (file_exists($widget['path'])) { $widget_db = widget::byPath($widget['path']); if (!is_object($widget_db)) { $widget_db = new widget(); } } else { $widget_db = new widget(); } utils::a2o($widget_db, $widget_ajax); $widget_db->save(); ajax::success(utils::o2a($widget_db)); } if (init('action') == 'add') { $widget = new widget(); $widget->setName(init('name')); $widget->save(); ajax::success(utils::o2a($widget)); } if (init('action') == 'remove') { $widget = widget::byPath(init('path')); if (!is_object($widget)) { throw new Exception('Widget non trouvé : ' . init('path')); } $widget->remove();
$link_id .= cmd::cmdToHumanReadable('#' . $cmd->getId() . '# && '); } } $result['link_id'] = trim(trim($link_id), '&&'); } ajax::success(jeedom::toHumanReadable($result)); } if (init('action') == 'save') { $interact_json = jeedom::fromHumanReadable(json_decode(init('interact'), true)); if (isset($interact_json['id'])) { $interact = interactDef::byId($interact_json['id']); } if (!isset($interact) || !is_object($interact)) { $interact = new interactDef(); } utils::a2o($interact, $interact_json); $interact->save(); ajax::success(utils::o2a($interact)); } if (init('action') == 'regenerateInteract') { interactDef::regenerateInteract(); ajax::success(); } if (init('action') == 'remove') { if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } $interact = interactDef::byId(init('id')); if (!is_object($interact)) { throw new Exception(__('Interaction inconnu verifié l\'id', __FILE__)); }
$return['plugin'] = $eqLogic->getEqType_Name(); if ($eqLogic->getObject_id() > 0) { $return['object_name'] = $eqLogic->getObject()->getName(); } ajax::success($return); } if (init('action') == 'save') { if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } $cmd_ajax = jeedom::fromHumanReadable(json_decode(init('cmd'), true)); $cmd = cmd::byId($cmd_ajax['id']); if (!is_object($cmd)) { $cmd = new cmd(); } utils::a2o($cmd, $cmd_ajax); $cmd->save(); ajax::success(); } if (init('action') == 'changeHistoryPoint') { if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } $history = history::byCmdIdDatetime(init('cmd_id'), init('datetime')); if (!is_object($history)) { throw new Exception(__('Aucun point ne correspond pour l\'historique : ', __FILE__) . init('cmd_id') . ' - ' . init('datetime')); } $history->setValue(init('value', null)); $history->save(null, true); ajax::success(); }
public function applyModuleConfiguration() { if ($this->getConfiguration('device') == '') { return true; } $device = self::devicesParameters($this->getConfiguration('device')); if (!is_array($device) || !isset($device['commands'])) { return true; } if (isset($device['configuration'])) { foreach ($device['configuration'] as $key => $value) { $this->setConfiguration($key, $value); } } $this->setConfiguration('applyDevice', $this->getConfiguration('device')); $cmd_order = 0; $link_cmds = array(); foreach ($device['commands'] as $command) { if (!isset($command['configuration']['instanceId'])) { $command['configuration']['instanceId'] = 0; } $cmd = null; foreach ($this->getCmd() as $liste_cmd) { if ($liste_cmd->getConfiguration('instanceId', 0) == $command['configuration']['instanceId'] && $liste_cmd->getConfiguration('class') == $command['configuration']['class'] && $liste_cmd->getConfiguration('value') == $command['configuration']['value']) { $cmd = $liste_cmd; break; } } try { if ($cmd == null || !is_object($cmd)) { $cmd = new zwaveCmd(); $cmd->setOrder($cmd_order); $cmd->setEqLogic_id($this->getId()); } else { $command['name'] = $cmd->getName(); } utils::a2o($cmd, $command); if (isset($command['value'])) { $cmd->setValue(null); } $cmd->save(); if (isset($command['value'])) { $link_cmds[$cmd->getId()] = $command['value']; } $cmd_order++; } catch (Exception $exc) { error_log($exc->getMessage()); } } if (count($link_cmds) > 0) { foreach ($this->getCmd() as $eqLogic_cmd) { foreach ($link_cmds as $cmd_id => $link_cmd) { if ($link_cmd == $eqLogic_cmd->getName()) { $cmd = cmd::byId($cmd_id); if (is_object($cmd)) { $cmd->setValue($eqLogic_cmd->getId()); $cmd->save(); } } } } } $this->save(); }
if (count(user::searchByRight('admin')) == 1 && $user->getRights('admin') == 1) { throw new Exception(__('Vous ne pouvez supprimer le dernière administrateur', __FILE__)); } $user->remove(); ajax::success(); } if (init('action') == 'saveProfils') { $user_json = json_decode(init('profils'), true); if (isset($user_json['id']) && $user_json['id'] != $_SESSION['user']->getId()) { throw new Exception('401 unautorized'); } $login = $_SESSION['user']->getLogin(); $rights = $_SESSION['user']->getRights(); $password = $_SESSION['user']->getPassword(); @session_start(); utils::a2o($_SESSION['user'], $user_json); foreach ($rights as $right => $value) { $_SESSION['user']->setRights($right, $value); } $_SESSION['user']->setLogin($login); if ($password != $_SESSION['user']->getPassword()) { $_SESSION['user']->setPassword(sha1($_SESSION['user']->getPassword())); } $_SESSION['user']->save(); @session_write_close(); ajax::success(); } if (init('action') == 'get') { ajax::success(utils::o2a($_SESSION['user'])); } if (init('action') == 'testLdapConnection') {
} } $scenario_ajax = json_decode(init('scenario'), true); if (isset($scenario_ajax['id'])) { $scenario_db = scenario::byId($scenario_ajax['id']); } if (!isset($scenario_db) || !is_object($scenario_db)) { $scenario_db = new scenario(); } else { if (!$scenario_db->hasRight('w')) { throw new Exception(__('Vous n\'etês pas autorisé à faire cette action', __FILE__)); } } $scenario_db->setTrigger(array()); $scenario_db->setSchedule(array()); utils::a2o($scenario_db, $scenario_ajax); $scenario_db->setConfiguration('timeDependency', $time_dependance); $scenario_db->save(); $scenario_element_list = array(); if (isset($scenario_ajax['elements'])) { foreach ($scenario_ajax['elements'] as $element_ajax) { $scenario_element_list[] = scenarioElement::saveAjaxElement($element_ajax); } $scenario_db->setScenarioElement($scenario_element_list); } $scenario_db->save(); ajax::success(utils::o2a($scenario_db)); } if (init('action') == 'actionToHtml') { ajax::success(scenarioExpression::getExpressionOptions(init('expression'), init('option'))); }
public function applyModuleConfiguration($_light = false) { $this->setConfiguration('applyDevice', $this->getConfiguration('device')); if ($this->getConfiguration('device') == '') { $this->save(); return true; } $device = self::devicesParameters($this->getConfiguration('device')); if (!is_array($device) || !isset($device['commands'])) { return true; } if (isset($device['configuration'])) { foreach ($device['configuration'] as $key => $value) { try { $this->setConfiguration($key, $value); } catch (Exception $e) { } } } $cmd_order = 0; $link_cmds = array(); $razberry_id = zwave::getZwaveInfo('controller::data::nodeId::value', $this->getConfiguration('serverID', 1)); nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Mise en place des groupes par défaut', __FILE__))); if (isset($device['groups']) && isset($device['groups']['associate'])) { foreach ($this->getAssociation() as $group_id => $associate) { foreach ($associate['nodes']['value'] as $node) { if ($node['id'] == $razberry_id && !isset($device['groups']['associate'][$group_id])) { $this->changeAssociation('remove', $group_id, $razberry_id); } } } foreach ($device['groups']['associate'] as $group) { try { $this->changeAssociation('add', $group, $razberry_id); } catch (Exception $e) { } } } nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Création des commandes', __FILE__))); if (self::$_listZwaveServer == null) { self::listServerZway(); } if (isset($device['commands_openzwave']) && self::$_listZwaveServer[$this->getConfiguration('serverID', 1)]['isOpenZwave'] == 1) { $commands = $device['commands_openzwave']; } else { $commands = $device['commands']; } foreach ($commands as &$command) { if (!isset($command['configuration']['instanceId'])) { $command['configuration']['instanceId'] = 0; } if (!isset($command['configuration']['class'])) { $command['configuration']['class'] = ''; } $cmd = null; foreach ($this->getCmd() as $liste_cmd) { if ($liste_cmd->getConfiguration('instanceId', 0) == $command['configuration']['instanceId'] && $liste_cmd->getConfiguration('class') == $command['configuration']['class'] && $liste_cmd->getConfiguration('value') == $command['configuration']['value']) { $cmd = $liste_cmd; break; } } try { if ($cmd == null || !is_object($cmd)) { $cmd = new zwaveCmd(); $cmd->setOrder($cmd_order); $cmd->setEqLogic_id($this->getId()); } else { $command['name'] = $cmd->getName(); if (isset($command['display'])) { unset($command['display']); } } utils::a2o($cmd, $command); if (isset($command['value'])) { $cmd->setValue(null); } $cmd->save(); if (isset($command['value'])) { $link_cmds[$cmd->getId()] = $command['value']; } $cmd_order++; } catch (Exception $exc) { } } if (count($link_cmds) > 0) { foreach ($this->getCmd() as $eqLogic_cmd) { foreach ($link_cmds as $cmd_id => $link_cmd) { if ($link_cmd == $eqLogic_cmd->getName()) { $cmd = cmd::byId($cmd_id); if (is_object($cmd)) { $cmd->setValue($eqLogic_cmd->getId()); $cmd->save(); } } } } } if (isset($device['wakeup']) && is_numeric($device['wakeup']) && $device['wakeup'] > 1) { try { $this->setWakeUp($device['wakeup']); } catch (Exception $ex) { } } if (!$_light) { try { nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Récupération de la configuration d\'origine du module', __FILE__))); $configuration = $this->getDeviceConfiguration(true); $optimiseConfigFound = false; foreach ($configuration as $id => &$parameter) { if (isset($device['parameters'][$id]['set'])) { $optimiseConfigFound = true; $configuration[$id]['value'] = $device['parameters'][$id]['set']; } } if ($optimiseConfigFound) { nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Envoi de la configuration optimisée Jeedom', __FILE__))); $this->setDeviceConfiguration($configuration); } } catch (Exception $ex) { } if (isset($device['configure']) && is_array($device['configure'])) { try { nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Execution des commandes post-configuration', __FILE__))); $this->applyDeviceConfigurationCommand(); } catch (Exception $ex) { } } } $this->save(); nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => '')); }
foreach ($eqLogics_ajax as $eqLogic_ajax) { foreach ($eqLogic_ajax['configuration'] as $key => $value) { if ($key == 'portType') { $eqLogic_ajaxType = $value; } } if ($eqLogic_ajaxType != 0) { $eqLogic_db = new jeenode(); utils::a2o($eqLogic_db, $eqLogic_ajax); $eqLogic_db->save(); $enable_eqLogic[$eqLogic_db->getId()] = true; $enable_cmd = array(); foreach ($eqLogic_ajax['cmd'] as $cmd_ajax) { $cmd_db = new jeenodeCmd(); $cmd_db->setEqLogic_id($eqLogic_db->getId()); utils::a2o($cmd_db, $cmd_ajax); $cmd_db->save(); $enable_cmd[$cmd_db->getId()] = true; } //suppression des entrées non modifiées. foreach ($eqLogic_db->getCmd() as $cmd_db) { if (!isset($enable_cmd[$cmd_db->getId()])) { $cmd_db->remove(); } } } else { $eqLogic_db = jeenode::byId($eqLogic_ajax['id']); $eqLogic_db->remove(); } } foreach ($eqReal_db->getEqLogic() as $eqLogic_db) {
} if (init('action') == 'all') { ajax::success(utils::o2a(object::buildTree())); } if (init('action') == 'save') { if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } $object_json = json_decode(init('object'), true); if (isset($object_json['id'])) { $object = object::byId($object_json['id']); } if (!isset($object) || !is_object($object)) { $object = new object(); } utils::a2o($object, $object_json); $object->save(); ajax::success(utils::o2a($object)); } if (init('action') == 'uploadImage') { $object = object::byId(init('id')); if (!is_object($object)) { throw new Exception(__('Objet inconnu verifié l\'id', __FILE__)); } if (!isset($_FILES['file'])) { throw new Exception(__('Aucun fichier trouvé. Vérifié parametre PHP (post size limit)', __FILE__)); } $extension = strtolower(strrchr($_FILES['file']['name'], '.')); if (!in_array($extension, array('.jpg', '.png'))) { throw new Exception('Extension du fichier non valide (autorisé .jpg .png) : ' . $extension); }
ajax::success($jeeNetwork->backup()); } if (init('action') == 'save') { if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } $update = true; $jeeNetwork_json = json_decode(init('jeeNetwork'), true); if (isset($jeeNetwork_json['id'])) { $jeeNetwork = jeeNetwork::byId($jeeNetwork_json['id']); } if (!isset($jeeNetwork) || !is_object($jeeNetwork)) { $update = false; $jeeNetwork = new jeeNetwork(); } utils::a2o($jeeNetwork, $jeeNetwork_json); $jeeNetwork->save(); if ($update) { $jeeNetwork->reload(); } ajax::success(utils::o2a($jeeNetwork)); } if (init('action') == 'changeMode') { if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } ajax::success(jeeNetwork::changeMode(init('mode'))); } if (init('action') == 'restartNgrok') { if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__));
$dbList = $typeCmd::byEqLogicId($eqLogic->getId()); $eqLogic->save(); $enableList = array(); if (isset($params['cmd'])) { $cmd_order = 0; foreach ($params['cmd'] as $cmd_info) { $cmd = null; if (isset($cmd_info['id'])) { $cmd = $typeCmd::byId($cmd_info['id']); } if (!is_object($cmd)) { $cmd = new $typeCmd(); } $cmd->setEqLogic_id($eqLogic->getId()); $cmd->setOrder($cmd_order); utils::a2o($cmd, jeedom::fromHumanReadable($cmd_info)); $cmd->save(); $cmd_order++; $enableList[$cmd->getId()] = true; } //suppression des entrées inexistante. foreach ($dbList as $dbObject) { if (!isset($enableList[$dbObject->getId()]) && !$dbObject->dontRemoveCmd()) { $dbObject->remove(); } } } $jsonrpc->makeSuccess(utils::o2a($eqLogic)); } if ($jsonrpc->getMethod() == 'eqLogic::byTypeAndId') { $return = array();
$dbList = $typeCmd::byEqLogicId($eqLogic->getId()); $eqLogic->save(); $enableList = array(); if (isset($eqLogicSave['cmd'])) { $cmd_order = 0; foreach ($eqLogicSave['cmd'] as $cmd_info) { $cmd = null; if (isset($cmd_info['id'])) { $cmd = $typeCmd::byId($cmd_info['id']); } if (!is_object($cmd)) { $cmd = new $typeCmd(); } $cmd->setEqLogic_id($eqLogic->getId()); $cmd->setOrder($cmd_order); utils::a2o($cmd, $cmd_info); $cmd->save(); $cmd_order++; $enableList[$cmd->getId()] = true; } //suppression des entrées non innexistante. foreach ($dbList as $dbObject) { if (!isset($enableList[$dbObject->getId()]) && !$dbObject->dontRemoveCmd()) { $dbObject->remove(); } } } if (method_exists($eqLogic, 'postAjax')) { $eqLogic->postAjax(); } }
* GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jeedom. If not, see <http://www.gnu.org/licenses/>. */ try { require_once dirname(__FILE__) . '/../../core/php/core.inc.php'; include_file('core', 'authentification', 'php'); if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } if (init('action') == 'byUserId') { ajax::success(utils::o2a(rights::byUserId(init('user_id')))); } if (init('action') == 'save') { $rights_json = json_decode(init('rights'), true); foreach ($rights_json as $right_json) { $rights = rights::byId($right_json['id']); if (!is_object($rights)) { $rights = new rights(); } utils::a2o($rights, $right_json); $rights->save(); } ajax::success(); } throw new Exception(__('Aucune methode correspondante à : ', __FILE__) . init('action')); /* * *********Catch exeption*************** */ } catch (Exception $e) { ajax::error(displayExeption($e), $e->getCode()); }
$view_ajax = json_decode(init('view'), true); utils::a2o($view, $view_ajax); $view->save(); if (count($view_ajax['zones']) > 0) { foreach ($view_ajax['zones'] as $viewZone_info) { $viewZone = new viewZone(); $viewZone->setView_id($view->getId()); utils::a2o($viewZone, $viewZone_info); $viewZone->save(); if (isset($viewZone_info['viewData'])) { $order = 0; foreach ($viewZone_info['viewData'] as $viewData_info) { $viewData = new viewData(); $viewData->setviewZone_id($viewZone->getId()); $viewData->setOrder($order); utils::a2o($viewData, $viewData_info); $viewData->save(); $order++; } } } } ajax::success(); } if (init('action') == 'getEqLogicviewZone') { $viewZone = viewZone::byId(init('viewZone_id')); if (!is_object($viewZone)) { throw new Exception(__('Vue non trouvé. Vérifier l\'id', __FILE__)); } $return = utils::o2a($viewZone); $return['eqLogic'] = array();
public function applyModuleConfiguration() { if ($this->getConfiguration('device') == '') { return true; } $this->setConfiguration('applyDevice', $this->getConfiguration('device')); $this->save(); $device_type = explode('::', $this->getConfiguration('device')); $packettype = $device_type[0]; $subtype = $device_type[1]; $device = self::devicesParameters($packettype); if (!is_array($device) || !isset($device['subtype'][$subtype])) { return true; } else { $device = $device['subtype'][$subtype]; } if (isset($device['configuration'])) { foreach ($device['configuration'] as $key => $value) { $this->setConfiguration($key, $value); } } $cmd_order = 0; foreach ($device['commands'] as $command) { $cmd = null; foreach ($this->getCmd() as $liste_cmd) { if ($liste_cmd->getConfiguration('logicalId', '') == $command['configuration']['logicalId']) { $cmd = $liste_cmd; break; } } try { if ($cmd == null || !is_object($cmd)) { $cmd = new rfxcomCmd(); $cmd->setOrder($cmd_order); $cmd->setEqLogic_id($this->getId()); } else { $command['name'] = $cmd->getName(); } utils::a2o($cmd, $command); $cmd->save(); $cmd_order++; } catch (Exception $exc) { } } $this->save(); }
if (init('action') == 'getPlanHeader') { $planHeader = planHeader::byId(init('id')); if (!is_object($planHeader)) { throw new Exception(__('Plan header inconnu verifié l\'id : ', __FILE__) . init('id')); } $return = utils::o2a($planHeader); $return['image'] = $planHeader->displayImage(); ajax::success($return); } if (init('action') == 'savePlanHeader') { $planHeader_ajax = json_decode(init('planHeader'), true); $planHeader = planHeader::byId($planHeader_ajax['id']); if (!is_object($planHeader)) { $planHeader = new planHeader(); } utils::a2o($planHeader, $planHeader_ajax); $planHeader->save(); ajax::success(utils::o2a($planHeader)); } if (init('action') == 'copyPlanHeader') { $planHeader = planHeader::byId(init('id')); if (!is_object($planHeader)) { throw new Exception(__('Plan header inconnu verifié l\'id : ', __FILE__) . init('id')); } ajax::success(utils::o2a($planHeader->copy(init('name')))); } if (init('action') == 'uploadImage') { $planHeader = planHeader::byId(init('id')); if (!is_object($planHeader)) { throw new Exception(__('Objet inconnu verifié l\'id', __FILE__)); }
public static function saveAjaxElement($element_ajax) { if (isset($element_ajax['id']) && $element_ajax['id'] != '') { $element_db = scenarioElement::byId($element_ajax['id']); } else { $element_db = new scenarioElement(); } if (!isset($element_db) || !is_object($element_db)) { throw new Exception(__('Elément inconnu - Vérifiez l\'id : ', __FILE__) . $element_ajax['id']); } utils::a2o($element_db, $element_ajax); $element_db->save(); $subElement_order = 0; $subElement_list = $element_db->getSubElement(); $enable_subElement = array(); foreach ($element_ajax['subElements'] as $subElement_ajax) { if (isset($subElement_ajax['id']) && $subElement_ajax['id'] != '') { $subElement_db = scenarioSubElement::byId($subElement_ajax['id']); } else { $subElement_db = new scenarioSubElement(); } if (!isset($subElement_db) || !is_object($subElement_db)) { throw new Exception(__('Elément inconnu vérifier l\'id : ', __FILE__) . $subElement_ajax['id']); } utils::a2o($subElement_db, $subElement_ajax); $subElement_db->setScenarioElement_id($element_db->getId()); $subElement_db->setOrder($subElement_order); $subElement_db->save(); $subElement_order++; $enable_subElement[$subElement_db->getId()] = true; $expression_list = $subElement_db->getExpression(); $expression_order = 0; $enable_expression = array(); foreach ($subElement_ajax['expressions'] as &$expression_ajax) { if (isset($expression_ajax['scenarioSubElement_id']) && $expression_ajax['scenarioSubElement_id'] != $subElement_db->getId() && isset($expression_ajax['id']) && $expression_ajax['id'] != '') { $expression_ajax['id'] = ''; } if (isset($expression_ajax['id']) && $expression_ajax['id'] != '') { $expression_db = scenarioExpression::byId($expression_ajax['id']); } else { $expression_db = new scenarioExpression(); } if (!isset($expression_db) || !is_object($expression_db)) { throw new Exception(__('Expression inconnue vérifié l\'id : ', __FILE__) . $expression_ajax['id']); } $expression_db->emptyOptions(); utils::a2o($expression_db, $expression_ajax); $expression_db->setScenarioSubElement_id($subElement_db->getId()); if ($expression_db->getType() == 'element') { $expression_db->setExpression(self::saveAjaxElement($expression_ajax['element'])); } $expression_db->setOrder($expression_order); $expression_db->save(); $expression_order++; $enable_expression[$expression_db->getId()] = true; } foreach ($expression_list as $expresssion) { if (!isset($enable_expression[$expresssion->getId()])) { $expresssion->remove(); } } } foreach ($subElement_list as $subElement) { if (!isset($enable_subElement[$subElement->getId()])) { $subElement->remove(); } } return $element_db->getId(); }
throw new Exception(__('Impossible de trouver l\'objet associé : ', __FILE__) . init('id')); } $market->remove(); ajax::success(); } if (init('action') == 'save') { $market_ajax = json_decode(init('market'), true); try { $market = market::byId($market_ajax['id']); } catch (Exception $e) { $market = new market(); } if (isset($market_ajax['rating'])) { unset($market_ajax['rating']); } utils::a2o($market, $market_ajax); $market->save(); ajax::success(); } if (init('action') == 'getInfo') { ajax::success(market::getInfo(init('logicalId'))); } if (init('action') == 'byLogicalId') { if (init('noExecption', 0) == 1) { try { ajax::success(utils::o2a(market::byLogicalIdAndType(init('logicalId'), init('type')))); } catch (Exception $e) { ajax::success(); } } else { ajax::success(utils::o2a(market::byLogicalIdAndType(init('logicalId'), init('type'))));
public function loadCmdFromConf($_update = false) { if (!is_file(dirname(__FILE__) . '/../config/devices/' . $this->getConfFilePath())) { return; } $content = file_get_contents(dirname(__FILE__) . '/../config/devices/' . $this->getConfFilePath()); if (!is_json($content)) { return; } $device = json_decode($content, true); if (!is_array($device) || !isset($device['commands'])) { return true; } $cmd_order = 0; $link_cmds = array(); if (isset($device['name']) && !$_update) { $this->setName('[' . $this->getLogicalId() . ']' . $device['name']); } if (isset($device['configuration'])) { foreach ($device['configuration'] as $key => $value) { try { $this->setConfiguration($key, $value); } catch (Exception $e) { } } } nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Création des commandes à partir d\'une configuration', __FILE__))); $commands = $device['commands']; foreach ($commands as &$command) { if (!isset($command['configuration']['instanceId'])) { $command['configuration']['instanceId'] = 0; } if (!isset($command['configuration']['class'])) { $command['configuration']['class'] = ''; } try { $cmd = new openzwaveCmd(); $cmd->setOrder($cmd_order); $cmd->setEqLogic_id($this->getId()); utils::a2o($cmd, $command); if (isset($command['value'])) { $cmd->setValue(null); } $cmd->save(); if (isset($command['value'])) { $link_cmds[$cmd->getId()] = $command['value']; } $cmd_order++; } catch (Exception $exc) { } } if (count($link_cmds) > 0) { foreach ($this->getCmd() as $eqLogic_cmd) { foreach ($link_cmds as $cmd_id => $link_cmd) { if ($link_cmd == $eqLogic_cmd->getName()) { $cmd = cmd::byId($cmd_id); if (is_object($cmd)) { $cmd->setValue($eqLogic_cmd->getId()); $cmd->save(); } } } } } $this->save(); nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => '')); }
require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php'; include_file('core', 'authentification', 'php'); if (!isConnect('admin')) { throw new Exception('401 Unauthorized'); } if (init('action') == 'get') { $return = array(); $eqLogic = eqLogic::byId(init('id')); if (!is_object($eqLogic)) { throw new Exception('Equipement non trouvé vérifiez l\'id : ' . init('id')); } $return['eqLogic'] = utils::o2a($eqLogic); $energy = energy::byEqLogic_id($eqLogic->getId()); $return['energy'] = is_object($energy) ? jeedom::toHumanReadable(utils::o2a($energy)) : array('eqLogic_id' => $eqLogic->getId(), 'id' => ''); ajax::success($return); } if (init('action') == 'save') { $energy_json = json_decode(init('energy'), true); $energy = energy::byId($energy_json['id']); if (!is_object($energy)) { $energy = new energy(); } utils::a2o($energy, jeedom::fromHumanReadable($energy_json)); $energy->save(); ajax::success(); } throw new Exception('Aucune methode correspondante'); /* * *********Catch exeption*************** */ } catch (Exception $e) { ajax::error(displayExeption($e), $e->getCode()); }