dat/visitors.php - index




































































































































































































































<?php

/* DAT/VISITORS.PHP - "Visitor code" related commands and functions */

print _message('visitors');

if (
$button == 'cancel') {
    unset(
$_GET['x']);
}

if (
$button == 'create') {

    
$record visitorpost();        // merges $_POST data
    
$res visitorcreat($record);
    echo 
'<b style="color:red;">',$res?'saved!':'error!','</b>';
}

if (
$button == 'save') {
    
// not much to do in way of validation; the visitorput
    // code checks for existence first; we might want to
    // add a "are you sure you want to edit the code?"
    // check (by reading the record first)

    
$record visitorpost();        // merges $_POST data
    
$res visitorput($record);
    echo 
'<b style="color:red;">',$res?'saved!':'error!','</b>';
}

visitors();

function 
visitors() {

// I know this is weird, calling this function right before it's defined,
// but this was in ADMIN.PHP as a function and it was just cut 'n pasted

// This will all be re-written anyway...

    
$html html();
    
$arg getvar('arg');
    
$op 'visitors';

    
// remember the order dependency of the list!
    
list($n,$e,$x,$c,$a) = getvars('visitors');    // in INC/GET.PHP

// one of 'x' 'c' 'e' 'n' 'a' is a "sub-command" to the "op" of "visitor"
// we do not like having to be careful of the order of these sub-commands,
// but we do kind of have to be careful; the 'a' sub-command is the "default"
// so it is last and not "else"d

    
if ($x) { // delete
        
if (config('confirmdelete') && !isset($_POST['yes'])) {
            
$preamble "Preparing to delete visitor $x...";
            
$action "delete visitor $x?";
            eval(
shit_show(_message('confirm')));
            return 
1;
        }
        else {
            
$s "<span id='status'>visitor $x was deleted</span>";
            
dbdelvisitor($x);
            echo 
$s;
        }
    }

    else
    if (
$c) { // create
        
$record visitorpost();
        
$record['ip'] = '127.0.0.1';
        
$record['meta'] = 'none';
        
$record['body'] = 'time:'.time().THIS_EOL;
        eval(
_vhtm('va'));
        return 
1;
    }
    else
    if (
$e) { // edit
        
$record dbvisitor('read',$e);
        
$record $record[0];
        foreach (
$record as $n => $v)
            
$record[$n] = htmlspecialchars($v);
        eval(
_vhtm('ve'));
        return 
1;
    }
    else
    if (
$n// read (why not 'r'? we forget)
        
$visitor dbvisitor('read',$n);

    if (
$a !== ""// lookup (and why 'a'? we forget that too!)
        
$visitor dbvisitor('lookup',$a);

    
// make list of links to view visitors alphanumerically

    
echo "<p>Select:";
    foreach (
range('A','Z') as $l) {
        
$m strtolower($l) . strtoupper($l);
        
$s $a && $a[1] == $l 'vsel' '';
        
$c dbvisitor('range',$m);
        
$t 'show visitors starting with '.$m;
        eval(
_vhtm('v',$c));
    }

    
$l '0';
    
$s $a == $l 'vsel' '';
    
$c dbvisitor('range','0-9');
    
$t 'show visitors starting with 0-9';
    eval(
_vhtm('v',$c));

    
$l '*';
    
$s $a == $l 'vsel' '';
    
$c dbvisitor('range','^a-zA-Z0-9');
    
$t 'show visitors starting with goofys';
    eval(
_vhtm('v',$c));

    echo 
"</p>"// end "<p>Select...

    
if (isset($visitor))
        if (
$visitor)
            foreach(
$visitor as $record) {
                if (!
visitorchksum($record)) {
                    echo 
"corrupt record found<br>";
                    continue;
                }
                
// have to be careful to escape some data!
                
$f urlencode($record['from']);
                foreach (
$record as $n => $v)
                    
$record[$n] = htmlspecialchars($v);
                eval(
_vhtm('vd'));
            }
        else
            echo 
"No visitors found.<br>";

    eval(
_vhtm('vc'));

    return 
0;
}

// more UGH! code, it too shall pass...

function _vhtm($html$c 0) {

    
$htm _htm();
    
$h $htm[$html][!!$c];
    return 
"print \"".str_replace('"','\\"',$h)."\";";
}

function 
_htm() {

$htm['v'][1] = <<<HTML
 <a class='\$s' title='\$t' href='?op=\$op&amp;a=\$l'>\$l</a><span style='font-size:90%;color:orange;vertical-align:1px;'>\$c</span>
HTML;
$htm['v'][0] = ' $l';

$htm['vd'][0] = <<<HTML

<!-- vd -->
<a class='x' href='?op=\$op&amp;a=\$a&amp;x=\$f' title="delete visitor {\$record['from']}{\$html['confirmdelete']}"></a>
<b><a href='?op=\$op&amp;a=\$a&amp;e=\$f' title="edit visitor {\$record['from']}">{\$record['from']}</a></b>
<span style='color:darkblue;'>'{\$record['code']}'</span>
<span style='color:darkblue;'>'{\$record['ip']}'</span>
<span style='color:darkblue;'>'{\$record['meta']}'</span>
<span style='color:darkblue;'>{\$record['body']}</span>
<br class='clear'>
HTML;

$htm['ve'][0] = <<<HTML

<!-- ve -->
<h3>Visitor: '{\$record['from']}'</h3>
<form class='vedit' method='post'
action='{\$_SERVER['PHP_SELF']}?op=\$op&amp;a=\$a'>
<input type='hidden' name='from' value="{\$record['from']}">
<p>code: <input name='code' value="{\$record['code']}"></p>
<p>ip:&nbsp;&nbsp; <input name='ip' value="{\$record['ip']}"></p>
<p>meta: <input name='meta' value="{\$record['meta']}"></p>
<span style='float:left;margin-right:.6em;'>body: </span><textarea name='body'>{\$record['body']}</textarea>
<div class='buttons'>
<button name='button' value='save'>save</button>
<button type='cancel'>cancel</button>
</div>
</form>
HTML;

$htm['va'][0] = <<<HTML

<!-- va -->
<h3>Create Visitor</h3>
<form class='vedit' method='post'
action='{\$_SERVER['PHP_SELF']}?op=\$op&amp;a=\$a'>
<p>from: <input name='from' value='{\$record['from']}'></p>
<p>code: <input name='code' value='{\$record['code']}'></p>
<p>ip:&nbsp;&nbsp; <input name='ip' value='{\$record['ip']}'></p>
<p>meta: <input name='meta' value='{\$record['meta']}'></p>
<span style='float:left;margin-right:.6em;'>body: </span><textarea name='body'>{\$record['body']}</textarea>
<div class='buttons'>
<button name='button' value='create'>create</button>
<button type='cancel'>cancel</button>
</div>
</form>
HTML;
// a "close proximity" data duplication

$htm['vc'][0] = <<<HTML

<!-- vc -->
<br>
<form style='float:left;margin-right:8px;' method='get' action='{\$_SERVER['PHP_SELF']}'>
<button name='c' value='1' title='create visitor record'>create</button>
<input type='hidden' name='op' value='\$op'>
<input type='hidden' name='a' value='\$a'>
</form>
<form method='get' action='{\$_SERVER['PHP_SELF']}'>
<input type='submit' value='done' title='done with visitors'>
<input type='hidden' name='arg' value='\$arg'>
</form>
HTML;

    return 
$htm;
}

/*

This is an alternate way of "doing" the command thingy I was once fooling with

<form class='x' method='post' action='?op=$op&amp;a=$a&amp;x={$record['from']}'>
<button title='delete visitor {$record['from']}' name='button' value='delete'>&times;</button>
</form>
*/