public static function stop() { try { echo "Desactivation de toutes les tâches"; config::save('enableCron', 0); foreach (cron::all() as $cron) { if ($cron->running()) { try { $cron->halt(); echo '.'; } catch (Exception $e) { sleep(5); $cron->halt(); } } } echo " OK\n"; } catch (Exception $e) { if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { throw $e; } else { echo "\n***ERREUR*** " . $e->getMessage(); } } /* * **********Arret des crons********************* */ try { if (cron::jeeCronRun()) { echo "Arret du cron master "; $pid = cron::getPidFile(); $kill = posix_kill($pid, 15); if (!$kill) { $kill = posix_kill($pid, 9); if (!$kill) { throw new Exception('Impossible d\'arrêter le cron master : ' . $pid); } } echo " OK\n"; } } catch (Exception $e) { if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { throw $e; } else { echo '***ERREUR*** ' . $e->getMessage(); } } /* * *********Arrêt des scénarios**************** */ try { echo "Désactivation de tous les scénarios"; config::save('enableScenario', 0); foreach (scenario::all() as $scenario) { try { $scenario->stop(); echo '.'; } catch (Exception $e) { sleep(5); $scenario->stop(); } } echo " OK\n"; } catch (Exception $e) { if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { throw $e; } else { echo '***ERREUR*** ' . $e->getMessage(); } } }
$return = array(); foreach (scenario::listGroup(init('term')) as $group) { $return[] = $group['group']; } ajax::success($return); } if (init('action') == 'toHtml') { if (init('id') == 'all' || is_json(init('id'))) { if (is_json(init('id'))) { $scenario_ajax = json_decode(init('id'), true); $scenarios = array(); foreach ($scenario_ajax as $id) { $scenarios[] = scenario::byId($id); } } else { $scenarios = scenario::all(); } $return = array(); foreach ($scenarios as $scenario) { if ($scenario->getIsVisible() == 1) { $return[$scenario->getId()] = $scenario->toHtml(init('version')); } } ajax::success($return); } else { $scenario = scenario::byId(init('id')); if (is_object($scenario)) { ajax::success($scenario->toHtml(init('version'))); } } ajax::success();
public static function cleanTable() { $ids = array('element' => array(), 'subelement' => array(), 'expression' => array()); foreach (scenario::all() as $scenario) { foreach ($scenario->getElement() as $element) { $result = $element->getAllId(); $ids['element'] = array_merge($ids['element'], $result['element']); $ids['subelement'] = array_merge($ids['subelement'], $result['subelement']); $ids['expression'] = array_merge($ids['expression'], $result['expression']); } } $sql = 'DELETE FROM scenarioExpression WHERE id NOT IN (-1'; foreach ($ids['expression'] as $expression_id) { $sql .= ',' . $expression_id; } $sql .= ')'; DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); $sql = 'DELETE FROM scenarioSubElement WHERE id NOT IN (-1'; foreach ($ids['subelement'] as $subelement_id) { $sql .= ',' . $subelement_id; } $sql .= ')'; DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); $sql = 'DELETE FROM scenarioElement WHERE id NOT IN (-1'; foreach ($ids['element'] as $element_id) { $sql .= ',' . $element_id; } $sql .= ')'; DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); }
<div class="form-group"> <input class="eqLogicAttr form-control input-sm" data-l1key="configuration" data-l2key="display_ids" id="display_ids" style="display:none;" /> </div> </fieldset> </form> <legend><i class="fa fa-list-alt"></i> {{Tableau des scénarios}}</legend> <table id="table_scenarios" class="table table-bordered table-condensed"> <thead> <tr> <th></th><th>{{Nom}}</th><th>{{Groupe}}</th> </tr> </thead> <tbody> <?php foreach (scenario::all() as $scenario) { echo '<tr><td><input type="checkbox" class="bootstrapSwitch scenarios" data-label-text="{{Afficher}}" id="' . $scenario->getId() . '"/></td><td><span>' . $scenario->getName() . '</span></td><td>' . $scenario->getGroup() . '</td></tr>'; } ?> </tbody> </table> <form class="form-horizontal"> <fieldset> <div class="form-actions"> <a class="btn btn-danger eqLogicAction" data-action="remove"><i class="fa fa-minus-circle"></i> {{Supprimer}}</a> <a class="btn btn-success eqLogicAction" data-action="save"><i class="fa fa-check-circle"></i> {{Sauvegarder}}</a> </div> </fieldset> </form>
throw new Exception('{{401 - Accès non autorisé}}'); } ?> <div class="form-horizontal"> <div class="alert alert-info" style="font-size:90%;"> {{Cette fenêtre vous permet de créer le format de l'événement dans Google Agenda, pour pouvoir lancer automatiquement des scénarios Jeedom à partir de Google.<br/><br/> Le format attendu doit être du type : sc=id_scenario;texte_information;variable_scenario;valeur_variable_1erMin;valeur_variable_DernièreMin <br/> -- Remarque : les valeurs du texte d'information et des variables ne doivent pas contenir de point-virgule (;). }} </div> <div class="form-group"> <label class="col-sm-2 control-label" >{{Nom du scénario}}</label> <div class="col-sm-3"> <select id="gCalendar_idScenario" class="eqLogicAttr form-control"> <?php foreach (scenario::all() as $_oScenario) { echo '<option value="' . $_oScenario->getId() . '">[' . ($_oScenario->getGroup() == '' ? 'Aucun' : $_oScenario->getGroup()) . '] ' . $_oScenario->getName() . '</option>'; } ?> </select> </div> <span>({{Valeur obligatoire}})</span> </div> <div class="form-group"> <label class="col-sm-2 control-label">{{Texte d'information}}</label> <div class="col-sm-3"> <input type="text" id="gCalendar_texte" class="eqLogicAttr form-control"/> </div> <span>({{Valeur non obligatoire}}, {{s'affiche sur le calendrier à coté du nom du scénario}})</span> </div> <div class="form-group">
<?php if (!hasRight('scenarioview', true)) { throw new Exception('{{401 - Accès non autorisé}}'); } $scenarios = array(); $scenarios[-1] = scenario::all(null); $scenarioListGroup = scenario::listGroup(); if (is_array($scenarioListGroup)) { foreach ($scenarioListGroup as $group) { $scenarios[$group['group']] = scenario::all($group['group']); } } ?> <div style="position : fixed;height:100%;width:15px;top:50px;left:0px;z-index:998;background-color:#f6f6f6;" id="bt_displayScenarioList"><i class="fa fa-arrow-circle-o-right" style="color : #b6b6b6;"></i></div> <div class="row row-overflow"> <div class="col-lg-2 col-md-3 col-sm-4" id="div_listScenario" style="z-index:999"> <div class="bs-sidebar nav nav-list bs-sidenav"> <a class="btn btn-success pull-right form-control" id="bt_switchToExpertMode" href="index.php?v=d&p=scenario" style="text-shadow: none;"><i class="fa fa-toggle-off"></i> {{Interface simple}}</a> <center> <div class="col-xs-6"> <?php if (config::byKey('enableScenario') == 0) { echo '<a class="btn btn-sm btn-success expertModeVisible" id="bt_changeAllScenarioState" data-state="1" style="margin-top : 3px;text-shadow: none;" ><i class="fa fa-check"></i> {{Act. scénarios}}</a>'; } else { echo '<a class="btn btn-sm btn-danger expertModeVisible" id="bt_changeAllScenarioState" data-state="0" style="margin-top : 3px;text-shadow: none;" ><i class="fa fa-times"></i> {{Désac. scénarios}}</a>'; } ?> </div>
<td style="font-weight : bold;">{{Cron actif}}</td> <?php if (config::byKey('enableCron', 'core', 1, true) == 0) { echo '<td class="alert alert-danger">{{NOK}}</td>'; echo '<td>{{Erreur cron : les crons sont désactivés. Allez dans Général -> Administration -> Moteur de tâches pour les réactiver}}</td>'; } else { echo '<td class="alert alert-success">{{OK}}</td>'; echo '<td></td>'; } ?> </tr> <tr> <td style="font-weight : bold;">{{Scénario actif}}</td> <?php if (config::byKey('enableScenario') == 0 && count(scenario::all()) > 0) { echo '<td class="alert alert-danger">{{NOK}}</td>'; echo '<td>{{Erreur scénario : tous les scénarios sont désactivés. Allez dans Général -> Scénarios pour les réactiver}}</td>'; } else { echo '<td class="alert alert-success">{{OK}}</td>'; echo '<td></td>'; } ?> </tr> <tr> <td style="font-weight : bold;">{{Démarré}}</td> <?php if (!jeedom::isStarted()) { echo '<td class="alert alert-danger">{{NOK}}</td>'; echo '<td></td>';
$cmd = cmd::byId($params['id']); if (!is_object($cmd)) { throw new Exception('Cmd introuvable : ' . $params['id'], -32702); } $jsonrpc->makeSuccess($cmd->getTendance($params['startTime'], $params['endTime'])); } if ($jsonrpc->getMethod() == 'cmd::getHistory') { $cmd = cmd::byId($params['id']); if (!is_object($cmd)) { throw new Exception('Cmd introuvable : ' . $params['id'], -32702); } $jsonrpc->makeSuccess(utils::o2a($cmd->getHistory($params['startTime'], $params['endTime']))); } /* * ************************Scénario*************************** */ if ($jsonrpc->getMethod() == 'scenario::all') { $jsonrpc->makeSuccess(utils::o2a(scenario::all())); } if ($jsonrpc->getMethod() == 'scenario::byId') { $scenario = scenario::byId($params['id']); if (!is_object($scenario)) { throw new Exception('Scenario introuvable : ' . $params['id'], -32703); } $jsonrpc->makeSuccess(utils::o2a($scenario)); } if ($jsonrpc->getMethod() == 'scenario::changeState') { $scenario = scenario::byId($params['id']); if (!is_object($scenario)) { throw new Exception('Scenario introuvable : ' . $params['id'], -32702); } if ($params['state'] == 'stop') { $jsonrpc->makeSuccess($scenario->stop());
public static function changeMode($_mode) { switch ($_mode) { case 'master': if (config::byKey('jeeNetwork::mode') != 'master') { $cron = new cron(); $cron->setClass('history'); $cron->setFunction('historize'); $cron->setSchedule('*/5 * * * * *'); $cron->setTimeout(5); $cron->save(); $cron = new cron(); $cron->setClass('scenario'); $cron->setFunction('check'); $cron->setSchedule('* * * * * *'); $cron->setTimeout(5); $cron->save(); $cron = new cron(); $cron->setClass('cmd'); $cron->setFunction('collect'); $cron->setSchedule('*/5 * * * * *'); $cron->setTimeout(5); $cron->save(); $cron = new cron(); $cron->setClass('history'); $cron->setFunction('archive'); $cron->setSchedule('00 * * * * *'); $cron->setTimeout(20); $cron->save(); config::save('jeeNetwork::mode', 'master'); } break; case 'slave': if (config::byKey('jeeNetwork::mode') != 'slave') { foreach (eqLogic::all() as $eqLogic) { $eqLogic->remove(); } foreach (object::all() as $object) { $object->remove(); } foreach (update::all() as $update) { switch ($update->getType()) { case 'core': break; case 'plugin': try { $plugin = plugin::byId($update->getLogicalId()); if (is_object($plugin) && $plugin->getAllowRemote() != 1) { $update->deleteObjet(); } } catch (Exception $e) { } break; default: $update->deleteObjet(); break; } } foreach (view::all() as $view) { $view->remove(); } foreach (plan::all() as $plan) { $plan->remove(); } foreach (scenario::all() as $scenario) { $scenario->remove(); } foreach (listener::all() as $listener) { $listener->remove(); } $cron = cron::byClassAndFunction('history', 'historize'); if (is_object($cron)) { $cron->remove(); } $cron = cron::byClassAndFunction('scenario', 'check'); if (is_object($cron)) { $cron->remove(); } $cron = cron::byClassAndFunction('cmd', 'collect'); if (is_object($cron)) { $cron->remove(); } $cron = cron::byClassAndFunction('history', 'archive'); if (is_object($cron)) { $cron->remove(); } $user = new user(); $user->setLogin('jeedom_master'); $user->setPassword(config::genKey(255)); $user->setRights('admin', 1); $user->save(); config::save('jeeNetwork::mode', 'slave'); } break; } }