<?php
if (! defined ( 'BLOCK_FILE' )) {
	if (function_exists ( "location" ))
		location ( "../index.php" );
	else
		die ();
	exit ();
}

global $tracker_lang, $lol_dir, $lol_pp, $CURGROUP;
list ( $blocktitle, $content ) = ReadCache ( 'lastlol', true, true );
if (! $content) {
	$sql = sql_query ( "SELECT lol.*, u.`group`, u.username, u.id FROM lol LEFT JOIN users AS u ON u.id = lol.uid ORDER BY rand() DESC LIMIT 1" ) or sqlerr ( __FILE__, __LINE__ );
	$row = mysql_fetch_array ( $sql );
	$group = $row ["group"];
	$username = $row ["username"];
	$value = $row ['value'];
	$type = $row ['type'];
	$page = number_format ( $row ['id'] / $lol_pp );
	if ($type == "text")
		$lol = "<div style=\"overflow: auto; height: 100px; width: 100px;\">$value</div>";
	elseif ($type == "file")
		$lol = "<img src=\"$lol_dir/$value\" width=\"100\" height=\"100\">";
	elseif ($type == "link")
		$lol = "<img src=\"$value\" width=\"100\" height=\"100\">";
	if (! empty ( $lol )) {
		$content = "<center><a href=\"lol.php?page=" . $page . "\">$lol</a></center>";
		$blocktitle = "Улыбка от " . get_user_group_color ( $group, $username ) . "";
	} else {
		$content = "<center>Нет улыбок" . WriteCurgroup ( ", желаете <a href=\"lol.php\">добавить?</a>", '$CURGROUP["can_addlol"] && $CURUSER' ) . "</center>";
		$blocktitle = "Нет улыбок";
	}
	$content = WriteCurgroup ( $content, '$CURGROUP["can_lol"]' );
	$content .= WriteBlockTitle ( $blocktitle );
	$content = WriteCache ( $content );
}
?>