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 .= '