$arr["minclassread"], "write" => $arr["minclasswrite"], "create" => $arr["minclasscreate"]);
}
//-------- Returns the forum ID of a topic, or false on error
function get_topic_forum($topicid)
{
$res = do_mysql_query("SELECT forumid FROM topics WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) != 1)
return false;
$arr = mysql_fetch_row($res);
return $arr[0];
}
//-------- Returns the ID of the last post of a forum
function update_topic_last_post($topicid)
{
$res = do_mysql_query("SELECT id FROM posts WHERE topicid=$topicid ORDER BY id DESC LIMIT 1") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res) or die("No post found");
$postid = $arr[0];
$lastpost_txt ='';
do_mysql_query("UPDATE topics SET lastpost=$postid, lastpost_txt='$lastpost_txt' WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
}
function get_forum_last_post($forumid)
{
$res = do_mysql_query("SELECT lastpost FROM topics WHERE forumid=$forumid ORDER BY lastpost DESC LIMIT 1") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res);
$postid = $arr[0];
if ($postid)
return $postid;
else
return 0;
}
//-------- Inserts a quick jump menu
function insert_quick_jump_menu($currentforum = 0)
{
print("\n");
}
//-------- Inserts a compose frame
function insert_compose_frame($id, $newtopic = true, $quote = false)
{
global $maxsubjectlength, $CURUSER;
if ($newtopic)
{
$res = do_mysql_query("SELECT name FROM forums WHERE id=". (int) $id) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die("Bad forum id");
$forumname = $arr["name"];
print("
\n");
stdfoot();
die;
}
//-------- Action: Delete post
if ($action == "deletepost")
{
$postid = (int) $_GET["postid"];
$sure = (int) $_GET["sure"];
if (get_user_class() < UC_MODERATOR || !is_valid_id($postid))
stderr( _("Error"),_("Permission denied"));
//------- Get topic id
$res = do_mysql_query("SELECT topicid FROM posts WHERE id=$postid") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res) or stderr( _("Error"), "Post not found");
$topicid = $arr[0];
//------- We can not delete the post if it is the only one of the topic
$res = do_mysql_query("SELECT COUNT(*) FROM posts WHERE topicid=$topicid") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res);
if ($arr[0] < 2)
stderr( _("Error"), "Can't delete post; it is the only post of the topic. You should\n" .
"delete the topic instead.\n");
/*
//------- Get the id of the last post before the one we're deleting
$res = do_mysql_query("SELECT id FROM posts WHERE topicid=$topicid AND id < $postid ORDER BY id DESC LIMIT 1") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
$redirtopost = "";
else
{
$arr = mysql_fetch_row($res);
$redirtopost = "&page=p$arr[0]#$arr[0]";
}
*/
//------- Make sure we know what we do :-)
if (!$sure)
{
stderr("Delete post", "Sanity check: You are about to delete a post. Click\n" .
"here if you are sure.");
}
//------- Delete post
do_mysql_query("DELETE FROM posts WHERE id=$postid") or sqlerr(__FILE__, __LINE__);
//Update topic reply counter
do_mysql_query("UPDATE topics SET replies=replies-1 WHERE topicid=".$topicid);
//------- Update topic
//update_topic_last_post($topicid);
header("Location: forums.php?action=viewtopic&topicid=$topicid$redirtopost");
die;
}
//-------- Action: Lock topic
if ($action == "locktopic")
{
$forumid = (int) $_GET["forumid"];
$topicid = (int) $_GET["topicid"];
$page = (int) $_GET["page"];
if (!is_valid_id($topicid) || get_user_class() < UC_MODERATOR)
stderr( _("Error"),_("Permission denied"));
do_mysql_query("UPDATE topics SET locked='yes' WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
header("Location: forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
//-------- Action: Unlock topic
if ($action == "unlocktopic")
{
$forumid = (int) $_GET["forumid"];
$topicid = (int) $_GET["topicid"];
$page = (int) $_GET["page"];
if (!is_valid_id($topicid) || get_user_class() < UC_MODERATOR)
die;
do_mysql_query("UPDATE topics SET locked='no' WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
header("Location: forums.php?action=viewforum&forumid=$forumid&page=$page");
die;
}
//-------- Action: Set locked on/off
if ($action == "setlocked")
{
$topicid = (int) $_POST["topicid"];
if (!$topicid || get_user_class() < UC_MODERATOR)
stderr( _("Error"),_("Permission denied"));
$locked = sqlesc($_POST["locked"]);
do_mysql_query("UPDATE topics SET locked=$locked WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
header("Location: $_POST[returnto]");
die;
}
//-------- Action: Set sticky on/off
if ($action == "setsticky")
{
$topicid = (int) $_POST["topicid"];
if (!$topicid || get_user_class() < UC_MODERATOR)
stderr( _("Error"),_("Permission denied"));
$sticky = sqlesc($_POST["sticky"]);
do_mysql_query("UPDATE topics SET sticky=$sticky WHERE id=$topicid") or sqlerr(__FILE__, __LINE__);
header("Location: $_POST[returnto]");
die;
}
//-------- Action: Rename topic
if ($action == 'renametopic')
{
if( get_user_class() < UC_MODERATOR)
stderr( _("Error"),_("Permission denied"));
$topicid = (int) $_POST['topicid'];
if (!is_valid_id($topicid))
stderr( _("Error"),"Invalid ID");
$subject = htmlspecialchars($_POST['subject']);
if ($subject == '')
stderr('Error', 'You must enter a new title!');
$subject = sqlesc($subject);
do_mysql_query("UPDATE topics SET subject=$subject WHERE id=$topicid") or sqlerr();
$returnto = '?action=viewtopic&topicid='.$topicid;
if ($returnto)
header("Location: $returnto");
die;
}
//-------- Action: View forum
if ($action == "viewforum")
{
$forumid = (int) $_GET["forumid"];
if (!is_valid_id($forumid))
stderr( _("Error"),"Invalid ID");
$page = (int) $_GET["page"];
$userid = $CURUSER["id"];
//------ Get forum name
$res = do_mysql_query("SELECT name, minclassread, topiccount FROM forums WHERE id=".$forumid) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res) or die;
$forumname = $arr["name"];
if (get_user_class() < $arr["minclassread"])
stderr( _("Error"),_("Permission denied"));
//------ Get topic count
$perpage = $CURUSER["topicsperpage"];
if (!$perpage) $perpage = 20;
/*
$res = do_mysql_query("SELECT COUNT(*) FROM topics WHERE forumid=$forumid") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res);
$num = $arr[0];
*/
$num = $arr['topiccount'];
if ($page == 0)
$page = 1;
$first = ($page * $perpage) - $perpage + 1;
$last = $first + $perpage - 1;
if ($last > $num)
$last = $num;
$pages = floor($num / $perpage);
if ($perpage * $pages < $num)
++$pages;
//------ Build menu
$menu = "
\n";
$offset = $first - 1;
//------ Get topics data
$topicsres = do_mysql_query("SELECT
t.*,
u.id as user_id,
u.username as user_name
FROM topics t
LEFT JOIN users u ON t.userid = u.id
WHERE
t.forumid=$forumid
ORDER BY t.sticky, t.lastpost DESC LIMIT $offset,$perpage") or
stderr("SQL Error", mysql_error());
stdhead("Forum");
$numtopics = mysql_num_rows($topicsres);
print("