Location: PHPKode > projects > hnGuestbook > guestbook/gb_adminview.php
<?
session_start(); 
include("gb_config.php");
if (isset($_SESSION['admin'])) {

$page = $_REQUEST['page'];


if (!(file_exists($data_file))){ 
fopen($data_file,"w") or die("Can't open data file");;
$data=file($data_file);	
}else{
fopen($data_file,"r");
$data=file($data_file);	
}

$count = count($data);

$total_pages = ceil($count/$messages_per_page); 

echo ("$la2 $count $la3. <br><br>");


//Make pages
if (isset($page) AND $page > 0)
  {
    if ($page > $total_pages) {
      $page = $total_pages; 
    } else {
      $begin=$page*$messages_per_page - $messages_per_page; 
    }
} else {
  $page = 1; 
  $begin = 0; 
  }

$next_page = $page + 1; 
$prev_page   = $page - 1;

  if ($prev_page < 1)
  {
    $prev_page = 1;
  } 

  if ($next_page > $total_pages)
  {
    $next_page = $total_pages;
  } 

if($count != 0){  
echo("$la4 $page $la5 $total_pages <br><br>");  

if($page == 1 && $total_pages == 1){
echo ("<font color = \"#CCCCCC\">$la6</font> | <font color = \"#CCCCCC\">$la7</font>"); 
}else if($page == $prev_page){  
echo ("<font color = \"#CCCCCC\">$la6</font> | <a href=\"JavaScript:ajax('POST','gb_adminview.php','page','$next_page')\">$la7</a>"); 
}else if($page == $next_page){
echo ("<a href=\"JavaScript:ajax('POST','gb_adminview.php','page','$prev_page')\">$la6</a> | <font color = \"#CCCCCC\">$la7</font>"); 
}else{
echo ("<a href=\"JavaScript:ajax('POST','gb_adminview.php','page','$prev_page')\">$la6</a> | <a href=\"JavaScript:ajax('POST','gb_adminview.php','page','$next_page')\">$la7</a>"); 
}

if($total_pages == 1){
echo(" | <font color = \"#CCCCCC\">$la8</font> | <font color = \"#CCCCCC\">$la9</font>");
}else{
echo(" | <a href=\"JavaScript:ajax('POST','gb_adminview.php','page','1')\">$la8</a> | <a href=\"JavaScript:ajax('POST','gb_adminview.php','page','$total_pages')\">$la9</a>");
}

echo(" | <a href=\"gb_admin.php?action=logout\"><b>$la24</b></a> <br> <br><a href=\"javascript:newwindow('gb_functions.php?banip=banip','banip',230,380)\" >$la39</a> <br><br>");
}

echo("<form method=\"POST\" action=\"gb_admin.php\">");
echo("<input type=\"hidden\" name=\"action\" value=\"delmul\"><input type=\"hidden\" name=\"page\" value=\"$page\">");

if($newest_on_top == 1)
$data = array_reverse($data);


$entries=array_slice($data,$begin,$messages_per_page);

$cont1=count($entries)-1;
$cont2=0;
$line_num = count($data) - ($page*$messages_per_page) + $messages_per_page;

while ($cont1>=$cont2) {
	$entry=$entries[$cont2];
	$entry=explode("|",$entry);
	$name = $entry[0];
	$homepage = $entry[1];
	$email = $entry[2];
	$message = $entry[3];
	$ip = $entry[4];
	$stime = $entry[5];
	$browser = $entry[6]; 
	
	$stime = date('m/d/y - g:i A', $stime);
	
	$message = wordwrap($message, $word_wrap, "<br>", true);
	
	//Smiley
	$message = ereg_replace(":p", " <img src=\"images/s1.gif\" alt=\":p\" border=\"0\"> ", $message);
	$message = ereg_replace(":)", " <img src=\"images/s2.gif\" alt=\":)\" border=\"0\"> ", $message);
	$message = ereg_replace(":a", " <img src=\"images/s3.gif\" alt=\":a\" border=\"0\"> ", $message);
	$message = ereg_replace(":o", " <img src=\"images/s4.gif\" alt=\":o\" border=\"0\"> ", $message);
	$message = ereg_replace(":s", " <img src=\"images/s5.gif\" alt=\":s\" border=\"0\"> ", $message);
	$message = ereg_replace(":r", " <img src=\"images/s6.gif\" alt=\":r\" border=\"0\"> ", $message);
	$message = ereg_replace(":v", " <img src=\"images/s7.gif\" alt=\":v\" border=\"0\"> ", $message);
	$message = ereg_replace(":h", " <img src=\"images/s8.gif\" alt=\":h\" border=\"0\"> ", $message);
	$message = ereg_replace(";)", " <img src=\"images/s9.gif\" alt=\";)\" border=\"0\"> ", $message);
	$message = ereg_replace(":m", " <img src=\"images/s10.gif\" alt=\":m\" border=\"0\"> ", $message);
	
	//Fix the "&" bug
	$message = str_replace("^amp^", "&",$message);
	$name = str_replace("^amp^", "&",$name);
	
	//URL
	if($convert_link == 1)
	$message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $message);
	
	if($homepage != 'http://'){
	$vhomepage = "<a href=\"$homepage\" target=\"_blank\"><img src=\"images/home.gif\" alt=\"$la13\" border=\"0\"></a>";
	}else{
	$vhomepage = "<img src=\"images/home2.gif\" alt=\"$la13\" border=\"0\">";
	}
	
	if($email){
	$email = str_replace('@','[at]',$email);
	$vemail = "<a href=\"mailto:$email\" target=\"_blank\"><img src=\"images/email.gif\" alt=\"$la12\" border=\"0\"></a>";
	}else{
	$vemail = "<img src=\"images/email2.gif\" alt=\"$la12\" border=\"0\">";
	}
	
	echo ("<div class=\"guestbook_top\"> <input type=\"checkbox\" name=\"delentry[]\" value=\"$line_num\"> <img src=\"images/person.gif\" alt=\"$name\" title=\"$name\"> <b>$name</b> <font size = 1>$la26 $stime </font></div><div class=\"guestbook\"> <div align=\"right\" style=\"padding:2px;\"> $vhomepage $vemail <font size = 1><b>IP:</b> $ip <a href=\"javascript:newwindow('gb_functions.php?banip=$ip','banip',230,380)\" >$la35</a> </font> <img src=\"images/browser.gif\" alt=\"$browser\" title=\"$browser\" border=\"0\"> </div> $message<br><br></div>");

	$cont2++;
	$line_num--;
}

echo ("<input type=\"submit\" value=\"$la25\" name=\"B1\">");
echo ("</form>");

if($count != 0){  
echo ("$la15 ");

//Print out page number

if (($page - 10) <= 0)
$rp = ($page - 11) * -1;

if (($total_pages - $page) < 10)
$lp = 10 + ($total_pages - $page) * -1;


if ($page != 1 && $page > 11)
echo("<a href=\"JavaScript:ajax('POST','gb_adminview.php','page','1')\">1</a> ... ");

for ($i=$page - (10 + $lp); $i < $page; $i++){
	
	if ($i < $page && $i > 0){
		echo("<a href=\"JavaScript:ajax('POST','gb_adminview.php','page','$i')\">$i</a> ");
	}
}


for ($i=$page; $i <= $page + 10 + $rp; $i++){
	if($page==$i){
		echo("<b>$i</b> ");
	}else if ($i >= $page && $i <= $total_pages){
		echo("<a href=\"JavaScript:ajax('POST','gb_adminview.php','page','$i')\">$i</a> ");
	}
}

if ($page != $total_pages && $page < $total_pages - 10)
echo(" ... <a href=\"JavaScript:ajax('POST','gb_adminview.php','page','$total_pages')\">$total_pages</a>");

}


}else{
echo("$la23");
}



?>

Return current item: hnGuestbook