List

Try: ca/tecreations/ViewFile.php -- Online


<?php

//create table tracy (
//    id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
//    txt VARCHAR(1000) NOT NULL,
//    ip varchar(15) NOT NULL,
//    timsTime varchar(24)
//)

require_once $_SERVER['DOCUMENT_ROOT'] . "/tec_SiteRoot.php";
global $DOCROOT, $TEC_PREFIX_DIR;

global $site_db;

$site_db->setDebug(false);

GLOBAL $hit_count;
$path = "/ca/tecreations/tracy.php";

$result = $site_db->select("SELECT hit_count FROM hits WHERE path='$path'");
if ($result['count'] == 1) {
    $row = $result['rows'];
    $hit_count = (((int)$row['hit_count'])+ 1);
    if (!isset($_REQUEST['no_hit'])) $site_db->issue("UPDATE hits SET hit_count = '$hit_count' WHERE path='$path'");
} else {
    $site_db->issue("INSERT INTO hits (path, hit_count) VALUES('$path','1')");
}

$add_err = "";
if (isset($_REQUEST['action'])) {
    $action = $_REQUEST['action'];
    //print("Action: $action<br />");
    //print("Txt: " . $_REQUEST['txt'] . "<br />");
    //die();
    
    if ($action == "add") {
        $txt = $_REQUEST['txt'];
        $ip = $_SERVER['REMOTE_ADDR'];
        if ($txt == "") $add_err = "Text cannot be empty.";
        else {
            $site_db->issue("INSERT INTO tracy (txt,ip,timsTime) VALUES('" . htmlentities($txt,ENT_QUOTES|ENT_HTML401) . "','$ip','" . $time->getTimsTime() . "')");
	    echo "$SELF";
            header("Location: $SELF?no_hit=true");
        }
    }
}

require_once $DOCROOT . $TEC_PREFIX_DIR . "html_start.php";
?>

    <script>
    function alertIfNecessary() {
        var msg = '<?php global $add_err; echo $add_err; ?>';
        alert(msg);
    }        

    function validate() {
        if (document.getElementById("txt").value == "") {
            alert("Text cannot be empty!");
            return false;
        }
        return true;
    } 
    </script>
</head>
<body <?php global $add_err; if (!empty($add_err)) echo "onload='alertIfNecessary();' " ?> >
<?php 
    include_once $DOCROOT . $TEC_PREFIX_DIR . "html_brand_menu_start.php";
    include_once $DOCROOT . $TEC_PREFIX_DIR . "menu/menuRoot.php";
    include_once $DOCROOT . $TEC_PREFIX_DIR . "html_brand_menu_stop.php";
?>

    <div class="container">
        <div class="page-header">
            <h2>Tracing</h2>
        </div>
        <?php
            //$site_db->setDebug(true);
            $result = $site_db->select("SELECT * FROM tracy");
            $count = $result["count"];                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           $count = $result['count'];
            for($i = 0; $i < $count;$i++) {
                if ($count == 1) $row = $result['rows'];
                else $row = $result['rows'][$i];
                echo "<div class='jumbotron padded'>\n";
                echo $row['id'] . "<br />\n";
                $txt = $row['txt'];
                if (startsWith($txt, "https://") | 
                    startsWith($txt,"http://") |
                    startsWith($txt, "mailto://")
                ) {
                    echo "<a href='$txt'>$txt</a><br />";
                } else {
                     echo html_entity_decode($row['txt'],ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401) . "<br />\n";
                }
                echo $row['ip'] . "<br />\n";
                echo $row['timsTime'] . "<br />\n";
                echo "</div>\n\n";
                if (isset($_SESSION['level']) && $_SESSION['level'] == 9) {
                    echo "<td class='text-center'><a href='" . $_SERVER['PHP_SELF'] . "?delete=" . $row['id'] . "'>Delete</a></td>" ;
                }
            }
        ?>
        <div class="padded">
            <hr />
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>">
                <div class="form-group">
                    <label for="txt">Text:</label>
                    <input class="form-control" name="txt" id="txt" maxlength="1000" />
                    <input type="hidden" name="no_hit" value="" />
                </div>
                <button type="submit" name="action" value="add" class="btn btn-primary">Add</button>
<?php

// onSubmit="return validate();"
 
?>
            </form>
            <hr />
        </div> 
        <div class="padded">
            <p>Hits: <?php global $hit_count; echo $hit_count; ?></p>
        </div>
    </div>
    <script>
    $(document).ready(function() {
	
        $("html, body").animate(
            { 
                scrollTop: <?php if (isset($_REQUEST['height']) && $_REQUEST['height'] != "undefined") { 
                                     echo "\"" . $_REQUEST['height'] . "px\""; 
                                 } else { 
                                     echo "$(document).height()"; 
                                 } 
                            ?>
             }, "slow")
    });
 
    </script>
<?php require_once $DOCROOT . $TEC_PREFIX_DIR . "footer.php"; ?>