function timerSettings(&$s20Table, $actionValue)
{
    //
    // Implements  the actions selected in the web timer page.
    //
    $actionType = $_POST['actionType'];
    $name = $_POST['name'];
    $mac = getMacFromName($name, $s20Table);
    if ($actionValue == "clearSwitchOff" || $actionValue == "clearCountdown") {
        $h = $m = $s = 0;
        $act = $s20Table[$mac]['st'];
    } else {
        $action = $_POST['action'];
        $h = $_POST['hours'];
        $m = $_POST['minutes'];
        $s = $_POST['seconds'];
        $act = $action == "on" ? 1 : 0;
    }
    $sec = $h * 3600 + $m * 60 + $s;
    if ($actionValue == "clearCountdown" || $actionValue == "setCountdown" && $actionType == "now") {
        //
        // Update regular countdown timer
        //
        // Set
        setTimer($mac, $h, $m, $s, $act, $s20Table);
        // Confirm
        $s20Table[$mac]['timerVal'] = checkTimerSec($mac, $s20Table, $action);
        $s20Table[$mac]['timerAction'] = $action;
        if ($s20Table[$mac]['timerVal'] != $sec || $s20Table[$mac]['timerAction'] != $act) {
            return 1;
        }
    } else {
        //
        // Update automatic switch off after on timer
        //
        if (setSwitchOffTimer($mac, $sec, $s20Table) != $sec) {
            return 1;
        }
    }
    return 0;
}
Exemple #2
0
        error_log("New session: S20 data initialized\n");
    }
}
//
// Check which page must be displayed
//
if ($_SERVER["REQUEST_METHOD"] != "POST") {
    require_once ORVFMS_PATH . "main_page.php";
    displayMainPage($s20Table, $myUrl);
    require_once ORVFMS_PATH . "main_page_scripts.php";
} else {
    if (isset($_POST['toMainPage'])) {
        $actionValue = $_POST['toMainPage'];
        if (substr($actionValue, 0, 7) == "switch_") {
            $switchName = substr($actionValue, 7);
            $mac = getMacFromName($switchName, $s20Table);
            $st = $s20Table[$mac]['st'];
            $newSt = actionAndCheck($mac, $st == 0 ? 1 : 0, $s20Table);
            $s20Table[$mac]['st'] = $newSt;
            $swVal = $s20Table[$mac]['switchOffTimer'];
            if ($st == 0 && $newSt == 1 && $swVal > 0) {
                $s20Table[$mac]['timerVal'] = $swVal;
                $s20Table[$mac]['timerAction'] = 0;
            }
        } else {
            if ($actionValue == "setCountdown" || $actionValue == "clearCountdown" || $actionValue == "clearSwitchOff") {
                require_once ORVFMS_PATH . "timer_settings.php";
                timerSettings($s20Table, $actionValue);
            }
        }
        require_once ORVFMS_PATH . "main_page.php";
Exemple #3
0
    if (DEBUG) {
        error_log("Session restarted; only status update\n");
    }
} else {
    $time_ref = time();
    $s20Table = initS20Data();
    $ndev = count($s20Table);
    $_SESSION["devNumber"] = $ndev;
    $_SESSION["time_ref"] = $time_ref;
    if (DEBUG) {
        error_log("New session: S20 data initialized\n");
    }
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $location = $_POST['selected'];
    $mac = getMacFromName($location, $s20Table);
    $st = $s20Table[$mac]['st'];
    $newSt = actionAndCheck($mac, $st == 0 ? 1 : 0, $s20Table);
    $s20Table[$mac]['st'] = $newSt;
}
$_SESSION["s20Table"] = $s20Table;
$ndevs = count($s20Table);
?>
<center>
<form action="<?php 
echo $myUrl;
?>
" method="post">
<?php 
// Compute button height
$bheight = intval(100 / $ndevs * 0.85);
Exemple #4
0
function sendActionByDeviceName($name, $action, $s20Table)
{
    //
    // Sends an action to device designates with $name
    //
    $mac = getMacFromName($name, $s20Table);
    return actionAndCheck($mac, $action, $s20Table);
}
function delProcess($timerName, $recCode, &$s20Table)
{
    $mac = getMacFromName($timerName, $s20Table);
    delTimer($mac, $recCode, $s20Table);
}
Exemple #6
0
function displayTimerPage($timerName, &$s20Table, $myUrl)
{
    $mac = getMacFromName($timerName, $s20Table);
    $swVal = $s20Table[$mac]['switchOffTimer'];
    $timerVal = $s20Table[$mac]['timerVal'];
    $timerAction = $s20Table[$mac]['timerAction'];
    ?>

<script>
var swVal = <?php 
    echo $swVal;
    ?>
;
var timerVal = <?php 
    echo $timerVal;
    ?>
;
var timerAction = <?php 
    echo $timerAction;
    ?>
;
function setActionOff(){
    var action;
    action = document.getElementById("action1");
    action.checked = true;
}
function checkIfValidOn(){
    var actionType;
    actionType = document.getElementById("actionType2");
    if(actionType.checked == true){
        setActionOff();
    }
}
var timerEnd;
var countDownId;
function displayCountDownTimer(){
    var delta;
    var countDownStr;
    delta = Math.round(timerEnd - new Date().getTime()/1000);
    if(delta < 0){
        clearInterval(countDownId);
        countDownStr = "hh:mm:ss";
        document.getElementById("countDown").style.color = "black";
    }
    else{
        countDownStr = convToString(delta);
        if(timerAction)
            document.getElementById("countDown").style.color = "green";
        else
            document.getElementById("countDown").style.color = "red";
    }
    document.getElementById("countDown").innerHTML = countDownStr;
}
function initTimerPageScripts(){
    document.getElementById("countDown").innerHTML = "hh:mm:ss";
    if(timerVal != 0){
        timerEnd = new Date().getTime()/1000 + timerVal;
        countDownId = setInterval(displayCountDownTimer,1000)
    }
}
</script>

<div style="text-align:center">
<h2> <?php 
    echo $timerName;
    ?>
 </h2>

<hr>

<form action="<?php 
    echo $myUrl;
    ?>
" method="post">
<input type="submit" name="toMainPage" value="back" 
    id="backButton">
<input type="submit" name="toDetailsPage" value="details" 
    id="menuButton">


<div>
Action<br>
  <input id="action1" type="radio" name="action" value="off"  checked>
  <label for="action1"><span><span></span></span>OFF</label>
  <input id="action2" type="radio" name="action" value="on" 
           onClick="checkIfValidOn()"> 
  <label for="action2"><span><span></span></span>ON</label>
<p>
Action type<br>
  <input id="actionType1" type="radio" name="actionType" value="now" checked> 
  <label for="actionType1"><span><span></span></span>Now</label>
  <input id="actionType2" type="radio" name="actionType" value="switchOn" onclick="setActionOff()"> 
  <label for="actionType2"><span><span></span></span>After switch on</label>
    <br>
</div><p>
<div id="countDown"></div>
<div>
<select name="hours">
<?php 
    for ($i = 0; $i < 17; $i++) {
        echo '<option value="' . $i . '">' . $i . '</option>' . "\n";
    }
    ?>
</select>:
<select name="minutes">
<?php 
    for ($i = 0; $i < 60; $i++) {
        echo '<option value="' . $i . '">' . $i . '</option>' . "\n";
    }
    ?>
</select>:
<select name="seconds">
<?php 
    for ($i = 0; $i < 60; $i++) {
        echo '<option value="' . $i . '">' . $i . '</option>' . "\n";
    }
    ?>

    <input type="hidden" name="name" value="<?php 
    echo $timerName;
    ?>
">
</select>
</div>
<p>
<br>
<button type="submit" name="toMainPage" value="setCountdown" 
    id="timerPageButton">Set countdown</button><p>
<button type="submit" name="toMainPage" value="clearCountdown"
    id="timerPageButton">Clear countdown</button><br>

<?php 
    if ($swVal > 0) {
        echo "<hr>";
        $msg = "<p>Automatic switch off timer set to: " . secToHourString($swVal) . "<p>";
        echo $msg;
        ?>
<button type="submit" name="toMainPage" value="clearSwitchOff" id="timerPageButton">
Clear automatic switch off<br>
</button><p><p>        
<?php 
    }
    ?>
</form>
</div>
<script>
    initTimerPageScripts();
</script>
<?php 
}
function displayEditPage($timerName, $editIndex, &$s20Table, $myUrl)
{
    global $daysOfWeek;
    $mac = getMacFromName($timerName, $s20Table);
    $details = $_SESSION['details'];
    $nTimers = count($details);
    $thisTimer = $details[$editIndex];
    ?>

<div style="text-align:center">
<h2> 
<?php 
    echo $timerName;
    echo '<img src="' . IMG_PATH . ($s20Table[$mac]['st'] ? "greenCircle100px.png" : "redCircle100px.png") . '" style="width:0.8em;position:relative;top:0.1em;left:0.3em;">';
    ?>
 
</h2>

<hr>

<?php 
    if ($editIndex < 0) {
        $h = $m = $s = 0;
        $code = "";
        $action = 0;
    } else {
        secToHour($thisTimer['time'], $h, $m, $s);
        $recCode = $thisTimer['recCode'];
        $action = $thisTimer['action'];
    }
    ?>

<div>
<form action="<?php 
    echo $myUrl;
    ?>
" method="post">
    <input type="submit" name="toDetailsPage" value="Back" 
        id="backButton"> 
    <div>hh : mm : ss</div>
<div>
<select name="hours">
<?php 
    for ($i = 0; $i < 24; $i++) {
        if ($i == $h) {
            $selected = ' selected="selected"';
        } else {
            $selected = '';
        }
        echo '<option value="' . $i . '"' . $selected . '>' . $i . '</option>' . "\n";
    }
    ?>
</select>:
<select name="minutes">
<?php 
    for ($i = 0; $i < 60; $i++) {
        if ($i == $m) {
            $selected = ' selected="selected"';
        } else {
            $selected = '';
        }
        echo '<option value="' . $i . '"' . $selected . '>' . $i . '</option>' . "\n";
    }
    ?>
</select>:
<select name="seconds">
<?php 
    for ($i = 0; $i < 60; $i++) {
        if ($i == $s) {
            $selected = ' selected="selected"';
        } else {
            $selected = '';
        }
        echo '<option value="' . $i . '"' . $selected . '>' . $i . '</option>' . "\n";
    }
    ?>


</select>
</div>
<p>
<p>


<div>
Action<br>
<input id="action1" type="radio" name="detailAction" value="0" <?php 
    if ($action == 0) {
        echo "checked";
    }
    ?>
>
  <label for="action1"><span><span></span></span>OFF</label>
  <input id="action2" type="radio" name="detailAction" value="1" <?php 
    if ($action == 1) {
        echo "checked";
    }
    ?>
> 
  <label for="action2"><span><span></span></span>ON</label>
</div><p>
<p>
<hr>
<h2>Repeat every:</h2>
<div class="editDetail">

<?php 
    $bits = $thisTimer['r'];
    for ($k = 0; $k < 7; $k++) {
        $bit = (int) $bits % 2;
        $bits = (int) ($bits / 2);
        echo '<div class="rowDetail">';
        echo '<div class="weekDayCol">';
        echo $daysOfWeek[$k];
        echo '</div>';
        ?>
      <div class="checkBoxCol">
      <input type="checkbox" id="weekday<?php 
        echo $k;
        ?>
" 
        name="weekday<?php 
        echo $k;
        ?>
"  <?php 
        if ($bit == 1) {
            echo "checked";
        }
        ?>
 onclick="updateAllFunc()" > 
      <label for="weekday<?php 
        echo $k;
        ?>
" ><span></span></label>        
      </div>
      </div>
<?php 
    }
    ?>
 <p>
 <div class="rowDetail">
   <div class="weekDayCol"> Everyday </div>
   <div class="checkBoxCol">
      <input type="checkbox" id="setAll" onclick="setAllFunc()">       <label for="setAll"><span></span></label>        
   </div>
 </div>
 <div class="rowDetail">
   <div class="weekDayCol"> Once </div>
   <div class="checkBoxCol">
      <input type="checkbox" id="clearAll" onclick="clearAllFunc()">       <label for="clearAll"><span></span></label>        
   </div>
 </div>
</div>
<hr>
<button type="submit" name="toDetailsPage" value="updateOrAdd" id="doneButton">Done</button>
<input type="hidden" name="name" value="<?php 
    echo $timerName;
    ?>
">
<input type="hidden" name="recCode" value="<?php 
    echo $recCode;
    ?>
">
</form>
<script>
updateAllFunc();
</script>
<?php 
}
function displayDetailsPage($timerName, &$s20Table, $myUrl)
{
    global $daysOfWeek;
    $mac = getMacFromName($timerName, $s20Table);
    ?>


<div style="text-align:center">
<h2> <?php 
    echo $timerName;
    ?>
 </h2>


<hr>
<?php 
    $allTimers = getAndParseTimerTable($mac, $s20Table);
    $_SESSION['details'] = $allTimers;
    $nTimers = count($allTimers);
    echo '<form action="' . $myUrl . '" method="post">';
    ?>
    <input type="submit" name="toMainPage" value="Back" 
        id="backButton"> 
    <button type="submit" name="toEditPage" value="add" 
        id="addButton" >Add</button>

<?php 
    echo '<div class="details">' . "\n";
    for ($i = 0; $i < $nTimers; $i++) {
        echo '<div class="row">';
        $details = $allTimers[$i];
        $hour = secToHourString($details['time']);
        echo '<div class="hour">' . $hour . '</div>';
        echo '<div class="editCol">';
        echo '<button type="submit" name="toEditPage" value="edit' . $i . '" 
                  id="editButton">Edit</button>';
        echo '</div>';
        echo '<div class="onoff">';
        echo $details['st'] ? "on " : "off";
        echo '<img src="' . IMG_PATH . ($details['st'] ? "greenCircle100px.png" : "redCircle100px.png") . '" style="width:0.8em;position:relative;top:0.1em;left:0.3em;">';
        echo '</div>';
        $bits = $details['r'];
        //        echo $details['r']." ".$bits." ";
        $first = 1;
        echo '<div class="daysOfWeek">';
        for ($k = 0; $k < 7; $k++) {
            $bit = $bits % 2;
            $bits = (int) ($bits / 2);
            if ($bit) {
                if (!$first) {
                    echo ",";
                }
                echo substr($daysOfWeek[$k], 0, 2);
                $first = 0;
            }
        }
        // echo " :".$details['recCode'];
        echo "</div>";
        echo '<div class="delCol">';
        echo '<button type="submit" name="toDetailsPage" value="del_' . $details['recCode'] . '" 
                  id="delButton">Delete</button>';
        echo "</div>\n";
        echo "</div>\n";
    }
    echo "</div>\n";
    echo '<input type="hidden" name="name" value="' . $timerName . '">';
    echo "<p><p><p>";
    echo '<button type="submit" name="toMainPage" value="done" id="doneButton">Done</button>';
    echo "</form>\n";
    ?>

<?php 
}