Location: PHPKode > projects > OpenGB Guestbook > gb/index.php
<?php
/* index.php
   Copyright (C) 2008  James Crickmere

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   
 */
 

	include('init.inc.php');






// how many rows to show per page
$rowsPerPage = 10;
if(isset($_GET['n']))
	$rowsPerPage = $_GET['n'];
	

// by default we show first page
$page_num = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['p']))
{
    $page_num = $_GET['p'];
}

// counting the offset
$offset = ($page_num - 1) * $rowsPerPage;

$post_query = mysql_query("SELECT * FROM `" . $gb_mysql_dbname . "`.`" . $gb_mysql_guestbook . "` ORDER BY id DESC LIMIT $offset, $rowsPerPage");
$html = '<hr size="1" class="gb_hr" />';
for($x=0;$post = mysql_fetch_array($post_query);$x++) {
	$html .= '<span class="gb_post_top"><b>Name: </b>' . $post['name'] . '<br />' . "\n";
	$html .= '<b>Date: </b>' . $post['date'] . '<br />' . "\n";
	if($post['website'] != null)
		$html .= '<b>Website: </b><a href="' . $post['website'] . '" class="gb_link" target="_blank">' . $post['website'] . '</a><br />' . "\n";
	if($post['show_email'] == true)
		$html .= '<b>Email: </b>' . $post['email'] . '<br />' . "\n";
	$html .= '</span><div class="gb_post_comment">';
	$html .= $post['comment'] . '</div><br />' . "\n";
	$html .= '<div  style="text-align:right;"><span class="gb_post_bottom">';
	if($post['email'] != null)
		$html .= '<a href="' . $gb_root . 'gb-admin/mail.php?id=' . $post['id'] . '"><img src="' . $gb_root . 'images/icons/mail_write_16.png" alt="Email User" title="Email User" border="0" /></a>';
	$html .= '<a href="' . $gb_root . 'gb-admin/delete.php?id=' . $post['id'] . '"><img src="' . $gb_root . 'images/icons/cancel_16.png" alt="Delete Post" title="Delete Post" border="0" /></a><a href="' . $gb_root . 'gb-admin/block.php?id=' . $post['id'] . '"><img src="' . $gb_root . 'images/icons/user_delete_16.png" alt="Block User" title="Block User" border="0" /></a></span></div><hr size="1" class="gb_hr" />' . "\n";
	if($x > 8) break;
}

$result = mysql_query("SELECT * FROM `$gb_mysql_dbname`.`$gb_mysql_guestbook");
$num_rows = mysql_num_rows($result);
$html .= '<br /><br />' . "\n";
$html .= '<div class="gb_navbar">';
if($page_num != 1) {
	$prev_page = $page_num - 1;
	$html .= "<a href=\"{$_SERVER['PHP_SELF']}?p=$prev_page&amp;n=" . $rowsPerPage . "\">&lt;&lt; Prev</a> ";
}
$html .= "Page $page_num of " . ceil($num_rows/$rowsPerPage);
if($page_num < ceil($num_rows/$rowsPerPage)) {
	$next_page = $page_num + 1;
	$html .= " <a href=\"{$_SERVER['PHP_SELF']}?p=$next_page&amp;n=" . $rowsPerPage . "\">Next &gt;&gt;</a>";
}
$html .= '<br /><form action="' . $_SERVER['PHP_SELF'] . '" method="get">Display <input type="text" name="n" value="' . $rowsPerPage . '" size="2" style="font-size:10pt; color:black;" /> results per page <input type="submit" value="Go" style="font-size:10pt; color:black;" /></form>';
$html .= '</div>';

mysql_close();



if($settings['analytics_code'] != null)
	$html .= '<script type="text/javascript">
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
		</script>
		<script type="text/javascript">
		var pageTracker = _gat._getTracker("' . $settings['analytics_code'] . '");
		pageTracker._trackPageview();
		</script>';
require_once('skins/' . $settings['skin'] . '/head.php');

?>
<span id="gb_top"><a href="<?php echo $gb_root; ?>add.php"><img src="images/icons/comment_add_16.png" alt="" align="absmiddle" border="0" />&nbsp;sign guestbook</a></span><br />
<?php echo $html; ?>
<br />

<!-- Please keep this link-->
<div style="color:#999999;font-size:8pt;text-align:center;">[<a href="http://opengb.googlecode.com">Guestbook powered by OpenGB <? echo $gb_version; ?></a>]&#09;[<a href="<?php echo $gb_root; ?>gb-admin/index.php">Admin</a>]</div>

<?php require_once('skins/' . $settings['skin'] . '/foot.php'); ?>
Return current item: OpenGB Guestbook