Exemplo n.º 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;
        $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 
}
Exemplo n.º 2
0
        error_log("New session: S20 data initialized\n");
    }
}
$_SESSION["s20Table"] = $s20Table;
//
// 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'])) {
        $mac = getMacAndActionFromPost($actionValue, $_POST['toMainPage']);
        if ($actionValue == "check") {
            $ip = getIpFromMac($mac, $s20Table);
            $s20Table[$mac]['lastOffCheck'] = time();
            $_SESSION['s20Table'] = $s20Table;
            if ($ip != 0) {
                $s20Table[$mac]['ip'] = $ip;
                $st = checkStatus($mac, $s20Table);
                $_SESSION["s20Table"] = $s20Table;
                if ($st >= 0) {
                    unset($s20Table[$mac]['off']);
                    $s20Table[$mac]['st'] = $st;
                    $_SESSION['s20Table'] = $s20Table;
                    require_once ORVFMS_PATH . "main_page.php";
                    displayMainPage($s20Table, $myUrl);
                    require_once ORVFMS_PATH . "main_page_scripts.php";
                }
            }
Exemplo n.º 3
0
function displayMainPage(&$s20Table, $myUrl)
{
    global $daysOfWeek;
    $ndevs = count($s20Table);
    ?>
<center>
<form action="<?php 
    echo $myUrl;
    ?>
" method="post">
<?php 
    //
    // Sort array (in this case, by mac address), such that data is displayed in
    // a deterministic sequence
    //
    $macs = array_keys($s20Table);
    sort($macs);
    //
    // Dynamic location style details;
    //
    // Compute big button height (90 percent of viewport height)
    $bigButHeight = 90 / $ndevs;
    // Countdown & next action time font size
    $fsize = 3;
    $posBigButton = 0;
    $clockTopMargin = 2;
    $timerLabelTopMargin = $bigButHeight * 0.85;
    $timerLabelvSpace = $bigButHeight * 0.1;
    //
    // Loop on all devices and display each button, coloured according to
    // current S20 state.
    //
    foreach ($macs as $mac) {
        $devData = $s20Table[$mac];
        $st = $devData['st'];
        $name = $devData['name'];
        $type = $st == 0 ? "redbutton" : "greenbutton";
        $style = 'style="height:' . $bigButHeight . 'vh;top:' . $posBigButton . 'vh;"';
        $bname = $name;
        if (array_key_exists('off', $devData)) {
            if (!array_key_exists('lastOffCheck', $s20Table[$mac])) {
                $s20Table[$mac]['lastOffCheck'] = $s20Table[$mac]['off'];
                $_SESSION['s20Table'] = $s20Table;
                $devData = $s20Table[$mac];
            }
            if (time() - $devData['lastOffCheck'] > 24 * 3600) {
                // Check once per day
                $s20Table[$mac]['lastOffCheck'] = time();
                $_SESSION['s20Table'] = $s20Table;
                $ip = getIpFromMac($mac, $s20Table);
                if ($ip != 0) {
                    $s20Table[$mac]['ip'] = $ip;
                    $st = checkStatus($mac, $s20Table);
                    $_SESSION["s20Table"] = $s20Table;
                    if ($st >= 0) {
                        unset($s20Table[$mac]['off']);
                        $s20Table[$mac]['st'] = $st;
                        $_SESSION['s20Table'] = $s20Table;
                        $devData = $s20Table[$mac];
                    }
                }
            }
        }
        if (array_key_exists('off', $devData)) {
            $type = "graybutton";
            $bname = $name . " (?)";
            $val = "check";
        } else {
            $val = "switch";
        }
        // display big button
        $bigButton = '<button type="submit" name="toMainPage" 
              value="' . $val . $mac . '" id="' . $type . '" ' . $style . '>' . $bname . '</button><br>' . "\n";
        echo $bigButton;
        if (!array_key_exists('off', $devData)) {
            // overlay timer button for each field (countdown timers);
            $posTimerButton = $posBigButton + $clockTopMargin;
            $timerButtonName = 'clock' . $mac;
            $styleTimer = 'style="top:' . $posTimerButton . 'vh"';
            $timerButton = '<input type="submit" name="toCountDownPage" id="countDownButton" 
                value="timer' . $mac . '" ' . $styleTimer . '/>' . "\n";
            echo $timerButton;
            // overlay clock button for each field
            $clockButton = '<input type="submit" name="toDetailsPage" id="clockButton" 
                value="clock' . $mac . '" ' . $styleTimer . '/>' . "\n";
            echo $clockButton;
            // Include field for timer information
            if ($devData['timerVal'] != 0) {
                if ($devData['timerAction']) {
                    $color = "#00BB00";
                } else {
                    $color = "#EE0000";
                }
            } else {
                if ($devData['switchOffTimer'] > 0) {
                    $color = "white";
                } else {
                    $color = "black";
                }
            }
            $timerLabelTop = $posBigButton + $timerLabelTopMargin;
            ?>
        <div class="counter" id="<?php 
            echo $mac;
            ?>
" style="top:<?php 
            echo $timerLabelTop;
            ?>
vh;
                         color:<?php 
            echo $color;
            ?>
;
                         font-size:<?php 
            echo $fsize;
            ?>
vh;"></div>
<?php 
            $next = getAllActions($mac, $s20Table);
            $nd = count($next);
            $maxd = $s20Table[$mac]['next'];
            if ($nd > $maxd) {
                $nd = $maxd;
            }
            if ($nd > 0) {
                $top = $posBigButton + $timerLabelTopMargin - $nd * $timerLabelvSpace;
                $actString = '<div class="next" style="top:' . $top . 'vh; color:#4C4C4C;"><span>Next:</span>   </div>';
                echo $actString . '\\n';
                for ($j = 0; $j < $nd; $j++) {
                    $nextAct = $next[$j][0];
                    $nextTimeStamp = $next[$j][1];
                    $top = $posBigButton + $timerLabelTopMargin - ($nd - $j - 1) * $timerLabelvSpace;
                    $nextActS = mkNextActString($nextTimeStamp, $nextAct, $top);
                    echo $nextActS . "\n";
                }
            }
        }
        $posBigButton += $bigButHeight;
    }
    /* Overlay find button */
    ?>

<input type="submit" name="toMainPage" id="findButton" 
                value="find000000000000">
</form>
</center>
<?php 
}