//-- The Max Class, ie: UC_CODER - Is Able To Delete, Edit The Forum Etc... --//
define('MAX_CLASS', UC_MANAGER);
//-- Set's The Max File Size In php.ini, No Need To Change --//
ini_set("upload_max_filesize", $maxfilesize);
//-- Set's The Root Path, Change Only If You Know What You Are Doing --//
//define('ROOT_PATH', $_SERVER['DOCUMENT_ROOT'].'/');
//-- The Extensions That Are Allowed To Be Uploaded By The Users --//
//-- Note: You Need To Have The Pics In The $image_dir Folder, ie zip.gif, rar.gif --//
$allowed_file_extensions = array('rar',
'zip');
//-- Just A Check, So That The Default URL, Wont Have A Ending Backslash (to Double Backslash The Links), No Need To Edit Or Delete --//
$site_url_rev = strrev($site_url);
if (!function_exists('highlight'))
{
function highlight ($search, $subject, $hlstart = '', $hlend = '')
{
$srchlen = strlen($search); //-- Length Of Searched String --//
if ($srchlen == 0)
{
return $subject;
}
$find = $subject;
while ($find = stristr($find, $search)) //-- Find $search Text In $subject -case Insensitive --//
{
$srchtxt = substr($find, 0, $srchlen); //-- Get New Search Text --//
$find = substr($find, $srchlen);
$subject = str_replace($srchtxt, $hlstart.$srchtxt.$hlend, $subject); //-- Highlight Found Case Insensitive Search Text --//
}
return $subject;
}
}
function catch_up ($id = 0)
{
global $CURUSER, $posts_read_expiry;
$userid = (int) $CURUSER['id'];
$res = sql_query("SELECT t.id, t.lastpost, r.id AS r_id, r.lastpostread
FROM topics AS t
LEFT JOIN posts AS p ON p.id = t.lastpost
LEFT JOIN readposts AS r ON r.userid=".sqlesc($userid)." AND r.topicid=t.id
WHERE p.added > ".sqlesc(get_date_time(gmtime() - $posts_read_expiry)).(!empty($id) ? '
AND t.id '.(is_array($id) ? 'IN ('.implode(', ', $id).')' : '= '.sqlesc($id)) : '')) or sqlerr(__FILE__, __LINE__);
while ($arr = mysqli_fetch_assoc($res))
{
$postid = (int) $arr['lastpost'];
if (!is_valid_id($arr['r_id']))
{
sql_query("INSERT INTO readposts (userid, topicid, lastpostread)
VALUES($userid, ".(int) $arr['id'].", $postid)") or sqlerr(__FILE__, __LINE__);
}
else
{
if ($arr['lastpostread'] < $postid)
{
sql_query("UPDATE readposts
SET lastpostread = $postid
WHERE id = ".$arr['r_id']) or sqlerr(__FILE__, __LINE__);
}
}
}
mysqli_free_result($res);
}
//-- Begin Cached Online Users --//
function forum_stats ()
{
//-- Active Users In Forums --//
global $forum_width, $CURUSER, $image_dir, $site_url;
$forum1 = sql_query("SELECT id, username, class, warned, donor
FROM users
WHERE forum_access >= $dt
ORDER BY class DESC") or sqlerr(__FILE__, __LINE__);
while ($forum2 = mysqli_fetch_assoc($forum1))
{
$forum3[] = $forum2;
}
function show_forums ($forid)
{
global $CURUSER, $image_dir, $posts_read_expiry, $site_url;
$forums_res = sql_query("SELECT f.id, f.name, f.description, f.postcount, f.topiccount, f.minclassread, p.added, p.topicid, p.userid, p.id AS pid, u.username, t.subject, t.lastpost, r.lastpostread
FROM forums AS f
LEFT JOIN posts AS p ON p.id = (SELECT MAX(lastpost) FROM topics WHERE forumid = f.id)
LEFT JOIN users AS u ON u.id = p.userid
LEFT JOIN topics AS t ON t.id = p.topicid
LEFT JOIN readposts AS r ON r.userid = ".sqlesc($CURUSER['id'])." AND r.topicid = p.topicid
WHERE f.forid = $forid
ORDER BY sort ASC") or sqlerr(__FILE__, __LINE__);
while ($forums_arr = mysqli_fetch_assoc($forums_res))
{
if ($CURUSER['class'] < $forums_arr["minclassread"])
{
continue;
}
}
//--Returns the Minimum Read/Write Class Levels of a Forum --//
function get_forum_access_levels ($forumid)
{
global $CURUSER, $site_url, $image_dir;
$res = sql_query("SELECT minclassread, minclasswrite, minclasscreate
FROM forums
WHERE id = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
//-- Returns The Forum Id Of A Topic, Or False On Error --//
function get_topic_forum ($topicid)
{
global $CURUSER, $image_dir, $posts_read_expiry, $site_url;
$res = sql_query("SELECT forumid
FROM topics
WHERE id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) != 1)
{
return false;
}
$arr = mysqli_fetch_assoc($res);
return (int) $arr['forumid'];
}
//-- Returns The Id Of The Last Post Of A Forum --//
function update_topic_last_post ($topicid)
{
$res = sql_query("SELECT MAX(id) AS id
FROM posts
WHERE topicid = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
$arr = mysqli_fetch_assoc($res) or die ("No Post Found!");
sql_query("UPDATE topics
SET lastpost = {$arr['id']}
WHERE id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
//-- Update Forum Post/Topic Count --//
$forums = sql_query("SELECT id
FROM forums");
$topics = sql_query("SELECT id
FROM topics
WHERE forumid = $forum[id]");
while ($topic = mysqli_fetch_assoc($topics))
{
$res = sql_query("SELECT COUNT(*)
FROM posts
WHERE topicid = $topic[id]");
$arr = mysqli_fetch_row($res);
$postcount += $arr[0];
++$topiccount;
}
sql_query("UPDATE forums
SET postcount = $postcount, topiccount = $topiccount
WHERE id = $forum[id]");
}
}
function get_forum_last_post ($forumid)
{
$res = sql_query("SELECT MAX(lastpost) AS lastpost
FROM topics
WHERE forumid = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$arr = mysqli_fetch_assoc($res);
$postid = (int) $arr['lastpost'];
return (is_valid_id($postid) ? $postid : 0);
}
//-- Inserts a Quick Jump Menu --//
function insert_quick_jump_menu ($currentforum = 0)
{
global $CURUSER;
?>
}
//-- Inserts a Compose Frame --//
function insert_compose_frame ($id, $newtopic = true, $quote = false, $attachment = false)
{
global $maxsubjectlength, $CURUSER, $maxfilesize, $image_dir, $use_attachment_mod, $site_url, $image_dir;
if ($newtopic)
{
$res = sql_query("SELECT name
FROM forums
WHERE id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$arr = mysqli_fetch_assoc($res) or die("Bad Forum ID!");
?>
New Topic in forum
}
else
{
$res = sql_query("SELECT t.forumid, t.subject, t.locked, f.minclassread
FROM topics AS t
LEFT JOIN forums AS f ON f.id = t.forumid
WHERE t.id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$arr = mysqli_fetch_assoc($res) or die ("Forum Error, Topic Not Found!");
if ($CURUSER['class'] < $arr['minclassread'])
{
error_message("warn", "Sorry", "You are Not Allowed in Here!");
end_table();
exit();
}
if ($arr['locked'] == 'yes' && $CURUSER['class'] < UC_SITE_EDITOR)
{
error_message("warn", "Sorry", "The Topic is Locked!");
end_table();
exit();
}
?>
Reply to Topic:
}
if ($quote)
{
$postid = (int) $_GET["postid"];
if (!is_valid_id($postid))
{
error_message("error", "Error", "Invalid ID!");
}
$res = sql_query("SELECT posts.*, users.username
FROM posts
JOIN users ON posts.userid = users.id
WHERE posts.id = $postid") or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) == 0)
{
error_message("error", "Error", "No Post with that ID!");
}
//-- Get Last 10 Posts If This Is A Reply --//
if (!$newtopic)
{
$postres = sql_query("SELECT p.id, p.added, p.body, u.id AS uid, u.username, u.avatar
FROM posts AS p
LEFT JOIN users AS u ON u.id = p.userid
WHERE p.topicid = ".sqlesc($id)."
ORDER BY p.id DESC
LIMIT 10") or sqlerr(__FILE__, __LINE__);
if (!is_valid_id($topicid))
{
error_message("error", "Error", "Invalid Topic ID!");
}
$topic_res = sql_query('SELECT t.sticky, t.locked, t.subject, t.forumid, f.minclasswrite,
(SELECT COUNT(id) FROM posts WHERE topicid = t.id) AS post_count
FROM topics AS t
LEFT JOIN forums AS f ON f.id = t.forumid
WHERE t.id = '.sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($topic_res) == 0)
{
error_message("error", "Error", "No Topic with that ID!");
}
$topic_arr = mysqli_fetch_assoc($topic_res);
if ($CURUSER['class'] < (int) $topic_arr['minclasswrite'])
{
error_message("error", "Error", "You are Not Allowed to Edit this Topic.");
}
if ($use_attachment_mod)
{
$res = sql_query("SELECT attachments.filename
FROM posts
LEFT JOIN attachments ON attachments.postid = posts.id
WHERE posts.topicid = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
while ($arr = mysqli_fetch_assoc($res))
{
if (!empty($arr['filename']) && is_file($attachment_dir."/".$arr['filename']))
{
unlink($attachment_dir."/".$arr['filename']);
}
}
}
sql_query("DELETE posts, topics ".($use_attachment_mod ? ", attachments, attachmentdownloads " : "").($use_poll_mod ? ", postpolls, postpollanswers " : "")."
FROM topics
LEFT JOIN posts ON posts.topicid = topics.id ".($use_attachment_mod ? "
LEFT JOIN attachments ON attachments.postid = posts.id
LEFT JOIN attachmentdownloads ON attachmentdownloads.fileid = attachments.id " : "").($use_poll_mod ? "
LEFT JOIN postpolls ON postpolls.id = topics.pollid
LEFT JOIN postpollanswers ON postpollanswers.pollid = postpolls.id " : "")."
WHERE topics.id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (!is_valid_id($new_forumid))
{
error_message("error", "Error", "Invalid Forum ID!");
}
if ($new_forumid != $forumid)
{
$post_count = (int) $topic_arr['post_count'];
$res = sql_query("SELECT minclasswrite
FROM forums
WHERE id = ".sqlesc($new_forumid)) or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) != 1)
{
error_message("error", "Error", "Forum Not Found!");
}
$arr = mysqli_fetch_assoc($res);
if ($CURUSER['class'] < (int) $arr['minclasswrite'])
{
error_message("error", "Error", "You are Not Allowed to Move this Topic into the Selected Forum.");
}
$updateset[] = 'forumid = '.sqlesc($new_forumid);
sql_query("UPDATE forums
SET topiccount = topiccount - 1, postcount = postcount - ".sqlesc($post_count)."
WHERE id = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
sql_query("UPDATE forums
SET topiccount = topiccount + 1, postcount = postcount + ".sqlesc($post_count)."
WHERE id = ".sqlesc($new_forumid)) or sqlerr(__FILE__, __LINE__);
if (!is_valid_id($forumid))
{
error_message("error", "Error", "Invalid ID!");
}
$res = sql_query("SELECT name, description, minclassread, minclasswrite, minclasscreate
FROM forums
WHERE id = $forumid") or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) == 0)
{
error_message("error", "Error", "No Forum Found with that ID!");
}
if (!is_valid_id($forumid))
{
error_message('error', 'Error', 'Invalid ID!');
}
$confirmed = (int) $_GET['confirmed'];
if (!$confirmed)
{
$rt = sql_query("SELECT topics.id, forums.name
FROM topics
LEFT JOIN forums ON forums.id=topics.forumid
WHERE topics.forumid = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$topics = mysqli_num_rows($rt);
$posts = 0;
if ($topics > 0)
{
while ($topic = mysqli_fetch_assoc($rt))
{
$ids[] = $topic['id'];
$forum = $topic['name'];
}
$rp = sql_query("SELECT COUNT(id)
FROM posts
WHERE topicid IN (".join(', ', $ids).")");
foreach ($ids
AS
$id)
{
if ($a = mysqli_fetch_row($rp))
{
$posts += $a[0];
}
}
}
if ($use_attachment_mod || $use_poll_mod)
{
$res = sql_query("SELECT ".($use_attachment_mod ? "
COUNT(attachments.id) AS attachments " : "").($use_poll_mod ? ($use_attachment_mod ? ', ' : '')."
COUNT(postpolls.id) AS polls " : "")."
FROM topics
LEFT JOIN posts ON topics.id=posts.topicid ".($use_attachment_mod ? "
LEFT JOIN attachments ON attachments.postid = posts.id " : "").($use_poll_mod ? "
LEFT JOIN postpolls ON postpolls.id=topics.pollid " : "")."
WHERE topics.forumid=".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
if ($use_flood_mod && $CURUSER['class'] < UC_SITE_EDITOR)
{
$res = sql_query("SELECT COUNT(id) AS c
FROM posts
WHERE userid = ".$CURUSER['id']."
AND added > '".get_date_time(gmtime() - ($minutes * 60))."'");
$arr = mysqli_fetch_assoc($res);
if ($arr['c'] > $limit)
{
error_message("info", "Flood", "More than ".$limit." Posts in the last ".$minutes." Minutes.");
}
}
if ($newtopic)
{
sql_query("INSERT INTO topics (userid, forumid, subject)
VALUES($userid, $forumid, ".sqlesc($subject).")") or sqlerr(__FILE__, __LINE__);
$topicid = mysqli_insert_id() or error_message("error", "Error", "No Topic ID Returned!");
/// Credits - Yummii ///
////////Shout in shoutbox when new torrent is uploaded//////////
$text = "Started a new thread ".$subject."";
//$userid = "7";
//$username = "System";
$date=time();
sql_query("INSERT INTO shoutbox (userid, username, date, text) VALUES (" . sqlesc($userid) . ", " . sqlesc($username) . ", $date, " . sqlesc($text) . ")") or sqlerr(__FILE__, __LINE__);
////////////end autoshout///////////////
sql_query("INSERT INTO posts (topicid, userid, added, body)
VALUES($topicid, $userid, ".sqlesc(get_date_time()).", ".sqlesc($body).")") or sqlerr(__FILE__, __LINE__);
$postid = mysqli_insert_id() or error_message("error", "Error", "No Post ID Returned!");
}
else
{
//-- Make Sure Topic Exists And Is Unlocked --//
$res = sql_query("SELECT locked
FROM topics
WHERE id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) == 0)
{
error_message("error", "Error", "Non-existent Topic!");
}
$arr = mysqli_fetch_assoc($res);
if ($arr["locked"] == 'yes' && $CURUSER['class'] < UC_SITE_EDITOR)
{
error_message("info", "", "This Topic is Locked. No New Posts are Allowed.");
}
//-- Check Double Post --//
$doublepost = sql_query("SELECT p.id, p.added, p.userid, p.body, t.lastpost, t.id
FROM posts AS p
INNER JOIN topics AS t ON p.id = t.lastpost
WHERE t.id = $topicid
AND p.userid = $userid
AND p.added > ".sqlesc(get_date_time(gmtime() - 1 * 86400))."
ORDER BY p.added DESC
LIMIT 1") or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($doublepost) == 0 || $CURUSER['class'] >= UC_SITE_EDITOR)
{
sql_query("INSERT INTO posts (topicid, userid, added, body)
VALUES($topicid, $userid, ".sqlesc(get_date_time()).", ".sqlesc($body).")") or sqlerr(__FILE__, __LINE__);
$postid = mysqli_insert_id() or die("Post ID N/A");
}
else
{
$results = mysqli_fetch_assoc($doublepost);
$postid = (int) $results['lastpost'];
sql_query("UPDATE posts
SET body = ".sqlesc(trim($results['body'])."\n\n".$body).", editedat = ".sqlesc(get_date_time()).", editedby = $userid
WHERE id = $postid") or sqlerr(__FILE__, __LINE__);
}
/// Credits - Yummii ///
////////Shout in shoutbox when new torrent is uploaded//////////
$subject = mysqli_result(sql_query("SELECT subject from topics where id=".$topicid),0);
$text = "Replied to the thread ".$subject."";
//$userid = "";
//$username = "";
$date=time();
sql_query("INSERT INTO shoutbox (userid, username, date, text) VALUES (" . sqlesc($userid) . ", " . sqlesc($username) . ", $date, " . sqlesc($text) . ")") or sqlerr(__FILE__, __LINE__);
////////////end autoshout///////////////
}
if (empty($fname))
{
$uploaderror = "Invalid Filename!";
}
if (!validfilename($fname))
{
$uploaderror = "Invalid Filename!";
}
foreach ($allowed_file_extensions
AS
$allowed_file_extension)
if (!preg_match('/^(.+)\.['.join(']|[', $allowed_file_extensions).']$/si', $fname, $matches))
{
$uploaderror = 'Only Files With The Following Extensions Are Allowed: '.join(', ', $allowed_file_extensions).'.';
}
if ($size > $maxfilesize)
{
$uploaderror = error_message("warn", "Sorry", "That File Is Too Large.");
}
if (ctype_digit($choice) && $choice < 256 && $choice == floor($choice))
{
$res = sql_query("SELECT pa.id
FROM postpolls AS p
LEFT JOIN postpollanswers AS pa ON pa.pollid = p.id AND pa.userid = ".sqlesc($userid)."
WHERE p.id = ".sqlesc($pollid)) or sqlerr(__FILE__, __LINE__);
$arr = mysqli_fetch_assoc($res) or error_message("error", "Sorry", "Non-existent Poll!");
if (is_valid_id($arr['id']))
{
error_message("error", "Error", "Dupe Vote");
}
sql_query("INSERT INTO postpollanswers
VALUES(id, ".sqlesc($pollid).", ".sqlesc($userid).", ".sqlesc($choice).")") or sqlerr(__FILE__, __LINE__);
if (mysqli_affected_rows() != 1)
{
error_message("error", "Error", "An Error Occured. Your Vote has NOT been Counted.");
}
}
else
{
error_message("error", "Error", "Please Select an Option.");
}
}
$topicid = (int) $_GET["topicid"];
if (!is_valid_id($topicid))
{
error_message("error", "Error", "Invalid Topic ID!2");
}
//-- Get topic info
$res = sql_query("SELECT ".($use_poll_mod ? 't.pollid, ' : '')."t.locked, t.subject, t.sticky, t.userid AS t_userid, t.forumid, f.name AS forum_name, f.minclassread, f.minclasswrite, f.minclasscreate, (SELECT COUNT(id) FROM posts WHERE topicid = t.id) AS p_count
FROM topics AS t
LEFT JOIN forums AS f ON f.id = t.forumid
WHERE t.id = ".sqlesc($topicid)) or sqlerr(__FILE__, __LINE__);
$arr = mysqli_fetch_assoc($res) or error_message("error", "Error", "Topic NOT Found");
if ($use_poll_mod && is_valid_id($pollid))
{
$res = sql_query("SELECT p.*, pa.id AS pa_id, pa.selection
FROM postpolls AS p
LEFT JOIN postpollanswers AS pa ON pa.pollid = p.id AND pa.userid = ".$CURUSER['id']."
WHERE p.id = ".sqlesc($pollid)) or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) > 0)
{
$arr1 = mysqli_fetch_assoc($res);
if ($CURUSER['class'] >= UC_ADMINISTRATOR)
{
if (!$listvotes)
{
echo "List Voters";
}
else
{
$res4 = sql_query("SELECT pa.userid, u.username
FROM postpollanswers AS pa
LEFT JOIN users AS u ON u.id = pa.userid
WHERE pa.pollid = ".sqlesc($pollid)) or sqlerr(__FILE__, __LINE__);
$voters = '';
while ($arr4 = mysqli_fetch_assoc($res4))
{
if (!empty($voters) && !empty($arr4['username']))
{
$voters .= ', ';
}
error_message("error", "Sorry", "Poll Does Not Exist");
}
?>
}
?>
//-- Print table
begin_frame();
$res = sql_query("SELECT p.id, p.added, p.userid, p.added, p.body, p.editedby, p.editedat, u.id AS uid, u.username AS uusername, u.class, u.avatar, u.donor, u.title, u.country, u.enabled, u.warned, u.uploaded, u.downloaded, u.signature, u.last_access, (SELECT COUNT(id) FROM posts WHERE userid = u.id) AS posts_count, u2.username AS u2_username ".($use_attachment_mod ? ", at.id AS at_id, at.filename AS at_filename, at.postid AS at_postid, at.size AS at_size, at.downloads AS at_downloads, at.owner AS at_owner " : "").", (SELECT lastpostread FROM readposts WHERE userid = ".sqlesc((int) $CURUSER['id']).""."AND topicid = p.topicid LIMIT 1) AS lastpostread "."FROM posts AS p "."LEFT JOIN users AS u ON p.userid = u.id ".($use_attachment_mod ? "LEFT JOIN attachments AS at ON at.postid = p.id " : "")."LEFT JOIN users AS u2 ON u2.id = p.editedby "."WHERE p.topicid = ".sqlesc($topicid)." ORDER BY id LIMIT $offset, $perpage") or sqlerr(__FILE__, __LINE__);
if (($postid > $lpr) && ($postadd > (get_date_time(gmtime() - $posts_read_expiry))))
{
if ($lpr)
{
sql_query("UPDATE readposts
SET lastpostread = $postid
WHERE userid = $userid
AND topicid = $topicid") or sqlerr(__FILE__, __LINE__);
}
else
{
sql_query("INSERT INTO readposts (userid, topicid, lastpostread)
VALUES($userid, $topicid, $postid)") or sqlerr(__FILE__, __LINE__);
}
}
if ($locked && $CURUSER['class'] < UC_SITE_EDITOR)
{
display_message("warn", "Sorry", "This Topic is Locked. No New Posts are Allowed.");
}
else
{
$arr = get_forum_access_levels($forumid);
if ($CURUSER['class'] < $arr["write"])
{
display_message("warn", "Sorry", "You are Mot Permitted to Post in this Forum.");
if (!is_valid_id($topicid))
{
error_message("error", "Error", "Invalid ID!");
}
if ( $CURUSER['forumpos'] == 'no' )
{
site_header("Post Reply");
error_message("error", "Error", "Your Forum Privilage Has Been Disabled");
site_footer();
exit();
}
else
{
site_header("Post Reply");
insert_compose_frame($topicid, false, false, true);
site_footer();
exit();
}
}
else if ($action == "editpost") //-- Action: Edit Post --//
{
$postid = (int) $_GET["postid"];
if (!is_valid_id($postid))
{
error_message("error", "Error", "Invalid ID!");
}
$res = sql_query("SELECT p.userid, p.topicid, p.body, t.locked
FROM posts AS p
LEFT JOIN topics AS t ON t.id = p.topicid
WHERE p.id = ".sqlesc($postid)) or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) == 0)
{
error_message("error", "Error", "No Post with that ID!");
}
sql_query("UPDATE posts
SET body = ".sqlesc($body).", editedat = ".sqlesc(get_date_time()).", editedby = {$CURUSER['id']}
WHERE id = $postid") or sqlerr(__FILE__, __LINE__);
if (!is_valid_id($postid))
{
error_message("error", "Error", "Invalid ID");
}
$res = sql_query("SELECT p.topicid".($use_attachment_mod ? ", a.filename" : "").", (SELECT COUNT(id) FROM posts WHERE topicid=p.topicid) AS posts_count, (SELECT MAX(id) FROM posts WHERE topicid=p.topicid AND id < p.id) AS p_id FROM posts AS p ".($use_attachment_mod ? "LEFT JOIN attachments AS a ON a.postid = p.id " : "")."
WHERE p.id=".sqlesc($postid)) or sqlerr(__FILE__, __LINE__);
$arr = mysqli_fetch_assoc($res) or error_message("error", "Error", "Post NOT Found");
if ($subaction == "edit")
{
if (!is_valid_id($pollid))
{
error_message("error", "Error", "Invalid ID!");
}
$res = sql_query("SELECT pp.*, t.id AS tid
FROM postpolls AS pp
LEFT JOIN topics AS t ON t.pollid = pp.id
WHERE pp.id = ".sqlesc($pollid)) or sqlerr(__FILE__, __LINE__);
if (mysqli_num_rows($res) == 0)
{
error_message("error", "Error", "No Poll found with that ID.");
}
if (!is_file($filename))
{
die('Non-existent Attachment.');
}
if (!is_readable($filename))
{
die('Attachment is Unreadable.');
}
if ((isset($_GET['subaction']) ? $_GET['subaction'] : '') == 'delete')
{
if ($CURUSER['id'] <> $resat["owner"] && $CURUSER['class'] < UC_SITE_EDITOR)
{
die('Not your Attachment to Delete.');
}
unlink($filename);
sql_query("DELETE attachments, attachmentdownloads
FROM attachments
LEFT JOIN attachmentdownloads ON attachmentdownloads.fileid = attachments.id
WHERE attachments.id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
die("File Successfully Deleted");
}
sql_query("UPDATE attachments
SET downloads = downloads + 1
WHERE id = ".sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$res = sql_query("SELECT fileid
FROM attachmentdownloads
WHERE fileid=".sqlesc($id)."
AND userid=".sqlesc($CURUSER['id']));
if (mysqli_num_rows($res) == 0)
{
sql_query("INSERT INTO attachmentdownloads (fileid, username, userid, date, downloads)
VALUES (".sqlesc($id).", ".sqlesc($CURUSER['username']).", ".sqlesc($CURUSER['id']).", ".sqlesc(get_date_time()).", 1)") or sqlerr(__FILE__, __LINE__);
}
else
{
sql_query("UPDATE attachmentdownloads
SET downloads = downloads + 1
WHERE fileid = ".sqlesc($id)."
AND userid = ".sqlesc($CURUSER['id']));
}
if (!is_valid_id($fileid))
{
die('Invalid ID!');
}
$res = sql_query("SELECT fileid, at.filename, userid, username, atdl.downloads, date, at.downloads AS dl
FROM attachmentdownloads AS atdl
LEFT JOIN attachments AS at ON at.id=atdl.fileid
WHERE fileid = ".sqlesc($fileid).($CURUSER['class'] < UC_SITE_EDITOR ? "
AND owner=".$CURUSER['id'] : '')) or sqlerr(__FILE__, __LINE__);
//-- Get Forum Details --//
$res = sql_query("SELECT f.name AS forum_name, f.minclassread, (SELECT COUNT(id) FROM topics WHERE forumid = f.id) AS t_count FROM forums AS f
WHERE f.id = ".sqlesc($forumid)) or sqlerr(__FILE__, __LINE__);
$arr = mysqli_fetch_assoc($res) or error_message("error", "Error", "No Forum with that ID!");
if ($CURUSER['class'] < $arr["minclassread"])
{
error_message("warn", "Warning", "Access Denied!");
}
$topics_res = sql_query("SELECT t.id, t.userid, t.views, t.locked, t.sticky".($use_poll_mod ? ', t.pollid' : '').", t.subject, u1.username, r.lastpostread, p.id AS p_id, p.userid AS p_userid, p.added AS p_added, (SELECT COUNT(id) FROM posts WHERE topicid=t.id) AS p_count, u2.username AS u2_username
FROM topics AS t
LEFT JOIN users AS u1 ON u1.id=t.userid
LEFT JOIN readposts AS r ON r.userid = ".sqlesc($userid)." AND r.topicid = t.id
LEFT JOIN posts AS p ON p.id = (SELECT MAX(id) FROM posts WHERE topicid = t.id)
LEFT JOIN users AS u2 ON u2.id = p.userid
WHERE t.forumid = ".sqlesc($forumid)."
ORDER BY t.sticky, t.lastpost DESC
LIMIT $offset, $perpage") or sqlerr(__FILE__, __LINE__);
site_header("Forum");
?>
$arr = get_forum_access_levels($forumid) or die();
$res = sql_query('SELECT t.lastpost, r.lastpostread, f.minclassread
FROM topics AS t
LEFT JOIN posts AS p ON t.lastpost=p.id
LEFT JOIN readposts AS r ON r.userid='.sqlesc((int) $CURUSER['id']).' AND r.topicid=t.id
LEFT JOIN forums AS f ON f.id=t.forumid
WHERE p.added > '.$added) or sqlerr(__FILE__, __LINE__);
$count = 0;
while ($arr = mysqli_fetch_assoc($res))
{
if ($arr['lastpostread'] >= $arr['lastpost'] || $CURUSER['class'] < $arr['minclassread'])
{
continue;
}