2012-01-26 08:00:25 +00:00
|
|
|
<?
|
|
|
|
if ($Message = db_string($_POST['message'])) {
|
|
|
|
if ($Subject = db_string($_POST['subject'])) {
|
|
|
|
// New staff pm conversation
|
|
|
|
$Level = db_string($_POST['level']);
|
|
|
|
$DB->query("
|
2013-02-22 08:00:24 +00:00
|
|
|
INSERT INTO staff_pm_conversations
|
2012-01-26 08:00:25 +00:00
|
|
|
(Subject, Status, Level, UserID, Date)
|
|
|
|
VALUES
|
|
|
|
('$Subject', 'Unanswered', $Level, ".$LoggedUser['ID'].", '".sqltime()."')"
|
|
|
|
);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
// New message
|
|
|
|
$ConvID = $DB->inserted_id();
|
|
|
|
$DB->query("
|
|
|
|
INSERT INTO staff_pm_messages
|
|
|
|
(UserID, SentDate, Message, ConvID)
|
|
|
|
VALUES
|
|
|
|
(".$LoggedUser['ID'].", '".sqltime()."', '$Message', $ConvID)"
|
|
|
|
);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
header('Location: staffpm.php');
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
} elseif ($ConvID = (int)$_POST['convid']) {
|
|
|
|
// Check if conversation belongs to user
|
|
|
|
$DB->query("SELECT UserID, AssignedToUser FROM staff_pm_conversations WHERE ID=$ConvID");
|
|
|
|
list($UserID, $AssignedToUser) = $DB->next_record();
|
|
|
|
|
2013-02-22 08:00:24 +00:00
|
|
|
|
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
if ($UserID == $LoggedUser['ID'] || $IsFLS || $UserID == $AssignedToUser) {
|
|
|
|
// Response to existing conversation
|
|
|
|
$DB->query("
|
|
|
|
INSERT INTO staff_pm_messages
|
|
|
|
(UserID, SentDate, Message, ConvID)
|
|
|
|
VALUES
|
|
|
|
(".$LoggedUser['ID'].", '".sqltime()."', '$Message', $ConvID)"
|
|
|
|
);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
// Update conversation
|
|
|
|
if ($IsFLS) {
|
|
|
|
// FLS/Staff
|
|
|
|
$DB->query("UPDATE staff_pm_conversations SET Date='".sqltime()."', Unread=true, Status='Open' WHERE ID=$ConvID");
|
|
|
|
$Cache->delete_value('num_staff_pms_'.$LoggedUser['ID']);
|
|
|
|
} else {
|
|
|
|
// User
|
|
|
|
$DB->query("UPDATE staff_pm_conversations SET Date='".sqltime()."', Unread=true, Status='Unanswered' WHERE ID=$ConvID");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear cache for user
|
|
|
|
$Cache->delete_value('staff_pm_new_'.$UserID);
|
|
|
|
$Cache->delete_value('staff_pm_new_'.$LoggedUser['ID']);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
header("Location: staffpm.php?action=viewconv&id=$ConvID");
|
|
|
|
} else {
|
|
|
|
// User is trying to respond to conversation that does no belong to them
|
|
|
|
error(403);
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
} else {
|
|
|
|
// Message but no subject or conversation id
|
|
|
|
header("Location: staffpm.php?action=viewconv&id=$ConvID");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
}
|
|
|
|
} elseif ($ConvID = (int)$_POST['convid']) {
|
|
|
|
// No message, but conversation id
|
|
|
|
header("Location: staffpm.php?action=viewconv&id=$ConvID");
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2012-01-26 08:00:25 +00:00
|
|
|
} else {
|
|
|
|
// No message or conversation id
|
|
|
|
header('Location: staffpm.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|