Improved conversation view (messages) some filters and fixes in functions_messages
Former-commit-id: 13597c6556939bbe772d5ed749930e30e5377c47
This commit is contained in:
parent
d2649bb51c
commit
0dbabd3ba3
|
@ -339,14 +339,16 @@ function messages_get_message_sent(int $message_id)
|
|||
/**
|
||||
* Counts private messages
|
||||
*
|
||||
* @param string $user Target user.
|
||||
* @param boolean $incl_read Whether or not to include read messages.
|
||||
* @param string $user Target user.
|
||||
* @param boolean $incl_read Whether or not to include read messages.
|
||||
* @param boolean $ignore_source Ignore source.
|
||||
*
|
||||
* @return integer The number of messages this user has
|
||||
*/
|
||||
function messages_get_count(
|
||||
string $user='',
|
||||
bool $incl_read=false
|
||||
bool $incl_read=false,
|
||||
bool $ignore_source=false
|
||||
) {
|
||||
if (empty($user)) {
|
||||
global $config;
|
||||
|
@ -361,10 +363,19 @@ function messages_get_count(
|
|||
$read = 'where t.read is null';
|
||||
}
|
||||
|
||||
if ($ignore_source === true) {
|
||||
$source_sql = '';
|
||||
} else {
|
||||
$source_sql = 'INNER JOIN tnotification_source ns
|
||||
ON tm.id_source = ns.id
|
||||
AND ns.enabled = 1';
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT count(*) FROM (
|
||||
SELECT DISTINCT tm.*, utimestamp_read > 0 as "read"
|
||||
FROM tmensajes tm
|
||||
%s
|
||||
LEFT JOIN tnotification_user nu
|
||||
ON tm.id_mensaje=nu.id_mensaje
|
||||
AND nu.id_user="%s"
|
||||
|
@ -377,6 +388,7 @@ function messages_get_count(
|
|||
AND (nu.id_user="%s" OR (up.id_usuario="%s" AND ng.id_group=0))
|
||||
) t
|
||||
%s',
|
||||
$source_sql,
|
||||
$user,
|
||||
$user,
|
||||
$user,
|
||||
|
|
|
@ -106,34 +106,69 @@ if ($read_message) {
|
|||
$dst_name = $message['id_usuario_destino'];
|
||||
}
|
||||
|
||||
$table = new stdClass();
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox filters';
|
||||
$table->data = [];
|
||||
// Parse message chain.
|
||||
?>
|
||||
|
||||
$table->data[0][0] = __('Sender');
|
||||
$table->data[0][1] = $user_name.' '.__('at').' '.ui_print_timestamp(
|
||||
$message['timestamp'],
|
||||
true,
|
||||
['prominent' => 'timestamp']
|
||||
);
|
||||
<h1>Conversation with <?php echo $user_name; ?></h1>
|
||||
<h2>Subject: <?php echo $message['subject']; ?></h2>
|
||||
|
||||
$table->data[1][0] = __('Destination');
|
||||
$table->data[1][1] = $dst_name;
|
||||
<?php
|
||||
$conversation = [];
|
||||
$target_str = $message['mensaje'];
|
||||
|
||||
while (preg_match_all(
|
||||
'/(.*)On(.*)wrote:(.*)/',
|
||||
$target_str,
|
||||
$decoded,
|
||||
PREG_PATTERN_ORDER
|
||||
) !== false && empty($target_str) !== true) {
|
||||
if (empty($decoded[2]) !== true) {
|
||||
array_push(
|
||||
$conversation,
|
||||
[
|
||||
'message' => array_pop($decoded)[0],
|
||||
'date' => array_pop($decoded)[0],
|
||||
]
|
||||
);
|
||||
} else {
|
||||
array_push(
|
||||
$conversation,
|
||||
['message' => $target_str]
|
||||
);
|
||||
}
|
||||
|
||||
$target_str = $decoded[1][0];
|
||||
}
|
||||
|
||||
ui_require_css_file('message_edit');
|
||||
foreach ($conversation as $row) {
|
||||
$date = $row['date'];
|
||||
|
||||
if ($date === null) {
|
||||
$date = date(
|
||||
$config['date_format'],
|
||||
$message['timestamp']
|
||||
).' '.$user_name;
|
||||
}
|
||||
|
||||
$order = [
|
||||
"\r\n",
|
||||
"\n",
|
||||
"\r",
|
||||
];
|
||||
$replace = '<br />';
|
||||
$parsed_message = str_replace(
|
||||
$order,
|
||||
$replace,
|
||||
io_safe_output($row['message'])
|
||||
);
|
||||
|
||||
echo '<div class="container">';
|
||||
echo ' <p>'.$parsed_message.'</p>';
|
||||
echo '<span class="time-left">'.$date.'</span>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
$table->data[2][0] = __('Subject');
|
||||
$table->data[2][1] = html_print_input_text_extended(
|
||||
'subject',
|
||||
$message['subject'],
|
||||
'text-subject',
|
||||
'',
|
||||
50,
|
||||
70,
|
||||
true,
|
||||
false,
|
||||
'',
|
||||
'readonly'
|
||||
);
|
||||
|
||||
$order = [
|
||||
"\r\n",
|
||||
|
@ -143,16 +178,6 @@ if ($read_message) {
|
|||
$replace = '<br />';
|
||||
$parsed_message = str_replace($order, $replace, $message['mensaje']);
|
||||
|
||||
$table->data[3][0] = __('Message');
|
||||
$table->data[3][1] = html_print_textarea(
|
||||
'message',
|
||||
15,
|
||||
255,
|
||||
$message['mensaje'],
|
||||
'readonly',
|
||||
true
|
||||
);
|
||||
|
||||
// Prevent RE: RE: RE:.
|
||||
if (strstr($message['subject'], 'RE:')) {
|
||||
$new_subj = $message['subject'];
|
||||
|
@ -166,8 +191,8 @@ if ($read_message) {
|
|||
$message['timestamp']
|
||||
).' '.$user_name.' '.__('wrote').":\n\n".$message['mensaje'];
|
||||
|
||||
|
||||
echo '<form id="delete_message" method="post" action="index.php?sec=message_list&sec2=operation/messages/message_list&show_sent=1&delete_message=1&id='.$message_id.'">';
|
||||
html_print_table($table);
|
||||
echo '</form>';
|
||||
|
||||
echo '<form id="reply_message" method="post" action="index.php?sec=message_list&sec2=operation/messages/message_edit&new_msg=1&reply=1">';
|
||||
|
@ -179,7 +204,7 @@ if ($read_message) {
|
|||
|
||||
echo "<div class= 'action-buttons' style=' width:".$table->width."'>";
|
||||
html_print_submit_button(
|
||||
__('Delete'),
|
||||
__('Delete conversation'),
|
||||
'delete_btn',
|
||||
false,
|
||||
'form="delete_message" class="sub delete"'
|
||||
|
|
|
@ -115,13 +115,13 @@ if ($show_sent) {
|
|||
$messages = messages_get_overview_sent('', 'DESC');
|
||||
} else {
|
||||
// Messages received.
|
||||
$num_messages = messages_get_count($config['id_user'], true);
|
||||
$num_messages = messages_get_count($config['id_user'], true, true);
|
||||
if ($num_messages > 0 && !is_ajax()) {
|
||||
$unread_messages = messages_get_count($config['id_user']);
|
||||
$unread_messages = messages_get_count($config['id_user'], false, true);
|
||||
echo '<p>'.__('You have').' <b>'.$unread_messages.'</b> '.__('unread message(s)').'.</p>';
|
||||
$messages = messages_get_overview();
|
||||
} else {
|
||||
$messages = messages_get_overview('status', 'ASC', false);
|
||||
$messages = messages_get_overview('status', 'ASC');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue