Code:
<?php
/***************************************************************************
* block_pic.php
* --------------------------
* begin : Febuary 2003
* copyright : (C) 2002, 2003 Smartor
* (C) 2003 IK
* email :
cms@kohl-net.de
*
*
***************************************************************************/
/***************************************************************************
*
* 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 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
// VARIABLES
// EDIT THE VARIABLES BELOW TO MEET YOUR REQUIREMENTS
$Display = 'Recent'; // Replace 'XXXX' with 'Recent' or 'Random'.
$CategoryID = 0; // Replace 0 with a category ID. Otherwise, keep it as it is.
// DO NOT EDIT BELOW, UNLESS YOU KNOW WHAT YOU ARE DOING !!!
// This first if statement is for the admin panel
if (($userdata['user_level']==ADMIN)&&($from_admin_panel))
{
$block_name = "Last / Random Picture";
}
else{
$template->set_filenames(array(
"block_pic" => "block_pic.tpl"));
$album_root_path = $phpbb_root_path . 'album_mod/';
include($album_root_path . 'album_common.'.$phpEx);
$sql = "SELECT c.*, COUNT(p.pic_id) AS count
FROM ". ALBUM_CAT_TABLE ." AS c
LEFT JOIN ". ALBUM_TABLE ." AS p ON c.cat_id = p.pic_cat_id
WHERE cat_id <> 0
GROUP BY cat_id
ORDER BY cat_order ASC";
if( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql);
}
$catrows = array();
while( $row = $db->sql_fetchrow($result) )
{
$album_user_access = album_user_access($row['cat_id'], $row, 1, 0, 0, 0, 0, 0); // VIEW
if ($album_user_access['view'] == 1)
{
$catrows[] = $row;
}
}
$allowed_cat = ''; // For Recent Public Pics below
//
// $catrows now stores all categories which this user can view. Dump them out!
//
for ($i = 0; $i < count($catrows); $i++)
{
$allowed_cat .= ($allowed_cat == '') ? $catrows[$i]['cat_id'] : ',' . $catrows[$i]['cat_id'];
}
//
// BEGIN Random or Recent Photo
//
if ($Display == 'Random') {
if ($CategoryID != 0) {
$sql = "SELECT * FROM " . ALBUM_TABLE . " p, " . ALBUM_CAT_TABLE ." ct
WHERE p.pic_cat_id=ct.cat_id AND p.pic_cat_id = $CategoryID
AND p.pic_cat_id IN ($allowed_cat)
AND ( p.pic_approval = 1 OR ct.cat_approval = 0 )
ORDER BY RAND() LIMIT 1";
}
else {
$sql = "SELECT * FROM " . ALBUM_TABLE . " p, " . ALBUM_CAT_TABLE ." ct
WHERE p.pic_cat_id=ct.cat_id AND p.pic_cat_id IN ($allowed_cat)
AND ( p.pic_approval = 1 OR ct.cat_approval = 0 )
ORDER BY RAND() LIMIT 1";
}
}
else if ($Display == 'Recent') {
if ($CategoryID != 0) {
$sql = "SELECT p.pic_id, p.pic_title, p.pic_username, p.pic_time
FROM " . ALBUM_TABLE . " p, " . ALBUM_CAT_TABLE ." ct
WHERE p.pic_cat_id=ct.cat_id AND p.pic_cat_id = $CategoryID
AND p.pic_cat_id IN ($allowed_cat)
AND ( p.pic_approval = 1 OR ct.cat_approval = 0 )
ORDER BY pic_time DESC LIMIT 0,1";
}
else {
$sql = "SELECT p.pic_id, p.pic_title, p.pic_username, p.pic_time
FROM " . ALBUM_TABLE . " p, " . ALBUM_CAT_TABLE ." ct
WHERE p.pic_cat_id=ct.cat_id AND p.pic_cat_id IN ($allowed_cat)
AND ( p.pic_approval = 1 OR ct.cat_approval = 0 )
ORDER BY pic_time DESC LIMIT 0,1";
}
}
if (!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, 'Could not query album information', '', __LINE__, __FILE__, $sql);
}
$picrow = $db->sql_fetchrow($result);
//
// END Random or Recent Photo
//
$template->assign_vars(array(
'L_NEWEST_PIC' => $lang['Newest_pic'],
'PIC_IMAGE' => append_sid('album_thumbnail.'. $phpEx . '?pic_id=' . $picrow['pic_id']),
'PIC_TITLE' => $picrow['pic_title'],
'PIC_POSTER' => $picrow['pic_username'],
'U_PIC_LINK' => append_sid('album_page.' . $phpEx . '?pic_id=' . $picrow['pic_id']),
'PIC_TIME' => create_date($board_config['default_dateformat'], $picrow['pic_time'], $board_config['board_timezone']),
'L_GOTO_ALBUM' => $lang['goto_album'])
);
$template->pparse("block_pic");
}
?>