Use group iid see BT#11603

pull/2487/head
jmontoyaa 9 years ago
parent 4c752d69bb
commit 7d74c5e62d
  1. 3
      main/announcements/announcements.php
  2. 4
      main/calendar/agenda.php
  3. 2
      main/calendar/agenda_js.php
  4. 13
      main/document/document.php
  5. 5
      main/document/edit_document.php
  6. 2
      main/document/upload.php
  7. 4
      main/dropbox/dropbox_functions.inc.php
  8. 4
      main/forum/editpost.php
  9. 3
      main/forum/forumfunction.inc.php
  10. 5
      main/forum/viewforum.php
  11. 6
      main/forum/viewthread.php
  12. 7
      main/forum/viewthread_flat.inc.php
  13. 12
      main/forum/viewthread_nested.inc.php
  14. 5
      main/forum/viewthread_threaded.inc.php
  15. 33
      main/group/group.php
  16. 2
      main/group/group_creation.php
  17. 20
      main/group/group_edit.php
  18. 16
      main/group/group_space.php
  19. 21
      main/group/member_settings.php
  20. 4
      main/group/settings.php
  21. 27
      main/group/tutor_settings.php
  22. 3
      main/inc/ajax/document.ajax.php
  23. 5
      main/inc/ajax/forum.ajax.php
  24. 9
      main/inc/lib/agenda.lib.php
  25. 21
      main/inc/lib/api.lib.php
  26. 8
      main/inc/lib/course.lib.php
  27. 2
      main/inc/lib/exercise.lib.php
  28. 322
      main/inc/lib/groupmanager.lib.php
  29. 5
      main/inc/lib/javascript/svgedit/extensions/imagelib/groups.php
  30. 2
      main/inc/lib/svg-edit/extensions/imagelib/groups.php
  31. 1
      main/inc/lib/userportal.lib.php
  32. 2
      main/wiki/index.php
  33. 31
      main/wiki/wiki.inc.php
  34. 4
      main/work/work.lib.php
  35. 20
      tests/main/inc/lib/groupmanager.lib.test.php

@ -416,7 +416,8 @@ switch ($action) {
if (!isset($announcement_to_modify)) { if (!isset($announcement_to_modify)) {
$announcement_to_modify = ''; $announcement_to_modify = '';
} }
$element = CourseManager::addGroupMultiSelect($form, $group_id, array());
$element = CourseManager::addGroupMultiSelect($form, $group_properties['iid'], array());
$form->setRequired($element); $form->setRequired($element);
$form->addElement( $form->addElement(
'checkbox', 'checkbox',

@ -30,6 +30,8 @@ if (empty($action)) {
} }
$group_id = api_get_group_id(); $group_id = api_get_group_id();
$groupInfo = GroupManager::get_group_properties($group_id);
$eventId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; $eventId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
$type = $event_type = isset($_GET['type']) ? $_GET['type'] : null; $type = $event_type = isset($_GET['type']) ? $_GET['type'] : null;
@ -109,7 +111,7 @@ if (api_is_allowed_to_edit(false, true) ||
!api_is_anonymous() && !api_is_anonymous() &&
api_is_allowed_to_session_edit(false, true)) || api_is_allowed_to_session_edit(false, true)) ||
GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR) && GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_CALENDAR) &&
GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid'])
) { ) {
switch ($action) { switch ($action) {
case 'add': case 'add':

@ -54,8 +54,8 @@ $session_id = api_get_session_id();
$group_id = api_get_group_id(); $group_id = api_get_group_id();
if (!empty($group_id)) { if (!empty($group_id)) {
$is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
$group_properties = GroupManager::get_group_properties($group_id); $group_properties = GroupManager::get_group_properties($group_id);
$is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties['iid']);
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
"url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(), "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
"name" => get_lang('Groups') "name" => get_lang('Groups')

@ -145,18 +145,19 @@ if (api_get_session_id() != 0) {
$group_member_with_upload_rights = $group_member_with_upload_rights && api_is_allowed_to_session_edit(false, true); $group_member_with_upload_rights = $group_member_with_upload_rights && api_is_allowed_to_session_edit(false, true);
} }
$groupMemberWithEditRights = $is_allowed_to_edit || GroupManager::is_tutor_of_group($userId, $groupId, $courseId); // Get group info
$group_properties = GroupManager::get_group_properties($groupId);
$groupMemberWithEditRights = $is_allowed_to_edit || GroupManager::is_tutor_of_group($userId, $group_properties['iid'], $courseId);
// Setting group variables. // Setting group variables.
if (!empty($groupId)) { if (!empty($groupId)) {
// Get group info
$group_properties = GroupManager::get_group_properties($groupId);
// Let's assume the user cannot upload files for the group // Let's assume the user cannot upload files for the group
$group_member_with_upload_rights = false; $group_member_with_upload_rights = false;
if ($group_properties['doc_state'] == 2) { if ($group_properties['doc_state'] == 2) {
// Documents are private // Documents are private
if ($is_allowed_to_edit || GroupManager::is_user_in_group($userId, $groupId)) { if ($is_allowed_to_edit || GroupManager::is_user_in_group($userId, $group_properties['iid'])) {
// Only courseadmin or group members (members + tutors) allowed // Only courseadmin or group members (members + tutors) allowed
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
@ -184,8 +185,8 @@ if (!empty($groupId)) {
// Allowed to upload? // Allowed to upload?
if ($is_allowed_to_edit || if ($is_allowed_to_edit ||
GroupManager::is_subscribed($userId, $groupId) || GroupManager::is_subscribed($userId, $group_properties['iid']) ||
GroupManager::is_tutor_of_group($userId, $groupId, $courseId) GroupManager::is_tutor_of_group($userId, $group_properties['iid'], $courseId)
) { ) {
// Only course admin or group members can upload // Only course admin or group members can upload
$group_member_with_upload_rights = true; $group_member_with_upload_rights = true;

@ -419,12 +419,13 @@ if (!empty($sessionId)) {
$owner_id = $document_info['insert_user_id']; $owner_id = $document_info['insert_user_id'];
$last_edit_date = $document_info['lastedit_date']; $last_edit_date = $document_info['lastedit_date'];
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
if ($owner_id == api_get_user_id() || if ($owner_id == api_get_user_id() ||
api_is_platform_admin() || api_is_platform_admin() ||
$is_allowed_to_edit || GroupManager:: is_user_in_group( $is_allowed_to_edit || GroupManager:: is_user_in_group(
api_get_user_id(), api_get_user_id(),
api_get_group_id() $groupInfo['iid']
) )
) { ) {
$action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq(); $action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq();
@ -581,7 +582,7 @@ function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc)
function show_return($document_id, $path, $call_from_tool='', $slide_id=0, $is_certificate_mode=false) function show_return($document_id, $path, $call_from_tool='', $slide_id=0, $is_certificate_mode=false)
{ {
$actionsLeft = null; $actionsLeft = null;
global $parent_id; global $parent_id;
$url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$parent_id; $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$parent_id;

@ -111,7 +111,7 @@ if (!empty($groupId)) {
$group_properties = GroupManager::get_group_properties($groupId); $group_properties = GroupManager::get_group_properties($groupId);
// Only courseadmin or group members allowed // Only courseadmin or group members allowed
if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), $groupId)) { if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), $group_properties['iid'])) {
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
'name' => get_lang('GroupSpace'), 'name' => get_lang('GroupSpace'),

@ -852,7 +852,6 @@ function store_add_dropbox($file = [])
// note: why can't this be valid? It is like sending a document to // note: why can't this be valid? It is like sending a document to
// yourself AND to a different person (I do this quite often with my e-mails) // yourself AND to a different person (I do this quite often with my e-mails)
if ($thisIsJustUpload && (count($_POST['recipients']) != 1)) { if ($thisIsJustUpload && (count($_POST['recipients']) != 1)) {
Display::addFlash(Display::return_message(get_lang('MailingJustUploadSelectNoOther'), 'warning')); Display::addFlash(Display::return_message(get_lang('MailingJustUploadSelectNoOther'), 'warning'));
return false; return false;
} }
@ -946,7 +945,8 @@ function store_add_dropbox($file = [])
if (strpos($rec, 'user_') === 0) { if (strpos($rec, 'user_') === 0) {
$new_work_recipients[] = substr($rec, strlen('user_')); $new_work_recipients[] = substr($rec, strlen('user_'));
} elseif (strpos($rec, 'group_') === 0) { } elseif (strpos($rec, 'group_') === 0) {
$userList = GroupManager::get_subscribed_users(substr($rec, strlen('group_'))); $groupInfo = GroupManager::get_group_properties(substr($rec, strlen('group_')));
$userList = GroupManager::get_subscribed_users($groupInfo['iid']);
foreach ($userList as $usr) { foreach ($userList as $usr) {
if (!in_array($usr['user_id'], $new_work_recipients) && $usr['user_id'] != $_user['user_id']) { if (!in_array($usr['user_id'], $new_work_recipients) && $usr['user_id'] != $_user['user_id']) {
$new_work_recipients[] = $usr['user_id']; $new_work_recipients[] = $usr['user_id'];

@ -72,9 +72,9 @@ if (!empty($gradebook) && $gradebook == 'view') {
); );
} }
$group_properties = GroupManager::get_group_properties(api_get_group_id());
if ($origin == 'group') { if ($origin == 'group') {
$_clean['toolgroup'] = api_get_group_id(); $_clean['toolgroup'] = api_get_group_id();
$group_properties = GroupManager::get_group_properties($_clean['toolgroup']);
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'), 'name' => get_lang('Groups'),
@ -173,7 +173,7 @@ $group_id = api_get_group_id();
if (!api_is_allowed_to_edit(null, true) && if (!api_is_allowed_to_edit(null, true) &&
$current_forum['allow_edit'] == 0 && $current_forum['allow_edit'] == 0 &&
!GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) !GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties['iid'])
) { ) {
$forum_allow = forum_not_allowed_here(); $forum_allow = forum_not_allowed_here();
if ($forum_allow === false) { if ($forum_allow === false) {

@ -1910,6 +1910,7 @@ function getPosts($forumInfo, $threadId, $orderDirection = 'ASC', $recursive = f
; ;
$groupId = api_get_group_id(); $groupId = api_get_group_id();
$groupInfo = GroupManager::get_group_properties($groupId);
$filterModerated = true; $filterModerated = true;
if (empty($groupId)) { if (empty($groupId)) {
@ -1917,7 +1918,7 @@ function getPosts($forumInfo, $threadId, $orderDirection = 'ASC', $recursive = f
$filterModerated = false; $filterModerated = false;
} }
} else { } else {
if (GroupManager::is_tutor_of_group(api_get_user_id(), $groupId)) { if (GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid'])) {
$filterModerated = false; $filterModerated = false;
} }
} }

@ -52,8 +52,9 @@ $userId = api_get_user_id();
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$groupId = api_get_group_id(); $groupId = api_get_group_id();
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
$groupInfo = GroupManager::get_group_properties($groupId);
$isTutor = GroupManager::is_tutor_of_group($userId, $groupId, $courseId); $isTutor = GroupManager::is_tutor_of_group($userId, $groupInfo['iid'], $courseId);
/* MAIN DISPLAY SECTION */ /* MAIN DISPLAY SECTION */
@ -82,7 +83,7 @@ if (!empty($groupId)) {
$group_properties = GroupManager::get_group_properties($groupId); $group_properties = GroupManager::get_group_properties($groupId);
//User has access in the group? //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); $is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties['iid']);
// Course // Course
if ( if (

@ -56,10 +56,10 @@ if (!empty($gradebook) && $gradebook == 'view') {
} }
$groupId = api_get_group_id(); $groupId = api_get_group_id();
$group_properties = GroupManager::get_group_properties($groupId);
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
if ($origin == 'group') { if ($origin == 'group') {
$group_properties = GroupManager::get_group_properties($groupId);
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(), 'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups') 'name' => get_lang('Groups')
@ -126,14 +126,14 @@ if (
isset($_GET['content']) && isset($_GET['content']) &&
isset($_GET['id']) && isset($_GET['id']) &&
(api_is_allowed_to_edit(false, true) || (api_is_allowed_to_edit(false, true) ||
GroupManager::is_tutor_of_group(api_get_user_id(), $groupId)) (isset($group_properties['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties['iid'])))
) { ) {
$message = delete_post($_GET['id']); $message = delete_post($_GET['id']);
} }
if (($my_action == 'invisible' || $my_action == 'visible') && if (($my_action == 'invisible' || $my_action == 'visible') &&
isset($_GET['id']) && isset($_GET['id']) &&
(api_is_allowed_to_edit(false, true) || (api_is_allowed_to_edit(false, true) ||
GroupManager::is_tutor_of_group(api_get_user_id(), $groupId)) (isset($group_properties['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $group_properties['iid'])))
) { ) {
$message = approve_post($_GET['id'], $_GET['action']); $message = approve_post($_GET['id'], $_GET['action']);
} }

@ -167,7 +167,8 @@ if (isset($current_thread['thread_id'])) {
// The user who posted it can edit his thread only if the course admin allowed // The user who posted it can edit his thread only if the course admin allowed
// this in the properties of the forum // this in the properties of the forum
// The course admin him/herself can do this off course always // The course admin him/herself can do this off course always
if (GroupManager::is_tutor_of_group($userId, $groupId) || $groupInfo = GroupManager::get_group_properties($groupId);
if ((isset($groupInfo['iid']) && GroupManager::is_tutor_of_group($userId, $groupInfo['iid'])) ||
($current_forum['allow_edit'] == 1 && $row['user_id'] == $_user['user_id']) || ($current_forum['allow_edit'] == 1 && $row['user_id'] == $_user['user_id']) ||
( (
api_is_allowed_to_edit(false, true) && api_is_allowed_to_edit(false, true) &&
@ -185,7 +186,7 @@ if (isset($current_thread['thread_id'])) {
} }
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
if (GroupManager::is_tutor_of_group($userId, $groupId) || if (GroupManager::is_tutor_of_group($userId, $groupInfo['iid']) ||
api_is_allowed_to_edit(false, true) && api_is_allowed_to_edit(false, true) &&
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId) !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
) { ) {
@ -211,7 +212,7 @@ if (isset($current_thread['thread_id'])) {
} }
if ( if (
GroupManager::is_tutor_of_group($userId, $groupId) || GroupManager::is_tutor_of_group($userId, $groupInfo['iid']) ||
(api_is_allowed_to_edit(false, true) && (api_is_allowed_to_edit(false, true) &&
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId) !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
) )

@ -34,7 +34,7 @@ $locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREA
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$currentThread = get_thread_information($_GET['thread']); $currentThread = get_thread_information($_GET['thread']);
$userId = api_get_user_id(); $userId = api_get_user_id();
$groupInfo = GroupManager::get_group_properties($group_id);
$postCount = 1; $postCount = 1;
foreach ($rows as $post) { foreach ($rows as $post) {
@ -48,11 +48,7 @@ foreach ($rows as $post) {
$messageclass = 'forum_message_post_text'; $messageclass = 'forum_message_post_text';
$leftclass = 'forum_message_left'; $leftclass = 'forum_message_left';
} }
/*
echo '<pre>';
print_r($post);
echo '</pre>';
*/
$indent = $post['indent_cnt']; $indent = $post['indent_cnt'];
$html = ''; $html = '';
@ -119,7 +115,7 @@ foreach ($rows as $post) {
// The course admin him/herself can do this off course always // The course admin him/herself can do this off course always
if ( if (
GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) || (isset($groupInfo['iid']) &&GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid'])) ||
($current_forum['allow_edit'] == 1 && $post['user_id'] == $userId) || ($current_forum['allow_edit'] == 1 && $post['user_id'] == $userId) ||
(api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)) (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && $current_forum['session_id'] != $sessionId))
) { ) {
@ -133,7 +129,7 @@ foreach ($rows as $post) {
} }
if ( if (
GroupManager::is_tutor_of_group(api_get_user_id(), $group_id) || (isset($groupInfo['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid'])) ||
api_is_allowed_to_edit(false, true) && api_is_allowed_to_edit(false, true) &&
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId) !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
) { ) {

@ -233,11 +233,12 @@ echo api_convert_and_format_date(
// Get attach id // Get attach id
$attachment_list = get_attachment($display_post_id); $attachment_list = get_attachment($display_post_id);
$id_attach = !empty($attachment_list) ? $attachment_list['id'] : ''; $id_attach = !empty($attachment_list) ? $attachment_list['id'] : '';
$groupInfo = GroupManager::get_group_properties($groupId);
// The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
// The course admin him/herself can do this off course always // The course admin him/herself can do this off course always
if ( if (
GroupManager::is_tutor_of_group(api_get_user_id(), $groupId) || ( (isset($groupInfo['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid'])) || (
$current_forum['allow_edit'] == 1 && $current_forum['allow_edit'] == 1 &&
$row['user_id'] == $_user['user_id'] $row['user_id'] == $_user['user_id']
) || ( ) || (
@ -277,7 +278,7 @@ if (!empty($my_post) && is_array($my_post)) {
} }
if ( if (
GroupManager::is_tutor_of_group(api_get_user_id(), $groupId) || (isset($groupInfo['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid'])) ||
api_is_allowed_to_edit(false, true) && api_is_allowed_to_edit(false, true) &&
!(api_is_course_coach() && $current_forum['session_id'] != $sessionId) !(api_is_course_coach() && $current_forum['session_id'] != $sessionId)
) { ) {

@ -51,6 +51,8 @@ $my_get_id = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
$currentUrl = api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(); $currentUrl = api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq();
$groupInfo = GroupManager::get_group_properties($my_group_id);
if (isset($_GET['action']) && $is_allowed_in_course) { if (isset($_GET['action']) && $is_allowed_in_course) {
switch ($_GET['action']) { switch ($_GET['action']) {
case 'set_visible': case 'set_visible':
@ -70,16 +72,16 @@ if (isset($_GET['action']) && $is_allowed_in_course) {
} }
break; break;
case 'self_reg': case 'self_reg':
if (GroupManager::is_self_registration_allowed($userId, $my_group_id)) { if (GroupManager::is_self_registration_allowed($userId, $groupInfo['iid'])) {
GroupManager::subscribe_users($userId, $my_group_id); GroupManager::subscribe_users($userId, $groupInfo['iid']);
Display::addFlash(Display::return_message(get_lang('GroupNowMember'))); Display::addFlash(Display::return_message(get_lang('GroupNowMember')));
header("Location: $currentUrl"); header("Location: $currentUrl");
exit; exit;
} }
break; break;
case 'self_unreg': case 'self_unreg':
if (GroupManager::is_self_unregistration_allowed($userId, $my_group_id)) { if (GroupManager::is_self_unregistration_allowed($userId, $groupInfo['iid'])) {
GroupManager::unsubscribe_users($userId, $my_group_id); GroupManager::unsubscribe_users($userId, $groupInfo['iid']);
Display::addFlash(Display::return_message(get_lang('StudentDeletesHimself'))); Display::addFlash(Display::return_message(get_lang('StudentDeletesHimself')));
header("Location: $currentUrl"); header("Location: $currentUrl");
@ -99,7 +101,11 @@ if (api_is_allowed_to_edit(false, true)) {
switch ($_POST['action']) { switch ($_POST['action']) {
case 'delete_selected': case 'delete_selected':
if (is_array($_POST['group'])) { if (is_array($_POST['group'])) {
GroupManager::delete_groups($my_group); foreach ($_POST['group'] as $myGroupId) {
$groupInfo = GroupManager::get_group_properties($myGroupId);
GroupManager::delete_groups($groupInfo['iid']);
}
Display::addFlash(Display::return_message(get_lang('SelectedGroupsDeleted'))); Display::addFlash(Display::return_message(get_lang('SelectedGroupsDeleted')));
header("Location: $currentUrl"); header("Location: $currentUrl");
exit; exit;
@ -107,7 +113,11 @@ if (api_is_allowed_to_edit(false, true)) {
break; break;
case 'empty_selected': case 'empty_selected':
if (is_array($_POST['group'])) { if (is_array($_POST['group'])) {
GroupManager :: unsubscribe_all_users($my_group); foreach ($_POST['group'] as $myGroupId) {
$groupInfo = GroupManager::get_group_properties($myGroupId);
GroupManager :: unsubscribe_all_users($groupInfo['iid']);
}
Display::addFlash(Display::return_message(get_lang('SelectedGroupsEmptied'))); Display::addFlash(Display::return_message(get_lang('SelectedGroupsEmptied')));
header("Location: $currentUrl"); header("Location: $currentUrl");
exit; exit;
@ -115,7 +125,10 @@ if (api_is_allowed_to_edit(false, true)) {
break; break;
case 'fill_selected': case 'fill_selected':
if (is_array($_POST['group'])) { if (is_array($_POST['group'])) {
GroupManager :: fill_groups($my_group); foreach ($_POST['group'] as $myGroupId) {
$groupInfo = GroupManager::get_group_properties($myGroupId);
GroupManager:: fill_groups($groupInfo['iid']);
}
Display::addFlash(Display::return_message(get_lang('SelectedGroupsFilled'))); Display::addFlash(Display::return_message(get_lang('SelectedGroupsFilled')));
header("Location: $currentUrl"); header("Location: $currentUrl");
exit; exit;
@ -134,13 +147,15 @@ if (api_is_allowed_to_edit(false, true)) {
exit; exit;
break; break;
case 'delete_one': case 'delete_one':
GroupManager :: delete_groups($my_get_id); $groupInfo = GroupManager::get_group_properties($my_get_id);
GroupManager :: delete_groups($groupInfo['iid']);
Display::addFlash(Display::return_message(get_lang('GroupDel'))); Display::addFlash(Display::return_message(get_lang('GroupDel')));
header("Location: $currentUrl"); header("Location: $currentUrl");
exit; exit;
break; break;
case 'fill_one': case 'fill_one':
GroupManager :: fill_groups($my_get_id); $groupInfo = GroupManager::get_group_properties($my_get_id);
GroupManager :: fill_groups($groupInfo['iid']);
Display::addFlash(Display::return_message(get_lang('GroupFilledGroups'))); Display::addFlash(Display::return_message(get_lang('GroupFilledGroups')));
header("Location: $currentUrl"); header("Location: $currentUrl");
exit; exit;

@ -246,7 +246,7 @@ EOT;
$base_group_options = array (); $base_group_options = array ();
$groups = GroupManager :: get_group_list(); $groups = GroupManager :: get_group_list();
foreach ($groups as $index => $group) { foreach ($groups as $index => $group) {
$number_of_students = GroupManager :: number_of_students($group['id']); $number_of_students = GroupManager :: number_of_students($group['iid']);
if ($number_of_students > 0) { if ($number_of_students > 0) {
$base_group_options[$group['id']] = $group['name'].' ('.$number_of_students.' '.get_lang('Users').')'; $base_group_options[$group['id']] = $group['name'].' ('.$number_of_students.' '.get_lang('Users').')';
} }

@ -25,7 +25,7 @@ $nameTools = get_lang('EditGroup');
$interbreadcrumb[] = array ('url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')); $interbreadcrumb[] = array ('url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups'));
$interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']); $interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']);
$is_group_member = GroupManager :: is_tutor_of_group(api_get_user_id(), $group_id); $is_group_member = GroupManager :: is_tutor_of_group(api_get_user_id(), $current_group['iid']);
if (!api_is_allowed_to_edit(false, true) && !$is_group_member) { if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
api_not_allowed(true); api_not_allowed(true);
@ -132,7 +132,7 @@ $form->addText('name', get_lang('GroupName'));
// Description // Description
$form->addElement('textarea', 'description', get_lang('Description'), array ('rows' => 6)); $form->addElement('textarea', 'description', get_lang('Description'), array ('rows' => 6));
$complete_user_list = GroupManager :: fill_groups_list($current_group['id']); $complete_user_list = GroupManager :: fill_groups_list($current_group['iid']);
usort($complete_user_list, 'sort_users'); usort($complete_user_list, 'sort_users');
$possible_users = array(); $possible_users = array();
@ -141,7 +141,7 @@ foreach ($complete_user_list as $index => $user) {
} }
// Group tutors // Group tutors
$group_tutor_list = GroupManager :: get_subscribed_tutors($current_group['id']); $group_tutor_list = GroupManager :: get_subscribed_tutors($current_group['iid']);
$selected_users = array(); $selected_users = array();
$selected_tutors = array(); $selected_tutors = array();
foreach ($group_tutor_list as $index => $user) { foreach ($group_tutor_list as $index => $user) {
@ -157,7 +157,7 @@ $group_tutors_element = $form->addElement(
); );
// Group members // Group members
$group_member_list = GroupManager :: get_subscribed_users($current_group['id']); $group_member_list = GroupManager :: get_subscribed_users($current_group['iid']);
$selected_users = array (); $selected_users = array ();
foreach ($group_member_list as $index => $user) { foreach ($group_member_list as $index => $user) {
@ -326,19 +326,19 @@ if ($form->validate()) {
); );
// Storing the tutors (we first remove all the tutors and then add only those who were selected) // Storing the tutors (we first remove all the tutors and then add only those who were selected)
GroupManager :: unsubscribe_all_tutors($current_group['id']); GroupManager :: unsubscribe_all_tutors($current_group['iid']);
if (isset ($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) { if (isset($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
GroupManager :: subscribe_tutors($values['group_tutors'], $current_group['id']); GroupManager :: subscribe_tutors($values['group_tutors'], $current_group['iid']);
} }
// Storing the users (we first remove all users and then add only those who were selected) // Storing the users (we first remove all users and then add only those who were selected)
GroupManager :: unsubscribe_all_users($current_group['id']); GroupManager :: unsubscribe_all_users($current_group['iid']);
if (isset ($_POST['group_members']) && count($_POST['group_members']) > 0) { if (isset ($_POST['group_members']) && count($_POST['group_members']) > 0) {
GroupManager :: subscribe_users($values['group_members'], $current_group['id']); GroupManager :: subscribe_users($values['group_members'], $current_group['iid']);
} }
// Returning to the group area (note: this is inconsistent with the rest of chamilo) // Returning to the group area (note: this is inconsistent with the rest of chamilo)
$cat = GroupManager :: get_category_from_group($current_group['id']); $cat = GroupManager :: get_category_from_group($current_group['iid']);
if (isset($_POST['group_members']) && if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member && count($_POST['group_members']) > $max_member &&
$max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT

@ -50,7 +50,7 @@ Display::display_introduction_section(TOOL_GROUP);
* User wants to register in this group * User wants to register in this group
*/ */
if (!empty($_GET['selfReg']) && if (!empty($_GET['selfReg']) &&
GroupManager :: is_self_registration_allowed($user_id, $current_group['id']) GroupManager :: is_self_registration_allowed($user_id, $current_group['iid'])
) { ) {
GroupManager :: subscribe_users($user_id, $current_group['id']); GroupManager :: subscribe_users($user_id, $current_group['id']);
Display :: display_normal_message(get_lang('GroupNowMember')); Display :: display_normal_message(get_lang('GroupNowMember'));
@ -60,9 +60,9 @@ if (!empty($_GET['selfReg']) &&
* User wants to unregister from this group * User wants to unregister from this group
*/ */
if (!empty($_GET['selfUnReg']) && if (!empty($_GET['selfUnReg']) &&
GroupManager :: is_self_unregistration_allowed($user_id, $current_group['id']) GroupManager :: is_self_unregistration_allowed($user_id, $current_group['iid'])
) { ) {
GroupManager :: unsubscribe_users($user_id, $current_group['id']); GroupManager :: unsubscribe_users($user_id, $current_group['iid']);
Display::display_normal_message(get_lang('StudentDeletesHimself')); Display::display_normal_message(get_lang('StudentDeletesHimself'));
} }
@ -75,7 +75,7 @@ echo '<a href="group.php">'.
* Register to group * Register to group
*/ */
$subscribe_group = ''; $subscribe_group = '';
if (GroupManager :: is_self_registration_allowed($user_id, $current_group['id'])) { if (GroupManager :: is_self_registration_allowed($user_id, $current_group['iid'])) {
$subscribe_group = '<a class="btn btn-default" href="'.api_get_self().'?selfReg=1&group_id='.$current_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'. $subscribe_group = '<a class="btn btn-default" href="'.api_get_self().'?selfReg=1&group_id='.$current_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.
get_lang("RegIntoGroup").'</a>'; get_lang("RegIntoGroup").'</a>';
} }
@ -84,7 +84,7 @@ if (GroupManager :: is_self_registration_allowed($user_id, $current_group['id'])
* Unregister from group * Unregister from group
*/ */
$unsubscribe_group = ''; $unsubscribe_group = '';
if (GroupManager :: is_self_unregistration_allowed($user_id, $current_group['id'])) { if (GroupManager :: is_self_unregistration_allowed($user_id, $current_group['iid'])) {
$unsubscribe_group = '<a class="btn btn-default" href="'.api_get_self().'?selfUnReg=1" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."'".')) return false;">'. $unsubscribe_group = '<a class="btn btn-default" href="'.api_get_self().'?selfUnReg=1" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."'".')) return false;">'.
get_lang("StudentUnsubscribe").'</a>'; get_lang("StudentUnsubscribe").'</a>';
} }
@ -94,7 +94,7 @@ echo '&nbsp;</div>';
$edit_url = ''; $edit_url = '';
if (api_is_allowed_to_edit(false, true) || if (api_is_allowed_to_edit(false, true) ||
GroupManager::is_tutor_of_group(api_get_user_id(), api_get_group_id()) GroupManager::is_tutor_of_group(api_get_user_id(), $current_group['iid'])
) { ) {
$edit_url = '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?'.api_get_cidreq().'">'. $edit_url = '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?'.api_get_cidreq().'">'.
Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>'; Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
@ -113,7 +113,7 @@ if (!empty($current_group['description'])) {
*/ */
// If the user is subscribed to the group or the user is a tutor of the group then // If the user is subscribed to the group or the user is a tutor of the group then
if (api_is_allowed_to_edit(false, true) || if (api_is_allowed_to_edit(false, true) ||
GroupManager::is_user_in_group(api_get_user_id(), $current_group['id']) GroupManager::is_user_in_group(api_get_user_id(), $current_group['iid'])
) { ) {
$actions_array = array(); $actions_array = array();
// Link to the forum of this group // Link to the forum of this group
@ -301,7 +301,7 @@ if (api_is_allowed_to_edit(false, true) ||
/* /*
* List all the tutors of the current group * List all the tutors of the current group
*/ */
$tutors = GroupManager::get_subscribed_tutors($current_group['id']); $tutors = GroupManager::get_subscribed_tutors($current_group['iid']);
$tutor_info = ''; $tutor_info = '';
if (count($tutors) == 0) { if (count($tutors) == 0) {

@ -25,7 +25,7 @@ $nameTools = get_lang('EditGroup');
$interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups')); $interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups'));
$interbreadcrumb[] = array('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']); $interbreadcrumb[] = array('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']);
$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id); $is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group['iid']);
if (!api_is_allowed_to_edit(false, true) && !$is_group_member) { if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
api_not_allowed(true); api_not_allowed(true);
@ -127,7 +127,13 @@ $(document).ready( function() {
$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq()); $form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
$form->addElement('hidden', 'action'); $form->addElement('hidden', 'action');
$form->addElement('hidden', 'max_student', $current_group['max_student']); $form->addElement('hidden', 'max_student', $current_group['max_student']);
$complete_user_list = GroupManager::fill_groups_list($current_group['id']); $complete_user_list = GroupManager::fill_groups_list($current_group['iid']);
$subscribedTutors = GroupManager::getTutors($current_group['iid']);
if ($subscribedTutors) {
$subscribedTutors = array_column($subscribedTutors, 'user_id');
}
$orderUserListByOfficialCode = api_get_setting('order_user_list_by_official_code'); $orderUserListByOfficialCode = api_get_setting('order_user_list_by_official_code');
$possible_users = array(); $possible_users = array();
@ -136,6 +142,9 @@ $userGroup = new UserGroup();
if (!empty($complete_user_list)) { if (!empty($complete_user_list)) {
usort($complete_user_list, 'sort_users'); usort($complete_user_list, 'sort_users');
foreach ($complete_user_list as $index => $user) { foreach ($complete_user_list as $index => $user) {
if (in_array($user['user_id'], $subscribedTutors)) {
continue;
}
//prevent invitee users add to groups or tutors - see #8091 //prevent invitee users add to groups or tutors - see #8091
if ($user['status'] != INVITEE) { if ($user['status'] != INVITEE) {
$officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null; $officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null;
@ -160,7 +169,7 @@ if (!empty($complete_user_list)) {
} }
// Group members // Group members
$group_member_list = GroupManager::get_subscribed_users($current_group['id']); $group_member_list = GroupManager::get_subscribed_users($current_group['iid']);
$selected_users = array (); $selected_users = array ();
if (!empty($group_member_list)) { if (!empty($group_member_list)) {
@ -185,7 +194,7 @@ if ($form->validate()) {
$values = $form->exportValues(); $values = $form->exportValues();
// Storing the users (we first remove all users and then add only those who were selected) // Storing the users (we first remove all users and then add only those who were selected)
GroupManager:: unsubscribe_all_users($current_group['id']); GroupManager:: unsubscribe_all_users($current_group['iid']);
if (isset ($_POST['group_members']) && count($_POST['group_members']) > 0) { if (isset ($_POST['group_members']) && count($_POST['group_members']) > 0) {
GroupManager:: subscribe_users( GroupManager:: subscribe_users(
$values['group_members'], $values['group_members'],
@ -194,7 +203,7 @@ if ($form->validate()) {
} }
// Returning to the group area (note: this is inconsistent with the rest of chamilo) // Returning to the group area (note: this is inconsistent with the rest of chamilo)
$cat = GroupManager :: get_category_from_group($current_group['id']); $cat = GroupManager :: get_category_from_group($current_group['iid']);
if (isset($_POST['group_members']) && if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member && count($_POST['group_members']) > $max_member &&
$max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
@ -212,7 +221,7 @@ $action = isset($_GET['action']) ? $_GET['action'] : null;
switch ($action) { switch ($action) {
case 'empty': case 'empty':
if (api_is_allowed_to_edit(false, true)) { if (api_is_allowed_to_edit(false, true)) {
GroupManager:: unsubscribe_all_users($group_id); GroupManager:: unsubscribe_all_users($current_group['iid']);
Display :: display_confirmation_message(get_lang('GroupEmptied')); Display :: display_confirmation_message(get_lang('GroupEmptied'));
} }
break; break;

@ -23,7 +23,7 @@ $current_group = GroupManager::get_group_properties($group_id);
$nameTools = get_lang('EditGroup'); $nameTools = get_lang('EditGroup');
$interbreadcrumb[] = array('url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')); $interbreadcrumb[] = array('url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups'));
$interbreadcrumb[] = array('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']); $interbreadcrumb[] = array('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']);
$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id); $is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group['iid']);
if (!api_is_allowed_to_edit(false, true) && !$is_group_member) { if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
api_not_allowed(true); api_not_allowed(true);
@ -235,7 +235,7 @@ if ($form->validate()) {
} }
$defaults = $current_group; $defaults = $current_group;
$category = GroupManager::get_category_from_group($group_id); $category = GroupManager::get_category_from_group($current_group['iid']);
if (!empty($category)) { if (!empty($category)) {
$defaults['category_id'] = $category['id']; $defaults['category_id'] = $category['id'];
} }

@ -25,7 +25,7 @@ $nameTools = get_lang('EditGroup');
$interbreadcrumb[] = array ('url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')); $interbreadcrumb[] = array ('url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups'));
$interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']); $interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']);
$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id); $is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group['iid']);
if (!api_is_allowed_to_edit(false, true) && !$is_group_member) { if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
api_not_allowed(true); api_not_allowed(true);
@ -110,20 +110,31 @@ $form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidre
$form->addElement('hidden', 'action'); $form->addElement('hidden', 'action');
// Group tutors // Group tutors
$group_tutor_list = GroupManager :: get_subscribed_tutors($current_group['id']); $group_tutor_list = GroupManager :: get_subscribed_tutors($current_group['iid']);
$selected_tutors = array(); $selected_tutors = array();
foreach ($group_tutor_list as $index => $user) { foreach ($group_tutor_list as $index => $user) {
$selected_tutors[] = $user['user_id']; $selected_tutors[] = $user['user_id'];
} }
$complete_user_list = GroupManager :: fill_groups_list($current_group['id']); $complete_user_list = GroupManager::fill_groups_list($current_group['iid']);
$possible_users = array(); $possible_users = array();
$userGroup = new UserGroup(); $userGroup = new UserGroup();
$subscribedUsers = GroupManager::get_subscribed_users($current_group['iid']);
if ($subscribedUsers) {
$subscribedUsers = array_column($subscribedUsers, 'user_id');
}
$orderUserListByOfficialCode = api_get_setting('order_user_list_by_official_code'); $orderUserListByOfficialCode = api_get_setting('order_user_list_by_official_code');
if (!empty($complete_user_list)) { if (!empty($complete_user_list)) {
usort($complete_user_list, 'sort_users'); usort($complete_user_list, 'sort_users');
foreach ($complete_user_list as $index => $user) { foreach ($complete_user_list as $index => $user) {
if (in_array($user['user_id'], $subscribedUsers)) {
continue;
}
//prevent invitee users add to groups or tutors - see #8091 //prevent invitee users add to groups or tutors - see #8091
if ($user['status'] != INVITEE) { if ($user['status'] != INVITEE) {
$officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null; $officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null;
@ -147,6 +158,7 @@ if (!empty($complete_user_list)) {
$user['lastname'] $user['lastname']
).' ('.$user['username'].')'; ).' ('.$user['username'].')';
} }
$possible_users[$user['user_id']] = $name.$groupNameListToString; $possible_users[$user['user_id']] = $name.$groupNameListToString;
} }
} }
@ -167,13 +179,14 @@ if ($form->validate()) {
$values = $form->exportValues(); $values = $form->exportValues();
// Storing the tutors (we first remove all the tutors and then add only those who were selected) // Storing the tutors (we first remove all the tutors and then add only those who were selected)
GroupManager :: unsubscribe_all_tutors($current_group['id']); GroupManager :: unsubscribe_all_tutors($current_group['iid']);
if (isset ($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) { if (isset($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
GroupManager :: subscribe_tutors($values['group_tutors'], $current_group['id']); GroupManager::subscribe_tutors($values['group_tutors'], $current_group['iid']);
} }
// Returning to the group area (note: this is inconsistent with the rest of chamilo) // Returning to the group area (note: this is inconsistent with the rest of chamilo)
$cat = GroupManager::get_category_from_group($current_group['id']); $cat = GroupManager::get_category_from_group($current_group['iid']);
if (isset($_POST['group_members']) && if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member && count($_POST['group_members']) > $max_member &&
$max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT

@ -14,8 +14,9 @@ switch ($action) {
$is_allowed_to_edit = api_is_allowed_to_edit(null, true); $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
// This needs cleaning! // This needs cleaning!
if (api_get_group_id()) { if (api_get_group_id()) {
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
// Only course admin or group members allowed // Only course admin or group members allowed
if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id())) { if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo['iid'])) {
} else { } else {
exit; exit;
} }

@ -129,9 +129,10 @@ if (!empty($action)) {
break; break;
} }
$group_id = api_get_group_id(); $group_id = api_get_group_id();
if (!api_is_allowed_to_edit(null, true) AND $groupInfo = GroupManager::get_group_properties($group_id);
if (!api_is_allowed_to_edit(null, true) &&
$current_forum['allow_edit'] == 0 && $current_forum['allow_edit'] == 0 &&
($group_id && !GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)) ($group_id && !GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid']))
) { ) {
$json['errorMessage'] = '4. if editing of replies is not allowed'; $json['errorMessage'] = '4. if editing of replies is not allowed';
break; break;

@ -2571,6 +2571,7 @@ class Agenda
public function displayActions($view, $filter = 0) public function displayActions($view, $filter = 0)
{ {
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
$actionsLeft = ''; $actionsLeft = '';
$actionsLeft .= "<a href='".api_get_path(WEB_CODE_PATH)."calendar/agenda_js.php?type={$this->type}'>". $actionsLeft .= "<a href='".api_get_path(WEB_CODE_PATH)."calendar/agenda_js.php?type={$this->type}'>".
@ -2588,8 +2589,8 @@ class Agenda
if (api_is_allowed_to_edit(false, true) || if (api_is_allowed_to_edit(false, true) ||
(api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false, true) ||
GroupManager::user_has_access(api_get_user_id(), api_get_group_id(), GroupManager::GROUP_TOOL_CALENDAR) && (GroupManager::user_has_access(api_get_user_id(), api_get_group_id(), GroupManager::GROUP_TOOL_CALENDAR) &&
GroupManager::is_tutor_of_group(api_get_user_id(), api_get_group_id()) isset($groupInfo['iid']) && GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo['iid']))
) { ) {
$actionsLeft .= Display::url( $actionsLeft .= Display::url(
Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM), Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM),
@ -2601,10 +2602,8 @@ class Agenda
api_get_path(WEB_CODE_PATH)."calendar/agenda.php?".api_get_cidreq()."&action=importical&type=".$this->type api_get_path(WEB_CODE_PATH)."calendar/agenda.php?".api_get_cidreq()."&action=importical&type=".$this->type
); );
if ($this->type == 'course') { if ($this->type === 'course') {
if (!isset($_GET['action'])) { if (!isset($_GET['action'])) {
$form = new FormValidator( $form = new FormValidator(
'form-search', 'form-search',
'post', 'post',

@ -2111,7 +2111,6 @@ function api_get_session_visibility(
// I don't care the session visibility. // I don't care the session visibility.
if (empty($row['access_start_date']) && empty($row['access_end_date'])) { if (empty($row['access_start_date']) && empty($row['access_end_date'])) {
// Session duration per student. // Session duration per student.
if (isset($row['duration']) && !empty($row['duration'])) { if (isset($row['duration']) && !empty($row['duration'])) {
$duration = $row['duration'] * 24 * 60 * 60; $duration = $row['duration'] * 24 * 60 * 60;
@ -2154,7 +2153,6 @@ function api_get_session_visibility(
return SESSION_AVAILABLE; return SESSION_AVAILABLE;
} else { } else {
// If start date was set. // If start date was set.
if (!empty($row['access_start_date'])) { if (!empty($row['access_start_date'])) {
if ($now > api_strtotime($row['access_start_date'], 'UTC')) { if ($now > api_strtotime($row['access_start_date'], 'UTC')) {
@ -2167,7 +2165,7 @@ function api_get_session_visibility(
// If the end date was set. // If the end date was set.
if (!empty($row['access_end_date'])) { if (!empty($row['access_end_date'])) {
// Only if date_start said that it was ok // Only if date_start said that it was ok
if ($visibility == SESSION_AVAILABLE) { if ($visibility === SESSION_AVAILABLE) {
if ($now < api_strtotime($row['access_end_date'], 'UTC')) { if ($now < api_strtotime($row['access_end_date'], 'UTC')) {
// Date still available // Date still available
$visibility = SESSION_AVAILABLE; $visibility = SESSION_AVAILABLE;
@ -2181,9 +2179,9 @@ function api_get_session_visibility(
/* If I'm a coach the visibility can change in my favor depending in /* If I'm a coach the visibility can change in my favor depending in
the coach dates */ the coach dates */
$is_coach = api_is_coach($session_id, $courseId); $isCoach = api_is_coach($session_id, $courseId);
if ($is_coach) { if ($isCoach) {
// Test end date. // Test end date.
if (!empty($row['coach_access_end_date'])) { if (!empty($row['coach_access_end_date'])) {
$endDateCoach = api_strtotime($row['coach_access_end_date'], 'UTC'); $endDateCoach = api_strtotime($row['coach_access_end_date'], 'UTC');
@ -2209,7 +2207,6 @@ function api_get_session_visibility(
$visibility = SESSION_INVISIBLE; $visibility = SESSION_INVISIBLE;
} }
} }
return $visibility; return $visibility;
} }
@ -2498,10 +2495,11 @@ function api_get_user_platform_status($user_id = null) {
//Group (in course) //Group (in course)
if ($group_id && $course_id) { if ($group_id && $course_id) {
$group_status = array(); $group_status = array();
$is_subscribed = GroupManager::is_subscribed($user_id, $group_id); $groupInfo = GroupManager::get_group_properties($group_id);
$is_subscribed = GroupManager::is_subscribed($user_id, $groupInfo['iid']);
if ($is_subscribed) { if ($is_subscribed) {
$group_status = array('id'=> $group_id , 'status' => 'student'); $group_status = array('id'=> $group_id , 'status' => 'student');
$is_tutor = GroupManager::is_tutor_of_group($user_id, $group_id); $is_tutor = GroupManager::is_tutor_of_group($user_id, $groupInfo['iid']);
if ($is_tutor) { if ($is_tutor) {
$group_status['status'] = 'tutor'; $group_status['status'] = 'tutor';
} else { } else {
@ -5578,7 +5576,7 @@ function api_is_course_visible_for_user($userid = null, $cid = null) {
*/ */
function api_is_element_in_the_session($tool, $element_id, $session_id = null) { function api_is_element_in_the_session($tool, $element_id, $session_id = null) {
if (is_null($session_id)) { if (is_null($session_id)) {
$session_id = intval($_SESSION['id_session']); $session_id = api_get_session_id();
} }
// Get information to build query depending of the tool. // Get information to build query depending of the tool.
@ -5604,7 +5602,8 @@ function api_is_element_in_the_session($tool, $element_id, $session_id = null) {
} }
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = "SELECT session_id FROM $table_tool WHERE c_id = $course_id AND $key_field = ".intval($element_id); $sql = "SELECT session_id FROM $table_tool
WHERE c_id = $course_id AND $key_field = ".intval($element_id);
$rs = Database::query($sql); $rs = Database::query($sql);
if ($element_session_id = Database::result($rs, 0, 0)) { if ($element_session_id = Database::result($rs, 0, 0)) {
if ($element_session_id == intval($session_id)) { if ($element_session_id == intval($session_id)) {
@ -8040,7 +8039,7 @@ function api_is_student_view_active() {
} }
/** /**
* Adds a file inside the upload/$type/id * Adds a file inside the upload/$type/id
* *
* @param string $type * @param string $type
* @param array $file * @param array $file

@ -2146,7 +2146,7 @@ class CourseManager
if ($in_get_empty_group == 0) { if ($in_get_empty_group == 0) {
// get only groups that are not empty // get only groups that are not empty
$sql = "SELECT DISTINCT g.id, g.name $sql = "SELECT DISTINCT g.id, g.iid, g.name
FROM " . Database::get_course_table(TABLE_GROUP) . " AS g FROM " . Database::get_course_table(TABLE_GROUP) . " AS g
INNER JOIN " . Database::get_course_table(TABLE_GROUP_USER) . " gu INNER JOIN " . Database::get_course_table(TABLE_GROUP_USER) . " gu
ON (g.id = gu.group_id AND g.c_id = $course_id AND gu.c_id = $course_id) ON (g.id = gu.group_id AND g.c_id = $course_id AND gu.c_id = $course_id)
@ -2154,7 +2154,7 @@ class CourseManager
ORDER BY g.name"; ORDER BY g.name";
} else { } else {
// get all groups even if they are empty // get all groups even if they are empty
$sql = "SELECT g.id, g.name $sql = "SELECT g.id, g.name, g.iid
FROM " . Database::get_course_table(TABLE_GROUP) . " AS g FROM " . Database::get_course_table(TABLE_GROUP) . " AS g
$session_condition $session_condition
AND c_id = $course_id"; AND c_id = $course_id";
@ -2162,7 +2162,7 @@ class CourseManager
$result = Database::query($sql); $result = Database::query($sql);
while ($group_data = Database::fetch_array($result)) { while ($group_data = Database::fetch_array($result)) {
$group_data['userNb'] = GroupManager::number_of_students($group_data['id'], $course_id); $group_data['userNb'] = GroupManager::number_of_students($group_data['iid'], $course_id);
$group_list[$group_data['id']] = $group_data; $group_list[$group_data['id']] = $group_data;
} }
return $group_list; return $group_list;
@ -5640,7 +5640,7 @@ class CourseManager
/** /**
* Shows the form for sending a message to a specific group or user. * Shows the form for sending a message to a specific group or user.
* @param FormValidator $form * @param FormValidator $form
* @param int $group_id * @param int $group_id iid
* @param array $to * @param array $to
*/ */
public static function addGroupMultiSelect($form, $group_id, $to = array()) public static function addGroupMultiSelect($form, $group_id, $to = array())

@ -3442,7 +3442,7 @@ HOTSPOT;
$currentCatId = 0; $currentCatId = 0;
for ($i = 0; $i < count($tabGroups); $i++) { for ($i = 0; $i < count($tabGroups); $i++) {
$tabCategory = GroupManager::get_category_from_group( $tabCategory = GroupManager::get_category_from_group(
$tabGroups[$i]["id"] $tabGroups[$i]['iid']
); );
if ($tabCategory["id"] != $currentCatId) { if ($tabCategory["id"] != $currentCatId) {
$res .= "<option value='-1' disabled='disabled'>" . $tabCategory["title"] . "</option>"; $res .= "<option value='-1' disabled='disabled'>" . $tabCategory["title"] . "</option>";

@ -86,7 +86,9 @@ class GroupManager
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
$table_group = Database :: get_course_table(TABLE_GROUP); $table_group = Database :: get_course_table(TABLE_GROUP);
$sql = "SELECT g.id, $sql = "SELECT
g.id,
g.iid,
g.name, g.name,
g.description, g.description,
g.category_id, g.category_id,
@ -124,7 +126,7 @@ class GroupManager
$groups = array(); $groups = array();
while ($thisGroup = Database::fetch_array($groupList)) { while ($thisGroup = Database::fetch_array($groupList)) {
$thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['id'])); $thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['iid']));
if ($thisGroup['session_id'] != 0) { if ($thisGroup['session_id'] != 0) {
$sql = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' $sql = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).'
WHERE id='.$thisGroup['session_id']; WHERE id='.$thisGroup['session_id'];
@ -153,7 +155,6 @@ class GroupManager
$course_id = $_course['real_id']; $course_id = $_course['real_id'];
$currentCourseRepository = $_course['path']; $currentCourseRepository = $_course['path'];
$category = self :: get_category($category_id); $category = self :: get_category($category_id);
$places = intval($places); $places = intval($places);
if ($category) { if ($category) {
@ -188,7 +189,7 @@ class GroupManager
} }
$table_group = Database :: get_course_table(TABLE_GROUP); $table_group = Database :: get_course_table(TABLE_GROUP);
$sql = "INSERT INTO ".$table_group." SET $sql = "INSERT INTO $table_group SET
c_id = $course_id, c_id = $course_id,
status = 1, status = 1,
category_id='".Database::escape_string($category_id)."', category_id='".Database::escape_string($category_id)."',
@ -398,9 +399,6 @@ class GroupManager
} }
} }
// Unsubscribe all users
self::unsubscribe_all_users($group_ids);
self::unsubscribe_all_tutors($group_ids);
$sql = "SELECT id, iid, secret_directory, session_id $sql = "SELECT id, iid, secret_directory, session_id
FROM $group_table FROM $group_table
@ -409,6 +407,10 @@ class GroupManager
while ($group = Database::fetch_object($db_result)) { while ($group = Database::fetch_object($db_result)) {
$groupId = $group->iid; $groupId = $group->iid;
// Unsubscribe all users
self::unsubscribe_all_users($groupId);
self::unsubscribe_all_tutors($groupId);
// move group-documents to garbage // move group-documents to garbage
$source_directory = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory; $source_directory = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory;
// File to renamed // File to renamed
@ -472,6 +474,7 @@ class GroupManager
if ($db_object) { if ($db_object) {
$result['id'] = $db_object->id; $result['id'] = $db_object->id;
$result['iid'] = $db_object->iid;
$result['name'] = $db_object->name; $result['name'] = $db_object->name;
$result['status'] = $db_object->status; $result['status'] = $db_object->status;
$result['description'] = $db_object->description; $result['description'] = $db_object->description;
@ -488,10 +491,10 @@ class GroupManager
$result['self_registration_allowed'] = $db_object->self_registration_allowed; $result['self_registration_allowed'] = $db_object->self_registration_allowed;
$result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed; $result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed;
$result['count_users'] = count( $result['count_users'] = count(
self::get_subscribed_users($group_id) self::get_subscribed_users($db_object->iid)
); );
$result['count_tutor'] = count( $result['count_tutor'] = count(
self::get_subscribed_tutors($group_id) self::get_subscribed_tutors($db_object->iid)
); );
$result['count_all'] = $result['count_users'] + $result['count_tutor']; $result['count_all'] = $result['count_users'] + $result['count_tutor'];
} }
@ -723,7 +726,7 @@ class GroupManager
/** /**
* Get the unique category of a given group * Get the unique category of a given group
* @param int $group_id The id of the group * @param int $group_id The iid of the group
* @param string $course_code The course in which the group is (default = * @param string $course_code The course in which the group is (default =
* current course) * current course)
* @return array The category * @return array The category
@ -750,7 +753,7 @@ class GroupManager
gc.c_id = $course_id AND gc.c_id = $course_id AND
g.c_id = $course_id AND g.c_id = $course_id AND
gc.id = g.category_id AND gc.id = g.category_id AND
g.id= $group_id g.iid = $group_id
LIMIT 1"; LIMIT 1";
$res = Database::query($sql); $res = Database::query($sql);
$cat = array(); $cat = array();
@ -1093,7 +1096,7 @@ class GroupManager
/** /**
* Get only tutors from a group * Get only tutors from a group
* @param int $group_id * @param int $group_id iid
* @return array * @return array
*/ */
public static function getTutors($group_id) public static function getTutors($group_id)
@ -1179,32 +1182,19 @@ class GroupManager
* ywarnier:> Now the course_id has been removed (25/1/2005) * ywarnier:> Now the course_id has been removed (25/1/2005)
* The databases are als very inconsistent in this. * The databases are als very inconsistent in this.
* *
* @param int $groupId iid
* @author Chrisptophe Gesche <christophe.geshe@claroline.net>, * @author Chrisptophe Gesche <christophe.geshe@claroline.net>,
* Hugues Peeters <hugues.peeters@claroline.net> - original version * Hugues Peeters <hugues.peeters@claroline.net> - original version
* @author Roan Embrechts - virtual course support, code cleaning * @author Roan Embrechts - virtual course support, code cleaning
* @author Bart Mollet - code cleaning, use other GroupManager-functions * @author Bart Mollet - code cleaning, use other GroupManager-functions
* @return void * @return void
*/ */
public static function fill_groups($group_ids) public static function fill_groups($groupId)
{ {
$_course = api_get_course_info(); $_course = api_get_course_info();
$groupId = (int) $groupId;
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); $category = self::get_category_from_group($groupId);
$group_ids = array_map('intval', $group_ids);
if (api_is_course_coach()) {
for ($i=0 ; $i < count($group_ids) ; $i++) {
if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])){
array_splice($group_ids,$i,1);
$i--;
}
}
if (count($group_ids)==0) {
return false;
}
}
$category = self::get_category_from_group($group_ids[0]);
$groups_per_user = (isset($category['groups_per_user']) ? $category['groups_per_user'] : self::GROUP_PER_MEMBER_NO_LIMIT); $groups_per_user = (isset($category['groups_per_user']) ? $category['groups_per_user'] : self::GROUP_PER_MEMBER_NO_LIMIT);
$group_table = Database:: get_course_table(TABLE_GROUP); $group_table = Database:: get_course_table(TABLE_GROUP);
$group_user_table = Database:: get_course_table(TABLE_GROUP_USER); $group_user_table = Database:: get_course_table(TABLE_GROUP_USER);
@ -1219,19 +1209,21 @@ class GroupManager
*/ */
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = "SELECT g.id gid, g.max_student-count(ug.user_id) nbPlaces, g.max_student $sql = "SELECT g.id gid, g.iid g.max_student-count(ug.user_id) nbPlaces, g.max_student
FROM ".$group_table." g FROM $group_table g
LEFT JOIN ".$group_user_table." ug ON LEFT JOIN $group_user_table ug ON
g.c_id = $course_id AND ug.c_id = $course_id AND g.id = ug.group_id g.c_id = $course_id AND
ug.c_id = $course_id AND
g.iid = ug.group_id
WHERE WHERE
g.id IN (".implode(',', $group_ids).") g.iid = $groupId
GROUP BY (g.id) GROUP BY (g.iid)
HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.") HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.")
ORDER BY nbPlaces DESC"; ORDER BY nbPlaces DESC";
$sql_result = Database::query($sql); $sql_result = Database::query($sql);
$group_available_place = array(); $group_available_place = array();
while ($group = Database::fetch_array($sql_result, 'ASSOC')) { while ($group = Database::fetch_array($sql_result, 'ASSOC')) {
$group_available_place[$group['gid']] = $group['nbPlaces']; $group_available_place[$group['iid']] = $group['nbPlaces'];
} }
/* /*
@ -1240,7 +1232,10 @@ class GroupManager
*/ */
for ($i = 0; $i < count($complete_user_list); $i ++) { for ($i = 0; $i < count($complete_user_list); $i ++) {
//find # of groups the user is enrolled in //find # of groups the user is enrolled in
$number_of_groups = self :: user_in_number_of_groups($complete_user_list[$i]["user_id"], (isset($category['id'])?$category['id']:null)); $number_of_groups = self :: user_in_number_of_groups(
$complete_user_list[$i]["user_id"],
isset($category['id']) ? $category['id'] : null
);
//add # of groups to user list //add # of groups to user list
$complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups; $complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups;
} }
@ -1286,7 +1281,7 @@ class GroupManager
/** /**
* Get the number of students in a group. * Get the number of students in a group.
* @param int $group_id * @param int $group_id iid
* @return int Number of students in the given group. * @return int Number of students in the given group.
*/ */
public static function number_of_students($group_id, $course_id = null) public static function number_of_students($group_id, $course_id = null)
@ -1309,7 +1304,7 @@ class GroupManager
/** /**
* Maximum number of students in a group * Maximum number of students in a group
* @param int $group_id * @param int $group_id iid
* @return int Maximum number of students in the given group. * @return int Maximum number of students in the given group.
*/ */
public static function maximum_number_of_students($group_id) public static function maximum_number_of_students($group_id)
@ -1317,7 +1312,8 @@ class GroupManager
$table_group = Database :: get_course_table(TABLE_GROUP); $table_group = Database :: get_course_table(TABLE_GROUP);
$group_id = intval($group_id); $group_id = intval($group_id);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$db_result = Database::query("SELECT max_student FROM $table_group WHERE c_id = $course_id AND id = $group_id"); $sql = "SELECT max_student FROM $table_group WHERE c_id = $course_id AND iid = $group_id";
$db_result = Database::query($sql);
$db_object = Database::fetch_object($db_result); $db_object = Database::fetch_object($db_result);
if ($db_object->max_student == 0) { if ($db_object->max_student == 0) {
return self::INFINITE; return self::INFINITE;
@ -1359,7 +1355,7 @@ class GroupManager
/** /**
* Is sef-registration allowed? * Is sef-registration allowed?
* @param int $user_id * @param int $user_id
* @param int $group_id * @param int $group_id iid
* @return bool TRUE if self-registration is allowed in the given group. * @return bool TRUE if self-registration is allowed in the given group.
*/ */
public static function is_self_registration_allowed($user_id, $group_id) public static function is_self_registration_allowed($user_id, $group_id)
@ -1373,7 +1369,7 @@ class GroupManager
if (isset($group_id)) { if (isset($group_id)) {
$sql = "SELECT self_registration_allowed $sql = "SELECT self_registration_allowed
FROM $table_group FROM $table_group
WHERE c_id = $course_id AND id = $group_id"; WHERE c_id = $course_id AND iid = $group_id";
$db_result = Database::query($sql); $db_result = Database::query($sql);
$db_object = Database::fetch_object($db_result); $db_object = Database::fetch_object($db_result);
@ -1386,7 +1382,7 @@ class GroupManager
/** /**
* Is sef-unregistration allowed? * Is sef-unregistration allowed?
* @param int $user_id * @param int $user_id
* @param int $group_id * @param int $group_id iid
* @return bool TRUE if self-unregistration is allowed in the given group. * @return bool TRUE if self-unregistration is allowed in the given group.
*/ */
public static function is_self_unregistration_allowed($user_id, $group_id) public static function is_self_unregistration_allowed($user_id, $group_id)
@ -1398,9 +1394,9 @@ class GroupManager
$group_id = intval($group_id); $group_id = intval($group_id);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$db_result = Database::query( $db_result = Database::query(
'SELECT self_unregistration_allowed 'SELECT self_unregistration_allowed
FROM '.$table_group.' FROM '.$table_group.'
WHERE c_id = '.$course_id.' AND id = '.$group_id WHERE c_id = '.$course_id.' AND iid = '.$group_id
); );
$db_object = Database::fetch_object($db_result); $db_object = Database::fetch_object($db_result);
@ -1410,7 +1406,7 @@ class GroupManager
/** /**
* Is user subscribed in group? * Is user subscribed in group?
* @param int $user_id * @param int $user_id
* @param int $group_id * @param int $group_id iid
* @return bool TRUE if given user is subscribed in given group * @return bool TRUE if given user is subscribed in given group
*/ */
public static function is_subscribed($user_id, $group_id) public static function is_subscribed($user_id, $group_id)
@ -1422,11 +1418,12 @@ class GroupManager
$group_id = intval($group_id); $group_id = intval($group_id);
$user_id = intval($user_id); $user_id = intval($user_id);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = 'SELECT 1 FROM '.$table_group_user.' $sql = "SELECT 1 FROM $table_group_user
WHERE WHERE
c_id = '.$course_id.' AND c_id = $course_id AND
group_id = '.$group_id.' AND group_id = $group_id AND
user_id = '.$user_id; user_id = $user_id
";
$result = Database::query($sql); $result = Database::query($sql);
return Database::num_rows($result) > 0; return Database::num_rows($result) > 0;
@ -1435,7 +1432,7 @@ class GroupManager
/** /**
* Can a user subscribe to a specified group in a course * Can a user subscribe to a specified group in a course
* @param int $user_id * @param int $user_id
* @param int $group_id * @param int $group_id iid
* @param bool $checkMaxNumberStudents * @param bool $checkMaxNumberStudents
* *
* @return bool TRUE if given user can be subscribed in given group * @return bool TRUE if given user can be subscribed in given group
@ -1461,12 +1458,14 @@ class GroupManager
} }
} }
$result = self :: is_tutor_of_group($user_id, $group_id); $result = self::is_tutor_of_group($user_id, $group_id);
if ($result) { if ($result) {
return false; return false;
} }
$result = self :: is_subscribed($user_id, $group_id); $result = self::is_subscribed($user_id, $group_id);
if ($result) { if ($result) {
return false; return false;
} }
@ -1477,7 +1476,7 @@ class GroupManager
/** /**
* Can a user unsubscribe to a specified group in a course * Can a user unsubscribe to a specified group in a course
* @param int $user_id * @param int $user_id
* @param int $group_id * @param int $group_id iid
* @return bool TRUE if given user can be unsubscribed from given group * @return bool TRUE if given user can be unsubscribed from given group
* @internal for now, same as GroupManager::is_subscribed($user_id,$group_id) * @internal for now, same as GroupManager::is_subscribed($user_id,$group_id)
*/ */
@ -1490,7 +1489,7 @@ class GroupManager
/** /**
* Get all subscribed users (members) from a group * Get all subscribed users (members) from a group
* @param int $group_id * @param int $group_id (iid)
* @return array An array with information of all users from the given group. * @return array An array with information of all users from the given group.
* (user_id, firstname, lastname, email) * (user_id, firstname, lastname, email)
*/ */
@ -1534,7 +1533,7 @@ class GroupManager
/** /**
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* Get all subscribed tutors of a group * Get all subscribed tutors of a group
* @param int $group_id * @param int $group_id (iid)
* @return array An array with information of all users from the given group. * @return array An array with information of all users from the given group.
* (user_id, firstname, lastname, email) * (user_id, firstname, lastname, email)
*/ */
@ -1553,11 +1552,13 @@ class GroupManager
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = "SELECT tg.id, u.user_id, u.lastname, u.firstname, u.email $sql = "SELECT tg.id, u.user_id, u.lastname, u.firstname, u.email
FROM ".$table_user." u, ".$table_group_tutor." tg FROM $table_user u, $table_group_tutor tg
WHERE WHERE
tg.c_id = $course_id AND tg.c_id = $course_id AND
tg.group_id='".$group_id."' AND tg.group_id = $group_id AND
tg.user_id=u.user_id".$order_clause; tg.user_id = u.user_id
$order_clause
";
$db_result = Database::query($sql); $db_result = Database::query($sql);
$users = array (); $users = array ();
while ($user = Database::fetch_object($db_result)) { while ($user = Database::fetch_object($db_result)) {
@ -1578,7 +1579,7 @@ class GroupManager
/** /**
* Subscribe user(s) to a specified group in current course (as a student) * Subscribe user(s) to a specified group in current course (as a student)
* @param mixed $user_ids Can be an array with user-id's or a single user-id * @param mixed $user_ids Can be an array with user-id's or a single user-id
* @param int $group_id * @param int $group_id iid
* @param int $course_id * @param int $course_id
* @return bool TRUE if successful * @return bool TRUE if successful
*/ */
@ -1606,26 +1607,26 @@ class GroupManager
/** /**
* Subscribe tutor(s) to a specified group in current course * Subscribe tutor(s) to a specified group in current course
* @param mixed $user_ids Can be an array with user-id's or a single user-id * @param mixed $user_ids Can be an array with user-id's or a single user-id
* @param int $group_id * @param int $group_id iid
* @param int $course_id * @param int $course_id
* *
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @see subscribe_users. This function is almost an exact copy of that function. * @see subscribe_users. This function is almost an exact copy of that function.
* @return bool TRUE if successful * @return bool TRUE if successful
*/ */
public static function subscribe_tutors($user_ids, $group_id, $course_id = null) public static function subscribe_tutors($user_ids, $groupId, $course_id = null)
{ {
$user_ids = is_array($user_ids) ? $user_ids : array($user_ids); $user_ids = is_array($user_ids) ? $user_ids : array($user_ids);
$result = true; $result = true;
$course_id = isset($course_id) && !empty($course_id) ? intval($course_id) : api_get_course_int_id(); $course_id = isset($course_id) && !empty($course_id) ? intval($course_id) : api_get_course_int_id();
$table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR);
$group_id = intval($group_id); $groupId = (int) $groupId;
foreach ($user_ids as $user_id) { foreach ($user_ids as $user_id) {
$user_id = intval($user_id); $user_id = intval($user_id);
if (self::can_user_subscribe($user_id, $group_id, false)) { if (self::can_user_subscribe($user_id, $groupId, false)) {
$sql = "INSERT INTO " . $table_group_tutor . " (c_id, user_id, group_id) $sql = "INSERT INTO " . $table_group_tutor . " (c_id, user_id, group_id)
VALUES ('$course_id', '" . $user_id . "', '" . $group_id . "')"; VALUES ('$course_id', '" . $user_id . "', '" . $groupId . "')";
$result = Database::query($sql); $result = Database::query($sql);
} }
} }
@ -1636,7 +1637,7 @@ class GroupManager
/** /**
* Unsubscribe user(s) from a specified group in current course * Unsubscribe user(s) from a specified group in current course
* @param mixed $user_ids Can be an array with user-id's or a single user-id * @param mixed $user_ids Can be an array with user-id's or a single user-id
* @param int $group_id * @param int $group_id iid
* @return bool TRUE if successful * @return bool TRUE if successful
*/ */
public static function unsubscribe_users($user_ids, $group_id) public static function unsubscribe_users($user_ids, $group_id)
@ -1656,52 +1657,40 @@ class GroupManager
/** /**
* Unsubscribe all users from one or more groups * Unsubscribe all users from one or more groups
* @param mixed $group_id Can be an array with group-id's or a single group-id * @param int $group_id iid
* @return bool TRUE if successful * @return bool TRUE if successful
*/ */
public static function unsubscribe_all_users($group_ids) public static function unsubscribe_all_users($groupId)
{ {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
//api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])
$group_ids = is_array($group_ids) ? $group_ids : array($group_ids); $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
$group_ids = array_map('intval', $group_ids); $sql = "DELETE FROM $table_group_user
if (count($group_ids) > 0) { WHERE
if (api_is_course_coach()) { group_id = $groupId AND
for ($i = 0; $i < count($group_ids); $i++) { c_id = $course_id";
if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) { $result = Database::query($sql);
array_splice($group_ids, $i, 1);
$i--;
}
}
if (count($group_ids) == 0) {
return false;
}
}
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
$sql = 'DELETE FROM '.$table_group_user.'
WHERE group_id IN ('.implode(',', $group_ids).') AND c_id = '.$course_id;
$result = Database::query($sql);
return $result; return $result;
}
return true;
} }
/** /**
* Unsubscribe all tutors from one or more groups * Unsubscribe all tutors from one or more groups
* @param mixed $group_id Can be an array with group-id's or a single group-id * @param int $groupId iid
* @see unsubscribe_all_users. This function is almost an exact copy of that function. * @see unsubscribe_all_users. This function is almost an exact copy of that function.
* @return bool TRUE if successful * @return bool TRUE if successful
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/ */
public static function unsubscribe_all_tutors($group_ids) public static function unsubscribe_all_tutors($groupId)
{ {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$group_ids = is_array($group_ids) ? $group_ids : array($group_ids); $groupId = (int) $groupId;
if (count($group_ids) > 0) {
if (!empty($groupId) > 0) {
$table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR);
$sql = 'DELETE FROM '.$table_group_tutor.' $sql = "DELETE FROM $table_group_tutor
WHERE group_id IN ('.implode(',', $group_ids).') AND c_id = '.$course_id; WHERE group_id = $groupId AND c_id = $course_id";
$result = Database::query($sql); $result = Database::query($sql);
return $result; return $result;
} }
@ -1711,7 +1700,7 @@ class GroupManager
/** /**
* Is the user a tutor of this group? * Is the user a tutor of this group?
* @param int $user_id the id of the user * @param int $user_id the id of the user
* @param int $group_id the id of the group * @param int $group_id the iid of the group
* @return boolean true/false * @return boolean true/false
* @todo use the function user_has_access that includes this function * @todo use the function user_has_access that includes this function
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
@ -1723,8 +1712,11 @@ class GroupManager
$group_id = intval($group_id); $group_id = intval($group_id);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = "SELECT * FROM ".$table_group_tutor." $sql = "SELECT * FROM $table_group_tutor
WHERE c_id = $course_id AND user_id='".$user_id."' AND group_id='".$group_id."'"; WHERE
c_id = $course_id AND
user_id = $user_id AND
group_id = $group_id";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) > 0) { if (Database::num_rows($result) > 0) {
return true; return true;
@ -1741,7 +1733,7 @@ class GroupManager
* 1. a member of the group OR * 1. a member of the group OR
* 2. a tutor of the group. This function combines both * 2. a tutor of the group. This function combines both
* @param int $user_id the id of the user * @param int $user_id the id of the user
* @param int $group_id the id of the group * @param int $group_id the iid of the group
* @return boolean true/false * @return boolean true/false
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/ */
@ -1749,7 +1741,7 @@ class GroupManager
{ {
$member = self :: is_subscribed($user_id, $group_id); $member = self :: is_subscribed($user_id, $group_id);
$tutor = self :: is_tutor_of_group($user_id, $group_id); $tutor = self :: is_tutor_of_group($user_id, $group_id);
if ($member OR $tutor) { if ($member || $tutor) {
return true; return true;
} else { } else {
return false; return false;
@ -1798,76 +1790,6 @@ class GroupManager
return $groups; return $groups;
} }
/**
* Get a combined list of all users of the real course $course_code
* and all users in virtual courses linked to this course $course_code
* Filter user list: remove duplicate users; plus
* remove users that
* - are already in the current group $group_id;
* - do not have student status in these courses;
* - are not appointed as tutor (group assistent) for this group;
* - have already reached their maximum # of groups in this course.
*
* Originally to get the correct list of users a big SQL statement was used,
* but this has become more complicated now there is not just one real course but many virtual courses.
* Still, that could have worked as well.
*
* @version 1.1.3
* @author Roan Embrechts
*/
public static function get_complete_list_of_users_that_can_be_added_to_group($course_code, $group_id)
{
$_course = api_get_course_info();
$category = self :: get_category_from_group($group_id, $course_code);
$number_of_groups_limit = $category['groups_per_user'] == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $category['groups_per_user'];
$real_course_code = $_course['sysCode'];
$real_course_info = api_get_course_info($real_course_code);
// add real course to the list
$user_subscribed_course_list = array($real_course_info);
// for all courses...
foreach ($user_subscribed_course_list as $this_course) {
$this_course_code = $this_course['code'];
$course_user_list = CourseManager :: get_user_list_from_course_code($this_course_code);
//for all users in the course
foreach ($course_user_list as $this_user) {
$user_id = $this_user['user_id'];
$loginname = $this_user['username'];
$lastname = $this_user['lastname'];
$firstname = $this_user['firstname'];
$status = $this_user['status'];
//$role = $this_user['role'];
$isTutor = $this_user['is_tutor'];
$full_name = api_get_person_name($firstname, $lastname);
if ($lastname == "" || $firstname == '') {
$full_name = $loginname;
}
$complete_user['user_id'] = $user_id;
$complete_user['full_name'] = $full_name;
$complete_user['firstname'] = $firstname;
$complete_user['lastname'] = $lastname;
$complete_user['status'] = $status;
$complete_user['is_tutor'] = $isTutor;
$student_number_of_groups = self :: user_in_number_of_groups($user_id, $category['id']);
//filter: only add users that have not exceeded their maximum amount of groups
if ($student_number_of_groups < $number_of_groups_limit) {
$complete_user_list[] = $complete_user;
}
}
}
if (is_array($complete_user_list)) {
//sort once, on array field "full_name"
$complete_user_list = TableSort :: sort_table($complete_user_list, "full_name");
//filter out duplicates, based on field "user_id"
$complete_user_list = self :: filter_duplicates($complete_user_list, "user_id");
$complete_user_list = self :: filter_users_already_in_group($complete_user_list, $group_id);
}
return $complete_user_list;
}
/** /**
* Filter out duplicates in a multidimensional array * Filter out duplicates in a multidimensional array
* by comparing field $compare_field. * by comparing field $compare_field.
@ -1888,18 +1810,6 @@ class GroupManager
} }
return $user_array_out; return $user_array_out;
} }
/**
* Filters from the array $user_array_in the users already in the group $group_id.
*/
public static function filter_users_already_in_group($user_array_in, $group_id)
{
foreach ($user_array_in as $this_user) {
if (!self :: is_subscribed($this_user['user_id'], $group_id)) {
$user_array_out[] = $this_user;
}
}
return $user_array_out;
}
/** /**
* Remove all users that are not students and all users who have tutor status * Remove all users that are not students and all users who have tutor status
@ -1998,7 +1908,7 @@ class GroupManager
return true; return true;
break; break;
case self::TOOL_PRIVATE: case self::TOOL_PRIVATE:
$userIsInGroup = self::is_user_in_group($user_id, $group_id); $userIsInGroup = self::is_user_in_group($user_id, $groupInfo['iid']);
if ($userIsInGroup) { if ($userIsInGroup) {
return true; return true;
} }
@ -2030,7 +1940,7 @@ class GroupManager
} }
$groupId = $groupInfo['id']; $groupId = $groupInfo['id'];
$tutors = self::get_subscribed_tutors($groupId, true); $tutors = self::get_subscribed_tutors($groupInfo['iid'], true);
if (in_array($userId, $tutors)) { if (in_array($userId, $tutors)) {
return true; return true;
@ -2123,29 +2033,19 @@ class GroupManager
* Fill the groups with students. * Fill the groups with students.
* *
* note : optimize fill_groups_list <--> fill_groups * note : optimize fill_groups_list <--> fill_groups
* @param array $group_ids * @param int $groupId (group iid)
* @return array|bool * @return array|bool
*/ */
public static function fill_groups_list($group_ids) public static function fill_groups_list($groupId)
{ {
$group_ids = is_array($group_ids) ? $group_ids : array($group_ids); $groupId = (int) $groupId;
$group_ids = array_map('intval', $group_ids); $_course = api_get_course_info();
if (api_is_course_coach()) { if (empty($_course) || empty($groupId)) {
for ($i = 0; $i < count($group_ids); $i++) { return [];
if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) {
array_splice($group_ids, $i, 1);
$i--;
}
}
if (count($group_ids) == 0) {
return false;
}
} }
$_course = api_get_course_info(); $category = self::get_category_from_group($groupId);
$category = self :: get_category_from_group($group_ids[0]);
$number_groups_per_user = self::GROUP_PER_MEMBER_NO_LIMIT; $number_groups_per_user = self::GROUP_PER_MEMBER_NO_LIMIT;
$categoryId = 0; $categoryId = 0;
if ($category) { if ($category) {
@ -2165,13 +2065,13 @@ class GroupManager
* (reverse) ordered by the number of place available * (reverse) ordered by the number of place available
*/ */
$sql = "SELECT g.id gid, count(ug.user_id) count_users, g.max_student $sql = "SELECT g.id gid, count(ug.user_id) count_users, g.max_student
FROM ".$group_table." g FROM $group_table g
LEFT JOIN ".$group_user_table." ug LEFT JOIN $group_user_table ug
ON g.id = ug.group_id ON g.iid = ug.group_id
WHERE g.c_id = $course_id AND WHERE g.c_id = $course_id AND
ug.c_id = $course_id AND ug.c_id = $course_id AND
g.id IN (".implode(',', $group_ids).") g.iid = $groupId
GROUP BY (g.id)"; GROUP BY (g.iid)";
$sql_result = Database::query($sql); $sql_result = Database::query($sql);
$group_available_place = array(); $group_available_place = array();
@ -2223,9 +2123,7 @@ class GroupManager
$user_info = api_get_user_info(); $user_info = api_get_user_info();
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$user_id = $user_info['user_id']; $user_id = $user_info['user_id'];
$orig = isset($origin) ? $origin : null; $orig = isset($origin) ? $origin : null;
$hideGroup = api_get_setting('hide_course_group_if_no_tools_available'); $hideGroup = api_get_setting('hide_course_group_if_no_tools_available');
foreach ($group_list as $this_group) { foreach ($group_list as $this_group) {
@ -2234,8 +2132,8 @@ class GroupManager
$session_img = api_get_session_image($this_group['session_id'], $user_info['status']); $session_img = api_get_session_image($this_group['session_id'], $user_info['status']);
// All the tutors of this group // All the tutors of this group
$tutorsids_of_group = self::get_subscribed_tutors($this_group['id'], true); $tutorsids_of_group = self::get_subscribed_tutors($this_group['iid'], true);
$isMember = self::is_subscribed($user_id, $this_group['id']); $isMember = self::is_subscribed($user_id, $this_group['iid']);
// Create a new table-row // Create a new table-row
$row = array(); $row = array();
@ -2306,9 +2204,9 @@ class GroupManager
// Self-registration / unregistration // Self-registration / unregistration
if (!api_is_allowed_to_edit(false, true)) { if (!api_is_allowed_to_edit(false, true)) {
if (self :: is_self_registration_allowed($user_id, $this_group['id'])) { if (self :: is_self_registration_allowed($user_id, $this_group['iid'])) {
$row[] = '<a class = "btn btn-default" href="group.php?'.api_get_cidreq().'&category='.$category_id.'&action=self_reg&group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfRegInf').'</a>'; $row[] = '<a class = "btn btn-default" href="group.php?'.api_get_cidreq().'&category='.$category_id.'&action=self_reg&group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfRegInf').'</a>';
} elseif (self :: is_self_unregistration_allowed($user_id, $this_group['id'])) { } elseif (self :: is_self_unregistration_allowed($user_id, $this_group['iid'])) {
$row[] = '<a class = "btn btn-default" href="group.php?'.api_get_cidreq().'&category='.$category_id.'&action=self_unreg&group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfUnRegInf').'</a>'; $row[] = '<a class = "btn btn-default" href="group.php?'.api_get_cidreq().'&category='.$category_id.'&action=self_unreg&group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfUnRegInf').'</a>';
} else { } else {
$row[] = '-'; $row[] = '-';

@ -66,8 +66,9 @@ $style .='</style>';
echo '<h2>'.get_lang('GroupSingle').': '.$group_properties['name'].'</h2>'; echo '<h2>'.get_lang('GroupSingle').': '.$group_properties['name'].'</h2>';
if (( if ((
$group_properties['doc_state'] == 2 && $group_properties['doc_state'] == 2 &&
($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $groupId))) || $group_properties['doc_state'] == 1 ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $group_properties['iid']))) ||
$group_properties['doc_state'] == 1
){ ){
if (!empty($png_svg_files)) { if (!empty($png_svg_files)) {

@ -67,7 +67,7 @@ echo '<h2>'.get_lang('GroupSingle').': '.$group_properties['name'].'</h2>';
if (( if ((
$group_properties['doc_state'] == 2 && $group_properties['doc_state'] == 2 &&
($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $groupId))) || $group_properties['doc_state'] == 1 ($is_allowed_to_edit || GroupManager :: is_user_in_group($_user['user_id'], $group_properties['iid']))) || $group_properties['doc_state'] == 1
){ ){
if (!empty($png_svg_files)) { if (!empty($png_svg_files)) {

@ -1208,7 +1208,6 @@ class IndexManager
foreach ($session['courses'] as $course) { foreach ($session['courses'] as $course) {
$is_coach_course = api_is_coach($session_id, $course['real_id']); $is_coach_course = api_is_coach($session_id, $course['real_id']);
$allowed_time = 0; $allowed_time = 0;
$dif_time_after = 0;
$allowedEndTime = true; $allowedEndTime = true;
if (!empty($date_session_start) && $date_session_start != '0000-00-00 00:00:00') { if (!empty($date_session_start) && $date_session_start != '0000-00-00 00:00:00') {
if ($is_coach_course) { if ($is_coach_course) {

@ -74,7 +74,7 @@ if ($groupId) {
api_not_allowed(); api_not_allowed();
} elseif ($group_properties['wiki_state']==2) { } elseif ($group_properties['wiki_state']==2) {
if (!api_is_allowed_to_edit(false, true) and if (!api_is_allowed_to_edit(false, true) and
!GroupManager :: is_user_in_group(api_get_user_id(), api_get_group_id()) !GroupManager :: is_user_in_group(api_get_user_id(), $group_properties['iid'])
) { ) {
api_not_allowed(); api_not_allowed();
} }

@ -925,11 +925,14 @@ class Wiki
Database::query($sql); Database::query($sql);
} }
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
// if both are empty and we are displaying the index page then we display the default text. // if both are empty and we are displaying the index page then we display the default text.
if ($row['content']=='' && $row['title']=='' && $page=='index') { if ($row['content']=='' && $row['title']=='' && $page=='index') {
if (api_is_allowed_to_edit(false, true) || if (api_is_allowed_to_edit(false, true) ||
api_is_platform_admin() || api_is_platform_admin() ||
GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id()) || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo['iid']) ||
api_is_allowed_in_course() api_is_allowed_in_course()
) { ) {
//Table structure for better export to pdf //Table structure for better export to pdf
@ -978,7 +981,7 @@ class Wiki
$actionsLeft .= $editLink; $actionsLeft .= $editLink;
} else { } else {
if ((api_is_allowed_in_course() || if ((api_is_allowed_in_course() ||
GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id())) GroupManager::is_user_in_group(api_get_user_id(), $groupInfo['iid']))
) { ) {
$actionsLeft .= $editLink; $actionsLeft .= $editLink;
} else { } else {
@ -1039,7 +1042,7 @@ class Wiki
// Only available if row['id'] is set // Only available if row['id'] is set
if ($row['id']) { if ($row['id']) {
if (api_is_allowed_to_session_edit(false, true) && api_is_allowed_to_edit() || if (api_is_allowed_to_session_edit(false, true) && api_is_allowed_to_edit() ||
GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id()) GroupManager::is_user_in_group(api_get_user_id(), $groupInfo['iid'])
) { ) {
// menu discuss page // menu discuss page
$actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=discuss&title='.api_htmlentities(urlencode($page)).'" '.self::is_active_navigation_tab('discuss').'>'. $actionsRight .= '<a href="index.php?'.api_get_cidreq().'&action=discuss&title='.api_htmlentities(urlencode($page)).'" '.self::is_active_navigation_tab('discuss').'>'.
@ -2097,6 +2100,7 @@ class Wiki
$assignment_type = $values['assignment']; $assignment_type = $values['assignment'];
$session_id = $this->session_id; $session_id = $this->session_id;
$groupId = api_get_group_id(); $groupId = api_get_group_id();
$groupInfo = GroupManager::get_group_properties($groupId);
if ($groupId==0) { if ($groupId==0) {
//extract course members //extract course members
@ -2107,8 +2111,8 @@ class Wiki
} }
} else { } else {
//extract group members //extract group members
$subscribed_users = GroupManager :: get_subscribed_users($groupId); $subscribed_users = GroupManager :: get_subscribed_users($groupInfo['iid']);
$subscribed_tutors = GroupManager :: get_subscribed_tutors($groupId); $subscribed_tutors = GroupManager :: get_subscribed_tutors($groupInfo['iid']);
$a_users_to_add_with_duplicates = array_merge($subscribed_users, $subscribed_tutors); $a_users_to_add_with_duplicates = array_merge($subscribed_users, $subscribed_tutors);
//remove duplicates //remove duplicates
@ -2158,8 +2162,9 @@ class Wiki
$name = api_get_person_name($o_user_to_add['firstname'], $o_user_to_add['lastname'])." . ".$username; $name = api_get_person_name($o_user_to_add['firstname'], $o_user_to_add['lastname'])." . ".$username;
$photo= '<img src="'.$userPicture.'" alt="'.$name.'" width="40" height="50" align="bottom" title="'.$name.'" />'; $photo= '<img src="'.$userPicture.'" alt="'.$name.'" width="40" height="50" align="bottom" title="'.$name.'" />';
$is_tutor_of_group = GroupManager::is_tutor_of_group($assig_user_id, $groupId); //student is tutor $is_tutor_of_group = GroupManager::is_tutor_of_group($assig_user_id, $groupInfo['iid']); //student is tutor
$is_tutor_and_member = GroupManager::is_tutor_of_group($assig_user_id, $groupId) && GroupManager::is_subscribed($assig_user_id, $groupId); $is_tutor_and_member = GroupManager::is_tutor_of_group($assig_user_id, $groupInfo['iid']) &&
GroupManager::is_subscribed($assig_user_id, $groupInfo['iid']);
// student is tutor and member // student is tutor and member
if ($is_tutor_and_member) { if ($is_tutor_and_member) {
@ -4234,10 +4239,11 @@ class Wiki
// check if is a wiki group // check if is a wiki group
if ($current_row['group_id'] != 0) { if ($current_row['group_id'] != 0) {
$groupInfo = GroupManager::get_group_properties($this->group_id);
//Only teacher, platform admin and group members can edit a wiki group //Only teacher, platform admin and group members can edit a wiki group
if (api_is_allowed_to_edit(false,true) || if (api_is_allowed_to_edit(false,true) ||
api_is_platform_admin() || api_is_platform_admin() ||
GroupManager :: is_user_in_group($userId, $this->group_id) || GroupManager :: is_user_in_group($userId, $groupInfo['iid']) ||
api_is_allowed_in_course() api_is_allowed_in_course()
) { ) {
$PassEdit = true; $PassEdit = true;
@ -4865,10 +4871,11 @@ class Wiki
// Check if is a wiki group // Check if is a wiki group
if (!empty($groupId)) { if (!empty($groupId)) {
$groupInfo = GroupManager::get_group_properties($groupId);
//Only teacher, platform admin and group members can edit a wiki group //Only teacher, platform admin and group members can edit a wiki group
if (api_is_allowed_to_edit(false,true) || if (api_is_allowed_to_edit(false,true) ||
api_is_platform_admin() || api_is_platform_admin() ||
GroupManager :: is_user_in_group($userId, $groupId) GroupManager :: is_user_in_group($userId, $groupInfo['iid'])
) { ) {
$PassEdit = true; $PassEdit = true;
} else { } else {
@ -5481,13 +5488,14 @@ class Wiki
if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) { if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
api_not_allowed(); api_not_allowed();
} }
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
echo '<div class="actions">'.get_lang('AddNew').'</div>'; echo '<div class="actions">'.get_lang('AddNew').'</div>';
echo '<br/>'; echo '<br/>';
//first, check if page index was created. chektitle=false //first, check if page index was created. chektitle=false
if (self::checktitle('index')) { if (self::checktitle('index')) {
if (api_is_allowed_to_edit(false,true) || if (api_is_allowed_to_edit(false,true) ||
api_is_platform_admin() || api_is_platform_admin() ||
GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id()) || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo['iid']) ||
api_is_allowed_in_course() api_is_allowed_in_course()
) { ) {
Display::addFlash(Display::display_normal_message(get_lang('GoAndEditMainPage'), false, true)); Display::addFlash(Display::display_normal_message(get_lang('GoAndEditMainPage'), false, true));
@ -5497,9 +5505,10 @@ class Wiki
} elseif (self::check_addnewpagelock()==0 && (api_is_allowed_to_edit(false, true)==false || api_is_platform_admin()==false)) { } elseif (self::check_addnewpagelock()==0 && (api_is_allowed_to_edit(false, true)==false || api_is_platform_admin()==false)) {
Display::addFlash(Display::display_error_message(get_lang('AddPagesLocked'), false, true)); Display::addFlash(Display::display_error_message(get_lang('AddPagesLocked'), false, true));
} else { } else {
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
if (api_is_allowed_to_edit(false,true) || if (api_is_allowed_to_edit(false,true) ||
api_is_platform_admin() || api_is_platform_admin() ||
GroupManager::is_user_in_group(api_get_user_id(), api_get_group_id()) || GroupManager::is_user_in_group(api_get_user_id(), $groupInfo['iid']) ||
$_GET['group_id'] == 0 $_GET['group_id'] == 0
) { ) {
self::display_new_wiki_form(); self::display_new_wiki_form();

@ -2379,11 +2379,11 @@ function get_list_users_without_publication($task_id, $studentId = null)
} }
$group_id = api_get_group_id(); $group_id = api_get_group_id();
$new_group_user_list = array(); $new_group_user_list = array();
if ($group_id) { if ($group_id) {
$group_user_list = GroupManager::get_subscribed_users($group_id); $groupInfo = GroupManager::get_group_properties($group_id);
$group_user_list = GroupManager::get_subscribed_users($groupInfo['iid']);
if (!empty($group_user_list)) { if (!empty($group_user_list)) {
foreach($group_user_list as $group_user) { foreach($group_user_list as $group_user) {
$new_group_user_list[] = $group_user['user_id']; $new_group_user_list[] = $group_user['user_id'];

@ -392,16 +392,6 @@ class TestGroupManager extends UnitTestCase {
//var_dump($res); //var_dump($res);
} }
public function testGetCompleteListOfUsersThatCanBeAddedToGroup(){
global $_course, $_user;
$course_code= 'chamilo_COURSETEST';
$group_id=2;
$res = GroupManager::get_complete_list_of_users_that_can_be_added_to_group($course_code, $group_id);
$this->assertTrue(is_array($res));
$this->assertTrue($res);
//var_dump($res);
}
public function testfilter_duplicates(){ public function testfilter_duplicates(){
$user_array_in = ''; $user_array_in = '';
$compare_field = ''; $compare_field = '';
@ -410,16 +400,6 @@ class TestGroupManager extends UnitTestCase {
//var_dump($res); //var_dump($res);
} }
public function testFilterUsersAlreadyInGroup(){
global $_course;
$user_array_in = array();
$group_id = 2;
$res = GroupManager::filter_users_already_in_group($user_array_in, $group_id);
$this->assertTrue(is_null($res));
$this->assertNull($res);
//var_dump($res);
}
public function testFilterOnlyStudents(){ public function testFilterOnlyStudents(){
$user_array_in=array(); $user_array_in=array();
$res= GroupManager::filter_only_students($user_array_in); $res= GroupManager::filter_only_students($user_array_in);

Loading…
Cancel
Save