diff --git a/main/exercise/overview.php b/main/exercise/overview.php index 0636459008..45acaf451f 100755 --- a/main/exercise/overview.php +++ b/main/exercise/overview.php @@ -388,10 +388,11 @@ if (!empty($attempts)) { $table_content = $table->toHtml(); } -if ($objExercise->selectAttempts()) { - $attempt_message = get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts(); +$selectAttempts = $objExercise->selectAttempts(); +if ($selectAttempts) { + $attempt_message = get_lang('Attempts').' '.$counter.' / '.$selectAttempts; - if ($counter == $objExercise->selectAttempts()) { + if ($counter == $selectAttempts) { $attempt_message = Display::return_message($attempt_message, 'error'); } else { $attempt_message = Display::return_message($attempt_message, 'info'); diff --git a/main/inc/ajax/message.ajax.php b/main/inc/ajax/message.ajax.php index 99b6ea3b86..4715a9fe1f 100755 --- a/main/inc/ajax/message.ajax.php +++ b/main/inc/ajax/message.ajax.php @@ -62,7 +62,7 @@ switch ($action) { $count_unread_message = 0; if (api_get_setting('allow_message_tool') === 'true') { // get count unread message and total invitations - $count_unread_message = MessageManager::getNumberOfMessages(['message_status' => [MESSAGE_STATUS_UNREAD]]); + $count_unread_message = MessageManager::getCountNewMessagesFromDB($userId); } if (api_get_setting('allow_social_tool') === 'true') { diff --git a/main/inc/lib/banner.lib.php b/main/inc/lib/banner.lib.php index 56017a2824..49809e174a 100755 --- a/main/inc/lib/banner.lib.php +++ b/main/inc/lib/banner.lib.php @@ -86,6 +86,21 @@ function accessToWhoIsOnline() $access = true; } + if ($access === true) { + $profileList = api_get_configuration_value('allow_online_users_by_status'); + if (!empty($profileList) && isset($profileList['status'])) { + $userInfo = api_get_user_info(); + if ($userInfo['is_admin']) { + $userInfo['status'] = PLATFORM_ADMIN; + } + $profileList = $profileList['status']; + $access = false; + if (in_array($userInfo['status'], $profileList)) { + $access = true; + } + } + } + return $access; } diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 2a7c891abd..5163ddbffd 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -15,6 +15,10 @@ use ChamiloSession as Session; */ class MessageManager { + const MESSAGE_TYPE_INBOX = 1; + const MESSAGE_TYPE_OUTBOX = 2; + const MESSAGE_TYPE_PROMOTED = 3; + /** * Get count new messages for the current user from the database. * @@ -53,30 +57,15 @@ class MessageManager * * @return int */ - public static function getNumberOfMessages($params = []) + public static function getNumberOfMessages($params) { - $messageStatus = [MESSAGE_STATUS_NEW, MESSAGE_STATUS_UNREAD]; - if (isset($params['message_status']) && !empty($params['message_status'])) { - $messageStatus = $params['message_status']; - } - $messageStatus = array_map('intval', $messageStatus); - $messageStatusCondition = implode("','", $messageStatus); - $table = Database::get_main_table(TABLE_MESSAGE); - $keyword = isset($params['keyword']) && !empty($params['keyword']) ? $params['keyword'] : ''; - - $keywordCondition = ''; - if (!empty($keyword)) { - $keyword = Database::escape_string($keyword); - $keywordCondition = " AND (title like '%$keyword%' OR content LIKE '%$keyword%') "; - } + $conditions = self::getWhereConditions($params); $sql = "SELECT COUNT(id) as number_messages FROM $table WHERE - msg_status IN ('$messageStatusCondition') AND - user_receiver_id = ".api_get_user_id()." - $keywordCondition + $conditions "; $result = Database::query($sql); $result = Database::fetch_array($result); @@ -88,6 +77,53 @@ class MessageManager return 0; } + /** + * @param array $extraParams + * + * @return string + */ + public static function getWhereConditions($extraParams) + { + $userId = api_get_user_id(); + + $keyword = isset($extraParams['keyword']) && !empty($extraParams['keyword']) ? $extraParams['keyword'] : ''; + $type = isset($extraParams['type']) && !empty($extraParams['type']) ? $extraParams['type'] : ''; + + if (empty($type)) { + return ''; + } + + switch ($type) { + case self::MESSAGE_TYPE_INBOX: + $statusList = [MESSAGE_STATUS_NEW, MESSAGE_STATUS_UNREAD]; + $userCondition = " user_receiver_id = $userId AND"; + break; + case self::MESSAGE_TYPE_OUTBOX: + $statusList = [MESSAGE_STATUS_OUTBOX]; + $userCondition = " user_sender_id = $userId AND"; + break; + case self::MESSAGE_TYPE_PROMOTED: + $statusList = [MESSAGE_STATUS_PROMOTED]; + $userCondition = " user_receiver_id = $userId AND"; + break; + } + + if (empty($statusList)) { + return ''; + } + + $keywordCondition = ''; + if (!empty($keyword)) { + $keyword = Database::escape_string($keyword); + $keywordCondition = " AND (title like '%$keyword%' OR content LIKE '%$keyword%') "; + } + $messageStatusCondition = implode("','", $statusList); + + return " $userCondition + msg_status IN ('$messageStatusCondition') + $keywordCondition"; + } + /** * Gets information about some messages, used for the inbox sortable table. * @@ -108,8 +144,6 @@ class MessageManager ) { $from = (int) $from; $numberOfItems = (int) $numberOfItems; - $userId = api_get_user_id(); - // Forcing this order. if (!isset($direction)) { $column = 2; @@ -125,24 +159,29 @@ class MessageManager $column = 2; } - $keyword = isset($extraParams['keyword']) && !empty($extraParams['keyword']) ? $extraParams['keyword'] : ''; - $viewUrl = api_get_path(WEB_CODE_PATH).'messages/view_message.php'; - if (isset($extraParams['view_url']) && !empty($extraParams['view_url'])) { - $viewUrl = $extraParams['view_url']; + $type = isset($extraParams['type']) && !empty($extraParams['type']) ? $extraParams['type'] : ''; + + if (empty($type)) { + return []; } - $keywordCondition = ''; - if (!empty($keyword)) { - $keyword = Database::escape_string($keyword); - $keywordCondition = " AND (title like '%$keyword%' OR content LIKE '%$keyword%') "; + $viewUrl = ''; + switch ($type) { + case self::MESSAGE_TYPE_OUTBOX: + case self::MESSAGE_TYPE_INBOX: + $viewUrl = api_get_path(WEB_CODE_PATH).'messages/view_message.php'; + break; + case self::MESSAGE_TYPE_PROMOTED: + $viewUrl = api_get_path(WEB_CODE_PATH).'social/view_promoted_message.php'; + break; } + $viewUrl .= '?type='.$type; - $messageStatus = [MESSAGE_STATUS_NEW, MESSAGE_STATUS_UNREAD]; - if (isset($extraParams['message_status']) && !empty($extraParams['message_status'])) { - $messageStatus = $extraParams['message_status']; + $whereConditions = self::getWhereConditions($extraParams); + + if (empty($whereConditions)) { + return []; } - $messageStatus = array_map('intval', $messageStatus); - $messageStatusCondition = implode("','", $messageStatus); $table = Database::get_main_table(TABLE_MESSAGE); $sql = "SELECT @@ -153,9 +192,7 @@ class MessageManager user_sender_id FROM $table WHERE - user_receiver_id = $userId AND - msg_status IN ('$messageStatusCondition') - $keywordCondition + $whereConditions ORDER BY col$column $direction LIMIT $from, $numberOfItems"; @@ -183,7 +220,7 @@ class MessageManager $userInfo = api_get_user_info($senderId); $message[3] = ''; if (!empty($senderId) && !empty($userInfo)) { - $message[1] = ''.$title.'
'; + $message[1] = ''.$title.'
'; $message[1] .= $userInfo['complete_name_with_username']; if (in_array('reply', $actions)) { $message[3] = @@ -194,7 +231,7 @@ class MessageManager ); } } else { - $message[1] = ''.$title.'
'; + $message[1] = ''.$title.'
'; $message[1] .= get_lang('UnknownUser'); if (in_array('reply', $actions)) { $message[3] = @@ -817,7 +854,10 @@ class MessageManager } $sql = "SELECT * FROM $table - WHERE id = $id AND msg_status <> ".MESSAGE_STATUS_OUTBOX; + WHERE + id = $id AND + user_receiver_id = $user_receiver_id AND + msg_status <> ".MESSAGE_STATUS_OUTBOX; $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { @@ -849,16 +889,16 @@ class MessageManager */ public static function delete_message_by_user_sender($user_sender_id, $id) { - if ($id != strval(intval($id))) { + $user_sender_id = (int) $user_sender_id; + $id = (int) $id; + + if (empty($id) || empty($user_sender_id)) { return false; } $table = Database::get_main_table(TABLE_MESSAGE); - $id = intval($id); - $user_sender_id = intval($user_sender_id); - - $sql = "SELECT * FROM $table WHERE id='$id'"; + $sql = "SELECT * FROM $table WHERE id = $id AND user_sender_id= $user_sender_id"; $rs = Database::query($sql); if (Database::num_rows($rs) > 0) { @@ -866,8 +906,8 @@ class MessageManager self::delete_message_attachment_file($id, $user_sender_id); // delete message $sql = "UPDATE $table - SET msg_status = ".MESSAGE_STATUS_DELETED." - WHERE user_sender_id='$user_sender_id' AND id='$id'"; + SET msg_status = '".MESSAGE_STATUS_DELETED."' + WHERE user_sender_id= $user_sender_id AND id= $id"; Database::query($sql); return true; @@ -1268,30 +1308,34 @@ class MessageManager /** * display message box in the inbox. * - * @param int the message id - * @param string inbox or outbox strings are available + * @param int $messageId + * @param int $type * * @todo replace numbers with letters in the $row array pff... * * @return string html with the message content */ - public static function showMessageBox($messageId, $source) + public static function showMessageBox($messageId, $type) { - $table = Database::get_main_table(TABLE_MESSAGE); $messageId = (int) $messageId; - if (empty($messageId)) { + if (empty($messageId) || empty($type)) { return ''; } $currentUserId = api_get_user_id(); - switch ($source) { - case 'outbox': + $table = Database::get_main_table(TABLE_MESSAGE); + + if (empty($type)) { + return ''; + } + + switch ($type) { + case self::MESSAGE_TYPE_OUTBOX: $status = MESSAGE_STATUS_OUTBOX; $userCondition = " user_sender_id = $currentUserId AND "; - break; - case 'inbox': + case self::MESSAGE_TYPE_INBOX: $status = MESSAGE_STATUS_NEW; $userCondition = " user_receiver_id = $currentUserId AND "; @@ -1300,17 +1344,21 @@ class MessageManager WHERE id = $messageId "; Database::query($query); break; - case 'promoted_messages': + case self::MESSAGE_TYPE_PROMOTED: $status = MESSAGE_STATUS_PROMOTED; $userCondition = " user_receiver_id = $currentUserId AND "; break; } + if (empty($userCondition)) { + return ''; + } + $query = "SELECT * FROM $table - WHERE - id = $messageId AND - $userCondition - msg_status = $status"; + WHERE + id = $messageId AND + $userCondition + msg_status = $status"; $result = Database::query($query); $row = Database::fetch_array($result, 'ASSOC'); @@ -1321,10 +1369,7 @@ class MessageManager $user_sender_id = $row['user_sender_id']; // get file attachments by message id - $files_attachments = self::getAttachmentLinkList( - $messageId, - $source - ); + $files_attachments = self::getAttachmentLinkList($messageId, $type); $row['content'] = str_replace('
', '
', $row['content']); $title = Security::remove_XSS($row['title'], STUDENT, true); @@ -1353,49 +1398,51 @@ class MessageManager $message_content .= ''; if (api_get_setting('allow_social_tool') === 'true') { $message_content .= '
'; - if ($source === 'outbox') { - $message_content .= '
'; - $message_content .= ''; + $message_content .= '
'; $message_content .= '
'; } else { - if ($source === 'outbox') { - $message_content .= get_lang('From').': '.$name.' '.api_strtolower(get_lang('To')).' '. - $receiverUserInfo['complete_name_with_username'].''; - } else { - $message_content .= get_lang('From').': '.$name.' '.api_strtolower(get_lang('To')).' '. - get_lang('Me').''; + switch ($type) { + case self::MESSAGE_TYPE_INBOX: + $message_content .= get_lang('From').': '.$name.' '.api_strtolower(get_lang('To')).' '. + get_lang('Me').''; + break; + case self::MESSAGE_TYPE_OUTBOX: + + $message_content .= get_lang('From').': '.$name.' '.api_strtolower(get_lang('To')).' '. + $receiverUserInfo['complete_name_with_username'].''; + break; } } @@ -1413,20 +1460,21 @@ class MessageManager $social_link = 'f=social'; } - if ($source == 'outbox') { - $message_content .= ''. - Display::return_icon('back.png', get_lang('ReturnToOutbox')).'  '; - } elseif ($source === 'inbox') { - $message_content .= ''. - Display::return_icon('back.png', get_lang('ReturnToInbox')).'  '; - $message_content .= ''. - Display::return_icon('message_reply.png', get_lang('ReplyToMessage')).'  '; - } - $urlMessage['delete'] = 'inbox.php?action=deleteone&id='.$messageId.'&'.$social_link; - - if (in_array($source, ['inbox', 'outbox'])) { - $message_content .= ''. - Display::return_icon('delete.png', get_lang('DeleteMessage')).' '; + switch ($type) { + case self::MESSAGE_TYPE_OUTBOX: + $message_content .= ''. + Display::return_icon('back.png', get_lang('ReturnToOutbox')).'  '; + $message_content .= ''. + Display::return_icon('delete.png', get_lang('DeleteMessage')).' '; + break; + case self::MESSAGE_TYPE_INBOX: + $message_content .= ''. + Display::return_icon('back.png', get_lang('ReturnToInbox')).'  '; + $message_content .= ''. + Display::return_icon('message_reply.png', get_lang('ReplyToMessage')).'  '; + $message_content .= ''. + Display::return_icon('delete.png', get_lang('DeleteMessage')).' '; + break; } $message_content .= ' @@ -1594,8 +1642,6 @@ class MessageManager * * @param $groupId * @param $topic_id - * @param $is_member - * @param $messageId * * @return string */ @@ -1629,7 +1675,7 @@ class MessageManager $items_page_nr = null; $user_sender_info = api_get_user_info($main_message['user_sender_id']); - $files_attachments = self::getAttachmentLinkList($main_message['id']); + $files_attachments = self::getAttachmentLinkList($main_message['id'], 0); $name = $user_sender_info['complete_name']; $topic_page_nr = isset($_GET['topics_page_nr']) ? (int) $_GET['topics_page_nr'] : null; @@ -1771,7 +1817,7 @@ class MessageManager $links .= '
'; $html_items = ''; $user_sender_info = api_get_user_info($topic['user_sender_id']); - $files_attachments = self::getAttachmentLinkList($topic['id']); + $files_attachments = self::getAttachmentLinkList($topic['id'], 0); $name = $user_sender_info['complete_name']; $links .= '
'; @@ -2002,12 +2048,12 @@ class MessageManager /** * Get array of links (download) for message attachment files. * - * @param int $messageId - * @param string $type message list (inbox/outbox) + * @param int $messageId + * @param int $type * * @return array */ - public static function getAttachmentLinkList($messageId, $type = '') + public static function getAttachmentLinkList($messageId, $type) { $files = self::getAttachmentList($messageId); // get file attachments by message id @@ -2025,10 +2071,9 @@ class MessageManager $comment = !empty($comment) ? ' - '.$comment.'' : ''; $attachmentLine = $attachIcon.' '.$link.' ('.$size.')'.$comment; - if ($row_file['comment'] == 'audio_message') { + if ($row_file['comment'] === 'audio_message') { $attachmentLine = '
'; - $formattedList .= '
'; + $formattedList .= '
'; $formattedList .= '
-
+
'.get_lang('Post').' @@ -1948,7 +1950,7 @@ class SocialManager extends UserManager } } } else { - $list = MessageManager::getAttachmentLinkList($messageId); + $list = MessageManager::getAttachmentLinkList($messageId, 0); } return $list; @@ -2448,15 +2450,15 @@ class SocialManager extends UserManager null, [ 'placeholder' => $socialWallPlaceholder, - 'cols-size' => [1, 10, 1], + 'cols-size' => [1, 12, 1], 'aria-label' => $socialWallPlaceholder, ] ); $form->addHtml('
'); - $form->addHtml('
'); + $form->addHtml('
'); $form->addFile('picture', get_lang('UploadFile'), ['custom' => true]); $form->addHtml('
'); - $form->addHtml('
'); + $form->addHtml('
'); $form->addButtonSend( get_lang('Post'), 'wall_post_button', @@ -2466,9 +2468,8 @@ class SocialManager extends UserManager 'custom' => true, ] ); + $form->addHtml('
'); $form->addHtml('
'); - $form->addHtml('
'); - $form->addHidden('url_content', ''); $html = Display::panel($form->returnForm(), get_lang('SocialWall')); diff --git a/main/messages/download.php b/main/messages/download.php index d2d136d9a1..f6a3c69f34 100755 --- a/main/messages/download.php +++ b/main/messages/download.php @@ -14,6 +14,7 @@ session_cache_limiter('public'); require_once __DIR__.'/../inc/global.inc.php'; $file_url = isset($_GET['file']) ? $_GET['file'] : ''; +$type = isset($_GET['type']) ? $_GET['type'] : ''; if (empty($file_url)) { api_not_allowed(); @@ -52,13 +53,13 @@ $current_uid = api_get_user_id(); // get message user id for inbox/outbox $message_uid = ''; -$message_type = ['inbox', 'outbox']; -if (in_array($_GET['type'], $message_type)) { - if ($_GET['type'] == 'inbox') { +switch ($type) { + case MessageManager::MESSAGE_TYPE_INBOX: $message_uid = $row_users['user_receiver_id']; - } else { + break; + case MessageManager::MESSAGE_TYPE_OUTBOX: $message_uid = $row_users['user_sender_id']; - } + break; } // allow to the correct user for download this file diff --git a/main/messages/inbox.php b/main/messages/inbox.php index ca20fda02e..0ba9c20824 100755 --- a/main/messages/inbox.php +++ b/main/messages/inbox.php @@ -23,74 +23,6 @@ Event::registerLog($logInfo); $allowSocial = api_get_setting('allow_social_tool') == 'true'; $allowMessage = api_get_setting('allow_message_tool') == 'true'; -if (isset($_GET['messages_page_nr'])) { - if ($allowSocial && $allowMessage) { - header('Location:inbox.php'); - exit; - } -} - -$nameTools = get_lang('Messages'); -$show_message = null; -if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) { - $info_reply = []; - $info_delete = []; - - if (isset($_GET['form_reply'])) { - //allow to insert messages - $info_reply = explode(base64_encode('&%ff..x'), $_GET['form_reply']); - $count_reply = count($info_reply); - $button_sent = urldecode($info_reply[4]); - } - - if (isset($_GET['form_delete'])) { - //allow to delete messages - $info_delete = explode(',', $_GET['form_delete']); - $count_delete = (count($info_delete) - 1); - } - - if (isset($button_sent)) { - $title = urldecode($info_reply[0]); - $content = str_replace("\\", '', urldecode($info_reply[1])); - - $user_reply = $info_reply[2]; - $user_email_base = str_replace(')', '(', $info_reply[5]); - $user_email_prepare = explode('(', $user_email_base); - if (count($user_email_prepare) == 1) { - $user_email = trim($user_email_prepare[0]); - } elseif (count($user_email_prepare) == 3) { - $user_email = trim($user_email_prepare[1]); - } - $user_id_by_email = MessageManager::get_user_id_by_email($user_email); - - if ($info_reply[6] == 'save_form') { - $user_id_by_email = $info_reply[2]; - } - if (isset($user_reply) && !is_null($user_id_by_email) && strlen($info_reply[0]) > 0) { - MessageManager::send_message($user_id_by_email, $title, $content); - $show_message .= MessageManager::return_message($user_id_by_email, 'confirmation'); - $social_right_content .= MessageManager::inboxDisplay(); - exit; - } elseif (is_null($user_id_by_email)) { - $message_box = get_lang('ErrorSendingMessage'); - $show_message .= Display::return_message(api_xml_http_response_encode($message_box), 'error'); - $social_right_content .= MessageManager::inboxDisplay(); - exit; - } - } elseif (trim($info_delete[0]) == 'delete') { - for ($i = 1; $i <= $count_delete; $i++) { - MessageManager::delete_message_by_user_receiver( - api_get_user_id(), - $info_delete[$i] - ); - } - $message_box = get_lang('SelectedMessagesDeleted'); - $show_message .= Display::return_message(api_xml_http_response_encode($message_box)); - $social_right_content .= MessageManager::inboxDisplay(); - exit; - } -} - if ($allowSocial) { $this_section = SECTION_SOCIAL; $interbreadcrumb[] = [ @@ -147,21 +79,7 @@ if ($allowSocial) { $social_right_content .= Display::toolbarAction('toolbar', [$actionsLeft, $actionsRight]); } -if (!isset($_GET['del_msg'])) { - $social_right_content .= MessageManager::inboxDisplay($keyword); -} else { - $num_msg = (int) $_POST['total']; - for ($i = 0; $i < $num_msg; $i++) { - if ($_POST[$i]) { - // The user_id was necessary to delete a message?? - $show_message .= MessageManager::delete_message_by_user_receiver( - api_get_user_id(), - $_POST['_'.$i] - ); - } - } - $social_right_content .= MessageManager::inboxDisplay(); -} +$social_right_content .= MessageManager::inboxDisplay($keyword); $tpl = new Template(null); diff --git a/main/messages/new_message.php b/main/messages/new_message.php index 99b5c0f856..02673d5a30 100755 --- a/main/messages/new_message.php +++ b/main/messages/new_message.php @@ -197,7 +197,7 @@ function manageForm($default, $select_from_user_list = null, $sent_to = '', $tpl if (isset($_GET['forward_id'])) { $forwardId = (int) $_GET['forward_id']; $message_reply_info = MessageManager::get_message_by_id($forwardId); - $attachments = MessageManager::getAttachmentLinkList($forwardId); + $attachments = MessageManager::getAttachmentLinkList($forwardId, MessageManager::MESSAGE_TYPE_INBOX); if (!empty($attachments)) { $fileListToString = !empty($attachments) ? implode('
', $attachments) : ''; $form->addLabel('', $fileListToString); diff --git a/main/messages/outbox.php b/main/messages/outbox.php index 6d2f60bb7d..5381d13b75 100755 --- a/main/messages/outbox.php +++ b/main/messages/outbox.php @@ -55,11 +55,6 @@ if ($allowMessage) { Display::return_icon('outbox.png', get_lang('Outbox')).''; } -$action = null; -if (isset($_REQUEST['action'])) { - $action = $_REQUEST['action']; -} - $keyword = ''; $social_right_content = ''; if ($allowSocial) { @@ -79,32 +74,8 @@ if ($allowSocial) { [$actionsLeft, $actionsRight] ); } -//MAIN CONTENT -if ($action == 'delete') { - $delete_list_id = []; - if (isset($_POST['out'])) { - $delete_list_id = $_POST['out']; - } - if (isset($_POST['id'])) { - $delete_list_id = $_POST['id']; - } - for ($i = 0; $i < count($delete_list_id); $i++) { - MessageManager::delete_message_by_user_sender( - api_get_user_id(), - $delete_list_id[$i] - ); - } - $delete_list_id = []; - $social_right_content .= MessageManager::outbox_display($keyword); -} elseif ($action == 'deleteone') { - $delete_list_id = []; - $id = Security::remove_XSS($_GET['id']); - MessageManager::delete_message_by_user_sender(api_get_user_id(), $id); - $delete_list_id = []; - $social_right_content .= MessageManager::outbox_display($keyword); -} else { - $social_right_content .= MessageManager::outbox_display($keyword); -} + +$social_right_content .= MessageManager::outBoxDisplay($keyword); $tpl = new Template(get_lang('Outbox')); // Block Social Avatar diff --git a/main/messages/view_message.php b/main/messages/view_message.php index 3cf060ed98..65e839124d 100755 --- a/main/messages/view_message.php +++ b/main/messages/view_message.php @@ -8,12 +8,18 @@ $cidReset = true; require_once __DIR__.'/../inc/global.inc.php'; api_block_anonymous_users(); -if (api_get_setting('allow_message_tool') != 'true') { +$allowSocial = api_get_setting('allow_social_tool') === 'true'; +$allowMessage = api_get_setting('allow_message_tool') === 'true'; + +if (!$allowMessage) { api_not_allowed(true); } -$allowSocial = api_get_setting('allow_social_tool') === 'true'; -$allowMessage = api_get_setting('allow_message_tool') === 'true'; +$messageId = isset($_GET['id']) ? (int) $_GET['id'] : 0; + +if (empty($messageId)) { + api_not_allowed(true); +} if ($allowSocial) { $this_section = SECTION_SOCIAL; @@ -25,7 +31,7 @@ if ($allowSocial) { $interbreadcrumb[] = ['url' => 'inbox.php', 'name' => get_lang('Messages')]; $social_right_content = '
'; -if (api_get_setting('allow_message_tool') === 'true') { +if ($allowMessage) { $social_right_content .= ''. Display::return_icon('new-message.png', get_lang('ComposeMessage')).''; $social_right_content .= ''. @@ -34,22 +40,18 @@ if (api_get_setting('allow_message_tool') === 'true') { Display::return_icon('outbox.png', get_lang('Outbox')).''; } $social_right_content .= '
'; +$type = isset($_GET['type']) ? (int) $_GET['type'] : MessageManager::MESSAGE_TYPE_INBOX; -if (empty($_GET['id'])) { - $messageId = $_GET['id_send']; - $source = 'outbox'; +$show_menu = 'messages_inbox'; +if ($type === MessageManager::MESSAGE_TYPE_OUTBOX) { $show_menu = 'messages_outbox'; -} else { - $messageId = $_GET['id']; - $source = 'inbox'; - $show_menu = 'messages_inbox'; } $message = ''; - $logInfo = [ 'tool' => 'Messages', - 'action' => $source, + 'tool_id' => $messageId, + 'action' => 'view-message', 'action_details' => 'view-message', ]; Event::registerLog($logInfo); @@ -60,7 +62,7 @@ if (api_get_setting('allow_social_tool') === 'true') { $social_menu_block = SocialManager::show_social_menu($show_menu); } // MAIN CONTENT -$message .= MessageManager::showMessageBox($messageId, $source); +$message .= MessageManager::showMessageBox($messageId, $type); if (!empty($message)) { $social_right_content .= $message; diff --git a/main/mySpace/access_details_session.php b/main/mySpace/access_details_session.php index aabf45006b..e96d7918b2 100644 --- a/main/mySpace/access_details_session.php +++ b/main/mySpace/access_details_session.php @@ -244,7 +244,7 @@ if ($form->validate()) { } } - $table = new HTML_Table(['class' => 'data_table']); + $table = new HTML_Table(['class' => 'data_table_pdf']); $headers = [ get_lang('MinStartDate'), get_lang('MaxEndDate'), diff --git a/main/social/promoted_messages.php b/main/social/promoted_messages.php index ec8671f708..05a37a5a50 100644 --- a/main/social/promoted_messages.php +++ b/main/social/promoted_messages.php @@ -17,31 +17,6 @@ $logInfo = [ ]; Event::registerLog($logInfo); -$nameTools = get_lang('Messages'); -$show_message = null; -if (isset($_GET['form_reply']) || isset($_GET['form_delete'])) { - $info_reply = []; - $info_delete = []; - if (isset($_GET['form_delete'])) { - //allow to delete messages - $info_delete = explode(',', $_GET['form_delete']); - $count_delete = (count($info_delete) - 1); - } - - if (trim($info_delete[0]) === 'delete') { - for ($i = 1; $i <= $count_delete; $i++) { - MessageManager::delete_message_by_user_receiver( - api_get_user_id(), - $info_delete[$i] - ); - } - $message_box = get_lang('SelectedMessagesDeleted'); - $show_message .= Display::return_message(api_xml_http_response_encode($message_box)); - $social_right_content .= MessageManager::inboxDisplay(); - exit; - } -} - $this_section = SECTION_SOCIAL; $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'social/home.php', @@ -68,22 +43,7 @@ if ($form->validate()) { } $actionsRight = $form->returnForm(); $social_right_content .= Display::toolbarAction('toolbar', [$actionsLeft, $actionsRight]); - -if (!isset($_GET['del_msg'])) { - $social_right_content .= MessageManager::getPromotedMessagesGrid($keyword); -} else { - $num_msg = (int) $_POST['total']; - for ($i = 0; $i < $num_msg; $i++) { - if ($_POST[$i]) { - // The user_id was necessary to delete a message?? - $show_message .= MessageManager::delete_message_by_user_receiver( - api_get_user_id(), - $_POST['_'.$i] - ); - } - } - $social_right_content .= MessageManager::getPromotedMessagesGrid(); -} +$social_right_content .= MessageManager::getPromotedMessagesGrid($keyword); $tpl = new Template(null); // Block Social Avatar diff --git a/main/social/view_promoted_message.php b/main/social/view_promoted_message.php index 750946a84d..6f16241a68 100644 --- a/main/social/view_promoted_message.php +++ b/main/social/view_promoted_message.php @@ -1,9 +1,6 @@ api_get_path(WEB_PATH).'main/social/home.php', 'n $interbreadcrumb[] = ['url' => 'promoted_messages.php', 'name' => get_lang('PromotedMessages')]; $social_right_content = ''; -if (empty($_GET['id'])) { - $messageId = $_GET['id_send']; - $source = 'outbox'; - $show_menu = 'messages_outbox'; -} else { - $messageId = $_GET['id']; - $source = 'inbox'; - $show_menu = 'messages_inbox'; -} +$messageId = $_GET['id']; $message = ''; - $logInfo = [ 'tool' => 'Messages', - 'action' => $source, + 'action' => 'promoted_messages', 'action_details' => 'view-message', ]; Event::registerLog($logInfo); -$social_menu_block = SocialManager::show_social_menu($show_menu); -$message .= MessageManager::showMessageBox($messageId, 'promoted_messages'); +$social_menu_block = SocialManager::show_social_menu('inbox'); +$message .= MessageManager::showMessageBox($messageId, MessageManager::MESSAGE_TYPE_PROMOTED); if (!empty($message)) { $social_right_content .= $message; @@ -45,7 +33,7 @@ if (!empty($message)) { } $tpl = new Template(get_lang('View')); // Block Social Avatar -SocialManager::setSocialUserBlock($tpl, api_get_user_id(), $show_menu); +SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'promoted_messages'); $tpl->assign('social_menu_block', $social_menu_block); $tpl->assign('social_right_content', $social_right_content);