List

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


<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/tec_SiteRoot.php";

function isValidIp($ip = '') {
    if ($ip == '') {
        print("<br />Ip cannot be empty in call to isValid(ip).<br />");
    }
    $parts = explode('.',$ip);
    if (count($parts) != 4) return false;
    return ((int)$parts[0] < 256 && (int)$parts[1] < 256 && (int)$parts[2] < 256 && (int)$parts[3] < 256);
} 



global $site_db;
$site_db->setDebug(false);
global $ip, $ip_err;

if (isset($_REQUEST['delete'])) {
    $site_db->issue("DELETE FROM seed_ips WHERE ip='" . $_SERVER['REMOTE_ADDR'] . "'");
} else if (isset($_REQUEST['submit']) && $_REQUEST['submit'] == "Add") {
    $ip = $_REQUEST['ip'];
    if (isValidIp($ip)) {
        $select = "SELECT id FROM seed_ips WHERE ip='$ip' LIMIT 1";
        $result = $site_db->select($select);
        if ($result['count'] == 1) {
            $rows = $result['rows'];
            $id = $rows['id'];
        }
        if ($result['count'] != 0) { 
            $replace = "UPDATE seed_ips SET ip='$ip' WHERE id='$id'";
            $site_db->issue($replace); 
        } else { 
            $insert = "INSERT INTO seed_ips (ip) VALUES ('$ip')";
            $site_db->issue($insert);
        }
    } else {
        $ip_err = "Invalid IP Address: $ip";
    }
} 

include_once "html_start.php";
?>
    <meta charset="UTF-8">
</head>
<body>
<?php
    include_once "html_brand_menu_start.php";
    include_once "menu/menuRoot.php";
    include_once "html_brand_menu_stop.php";


$sql = "SELECT * FROM seed_ips";
$result = $site_db->select($sql);
$rows = $result['rows'];
if ($result['count'] > 0) {
    if (isset($rows['ip'])) {
        print($rows['ip']);
        if ($rows['ip'] == $_SERVER['REMOTE_ADDR']) {
            print("&nbsp;&nbsp;&nbsp;<a href='" . $_SERVER['PHP_SELF'] . "?delete'>Delete</a>");
        }

        print("<br />");
    } else {
        for($i = 0; $i < count($rows); $i++) {
            print($rows[$i]['ip']);
            if ($rows[$i]['ip'] == $_SERVER['REMOTE_ADDR']) {
                print("&nbsp;&nbsp;&nbsp;<a href='" . $_SERVER['PHP_SELF'] . "?delete'>Delete</a>");
            }
            print("<br />");
        }
    }
}


?>
<br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input type="text" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" maxlength="15" name="ip"><br />
<span class="help-block"><?php global $ip_err; echo $ip_err; ?></span><br />
<input type="submit" name="submit" value="Add"><br />
</form>

<?php
   require_once "$TEC_PREFIX_DIR/footer.php";