THIS source compiler<?php
/* DAT/VISITORS.PHP - "Visitor code" related commands and functions */
// (This is the second version and there will be at least one more re-write.)
print _message('visitors');
if ($button == 'cancel') {
unset($_GET['x']);
}
if ($button == 'create' || $button == 'save') {
$record = visitorpost(); // merges $_POST data
if ($button == 'save')
$res = visitorput($record);
else
$res = visitorcreat($record);
echo '<b style="color:red;">',$res?'saved!':'error!','</b>';
}
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.
// What we'll probably do is put it all in one function.
function visitors() {
$html = html();
$arg = getvar('arg');
$op = 'visitors';
// our $_GET variables:
$e = $x = $c = $a = '';
extract($_GET,EXTR_IF_EXISTS);
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 = visitornew('','',NULL,0);
eval(_htmltempl('add'));
return 1;
}
else
if ($e !== '') { // edit
$record = dbvisitor('read',$e);
foreach ($record as $n => $v)
$record[$n] = htmlspecialchars($v);
eval(_htmltempl('edit'));
return 1;
}
if ($a !== '') {
// convert &a=? to lookup range string for query
if ($a == '0')
$r = '0-9';
else
if ($a == '*')
$r = '^a-zA-Z0-9';
else
$r = strtolower($a).strtoupper($a);
$visitor = dbvisitor('lookup',$r);
}
// make list of links to view visitors alphanumerically
echo "<p>Select:";
foreach (range('A','Z') as $l) {
$m = strtolower($l) . strtoupper($l);
$s = ($a == $l) ? 'vsel' : '';
$c = dbvisitor('range',$m);
$t = 'show visitors starting with '.$m;
eval(_htmltempl($c?'select':'none'));
}
$l = '0';
$s = ($a == $l) ? 'vsel' : '';
$c = dbvisitor('range','0-9');
$t = 'show visitors starting with 0-9';
eval(_htmltempl($c?'select':'none'));
$l = '*';
$s = ($a == $l) ? 'vsel' : '';
$c = dbvisitor('range','^a-zA-Z0-9');
$t = 'show visitors starting with goofys';
eval(_htmltempl($c?'select':'none'));
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(_htmltempl('display'));
}
else
echo "No visitors found.<br>";
eval(_htmltempl('menu'));
return 0;
}
function _htmltempl($templ) {
$htm['select'] = <<<HTML
<a class='\$s' title='\$t' href='?op=\$op&a=\$l'>\$l</a><span style='font-size:90%;color:orange;vertical-align:1px;'>\$c</span>
HTML;
$htm['none'] = ' $l';
$htm['display'] = <<<HTML
<a class='x' href='?op=\$op&a=\$a&x=\$f' title="delete visitor {\$record['from']}{\$html['confirmdelete']}"></a>
<b><a href='?op=\$op&a=\$a&e=\$f' title="edit visitor {\$record['from']}">{\$record['from']}</a></b>
<span style='color:darkblue;'>'{\$record['code']}'</span>
<span style='color:darkblue;'>{\$record['body']}</span>
<br class='clear'>
HTML;
$htm['edit'] = <<<HTML
<h3>Edit Visitor: '{\$record['from']}'</h3>
<form class='vedit' method='post'
action='{\$_SERVER['PHP_SELF']}?op=\$op&a=\$a'>
<input type='hidden' name='from' value="{\$record['from']}">
<p>code: <input name='code' value="{\$record['code']}"> to update password enter new one here (not beginning with the salt)</p>
<span style='float:left;margin-right:.6em;'>body: </span><textarea rows='5' name='body'>{\$record['body']}</textarea>
<div class='buttons'>
<button name='button' value='save'>save</button>
<button type='cancel'>cancel</button>
</div>
</form>
HTML;
$htm['add'] = <<<HTML
<h3>Create Visitor</h3>
<form class='vedit' method='post'
action='{\$_SERVER['PHP_SELF']}?op=\$op&a=\$a'>
<p>from: <input name='from' value='{\$record['from']}'></p>
<p>code: <input name='code' value='{\$record['code']}'> plain text (will be encrypted)</p>
<span style='float:left;margin-right:.6em;'>body: </span><textarea rows='5' 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['menu'] = <<<HTML
<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 "print \"".str_replace('"','\\"',$htm[$templ])."\";";
}
Source Code Index