<?php

/*
    function tail()

    returns $tail_size lines from $file
    like a unix tail, handy for log files
    
    corz.org 2004
    
*/
/*
    example..    */
    
$show_lines = 5;

$pre_bit = '/usr/local/www/www.lagged.za.net/tmp/tracker/';
$post_bit = '.log';
$logs_date = date('Y-m-d');
#$refs_log = '/usr/local/www/www.lagged.za.net/tmp/tracker/2007-03-06.log';
$refs_log = $pre_bit.$logs_date.$post_bit;

echo '<b>Last ',($show_lines - 1),' positions of Estaga</b><br>
<textarea name="refs_tail" rows=6 cols=130 style="font:12px courier">'
,tail($refs_log, $show_lines),'</textarea>';

$gmapsurl = "/usr/local/www/www.lagged.za.net/tmp/tracker/.lastgooglemaps.url";
$fh = fopen($gmapsurl, 'r');
$theData = fread($fh, 200);
fclose($fh);
echo "<p><a href=\"$theData\">Google Map URL</a></p>";


/*
function tail($file,$tail_size)    */
function tail($file,$tail_size) {
    
    if(file_exists($file)) {
        $file_contents = implode('',file($file));
        $lines = explode("\n", $file_contents);
        $line_count = count($lines);
        
        for($i=($line_count-$tail_size);$i <= $line_count;$i++) {
            $tail_string .= $lines[$i]."\n";
        }
    } else {
        $tail_string = 'couldn\'t find the log file';
    }    
return $tail_string;
}/* end function tail($file,$tail_size)
*/

?>

