|
@@ -50,10 +50,13 @@ require_once 'forumfunction.inc.php';
|
|
|
|
|
|
$userid = api_get_user_id();
|
|
|
$sessionId = api_get_session_id();
|
|
|
+$groupId = api_get_group_id();
|
|
|
+$courseId = api_get_course_int_id();
|
|
|
+
|
|
|
+$isTutor = GroupManager::is_tutor_of_group($userId, $groupId, $courseId);
|
|
|
|
|
|
/* MAIN DISPLAY SECTION */
|
|
|
|
|
|
-$groupId = api_get_group_id();
|
|
|
$my_forum = isset($_GET['forum']) ? $_GET['forum'] : '';
|
|
|
// Note: This has to be validated that it is an existing forum.
|
|
|
$current_forum = get_forum_information($my_forum);
|
|
@@ -69,23 +72,23 @@ if (!empty($groupId)) {
|
|
|
//Group info & group category info
|
|
|
$group_properties = GroupManager::get_group_properties($groupId);
|
|
|
//User has access in the group?
|
|
|
- $user_has_access_in_group = GroupManager::user_has_access($userid, $groupId, GroupManager::GROUP_TOOL_FORUM);
|
|
|
+ $user_has_access_in_group = GroupManager::user_has_access($userId, $groupId, GroupManager::GROUP_TOOL_FORUM);
|
|
|
$is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $groupId);
|
|
|
|
|
|
//Course
|
|
|
if (
|
|
|
- !api_is_allowed_to_edit(false, true) AND //is a student
|
|
|
- (($current_forum_category && $current_forum_category['visibility'] == 0) OR
|
|
|
- $current_forum['visibility'] == 0 OR !$user_has_access_in_group)
|
|
|
+ !api_is_allowed_to_edit(false, true) && //is a student
|
|
|
+ (($current_forum_category && $current_forum_category['visibility'] == 0) ||
|
|
|
+ $current_forum['visibility'] == 0 || !$user_has_access_in_group)
|
|
|
) {
|
|
|
api_not_allowed(true);
|
|
|
}
|
|
|
} else {
|
|
|
//Course
|
|
|
if (
|
|
|
- !api_is_allowed_to_edit(false, true) AND //is a student
|
|
|
+ !api_is_allowed_to_edit(false, true) && //is a student
|
|
|
(
|
|
|
- ($current_forum_category && $current_forum_category['visibility'] == 0) OR
|
|
|
+ ($current_forum_category && $current_forum_category['visibility'] == 0) ||
|
|
|
$current_forum['visibility'] == 0
|
|
|
) //forum category or forum visibility is false
|
|
|
) {
|
|
@@ -105,11 +108,6 @@ if (api_is_in_gradebook()) {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
-if (!empty($_GET['gidReq'])) {
|
|
|
- $toolgroup = Database::escape_string($_GET['gidReq']);
|
|
|
- Session::write('toolgroup',$toolgroup);
|
|
|
-}
|
|
|
-
|
|
|
$forumUrl = api_get_path(WEB_CODE_PATH).'forum/';
|
|
|
|
|
|
if ($origin == 'group') {
|
|
@@ -151,9 +149,9 @@ if ($origin == 'learnpath') {
|
|
|
/* Actions */
|
|
|
// Change visibility of a forum or a forum category.
|
|
|
if (
|
|
|
- ($my_action == 'invisible' OR $my_action == 'visible') AND
|
|
|
- isset($_GET['content']) AND
|
|
|
- isset($_GET['id']) AND
|
|
|
+ ($my_action == 'invisible' || $my_action == 'visible') &&
|
|
|
+ isset($_GET['content']) &&
|
|
|
+ isset($_GET['id']) &&
|
|
|
api_is_allowed_to_edit(false, true) &&
|
|
|
api_is_allowed_to_session_edit(false, true)
|
|
|
) {
|
|
@@ -161,8 +159,8 @@ if (
|
|
|
}
|
|
|
// Locking and unlocking.
|
|
|
if (
|
|
|
- ($my_action == 'lock' OR $my_action == 'unlock') AND
|
|
|
- isset($_GET['content']) AND isset($_GET['id']) AND
|
|
|
+ ($my_action == 'lock' || $my_action == 'unlock') &&
|
|
|
+ isset($_GET['content']) && isset($_GET['id']) &&
|
|
|
api_is_allowed_to_edit(false, true) &&
|
|
|
api_is_allowed_to_session_edit(false, true)
|
|
|
) {
|
|
@@ -170,9 +168,9 @@ if (
|
|
|
}
|
|
|
// Deleting.
|
|
|
if (
|
|
|
- $my_action == 'delete' AND
|
|
|
- isset($_GET['content']) AND
|
|
|
- isset($_GET['id']) AND
|
|
|
+ $my_action == 'delete' &&
|
|
|
+ isset($_GET['content']) &&
|
|
|
+ isset($_GET['id']) &&
|
|
|
api_is_allowed_to_edit(false, true) &&
|
|
|
api_is_allowed_to_session_edit(false, true)
|
|
|
) {
|
|
@@ -276,7 +274,7 @@ if (
|
|
|
$table_list .= '<th>' . get_lang('Qualify') . '</th>';
|
|
|
}
|
|
|
$table_list .= '</tr>';
|
|
|
- $max_qualify = showQualify('2', $userid, $_GET['id']);
|
|
|
+ $max_qualify = showQualify('2', $userId, $_GET['id']);
|
|
|
$counter_stdlist = 0;
|
|
|
|
|
|
if (Database::num_rows($student_list) > 0) {
|
|
@@ -357,9 +355,9 @@ if ($origin != 'learnpath') {
|
|
|
// 2. the course member is here and new threads are allowed
|
|
|
// 3. a visitor is here and new threads AND allowed AND anonymous posts are allowed
|
|
|
if (
|
|
|
- api_is_allowed_to_edit(false, true) OR
|
|
|
- ($current_forum['allow_new_threads'] == 1 AND isset($_user['user_id'])) OR
|
|
|
- ($current_forum['allow_new_threads'] == 1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous'] == 1)
|
|
|
+ api_is_allowed_to_edit(false, true) ||
|
|
|
+ ($current_forum['allow_new_threads'] == 1 && isset($_user['user_id'])) ||
|
|
|
+ ($current_forum['allow_new_threads'] == 1 && !isset($_user['user_id']) && $current_forum['allow_anonymous'] == 1)
|
|
|
) {
|
|
|
if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
|
|
|
if (!api_is_anonymous() && !api_is_invitee()) {
|
|
@@ -431,7 +429,7 @@ if (is_array($threads)) {
|
|
|
foreach ($threads as $row) {
|
|
|
// Thread who have no replies yet and the only post is invisible should not be displayed to students.
|
|
|
if (api_is_allowed_to_edit(false, true) ||
|
|
|
- !($row['thread_replies'] == '0' AND $row['visibility'] == '0')
|
|
|
+ !($row['thread_replies'] == '0' && $row['visibility'] == '0')
|
|
|
) {
|
|
|
|
|
|
$my_whatsnew_post_info = null;
|
|
@@ -541,60 +539,22 @@ if (is_array($threads)) {
|
|
|
. Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY)
|
|
|
. ' ' . $last_post;
|
|
|
$html .= '</div>';
|
|
|
-
|
|
|
- /*
|
|
|
- if ($row['last_poster_user_id'] == '0') {
|
|
|
- $name = $row['poster_name'];
|
|
|
- $last_poster_username = "";
|
|
|
- } else {
|
|
|
- $name = api_get_person_name($row['last_poster_firstname'], $row['last_poster_lastname']);
|
|
|
- $tab_last_poster_info = api_get_user_info($row['last_poster_user_id']);
|
|
|
- $last_poster_username = sprintf(get_lang('LoginX'), $tab_last_poster_info['username']);
|
|
|
- }
|
|
|
- // If the last post is invisible and it is not the teacher who is looking then we have to find the last visible post of the thread.
|
|
|
- if (($row['visible'] == '1' OR api_is_allowed_to_edit(false, true)) && $origin != 'learnpath') {
|
|
|
- $last_post = $post_date.' '.get_lang('By').' '.display_user_link($row['last_poster_user_id'], $name, '', $last_poster_username);
|
|
|
- } elseif ($origin != 'learnpath') {
|
|
|
- $last_post_sql = "SELECT post.*, user.firstname, user.lastname, user.username FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' AND post.c_id=".api_get_course_int_id()." ORDER BY post_id DESC";
|
|
|
- $last_post_result = Database::query($last_post_sql);
|
|
|
- $last_post_row = Database::fetch_array($last_post_result);
|
|
|
- $name = api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
|
|
|
- $last_post_info_username = sprintf(get_lang('LoginX'), $last_post_row['username']);
|
|
|
- $last_post = api_convert_and_format_date($last_post_row['post_date']).' '.get_lang('By').' '.display_user_link($last_post_row['poster_id'], $name, '', $last_post_info_username);
|
|
|
- } else {
|
|
|
- $last_post_sql = "SELECT post.*, user.firstname, user.lastname, user.username FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' AND post.c_id=".api_get_course_int_id()." ORDER BY post_id DESC";
|
|
|
- $last_post_result = Database::query($last_post_sql);
|
|
|
- $last_post_row = Database::fetch_array($last_post_result);
|
|
|
- $last_post_info_username = sprintf(get_lang('LoginX'), $last_post_row['username']);
|
|
|
- $name = api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
|
|
|
- $last_post = api_convert_and_format_date($last_post_row['post_date']).' '.get_lang('By').' '.Display::tag('span', $name, array("title"=>api_htmlentities($last_post_info_username, ENT_QUOTES)));
|
|
|
- }*/
|
|
|
-
|
|
|
-
|
|
|
$html .= '<div class="col-md-3">';
|
|
|
+ $cidreq = api_get_cidreq();
|
|
|
+
|
|
|
// Get attachment id.
|
|
|
if (isset($row['post_id'])) {
|
|
|
$attachment_list = get_attachment($row['post_id']);
|
|
|
}
|
|
|
$id_attach = !empty($attachment_list) ? $attachment_list['id'] : '';
|
|
|
-
|
|
|
- $sql = "SELECT post_id
|
|
|
- FROM $table_posts
|
|
|
- WHERE
|
|
|
- c_id = $course_id AND
|
|
|
- post_title='" . Database::escape_string($row['thread_title']) . "' AND
|
|
|
- thread_id = ".$row['thread_id']."
|
|
|
- ";
|
|
|
-
|
|
|
- $result_post_id = Database::query($sql);
|
|
|
- $row_post_id = Database::fetch_array($result_post_id);
|
|
|
$iconsEdit = '';
|
|
|
if ($origin != 'learnpath') {
|
|
|
if (api_is_allowed_to_edit(false, true) &&
|
|
|
- !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)) {
|
|
|
- $iconsEdit .= '<a href="' . $forumUrl . 'editpost.php?' . api_get_cidreq()
|
|
|
- . '&forum=' . Security::remove_XSS($my_forum) . '&thread='
|
|
|
- . Security::remove_XSS($row['thread_id']) . '&post=' . $row_post_id['post_id']
|
|
|
+ !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
|
|
|
+ ) {
|
|
|
+ $iconsEdit .= '<a href="' . $forumUrl . 'editthread.php?' . $cidreq
|
|
|
+ . '&forum=' . intval($my_forum) . '&thread='
|
|
|
+ . intval($row['thread_id'])
|
|
|
. '&id_attach=' . $id_attach . '">'
|
|
|
. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>';
|
|
|
|
|
@@ -606,8 +566,8 @@ if (is_array($threads)) {
|
|
|
ICON_SIZE_SMALL
|
|
|
);
|
|
|
} else {
|
|
|
- $iconsEdit.= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&forum='
|
|
|
- . Security::remove_XSS($my_forum) . '&action=delete&content=thread&id='
|
|
|
+ $iconsEdit.= '<a href="' . api_get_self() . '?' . $cidreq . '&forum='
|
|
|
+ . intval($my_forum) . '&action=delete&content=thread&id='
|
|
|
. $row['thread_id'] . $origin_string
|
|
|
. "\" onclick=\"javascript:if(!confirm('"
|
|
|
. addslashes(api_htmlentities(get_lang('DeleteCompleteThread'), ENT_QUOTES))
|
|
@@ -635,8 +595,8 @@ if (is_array($threads)) {
|
|
|
'gidReq' => api_get_group_id()
|
|
|
)
|
|
|
);
|
|
|
- $iconsEdit .= '<a href="viewforum.php?' . api_get_cidreq() . '&forum='
|
|
|
- . Security::remove_XSS($my_forum)
|
|
|
+ $iconsEdit .= '<a href="viewforum.php?' . $cidreq . '&forum='
|
|
|
+ . intval($my_forum)
|
|
|
. '&action=move&thread=' . $row['thread_id'] . $origin_string . '">'
|
|
|
. Display::return_icon('move.png', get_lang('MoveThread'), array(), ICON_SIZE_SMALL)
|
|
|
. '</a>';
|
|
@@ -685,8 +645,6 @@ if (is_array($threads)) {
|
|
|
echo '</div>';
|
|
|
echo isset($table_list) ? $table_list : '';
|
|
|
|
|
|
-/* FOOTER */
|
|
|
-
|
|
|
if ($origin != 'learnpath') {
|
|
|
Display::display_footer();
|
|
|
}
|