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

global $user, $prefix, $db;
include ("config/config_album.php");
mt_srand((double)microtime()*1000000);
if (is_user($user)) {
	$total = $db->sql_fetchrow($db->sql_query("SELECT COUNT(p.pid) AS total FROM ".$prefix."_album_pictures AS p LEFT JOIN ".$prefix."_album_categories AS c ON c.gallid=p.gid WHERE c.visible>=1"));
} else {
	$total = $db->sql_fetchrow($db->sql_query("SELECT COUNT(p.pid) AS total FROM ".$prefix."_album_pictures AS p LEFT JOIN ".$prefix."_album_categories AS c ON c.gallid=p.gid WHERE c.visible>=2"));
}
$p = mt_rand(0, ($total['total'] - 1));
$pic = $db->sql_fetchrow($db->sql_query("SELECT p.pid, p.img, p.name, p.description, c.galloc FROM ".$prefix."_album_pictures AS p LEFT JOIN ".$prefix."_album_categories AS c ON c.gallid=p.gid LIMIT $p,1"));
if (file_exists("$gallerypath/$pic[galloc]/thumb/$pic[img]")) {
	$content = "<center><a href=\"index.php?op=modload&name=Album&do=showpic&pid=$pic[pid]\" title=\"".htmlspecialchars($pic['description'])."\"><img src=\"$gallerypath/$pic[galloc]/thumb/$pic[img]\" width=\"150\" border=\"0\" alt=\"".htmlspecialchars($pic['description'])."\"></center>";
} else {
	$content = "<center><a href=\"index.php?op=modload&name=Album&do=showpic&pid=$pic[pid]\" title=\"".htmlspecialchars($pic['description'])."\"><img src=\"$gallerypath/$pic[galloc]/$pic[img]\" width=\"150\" border=\"0\" alt=\"".htmlspecialchars($pic['description'])."\"></center>";
}
?>