Location: PHPKode > projects > Top site PHP script > topsite/index.php
<?php
include('config.php');
function dehtml($html)
{
	return htmlentities($html, ENT_QUOTES, 'utf-8');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />
        <title>Top site</title>
    </head>
    <body>
    	<div class="header">
        	<a href="<?php echo $url_topsite; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Top site" /></a>
	    </div>
<?php
//We check if the admin is trying to log in
if(isset($_POST['password']))
{
	//We check if the password is the good one
	if(strtolower($_POST['password'])==strtolower($password))
	{
		echo '<div class="connexion">You have soccessfuly been logged.</div>';
		$_SESSION['logged'] = true;
	}
	else
	{
		echo '<div class="connexion">The password you typed is not the good one.</div>';
	}
}
//We display a subscribtion link
?>
<div class="new"><a href="new.php">Add your Website to our Top Site</a></div>
<table class="topsite" cellpadding="0" cellspacing="0">
	<tr>
    	<th class="ranking_th">Ranking</th>
    	<th class="site_th">Site</th>
    	<th class="votes_th">Votes</th>
    </tr>
<?php
//We get the number of websites
$req1 = mysql_fetch_array(mysql_query('select count(id) as nb from topsite where status="ok"'));
//We get the current page
if(isset($_GET['page']))
{
	$page = intval($_GET['page']);
}
else
{
	$page = 1;
}
//We calculate the number of pages and we display pages links
$nbpages = ceil($req1['nb']/$nb_site_page);
if($page<1 or $page>$nbpages)
{
	$page = 1;
}
$pages_site = 'Pages: ';
if($page>1)
{
	$pages_site .= '<a href="?page='.($page-1).'">Previous</a> ';
}
for($i=1;$i<=$nbpages;$i++)
{
	if($i==$page)
	{
		$pages_site .= '<strong>'.$i.'</strong> ';
	}
	else
	{
		$pages_site .= '<a href="?page='.$i.'">'.$i.'</a> ';
	}
}
if($page<$nbpages)
{
	$pages_site .= '<a href="?page='.($page+1).'">Next</a>';
}
?>
    <tr>
    	<td colspan="3" class="pages"><?php echo $pages_site; ?></td>
    </tr>
<?php
//We calculate the first and last message position to display
$first_message = ($page-1)*$nb_site_page;
$last_message = $first_message +$nb_site_page;
$i = $first_message ;
//On affiche les sites
$req2 = mysql_query('select id, url, name, description, banner, votes from topsite where status="ok" order by votes desc limit '.$first_message .','.$last_message);
while($dnn2 = mysql_fetch_array($req2))
{
	$i++;
?>
	<tr>
    	<td class="ranking"><?php echo $i; ?>
<?php
//We verify if its an admin
if($_SESSION['logged']==true)
{
?>
			<br /><a href="accept_reject.php?id=<?php echo $dnn2['id']; ?>&ch=s" style="font-size:16px;">Delete this Website</a>
<?php
}
?>
		</td>
    	<td class="site"><a href="<?php echo dehtml($dnn2['url']); ?>" style="color:#0000ff;text-decoration:underline;font-weight:bold;"><?php echo dehtml($dnn2['name']); ?></a><br />
		<?php echo dehtml($dnn2['description']); ?><br />
        <a href="<?php echo dehtml($dnn2['url']); ?>" style="color:#008000;"><?php echo dehtml($dnn2['url']); ?></a> - <a href="http://www.webestools.com/" title="PageRank google Top site top list generators free tools and services for webmasters counters tchat ajax tools free"><img src="http://images.webestools.com/prggl.gif?site=<?php echo urlencode($dnn2['url']); ?>&style=5" /></a>
        <div style="text-align:center;"><a href="<?php echo dehtml($dnn2['url']); ?>"><img src="<?php echo dehtml($dnn2['banner']); ?>" alt="<?php echo dehtml($dnn2['name']); ?>" style="max-width:500px;max-height:200px;" /></a></div></td>
    	<td class="votes"><?php echo $dnn2['votes']; ?><br /><a href="vote.php?id=<?php echo $dnn2['id']; ?>">Vote</a></td>
    </tr>
<?php
}
//We display pages site (again)
?>
    <tr>
    	<td colspan="3" class="pages"><?php echo $pages_site; ?></td>
    </tr>
</table>
<?php
//We verify if its an admin
if($_SESSION['logged']==true)
{
//We display a link to reset votes
?>
<div style="text-align:right;margin-right:20px;"><a href="reset.php">Reset votes</a></div>
<?php
}
//We display a subscribtion link
?>
<div class="new"><a href="new.php">Add your Website to our Top Site</a></div>
<?php
//We verify if its an admin
if($_SESSION['logged']==true)
{
?>
<h1>Administration</h1>
<table class="topsite" cellpadding="0" cellspacing="0">
	<tr>
    	<th class="site_th">Site</th>
    	<th class="votes_th">Votes</th>
    	<th class="accept_reject_th">Accept/Reject</th>
    </tr>
<?php
//We display new web sites(to aprove or reject)
$i = false;
$req2 = mysql_query('select id, url, name, description, banner, votes from topsite where status!="ok"');
while($dnn2 = mysql_fetch_array($req2))
{
	$i = true;
?>
	<tr>
    	<td class="site"><a href="<?php echo dehtml($dnn2['url']); ?>" style="color:#0000ff;text-decoration:underline;font-weight:bold;"><?php echo dehtml($dnn2['name']); ?></a><br />
		<?php echo dehtml($dnn2['description']); ?><br />
        <a href="<?php echo dehtml($dnn2['url']); ?>" style="color:#008000;"><?php echo dehtml($dnn2['url']); ?></a> - <a href="http://www.webestools.com/" title="PageRank google Top site top list generators free tools and services for webmasters counters tchat ajax tools free"><img src="http://images.webestools.com/prggl.gif?site=<?php echo urlencode($dnn2['url']); ?>&style=5" /></a>
        <div style="text-align:center;"><a href="<?php echo dehtml($dnn2['url']); ?>"><img src="<?php echo dehtml($dnn2['banner']); ?>" alt="<?php echo dehtml($dnn2['name']); ?>" style="max-width:500px;max-height:200px;" /></a></div></td>
    	<td class="votes"><?php echo $dnn2['votes']; ?><br /><a href="vote.php?id=<?php echo $dnn2['id']; ?>">Vote</a></td>
        <td class="accept_reject"><a href="accept_reject.php?id=<?php echo $dnn2['id']; ?>&ch=a">Accept</a><br /><a href="accept_reject.php?id=<?php echo $dnn2['id']; ?>&ch=r">Reject</a></td>
    </tr>
<?php
}
if(!$i)
{
?>
	<tr>
    	<td colspan="3">There is no website waiting for approval.</td>
    </tr>
<?php
}
?>
</table>
<?php
}
else
{
	//If the admin is not logged, we display a form
?>
<a href="#null" onclick="document.getElementById('administration').style.display='block';">Administration</a>
<form action="<?php echo $url_topsite; ?>" method="post" id="administration" style="display:none;">
	<label for="password">Password</label><input type="password" name="password" id="password" /><input type="submit" value="Log in" />
</form>
<?php
}
?>
        <div class="foot">
            <a href="http://www.webestools.com/">Webestools</a>
        </div>
    </body>
</html>
Return current item: Top site PHP script