<?php
if (!defined('MODULE_FILE')) {
	Header("Location: ../../../index.php");
	exit;
}

function top() {
	global $galleryvar, $bgcolor1, $bgcolor4, $user, $prefix, $name, $adminpath, $db;
	galleryHeader();
	
	$result = $db->sql_query("select pid, name, counter, rate, votes, visible from $prefix"._album_pictures." p, $prefix"._album_categories." c WHERE p.gid=c.gallid AND c.visible>0 order by counter DESC, rate DESC");
	$result1 = $db->sql_query("select pid, name, counter, rate, votes, visible from $prefix"._album_pictures." p, $prefix"._album_categories." c WHERE p.gid=c.gallid AND c.visible>0 order by rate DESC, votes ASC, counter DESC");
	$nav = navigationGall();
	
	if ($galleryvar['allowrate']) $col = 4; else $col = 3;

	OpenTable();
	echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td colspan=3 align=\"center\">$nav<br></td></tr><tr><td>&nbsp;</td><td width=\"70%\" align=\"center\">";
	echo '<font class="option">'._GALTOP10H.'</font><p><table width="100%" align="center" border="0" cellspacing="1" cellpadding="3" class="bgcolor4"><tr class="bgcolor1"><th colspan="'.$col.'" width="100%" align="center" bgcolor="'.$bgcolor1.'"><font class=block-title>'._GALTOP10HITS.'</font></th></tr><tr class="bgcolor1"><td align="center" bgcolor="'.$bgcolor1.'">'._GALTOPPOS.'</td><td align="center" bgcolor="'.$bgcolor1.'">'._GALTOPHITS.'</td>';
	
	if ($allowrate) {
		echo '<td align="center" bgcolor="'.$bgcolor1.'"><font class="title">'._GALTOPRATING.'</font></td>';
	}
	echo '<td align="center" bgcolor="'.$bgcolor1.'">'._GALTOPMEDIA.'</td></tr>';
	$pos = 1;

	while((list($pid, $name, $counter, $rate, $votes, $visible) = $db->sql_fetchrow($result)) && $pos <= 10) {
		echo '<tr class="bgcolor1"><td align="center" bgcolor="'.$bgcolor1.'">'.$pos.'</td><td align="center" bgcolor="'.$bgcolor1.'">'.$counter.'</td>';

		if ($allowrate) {
			echo '<td align="center" bgcolor="'.$bgcolor1.'">'.$rate.'</td>';
		}
		if ($visible==1) {
			if (is_user($user)) {
				echo "<td align=\"center\" bgcolor=$bgcolor1><a href=\"index.php?name=Album&file=index&do=showpic&amp;pid=$pid\">$name</a></td>";
			} else {
				echo "<td align=\"center\" bgcolor=$bgcolor1> $name (*)</td>";
			}
		} else {
			echo "<td align=\"center\" bgcolor=$bgcolor1><a href=\"index.php?name=Album&file=index&do=showpic&amp;pid=$pid\">$name</a></td>";
		}
		$pos += 1;
	}
	echo "</tr></table><p>";
	
	if ($galleryvar['allowrate']) {
		echo '<table width="100%" align="center" border="0" cellspacing="1" cellpadding="3" class="bgcolor4"><tr class="bgcolor1"><th colspan="4" width="100%" align="center" bgcolor="'.$bgcolor1.'"><font class=block-title>'._GALTOP10RATING.'</font></th></tr>';
	}
	echo '<tr class="bgcolor1"><td align="center" bgcolor="'.$bgcolor1.'">'._GALTOPPOS.'</td><td align="center" bgcolor="'.$bgcolor1.'">'._GALTOPRATING.'</td><td align="center" bgcolor="'.$bgcolor1.'">'._GALTOPVOTES.'</td><td align="center" bgcolor="'.$bgcolor1.'">'._GALTOPMEDIA.'</td></tr>';
	$pos = 1;
	while ((list($pid, $name, $counter, $rate, $votes, $visible) = $db->sql_fetchrow($result1)) && $pos <= 10) {
		if ($visible==1) {
			if (is_user($user)) {
				echo '<tr class="bgcolor1"><td align="center" bgcolor="'.$bgcolor1.'">'.$pos.'</td><td align="center" bgcolor="'.$bgcolor1.'">'.$rate.'</td><td align="center" bgcolor="'.$bgcolor1.'">'.$votes.'</td><td align="center" bgcolor="'.$bgcolor1.'"><a href="index.php?name=Album&file=index&do=showpic&amp;pid='.$pid.'">'.$name.'</a></td></tr>';
			} else {
				echo '<tr class="bgcolor1"><td align="center" bgcolor="'.$bgcolor1.'">'.$pos.'</td><td align="center" bgcolor="'.$bgcolor1.'">'.$rate.'</td><td align="center" bgcolor="'.$bgcolor1.'">'.$votes.'</td><td align="center" bgcolor="'.$bgcolor1.'">'.$name.' (*)</td></tr>';
			}
		} else {
			echo '<tr class="bgcolor1"><td align="center" bgcolor="'.$bgcolor1.'">'.$pos.'</td><td align="center" bgcolor="'.$bgcolor1.'">'.$rate.'</td><td align="center" bgcolor="'.$bgcolor1.'">'.$votes.'</td><td align="center" bgcolor="'.$bgcolor1.'"><a href="index.php?name=Album&file=index&do=showpic&amp;pid='.$pid.'">'.$name.'</a></td></tr>';
		}
		$pos += 1;
	}
	echo "</table>";

	if (!is_user($user)) {
		print '<br><center><font class="tiny">'._GALCATMEMBERS.'</font></center>';
	}
	echo "<br></td><td>&nbsp;</td></tr></table>";
	CloseTable();
	include("footer.php");
}
?>