improvement and restoration of the message view - refs #2681

pull/2877/head
Alex Aragón 6 years ago
parent e5cf341244
commit 5a7045a05c
  1. 87
      assets/css/scss/_inbox.scss
  2. 2
      assets/css/scss/index.scss
  3. 153
      main/inc/lib/message.lib.php
  4. 56
      main/messages/view_message.php
  5. 62
      main/template/default/message/view_message.html.twig

@ -0,0 +1,87 @@
.email-head {
background-color: #fff;
.email-head-subject {
padding: 25px 25px;
border-bottom: 1px solid #e6e6f2;
.icons{
font-size: 14px;
float: right;
.icon{
color: #71738d;
vertical-align: middle;
}
}
.title {
display: block;
font-size: 1.769rem;
font-weight: 500;
color: #3d405c;
a{
.icon{
color: silver;
font-size: 14px;
margin-right: 6px;
vertical-align: middle;
line-height: 31px;
position: relative;
top: -1px;
}
&.active{
.icon{
color: #ffc600;
}
}
}
}
}
.email-head-sender {
padding: 13px 25px;
line-height: 40px;
.date {
float: right;
font-size: 12px;
}
.avatar{
float: left;
margin-right: 10px;
width: 2.25rem;
height: 2.25rem;
border-radius: 50%;
border: 2px solid #e6e6f2;
background: #F7F9FA;
color: #fff;
}
.sender{
font-size: 1.15rem;
.email{
font-size: 12px;
}
}
}
}
.email-body{
background-color: #fff;
border-top: 1px solid #e6e6f2;
padding: 30px 28px;
}
.email-attachments{
background-color: #fff;
padding: 25px 28px;
border-top: 1px solid #e6e6f2;
.title{
display: block;
font-weight: 500;
}
ul{
list-style: none;
margin: 15px 0 0;
padding: 0;
li{
line-height: 23px;
a{
color: #404040;
font-weight: 500;
}
}
}
}

@ -1,6 +1,6 @@
@import 'variables'; @import 'variables';
@import "media"; @import "media";
//@import 'loader'; @import 'inbox';
@import 'sidebar'; @import 'sidebar';
@import 'login'; @import 'login';
@import 'install'; @import 'install';

@ -1278,13 +1278,14 @@ class MessageManager
* *
* @todo replace numbers with letters in the $row array pff... * @todo replace numbers with letters in the $row array pff...
* *
* @return string html with the message content * @return array the message content
*/ */
public static function showMessageBox($messageId, $source = 'inbox') public static function showMessageBox($messageId, $source = 'inbox')
{ {
$table = Database::get_main_table(TABLE_MESSAGE); $table = Database::get_main_table(TABLE_MESSAGE);
$messageId = (int) $messageId; $messageId = (int) $messageId;
$currentUserId = api_get_user_id(); $currentUserId = api_get_user_id();
$msg = [];
if ($source == 'outbox') { if ($source == 'outbox') {
if (isset($messageId) && is_numeric($messageId)) { if (isset($messageId) && is_numeric($messageId)) {
@ -1315,119 +1316,65 @@ class MessageManager
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
if (empty($row)) { if (empty($row)) {
return ''; return $msg;
} }
$user_sender_id = $row['user_sender_id']; $user_sender_id = $row['user_sender_id'];
$msg['id'] = $row['id'];
$msg['status'] = $row['msg_status'];
$msg['user_id'] = $user_sender_id;
// get file attachments by message id // get file attachments by message id
$files_attachments = self::getAttachmentLinkList( $files_attachments = self::getAttachmentLinkList(
$messageId, $messageId,
$source $source
); );
$msg['title'] = Security::remove_XSS($row['title'], STUDENT, true);
$msg['attachments'] = $files_attachments;
$row['content'] = str_replace('</br>', '<br />', $row['content']); $contentMsg = str_replace('</br>', '<br />', $row['content']);
$title = Security::remove_XSS($row['title'], STUDENT, true); $content = Security::remove_XSS($contentMsg, STUDENT, true);
$content = Security::remove_XSS($row['content'], STUDENT, true); $msg['content'] = $content;
$name = get_lang('UnknownUser');
$fromUser = api_get_user_info($user_sender_id); $fromUser = api_get_user_info($user_sender_id);
$userImage = '';
if (!empty($user_sender_id) && !empty($fromUser)) { if (!empty($user_sender_id) && !empty($fromUser)) {
$name = $fromUser['complete_name_with_username']; $msg['form_user'] = [
$userImage = Display::img( 'id' => $fromUser['id'],
$fromUser['avatar_small'], 'name' => $fromUser['complete_name'],
$name, 'username' => $fromUser['username'],
['title' => $name, 'class' => 'rounded-circle mr-2'], 'avatar' => $fromUser['avatar_small'],
false 'email' => $fromUser['email'],
); ];
} }
$msg['date'] = Display::dateToStringAgoAndLongDate($row['send_date']);
$message_content = Display::page_subheader(str_replace("\\", "", $title));
$receiverUserInfo = [];
if (!empty($row['user_receiver_id'])) { if (!empty($row['user_receiver_id'])) {
$receiverUserInfo = api_get_user_info($row['user_receiver_id']); $receiverUserInfo = api_get_user_info($row['user_receiver_id']);
$msg['receiver_user'] = [
'id' => $receiverUserInfo['id'],
'name' => $receiverUserInfo['complete_name'],
'username' => $receiverUserInfo['username'],
'avatar' => $receiverUserInfo['avatar'],
'email' => $receiverUserInfo['email']
];
} }
$message_content .= '<tr>'; $urlMessage = [];
if (api_get_setting('allow_social_tool') == 'true') {
$message_content .= '<div class="row">';
if ($source == 'outbox') {
$message_content .= '<div class="col-md-12">';
$message_content .= '<ul class="list-message">';
$message_content .= '<li>'.$userImage.'</li>';
$message_content .= '<li>'.$name.'&nbsp;';
if (!empty($receiverUserInfo)) {
$message_content .= api_strtolower(
get_lang('To')
).'&nbsp;<b>'.$receiverUserInfo['complete_name_with_username'].'</b></li>';
} else {
$message_content .= api_strtolower(get_lang('To')).'&nbsp;<b>-</b></li>';
}
$message_content .= '<li>'.Display::dateToStringAgoAndLongDate($row['send_date']).'</li>';
$message_content .= '</ul>';
$message_content .= '</div>';
} else {
$message_content .= '<div class="col-md-12">';
$message_content .= '<ul class="list-message">';
if (!empty($user_sender_id)) {
$message_content .= '<li>'.$userImage.'</li>';
$message_content .= '<li><a href="'.api_get_path(
WEB_PATH
).'main/social/profile.php?u='.$user_sender_id.'">'.$name.'</a>';
} else {
$message_content .= '<li>'.$name;
}
$message_content .= '&nbsp;'.api_strtolower(get_lang('To')).'&nbsp;'.get_lang('Me');
$message_content .= '<li>'.Display::dateToStringAgoAndLongDate($row['send_date']).'</li>';
$message_content .= '</ul>';
$message_content .= '</div>';
}
$message_content .= '</div>';
} else {
if ($source == 'outbox') {
$message_content .= get_lang('From').':&nbsp;'.$name.'</b> '.api_strtolower(get_lang('To')).' <b>'.
$receiverUserInfo['complete_name_with_username'].'</b>';
} else {
$message_content .= get_lang('From').':&nbsp;'.$name.'</b> '.api_strtolower(get_lang('To')).' <b>'.
get_lang('Me').'</b>';
}
}
$message_content .= '
<hr style="color:#ddd" />
<table width="100%">
<tr>
<td valign=top class="view-message-content">'.str_replace("\\", "", $content).'</td>
</tr>
</table>
<div id="message-attach">'.(!empty($files_attachments) ? implode('<br />', $files_attachments) : '').'</div>
<div style="padding: 15px 0px 5px 0px">';
$social_link = ''; $social_link = '';
if (isset($_GET['f']) && $_GET['f'] == 'social') { if (isset($_GET['f']) && $_GET['f'] == 'social') {
$social_link = 'f=social'; $social_link = 'f=social';
} }
if ($source == 'outbox') { if ($source == 'outbox') {
$message_content .= '<a href="outbox.php?'.$social_link.'">'. $urlMessage['return'] = 'outbox.php?'.$social_link;
Display::return_icon('back.png', get_lang('ReturnToOutbox')).'</a> &nbsp';
} else { } else {
$message_content .= '<a href="inbox.php?'.$social_link.'">'. $urlMessage['back'] = 'inbox.php?'.$social_link;
Display::return_icon('back.png', get_lang('ReturnToInbox')).'</a> &nbsp'; $urlMessage['new_message'] = 'new_message.php?re_id='.$messageId.'&'.$social_link;
$message_content .= '<a href="new_message.php?re_id='.$messageId.'&'.$social_link.'">'.
Display::return_icon('message_reply.png', get_lang('ReplyToMessage')).'</a> &nbsp';
} }
$message_content .= '<a href="inbox.php?action=deleteone&id='.$messageId.'&'.$social_link.'" >'. $urlMessage['delete'] = 'inbox.php?action=deleteone&id='.$messageId.'&'.$social_link;
Display::return_icon('delete.png', get_lang('DeleteMessage')).'</a>&nbsp';
$message_content .= '</div></td> $msg['url'] = $urlMessage;
<td width=10></td>
</tr>
</table>';
return $message_content; return $msg;
} }
/** /**
@ -2005,28 +1952,44 @@ class MessageManager
$files = self::getAttachmentList($messageId); $files = self::getAttachmentList($messageId);
// get file attachments by message id // get file attachments by message id
$list = []; $list = [];
$totalSize = 0;
if ($files) { if ($files) {
$attachIcon = Display::return_icon('attachment.gif', '');
$archiveURL = api_get_path(WEB_CODE_PATH).'messages/download.php?type='.$type.'&file='; $archiveURL = api_get_path(WEB_CODE_PATH).'messages/download.php?type='.$type.'&file=';
$countFiles = count($files);
foreach ($files as $row_file) { foreach ($files as $row_file) {
$archiveFile = $row_file['path']; $archiveFile = $row_file['path'];
$filename = $row_file['filename']; $filename = $row_file['filename'];
$totalSize += $row_file['size'];
$size = format_file_size($row_file['size']); $size = format_file_size($row_file['size']);
$comment = Security::remove_XSS($row_file['comment']); $comment = Security::remove_XSS($row_file['comment']);
$filename = Security::remove_XSS($filename); $filename = Security::remove_XSS($filename);
$link = Display::url($filename, $archiveURL.$archiveFile); $type = 'file';
$comment = !empty($comment) ? '&nbsp;-&nbsp;<i>'.$comment.'</i>' : '';
$attachmentLine = $attachIcon.'&nbsp;'.$link.'&nbsp;('.$size.')'.$comment;
if ($row_file['comment'] == 'audio_message') { if ($row_file['comment'] == 'audio_message') {
$attachmentLine = '<audio src="'.$archiveURL.$archiveFile.'"/>'; $type= 'audio';
} }
$list[] = $attachmentLine; $listTemp = [
'filename' => $filename,
'size' => $size,
'comment' => $comment,
'url' => $archiveURL.$archiveFile,
'type' => $type
];
$list[] = $listTemp;
} }
return [
'quantity' => $countFiles,
'total_size' => format_file_size($totalSize),
'files' => $list
];
} else {
return [];
} }
return $list;
} }
/** /**

@ -24,16 +24,37 @@ if ($allowSocial) {
} }
$interbreadcrumb[] = ['url' => 'inbox.php', 'name' => get_lang('Messages')]; $interbreadcrumb[] = ['url' => 'inbox.php', 'name' => get_lang('Messages')];
$social_right_content = '<div class="actions">';
if (api_get_setting('allow_message_tool') === 'true') { if (api_get_setting('allow_message_tool') === 'true') {
$social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'.
Display::return_icon('new-message.png', get_lang('ComposeMessage')).'</a>'; $actionLeft = Display::url(
$social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'. Display::return_icon(
Display::return_icon('inbox.png', get_lang('Inbox')).'</a>'; 'new-message.png',
$social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'. get_lang('ComposeMessage')
Display::return_icon('outbox.png', get_lang('Outbox')).'</a>'; ),
api_get_path(WEB_PATH).'main/messages/new_message.php'
);
$actionLeft.=Display::url(
Display::return_icon(
'inbox.png',
get_lang('Inbox')
),
api_get_path(WEB_PATH).'main/messages/inbox.php'
);
$actionLeft.=Display::url(
Display::return_icon(
'outbox.png',
get_lang('Outbox')
),
api_get_path(WEB_PATH).'main/messages/outbox.php'
);
$toolbar = Display::toolbarAction('inbox',[ 0 => $actionLeft ]);
} }
$social_right_content .= '</div>';
if (empty($_GET['id'])) { if (empty($_GET['id'])) {
$messageId = $_GET['id_send']; $messageId = $_GET['id_send'];
@ -56,31 +77,28 @@ $logInfo = [
]; ];
Event::registerLog($logInfo); Event::registerLog($logInfo);
// LEFT COLUMN
if (api_get_setting('allow_social_tool') === 'true') {
// Block Social Menu
$social_menu_block = SocialManager::show_social_menu($show_menu);
}
// MAIN CONTENT // MAIN CONTENT
$message .= MessageManager::showMessageBox($messageId, $source); $message = MessageManager::showMessageBox($messageId, $source);
$messageContent = '';
if (!empty($message)) { if (!empty($message)) {
$social_right_content .= $message; $messageContent = $message;
} else { } else {
api_not_allowed(true); api_not_allowed(true);
} }
$tpl = new Template(get_lang('View')); $tpl = new Template(get_lang('View'));
// Block Social Avatar // Block Social Avatar
SocialManager::setSocialUserBlock($tpl, api_get_user_id(), $show_menu); SocialManager::setSocialUserBlock($tpl, api_get_user_id(), $show_menu);
if (api_get_setting('allow_social_tool') === 'true') { if (api_get_setting('allow_social_tool') === 'true') {
$tpl->assign('social_menu_block', $social_menu_block); $tpl->assign('actions',$toolbar);
$tpl->assign('social_right_content', $social_right_content); $tpl->assign('message', $messageContent);
$social_layout = $tpl->get_template('social/inbox.tpl'); $social_layout = $tpl->get_template('message/view_message.html.twig');
$tpl->display($social_layout); $tpl->display($social_layout);
} else { } else {
$content = $social_right_content; $content = $social_right_content;
$tpl->assign('content', $content); $tpl->assign('content', $content);
$tpl->display_one_col_template(); $tpl->display_one_col_template();
} }

@ -0,0 +1,62 @@
{% extends '@ChamiloTheme/Layout/layout_one_col.html.twig' %}
{% block content %}
{% autoescape false %}
<div id="message_{{ message.id }}" data-status="{{ message.status }}" class="mail-email">
<div class="email-head">
<div class="email-head-subject">
<div class="title">
<a class="active" href="#">
<span class="icon">
<i class="fas fa-star"></i>
</span>
</a>
<span>
{{ message.title }}
</span>
<div class="icons">
<div class="btn-group" role="group" >
<a href="{{ message.url.back }}" class="btn btn-outline-secondary icon"><i class="fas fa-arrow-circle-left"></i> {{ 'Back'|trans }}</a>
<a href="#" onclick="window.print();" class="btn btn-outline-secondary icon"><i class="fas fa-print"></i> {{ 'Print'|trans }}</a>
<a href="{{ message.url.new_message }}" class="btn btn-outline-secondary icon"><i class="fas fa-reply"></i> {{ 'Reply'|trans }}</a>
<a href="{{ message.url.delete }}" class="btn btn-outline-secondary icon"><i class="fas fa-trash"></i> {{ 'Delete'|trans }}</a>
</div>
</div>
</div>
</div>
<div class="email-head-sender">
<div class="date">{{ message.date }}</div>
<div class="avatar">
<img src="{{ message.form_user.avatar }}" alt="Avatar" class="rounded-circle user-avatar-md">
</div>
<div class="sender">
<a href="{{ _p.web }}main/social/profile.php?u={{ message.form_user.id }}">{{ message.form_user.name }}</a>
<div class="email">{{ message.form_user.email }}</div>
</div>
</div>
</div>
<div class="email-body">
{{ message.content }}
</div>
{% if message.attachments %}
<div class="email-attachments">
<div class="title">{{ 'Attachments'|trans }} <span>({{ message.attachments.quantity }} {{ 'Files'|trans }}, {{ message.attachments.total_size }})</span></div>
<ul>
{% for item in message.attachments.files %}
<li>
<a href="{{ item.url }}">
<i class="fas fa-paperclip"></i> {{ item.filename }}
<span>({{ item.size }})</span>
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
{% endautoescape %}
{% endblock %}
Loading…
Cancel
Save