Example #1
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 
}
Example #2
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;"';
        // display big button
        $bigButton = '<button type="submit" name="toMainPage" 
               value="switch_' . $name . '" id="' . $type . '" ' . $style . '>' . $name . '</button><br>' . "\n";
        echo $bigButton;
        // overlay timer button for each field
        $posTimerButton = $posBigButton + $clockTopMargin;
        $timerButtonName = 'clock_' . $name;
        $styleTimer = 'style="top:' . $posTimerButton . 'vh"';
        $timerButton = '<input type="submit" name="toCountDownPage" id="countDownButton" 
                value="timer_' . $name . '" ' . $styleTimer . '/>' . "\n";
        echo $timerButton;
        $clockButton = '<input type="submit" name="toDetailsPage" id="clockButton" 
                value="clock_' . $name . '" ' . $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 "b" . $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);
        if ($nd > 0) {
            $maxd = NUMBER_OF_NEXT_ACTIONS_DISPLAYED_IN_MAIN_PAGE;
            if ($nd > $maxd) {
                $nd = $maxd;
            }
            $top = $posBigButton + $timerLabelTopMargin - $nd * $timerLabelvSpace;
            $actString = '<div class="next" style="top:' . $top . 'vh; color:#4C4C4C;"><span>Next ' . ($nd > 1 ? $nd : "") . ':</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;
    }
    ?>
</center>
<?php 
}
Example #3
0
    logger("No function to call");
}
$rptuser = mysql_real_escape_string($rptuser);
if ($function == 'getUsers') {
    logger("Getting Users");
    getAllUsers();
    sendResponse($finalResult['UserInfo'], 'user');
} else {
    if ($function == 'getGroups') {
        logger("Getting Groups");
        getAllGroups();
        sendResponse($finalResult['GroupInfo'], 'group');
    } else {
        if ($function == 'getActions') {
            logger("Getting Actions");
            getAllActions();
            sendResponse($finalResult['ActionInfo'], 'action');
        } else {
            if ($function == 'getHosts') {
                logger("Getting Hosts");
                getAllHosts();
                sendResponse($finalResult['HostInfo'], 'host');
            } else {
                if ($function == 'getVolumes') {
                    logger("Getting Volumes");
                    getAllVolumes();
                    sendResponse($finalResult['VolumeInfo'], 'volume');
                } else {
                    if ($function == 'getPrinters') {
                        logger("Getting Printers");
                        getAllPrinters();