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 "media";
//@import 'loader';
@import 'inbox';
@import 'sidebar';
@import 'login';
@import 'install';

@ -1278,13 +1278,14 @@ class MessageManager
*
* @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')
{
$table = Database::get_main_table(TABLE_MESSAGE);
$messageId = (int) $messageId;
$currentUserId = api_get_user_id();
$msg = [];
if ($source == 'outbox') {
if (isset($messageId) && is_numeric($messageId)) {
@ -1315,119 +1316,65 @@ class MessageManager
$row = Database::fetch_array($result, 'ASSOC');
if (empty($row)) {
return '';
return $msg;
}
$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
$files_attachments = self::getAttachmentLinkList(
$messageId,
$source
);
$msg['title'] = Security::remove_XSS($row['title'], STUDENT, true);
$msg['attachments'] = $files_attachments;
$row['content'] = str_replace('</br>', '<br />', $row['content']);
$title = Security::remove_XSS($row['title'], STUDENT, true);
$content = Security::remove_XSS($row['content'], STUDENT, true);
$name = get_lang('UnknownUser');
$contentMsg = str_replace('</br>', '<br />', $row['content']);
$content = Security::remove_XSS($contentMsg, STUDENT, true);
$msg['content'] = $content;
$fromUser = api_get_user_info($user_sender_id);
$userImage = '';
if (!empty($user_sender_id) && !empty($fromUser)) {
$name = $fromUser['complete_name_with_username'];
$userImage = Display::img(
$fromUser['avatar_small'],
$name,
['title' => $name, 'class' => 'rounded-circle mr-2'],
false
);
$msg['form_user'] = [
'id' => $fromUser['id'],
'name' => $fromUser['complete_name'],
'username' => $fromUser['username'],
'avatar' => $fromUser['avatar_small'],
'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'])) {
$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>';
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">';
$urlMessage = [];
$social_link = '';
if (isset($_GET['f']) && $_GET['f'] == 'social') {
$social_link = 'f=social';
}
if ($source == 'outbox') {
$message_content .= '<a href="outbox.php?'.$social_link.'">'.
Display::return_icon('back.png', get_lang('ReturnToOutbox')).'</a> &nbsp';
$urlMessage['return'] = 'outbox.php?'.$social_link;
} else {
$message_content .= '<a href="inbox.php?'.$social_link.'">'.
Display::return_icon('back.png', get_lang('ReturnToInbox')).'</a> &nbsp';
$message_content .= '<a href="new_message.php?re_id='.$messageId.'&'.$social_link.'">'.
Display::return_icon('message_reply.png', get_lang('ReplyToMessage')).'</a> &nbsp';
$urlMessage['back'] = 'inbox.php?'.$social_link;
$urlMessage['new_message'] = 'new_message.php?re_id='.$messageId.'&'.$social_link;
}
$message_content .= '<a href="inbox.php?action=deleteone&id='.$messageId.'&'.$social_link.'" >'.
Display::return_icon('delete.png', get_lang('DeleteMessage')).'</a>&nbsp';
$urlMessage['delete'] = 'inbox.php?action=deleteone&id='.$messageId.'&'.$social_link;
$message_content .= '</div></td>
<td width=10></td>
</tr>
</table>';
$msg['url'] = $urlMessage;
return $message_content;
return $msg;
}
/**
@ -2005,28 +1952,44 @@ class MessageManager
$files = self::getAttachmentList($messageId);
// get file attachments by message id
$list = [];
$totalSize = 0;
if ($files) {
$attachIcon = Display::return_icon('attachment.gif', '');
$archiveURL = api_get_path(WEB_CODE_PATH).'messages/download.php?type='.$type.'&file=';
$countFiles = count($files);
foreach ($files as $row_file) {
$archiveFile = $row_file['path'];
$filename = $row_file['filename'];
$totalSize += $row_file['size'];
$size = format_file_size($row_file['size']);
$comment = Security::remove_XSS($row_file['comment']);
$filename = Security::remove_XSS($filename);
$link = Display::url($filename, $archiveURL.$archiveFile);
$comment = !empty($comment) ? '&nbsp;-&nbsp;<i>'.$comment.'</i>' : '';
$type = 'file';
$attachmentLine = $attachIcon.'&nbsp;'.$link.'&nbsp;('.$size.')'.$comment;
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')];
$social_right_content = '<div class="actions">';
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>';
$social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.
Display::return_icon('inbox.png', get_lang('Inbox')).'</a>';
$social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'.
Display::return_icon('outbox.png', get_lang('Outbox')).'</a>';
$actionLeft = Display::url(
Display::return_icon(
'new-message.png',
get_lang('ComposeMessage')
),
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'])) {
$messageId = $_GET['id_send'];
@ -56,31 +77,28 @@ $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
$message .= MessageManager::showMessageBox($messageId, $source);
$message = MessageManager::showMessageBox($messageId, $source);
$messageContent = '';
if (!empty($message)) {
$social_right_content .= $message;
$messageContent = $message;
} else {
api_not_allowed(true);
}
$tpl = new Template(get_lang('View'));
// Block Social Avatar
SocialManager::setSocialUserBlock($tpl, api_get_user_id(), $show_menu);
if (api_get_setting('allow_social_tool') === 'true') {
$tpl->assign('social_menu_block', $social_menu_block);
$tpl->assign('social_right_content', $social_right_content);
$social_layout = $tpl->get_template('social/inbox.tpl');
$tpl->assign('actions',$toolbar);
$tpl->assign('message', $messageContent);
$social_layout = $tpl->get_template('message/view_message.html.twig');
$tpl->display($social_layout);
} else {
$content = $social_right_content;
$tpl->assign('content', $content);
$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