Example #1
0
    }
}
echo '</div>';
?>
</div>
<?php 
if ($_SESSION['user']->getOptions('displayScenarioByDefault') == 1) {
    echo '<div class="col-lg-2 col-md-2 col-sm-3" id="div_displayScenario">';
} else {
    echo '<div class="col-lg-2 col-md-2 col-sm-3" id="div_displayScenario" style="display:none;">';
}
?>
<legend><i class="fa fa-history"></i> {{Scénarios}}</legend>
<?php 
if (init('object_id') == '') {
    foreach (scenario::byObjectId(null, false, true) as $scenario) {
        echo $scenario->toHtml('dashboard');
    }
}
foreach ($object->getScenario(false, true) as $scenario) {
    echo $scenario->toHtml('dashboard');
}
foreach ($child_object as $child) {
    foreach ($child->getScenario(false, true) as $scenario) {
        echo $scenario->toHtml('dashboard');
    }
}
?>
</div>
</div>
Example #2
0
            $dataStore = new dataStore();
            $dataStore->setKey(init('key'));
            $dataStore->setLink_id(init('link_id'));
            $dataStore->setType(init('type'));
        } else {
            $dataStore = dataStore::byId(init('id'));
        }
        if (!is_object($dataStore)) {
            throw new Exception(__('Data store inconnu vérifer l\'id : ', __FILE__) . init('id'));
        }
        $dataStore->setValue(init('value'));
        $dataStore->save();
        ajax::success();
    }
    if (init('action') == 'all') {
        $datastores = utils::o2a(dataStore::byTypeLinkId(init('type')));
        if (init('usedBy') == 1) {
            foreach ($datastores as &$datastore) {
                $datastore['usedBy'] = array('scenario' => array());
                foreach (scenario::byUsedCommand($datastore['key'], true) as $scenario) {
                    $datastore['usedBy']['scenario'][] = $scenario->getHumanName();
                }
            }
        }
        ajax::success($datastores);
    }
    throw new Exception(__('Aucune methode correspondante à : ', __FILE__) . init('action'));
    /*     * *********Catch exeption*************** */
} catch (Exception $e) {
    ajax::error(displayExeption($e), $e->getCode());
}
<?php

if (!isConnect()) {
    throw new Exception('{{401 - Accès non autorisé}}');
}
$scenario = scenario::byId(init('scenario_id'));
if (!is_object($scenario)) {
    throw new Exception(__('Aucun scénario ne correspondant à : ', __FILE__) . init('scenario_id'));
}
sendVarToJs('scenarioLog_scenario_id', init('scenario_id'));
?>
<div style="display: none;width : 100%" id="div_alertScenarioLog"></div>
<a class="btn btn-danger pull-right" id="bt_scenarioLogEmpty"><i class="fa fa-trash"></i> {{Vider les logs}}</a>
<a class="btn btn-success pull-right" id="bt_scenarioLogDownload"><i class="fa fa-cloud-download"></i> {{Télécharger}}</a>
<a class="btn btn-primary pull-right" id="bt_scenarioLogRefresh"><i class="fa fa-refresh"></i> {{Rafraîchir}}</a>
<br/><br/>
<?php 
if (file_exists(dirname(__FILE__) . '/../../log/scenarioLog/scenario' . init('scenario_id') . '.log')) {
    echo '<pre id="pre_logScenarioDisplay">' . trim(file_get_contents(dirname(__FILE__) . '/../../log/scenarioLog/scenario' . init('scenario_id') . '.log')) . '</pre>';
} else {
    echo "{{Aucun log n'existe pour votre scénario : }}" . dirname(__FILE__) . '/../../log/scenarioLog/scenario' . init('scenario_id') . '.log.';
}
?>
<script>
    $('#bt_scenarioLogEmpty').on('click', function () {
     jeedom.scenario.emptyLog({
        id: <?php 
echo init('scenario_id');
?>
,
        error: function (error) {
Example #4
0
     $return['reply'] = $reply;
 }
 if ($interactQuery->getLink_type() == 'whatDoYouKnow') {
     $object = object::byId($interactQuery->getLink_id());
     if (is_object($object)) {
         $reply = interactQuery::whatDoYouKnow($object);
         if (trim($reply) == '') {
             $return['reply'] = __('Je ne sais rien sur ', __FILE__) . $object->getName();
         }
         $return['reply'] = $reply;
     }
     $return['reply'] = interactQuery::whatDoYouKnow();
 }
 if ($interactQuery->getLink_type() == 'scenario') {
     $return['scenario'] = '';
     $scenario = scenario::byId($interactQuery->getLink_id());
     if (!is_object($scenario)) {
         $return['scenario'] = __('Impossible de trouver le scénario correspondant', __FILE__);
     }
     $return['scenario'] = '#' . $scenario->getHumanName() . '#';
     switch ($interactDef->getOptions('scenario_action')) {
         case 'start':
             $return['action'] = __('lancer', __FILE__);
             break;
         case 'stop':
             $return['action'] = __('arrêter', __FILE__);
             break;
         case 'activate':
             $return['action'] = __('activer', __FILE__);
             break;
         case 'deactivate':
Example #5
0
     throw new Exception(__('401 - Accès non autorisé', __FILE__));
 }
 $time_dependance = 0;
 $time_keyword = array('#time#', '#seconde#', '#heure#', '#minute#', '#jour#', '#mois#', '#annee#', '#timestamp#', '#date#', '#semaine#', '#sjour#', '#njour#', '#smois#');
 foreach ($time_keyword as $keyword) {
     if (strpos(init('scenario'), $keyword) !== false) {
         $time_dependance = 1;
         break;
     }
 }
 $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);
     }
Example #6
0
 public function getScenario($_onlyEnable = true, $_onlyVisible = false)
 {
     return scenario::byObjectId($this->getId(), $_onlyEnable, $_onlyVisible);
 }
Example #7
0
<?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>
Example #8
0
 public function getUsedBy()
 {
     $return = array();
     $return['cmd'] = self::searchConfiguration('#' . $this->getId() . '#');
     $return['eqLogic'] = eqLogic::searchConfiguration('#' . $this->getId() . '#');
     $return['scenario'] = scenario::byUsedCommand($this->getId());
     $return['interact'] = interactDef::byUsedCommand($this->getId());
     return $return;
 }
Example #9
0
			<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>';
Example #10
0
 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;
 }
Example #11
0
     }
     $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());
     }
     if ($params['state'] == 'run') {
         $jsonrpc->makeSuccess($scenario->launch(false, __('Scénario exécuté sur appel API', __FILE__)));
     }
     if ($params['state'] == 'enable') {
         $scenario->setIsActive(1);
         $jsonrpc->makeSuccess($scenario->save());
     }
     if ($params['state'] == 'disable') {
         $scenario->setIsActive(0);
 /**
  * Format le Widget "gCalendar"
  * @return void
  */
 public function toHtml($_version)
 {
     log::add('gCalendar', 'debug', '[' . $this->getId() . '] toHtml(' . $_version . ') start ...');
     // utilisation du widget "standard" jeedom //
     if ($this->getConfiguration('widgetOther') == '1') {
         log::add('gCalendar', 'debug', '[' . $this->getId() . '] toHtml(' . $_version . ') use jeedom widget (no plugin widget).');
         return parent::toHtml($_version);
     }
     // utilisation du widget du plugin //
     $_version = jeedom::versionAlias($_version);
     $mc = cache::byKey('gcalendarWidget' . $_version . $this->getId());
     if ($mc->getValue() != '') {
         log::add('gCalendar', 'debug', '[' . $this->getId() . '] toHtml(' . $_version . ') aborded !');
         return $mc->getValue();
     }
     $_sToday = $this->getConfiguration('hideDateDashboard') == 1 ? '' : __("aujourd'hui", __FILE__) . " : " . $this->getToday();
     $replace = array('#id#' => $this->getId(), '#name#' => $this->getIsEnable() ? $this->getName() : '<del>' . $this->getName() . '</del>', '#background_color#' => $this->getBackgroundColor($_version), '#today#' => $_version == 'mobile' ? date('d') : $_sToday, '#gCalArray#' => '0');
     if ($_version != 'mobile') {
         $replace['#eqLink#'] = $this->getLinkToConfiguration();
         $replace['#refreshDate#'] = !empty($this->_sRefreshDate) ? $this->_sRefreshDate : date('Y-m-d H:i:s');
         $replace['#txtView#'] = __("affichage", __FILE__);
         $replace['#txtGotoAG#'] = __("voir Agenda Google", __FILE__);
         $replace['#txtDay#'] = __("journée", __FILE__);
         $replace['#txtNextHour#'] = __("prochaine heure", __FILE__);
         $replace['#txtNow#'] = __("instantané", __FILE__);
     }
     // action sur l'affichage du nom //
     if (($_version == 'dview' || $_version == 'mview') && $this->getDisplay('doNotShowNameOnView') == 1) {
         $replace['#name#'] = '';
     }
     if ($_version == 'dashboard' && $this->getDisplay('doNotShowNameOnDashboard') == 1) {
         $replace['#name#'] = '';
     }
     if ($_version == 'mobile' && $this->getDisplay('doNotShowNameOnMobile') == 1) {
         $replace['#name#'] = '';
     }
     // pour chaque calendrier du widget //
     // tableau JS >> 0:nom jeedom / 1:type de vue / 2:date de mise à jour / 3:valeur affichée / 4:titre google / 5:url / 6:nb évènement //
     $nbCalRefresh = 0;
     foreach ($this->getCmd('info') as $cmdGCal) {
         if ($cmdGCal->getIsVisible()) {
             if (($_sEvents = $cmdGCal->execCmd()) != '') {
                 // génère le format en fonction de la vue //
                 if ($cmdGCal->getConfiguration('viewStyle') != 'current_titleOnly') {
                     $_aEvents = explode('||', $_sEvents);
                     $nbEvent = $cmdGCal->getConfiguration('defaultValue', GCALENDAR_TXT_DV) != $_sEvents ? count($_aEvents) : 0;
                     if ($nbEvent > 0) {
                         // pour chaque événement //
                         for ($i = 0; $i < count($_aEvents); $i++) {
                             $_aOneEvent = explode(';', $_aEvents[$i]);
                             // définit les valeurs à afficher : heure //
                             $_sEventHours = "<span class='gCalendar_hour'>(" . $_aOneEvent[0] . "-" . $_aOneEvent[1] . ")</span>";
                             if ($cmdGCal->getConfiguration('showHour') == 0) {
                                 $_sEventHours = "";
                             } else {
                                 if ($cmdGCal->getConfiguration('showHour24H') == 0 && $_aOneEvent[0] == "00:00" && $_aOneEvent[1] == "23:59") {
                                     $_sEventHours = "";
                                 }
                             }
                             // état //
                             if ($_aOneEvent[2] == 'DA') {
                                 $_sEventState = " <i class='fa fa-plus-circle' title='" . __('évènement actif: 1ère minute', __FILE__) . "' style='color:#FF0000;'></i>";
                             } elseif ($_aOneEvent[2] == 'FA') {
                                 $_sEventState = " <i class='fa fa-ban' title='" . __('évènement actif: dernière minute', __FILE__) . "' style='color:#FF0000;'></i>";
                             } elseif ($_aOneEvent[2] == 'A') {
                                 $_sEventState = " <i class='fa fa-check-circle-o' title='" . __('évènement actif', __FILE__) . "' style='color:#0000FF;'></i>";
                             } else {
                                 $_sEventState = "";
                             }
                             // titre //
                             $_sEventTxt = $_aOneEvent[3];
                             // gestion des scénarios //
                             if ($this->getConfiguration('acceptLaunchSc') == '1') {
                                 if ($_aOneEvent[4] == 'S' && $_aOneEvent[3] >= 1) {
                                     $_oSc = scenario::byId($_aOneEvent[3]);
                                     //log::add('gCalendar', 'debug', '[' . $this->getId() . '] toHtml() object scenario='.print_r($_oSc,true));
                                     if ($_oSc !== false) {
                                         $_aOneEvent[5] = $_aOneEvent[5] != '' ? ' (' . $_aOneEvent[5] . ')' : '';
                                         $_aOneEvent[7] = $_aOneEvent[7] != '' ? __('1er min', __FILE__) . '=' . $_aOneEvent[7] . ' | ' : '';
                                         $_aOneEvent[8] = $_aOneEvent[8] != '' ? __('dern. min', __FILE__) . '=' . $_aOneEvent[8] : '';
                                         if ($_version == 'mobile') {
                                             $_sIcon = "<i class='fa fa-cogs'></i> ";
                                         } else {
                                             $_sIcon = "<a href='index.php?v=d&p=scenario&id=" . $_aOneEvent[3] . "'><i class='fa fa-cogs' title='" . __('éditer le scénario', __FILE__) . "'></i></a> ";
                                         }
                                         $_sEventTxt = $_sIcon . '<span title="' . $_aOneEvent[7] . $_aOneEvent[8] . '">' . $_oSc->getName() . '</span>' . $_aOneEvent[5];
                                     } else {
                                         log::add('gCalendar', 'error', '[' . $this->getId() . '|' . $cmdGCal->getId() . '] toHtml().sc=' . $_aOneEvent[3] . ' ' . __("l'id du scénario n'existe pas, merci de vérifier.", __FILE__));
                                     }
                                 } else {
                                     $_sEventTxt = str_replace('{ERR}', "<span title='" . __('Erreur dans le format de la trame', __FILE__) . "'>{ERR}</span>", $_aOneEvent[3]);
                                 }
                             } else {
                                 // titre //
                                 if ($_aOneEvent[4] == 'S') {
                                     $_sEventTxt = 'sc=' . $_aOneEvent[3] . ';' . $_aOneEvent[5] . ';' . $_aOneEvent[6] . ';' . $_aOneEvent[7] . ';' . $_aOneEvent[8];
                                 }
                             }
                             if ($_version == 'mobile') {
                                 if ($_aOneEvent[2] == 'P') {
                                     $_aEvents[$i] = '';
                                     $nbEvent--;
                                 } else {
                                     $_aEvents[$i] = "<div class='gCalendar_itemActif'>" . $_sEventHours . $_sEventState . " " . $_sEventTxt . "</div>";
                                 }
                             } else {
                                 if ($i < count($_aEvents) - 1) {
                                     $_sBorder = 'border-bottom:1px solid #DDDDDD;';
                                 } else {
                                     $_sBorder = '';
                                 }
                                 if ($_aOneEvent[2] == 'P') {
                                     $_aEvents[$i] = "<div class='gCalendar_itemInactif' style='font-style:italic;color:#BBBBBB;" . $_sBorder . "'>" . $_sEventHours . $_sEventState . " " . $_sEventTxt . "</div>";
                                 } else {
                                     $_aEvents[$i] = "<div class='gCalendar_itemActif' style='" . $_sBorder . "'>" . $_sEventHours . $_sEventState . " " . $_sEventTxt . "</div>";
                                 }
                             }
                         }
                         $_sEvents = implode('', $_aEvents);
                     } else {
                         if ($_version == 'mobile') {
                             $_sEvents = "<div class='gCalendar_itemInactif'>" . $_sEvents . "</div>";
                         } else {
                             $_sEvents = "<span class='gCalendar_itemInactif'>" . $_sEvents . "</span>";
                         }
                     }
                 } else {
                     $nbEvent = $cmdGCal->getConfiguration('defaultValue', GCALENDAR_TXT_DV) != $_sEvents ? count(explode(' - ', $_sEvents)) : 0;
                     if ($_version == 'mobile') {
                         $_sEvents = "<div class='gCalendar_itemActif'>" . $_sEvents . "</div>";
                     } else {
                         $_sEvents = "<div class='gCalendar_itemActif'>" . $_sEvents . "</div>";
                     }
                 }
                 $_sEvents = str_replace('"', '\\"', $_sEvents);
                 $replace['#gCalArray#'] .= ',["' . str_replace('"', '\\"', $cmdGCal->getName()) . '", "' . $cmdGCal->getConfiguration('viewStyle') . '", "' . $cmdGCal->getCollectDate() . '", "' . $_sEvents . '", "' . str_replace('"', '\\"', $cmdGCal->getConfiguration('_sGCalTitle')) . '", "' . str_replace('"', '\\"', $cmdGCal->getConfiguration('_sGCalUrlCalendar')) . '", "' . $nbEvent . '"]';
                 $nbCalRefresh++;
             }
         }
     }
     $parameters = $this->getDisplay('parameters');
     if (is_array($parameters)) {
         foreach ($parameters as $key => $value) {
             $replace['#' . $key . '#'] = $value;
         }
     }
     log::add('gCalendar', 'debug', '[' . $this->getId() . '] toHtml().replace=' . print_r($replace, true));
     $html = template_replace($replace, getTemplate('core', $_version, 'gCalendar', 'gCalendar'));
     cache::set('gcalendarWidget' . $_version . $this->getId(), $html, 0);
     log::add('gCalendar', 'info', '[' . $this->getId() . '] toHtml(' . $_version . ') Refresh Widget (' . $nbCalRefresh . ' cal.): OK');
     return $html;
 }
// Creer 2 variables (General / Scenarios / Voir Variables / Ajouter)
// SPARK_ID : L'id de votre spark
// SPARK_TOKEN : Votre token
//
// Créer un script puis une commande d'info, type script, sous type numerique.
// Cliquer sur nouveau
// Copier / Coller ce script
// Enregistrer
// Le chemin du script apparait dans le champ requete, a jouter a la fin le numéro du fil pilote a cheker :
// ex Fil pilote 1 : /chemin vers le script/etatFP.php 1
// =========================================================================
// Plus rien a modifier en dessous de cette ligne.
require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php';
// Declaration des variables :
$core = scenario::getData("SPARK_ID");
$token = scenario::getData("SPARK_TOKEN");
// Let's Go !
//recuperation de l'argument du cFP
$fp = $argv[1];
//Attention tableu commence à 0 :
$fp = $fp - 1;
//initialisation de la requete :
//URL of targeted site
$url = "https://api.spark.io/v1/devices/{$core}/etatfp?access_token={$token}";
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$output = curl_exec($ch);
 public function getScenario()
 {
     $scenario = scenario::byElement($this->getId());
     if (is_object($scenario)) {
         return $scenario;
     }
     $expression = scenarioExpression::byElement($this->getId());
     if (is_object($expression)) {
         return $expression->getSubElement()->getElement()->getScenario();
     }
     return null;
 }
Example #15
0
 public function executeAndReply($_parameters)
 {
     $interactDef = interactDef::byId($this->getInteractDef_id());
     if (!is_object($interactDef)) {
         return __('Inconsistance de la base de données', __FILE__);
     }
     if (isset($_parameters['profile']) && trim($interactDef->getPerson()) != '') {
         $person = strtolower($interactDef->getPerson());
         $person = explode('|', $person);
         if (!in_array($_parameters['profile'], $person)) {
             return __('Vous n\'êtes pas autorisé à exécuter cette action', __FILE__);
         }
     }
     if ($this->getLink_type() == 'whatDoYouKnow') {
         $object = object::byId($this->getLink_id());
         if (is_object($object)) {
             $reply = self::whatDoYouKnow($object);
             if (trim($reply) == '') {
                 return __('Je ne sais rien sur ', __FILE__) . $object->getName();
             }
             return $reply;
         }
         return self::whatDoYouKnow();
     }
     if ($this->getLink_type() == 'scenario') {
         $scenario = scenario::byId($this->getLink_id());
         if (!is_object($scenario)) {
             return __('Impossible de trouver le scénario correspondant', __FILE__);
         }
         log::add('interact', 'debug', 'Execution du scénario : ' . $scenario->getHumanName() . ' => ' . $interactDef->getOptions('scenario_action'));
         $interactDef = $this->getInteractDef();
         if (!is_object($interactDef)) {
             return __('Impossible de trouver la définition de l\'interaction', __FILE__);
         }
         $reply = $interactDef->selectReply();
         if (trim($reply) == '') {
             $reply = self::replyOk();
         }
         $replace = array();
         $replace['#profile#'] = isset($_parameters['profile']) ? $_parameters['profile'] : '';
         $reply = scenarioExpression::setTags(str_replace(array_keys($replace), $replace, $reply));
         switch ($interactDef->getOptions('scenario_action')) {
             case 'start':
                 $scenario->setTags(array('#query#' => $this->getQuery(), '#profile#' => $replace['#profile#']));
                 $return = $scenario->launch(false, 'interact', __('Scénario exécuté sur interaction (S.A.R.A.H, SMS...)', __FILE__), 1);
                 if (is_string($return) && $return != '') {
                     $return = str_replace(array_keys($replace), $replace, $return);
                     return $return;
                 }
                 return $reply;
             case 'stop':
                 $scenario->stop();
                 return $reply;
             case 'activate':
                 $scenario->setIsActive(1);
                 $scenario->save();
                 return $reply;
             case 'deactivate':
                 $scenario->setIsActive(0);
                 $scenario->save();
                 return $reply;
             default:
                 return __('Aucune action n\'est définie dans l\'interaction sur le scénario : ', __FILE__) . $scenario->getHumanName();
         }
     }
     $reply = $interactDef->selectReply();
     $synonymes = array();
     if ($interactDef->getOptions('synonymes') != '') {
         foreach (explode('|', $interactDef->getOptions('synonymes')) as $value) {
             $values = explode('=', $value);
             $synonymes[strtolower($values[0])] = explode(',', $values[1]);
         }
     }
     $replace = array();
     $replace['#profile#'] = isset($_parameters['profile']) ? $_parameters['profile'] : '';
     if ($this->getLink_type() == 'cmd') {
         foreach (explode('&&', $this->getLink_id()) as $cmd_id) {
             $cmd = cmd::byId($cmd_id);
             if (!is_object($cmd)) {
                 continue;
             }
             $replace['#commande#'] = $cmd->getName();
             if (isset($synonymes[strtolower($cmd->getName())])) {
                 $replace['#commande#'] = $synonymes[strtolower($cmd->getName())][rand(0, count($synonymes[strtolower($cmd->getName())]) - 1)];
             }
             $replace['#objet#'] = '';
             $replace['#equipement#'] = '';
             $eqLogic = $cmd->getEqLogic();
             if (is_object($eqLogic)) {
                 $replace['#equipement#'] = $eqLogic->getName();
                 $object = $eqLogic->getObject();
                 if (is_object($object)) {
                     $replace['#objet#'] = $object->getName();
                 }
             }
             $replace['#unite#'] = $cmd->getUnite();
             if ($cmd->getType() == 'action') {
                 $options = null;
                 if ($cmd->getSubType() == 'slider') {
                     preg_match_all("/([0-9]*)/", $_parameters['dictation'], $matches);
                     foreach ($matches[1] as $number) {
                         if (is_numeric($number)) {
                             $options['slider'] = $number;
                         }
                     }
                 }
                 if ($cmd->getSubType() == 'color') {
                     $colors = config::byKey('convertColor');
                     foreach (explode(' ', $_parameters['dictation']) as $word) {
                         if (isset($colors[strtolower($word)])) {
                             $options['color'] = $colors[strtolower($word)];
                         }
                     }
                 }
                 try {
                     log::add('interact', 'debug', 'Execution de la commande : ' . $cmd->getHumanName() . ' => ' . print_r($options, true));
                     if ($cmd->execCmd($options) === false) {
                         return __('Impossible d\'exécuter la commande', __FILE__);
                     }
                 } catch (Exception $exc) {
                     return $exc->getMessage();
                 }
                 if ($options != null) {
                     foreach ($options as $key => $value) {
                         $replace['#' . $key . '#'] = $value;
                     }
                 }
             }
             if ($cmd->getType() == 'info') {
                 $value = $cmd->execCmd();
                 if ($value === null) {
                     return __('Impossible de récupérer la valeur de la commande', __FILE__);
                 } else {
                     $replace['#valeur#'] = $value;
                     if ($cmd->getSubType() == 'binary' && $interactDef->getOptions('convertBinary') != '') {
                         $convertBinary = $interactDef->getOptions('convertBinary');
                         $convertBinary = explode('|', $convertBinary);
                         $replace['#valeur#'] = $convertBinary[$replace['#valeur#']];
                     }
                 }
             }
         }
     }
     return scenarioExpression::setTags(str_replace(array_keys($replace), $replace, $reply));
 }
Example #16
0
				<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">
Example #18
0
 public static function fromHumanReadable($_input)
 {
     return scenario::fromHumanReadable(eqLogic::fromHumanReadable(cmd::humanReadableToCmd($_input)));
 }
Example #19
0
 public function toHtml($_version)
 {
     if (!$this->hasRight('r')) {
         return '';
     }
     $sql = 'SELECT `value` FROM cache
 WHERE `key`="scenarioHtml' . $_version . $this->getId() . '"';
     $result = DB::Prepare($sql, array(), DB::FETCH_TYPE_ROW);
     if ($result['value'] != '') {
         return $result['value'];
     }
     $_version = jeedom::versionAlias($_version);
     $replace = array('#id#' => $this->getId(), '#state#' => $this->getState(), '#isActive#' => $this->getIsActive(), '#name#' => $this->getDisplay('name') != '' ? $this->getDisplay('name') : $this->getHumanName(), '#icon#' => $this->getIcon(), '#lastLaunch#' => $this->getLastLaunch(), '#scenarioLink#' => $this->getLinkToConfiguration());
     if (!isset(self::$_templateArray)) {
         self::$_templateArray = array();
     }
     if (!isset(self::$_templateArray[$_version])) {
         self::$_templateArray[$_version] = getTemplate('core', $_version, 'scenario');
     }
     $html = template_replace($replace, self::$_templateArray[$_version]);
     cache::set('scenarioHtml' . $_version . $this->getId(), $html, 0);
     return $html;
 }
Example #20
0
 public function export()
 {
     $return = '';
     if ($this->getType() == 'element') {
         $element = scenarioElement::byId($this->getExpression());
         if (is_object($element)) {
             $exports = explode("\n", $element->export());
             foreach ($exports as $export) {
                 $return .= "    " . $export . "\n";
             }
         }
         return rtrim($return);
     }
     $options = $this->getOptions();
     if ($this->getType() == 'action') {
         if ($this->getExpression() == 'icon') {
             return '';
         } else {
             if ($this->getExpression() == 'sleep') {
                 return '(sleep) Pause de  : ' . $options['duration'];
             } else {
                 if ($this->getExpression() == 'stop') {
                     return '(stop) Arret du scenario';
                 } else {
                     if ($this->getExpression() == 'scenario') {
                         $actionScenario = scenario::byId($this->getOptions('scenario_id'));
                         if (is_object($actionScenario)) {
                             return '(scenario) ' . $this->getOptions('action') . ' de ' . $actionScenario->getHumanName();
                         }
                     } else {
                         if ($this->getExpression() == 'variable') {
                             return '(variable) Affectation de la variable : ' . $this->getOptions('name') . ' à ' . $this->getOptions('value');
                         } else {
                             $return = jeedom::toHumanReadable($this->getExpression());
                             if (is_array($options) && count($options) != 0) {
                                 $return .= ' - Options : ' . print_r(jeedom::toHumanReadable($options), true);
                             }
                             return $return;
                         }
                     }
                 }
             }
         }
     } else {
         if ($this->getType() == 'condition') {
             return jeedom::toHumanReadable($this->getExpression());
         }
     }
     if ($this->getType() == 'code') {
     }
 }
Example #21
0
 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;
     }
 }