2011-03-28 14:21:28 +00:00
|
|
|
<?
|
|
|
|
/*********************************************************************\
|
|
|
|
//--------------Mod thread-------------------------------------------//
|
|
|
|
|
2013-02-22 08:00:24 +00:00
|
|
|
This page gets called if we're editing a thread.
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
Known issues:
|
2013-02-22 08:00:24 +00:00
|
|
|
If multiple threads are moved before forum activity occurs then
|
|
|
|
threads will linger with the 'Moved' flag until they're knocked off
|
2011-03-28 14:21:28 +00:00
|
|
|
the front page.
|
|
|
|
|
|
|
|
\*********************************************************************/
|
2013-08-28 23:08:41 +00:00
|
|
|
define("TRASH_FORUM_ID", 12);
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
// Quick SQL injection check
|
2013-04-19 08:00:55 +00:00
|
|
|
if (!is_number($_POST['threadid'])) {
|
|
|
|
error(404);
|
|
|
|
}
|
2013-05-04 08:00:48 +00:00
|
|
|
if ($_POST['title'] == '') {
|
2013-04-19 08:00:55 +00:00
|
|
|
error(0);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
// End injection check
|
|
|
|
// Make sure they are moderators
|
2013-04-19 08:00:55 +00:00
|
|
|
if (!check_perms('site_moderate_forums')) {
|
|
|
|
error(403);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
authorize();
|
|
|
|
|
|
|
|
// Variables for database input
|
|
|
|
|
|
|
|
$TopicID = (int)$_POST['threadid'];
|
|
|
|
$Sticky = (isset($_POST['sticky'])) ? 1 : 0;
|
|
|
|
$Locked = (isset($_POST['locked'])) ? 1 : 0;
|
2013-07-01 08:01:00 +00:00
|
|
|
$Ranking = (int) $_POST['ranking'];
|
2013-07-02 08:01:37 +00:00
|
|
|
if (!$Sticky && $Ranking > 0) {
|
2013-07-01 08:01:00 +00:00
|
|
|
$Ranking = 0;
|
2013-07-02 08:01:37 +00:00
|
|
|
} elseif (0 > $Ranking) {
|
2013-07-01 08:01:00 +00:00
|
|
|
error("Ranking cannot be a negative value");
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
$Title = db_string($_POST['title']);
|
2012-04-02 08:00:21 +00:00
|
|
|
$RawTitle = $_POST['title'];
|
2011-03-28 14:21:28 +00:00
|
|
|
$ForumID = (int)$_POST['forumid'];
|
|
|
|
$Page = (int)$_POST['page'];
|
2013-08-28 23:08:41 +00:00
|
|
|
$Action = "";
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2012-04-02 08:00:21 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
if ($Locked == 1) {
|
2012-04-02 08:00:21 +00:00
|
|
|
|
2013-07-02 08:01:37 +00:00
|
|
|
$DB->query("
|
|
|
|
DELETE FROM forums_last_read_topics
|
|
|
|
WHERE TopicID = '$TopicID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
t.ForumID,
|
|
|
|
f.MinClassWrite,
|
2013-08-28 23:08:41 +00:00
|
|
|
COUNT(p.ID) AS Posts,
|
|
|
|
t.AuthorID
|
2011-03-28 14:21:28 +00:00
|
|
|
FROM forums_topics AS t
|
2013-07-02 08:01:37 +00:00
|
|
|
LEFT JOIN forums_posts AS p ON p.TopicID = t.ID
|
|
|
|
LEFT JOIN forums AS f ON f.ID = t.ForumID
|
|
|
|
WHERE t.ID = '$TopicID'
|
2011-03-28 14:21:28 +00:00
|
|
|
GROUP BY p.TopicID");
|
2013-08-28 23:08:41 +00:00
|
|
|
list($OldForumID, $MinClassWrite, $Posts, $ThreadAuthorID) = $DB->next_record();
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
if ($MinClassWrite > $LoggedUser['Class']) {
|
|
|
|
error(403);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
// If we're moving
|
2013-07-02 08:01:37 +00:00
|
|
|
$Cache->delete_value("forums_$ForumID");
|
|
|
|
$Cache->delete_value("forums_$OldForumID");
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
// If we're deleting a thread
|
2013-04-19 08:00:55 +00:00
|
|
|
if (isset($_POST['delete'])) {
|
|
|
|
if (check_perms('site_admin_forums')) {
|
2013-07-02 08:01:37 +00:00
|
|
|
$DB->query("
|
|
|
|
DELETE FROM forums_posts
|
|
|
|
WHERE TopicID = '$TopicID'");
|
|
|
|
$DB->query("
|
|
|
|
DELETE FROM forums_topics
|
|
|
|
WHERE ID = '$TopicID'");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
t.ID,
|
|
|
|
t.LastPostID,
|
|
|
|
t.Title,
|
|
|
|
p.AuthorID,
|
|
|
|
um.Username,
|
|
|
|
p.AddedTime,
|
2013-07-02 08:01:37 +00:00
|
|
|
(
|
|
|
|
SELECT COUNT(pp.ID)
|
2013-04-19 08:00:55 +00:00
|
|
|
FROM forums_posts AS pp
|
2013-07-02 08:01:37 +00:00
|
|
|
JOIN forums_topics AS tt ON pp.TopicID = tt.ID
|
|
|
|
WHERE tt.ForumID = '$ForumID'
|
|
|
|
),
|
2013-04-19 08:00:55 +00:00
|
|
|
t.IsLocked,
|
|
|
|
t.IsSticky
|
2013-02-22 08:00:24 +00:00
|
|
|
FROM forums_topics AS t
|
2013-07-02 08:01:37 +00:00
|
|
|
JOIN forums_posts AS p ON p.ID = t.LastPostID
|
|
|
|
LEFT JOIN users_main AS um ON um.ID = p.AuthorID
|
|
|
|
WHERE t.ForumID = '$ForumID'
|
2011-06-15 08:00:05 +00:00
|
|
|
GROUP BY t.ID
|
2013-04-19 08:00:55 +00:00
|
|
|
ORDER BY t.LastPostID DESC
|
|
|
|
LIMIT 1");
|
2012-06-16 08:00:18 +00:00
|
|
|
list($NewLastTopic, $NewLastPostID, $NewLastTitle, $NewLastAuthorID, $NewLastAuthorName, $NewLastAddedTime, $NumPosts, $NewLocked, $NewSticky) = $DB->next_record(MYSQLI_NUM, false);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums
|
|
|
|
SET
|
2013-07-02 08:01:37 +00:00
|
|
|
NumTopics = NumTopics - 1,
|
|
|
|
NumPosts = NumPosts - '$Posts',
|
|
|
|
LastPostTopicID = '$NewLastTopic',
|
|
|
|
LastPostID = '$NewLastPostID',
|
|
|
|
LastPostAuthorID = '$NewLastAuthorID',
|
|
|
|
LastPostTime = '$NewLastAddedTime'
|
2011-06-15 08:00:05 +00:00
|
|
|
WHERE ID='$ForumID'");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-07-02 08:01:37 +00:00
|
|
|
$Cache->delete_value("thread_$TopicID");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-06-15 08:00:05 +00:00
|
|
|
$Cache->begin_transaction('forums_list');
|
|
|
|
$UpdateArray = array(
|
2013-04-19 08:00:55 +00:00
|
|
|
'NumPosts' => $NumPosts,
|
|
|
|
'NumTopics' => '-1',
|
|
|
|
'LastPostID' => $NewLastPostID,
|
|
|
|
'LastPostAuthorID' => $NewLastAuthorID,
|
|
|
|
'LastPostTopicID' => $NewLastTopic,
|
|
|
|
'LastPostTime' => $NewLastAddedTime,
|
|
|
|
'Title' => $NewLastTitle,
|
|
|
|
'IsLocked' => $NewLocked,
|
|
|
|
'IsSticky' => $NewSticky
|
2011-06-15 08:00:05 +00:00
|
|
|
);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-06-15 08:00:05 +00:00
|
|
|
$Cache->update_row($ForumID, $UpdateArray);
|
|
|
|
$Cache->commit_transaction(0);
|
2013-07-02 08:01:37 +00:00
|
|
|
$Cache->delete_value("thread_{$TopicID}_info");
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-08-28 23:08:41 +00:00
|
|
|
// subscriptions
|
|
|
|
Subscriptions::move_subscriptions('forums', $TopicID, null);
|
|
|
|
|
|
|
|
// quote notifications
|
|
|
|
Subscriptions::flush_quote_notifications('forums', $TopicID);
|
|
|
|
$DB->query("DELETE FROM users_notify_quoted WHERE Page = 'forums' AND PageID = '".$TopicID."'");
|
|
|
|
|
2011-06-15 08:00:05 +00:00
|
|
|
header('Location: forums.php?action=viewforum&forumid='.$ForumID);
|
|
|
|
} else {
|
|
|
|
error(403);
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
} else { // If we're just editing it
|
2013-05-16 16:15:57 +00:00
|
|
|
|
2013-07-02 08:01:37 +00:00
|
|
|
$Cache->begin_transaction("thread_{$TopicID}_info");
|
2011-03-28 14:21:28 +00:00
|
|
|
$UpdateArray = array(
|
2013-04-19 08:00:55 +00:00
|
|
|
'IsSticky' => $Sticky,
|
2013-07-01 08:01:00 +00:00
|
|
|
'Ranking' => $Ranking,
|
2013-04-19 08:00:55 +00:00
|
|
|
'IsLocked' => $Locked,
|
|
|
|
'Title' => Format::cut_string($RawTitle, 150, 1, 0),
|
|
|
|
'ForumID' => $ForumID
|
2011-03-28 14:21:28 +00:00
|
|
|
);
|
|
|
|
$Cache->update_row(false, $UpdateArray);
|
|
|
|
$Cache->commit_transaction(0);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums_topics
|
|
|
|
SET
|
|
|
|
IsSticky = '$Sticky',
|
2013-07-01 08:01:00 +00:00
|
|
|
Ranking = '$Ranking',
|
2013-04-19 08:00:55 +00:00
|
|
|
IsLocked = '$Locked',
|
|
|
|
Title = '$Title',
|
2013-07-02 08:01:37 +00:00
|
|
|
ForumID = '$ForumID'
|
|
|
|
WHERE ID = '$TopicID'");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
if ($ForumID != $OldForumID) { // If we're moving a thread, change the forum stats
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-07-02 08:01:37 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT MinClassRead, MinClassWrite, Name
|
|
|
|
FROM forums
|
|
|
|
WHERE ID = '$ForumID'");
|
2012-06-16 08:00:18 +00:00
|
|
|
list($MinClassRead, $MinClassWrite, $ForumName) = $DB->next_record(MYSQLI_NUM, false);
|
2013-07-02 08:01:37 +00:00
|
|
|
$Cache->begin_transaction("thread_{$TopicID}_info");
|
2011-03-28 14:21:28 +00:00
|
|
|
$UpdateArray = array(
|
2013-04-19 08:00:55 +00:00
|
|
|
'ForumName' => $ForumName,
|
|
|
|
'MinClassRead' => $MinClassRead,
|
|
|
|
'MinClassWrite' => $MinClassWrite
|
2011-03-28 14:21:28 +00:00
|
|
|
);
|
|
|
|
$Cache->update_row(false, $UpdateArray);
|
2013-04-19 08:00:55 +00:00
|
|
|
$Cache->commit_transaction(3600 * 24 * 5);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$Cache->begin_transaction('forums_list');
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
// Forum we're moving from
|
2013-04-19 08:00:55 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
t.ID,
|
|
|
|
t.LastPostID,
|
|
|
|
t.Title,
|
|
|
|
p.AuthorID,
|
|
|
|
um.Username,
|
|
|
|
p.AddedTime,
|
2013-07-02 08:01:37 +00:00
|
|
|
(
|
|
|
|
SELECT COUNT(pp.ID)
|
2013-04-19 08:00:55 +00:00
|
|
|
FROM forums_posts AS pp
|
2013-07-02 08:01:37 +00:00
|
|
|
JOIN forums_topics AS tt ON pp.TopicID = tt.ID
|
|
|
|
WHERE tt.ForumID = '$OldForumID'
|
|
|
|
),
|
2013-04-19 08:00:55 +00:00
|
|
|
t.IsLocked,
|
2013-07-01 08:01:00 +00:00
|
|
|
t.IsSticky,
|
|
|
|
t.Ranking
|
2013-02-22 08:00:24 +00:00
|
|
|
FROM forums_topics AS t
|
2013-07-02 08:01:37 +00:00
|
|
|
JOIN forums_posts AS p ON p.ID = t.LastPostID
|
|
|
|
LEFT JOIN users_main AS um ON um.ID = p.AuthorID
|
|
|
|
WHERE t.ForumID = '$OldForumID'
|
2013-04-19 08:00:55 +00:00
|
|
|
ORDER BY t.LastPostID DESC
|
|
|
|
LIMIT 1");
|
2013-07-01 08:01:00 +00:00
|
|
|
list($NewLastTopic, $NewLastPostID, $NewLastTitle, $NewLastAuthorID, $NewLastAuthorName, $NewLastAddedTime, $NumPosts, $NewLocked, $NewSticky, $NewRanking) = $DB->next_record(MYSQLI_NUM, false);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums
|
|
|
|
SET
|
2013-07-02 08:01:37 +00:00
|
|
|
NumTopics = NumTopics - 1,
|
|
|
|
NumPosts = NumPosts - '$Posts',
|
|
|
|
LastPostTopicID = '$NewLastTopic',
|
|
|
|
LastPostID = '$NewLastPostID',
|
|
|
|
LastPostAuthorID = '$NewLastAuthorID',
|
|
|
|
LastPostTime = '$NewLastAddedTime'
|
|
|
|
WHERE ID = '$OldForumID'");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$UpdateArray = array(
|
2013-04-19 08:00:55 +00:00
|
|
|
'NumPosts' => $NumPosts,
|
|
|
|
'NumTopics' => '-1',
|
|
|
|
'LastPostID' => $NewLastPostID,
|
|
|
|
'LastPostAuthorID' => $NewLastAuthorID,
|
|
|
|
'LastPostTopicID' => $NewLastTopic,
|
|
|
|
'LastPostTime' => $NewLastAddedTime,
|
|
|
|
'Title' => $NewLastTitle,
|
|
|
|
'IsLocked' => $NewLocked,
|
2013-07-01 08:01:00 +00:00
|
|
|
'IsSticky' => $NewSticky,
|
|
|
|
'Ranking' => $NewRanking
|
2011-03-28 14:21:28 +00:00
|
|
|
);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$Cache->update_row($OldForumID, $UpdateArray);
|
|
|
|
|
|
|
|
// Forum we're moving to
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
t.ID,
|
|
|
|
t.LastPostID,
|
|
|
|
t.Title,
|
|
|
|
p.AuthorID,
|
|
|
|
um.Username,
|
|
|
|
p.AddedTime,
|
2013-07-02 08:01:37 +00:00
|
|
|
(
|
|
|
|
SELECT COUNT(pp.ID)
|
2013-04-19 08:00:55 +00:00
|
|
|
FROM forums_posts AS pp
|
2013-07-02 08:01:37 +00:00
|
|
|
JOIN forums_topics AS tt ON pp.TopicID = tt.ID
|
|
|
|
WHERE tt.ForumID = '$ForumID')
|
2013-04-19 08:00:55 +00:00
|
|
|
FROM forums_topics AS t
|
2013-07-02 08:01:37 +00:00
|
|
|
JOIN forums_posts AS p ON p.ID = t.LastPostID
|
|
|
|
LEFT JOIN users_main AS um ON um.ID = p.AuthorID
|
|
|
|
WHERE t.ForumID = '$ForumID'
|
2013-04-19 08:00:55 +00:00
|
|
|
ORDER BY t.LastPostID DESC
|
|
|
|
LIMIT 1");
|
2012-06-16 08:00:18 +00:00
|
|
|
list($NewLastTopic, $NewLastPostID, $NewLastTitle, $NewLastAuthorID, $NewLastAuthorName, $NewLastAddedTime, $NumPosts) = $DB->next_record(MYSQLI_NUM, false);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums
|
|
|
|
SET
|
2013-07-02 08:01:37 +00:00
|
|
|
NumTopics = NumTopics + 1,
|
|
|
|
NumPosts = NumPosts + '$Posts',
|
|
|
|
LastPostTopicID = '$NewLastTopic',
|
|
|
|
LastPostID = '$NewLastPostID',
|
|
|
|
LastPostAuthorID = '$NewLastAuthorID',
|
|
|
|
LastPostTime = '$NewLastAddedTime'
|
|
|
|
WHERE ID = '$ForumID'");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$UpdateArray = array(
|
2013-04-19 08:00:55 +00:00
|
|
|
'NumPosts' => ($NumPosts + $Posts),
|
|
|
|
'NumTopics' => '+1',
|
|
|
|
'LastPostID' => $NewLastPostID,
|
|
|
|
'LastPostAuthorID' => $NewLastAuthorID,
|
|
|
|
'LastPostTopicID' => $NewLastTopic,
|
|
|
|
'LastPostTime' => $NewLastAddedTime,
|
|
|
|
'Title' => $NewLastTitle
|
2011-03-28 14:21:28 +00:00
|
|
|
);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$Cache->update_row($ForumID, $UpdateArray);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-03-28 14:21:28 +00:00
|
|
|
$Cache->commit_transaction(0);
|
2013-08-28 23:08:41 +00:00
|
|
|
|
|
|
|
if ($ForumID == TRASH_FORUM_ID) {
|
|
|
|
$Action = "trashing";
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
} else { // Editing
|
2013-07-02 08:01:37 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT LastPostTopicID
|
|
|
|
FROM forums
|
|
|
|
WHERE ID = '$ForumID'");
|
2011-03-28 14:21:28 +00:00
|
|
|
list($LastTopicID) = $DB->next_record();
|
2013-04-19 08:00:55 +00:00
|
|
|
if ($LastTopicID == $TopicID) {
|
2011-03-28 14:21:28 +00:00
|
|
|
$UpdateArray = array(
|
2013-04-19 08:00:55 +00:00
|
|
|
'Title' => $RawTitle,
|
|
|
|
'IsLocked' => $Locked,
|
2013-07-01 08:01:00 +00:00
|
|
|
'IsSticky' => $Sticky,
|
|
|
|
'Ranking' => $Ranking
|
2011-03-28 14:21:28 +00:00
|
|
|
);
|
|
|
|
$Cache->begin_transaction('forums_list');
|
|
|
|
$Cache->update_row($ForumID, $UpdateArray);
|
|
|
|
$Cache->commit_transaction(0);
|
|
|
|
}
|
|
|
|
}
|
2013-04-19 08:00:55 +00:00
|
|
|
if ($Locked) {
|
|
|
|
$CatalogueID = floor($NumPosts / THREAD_CATALOGUE);
|
|
|
|
for ($i = 0; $i <= $CatalogueID; $i++) {
|
2013-07-02 08:01:37 +00:00
|
|
|
$Cache->expire_value("thread_{$TopicID}_catalogue_$i", 3600 * 24 * 7); // 7 days
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-07-02 08:01:37 +00:00
|
|
|
$Cache->expire_value("thread_{$TopicID}_info", 3600 * 24 * 7); // 7 days
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2013-07-02 08:01:37 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE forums_polls
|
|
|
|
SET Closed = '0'
|
|
|
|
WHERE TopicID = '$TopicID'");
|
|
|
|
$Cache->delete_value("polls_$TopicID");
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-08-28 23:08:41 +00:00
|
|
|
if (isset($Action)) {
|
|
|
|
switch ($Action) {
|
|
|
|
case "implementing":
|
|
|
|
$Notification = "Your suggestion '$NewLastTitle' has been implemented";
|
|
|
|
break;
|
|
|
|
case "rejecting":
|
|
|
|
$Notification = "Your suggestion '$NewLastTitle' has been rejected";
|
|
|
|
break;
|
|
|
|
case "trashing":
|
|
|
|
$Notification = "Your thread '$NewLastTitle' has been trashed";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (isset($Notification)) {
|
|
|
|
NotificationsManager::notify_user($ThreadAuthorID, NotificationsManager::FORUMALERTS, $Notification, 'forums.php?action=viewthread&threadid='.$TopicID);
|
|
|
|
}
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
header('Location: forums.php?action=viewthread&threadid='.$TopicID.'&page='.$Page);
|
|
|
|
}
|