Example #1
0
function displaySetupPage($mac, &$s20Table, $myUrl)
{
    global $daysOfWeek;
    $devData = $s20Table[$mac];
    $timerName = $devData['name'];
    ?>

<div style="text-align:center">
<h2> 
<form action="<?php 
    echo $myUrl;
    ?>
" method="post">
<?php 
    if (array_key_exists('off', $s20Table[$mac])) {
        echo $timerName;
        $mayEdit = 0;
    } else {
        $mayEdit = 1;
        ?>

        <input type = "text" name="newName" value="<?php 
        echo $timerName;
        ?>
" id="inputName">
<?php 
    }
    if (isset($devData['st']) && $devData['st'] >= 0 && !array_key_exists('off', $s20Table[$mac])) {
        $stDisplay = $devData['st'] ? "greenCircle100px.png" : "redCircle100px.png";
        echo '<img src="' . IMG_PATH . $stDisplay . '" style="width:0.8em;position:relative;top:0.1em;left:0.3em;">';
    }
    $nnext = $devData['next'];
    if ($mayEdit) {
        echo '<br><div id="mayEdit">Socket name above is editable</div>';
    }
    ?>
 
</h2>
<p>
<hr>





    <input type="submit" name="toMainPage" value="back<?php 
    echo $mac;
    ?>
"  
    id="backButton"> 

<?php 
    if (!array_key_exists('off', $s20Table[$mac])) {
        ?>

<div>
        Number of next events displayed in main page for this timer: 
<select name="numberOfNextEvents">        
<?php 
        for ($i = 0; $i < 8; $i++) {
            echo '<option value="' . $i . '"' . ($nnext == $i ? ' selected="selected"' : ' ') . '>' . $i . '</option>' . "\n";
        }
        ?>
</select>

<p>




<p>

<button type="submit" name="toMainPage" value="procSetup<?php 
        echo $mac;
        ?>
" id="doneButton">Done</button>



<div style="margin-top:10vh;">
<hr>
Delete device from the system<p>
<button type="submit" name="toMainPage" value="procSetupDel<?php 
        echo $mac;
        ?>
" id="deleteButton">Delete device</button>
<hr>
</div>
<?php 
    } else {
        $inactiveTimeStamp = $s20Table[$mac]['off'];
        $inactiveString = gmdate("D M j G:i:s T Y", $inactiveTimeStamp);
        $now = time();
        $delta = $now - $inactiveTimeStamp;
        $deltaString = secToHourString($delta);
        $msg = "This device is inactive since " . $inactiveString;
        $msg = $msg . " (" . $deltaString . "s ago)<p>";
        $msg = $msg . "It did not reply to a re-activate command. Is it connected and on-line?<p>";
        echo $msg;
        ?>
<hr>
<button type="submit" name="toMainPage" value="procSetupDel<?php 
        echo $mac;
        ?>
" id="deleteButton">Delete device</button>
<p>
<button type="submit" name="toMainPage" value="procSetupCancel<?php 
        echo $mac;
        ?>
" id="cancelButton">Cancel</button>


<?php 
    }
    ?>
</form>

</div>

<?php 
}
Example #2
0
function displaySetupPage($mac, &$s20Table, $myUrl)
{
    global $daysOfWeek;
    $devData = $s20Table[$mac];
    $timerName = $devData['name'];
    ?>

<div style="text-align:center">
<h2> 
<form action="<?php 
    echo $myUrl;
    ?>
" method="post">
<?php 
    if (array_key_exists('off', $s20Table[$mac])) {
        echo $timerName;
        $isActive = 0;
    } else {
        $isActive = 1;
        ?>

        <input type = "text" name="newName" value="<?php 
        echo $timerName;
        ?>
" id="inputName">
<?php 
    }
    if (isset($devData['st']) && $devData['st'] >= 0 && !array_key_exists('off', $s20Table[$mac])) {
        $stDisplay = $devData['st'] ? "greenCircle100px.png" : "redCircle100px.png";
        echo '<img src="' . IMG_PATH . $stDisplay . '" style="width:0.8em;position:relative;top:0.1em;left:0.3em;">';
    }
    $nnext = $devData['next'];
    if ($isActive) {
        echo '<br><div id="mayEdit">Socket name above is editable</div>';
    }
    ?>
 
</h2>
<p>
<hr>





    <input type="submit" name="toMainPage" value="back<?php 
    echo $mac;
    ?>
"  
    id="backButton"> 

<?php 
    if ($isActive) {
        ?>

<div>
        Number of next events displayed in main page for this timer: 
<select name="numberOfNextEvents">        
<?php 
        for ($i = 0; $i < 8; $i++) {
            echo '<option value="' . $i . '"' . ($nnext == $i ? ' selected="selected"' : ' ') . '>' . $i . '</option>' . "\n";
        }
        ?>
</select>

<p>
<hr>
<?php 
        $ip = getIpFromMac($mac, $s20Table);
        $dev = $s20Table[$mac];
        $time = $dev['time'];
        $serverTime = $dev['serverTime'];
        $tz = $dev['timeZone'];
        $serverTzS = date_default_timezone_get();
        $serverTz = timezone_open($serverTzS);
        $serverTzOffset = $serverTz->getOffset(new DateTime());
        echo '<div id="socketTime"></div>';
        echo '<div id="serverTime"></div>';
        echo "<hr>";
        ?>
S20 mac address - 
<?php 
        echo formatMac($mac);
        ?>
<hr>
<script>
var socketTimeRef = <?php 
        echo $time;
        ?>
;
var serverTimeRef = <?php 
        echo $serverTime;
        ?>
;
var socketTz  = <?php 
        echo $tz;
        ?>
;
var serverTz  = <?php 
        echo $serverTzOffset;
        ?>
;
var t0_ref = new Date().getTime()/1000;


function  displaySocketTime(){
    var now,socketTime,serverTime;
    now = new Date().getTime()/1000;
    socketTime = now - t0_ref + socketTimeRef;
    serverTime = now - t0_ref + serverTimeRef;
    var socketTimeO = new Date(1000*socketTime);
    var serverTimeO = new Date(1000*serverTime);
    var socketTimeS = socketTimeO.toString();
    var serverTimeS = serverTimeO.toString();
    socketTimeS = socketTimeS.substring(0,24);
    serverTimeS = serverTimeS.substring(0,24);
    var msgSckt = "Socket time is " + socketTimeS+", tz="+socketTz;
    var msgServ = "Server time is " + serverTimeS+", tz="+serverTz;
    document.getElementById('socketTime').innerHTML = msgSckt;
    document.getElementById('serverTime').innerHTML = msgServ;
}
setInterval(displaySocketTime,1000); 
</script>


<p>

<button type="submit" name="toMainPage" value="procSetup<?php 
        echo $mac;
        ?>
" id="doneButton">Done</button>




<div style="margin-top:10vh;">
<hr>
Delete device from the system<p>
<button type="submit" name="toMainPage" value="procSetupDel<?php 
        echo $mac;
        ?>
" id="deleteButton">Delete device</button>
<hr>
</div>
<?php 
    } else {
        $inactiveTimeStamp = $s20Table[$mac]['off'];
        $inactiveString = gmdate("D M j G:i:s T Y", $inactiveTimeStamp);
        $now = time();
        $delta = $now - $inactiveTimeStamp;
        $deltaString = secToHourString($delta);
        $msg = "This device is inactive since " . $inactiveString;
        $msg = $msg . " (" . $deltaString . "s ago)<p>";
        $msg = $msg . "It did not reply to a re-activate command. Is it connected and on-line?<p>";
        echo $msg;
        ?>
<hr>
<button type="submit" name="toMainPage" value="procSetupDel<?php 
        echo $mac;
        ?>
" id="deleteButton">Delete device</button>
<p>
<button type="submit" name="toMainPage" value="procSetupCancel<?php 
        echo $mac;
        ?>
" id="cancelButton">Cancel</button>


<?php 
    }
    ?>
</form>

</div>

<?php 
}
Example #3
0
function displayTimerPage($mac, &$s20Table, $myUrl)
{
    $timerName = $s20Table[$mac]['name'];
    $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;
    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>

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

<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";
    }
    ?>

</select>
</div>
<p>
<br>
<button type="submit" name="toMainPage" value="setCountdown<?php 
    echo $mac;
    ?>
" 
    id="timerPageButton">Set countdown</button><p>
<button type="submit" name="toMainPage" value="clearCountdown<?php 
    echo $mac;
    ?>
"
    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<?php 
        echo $mac;
        ?>
" id="timerPageButton">
Clear automatic switch off<br>
</button><p><p>        
<?php 
    }
    ?>
</form>
</div>
<script>
    initTimerPageScripts();
</script>
<?php 
}
Example #4
0
function displayDetailsPage($mac, &$s20Table, $myUrl)
{
    global $daysOfWeek, $months;
    $timerName = $s20Table[$mac]['name'];
    ?>


<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 
    $allTimers = getAndParseTimerTable($mac, $s20Table);
    $_SESSION['details'] = $allTimers;
    $nTimers = count($allTimers);
    echo '<form action="' . $myUrl . '" method="post">';
    ?>
    <input type="submit" name="toMainPage" value="back<?php 
    echo $mac;
    ?>
" 
        id="backButton"> 
    <button type="submit" name="toEditPage" value="add<?php 
    echo $mac;
    ?>
" 
        id="addButton" >Add</button>
        <input type="submit" name="toSetupPage" value="setup<?php 
    echo $mac;
    ?>
" 
        id="setupButton">

<?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' . sprintf("%04d", $i) . $mac . '" 
                  id="editButton">Edit</button>';
        echo '</div>';
        echo '<div class="onoff">';
        echo $details['action'] ? "on " : "off";
        echo '<img src="' . IMG_PATH . ($details['action'] ? "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">';
        if ($bits > 0) {
            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;
                }
            }
        } else {
            echo $details['d'] . "  " . $months[$details['m'] - 1] . " " . $details['y'];
        }
        echo "</div>";
        echo '<div class="delCol">';
        echo '<button type="submit" name="toDetailsPage" value="del' . $details['recCode'] . $mac . '" 
                  id="delButton">Delete</button>';
        echo "</div>\n";
        echo "</div>\n";
    }
    echo "</div>\n";
    echo "<p><p><p>";
    echo '<button type="submit" name="toMainPage" value="done" id="doneButton">Done</button>';
    echo "</form>\n";
    ?>

<?php 
}