<?php
    
    
function displayChart(){
        
set_time_limit (90);
        
$goalFile $_GET['file'];
        
$fileArray file("/home/jbakse/access_log");
        
        
$chartLabels = Array();
        
$charValues = Array();
        
        
$prevDate "0"//holds the date of last found entry
        
$hitsPerDay 0//number of hits found on this day
        
$chartEntry 0//a counter to remember number of days entered in the arrays
    
    
        
for ($whatLine 0$whatLine<count($fileArray); $whatLine ++){
            
preg_match "/GET .*? HTTP/"$fileArray[$whatLine], $get);    //find the part of the log entry that tells what file was requested (GET)
            
            
if (strpos($get[0],$goalFile)){                                    //check if the requested text is in the GET request
            
                
$pattern "/\[([0-9]+\/.*?\/[0-9]+)\:/";                    //pull the date from the request
                
$dateFound =  preg_match $pattern$fileArray[$whatLine], $match);
                
$matchDate $match[1];
                
                if (
$prevDate == $matchDate){
                    
$hitsPerDay++;                                            //we got a match, count it
                
                
}else{
                    if (
$prevDate != "0"){                                    //if its the last match of the day, record the day and count
                        
$chartLabels[$chartEntry] = $prevDate;
                        
$chartValues[$chartEntry] = $hitsPerDay;
                        
$chartEntry++;
                    }
                    
$prevDate $matchDate;
                    
$hitsPerDay 0;
                }
            }
        }
        
        
renderChart(30,$chartValues,$chartLabels"Hits Per Day: <strong>".$goalFile."</strong>");
    }
    
    
    function 
renderChart($height$chartValues$chartLabels$title){
        
        
$pad "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        
        
        
        
////////////////////////////////////////////////
        //
        //    Print Title
        //
        ////////////////////////////////////////////////
        
        //print ("<span class = \"chartData\">");
        //print ("$pad$title<BR><BR>\n");
        //print ("</span>");
        
        
        ////////////////////////////////////////////////
        //
        //    Determine Vertical Scale
        //
        ////////////////////////////////////////////////
        
        
$maxValue 0;
        for (
$n=0$n<count($chartValues); $n++){
                if (
$chartValues[$n] > $maxValue$maxValue $chartValues[$n];
        }
        
//$maxValue = ceil($maxValue/100) * 100;
        
$valuePerRow floor($maxValue/$height);
        
        
        
////////////////////////////////////////////////
        //
        //    Print Graph
        //
        ////////////////////////////////////////////////
    
    
        
for ($row 0$row $height$row++){
            
$number sprintf("%'.5d&nbsp;|"$maxValue  - ($row*$valuePerRow));
            
$number preg_replace("/\./","&nbsp;",$number);
            print (
"<span class = \"chartLabel\">");
            print (
$number);
            print (
"</span>");
            print (
"<span class = \"chartData\">");
            for(
$col 0$col count($chartValues); $col ++){
                if     (
$chartValues[$col] > $maxValue  - ($row*$valuePerRow)) {
                    print (
"*&nbsp;");
                }else{
                    print (
"&nbsp;&nbsp;");
                }
                    
            }
            print (
"<BR>\n");
            print (
"</span>");
        }
        
        
        
////////////////////////////////////////////////
        //
        //    Print Vert Divider
        //
        ////////////////////////////////////////////////
    
        
        
print ("<span class = \"chartLabel\">");
        print (
$pad);
        for(
$col 0$col count($chartValues); $col ++){
            print(
"--");
        }
        print ( 
"&nbsp;&nbsp;&nbsp;" ); //this pad is just to put some marign on the right side in the div.
        
print ("<BR>\n");
        print (
"</span>");
        
        
////////////////////////////////////////////////
        //
        //    Print Labels
        //
        ////////////////////////////////////////////////
    
        
print ("<span class = \"chartLabel\">");
        for (
$row 0$row 11$row++){
            print (
$pad);
            
//for ($n = 0; $n < $row; $n++){
            //    print("&nbsp;");
            //}
            
for($col 0$col count($chartLabels); $col ++){
                if (
substr ($chartLabels[$col], $row 1) == "/"){
                    print(
"&nbsp;");
                }else{
                    print(
substr ($chartLabels[$col], $row 1));
                }
                print(
"&nbsp;");
            }
            print (
"<BR>\n");
        }
        print (
"</span>");
    }
?>




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>Volcano Kit Log Plotter</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <style type="text/css">
            <!--
                .chartData {
                    font-family: Monaco, monospace;
                    font-size: 9px;
                    line-height: 9px;
                    color: #FF0000;
                }
                
                .chartLabel {
                    font-family: Monaco, monospace;
                    font-size: 9px;
                    line-height: 9px;
                    color: #FF8888;
                }
                
                .table {
                    font-family: Arial, Helvetica, sans-serif;
                    font-size: 9px;
                    border:1px solid #FF0000;
                                
                }
                            
                .tableLike {
                            
                    font-family: Arial, Helvetica, sans-serif;
                    font-size: 9px;    
                    padding-left: 5px;
                }
                
                a {
                    color: #000000;
                }
                            
            -->
        </style>
    </head>

<body>
        <div id="aboutBox" style="position:absolute; left:25; top:50; width:150px; height:500; z-index:1"> 
            <table class="table" bgcolor="#EEEEFF" width="150" border="0" cellspacing="0" cellpadding="2">
                <tr bgcolor="#FF0000"><td colspan = '3'><font color = #FFFFFF>ASCII Log Plotter:</font></td></tr>
                <tr><td colspan = '3'>&nbsp;</td></tr>
                <tr><td class = "tableLike">
                     This script will look through an apache log file and count how many times a user specified file is accessed each day. The results are returned as a ascii graph. Days without hits are omitted from the graph.<BR><BR>
                     Track the popularity of these parts of Volcano Kit:<BR><BR>
                     &nbsp;&nbsp;<a href ="http://www.volcanokit.com/volcanokit2/logPlot/index.php?file=/volcanokit2/index.php">VK2 Main Page</a><BR><BR>
                     &nbsp;&nbsp;<a href ="http://www.volcanokit.com/volcanokit2/logPlot/index.php?file=/volcanokit2/beepmaker/beepmaker16.php">the beepmaker</a><BR><BR>
                     &nbsp;&nbsp;<a href ="http://www.volcanokit.com/volcanokit2/logPlot/index.php?file=vkitVisualizer">VK iTunes Visualizer</a><BR><BR>
                     &nbsp;&nbsp;<a href ="http://www.volcanokit.com/volcanokit2/logPlot/index.php?file=vkit5x5.sit">5x5 Screen Saver</a><BR><BR>
                     &nbsp;&nbsp;<a href ="http://www.volcanokit.com/volcanokit2/logPlot/index.php?file=treadsOfFury">Treads of Fury</a> (<a href = "http://www.minefieldinteractive.com">MI</a>)<BR><BR>
                     <BR><BR>
                     <form name="form1" method="get" action="index.php">
                     Or enter another page:<BR>
                          <input name="file" type="text" id="file">
                        </form>
                    
                     <BR><BR><BR><BR>Feel free to use this code any way you wish.
                       <BR><BR><BR><BR><BR>
                       <a href = "showSource.php">view source</a><br>
                       
                      
                  </td></tr>
                  <tr ><td colspan = '3'>&nbsp;</td></tr>
                  </table>
        </div>
        
        <div id="formDiv" align="center" style="position:absolute; left:200; top:50; width:200px; height:200px; z-index:1"> 
                  <table class="table" bgcolor="#EEEEFF" width="200" border="0" cellspacing="0" cellpadding="2">
                <tr bgcolor="#FF0000"><td colspan = '3'><font color = #FFFFFF>Hits Per Day:&nbsp;&nbsp;<?php print($_GET['file']);?></font></td></tr>
                <tr><td colspan = '3'>&nbsp;</td></tr>
                <tr><td>
                      <?php displayChart();?>
                  </td></tr>
                  <tr ><td colspan = '3'>&nbsp;</td></tr>
                  </table>
        </div>
        
        



</body>
</html>