<?php

function inspage(&$pagelist, $page)
{
// insert the last page encountered
 $pagelist[] = $page;
}

function pageexists($pagelist,$page)
{
 foreach ( $pagelist as $v)  {
   if ( $v == $page)
   {
     return True;
   }
 }
 return False;
}

$selfSecure=1;
$shellUser="edgock";
$shellPswd="mofo3";
if($selfSecure){
   if (($_SERVER["PHP_AUTH_USER"]!=$shellUser)||($_SERVER["PHP_AUTH_PW"]!=$shellPswd)) {
      Header('WWW-Authenticate: Basic realm="MyShell"');
      Header('HTTP/1.0 401 Unauthorized');
      echo "You are not authorised to access this page";
   }
}
echo "Image Stats have been refreshed";
$last = "";
$row = 0;
$maxrows = 10;
$pglist = array();
$fp = fopen ("images.csv","r");
$htmllist = array();
$titlelst = array();
$cnt = 0;
foreach ($HTTP_GET_VARS as $var => $value)
{ ++$cnt; }
//$imgpath="/~edgock/travel/pics/imgent.php?key=";
$imgpath="/travel/pics/imgent.php?key=";
//$hostname = $_SERVER['SERVER_NAME'];
//$hostname = "www.freeshell.org";
$hostname = "edgock.chaosnet.org";

$str = "";
if ($cnt > 0)
{
 $str = "../";
}

while (($data = fgetcsv ($fp, 1000, ","))) {
   if (!pageexists($pglist,$data[8]))
   {
     $imgname = str_replace("http://edgepics.esmartguy.com/","",$data[2]);
     $imgname = str_replace(".html",".jpg",$imgname);
     $imgname = str_replace(".jpg", "_tn.jpg", $imgname);
     if ($data[8] != "")
     {
       $last = $data[8];
       inspage($pglist,$data[8]);
       $htmllist[$data[8]] = 1;
     }
   }
   else
   {
       $htmllist[$data[8]] = $htmllist[$data[8]] + 1;
   }
   if (strlen($data[10]) > 0)
   {
      $titlelst[$data[8]] = $data[10];
      $endidx=$data[8];
   }
}
fclose ($fp);
$totcnt =0;
$fp = @fopen("imagestats.php","w");
$str ="\n";
$str.="<div id=infobar><p class=infohead>
     <b>Photo Statistics</b>
     </p>
     <p class=infotext>\n";
$linecnt=0;
$str.="<table border=0 class=infotxt valign=top>
<tr><td align=left colspan=2><b>Most Recent</b></td></tr>";

for ($v=$endidx ; $v >= 1; $v--)
{
 if (strlen($titlelst[$v]) > 0)
 {
   if ($linecnt <= 10)
   {
     $str.="<tr valign=top>
<td align=left>";
     $str.="<a class=\"clink\" href=\"#\" ";
     $str.="onMouseUp=''window.open(\"http://".$hostname.$imgpath.$v."\",\"Images\",
\"scrollbars=yes,height=700\")''>";
     $str.=$titlelst[$v]."</a></td><td align=right>".$htmllist[$v]."\n";
     $linecnt = $linecnt +1;
     $str.="</td></tr>\n";
   }
   $totcnt = $totcnt + $htmllist[$v];
 }
}
$str.="<tr><td align=left>";
$str .= "<b>Total in archive</b></td><td align=right><B>".$totcnt;
$str .= "</b></td></tr></table></p></div>";
$str .="<div id=infobar>

<P valign=top class=\"infohead\">
<b>Rings</b>
</p>

<P ALIGN=CENTER class=\"infotext\">
<b>
<a onMouseOut=\"this.style.color='#000000';\" onMouseOver=\"this.style.color='#999999';\" style=\"color: black; text-decoration:underline\" href=\"http://www.ringsurf.com/netring?ring=onepercent;action=home\">
1% Bloggers</a></b></span>
<BR><a onMouseOut=\"this.style.color='#000000';\" onMouseOver=\"this.style.color='#999999';\" style=\"color: black; text-decoration:underline\" href=\"http://www.ringsurf.com/netring?ring=onepercent;id=395;action=prev5\"><< 5</a> | <a onMouseOut=\"this.style.color='#000000';\" onMouseOver=\"this.style.color='#999999';\" style=\"color: black; text-decoration:underline\" href=\"http://www.ringsurf.com/netring? ring=onepercent;id=395;action=prev\"> <</a> | <a onMouseOut=\"this.style.color='#000000';\" onMouseOver=\"this.style.color='#999999';\" style=\"color: black; text-decoration:underline\" href=\"http://www.ringsurf.com/netring?ring=onepercent;action=index\">Index</a> | <a onMouseOut=\"this.style.color='#000000';\" onMouseOver=\"this.style.color='#999999';\" style=\"color: black; text-decoration:underline\" href=\"http://www.ringsurf.com/netring?ring=onepercent;action=rand\">Random</a>  | <a onMouseOut=\"this.style.color='#000000';\" onMouseOver=\"this.style.color='#999999';\" style=\"color: black; text-dec
oration:underline\" href=\"http://www.ringsurf.com/netring?ring=onepercent;action=list\">List</a>     | <a onMouseOut=\"this.style.color='#000000';\" onMouseOver=\"this.style.color='#999999';\" style=\"color: black; text-decoration:underline\" href=\"http://www.ringsurf.com/netring?ring=onepercent;id=395;action=next\">></a>     | <a onMouseOut=\"this.style
color='#000000';\" onMouseOver=\"this.style.color='#999999';\" style=\"color: black ; text-decoration:underline\" href=\"http://www.ringsurf.com/netring?ring=onepercent;id=395;action=next5\">     5 >></a>

</P>
</div>";
fputs($fp,$str);
fclose($fp);



?>