public function cron30($_eqlogic_id = null) { if ($_eqlogic_id !== null) { $eqLogics = array(eqLogic::byId($_eqlogic_id)); } else { $eqLogics = eqLogic::byType('karotz'); } foreach ($eqLogics as $karotz) { if ($karotz->getIsEnable() == 1) { $request = 'http://' . $karotz->getConfiguration('addr') . '/cgi-bin/status'; $request = new com_http($request); $jsonstatus = json_decode($request->exec(5, 1), true); $change = false; foreach ($karotz->getCmd() as $cmd) { if (!isset($jsonstatus[$cmd->getLogicalId()])) { continue; } $value = $jsonstatus[$cmd->getLogicalId()]; if ($cmd->getLogicalId() == 'led_color') { $value = '#' . $value; } if ($cmd->execCmd() !== $cmd->formatValue($value)) { $cmd->event($value); $change = true; } } if ($change) { $karotz->refreshWidget(); } } } }
public static function cronHourly($_eqlogic_id = null) { if ($_eqlogic_id !== null) { $eqLogics = array(eqLogic::byId($_eqlogic_id)); } else { $eqLogics = eqLogic::byType('porkfolio'); } foreach ($eqLogics as $porkfolio) { if ($porkfolio->getIsEnable() == 1) { log::add('porkfolio', 'debug', 'Pull Cron pour Porkfolio'); $porkfolioInfo = $porkfolio->getporkfolioInfo(); $somme = isset($porkfolioInfo['Somme']) ? $porkfolioInfo['Somme'] : "old"; $derniervers = isset($porkfolioInfo['Dernier']) ? $porkfolioInfo['Dernier'] : "old"; $datemvt = isset($porkfolioInfo['Date Mouvement']) ? $porkfolioInfo['Date Mouvement'] : "old"; $dateretournement = isset($porkfolioInfo['Date Retournement']) ? $porkfolioInfo['Date Retournement'] : "old"; $datevers = isset($porkfolioInfo['Date depot']) ? $porkfolioInfo['Date depot'] : "old"; $objectif = isset($porkfolioInfo['Objectif']) ? $porkfolioInfo['Objectif'] : "old"; $nez = isset($porkfolioInfo['Nez']) ? $porkfolioInfo['Nez'] : "old"; foreach ($porkfolio->getCmd('info') as $cmd) { switch ($cmd->getName()) { case 'Somme': $value = $somme; break; case 'Dernière Opération': $value = $derniervers; break; case 'Date mouvement': $value = $datemvt; break; case 'Date dépot': $value = $datevers; break; case 'Nez': $value = $nez; break; case 'Date retournement': $value = $dateretournement; break; case 'Objectif': $value = $objectif; break; } if ($value == 0 || $value != 'old') { $cmd->event($value); log::add('porkfolio', 'debug', 'set:' . $cmd->getName() . ' to ' . $value); } } $mc = cache::byKey('porkfolioWidgetmobile' . $porkfolio->getId()); $mc->remove(); $mc = cache::byKey('porkfolioWidgetdashboard' . $porkfolio->getId()); $mc->remove(); $porkfolio->toHtml('mobile'); $porkfolio->toHtml('dashboard'); $porkfolio->refreshWidget(); } } }
public static function cron30($_eqlogic_id = null) { if ($_eqlogic_id !== null) { $eqLogics = array(eqLogic::byId($_eqlogic_id)); } else { $eqLogics = eqLogic::byType('wazeintime'); sleep(rand(0, 120)); } foreach ($eqLogics as $wazeintime) { if ($wazeintime->getIsEnable() == 1) { try { $start = $wazeintime->getPosition('start'); $end = $wazeintime->getPosition('end'); $row = $wazeintime->getConfiguration('NOA') ? '' : 'row-'; $wazeRouteurl = 'https://www.waze.com/' . $row . 'RoutingManager/routingRequest?from=x%3A' . $start['lon'] . '+y%3A' . $start['lat'] . '&to=x%3A' . $end['lon'] . '+y%3A' . $end['lat'] . '&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At'; $request_http = new com_http($wazeRouteurl); $request_http->setUserAgent('User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0'); $json = json_decode($request_http->exec(6, 2), true); if (isset($json['error'])) { throw new Exception($json['error']); } $data = self::extractInfo($json); $wazeRoutereturl = 'https://www.waze.com/' . $row . 'RoutingManager/routingRequest?from=x%3A' . $end['lon'] . '+y%3A' . $end['lat'] . '&to=x%3A' . $start['lon'] . '+y%3A' . $start['lat'] . '&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At'; $request_http = new com_http($wazeRoutereturl); $request_http->setUserAgent('User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0'); $json = json_decode($request_http->exec(6, 2), true); if (isset($json['error'])) { throw new Exception($json['error']); } $data = array_merge($data, self::extractInfo($json, 'ret')); log::add('wazeintime', 'debug', 'Data : ' . print_r($data, true)); foreach ($wazeintime->getCmd('info') as $cmd) { if ($cmd->getLogicalId() == 'lastrefresh') { $cmd->event(date('H:i')); continue; } if (!isset($data[$cmd->getLogicalId()])) { continue; } if ($cmd->formatValue($data[$cmd->getLogicalId()]) != $cmd->execCmd()) { $cmd->setCollectDate(''); $cmd->event($data[$cmd->getLogicalId()]); } } $wazeintime->refreshWidget(); } catch (Exception $e) { log::add('wazeintime', 'error', $e->getMessage()); } } } }
public static function cron($_eqlogic_id = null, $force = false) { if ($_eqlogic_id !== null) { $eqLogics = array(eqLogic::byId($_eqlogic_id)); } else { $eqLogics = eqLogic::byType('trains'); } foreach ($eqLogics as $trains) { if ($trains->getIsEnable() == 1) { if ($force || date('Hi', time()) >= $trains->getConfiguration('trains_maj_deb') && date('Hi', time()) <= $trains->getConfiguration('trains_maj_fin')) { log::add('trains', 'debug', 'Pull ' . ($force ? 'Forcé' : 'Cron') . ' pour trains '); $baseUrl = 'http://www.gares-sncf.com/fr/train-times/departure/' . $trains->getConfiguration('trains_depart') . '/gl'; $arrivee = $trains->getConfiguration('trains_arrivee'); $response = file_get_contents($baseUrl); $json = json_decode($response, true); $departs = []; foreach ($json['trains'] as $depart) { $trainCourant = (object) []; if ($arrivee == '' || $trains->string_contains($depart['origdest'], $arrivee)) { $trainCourant->dest = $depart['origdest']; $trainCourant->type = $depart['type']; $trainCourant->voie = $depart['voie']; $trainCourant->heure = $depart['heure']; $trainCourant->etat = $depart['etat']; $trainCourant->retard = $depart['retard']; $trainCourant->infos = $depart['infos']; $departs[] = $trainCourant; } } log::add('trains', 'debug', 'Date de mise à jour des infos récupérées : ' . $json['updated']); log::add('trains', 'debug', 'infos récupérées : ' . json_encode($departs)); $result = (object) []; $result->updated = $json['updated']; $result->departs = $departs; $trainsCmd = $trains->getCmd(null, 'Departs'); if (is_object($trainsCmd)) { $trainsCmd->event(json_encode($result)); } $trains->refreshWidget(); } } } }
public function copyFromEqLogic($_eqLogic_id) { $eqLogic = eqLogic::byId($_eqLogic_id); if (!is_object($eqLogic)) { throw new Exception(__('Impossible de trouver l\'équipement : ', __FILE__) . $_eqLogic_id); } if ($eqLogic->getEqType_name() == 'virtual') { throw new Exception(__('Vous ne pouvez importer la configuration d\'un équipement virtuel', __FILE__)); } foreach ($eqLogic->getCategory() as $key => $value) { $this->setCategory($key, $value); } foreach ($eqLogic->getCmd() as $cmd_def) { $cmd = new virtualCmd(); $cmd->setName($cmd_def->getName()); $cmd->setEqLogic_id($this->getId()); $cmd->setIsVisible($cmd_def->getIsVisible()); $cmd->setType($cmd_def->getType()); $cmd->setUnite($cmd_def->getUnite()); $cmd->setOrder($cmd_def->getOrder()); $cmd->setDisplay('icon', $cmd_def->getDisplay('icon')); $cmd->setDisplay('invertBinary', $cmd_def->getDisplay('invertBinary')); foreach ($cmd_def->getTemplate() as $key => $value) { $cmd->setTemplate($key, $value); } $cmd->setSubType($cmd_def->getSubType()); if ($cmd->getType() == 'info') { $cmd->setConfiguration('calcul', '#' . $cmd_def->getId() . '#'); $cmd->setValue($cmd_def->getId()); $cmd->setEventOnly(1); } else { $cmd->setValue($cmd_def->getValue()); $cmd->setConfiguration('infoName', '#' . $cmd_def->getId() . '#'); } $cmd->save(); } $this->save(); }
throw new Exception(__('401 - Accès non autorisé', __FILE__)); } $type = init('type'); switch ($type) { case 'cmdHistory': $cmd = cmd::byId(init('id')); if (!is_object($cmd)) { throw new Exception(__('Commande introuvable : ', __FILE__) . init('id')); } header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=' . str_replace(' ', '_', $cmd->getHumanName()) . '.csv'); $histories = $cmd->getHistory(); foreach ($histories as $history) { echo $history->getDatetime(); echo ';'; echo str_replace('.', ',', $history->getValue()); echo "\n"; } break; case 'eqLogic': $eqLogic = eqLogic::byId(init('id')); if (!is_object($eqLogic)) { throw new Exception(__('Commande introuvable : ', __FILE__) . init('id')); } header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=' . $eqLogic->getHumanName() . '.json'); echo json_encode($eqLogic->export(), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); break; default: break; }
public function execute(&$scenario = null) { if ($this->getOptions('enable', 1) == 0) { return; } $message = ''; try { if ($this->getType() == 'element') { $element = scenarioElement::byId($this->getExpression()); if (is_object($element)) { $this->setLog($scenario, __('Exécution d\'un bloc élément : ', __FILE__) . $this->getExpression()); return $element->execute($scenario); } return; } $options = $this->getOptions(); if (isset($options['enable'])) { unset($options['enable']); } if (is_array($options) && $this->getExpression() != 'wait') { foreach ($options as $key => $value) { $options[$key] = str_replace('"', '', self::setTags($value, $scenario)); } } if ($this->getType() == 'action') { if ($this->getExpression() == 'icon') { if ($scenario != null) { $options = $this->getOptions(); $this->setLog($scenario, __('Changement de l\'icone du scénario : ', __FILE__) . $options['icon']); $scenario->setDisplay('icon', $options['icon']); $scenario->save(); } return; } else { if ($this->getExpression() == 'wait') { if (!isset($options['condition'])) { return; } $result = false; $occurence = 0; $limit = isset($options['timeout']) && is_numeric($options['timeout']) ? $options['timeout'] : 7200; while ($result !== true) { $expression = self::setTags($options['condition'], $scenario); $result = evaluate($expression); if ($occurence > $limit) { $this->setLog($scenario, __('[Wait] Condition valide par dépassement de temps', __FILE__)); return; } $occurence++; sleep(1); } $this->setLog($scenario, __('[Wait] Condition valide : ', __FILE__) . $expression); return; } else { if ($this->getExpression() == 'sleep') { if (isset($options['duration'])) { try { $options['duration'] = evaluate($options['duration']); } catch (Exception $e) { } if (is_numeric($options['duration']) && $options['duration'] > 0) { $this->setLog($scenario, __('Pause de ', __FILE__) . $options['duration'] . __(' seconde(s)', __FILE__)); if ($options['duration'] < 1) { return usleep($options['duration'] * 1000); } else { return sleep($options['duration']); } } } $this->setLog($scenario, __('Aucune durée trouvée pour l\'action sleep ou la durée n\'est pas valide : ', __FILE__) . $options['duration']); return; } else { if ($this->getExpression() == 'stop') { if ($scenario != null) { $this->setLog($scenario, __('Arret du scénario', __FILE__)); $scenario->setState('stop'); $scenario->setPID(''); $scenario->persistLog(); $scenario->save(); } die; } else { if ($this->getExpression() == 'log') { if ($scenario != null) { $scenario->setLog('Log : ' . $options['message']); if ($scenario->getConfiguration('speedPriority', 0) == 1) { $scenario->persistLog(); } } return; } else { if ($this->getExpression() == 'message') { message::add('scenario', $options['message']); return; } else { if ($this->getExpression() == 'equipement') { $eqLogic = eqLogic::byId(str_replace(array('#eqLogic', '#'), '', $this->getOptions('eqLogic'))); if (!is_object($eqLogic)) { throw new Exception(__('Action sur l\'équipement impossible. Equipement introuvable - Vérifiez l\'id : ', __FILE__) . $this->getOptions('eqLogic')); } switch ($this->getOptions('action')) { case 'show': $this->setLog($scenario, __('Equipement visible : ', __FILE__) . $eqLogic->getHumanName()); $eqLogic->setIsVisible(1); $eqLogic->save(); break; case 'hide': $this->setLog($scenario, __('Equipement masqué : ', __FILE__) . $eqLogic->getHumanName()); $eqLogic->setIsVisible(0); $eqLogic->save(); break; case 'deactivate': $this->setLog($scenario, __('Equipement désactivé : ', __FILE__) . $eqLogic->getHumanName()); $eqLogic->setIsEnable(0); $eqLogic->save(); break; case 'activate': $this->setLog($scenario, __('Equipement activé : ', __FILE__) . $eqLogic->getHumanName()); $eqLogic->setIsEnable(1); $eqLogic->save(); break; } return; } else { if ($this->getExpression() == 'say') { $this->setLog($scenario, __('Je dis : ', __FILE__) . $options['message']); nodejs::pushUpdate('jeedom::say', $options['message']); return; } else { if ($this->getExpression() == 'gotodesign') { $this->setLog($scenario, __('Changement design : ', __FILE__) . $options['plan_id']); nodejs::pushUpdate('jeedom::gotoplan', $options['plan_id']); return; } else { if ($this->getExpression() == 'return') { $this->setLog($scenario, __('Je vais retourner : ', __FILE__) . $options['message']); $scenario->setReturn($scenario->getReturn() . $options['message']); return; } else { if ($this->getExpression() == 'scenario') { if ($scenario != null && $this->getOptions('scenario_id') == $scenario->getId()) { $actionScenario =& $scenario; } else { $actionScenario = scenario::byId($this->getOptions('scenario_id')); } if (!is_object($actionScenario)) { throw new Exception($scenario, __('Action sur scénario impossible. Scénario introuvable - Vérifiez l\'id : ', __FILE__) . $this->getOptions('scenario_id')); } switch ($this->getOptions('action')) { case 'start': $this->setLog($scenario, __('Lancement du scénario : ', __FILE__) . $actionScenario->getName()); if ($scenario != null) { $actionScenario->launch(false, __('Lancement provoqué par le scénario : ', __FILE__) . $scenario->getHumanName()); } else { $actionScenario->launch(false, __('Lancement provoqué', __FILE__)); } break; case 'stop': $this->setLog($scenario, __('Arrêt forcé du scénario : ', __FILE__) . $actionScenario->getName()); $actionScenario->stop(); break; case 'deactivate': $this->setLog($scenario, __('Désactivation du scénario : ', __FILE__) . $actionScenario->getName()); $actionScenario->setIsActive(0); $actionScenario->save(); break; case 'activate': $this->setLog($scenario, __('Activation du scénario : ', __FILE__) . $actionScenario->getName()); $actionScenario->setIsActive(1); $actionScenario->save(); break; } return; } else { if ($this->getExpression() == 'variable') { $options['value'] = self::setTags($options['value']); try { $result = evaluate($options['value']); if (!is_numeric($result)) { $result = $options['value']; } } catch (Exception $ex) { $result = $options['value']; } $message = __('Affectation de la variable ', __FILE__) . $this->getOptions('name') . __(' => ', __FILE__) . $options['value'] . ' = ' . $result; $this->setLog($scenario, $message); $dataStore = new dataStore(); $dataStore->setType('scenario'); $dataStore->setKey($this->getOptions('name')); $dataStore->setValue($result); $dataStore->setLink_id(-1); $dataStore->save(); return; } else { $cmd = cmd::byId(str_replace('#', '', $this->getExpression())); if (is_object($cmd)) { if ($cmd->getSubtype() == 'slider' && isset($options['slider'])) { $options['slider'] = evaluate($options['slider']); } if (is_array($options) && count($options) != 0) { $this->setLog($scenario, __('Exécution de la commande ', __FILE__) . $cmd->getHumanName() . __(" avec comme option(s) : \n", __FILE__) . print_r($options, true)); } else { $this->setLog($scenario, __('Exécution de la commande ', __FILE__) . $cmd->getHumanName()); } if (is_object($scenario) && $scenario->getConfiguration('cmdNoWait', 0) == 1) { $options['speedAndNoErrorReport'] = true; } return $cmd->execCmd($options); } $this->setLog($scenario, __('[Erreur] Aucune commande trouvée pour ', __FILE__) . $this->getExpression()); return; } } } } } } } } } } } } } else { if ($this->getType() == 'condition') { $expression = self::setTags($this->getExpression(), $scenario, true); $message = __('Evaluation de la condition : [', __FILE__) . $expression . '] = '; $result = evaluate($expression); if (is_bool($result)) { if ($result) { $message .= __('Vrai', __FILE__); } else { $message .= __('Faux', __FILE__); } } else { $message .= $result; } $this->setLog($scenario, $message); return $result; } else { if ($this->getType() == 'code') { $this->setLog($scenario, __('Exécution d\'un bloc code', __FILE__)); return eval($this->getExpression()); } } } } catch (Exception $e) { $this->setLog($scenario, $message . $e->getMessage()); } }
public function getEqLogic() { if ($this->_eqLogic == null) { $this->_eqLogic = eqLogic::byId($this->eqLogic_id); } return $this->_eqLogic; }
public function ping() { if ($this->getConfiguration('pingState', 1) != 1) { return true; } log::add('alarm', 'debug', 'Lancement du ping de l\'alarme : ' . $this->getHumanName()); foreach ($this->getConfiguration('pingTest') as $pingTest) { $eqLogic = eqLogic::byId(str_replace('#', '', $pingTest['eqLogic'])); if (!is_object($eqLogic)) { continue; } log::add('alarm', 'debug', 'Test ping pour : ' . $eqLogic->getHumanName()); if ($eqLogic->getIsEnable() == 1 && method_exists($eqLogic, 'ping')) { if (!$eqLogic->ping()) { log::add('alarm', 'debug', 'Ping NOK sur : ' . $eqLogic->getHumanName()); $this->setConfiguration('pingState', 0); $this->save(); log::add('alarm', 'debug', 'Alert perte ping éxecution des actions'); foreach ($this->getConfiguration('ping') as $action) { $cmd = cmd::byId(str_replace('#', '', $action['cmd'])); if (is_object($cmd)) { try { log::add('alarm', 'debug', 'Exécution de la commande ' . $cmd->getHumanName()); $options = array(); if (isset($action['options'])) { $options = $action['options']; } $cmd->execCmd($options); } catch (Exception $e) { log::add('alarm', 'error', 'Erreur lors de l\'éxecution de ' . $cmd->getHumanName() . '. Détails : ' . $e->getMessage()); } } } break; } else { log::add('alarm', 'debug', 'Ping OK sur : ' . $eqLogic->getHumanName()); } } else { log::add('alarm', 'debug', 'Aucune méthode de ping pour : ' . $eqLogic->getHumanName()); } } }
<?php if (!isConnect('admin')) { throw new Exception('{{401 - Accès non autorisé}}'); } $eqLogic = eqLogic::byId(init('eqLogic_id')); if (!is_object($eqLogic)) { throw new Exception('EqLogic non trouvé : ' . init('eqLogic_id')); } sendVarToJS('eqLogicInfo', utils::o2a($eqLogic)); ?> <div style="display: none;" id="md_displayEqLogicConfigure"></div> <a class="btn btn-danger pull-right btn-sm" id="bt_eqLogicConfigureRemove"><i class="fa fa-times"></i> {{Supprimer}}</a> <a class="btn btn-success pull-right btn-sm" id="bt_eqLogicConfigureSave"><i class="fa fa-check-circle"></i> {{Enregistrer}}</a> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#information" aria-controls="home" role="tab" data-toggle="tab">{{Informations}}</a></li> <li role="presentation"><a href="#display" aria-controls="messages" role="tab" data-toggle="tab">{{Affichage avancé}}</a></li> </ul> <div class="tab-content" id="div_displayEqLogicConfigure"> <div role="tabpanel" class="tab-pane active" id="information"> <br/> <div class="row"> <div class="col-sm-4" > <form class="form-horizontal"> <fieldset> <div class="form-group"> <label class="col-sm-4 control-label">{{ID}}</label> <div class="col-sm-4">
public function getLink() { if ($this->getLink_type() == 'eqLogic') { $eqLogic = eqLogic::byId($this->getLink_id()); return $eqLogic; } else { if ($this->getLink_type() == 'scenario') { $scenario = scenario::byId($this->getLink_id()); return $scenario; } } return null; }
foreach ($eqLogic->getCmd() as $cmd) { $info_cmd = utils::o2a($cmd); if ($cmd->getType() == 'info') { $info_cmd['value'] = $cmd->execCmd(); $info_cmd['collectDate'] = $cmd->getCollectDate(); } $info_cmds[] = $info_cmd; } $info_eqLogic = utils::o2a($eqLogic); $info_eqLogic['cmds'] = $info_cmds; $info_eqLogics[] = $info_eqLogic; } $return[$eqType] = $info_eqLogics; } foreach ($params['id'] as $id) { $eqLogic = eqLogic::byId($id); $info_cmds = array(); foreach ($eqLogic->getCmd() as $cmd) { $info_cmd = utils::o2a($cmd); if ($cmd->getType() == 'info') { $info_cmd['value'] = $cmd->execCmd(); $info_cmd['collectDate'] = $cmd->getCollectDate(); } $info_cmds[] = $info_cmd; } $info_eqLogic = utils::o2a($eqLogic); $info_eqLogic['cmds'] = $info_cmds; $return[$id] = $info_eqLogic; } $jsonrpc->makeSuccess($return); }
public static function clean() { $sql = "DELETE FROM `cache` WHERE (UNIX_TIMESTAMP(`datetime`) + lifetime) < UNIX_TIMESTAMP(NOW()) AND lifetime > 0"; DB::Prepare($sql, array(), DB::FETCH_TYPE_ROW); $sql = "SELECT * FROM `cache` WHERE `key` LIKE 'cmd%' AND lifetime = 0"; $results = DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); foreach ($results as $result) { $id = str_replace('cmd', '', $result['key']); if (is_numeric($id)) { $cmd = cmd::byId($id); if (!is_object($cmd)) { $sql = "DELETE FROM `cache` WHERE `key`=:key"; $value = array('key' => $result['key']); DB::Prepare($sql, $value, DB::FETCH_TYPE_ROW); } } } $sql = "SELECT * FROM `cache` WHERE `key` LIKE 'core::eqLogic%::lastCommunication'"; $results = DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); foreach ($results as $result) { $id = str_replace(array('core::eqLogic', '::lastCommunication'), '', $result['key']); if (is_numeric($id)) { $eqLogic = eqLogic::byId($id); if (!is_object($eqLogic)) { $sql = "DELETE FROM `cache` WHERE `key`=:key"; $value = array('key' => $result['key']); DB::Prepare($sql, $value, DB::FETCH_TYPE_ROW); } } } $sql = "SELECT * FROM `cache` WHERE `key` LIKE 'core::eqLogic%::numberTryWithoutSuccess'"; $results = DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); foreach ($results as $result) { $id = str_replace(array('core::eqLogic', '::numberTryWithoutSuccess'), '', $result['key']); if (is_numeric($id)) { $eqLogic = eqLogic::byId($id); if (!is_object($eqLogic)) { $sql = "DELETE FROM `cache` WHERE `key`=:key"; $value = array('key' => $result['key']); DB::Prepare($sql, $value, DB::FETCH_TYPE_ROW); } } } $sql = "SELECT * FROM `cache` WHERE `key` LIKE 'core::eqLogic%::numberTryWithoutSuccess'"; $results = DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); foreach ($results as $result) { $id = str_replace(array('core::eqLogic', '::numberTryWithoutSuccess'), '', $result['key']); if (is_numeric($id)) { $eqLogic = eqLogic::byId($id); if (!is_object($eqLogic)) { $sql = "DELETE FROM `cache` WHERE `key`=:key"; $value = array('key' => $result['key']); DB::Prepare($sql, $value, DB::FETCH_TYPE_ROW); } } } $sql = "SELECT * FROM `cache` WHERE `key` LIKE 'widgetHtmldashboard%'"; $results = DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); foreach ($results as $result) { $id = str_replace(array('widgetHtmldashboard'), '', $result['key']); if (is_numeric($id)) { $eqLogic = eqLogic::byId($id); if (!is_object($eqLogic)) { $sql = "DELETE FROM `cache` WHERE `key`=:key"; $value = array('key' => $result['key']); DB::Prepare($sql, $value, DB::FETCH_TYPE_ROW); } } } }
public static function cron30($_eqlogic_id = null) { if ($_eqlogic_id !== null) { $eqLogics = array(eqLogic::byId($_eqlogic_id)); } else { $eqLogics = eqLogic::byType('wazeintime'); } foreach ($eqLogics as $wazeintime) { if ($wazeintime->getIsEnable() == 1) { log::add('wazeintime', 'debug', 'Pull Cron pour Waze Duration'); $latdepart = $wazeintime->getConfiguration('latdepart'); $londepart = $wazeintime->getConfiguration('londepart'); $latarrive = $wazeintime->getConfiguration('latarrive'); $lonarrive = $wazeintime->getConfiguration('lonarrive'); if ($wazeintime->getConfiguration('NOA')) { $row = ''; } else { $row = 'row-'; } $wazeRouteurl = "https://www.waze.com/" . $row . "RoutingManager/routingRequest?from=x%3A{$londepart}+y%3A{$latdepart}&to=x%3A{$lonarrive}+y%3A{$latarrive}&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At"; log::add('wazeintime', 'debug', $wazeRouteurl); $wazeRoutereturl = "https://www.waze.com/" . $row . "RoutingManager/routingRequest?from=x%3A{$lonarrive}+y%3A{$latarrive}&to=x%3A{$londepart}+y%3A{$latdepart}&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At"; $routeResponseText = file_get_contents($wazeRouteurl); $routeResponseJson = json_decode($routeResponseText, true); $route1Name = isset($routeResponseJson['alternatives'][0]['response']['routeName']) ? $routeResponseJson['alternatives'][0]['response']['routeName'] : "NA"; $route2Name = isset($routeResponseJson['alternatives'][1]['response']['routeName']) ? $routeResponseJson['alternatives'][1]['response']['routeName'] : "NA"; $route3Name = isset($routeResponseJson['alternatives'][2]['response']['routeName']) ? $routeResponseJson['alternatives'][2]['response']['routeName'] : "NA"; $route1 = $routeResponseJson['alternatives'][0]['response']['results']; $route2 = $routeResponseJson['alternatives'][1]['response']['results']; $route3 = $routeResponseJson['alternatives'][2]['response']['results']; $route1TotalTimeSec = 0; foreach ($route1 as $street) { $route1TotalTimeSec += $street['crossTime']; } $route2TotalTimeSec = 0; foreach ($route2 as $street) { $route2TotalTimeSec += $street['crossTime']; } $route3TotalTimeSec = 0; foreach ($route3 as $street) { $route3TotalTimeSec += $street['crossTime']; } $route1TotalTimeMin = round($route1TotalTimeSec / 60); $route2TotalTimeMin = round($route2TotalTimeSec / 60); $route3TotalTimeMin = round($route3TotalTimeSec / 60); $routeretResponseText = file_get_contents($wazeRoutereturl); $routeretResponseJson = json_decode($routeretResponseText, true); $route1retName = isset($routeretResponseJson['alternatives'][0]['response']['routeName']) ? $routeretResponseJson['alternatives'][0]['response']['routeName'] : "NA"; $route2retName = isset($routeretResponseJson['alternatives'][1]['response']['routeName']) ? $routeretResponseJson['alternatives'][1]['response']['routeName'] : "NA"; $route3retName = isset($routeretResponseJson['alternatives'][2]['response']['routeName']) ? $routeretResponseJson['alternatives'][2]['response']['routeName'] : "NA"; $routeret1 = $routeretResponseJson['alternatives'][0]['response']['results']; $routeret2 = $routeretResponseJson['alternatives'][1]['response']['results']; $routeret3 = $routeretResponseJson['alternatives'][2]['response']['results']; $route1retTotalTimeSec = 0; foreach ($routeret1 as $street) { $route1retTotalTimeSec += $street['crossTime']; } $route2retTotalTimeSec = 0; foreach ($routeret2 as $street) { $route2retTotalTimeSec += $street['crossTime']; } $route3retTotalTimeSec = 0; foreach ($routeret3 as $street) { $route3retTotalTimeSec += $street['crossTime']; } $route1retTotalTimeMin = round($route1retTotalTimeSec / 60); $route2retTotalTimeMin = round($route2retTotalTimeSec / 60); $route3retTotalTimeMin = round($route3retTotalTimeSec / 60); foreach ($wazeintime->getCmd('info') as $cmd) { switch ($cmd->getName()) { case 'Durée 1': $value = $route1TotalTimeMin; break; case 'Durée 2': $value = $route2TotalTimeMin; break; case 'Durée 3': $value = $route3TotalTimeMin; break; case 'Trajet 1': $value = $route1Name; break; case 'Trajet 2': $value = $route2Name; break; case 'Trajet 3': $value = $route3Name; break; case 'Durée retour 1': $value = $route1retTotalTimeMin; break; case 'Durée retour 2': $value = $route2retTotalTimeMin; break; case 'Durée retour 3': $value = $route3retTotalTimeMin; break; case 'Trajet retour 1': $value = $route1retName; break; case 'Trajet retour 2': $value = $route2retName; break; case 'Trajet retour 3': $value = $route3retName; break; case 'Dernier refresh': $value = date('H:i'); } if ($value == 0 || $value != 'old') { $cmd->event($value); log::add('wazeintime', 'debug', 'set:' . $cmd->getName() . ' to ' . $value); } } $wazeintime->refreshWidget(); } } }
/* Uploadify v3.1.0 Copyright (c) 2012 Reactive Apps, Ronnie Garcia Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> */ die; require_once dirname(__FILE__) . "/../../core/php/core.inc.php"; if (!empty($_FILES) && isset($_GET['id']) && isset($_GET['type'])) { $fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array(strtolower($fileParts['extension']), $fileTypes)) { switch ($_GET['type']) { case "eqLogic": $eqLogic = eqLogic::byId($_GET['id']); if (!is_object($eqLogic)) { error_log('EqLogic inconnu verifié l\'id'); return false; } $eqLogic->saveImage(getUploadedImage(200, 150)); break; case "object": $object = object::byId($_GET['id']); if (!is_object($object)) { error_log('Object inconnu verifié l\'id'); return false; } $object->saveImage(getUploadedImage()); break; default: