DIR : /home/kozerus/public_html/ko_center/leds_context.php

/home/kozerus/public_html/ko_center

<?php
// leds_context.php — fully functional leds_context logic
// Displays div_leds_context with four clickable ko_center.png images
// Uses exec() to update/select the cfg table in ko_center.db3

session_start();

$dbfile = "ko_center.db3";

// ------------------------------------------------------------------
// exec_set_leds_context — use PHP exec() to update the cfg table
// ------------------------------------------------------------------
function exec_set_leds_context( $dbfile, $leds_context ) {
    $sqlcmd = "sqlite3 $dbfile \"update cfg set val='$leds_context' where fld='leds_context'\"";
    exec( $sqlcmd, $out, $err );
    return( $err );
}

// ------------------------------------------------------------------
// exec_get_leds_context — use PHP exec() to retrieve from cfg table
// ------------------------------------------------------------------
function exec_get_leds_context( $dbfile ) {
    $sqlcmd = "sqlite3 $dbfile \"select val from cfg where fld='leds_context'\"";
    exec( $sqlcmd, $out, $err );
    if( isset( $out[0] ) && $out[0] !== "" ) {
        return( $out[0] );
    }
    return( "" );
}

// ------------------------------------------------------------------
// Handle form submission — set the leds_context
// ------------------------------------------------------------------
if( isset( $_POST['set_leds_context'] ) || isset( $_GET['leds_context'] ) ) {
    $lc = "";
    if( isset( $_POST['set_leds_context'] ) ) { $lc = $_POST['set_leds_context']; }
    if( isset( $_GET['leds_context'] ) )    { $lc = $_GET['leds_context']; }
    $lc = strtolower( trim( $lc ) );
    // validate allowed values
    $allowed = array( "ai", "us", "cab", "" );
    if( in_array( $lc, $allowed ) ) {
        exec_set_leds_context( $dbfile, $lc );
        $GLOBALS['leds_context'] = $lc;
    }
}

// ------------------------------------------------------------------
// Load current leds_context from the database
// ------------------------------------------------------------------
$GLOBALS['leds_context'] = exec_get_leds_context( $dbfile );

// ------------------------------------------------------------------
// html_style_leds_context — CSS for the context buttons
// ------------------------------------------------------------------
function html_style_leds_context() {
    $htmout = "";
    $htmout .= "    <style type=\"text/css\">\n";
    $htmout .= "        .leds_context {\n";
    $htmout .= "            -moz-box-shadow:inset 0px 1px 0px 0px #fcf8f2;\n";
    $htmout .= "            -webkit-box-shadow:inset 0px 1px 0px 0px #fcf8f2;\n";
    $htmout .= "            box-shadow:inset 0px 1px 0px 0px #fcf8f2;\n";
    $htmout .= "            background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #fae4bd), color-stop(1, #eac380) );\n";
    $htmout .= "            background:-moz-linear-gradient( center top, #fae4bd 5%, #eac380 100% );\n";
    $htmout .= "            filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fae4bd', endColorstr='#eac380');\n";
    $htmout .= "            background-color:#fae4bd;\n";
    $htmout .= "            -webkit-border-top-left-radius:0px;\n";
    $htmout .= "            -moz-border-radius-topleft:0px;\n";
    $htmout .= "            border-top-left-radius:0px;\n";
    $htmout .= "            -webkit-border-top-right-radius:0px;\n";
    $htmout .= "            -moz-border-radius-topright:0px;\n";
    $htmout .= "            border-top-right-radius:0px;\n";
    $htmout .= "            -webkit-border-bottom-right-radius:0px;\n";
    $htmout .= "            -moz-border-radius-bottomright:0px;\n";
    $htmout .= "            border-bottom-right-radius:0px;\n";
    $htmout .= "            -webkit-border-bottom-left-radius:0px;\n";
    $htmout .= "            -moz-border-radius-bottomleft:0px;\n";
    $htmout .= "            border-bottom-left-radius:0px;\n";
    $htmout .= "            text-indent:0;\n";
    $htmout .= "            border:1px solid #eeb44f;\n";
    $htmout .= "            display:inline-block;\n";
    $htmout .= "            color:#ffffff;\n";
    $htmout .= "            font-family:Arial;\n";
    $htmout .= "            font-size:15px;\n";
    $htmout .= "            font-weight:bold;\n";
    $htmout .= "            font-style:normal;\n";
    $htmout .= "            height:40px;\n";
    $htmout .= "            line-height:40px;\n";
    $htmout .= "            width:100px;\n";
    $htmout .= "            text-decoration:none;\n";
    $htmout .= "            text-align:center;\n";
    $htmout .= "            text-shadow:1px -21px 0px #cc9f52;\n";
    $htmout .= "        }\n";
    $htmout .= "        .leds_context:hover {\n";
    $htmout .= "            background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #eac380), color-stop(1, #fae4bd) );\n";
    $htmout .= "            background:-moz-linear-gradient( center top, #eac380 5%, #fae4bd 100% );\n";
    $htmout .= "            filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#eac380', endColorstr='#fae4bd');\n";
    $htmout .= "            background-color:#eac380;\n";
    $htmout .= "        }\n";
    $htmout .= "        .leds_context:active {\n";
    $htmout .= "            position:relative;\n";
    $htmout .= "            top:1px;\n";
    $htmout .= "        }\n";
    $htmout .= "        .leds_context_img {\n";
    $htmout .= "            border:0;\n";
    $htmout .= "            cursor:pointer;\n";
    $htmout .= "        }\n";
    $htmout .= "    </style>\n";
    return( $htmout );
}

// ------------------------------------------------------------------
// html_leds_context — four clickable images in div_leds_context
// ------------------------------------------------------------------
function html_leds_context() {
    $htmout = "";
    $htmout .= "<div id=\"div_leds_context\">\n";

    $contexts = array( "ai", "us", "cab", "" );
    foreach( $contexts as $ctx ) {
        $label = ( $ctx === "" ) ? "blank" : strtoupper( $ctx );
        if( $GLOBALS['leds_context'] === $ctx ) {
            $height = 150;
        } else {
            $height = 100;
        }
        $htmout .= "    <form method=\"post\" action=\"\" style=\"display:inline;margin:0;padding:0;\">\n";
        $htmout .= "        <input type=\"hidden\" name=\"set_leds_context\" value=\"$ctx\" />\n";
        $htmout .= "        <button type=\"submit\" name=\"leds_context\" class=\"leds_context\" value=\"$ctx\">\n";
        $htmout .= "            <img class=\"leds_context_img\" src=\"ko_center.png\" height=\"$height\" alt=\"$label\" />\n";
        $htmout .= "        </button>\n";
        $htmout .= "    </form>\n";
        $htmout .= "    &nbsp;\n";
    }

    $htmout .= "</div>\n";
    return( $htmout );
}

// ------------------------------------------------------------------
// Output the full page for browser review
// ------------------------------------------------------------------
?><!DOCTYPE html>
<html>
<head>
    <title>leds_context review</title>
    <meta charset="UTF-8">
    <?php print html_style_leds_context(); ?>
</head>
<body>
    <h2>leds_context — current value: <?php print htmlspecialchars( $GLOBALS['leds_context'] ); ?></h2>
    <?php print html_leds_context(); ?>
    <hr>
    <p>Click an image above to set the context. The active context image is taller (20px) vs inactive (10px).</p>
    <p>Database: <?php print $dbfile; ?></p>
</body>
</html>
//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer