<?php 
session_start
();
setcookie("test",1,0,"/");
echo 
"<!-- session page views: ".$_SESSION['page_views']."line ".__LINE__." -->\n";
//setcookie("test",1,0,"/");

 //echo"<!-- SESSION ";
//print_r($_SESSION);
//print_r($_COOKIE);
//echo" -->"; 
//echo "<!-- session page views: ".$_SESSION['page_views']."line ".__LINE__." -->\n";
$_SESSION['view_poem'] = 0;
if (!isset(
$_SESSION['page_views'])) {
   
$_SESSION['page_views'] = 1;
} else {
   
$_SESSION['page_views']++;
}
//echo "<!-- session page views: ".$_SESSION['page_views']."line ".__LINE__." -->\n";
$self $_SERVER['PHP_SELF'];
$url $_SERVER['REQUEST_URI'];
$visitor_ip $_SERVER['REMOTE_ADDR'];
if (@
$_SESSION['host']){
    
$host $_SESSION['host'];
}else{
    
$host gethostbyaddr($visitor_ip);
    
$_SESSION['host'] = $host;
}
if(
$_GET['bite'] ){
$bite $_GET['bite'];
}
if (!
$_SERVER['QUERY_STRING']){
echo 
"<!-- session page views: ".$_SESSION['page_views']."line ".__LINE__." -->\n";
$bite 0;
$_SESSION['page_views'] = 1;
$_SESSION['session_excerpt'] ="";
$_SESSION['num_clicks']  = NULL;
}
//echo "<!-- session page views: ".$_SESSION['page_views']."line ".__LINE__." -->\n";
$page_views $_SESSION['page_views'];
if (
$_SESSION['num_clicks']){
$num_clicks $_SESSION['num_clicks'];
}else{
$num_clicks rand (3,14);
$_SESSION['num_clicks'] = $num_clicks;
}
$sess_id session_id();
//echo "<!-- session page views: ".$_SESSION['page_views']."line ".__LINE__." -->\n";
//this function is used to move the colors closer to monochromatic.  $src is the orginal value of r, g, or b.  $dest is the mean of the rgb values.  $step is the number of page views so far this session
function step_closer($src,$dest,$step){
global 
$num_clicks;
$a $dest $src;
$b round($a/($num_clicks+1));
$c $b*$step;
$d $src $c;
return 
$d;
}
//this function shifts the colors toward black with each successive page view
function shift_black($color_value$switch){
global 
$page_views;
global 
$num_clicks;
$mult round((255/$num_clicks)*.60);
if (!
$switch){
        
$color_value $color_value - (($page_views)*$mult);
            if (
$color_value 0){
            
$color_value 0;
            }
        }else{
        
$color_value $color_value - (($page_views)*(round($mult/2)));
            if (
$color_value 0){
            
$color_value 0;
            }
        }        
return 
$color_value;
}
//end function


include("911text.php");
$db_excerpt addslashes($excerpt);
if (
$page_views == 1){
$_SESSION['session_excerpt'] .="<h1>$excerpt</h1>\n";
}else{
$_SESSION['session_excerpt'] .="<p>$excerpt</p>\n";
}
//as part of the project, OT!OM! Productions tracks the visits to "bite size," as well as the phrases generated in each page request.  The information recorded is similar to that recorded in standard web log files.  For security reasons, the mysql query is kept in separate include files.

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

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

//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;
}

//this is another function for selecting a contrasting color.  We don't actually use this one.  If the value of the background color (r, g, or b) was near 128, it didn't work well, so we needed to stick some more randomness in.
function add_inverse($number){
$number 255-$number;
     if (
$number 119 && $number <128){
        
$number rand (0,119);
    }
    if (
$number 127 && $number <135){
        
$number rand (135,255);
    } 
return 
$number;
}
if (@
$_GET['r'] != ""){
$rp$_GET['r'];
}else{
$rp rand (0,255);
}
//select the persistent background colors
if (@$_GET['g'] != ""){
$gp$_GET['g'];
}else{
$gp rand (0,255);
}
if (@
$_GET['b']!= ""){
$bp$_GET['b'];
}else{
$bp rand (0,255);
}


//initialize the $col_scheme array
$col_schemes[] = "";

//use the length of the excerpt string to determine the number of col_schemes
$max_col $length +1;

//in case the page gets very large, set a maximum number of col_schemes
if ($max_col 101){
$max_col 101
}

//now generate the col_schemes
for ($i 0$i <= $max_col$i++) {

    
$r rand (0,255);
    
$g rand (0,255);
    
$b rand (0,255);
    
//find the mean of rgb, and move each value closer to it
    
$mono_col round(($r+$g+$b)/3);
    
$r step_closer($r,$mono_col,$page_views-1);
    
$g step_closer($g,$mono_col,$page_views-1);
    
$b step_closer($b,$mono_col,$page_views-1);  
    
//shift rgb toward black        
    
$r shift_black($r,0);
    
$g shift_black($g,0);
    
$b shift_black($b,0);  
    
//define the contrasting font color
    
$sr wheel($r);
    
$sg wheel($g);
    
$sb wheel($b);
    
//shift the font color toward black
    
$sr shift_black($sr,1);
    
$sg shift_black($sg,1);
    
$sb shift_black($sb,1); 
     
    
//now add the values to the array
     
$col_schemes[$i]['r'] = $r;
    
$col_schemes[$i]['g'] = $g;
    
$col_schemes[$i]['b'] = $b;
    
$col_schemes[$i]['sr'] = $sr;
    
$col_schemes[$i]['sg'] = $sg;
    
$col_schemes[$i]['sb'] = $sb;
    
$col_schemes[$i]['mono_col'] = $mono_col
}

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

?>
<html>
<head>
<?php 
echo "<!-- page_views: $page_views -->\n";
?>
<title>bite size: <?php echo $title_desc?> from 9/11: <?php echo $title_excerpt?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Description" content="<?php echo $meta_excerpt?>">
<meta name="Keywords" content="<?php echo $meta_excerpt?>">
<link rel="shortcut icon" href="/favicon.ico" />
<style type="text/css">
<!--
body, table, tr, td {margin:0px;padding:0px;background-color:<?php  echo "rgb($rp,$gp,$bp)" ?>}

.outer_box{float:left;height:90px;width:90px;text-align:center;background-color:<?php  echo "rgb($rp,$gp,$bp)" ?>}
.inner_box{height:50px;width:50px;margin:20px;text-align:center;font-size:32px;padding:5px}
div.phrase{display:none;height:0px;overflow:hidden;visibility:hidden}
a{display:block;overflow:hidden;height:50px;width:50px;margin:20px;text-align:center;padding 0px 0px 0px 0px;text-decoration:none;} 
.end_message a:link{overflow:visible;height:20px;width:100%;display:inline;background-color:transparent;color:<?php  echo "rgb(".wheel($rp).",".wheel($gp).",".wheel($bp).")" ?>}
.end_message a:visited{overflow:visible;height:20px;width:100%;display:inline;background-color:transparent;color:<?php  echo "rgb(".wheel($rp).",".wheel($gp).",".wheel($bp).")" ?>}
.end_message a:active{overflow:visible;height:20px;width:100%;display:inline;background-color:transparent;;color:<?php  echo "rgb(".wheel($rp).",".wheel($gp).",".wheel($bp).")" ?>}
.end_message a:hover{overflow:visible;height:20px;width:100%;display:inline;background-color:transparent;;color:rgb(200,200,200);}
.start_message{position:absolute;top:80px;font-weight:bold;font-size:12px;font-family:arial, helvetica,sans-serif;letter-spacing:1px;left:0px;width:100%;text-align:center;background-color:transparent;color:<?php  echo "rgb(".wheel($rp).",".wheel($gp).",".wheel($bp).")" ?>}
.end_message{position:absolute;top:0px;left:0px;    width:100%;height:100%;z-index:1;padding-top:80px;padding:auto;font-weight:bold;font-size:12px;font-family:arial, helvetica, sans-serif;letter-spacing:1px;left:0px;width:100%;text-align:center;background-color:transparent;color:<?php  echo "rgb(".wheel($rp).",".wheel($gp).",".wheel($bp).")" ?>
}
-->
</style>
<style type="text/css" media="print">
<!--
body {font-size:14pt;}}
.outer_box{display:none;visibility:hidden;}
.inner_box{display:none;visibility:hidden;}
.start_message{display:none;visibility:hidden;}
.end_message{display:none;visibility:hidden;}
div.phrase{text-align:center;margin:5%;display:block;visibility:visible;font-family:verdana,sans-serif;font-size:12pt;}
div.phrase p{visibility:hidden;text-align:center;font-family:verdana,sans-serif;font-size:12pt;}

-->
</style>
</head>

<body >
<div class="phrase"><?php 
//in case someone wants to print the page, include the poem so far
echo $_SESSION['session_excerpt']; ?></div>
<?php
 
if ($page_views == 1){?>
<div class="start_message" ><!-- build a poem  --><?php echo $num_clicks?> clicks</div>
<?php }
 if (
$_SESSION['page_views'] > $num_clicks){?>
<div class="end_message" ><p><a href="show_poem.php">view poem</a><a href="bite_size.php">start over</a></p></div>
<?php }?>

<table width="100%" height="90%"><tr align="center"><td align="center" valign="middle">
<script>
<!-- 
//this javascript sets the left boundary of the float:left div tags
var length = <?php echo $length ?>;
if (90*(length) < document.body.offsetWidth){
var left_offset = (document.body.offsetWidth-(90*length))-11;

}else{
var left_offset = ((document.body.offsetWidth-90)%90)+45;
}
left_offset = (left_offset/2);
document.write("<div style=\"padding:0px;margin:0px;margin-left:"+left_offset+"px\">");
 -->
</script>
<?php
$count 
count($col_schemes);

//now loop through the excerpt, creating the letter boxes.  
for ($i 0$i $length$i++) {
    
$modi $i%$count;
    
$pagei $i%$num_clicks;
    
     
$r $col_schemes[$modi]['r'];
     
$g $col_schemes[$modi]['g'];
     
$b$col_schemes[$modi]['b'];
     
$sr $col_schemes[$modi]['sr'];
     
$sg $col_schemes[$modi]['sg'];
     
$sb$col_schemes[$modi]['sb'];
?>

<div class="outer_box">
<?php echo "<!-- mono_col: "$col_schemes[$modi]['mono_col']." -->\n" ?>
<a style="font-size:28pt;padding-top:0px;padding-bottom:0px;background-color:<?php  echo "rgb($r,$g,$b)" ?>;color:<?php  echo "rgb($sr,$sg,$sb)" ?>;"href="<?php echo $self?>?bite=<?php echo $pagei?>&letter=<?php echo $characters[$i];?>&r=<?php  echo $r?>&g=<?php  echo $g?>&b=<?php  echo $b?>"><?php echo $characters[$i];?></a>
</div> 

<?php  
}//end for ($i = 0; $i < $length; $i++)

//now add the final boxes--the links to the report, the statement, and the Creative Commons declaration, if the string is above a certain length
if ($word_length >= $show_tools && $page_views $num_clicks)
{
$modi $i%$count;
 echo 
"<!--index: $i col_scheme: $modi -->\n";
$r $col_schemes[$i%$count]['r'];
 
$g $col_schemes[$i%$count]['g'];
 
$b$col_schemes[$i%$count]['b'];
 
$sr $col_schemes[$i%$count]['sr'];
 
$sg $col_schemes[$i%$count]['sg'];
 
$sb$col_schemes[$i%$count]['sb'];
 
?>
<div class="outer_box">
<a  style="display:block;overflow:hidden;height:50px;width:50px;margin:20px;text-align:center;font-size:11pt;padding:auto;font-weight:bold;background-color:<?php  echo "rgb($r,$g,$b)" ?>;color:<?php  echo "rgb($sr,$sg,$sb)" ?>;text-decoration:none;"href="http://www.9-11commission.gov/report/index.htm" target="_blank"><br>9/11</a>
</div> 
<?php  
$i
++;
$modi $i%$count;
echo 
"<!--index: $i col_scheme: $modi -->\n";
$r $col_schemes[$i%$count]['r'];
 
$g $col_schemes[$i%$count]['g'];
 
$b$col_schemes[$i%$count]['b'];
 
$sr $col_schemes[$i%$count]['sr'];
 
$sg $col_schemes[$i%$count]['sg'];
 
$sb$col_schemes[$i%$count]['sb'];
 
?>
<div class="outer_box">
<a style="line-spacing:.5;font-size:11pt;font-weight:bold;padding:auto;background-color:<?php  echo "rgb($r,$g,$b)" ?>;color:<?php  echo "rgb($sr,$sg,$sb)" ?>;text-decoration:none;"href="/bite_size/statement.php">&nbsp;<br>???</a>
</div> 
<?php  
$i
++;
$modi $i%$count;
echo 
"<!--index: $i col_scheme: $modi -->\n";
$r $col_schemes[$i%$count]['r'];
 
$g $col_schemes[$i%$count]['g'];
 
$b$col_schemes[$i%$count]['b'];
 
$sr $col_schemes[$i%$count]['sr'];
 
$sg $col_schemes[$i%$count]['sg'];
 
$sb$col_schemes[$i%$count]['sb'];
 
?>
<div class="outer_box">
<a style="line-spacing:.5;font-size:11pt;font-weight:bold;background-color:<?php  echo "rgb($r,$g,$b)" ?>;color:<?php  echo "rgb($sr,$sg,$sb)" ?>;text-decoration:none;" href="http://creativecommons.org/licenses/publicdomain/" target="_blank">&nbsp;<br>CC</a>
</div> 
<?php 
}// end if ($word_length < $show_tools)
/* echo"<!-- ";
print_r($_SESSION);
print_r($_SERVER);
echo" -->"; */
?>
</div>
</td></tr></table>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-400288-1";
urchinTracker();
</script>
</body>
</html>