Empty commit

This commit is contained in:
Git 2013-10-14 08:00:53 +00:00
parent 7100fdf7a7
commit 4a141a9ed9
24 changed files with 522 additions and 188 deletions

View File

@ -251,6 +251,21 @@ public static function get_last_read($Forums) {
return $LastRead;
}
/**
* Add a note to a topic.
* @param int $TopicID
* @param string $Note
* @param int|null $UserID
* @return boolean
*/
public static function add_topic_note($TopicID, $Note, $UserID = null) {
$UserID = $UserID ?: G::$LoggedUser['ID'];
$QueryID = G::$DB->get_query_id();
G::$DB->query("INSERT INTO forums_topic_notes (TopicID, AuthorID, AddedTime, Body) VALUES ($TopicID, $UserID, '" . sqltime() . "', '" . db_string($Note) . "')");
G::$DB->set_query_id($QueryID);
return (bool)G::$DB->affected_rows();
}
/**
* Determine if a thread is unread
* @param bool $Locked

View File

@ -122,7 +122,13 @@ protected function send_raw($Text) {
}
public function send_to($Channel, $Text) {
$this->send_raw("PRIVMSG $Channel :$Text");
// split the message up into <= 460 character strings and send each individually
// this is used to prevent messages from getting truncated
$Text = wordwrap($Text, 460, "\n", true);
$TextArray = explode("\n", $Text);
foreach ($TextArray as $Text) {
$this->send_raw("PRIVMSG $Channel :$Text");
}
}
protected function whois($Nick) {

View File

@ -1,5 +1,11 @@
CHANGE LOG
2013-10-13 by Y
Added thread notes in forums
2013-10-13 by Ajax
Added "Ask the Staff" tool for users to ask staff random questions.
2013-10-10 by alderaan
Users will receive a PM when they get promoted or demoted

View File

@ -429,6 +429,17 @@ CREATE TABLE `forums_specific_rules` (
`ThreadID` int(10) DEFAULT NULL
) ENGINE=InnoDB CHARSET utf8;
CREATE TABLE `forums_topic_notes` (
`ID` int(10) NOT NULL AUTO_INCREMENT,
`TopicID` int(10) NOT NULL,
`AuthorID` int(10) NOT NULL,
`AddedTime` datetime NOT NULL,
`Body` mediumtext,
PRIMARY KEY (`ID`),
KEY `TopicID` (`TopicID`),
KEY `AuthorID` (`AuthorID`)
) ENGINE=InnoDB CHARSET utf8;
CREATE TABLE `forums_topics` (
`ID` int(10) NOT NULL AUTO_INCREMENT,
`Title` varchar(150) NOT NULL,
@ -992,6 +1003,12 @@ CREATE TABLE `staff_blog_visits` (
CONSTRAINT `staff_blog_visits_ibfk_1` FOREIGN KEY (`UserID`) REFERENCES `users_main` (`ID`) ON DELETE CASCADE
) ENGINE=InnoDB CHARSET utf8;
CREATE TABLE `staff_ignored_questions` (
`QuestionID` int(10) NOT NULL,
`UserID` int(10) NOT NULL,
PRIMARY KEY (`QuestionID`,`UserID`)
) ENGINE=InnoDB CHARSET utf8;
CREATE TABLE `staff_pm_conversations` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Subject` text,
@ -1309,7 +1326,8 @@ CREATE TABLE `user_questions` (
`Question` mediumtext NOT NULL,
`UserID` int(10) NOT NULL,
`Date` datetime NOT NULL,
PRIMARY KEY (`ID`)
PRIMARY KEY (`ID`),
KEY `Date` (`Date`)
) ENGINE=InnoDB CHARSET utf8;
CREATE TABLE `users_collage_subs` (

View File

@ -32,6 +32,9 @@
case 'take_warn':
require(SERVER_ROOT.'/sections/forums/take_warn.php');
break;
case 'take_topic_notes':
require(SERVER_ROOT.'/sections/forums/take_topic_notes.php');
break;
default:
error(0);

View File

@ -10,7 +10,7 @@
the front page.
\*********************************************************************/
define("TRASH_FORUM_ID", 12);
define('TRASH_FORUM_ID', 12);
// Quick SQL injection check
if (!is_number($_POST['threadid'])) {
@ -35,13 +35,13 @@
if (!$Sticky && $Ranking > 0) {
$Ranking = 0;
} elseif (0 > $Ranking) {
error("Ranking cannot be a negative value");
error('Ranking cannot be a negative value');
}
$Title = db_string($_POST['title']);
$RawTitle = $_POST['title'];
$ForumID = (int)$_POST['forumid'];
$Page = (int)$_POST['page'];
$Action = "";
$Action = '';
if ($Locked == 1) {
@ -54,101 +54,108 @@
$DB->query("
SELECT
t.ForumID,
f.Name,
f.MinClassWrite,
COUNT(p.ID) AS Posts,
t.AuthorID
t.AuthorID,
t.Title,
t.IsLocked,
t.IsSticky,
t.Ranking
FROM forums_topics AS t
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'
GROUP BY p.TopicID");
list($OldForumID, $MinClassWrite, $Posts, $ThreadAuthorID) = $DB->next_record();
list($OldForumID, $OldForumName, $MinClassWrite, $Posts, $ThreadAuthorID, $OldTitle, $OldLocked, $OldSticky, $OldRanking) = $DB->next_record(MYSQLI_BOTH, false);
if ($MinClassWrite > $LoggedUser['Class']) {
error(403);
}
// If we're moving
$Cache->delete_value("forums_$ForumID");
$Cache->delete_value("forums_$OldForumID");
// If we're deleting a thread
if (isset($_POST['delete'])) {
if (check_perms('site_admin_forums')) {
$DB->query("
DELETE FROM forums_posts
WHERE TopicID = '$TopicID'");
$DB->query("
DELETE FROM forums_topics
WHERE ID = '$TopicID'");
$DB->query("
SELECT
t.ID,
t.LastPostID,
t.Title,
p.AuthorID,
um.Username,
p.AddedTime,
(
SELECT COUNT(pp.ID)
FROM forums_posts AS pp
JOIN forums_topics AS tt ON pp.TopicID = tt.ID
WHERE tt.ForumID = '$ForumID'
),
t.IsLocked,
t.IsSticky
FROM forums_topics AS t
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'
GROUP BY t.ID
ORDER BY t.LastPostID DESC
LIMIT 1");
list($NewLastTopic, $NewLastPostID, $NewLastTitle, $NewLastAuthorID, $NewLastAuthorName, $NewLastAddedTime, $NumPosts, $NewLocked, $NewSticky) = $DB->next_record(MYSQLI_NUM, false);
$DB->query("
UPDATE forums
SET
NumTopics = NumTopics - 1,
NumPosts = NumPosts - '$Posts',
LastPostTopicID = '$NewLastTopic',
LastPostID = '$NewLastPostID',
LastPostAuthorID = '$NewLastAuthorID',
LastPostTime = '$NewLastAddedTime'
WHERE ID='$ForumID'");
$Cache->delete_value("thread_$TopicID");
$Cache->begin_transaction('forums_list');
$UpdateArray = array(
'NumPosts' => $NumPosts,
'NumTopics' => '-1',
'LastPostID' => $NewLastPostID,
'LastPostAuthorID' => $NewLastAuthorID,
'LastPostTopicID' => $NewLastTopic,
'LastPostTime' => $NewLastAddedTime,
'Title' => $NewLastTitle,
'IsLocked' => $NewLocked,
'IsSticky' => $NewSticky
);
$Cache->update_row($ForumID, $UpdateArray);
$Cache->commit_transaction(0);
$Cache->delete_value("thread_{$TopicID}_info");
// 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."'");
header('Location: forums.php?action=viewforum&forumid='.$ForumID);
} else {
if (!check_perms('site_admin_forums')) {
error(403);
}
$DB->query("
DELETE FROM forums_posts
WHERE TopicID = '$TopicID'");
$DB->query("
DELETE FROM forums_topics
WHERE ID = '$TopicID'");
$DB->query("
SELECT
t.ID,
t.LastPostID,
t.Title,
p.AuthorID,
um.Username,
p.AddedTime,
(
SELECT COUNT(pp.ID)
FROM forums_posts AS pp
JOIN forums_topics AS tt ON pp.TopicID = tt.ID
WHERE tt.ForumID = '$ForumID'
),
t.IsLocked,
t.IsSticky
FROM forums_topics AS t
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'
GROUP BY t.ID
ORDER BY t.LastPostID DESC
LIMIT 1");
list($NewLastTopic, $NewLastPostID, $NewLastTitle, $NewLastAuthorID, $NewLastAuthorName, $NewLastAddedTime, $NumPosts, $NewLocked, $NewSticky) = $DB->next_record(MYSQLI_NUM, false);
$DB->query("
UPDATE forums
SET
NumTopics = NumTopics - 1,
NumPosts = NumPosts - '$Posts',
LastPostTopicID = '$NewLastTopic',
LastPostID = '$NewLastPostID',
LastPostAuthorID = '$NewLastAuthorID',
LastPostTime = '$NewLastAddedTime'
WHERE ID='$ForumID'");
$Cache->delete_value("thread_$TopicID");
$Cache->begin_transaction('forums_list');
$UpdateArray = array(
'NumPosts' => $NumPosts,
'NumTopics' => '-1',
'LastPostID' => $NewLastPostID,
'LastPostAuthorID' => $NewLastAuthorID,
'LastPostTopicID' => $NewLastTopic,
'LastPostTime' => $NewLastAddedTime,
'Title' => $NewLastTitle,
'IsLocked' => $NewLocked,
'IsSticky' => $NewSticky
);
$Cache->update_row($ForumID, $UpdateArray);
$Cache->commit_transaction(0);
$Cache->delete_value("thread_{$TopicID}_info");
// 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."'");
header('Location: forums.php?action=viewforum&forumid='.$ForumID);
} else { // If we're just editing it
$Action = 'editing';
if (isset($_POST['trash'])) {
$ForumID = TRASH_FORUM_ID;
$Action = 'trashing';
}
$Cache->begin_transaction("thread_{$TopicID}_info");
$UpdateArray = array(
@ -173,6 +180,8 @@
if ($ForumID != $OldForumID) { // If we're moving a thread, change the forum stats
$Cache->delete_value("forums_$ForumID");
$Cache->delete_value("forums_$OldForumID");
$DB->query("
SELECT MinClassRead, MinClassWrite, Name
@ -294,7 +303,7 @@
$Cache->commit_transaction(0);
if ($ForumID == TRASH_FORUM_ID) {
$Action = "trashing";
$Action = 'trashing';
}
} else { // Editing
$DB->query("
@ -327,23 +336,48 @@
WHERE TopicID = '$TopicID'");
$Cache->delete_value("polls_$TopicID");
}
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);
}
// topic notes and notifications
$TopicNotes = [];
switch ($Action) {
case 'editing':
if ($OldTitle != $RawTitle) {
// title edited
$TopicNotes[] = "Title edited from '$OldTitle' to '$RawTitle'";
}
if ($OldLocked != $Locked) {
if (!$OldLocked) {
$TopicNotes[] = 'Locked';
} else {
$TopicNotes[] = 'Unlocked';
}
}
if ($OldSticky != $Sticky) {
if (!$OldSticky) {
$TopicNotes[] = 'Stickied';
} else {
$TopicNotes[] = 'Unstickied';
}
}
if ($OldRanking != $Ranking) {
$TopicNotes[] = "Ranking changed from $OldRanking to $Ranking";
}
if ($ForumID != $OldForumID) {
$TopicNotes[] = "Moved from [url=https://" . SSL_SITE_URL . "/forums.php?action=viewforum&forumid=$OldForumID]${OldForumName}[/url] to [url=https://" . SSL_SITE_URL . "/forums.php?action=viewforum&forumid=$ForumID]${ForumName}[/url]";
}
break;
case 'trashing':
$TopicNotes[] = 'Trashed';
$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);
}
if (count($TopicNotes) > 0) {
Forums::add_topic_note($TopicID, implode("\n", $TopicNotes));
}
header('Location: forums.php?action=viewthread&threadid='.$TopicID.'&page='.$Page);
}

View File

@ -28,11 +28,13 @@
UPDATE forums_topics
SET StickyPostID = 0
WHERE ID = $ThreadID");
Forums::add_topic_note($ThreadID, "Post $PostID unstickied");
} else {
$DB->query("
UPDATE forums_topics
SET StickyPostID = $PostID
WHERE ID = $ThreadID");
Forums::add_topic_note($ThreadID, "Post $PostID stickied");
}
$Cache->delete_value('thread_'.$ThreadID.'_info');
$ThisCatalogue = floor((POSTS_PER_PAGE * $Page - POSTS_PER_PAGE) / THREAD_CATALOGUE);

View File

@ -0,0 +1,17 @@
<?
authorize();
if (!check_perms('site_moderate_forums')) {
error(403);
}
if (!isset($_POST['topicid'], $_POST['body']) || !is_number($_POST['topicid']) || $_POST['body'] == '') {
error(404);
}
$TopicID = (int)$_POST['topicid'];
Forums::add_topic_note($TopicID, $_POST['body']);
header("Location: forums.php?action=viewthread&threadid=$TopicID#thread_notes");
die();

View File

@ -543,7 +543,31 @@
}
}
if (check_perms('site_moderate_forums')) {
G::$DB->query("SELECT ID, AuthorID, AddedTime, Body FROM forums_topic_notes WHERE TopicID = $ThreadID ORDER BY ID ASC");
$Notes = G::$DB->to_array();
?>
<br />
<h3 id="thread_notes">Thread notes</h3>
<form action="forums.php" method="post">
<input type="hidden" name="action" value="take_topic_notes" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="topicid" value="<?=$ThreadID?>" />
<table cellpadding="6" cellspacing="1" border="0" width="100%" class="layout border">
<?
foreach ($Notes as $Note) {
?>
<tr><td><?=Users::format_username($Note['AuthorID'])?> (<?=time_diff($Note['AddedTime'], 2, true, true)?>)</td><td><?=$Text->full_format($Note['Body'])?></td></tr>
<?
}
?>
<tr>
<td colspan="2" class="center">
<div class="field_div textarea_wrap"><textarea id="topic_notes" name="body" cols="90" rows="3" onkeyup="resize('threadnotes')" style=" margin: 0px; width: 735px;"></textarea></div>
<input type="submit" value="Save" />
</td>
</tr>
</table>
</form>
<br />
<h3>Edit thread</h3>
<form class="edit_form" name="forum_thread" action="forums.php" method="post">
@ -552,7 +576,6 @@
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="threadid" value="<?=$ThreadID?>" />
<input type="hidden" name="page" value="<?=$Page?>" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
</div>
<table cellpadding="6" cellspacing="1" border="0" width="100%" class="layout border">
<tr>
@ -618,6 +641,9 @@
<tr>
<td colspan="2" class="center">
<input type="submit" value="Edit thread" tabindex="2" />
<span style="float: right;">
<input type="submit" name="trash" value="Trash" tabindex="2" />
</span>
</td>
</tr>

View File

@ -0,0 +1,36 @@
<?
include(SERVER_ROOT.'/classes/text.class.php');
$Text = new TEXT(true);
$ID = (int) $_POST['id'];
if (empty($ID)) {
die();
}
$UserID = (int) $_POST['userid'];
$UserIDSQL = "";
if (!empty($UserID)) {
$UserIDSQL = " AND UserID != '$UserID' ";
}
G::$DB->query("SELECT UserID, Answer, Date FROM staff_answers WHERE QuestionID = '$ID' $UserIDSQL ORDER BY DATE DESC");
$Answers = G::$DB->to_array();
?>
<div id="responses_for_<?=$ID?>" style="margin-left: 20px;">
<? foreach($Answers as $Answer) { ?>
<div class="box box2" >
<div class="head">
<span>
Answer by <?=Users::format_username($Answer['UserID'])?> - <?=time_diff($Answer['Date'])?>
</span>
</div>
<div class="pad">
<?=$Text->full_format($Answer['Answer'])?>
</div>
</div>
<? } ?>
</div>

View File

@ -11,7 +11,10 @@
error(404);
}
$DB->query("SELECT ID, Question, UserID, Date FROM user_questions WHERE ID = '$ID'");
$DB->query("
SELECT ID, Question, UserID, Date
FROM user_questions
WHERE ID = '$ID'");
$Question = $DB->next_record();
View::show_header("Ask the Staff");
@ -24,7 +27,7 @@
<div class="linkbox">
<a class="brackets" href="questions.php">View questions</a>
<a class="brackets" href="questions.php?action=answers">View staff answers</a>
</div>
<a class="brackets" href="questions.php?action=popular_questions">Popular questions</a>
<div class="box box2">
<div class="head">
<span>
@ -37,7 +40,7 @@
</div>
</div>
<div class="center box pad">
<form method="POST">
<form method="post">
<input type="hidden" name="action" value="take_answer_question" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="id" value="<?=$ID?>" />
@ -50,4 +53,4 @@
</div>
<?
View::show_footer();
View::show_footer();

View File

@ -1,32 +1,33 @@
<?
View::show_header("Ask the Staff");
$DB->query("
SELECT
sq.UserID, um.Username, count(1) AS Answered
FROM staff_answers AS sq
LEFT JOIN users_main AS um
ON um.ID = sq.UserID
GROUP BY sq.UserID
ORDER BY um.Username ASC");
SELECT
sq.UserID, um.Username, count(1) AS Answered
FROM staff_answers AS sq
LEFT JOIN users_main AS um ON um.ID = sq.UserID
GROUP BY sq.UserID
ORDER BY um.Username ASC");
$Staff = $DB->to_array();
$DB->query("SELECT COUNT(1) FROM user_questions");
$DB->query("
SELECT COUNT(1)
FROM user_questions");
list($TotalQuestions) = $DB->next_record();
View::show_header("Ask the Staff");
?>
<div class="thin">
<h2>
Staff Answers
</h2>
<div class="header">
<h2>Staff Answers</h2>
</div>
<div class="linkbox">
<?
if (check_perms("users_mod")) { ?>
<? if (check_perms("users_mod")) { ?>
<a class="brackets" href="questions.php">View questions</a>
<? } else { ?>
<a class="brackets" href="questions.php">Ask question</a>
<? } ?>
<a class="brackets" href="questions.php?action=popular_questions">Popular questions</a>
</div>
<? foreach($Staff as $User) { ?>
<h2>
@ -37,4 +38,4 @@
</div>
<?
View::show_footer();
View::show_footer();

View File

@ -4,14 +4,14 @@
?>
<div class="thin">
<h2>
Ask Staff Anything
</h2>
<div class="header">
<h2>Ask Staff Anything</h2>
</div>
<div class="linkbox">
<a class="brackets" href="questions.php?action=answers">View staff answers</a>
</div>
<div class="center box pad">
<form method="POST">
<form method="post">
<input type="hidden" name="action" value="take_ask_question" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<textarea id="question" class="required" onkeyup="resize('question');" name="question" cols="90" rows="8"></textarea>

View File

@ -35,6 +35,15 @@
case 'view_answers':
include(SERVER_ROOT.'/sections/questions/view_answers.php');
break;
case 'popular_questions':
include(SERVER_ROOT.'/sections/questions/popular_questions.php');
break;
case 'ajax_get_answers':
include(SERVER_ROOT.'/sections/questions/ajax_get_answers.php');
break;
case 'take_ignore_question':
include(SERVER_ROOT.'/sections/questions/take_ignore_question.php');
break;
default:
error(404);
break;

View File

@ -0,0 +1,60 @@
<?
include(SERVER_ROOT.'/classes/text.class.php');
$Text = new TEXT(true);
G::$DB->query("
SELECT
q.ID, q.Question, q.UserID, q.Date AS QuestionDate,
(SELECT COUNT(1) FROM staff_answers WHERE QuestionID = q.ID) AS Responses
FROM user_questions AS q
JOIN staff_answers AS a ON q.ID = a.QuestionID
GROUP BY q.ID
ORDER BY Responses DESC");
$Questions = G::$DB->to_array();
View::show_header("Popular Questions", "questions");
?>
<div class="thin">
<div class="header">
<h2>Popular Questions</h2>
</div>
<div class="linkbox">
<? if (check_perms("users_mod")) { ?>
<a class="brackets" href="questions.php">View questions</a>
<? } else { ?>
<a class="brackets" href="questions.php">Ask question</a>
<? } ?>
<a class="brackets" href="questions.php?action=answers">View staff answers</a>
</div>
<? foreach($Questions as $Question) { ?>
<div id="question<?=$Question['ID']?>" class="box box2">
<div class="head">
<span>
<a class="post_id" href="questions.php?action=popular_questions#question<?=$Question['ID']?>">#<?=$Question['ID']?></a>
Question by <?=Users::format_username($Question['UserID'])?> - <?=time_diff($Question['QuestionDate'])?>
</span>
<span style="float: right;">
<a href="#" id="<?=$Question['ID']?>" class="view_responses brackets"><?=$Question['Responses'] == 1 ? ("View " . $Question['Responses'] . " response") : ("View " . $Question['Responses'] . " responses")?></a>
<? if (check_perms("users_mod")) { ?>
-
<form class="hidden" id="delete_<?=$Question['ID']?>" method="POST">
<input type="hidden" name="action" value="take_remove_answer" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="question_id" value="<?=$Question['ID']?>" />
</form>
<a href="#" onclick="if (confirm('Are you sure?') == true) { $('#delete_<?=$Question['ID']?>').raw().submit(); } return false;" class="brackets">Delete</a>
<? } ?>
</span>
</div>
<div class="pad">
<?=$Text->full_format($Question['Question'])?>
</div>
</div>
<? } ?>
</div>
<?
View::show_footer();

View File

@ -6,15 +6,31 @@
$Text = new TEXT(true);
$DB->query("
SELECT
uq.ID, uq.Question, uq.UserID, uq.Date
FROM user_questions AS uq
WHERE uq.ID NOT IN
(SELECT sq.QuestionID FROM staff_answers AS sq WHERE sq.UserID = '$LoggedUser[ID]')
ORDER BY uq.Date DESC");
SELECT
uq.ID,
uq.Question,
uq.UserID,
uq.Date,
(
SELECT COUNT(1)
FROM staff_answers
WHERE QuestionID = uq.ID
) AS Responses
FROM user_questions AS uq
WHERE uq.ID NOT IN
(
SELECT siq.QuestionID FROM staff_ignored_questions AS siq WHERE siq.UserID = '$LoggedUser[ID]'
)
AND uq.ID NOT IN
(
SELECT sq.QuestionID FROM staff_answers AS sq WHERE sq.UserID = '$LoggedUser[ID]'
)
ORDER BY uq.Date DESC");
$Questions = $DB->to_array();
$DB->query("SELECT COUNT(1) FROM user_questions");
$DB->query("
SELECT COUNT(1)
FROM user_questions");
list($TotalQuestions) = $DB->next_record();
View::show_header("Ask the Staff", "questions");
@ -22,14 +38,17 @@
?>
<div class="thin">
<h2>
User Questions
<span style="float: right;">
<?=$TotalQuestions?> questions asked, <?=count($Questions)?> left to answer
</span>
</h2>
<div class="header">
<h2>
User Questions
<span style="float: right;">
<?=$TotalQuestions?> questions asked, <?=count($Questions)?> left to answer
</span>
</h2>
</div>
<div class="linkbox">
<a class="brackets" href="questions.php?action=answers">View staff answers</a>
<a class="brackets" href="questions.php?action=popular_questions">Popular questions</a>
</div>
<? foreach($Questions as $Question) { ?>
<div id="question<?=$Question['ID']?>" class="box box2">
@ -39,12 +58,23 @@
<?=Users::format_username($Question['UserID'])?> - <?=time_diff($Question['Date'])?>
</span>
<span style="float: right;">
<form class="hidden" id="delete_<?=$Question['ID']?>" method="POST">
<? if ($Question['Responses'] > 0) { ?>
<a href="#" id="<?=$Question['ID']?>" class="view_responses brackets"><?=$Question['Responses'] == 1 ? ("View " . $Question['Responses'] . " response") : ("View " . $Question['Responses'] . " responses")?></a>
-
<? } ?>
<form class="hidden" id="delete_<?=$Question['ID']?>" method="post">
<input type="hidden" name="action" value="take_remove_question" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="question_id" value="<?=$Question['ID']?>" />
</form>
<a href="#" onclick="$('#delete_<?=$Question['ID']?>').raw().submit(); return false;" class="brackets">Delete</a>
<a href="#" onclick="if (confirm('Are you sure?') == true) { $('#delete_<?=$Question['ID']?>').raw().submit(); } return false;" class="brackets">Delete</a>
-
<form class="hidden" id="ignore_<?=$Question['ID']?>" method="post">
<input type="hidden" name="action" value="take_ignore_question" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="question_id" value="<?=$Question['ID']?>" />
</form>
<a href="#" onclick="if (confirm('Are you sure?') == true) { $('#ignore_<?=$Question['ID']?>').raw().submit(); } return false;" class="brackets">Ignore</a>
-
<a href="#" id="<?=$Question['ID']?>" class="answer_link brackets">Answer</a>
</span>
@ -54,13 +84,11 @@
</div>
</div>
<div id="answer<?=$Question['ID']?>" class="hidden center box pad">
<textarea id="replybox_<?=$Question['ID']?>" class="required" onkeyup="resize('replybox_<?=$Question['ID']?>');" name="answer" cols="90" rows="8"></textarea>
<div id="buttons" class="center">
<input type="submit" class="submit submit_button" id="<?=$Question['ID']?>" value="Answer" />
</div>
<? new TEXTAREA_PREVIEW("replybox_" . $Question['ID'], "replybox_" . $Question['ID'], '', 40, 8); ?>
<input type="submit" class="submit submit_button" id="<?=$Question['ID']?>" value="Answer" />
</div>
<? } ?>
</div>
<?
View::show_footer();
View::show_footer();

View File

@ -15,24 +15,25 @@
error(404);
}
$DB->query("SELECT 1 FROM staff_answers WHERE QuestionID = '$ID' AND UserID = '$LoggedUser[ID]'");
$DB->query("
SELECT 1
FROM staff_answers
WHERE QuestionID = '$ID'
AND UserID = '$LoggedUser[ID]'");
if (!$DB->has_results()) {
$DB->query("
INSERT INTO staff_answers
(QuestionID, UserID, Answer, Date)
VALUES
('$ID', '$UserID', '$Answer', '$Date')");
$DB->query("SELECT UserID FROM user_questions WHERE ID = '$ID'");
INSERT INTO staff_answers
(QuestionID, UserID, Answer, Date)
VALUES
('$ID', '$UserID', '$Answer', '$Date')");
$DB->query("
SELECT UserID
FROM user_questions
WHERE ID = '$ID'");
list($ToID) = $DB->next_record();
Misc::send_pm($ToID, 0, "Your question has been answered", "One of your questions has been answered! View the response [url=https://". SSL_SITE_URL . "/questions.php?action=view_answers&userid=$UserID#question$ID]here[/url].");
} else {
error("You have already answered this question");
}
header("Location: questions.php");

View File

@ -12,9 +12,9 @@
$Date = sqltime();
$DB->query("
INSERT INTO user_questions
(Question, UserID, Date)
VALUES
('$Question', '$UserID', '$Date')");
INSERT INTO user_questions
(Question, UserID, Date)
VALUES
('$Question', '$UserID', '$Date')");
header("Location: questions.php");
header("Location: questions.php");

View File

@ -0,0 +1,18 @@
<?
if (!check_perms("users_mod")) {
error(404);
}
$ID = $_POST['question_id'];
if (!is_number($ID)) {
error(404);
}
G::$DB->query("
INSERT INTO staff_ignored_questions
(QuestionID, UserID)
VALUES
('$ID', '$LoggedUser[ID]')");
header("Location: questions.php");

View File

@ -11,6 +11,9 @@
error(404);
}
G::$DB->query("DELETE FROM staff_answers WHERE QuestionID = '$ID' AND UserID = '$LoggedUser[ID]'");
G::$DB->query("
DELETE FROM staff_answers
WHERE QuestionID = '$ID'
AND UserID = '$LoggedUser[ID]'");
header("Location: questions.php");

View File

@ -11,6 +11,8 @@
error(404);
}
G::$DB->query("DELETE FROM user_questions WHERE ID = '$ID'");
G::$DB->query("
DELETE FROM user_questions
WHERE ID = '$ID'");
header("Location: questions.php");

View File

@ -8,58 +8,81 @@
error("No UserID");
}
$Permissions = Permissions::get_permissions_for_user($UserID);
if (!isset($Permissions['users_mod']) || !$Permissions['users_mod']) {
error(404);
}
$UserInfo = Users::user_info($UserID);
G::$DB->query("
SELECT
u.Username, q.ID, q.Question, q.UserID, q.Date AS QuestionDate, a.Answer, a.Date AS AnswerDate
FROM user_questions AS q
JOIN staff_answers AS a ON q.ID = a.QuestionID
JOIN users_main AS u ON u.ID = q.UserID
WHERE a.UserID = '$UserID'
ORDER BY q.Date DESC");
SELECT
u.Username,
q.ID,
q.Question,
q.UserID,
q.Date AS QuestionDate,
a.Answer,
a.Date AS AnswerDate,
(
SELECT COUNT(1)
FROM staff_answers
WHERE QuestionID = q.ID
AND UserID != '$UserID'
) AS Responses
FROM user_questions AS q
JOIN staff_answers AS a ON q.ID = a.QuestionID
JOIN users_main AS u ON u.ID = q.UserID
WHERE a.UserID = '$UserID'
ORDER BY AnswerDate DESC");
$Questions = G::$DB->to_array();
View::show_header($UserInfo['Username'] . "'s answers");
View::show_header($UserInfo['Username'] . "'s answers", "questions");
?>
<div class="thin">
<h2>
<?=$UserInfo['Username']?>'s Answers
</h2>
<div class="header">
<h2><?=$UserInfo['Username']?>'s Answers</h2>
</div>
<div class="linkbox">
<? if (check_perms("users_mod")) { ?>
<a class="brackets" href="questions.php">View questions</a>
<? } else { ?>
<a class="brackets" href="questions.php">Ask question</a>
<? } ?>
<? if (check_perms("users_mod")) { ?>
<a class="brackets" href="questions.php">View questions</a>
<? } else { ?>
<a class="brackets" href="questions.php">Ask question</a>
<? } ?>
<a class="brackets" href="questions.php?action=answers">View staff answers</a>
<a class="brackets" href="questions.php?action=popular_questions">Popular questions</a>
</div>
<? foreach($Questions as $Question) { ?>
<div id="question<?=$Question['ID']?>" class="forum_post box box2">
<div id="question<?=$Question['ID']?>" class="box box2">
<div class="head">
<span>
<a class="post_id" href="questions.php?action=view_answers&amp;userid=<?=$UserID?>#question<?=$Question['ID']?>">#<?=$Question['ID']?></a>
Question by <?=Users::format_username($Question['UserID'])?> - <?=time_diff($Question['QuestionDate'])?>
</span>
<? if (check_perms("users_mod")) { ?>
<span style="float: right;">
<form class="hidden" id="delete_<?=$Question['ID']?>" method="POST">
<? if ($Question['Responses'] > 0) { ?>
<a href="#" data-gazelle-userid="<?=$UserID?>" id="<?=$Question['ID']?>" class="view_responses brackets"><?=$Question['Responses'] == 1 ? ("View " . $Question['Responses'] . " other response") : ("View " . $Question['Responses'] . " other responses")?></a>
-
<? } ?>
<? if (check_perms("users_mod")) { ?>
<form class="hidden" id="delete_<?=$Question['ID']?>" method="post">
<input type="hidden" name="action" value="take_remove_answer" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<input type="hidden" name="question_id" value="<?=$Question['ID']?>" />
</form>
<a href="#" onclick="$('#delete_<?=$Question['ID']?>').raw().submit(); return false;" class="brackets">Delete</a>
</span>
<a href="#" onclick="if (confirm('Are you sure?') == true) { $('#delete_<?=$Question['ID']?>').raw().submit(); } return false;" class="brackets">Delete</a>
<? } ?>
</span>
</div>
<div class="pad">
<?=$Text->full_format("[quote=" . $Question['Username'] . "]". $Question['Question'] . "[/quote]" . "\n". $Question['Answer'])?>
<?=$Text->full_format("[quote=" . $Question['Username'] . "]". $Question['Question'] . "[/quote]\n". $Question['Answer'])?>
</div>
</div>
<? } ?>
</div>
<?
View::show_footer();
View::show_footer();

View File

@ -926,6 +926,7 @@ function next_hour() {
$Cache->commit_transaction(3600 * 24 * 30);
$Cache->expire_value("thread_$ID".'_catalogue_0', 3600 * 24 * 30);
$Cache->expire_value("thread_$ID".'_info', 3600 * 24 * 30);
Forums::add_topic_note($ID, 'Locked automatically by schedule', 0);
}
$ForumIDs = array_flip(array_flip($ForumIDs));

View File

@ -1,4 +1,5 @@
$(document).ready(function() {
var open_responses =
$(".answer_link").click(function(e) {
e.preventDefault();
id = this.id;
@ -18,7 +19,28 @@ $(document).ready(function() {
}).done(function() {
$("#question" + id).remove();
$("#answer" + id).remove();
$("#responses_for_" + id).remove();
});
});
$(".view_responses").click(function(e) {
e.preventDefault();
id = this.id;
if ($("#responses_for_" + id).length == 0) {
$.ajax({
type : "POST",
url : "questions.php?action=ajax_get_answers",
dataType : "html",
data : {
"id" : id,
"userid" : $(this).data("gazelle-userid")
}
}).done(function(response) {
$("#question" + id).after(response);
});
} else {
$("#responses_for_" + id).remove();
}
});
});