<?php 
session_start
();
$sess_id session_id();
if (@
$_GET['poem']){
$_SESSION['view_poem'] = $_GET['poem'];
}
echo 
"<!-- _SESSION['view_poem']: ".$_SESSION['view_poem']."line: ".__LINE__;
print_r($_SESSION);
echo 
" -->\n";
if (!
$_SESSION['view_poem']){
$_SESSION['view_poem'] = 1;
}else{
$_SESSION['view_poem']++;
}
echo 
"<!-- _SESSION['view_poem']: ".$_SESSION['view_poem']."line: ".__LINE__." -->\n";
$view_poem_query $_SESSION['view_poem']-1;
echo 
"<!-- _SESSION['view_poem']: ".$_SESSION['view_poem']."line: ".__LINE__." -->\n";
$visitor_ip $_SERVER['REMOTE_ADDR'];
if (@
$_SESSION['host']){
    
$host $_SESSION['host'];
}else{
    
$host gethostbyaddr($visitor_ip);
    
$_SESSION['host'] = $host;
}

include(
"../../php_includes/db_connect.inc");

if ( (!
$_SESSION['session_excerpt']) || ($_SESSION['view_poem']>1)){
//LIMIT $view_poem_query,1
    
$sql "SELECT
            Poem,
            DATE_FORMAT(TimeVisited,'%m/%e/%Y %r') AS TimeOfVisit,
            IPAddress
            from show_poem_tracking
            WHERE LENGTH(Poem) > 50
            ORDER BY id  DESC
            
            "
;
        
$result mysql_query($sql);
        if (!
$result) {
              echo (
'<!-- Invalid query: ' mysql_error().'<br>'.$sql.'-->');
        }
        
/* $rows = mysql_fetch_array($result);
        echo "<pre>";
        print_r($rows);
        echo "</pre>"; */
        
$count_poems mysql_num_rows($result);
        
$flip_poem rand(1,$count_poems);
        
$i=1;
        while (
$rows mysql_fetch_array($result)){
            
            if (
$i == $flip_poem){
            
            
$Poem stripslashes($rows['Poem']);
            
$TimeLine "created on ".$rows['TimeOfVisit'];
            
//echo "<!-- TimeLine: ".$TimeLine."<br> -->";
            
}
            
$i++;

        }
//end while 
}else{
    
$Poem $_SESSION['session_excerpt'];
    
$Pages $_SESSION['page_views'];
    
$session_excerpt addslashes($_SESSION['session_excerpt']);
    include (
"../../php_includes/show_poem_track_query.inc");
}


$pos strpos($Poem,'</h1>');
$title_excerpt substr($Poem,4,$pos-4);


//just to be more aleatory, create alternate versions of the page title
$flip_title rand(0,3);
if (
$flip_title == 0){
$title_desc "aleatory poetry";
}
if (
$flip_title == 1){
$title_desc "aleatory poetry";
}
if (
$flip_title == 2){
$title_desc "aleatory poetry";
}
if (
$flip_title == 3){
$title_desc "aleatory poetry";
}

//function for selecting the font color.  It makes sure that the font color is as different as possible from its background.
function wheel($number) {
$number=$number+128;
    if (
$number >255){
    
$number $number-256;
    }
return 
$number;
}
$r=rand(0,255);
$g=$r;
$b=$r;

$sr wheel($r);
$sg wheel($g);
$sb wheel($b);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>bite size: <?php echo $title_desc ?> from 9/11: show poem: <?php echo $title_excerpt ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!-- 
body{background-color:rgb(<?php echo $sr;?>,<?php echo $sg;?>,<?php echo $sb;?>);text-align:center;}
div.phrase{color:rgb(<?php echo $sr?>,<?php echo $sg?>,<?php echo $sb;?>);padding:20px;background-color:rgb(<?php echo $r;?>,<?php echo $g;?>,<?php echo $b;?>)}
div.phrase{text-align:center;margin:20px;border:1px gray solid; visibility:visible;font-family:verdana,sans-serif;font-size:12pt;}
div.phrase p{text-align:center;font-family:verdana,sans-serif;font-size:12pt;} 
div.phrase small {font-style:italic;text-align:right;}
h1{font-family:verdana,sans-serif;text-align:center;margin-top:5px;padding-top;0px;}

div.credits{text-align:center;padding;0px;margin: 0px auto; margin:1px yellow solid;}
.credits p {font-size:10px;margin:0px;padding:0px;margin-top:10px;font-family:verdana,sans-serif;}

a {font-family:Verdana, Arial, Helvetica, sans-serif;}
a:link{color:rgb(<?php echo $r;?>,<?php echo $g;?>,<?php echo $b;?>)}
a:hover{text-decoration:underline}
a:active{color:rgb(<?php echo $r;?>,<?php echo $g;?>,<?php echo $b;?>)}
a:visited{color:rgb(<?php echo $r;?>,<?php echo $g;?>,<?php echo $b;?>)}
-->
</style>
<style type="text/css" media="print">
<!-- 
body {display:none; visibility:hidden}
div.credits{display:none;visibility:hidden;}
div.phrase p{ visibility:hidden}
 -->
</style>
</head>

<body>

<div class="phrase"><?php echo $Poem?>

</div>

<div class="credits" >

<p style="padding-top:0px;"><a href="/"><span style="font-size:16px;margin:0px;padding:0px;">OT!OM!</span><br><span style="font-size:10px;margin:0px;padding:0px;">Productions</span></a></p>

<p><a href="/bite_size/">build a new poem</a> | <a href="/bite_size/show_poem.php?poem=<?php echo $_SESSION['view_poem']; ?>">view another poem</a> | <a href="/bite_size/statement.php">bite size: statement</a></p>
<?php // echo "view_poem_query: $view_poem_query count_poems: $count_poems";
/* echo"<!-- ";
print_r($GLOBALS);
echo" -->"; */

?>

</div>
</body>
</html>