Commit 58d78167 by Scott

Refactor qa-page-message

Always show recent correspondence.
Show success and error messages at all appropriate times.
parent 426f5587
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
$handle = qa_request_part(1); $handle = qa_request_part(1);
$loginuserid = qa_get_logged_in_userid(); $loginuserid = qa_get_logged_in_userid();
$qa_content = qa_content_prepare();
// Check we have a handle, we're not using Q2A's single-sign on integration and that we're logged in // Check we have a handle, we're not using Q2A's single-sign on integration and that we're logged in
...@@ -47,13 +49,12 @@ ...@@ -47,13 +49,12 @@
qa_redirect('users'); qa_redirect('users');
if (!isset($loginuserid)) { if (!isset($loginuserid)) {
$qa_content = qa_content_prepare();
$qa_content['error'] = qa_insert_login_links(qa_lang_html('misc/message_must_login'), qa_request()); $qa_content['error'] = qa_insert_login_links(qa_lang_html('misc/message_must_login'), qa_request());
return $qa_content; return $qa_content;
} }
// Find the user profile and questions and answers for this handle // Find the user profile and their recent private messages
list($toaccount, $torecent, $fromrecent) = qa_db_select_with_pending( list($toaccount, $torecent, $fromrecent) = qa_db_select_with_pending(
qa_db_user_account_selectspec($handle, false), qa_db_user_account_selectspec($handle, false),
...@@ -68,37 +69,35 @@ ...@@ -68,37 +69,35 @@
return include QA_INCLUDE_DIR.'qa-page-not-found.php'; return include QA_INCLUDE_DIR.'qa-page-not-found.php';
// Check that we have permission and haven't reached the limit // Check that we have permission and haven't reached the limit, but don't quit just yet
$errorhtml = null;
switch (qa_user_permit_error(null, QA_LIMIT_MESSAGES)) { switch (qa_user_permit_error(null, QA_LIMIT_MESSAGES)) {
case 'limit': case 'limit':
$errorhtml = qa_lang_html('misc/message_limit'); $pageerror = qa_lang_html('misc/message_limit');
break; break;
case false: case false:
break; break;
default: default:
$errorhtml = qa_lang_html('users/no_permission'); $pageerror = qa_lang_html('users/no_permission');
break; break;
} }
if (isset($errorhtml)) {
$qa_content = qa_content_prepare();
$qa_content['error'] = $errorhtml;
return $qa_content;
}
// Process sending a message to user // Process sending a message to user
$messagesent = (qa_get_state() == 'message-sent'); $messagesent = qa_get_state() == 'message-sent';
if (qa_post_text('domessage')) { if (qa_post_text('domessage')) {
$inmessage = qa_post_text('message'); $inmessage = qa_post_text('message');
if (isset($pageerror)) {
// not permitted to post, so quit here
$qa_content['error'] = $pageerror;
return $qa_content;
}
if ( !qa_check_form_security_code('message-'.$handle, qa_post_text('code')) ) if ( !qa_check_form_security_code('message-'.$handle, qa_post_text('code')) )
$pageerror = qa_lang_html('misc/form_security_again'); $pageerror = qa_lang_html('misc/form_security_again');
...@@ -153,7 +152,7 @@ ...@@ -153,7 +152,7 @@
// Prepare content for theme // Prepare content for theme
$qa_content = qa_content_prepare(); $hideForm = !empty($pageerror) || $messagesent;
$qa_content['title'] = qa_lang_html('misc/private_message_title'); $qa_content['title'] = qa_lang_html('misc/private_message_title');
...@@ -164,9 +163,11 @@ ...@@ -164,9 +163,11 @@
'style' => 'tall', 'style' => 'tall',
'ok' => $messagesent ? qa_lang_html('misc/message_sent') : null,
'fields' => array( 'fields' => array(
'message' => array( 'message' => array(
'type' => $messagesent ? 'static' : '', 'type' => $hideForm ? 'static' : '',
'label' => qa_lang_html_sub('misc/message_for_x', qa_get_one_user_html($handle, false)), 'label' => qa_lang_html_sub('misc/message_for_x', qa_get_one_user_html($handle, false)),
'tags' => 'name="message" id="message"', 'tags' => 'name="message" id="message"',
'value' => qa_html(@$inmessage, $messagesent), 'value' => qa_html(@$inmessage, $messagesent),
...@@ -191,8 +192,7 @@ ...@@ -191,8 +192,7 @@
$qa_content['focusid'] = 'message'; $qa_content['focusid'] = 'message';
if ($messagesent) { if ($hideForm) {
$qa_content['form_message']['ok'] = qa_lang_html('misc/message_sent');
unset($qa_content['form_message']['buttons']); unset($qa_content['form_message']['buttons']);
if (qa_opt('show_message_history')) if (qa_opt('show_message_history'))
...@@ -228,7 +228,6 @@ ...@@ -228,7 +228,6 @@
$qa_content['raw']['account'] = $toaccount; // for plugin layers to access $qa_content['raw']['account'] = $toaccount; // for plugin layers to access
return $qa_content; return $qa_content;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment