'group.php', 'name' => get_lang('Groups')); $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); if (!api_is_allowed_to_edit(false, true) && !$is_group_member) { api_not_allowed(true); } /* FUNCTIONS */ /** * List all users registered to the course */ function search_members_keyword($firstname, $lastname, $username, $official_code, $keyword) { if (api_strripos($firstname, $keyword) !== false || api_strripos($lastname, $keyword) !== false || api_strripos($username, $keyword) !== false || api_strripos($official_code, $keyword) !== false ) { return true; } else { return false; } } /** * Function to sort users after getting the list in the DB. * Necessary because there are 2 or 3 queries. Called by usort() */ function sort_users($user_a, $user_b) { if (api_sort_by_first_name()) { $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']); if ($cmp !== 0) { return $cmp; } else { $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']); if ($cmp !== 0) { return $cmp; } else { return api_strcmp($user_a['username'], $user_b['username']); } } } else { $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']); if ($cmp !== 0) { return $cmp; } else { $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']); if ($cmp !== 0) { return $cmp; } else { return api_strcmp($user_a['username'], $user_b['username']); } } } } /** * Function to check if the number of selected group members is valid */ function check_group_members($value) { if ($value['max_student'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) { return true; } if (isset($value['max_student']) && isset($value['group_members']) && $value['max_student'] < count($value['group_members'])) { return array('group_members' => get_lang('GroupTooMuchMembers')); } return true; } /* MAIN CODE */ $htmlHeadXtra[] = ''; // Build form $form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq()); $form->addElement('hidden', 'action'); $form->addElement('hidden', 'max_student', $current_group['max_student']); $complete_user_list = GroupManager::fill_groups_list($current_group['id']); usort($complete_user_list, 'sort_users'); $possible_users = array(); foreach ($complete_user_list as $index => $user) { $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; } // Group members $group_member_list = GroupManager :: get_subscribed_users($current_group['id']); $selected_users = array (); foreach ($group_member_list as $index => $user) { $selected_users[] = $user['user_id']; } // possible : number_groups_left > 0 and is group member $possible_users = array(); foreach ($complete_user_list as $index => $user) { if ($user['number_groups_left'] > 0 || in_array($user['user_id'], $selected_users)) { $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; } } $group_members_element = $form->addElement('advmultiselect', 'group_members', get_lang('GroupMembers'), $possible_users, 'style="width: 280px;"'); $group_members_element->setElementTemplate(' {javascript} {label_2}  {label_3} {unselected} {add}

{remove} {selected} '); $group_members_element->setButtonAttributes('add', array('class' => 'btn arrowr')); $group_members_element->setButtonAttributes('remove', array('class' => 'btn arrowl')); $form->addFormRule('check_group_members'); /*$url = ''. get_lang('EmptyGroup').' '; $form->addElement('label', null, $url);*/ // submit button $form->addElement('style_submit_button', 'submit', get_lang('SaveSettings'), 'class="save"'); if ($form->validate()) { $values = $form->exportValues(); // Storing the users (we first remove all users and then add only those who were selected) GroupManager :: unsubscribe_all_users($current_group['id']); if (isset ($_POST['group_members']) && count($_POST['group_members']) > 0) { GroupManager :: subscribe_users($values['group_members'], $current_group['id']); } // Returning to the group area (note: this is inconsistent with the rest of chamilo) $cat = GroupManager :: get_category_from_group($current_group['id']); if (isset($_POST['group_members']) && count($_POST['group_members']) > $max_member && $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT) { header('Location: group.php?'.api_get_cidreq(true, false).'&action=warning_message&msg='.get_lang('GroupTooMuchMembers')); } else { header('Location: group.php?'.api_get_cidreq(true, false).'&action=success_message&msg='.get_lang('GroupSettingsModified').'&category='.$cat['id']); } exit; } $action = isset($_GET['action']) ? $_GET['action'] : null; switch ($action) { case 'empty': if (api_is_allowed_to_edit(false, true)) { GroupManager :: unsubscribe_all_users($group_id); Display :: display_confirmation_message(get_lang('GroupEmptied')); } break; } $defaults = $current_group; $defaults['group_members'] = $selected_users; $action = isset($_GET['action']) ? $_GET['action'] : ''; $defaults['action'] = $action; if (!empty($_GET['keyword']) && !empty($_GET['submit'])) { $keyword_name = Security::remove_XSS($_GET['keyword']); echo '
'.get_lang('SearchResultsFor').' '.$keyword_name.'
'; } Display :: display_header($nameTools, 'Group'); //@todo fix this if (isset($_GET['show_message_warning'])) { echo Display::display_warning_message($_GET['show_message_warning']); } if (isset($_GET['show_message_sucess'])) { echo Display::display_normal_message($_GET['show_message_sucess']); } $form->setDefaults($defaults); echo GroupManager::getSettingBar('member'); $form->display(); Display :: display_footer();