Gazelle/sections/staffpm/viewconv.php

239 lines
7.7 KiB
PHP
Raw Normal View History

<?
include(SERVER_ROOT.'/classes/class_text.php');
$Text = new TEXT;
if ($ConvID = (int)$_GET['id']) {
// Get conversation info
$DB->query("SELECT Subject, UserID, Level, AssignedToUser, Unread, Status FROM staff_pm_conversations WHERE ID=$ConvID");
list($Subject, $UserID, $Level, $AssignedToUser, $Unread, $Status) = $DB->next_record();
2012-01-26 08:00:25 +00:00
$DB->query("SELECT Subject, UserID, Level, AssignedToUser, Unread, Status FROM staff_pm_conversations WHERE ID=$ConvID");
list($Subject, $UserID, $Level, $AssignedToUser, $Unread, $Status) = $DB->next_record();
2012-03-28 08:00:20 +00:00
if (!(($UserID == $LoggedUser['ID']) || ($AssignedToUser == $LoggedUser['ID']) || (($Level > 0 && $Level <= $LoggedUser['EffectiveClass']) || ($Level == 0 && $IsFLS)))) {
2011-11-18 08:00:16 +00:00
// User is trying to view someone else's conversation
error(403);
}
// User is trying to view their own unread conversation, set it to read
if ($UserID == $LoggedUser['ID'] && $Unread) {
$DB->query("UPDATE staff_pm_conversations SET Unread=false WHERE ID=$ConvID");
// Clear cache for user
$Cache->delete_value('staff_pm_new_'.$LoggedUser['ID']);
}
2013-02-13 08:00:35 +00:00
View::show_header('Staff PM', 'staffpm,bbcode,jquery');
2012-10-11 08:00:15 +00:00
$UserInfo = Users::user_info($UserID);
$UserStr = Users::format_username($UserID, true, true, true, true);
2013-04-17 08:00:58 +00:00
$OwnerID = $UserID;
2012-03-04 08:00:21 +00:00
$OwnerName = $UserInfo['Username'];
?>
<div id="thin">
2012-08-19 08:00:19 +00:00
<div class="header">
<h2>Staff PM - <?=display_str($Subject)?></h2>
<div class="linkbox">
<?
2011-11-18 08:00:16 +00:00
// Staff only
if ($IsStaff) {
?>
2013-02-09 08:01:01 +00:00
<a href="staffpm.php" class="brackets">My unanswered</a>
<?
2011-11-18 08:00:16 +00:00
}
2011-11-18 08:00:16 +00:00
// FLS/Staff
if ($IsFLS) {
?>
2013-02-09 08:01:01 +00:00
<a href="staffpm.php?view=unanswered" class="brackets">All unanswered</a>
<a href="staffpm.php?view=open" class="brackets">Open</a>
<a href="staffpm.php?view=resolved" class="brackets">Resolved</a>
<?
// User
2011-11-18 08:00:16 +00:00
} else {
?>
2013-02-09 08:01:01 +00:00
<a href="staffpm.php" class="brackets">Back to inbox</a>
<?
2011-11-18 08:00:16 +00:00
}
2012-08-19 08:00:19 +00:00
?> </div>
</div>
2012-08-19 08:00:19 +00:00
<br />
<br />
<div id="inbox">
<?
2011-11-18 08:00:16 +00:00
// Get messages
2013-05-22 08:01:02 +00:00
$StaffPMs = $DB->query("
SELECT UserID, SentDate, Message, ID
FROM staff_pm_messages
WHERE ConvID=$ConvID");
2011-11-18 08:00:16 +00:00
2013-04-17 08:00:58 +00:00
while (list($UserID, $SentDate, $Message, $MessageID) = $DB->next_record()) {
2011-11-18 08:00:16 +00:00
// Set user string
if ($UserID == $OwnerID) {
// User, use prepared string
$UserString = $UserStr;
2013-04-17 08:00:58 +00:00
$Username = $OwnerName;
2011-11-18 08:00:16 +00:00
} else {
// Staff/FLS
2012-10-11 08:00:15 +00:00
$UserInfo = Users::user_info($UserID);
$UserString = Users::format_username($UserID, true, true, true, true);
2012-03-04 08:00:21 +00:00
$Username = $UserInfo['Username'];
2011-11-18 08:00:16 +00:00
}
?>
2013-05-22 08:01:02 +00:00
<div class="box vertical_space" id="post<?=$MessageID?>">
<div class="head">
2013-05-22 08:01:02 +00:00
<? // TODO: the inline style in the <a> tag is an ugly hack. get rid of it. ?>
<a class="postid" href="staffpm.php?action=viewconv&amp;id=<?=$ConvID?>#post<?=$MessageID?>" style="font-weight: normal;">#<?=$MessageID?></a>
<strong>
<?=$UserString?>
</strong>
<?=time_diff($SentDate, 2, true)?>
2012-03-04 08:00:21 +00:00
<? if ($Status != 'Resolved') { ?>
2013-02-09 08:01:01 +00:00
- <a href="#quickpost" onclick="Quote('<?=$MessageID?>','<?=$Username?>');" class="brackets">Quote</a>
2012-03-04 08:00:21 +00:00
<? } ?>
</div>
<div class="body"><?=$Text->full_format($Message)?></div>
</div>
2013-05-22 08:01:02 +00:00
<div align="center" style="display: none;"></div>
<?
2011-11-18 08:00:16 +00:00
$DB->set_query_id($StaffPMs);
}
2011-11-18 08:00:16 +00:00
// Common responses
if ($IsFLS && $Status != 'Resolved') {
?>
<div id="common_answers" class="hidden">
<div class="box vertical_space">
<div class="head">
<strong>Preview</strong>
</div>
2013-02-09 08:01:01 +00:00
<div id="common_answers_body" class="body">Select an answer from the drop-down to view it.</div>
</div>
<br />
<div class="center">
2012-09-20 08:00:49 +00:00
<select id="common_answers_select" onchange="UpdateMessage();">
<option id="first_common_response">Select a message</option>
<?
2011-11-18 08:00:16 +00:00
// List common responses
$DB->query("SELECT ID, Name FROM staff_pm_responses");
2013-04-17 08:00:58 +00:00
while (list($ID, $Name) = $DB->next_record()) {
?>
<option value="<?=$ID?>"><?=$Name?></option>
2011-11-18 08:00:16 +00:00
<? } ?>
</select>
2012-09-09 08:00:26 +00:00
<input type="button" value="Set message" onclick="SetMessage();" />
<input type="button" value="Create new / Edit" onclick="location.href='staffpm.php?action=responses&amp;convid=<?=$ConvID?>'" />
</div>
</div>
2011-11-18 08:00:16 +00:00
<? }
2011-11-18 08:00:16 +00:00
// Ajax assign response div
if ($IsStaff) { ?>
<div id="ajax_message" class="hidden center alertbar"></div>
2011-11-18 08:00:16 +00:00
<? }
2013-05-22 08:01:02 +00:00
// Reply box and buttons
?>
<h3>Reply</h3>
<div class="box pad">
<div id="buttons" class="center">
2012-09-15 08:00:25 +00:00
<form class="manage_form" name="staff_messages" action="staffpm.php" method="post" id="messageform">
<input type="hidden" name="action" value="takepost" />
<input type="hidden" name="convid" value="<?=$ConvID?>" id="convid" />
2013-02-13 08:00:35 +00:00
<?
$TextPrev = new TEXTAREA_PREVIEW('message', 'quickpost', '', 90, 10, true, false);
?>
<br />
<?
2011-11-18 08:00:16 +00:00
// Assign to
if ($IsStaff) {
// Staff assign dropdown
?>
<select id="assign_to" name="assign">
<optgroup label="User classes">
2011-11-18 08:00:16 +00:00
<? // FLS "class"
2013-05-22 08:01:02 +00:00
$Selected = ((!$AssignedToUser && $Level == 0) ? ' selected="selected"' : '');
?>
<option value="class_0"<?=$Selected?>>First Line Support</option>
2011-11-18 08:00:16 +00:00
<? // Staff classes
foreach ($ClassLevels as $Class) {
// Create one <option> for each staff user class
if ($Class['Level'] >= 650) {
2013-05-22 08:01:02 +00:00
$Selected = ((!$AssignedToUser && ($Level == $Class['Level'])) ? ' selected="selected"' : '');
?>
<option value="class_<?=$Class['Level']?>"<?=$Selected?>><?=$Class['Name']?></option>
2011-11-18 08:00:16 +00:00
<? }
} ?>
</optgroup>
<optgroup label="Staff">
2011-11-18 08:00:16 +00:00
<? // Staff members
$DB->query("
SELECT
m.ID,
m.Username
FROM permissions as p
2013-04-17 08:00:58 +00:00
JOIN users_main as m ON m.PermissionID=p.ID
2011-11-18 08:00:16 +00:00
WHERE p.DisplayStaff='1'
ORDER BY p.Level DESC, m.Username ASC"
);
2013-04-17 08:00:58 +00:00
while (list($ID, $Name) = $DB->next_record()) {
2011-11-18 08:00:16 +00:00
// Create one <option> for each staff member
2013-05-22 08:01:02 +00:00
$Selected = (($AssignedToUser == $ID) ? ' selected="selected"' : '');
?>
<option value="user_<?=$ID?>"<?=$Selected?>><?=$Name?></option>
2011-11-18 08:00:16 +00:00
<? } ?>
</optgroup>
<optgroup label="First Line Support">
<?
2011-11-18 08:00:16 +00:00
// FLS users
$DB->query("
SELECT
m.ID,
m.Username
FROM users_info as i
2013-04-17 08:00:58 +00:00
JOIN users_main as m ON m.ID=i.UserID
JOIN permissions as p ON p.ID=m.PermissionID
2011-11-18 08:00:16 +00:00
WHERE p.DisplayStaff!='1' AND i.SupportFor!=''
ORDER BY m.Username ASC
");
2013-04-17 08:00:58 +00:00
while (list($ID, $Name) = $DB->next_record()) {
2011-11-18 08:00:16 +00:00
// Create one <option> for each FLS user
2013-05-22 08:01:02 +00:00
$Selected = (($AssignedToUser == $ID) ? ' selected="selected"' : '');
?>
<option value="user_<?=$ID?>"<?=$Selected?>><?=$Name?></option>
2011-11-18 08:00:16 +00:00
<? } ?>
</optgroup>
</select>
2012-09-09 08:00:26 +00:00
<input type="button" onclick="Assign();" value="Assign" />
2011-11-18 08:00:16 +00:00
<? } elseif ($IsFLS) { // FLS assign button ?>
2012-09-09 08:00:26 +00:00
<input type="button" value="Assign to staff" onclick="location.href='staffpm.php?action=assign&amp;to=staff&amp;convid=<?=$ConvID?>';" />
<input type="button" value="Assign to forum staff" onclick="location.href='staffpm.php?action=assign&amp;to=forum&amp;convid=<?=$ConvID?>';" />
2011-11-18 08:00:16 +00:00
<? }
2011-12-06 08:00:14 +00:00
if ($Status != 'Resolved') { ?>
2012-09-09 08:00:26 +00:00
<input type="button" value="Resolve" onclick="location.href='staffpm.php?action=resolve&amp;id=<?=$ConvID?>';" />
2013-04-17 08:00:58 +00:00
<? if ($IsFLS) { //Moved by request ?>
2012-09-09 08:00:26 +00:00
<input type="button" value="Common answers" onclick="$('#common_answers').toggle();" />
2011-11-18 08:00:16 +00:00
<? } ?>
2013-02-13 08:00:35 +00:00
<input type="button" id="previewbtn" value="Preview" class="hidden button_preview_<?=$TextPrev->getID()?>" title="Preview text" />
<input type="submit" value="Send message" />
2011-11-18 08:00:16 +00:00
<? } else { ?>
2012-09-09 08:00:26 +00:00
<input type="button" value="Unresolve" onclick="location.href='staffpm.php?action=unresolve&amp;id=<?=$ConvID?>';" />
2013-02-22 08:00:24 +00:00
<? }
2012-01-26 08:00:25 +00:00
if (check_perms('users_give_donor')) { ?>
2013-02-22 08:00:24 +00:00
<br />
2012-09-09 08:00:26 +00:00
<input type="button" value="Make Donor" onclick="location.href='staffpm.php?action=make_donor&amp;id=<?=$ConvID?>';" />
2011-11-18 08:00:16 +00:00
<? } ?>
</form>
</div>
</div>
</div>
</div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();
} else {
2013-04-17 08:00:58 +00:00
// No ID
header('Location: staffpm.php');
}