"group.php", "name" => get_lang('GroupManagement')); if (!api_is_allowed_to_edit(false,true)) { api_not_allowed(true); } /* ============================================================================== FUNCTIONS ============================================================================== */ /** * 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) { $cmp = strcasecmp($user_a['lastname'], $user_b['lastname']); if ($cmp !== 0) { return $cmp; } else { $cmp = strcasecmp($user_a['firstname'], $user_b['firstname']); if ($cmp !== 0) { return $cmp; } else { return strcasecmp($user_a['username'], $user_b['username']); } } } /** * Function to check the given max number of members per group */ function check_max_number_of_members($value) { $max_member_no_limit = $value['max_member_no_limit']; if ($max_member_no_limit == MEMBER_PER_GROUP_NO_LIMIT) { return true; } $max_member = $value['max_member']; return is_numeric($max_member); } /** * Function to check if the number of selected group members is valid */ function check_group_members($value) { if ($value['max_member_no_limit'] == MEMBER_PER_GROUP_NO_LIMIT) { return true; } if (isset($value['max_member']) && isset($value['group_members']) && $value['max_member'] < count($value['group_members'])) { return array ('group_members' => get_lang('GroupTooMuchMembers')); } return true; } /* ============================================================================== MAIN CODE ============================================================================== */ // Build form $form = new FormValidator('group_edit'); $form->addElement('hidden', 'action'); $form->addElement('hidden', 'referer'); // Group name $form->add_textfield('name', get_lang('GroupName')); // Description $form->addElement('textarea', 'description', get_lang('GroupDescription'), array ('cols' => 50, 'rows' => 6)); // Tutors: this has been replaced with the new tutors code //$tutors = GroupManager :: get_all_tutors(); //$possible_tutors[0] = get_lang('GroupNoTutor'); //foreach ($tutors as $index => $tutor) //{ // $possible_tutors[$tutor['user_id']] = $tutor['lastname'].' '.$tutor['firstname']; //} //$group = array (); //$group[] = & $form->createElement('select', 'tutor_id', null, $possible_tutors); //$group[] = & $form->createElement('static', null, null, ' '.get_lang('AddTutors').''); //$form->addGroup($group, 'tutor_group', get_lang('GroupTutor'), '', false); // Members per group $form->addElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), MEMBER_PER_GROUP_NO_LIMIT); $group = array (); $group[] = & $form->createElement('radio', 'max_member_no_limit', null, get_lang('Max'), 1); $group[] = & $form->createElement('text', 'max_member', null, array ('size' => 2)); $group[] = & $form->createElement('static', null, null, get_lang('GroupPlacesThis')); $form->addGroup($group, 'max_member_group', null, '', false); $form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members'); // Self registration $form->addElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1); $form->addElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1); // Documents settings $form->addElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); $form->addElement('radio', 'doc_state', null, get_lang('Public'), TOOL_PUBLIC); $form->addElement('radio', 'doc_state', null, get_lang('Private'), TOOL_PRIVATE); // Work settings $form->addElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); $form->addElement('radio', 'work_state', null, get_lang('Public'), TOOL_PUBLIC); $form->addElement('radio', 'work_state', null, get_lang('Private'), TOOL_PRIVATE); // Calendar settings $form->addElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); $form->addElement('radio', 'calendar_state', null, get_lang('Public'), TOOL_PUBLIC); $form->addElement('radio', 'calendar_state', null, get_lang('Private'), TOOL_PRIVATE); // Announcements settings $form->addElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); $form->addElement('radio', 'announcements_state', null, get_lang('Public'), TOOL_PUBLIC); $form->addElement('radio', 'announcements_state', null, get_lang('Private'), TOOL_PRIVATE); //Forum settings $form->addElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); $form->addElement('radio', 'forum_state', null, get_lang('Public'), TOOL_PUBLIC); $form->addElement('radio', 'forum_state', null, get_lang('Private'), TOOL_PRIVATE); // Wiki settings $form->addElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); $form->addElement('radio', 'wiki_state', null, get_lang('Public'), TOOL_PUBLIC); $form->addElement('radio', 'wiki_state', null, get_lang('Private'), TOOL_PRIVATE); // getting all the users if (isset($_SESSION['id_session'])) { $complete_user_list = CourseManager :: get_user_list_from_course_code($_course['id'],true,$_SESSION['id_session']); $complete_user_list2 = CourseManager :: get_coach_list_from_course_code($_course['id'],$_SESSION['id_session']); $complete_user_list = array_merge($complete_user_list,$complete_user_list2); } else { $complete_user_list = CourseManager :: get_user_list_from_course_code($_course['id']); } usort($complete_user_list, 'sort_users'); $possible_users = array (); foreach ($complete_user_list as $index => $user) { $possible_users[$user['user_id']] = $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'; } //print_r($complete_user_list2); // Group tutors $group_tutor_list = GroupManager :: get_subscribed_tutors($current_group['id']); $selected_users = array (); $selected_tutors = array(); foreach ($group_tutor_list as $index => $user) { //$possible_users[$user['user_id']] = $user['lastname'].' '.$user['firstname']; $selected_tutors[] = $user['user_id']; } $group_tutors_element = $form->addElement('advmultiselect', 'group_tutors', get_lang('GroupTutors'), $possible_users, 'style="width: 225px;"'); $group_tutors_element->setElementTemplate(' {javascript}
{label_2} | {label_3} | |
---|---|---|
{unselected} | {add} {remove} |
{selected} |
{label_2} | {label_3} | |
---|---|---|
{unselected} | {add} {remove} |
{selected} |