diff --git a/main/group/group.php b/main/group/group.php index b5855cdf31..320558046e 100644 --- a/main/group/group.php +++ b/main/group/group.php @@ -14,11 +14,8 @@ * @author Isaac Flores, code cleaning and improvements * @package chamilo.group */ -/* INIT SECTION */ -// Name of the language file that needs to be included -$language_file = 'group'; +$is_allowed_in_course = api_is_allowed_to_edit(false, true); -require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; $current_course_tool = TOOL_GROUP; @@ -26,35 +23,40 @@ $current_course_tool = TOOL_GROUP; api_protect_course_script(true); $htmlHeadXtra[] = ''; $nameTools = get_lang('GroupManagement'); $course_id = api_get_course_int_id(); // Create default category if it doesn't exist when group categories aren't allowed if (api_get_setting('allow_group_categories') == 'false') { - $cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY); - $sql = "SELECT * FROM $cat_table WHERE c_id = $course_id AND id = '".GroupManager::DEFAULT_GROUP_CATEGORY."'"; - $res = Database::query($sql); - $num = Database::num_rows($res); - if ($num == 0) { - $sql = "INSERT INTO ".$cat_table." ( c_id, id , title , description , forum_state, wiki_state, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order) - VALUES ($course_id, '2', '".Database::escape_string(get_lang('DefaultGroupCategory'))."', '', '1', '1', '8', '0', '0', '0', '0');"; - Database::query ($sql); - } + $cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY); + $sql = "SELECT * FROM $cat_table WHERE c_id = $course_id AND id = '".GroupManager::DEFAULT_GROUP_CATEGORY."'"; + $res = Database::query($sql); + $num = Database::num_rows($res); + if ($num == 0) { + $sql = "INSERT INTO ".$cat_table." + (c_id, id, title, description, forum_state, wiki_state, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order) + VALUES ($course_id, '2', '".Database::escape_string(get_lang('DefaultGroupCategory'))."', '', '1', '1', '8', '0', '0', '0', '0');"; + Database::query($sql); + } } /* Header */ if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') { - // So we are not in learnpath tool - event_access_tool(TOOL_GROUP); + // So we are not in learnpath tool + event_access_tool(TOOL_GROUP); + if (!$is_allowed_in_course) { + api_not_allowed(true); + } } Display::display_header(get_lang('Groups')); @@ -63,7 +65,7 @@ Display::display_header(get_lang('Groups')); Display::display_introduction_section(TOOL_GROUP); /* - * Self-registration and unregistration + * Self-registration and un-registration */ $my_group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null; $my_msg = isset($_GET['msg']) ? Security::remove_XSS($_GET['msg']) : null; @@ -73,29 +75,29 @@ Display::display_introduction_section(TOOL_GROUP); $my_get_id = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null; if (isset($_GET['action'])) { - switch ($_GET['action']) { - case 'self_reg' : - if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $my_group_id)) { - GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $my_group_id); - Display :: display_confirmation_message(get_lang('GroupNowMember')); - } - break; - case 'self_unreg' : - if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $my_group_id)) { - GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $my_group_id); - Display :: display_confirmation_message(get_lang('StudentDeletesHimself')); - } - break; - case 'show_msg' : - Display :: display_confirmation_message($my_msg); - break; - case 'warning_message' : - Display :: display_warning_message($my_msg); - break; - case 'success_message' : - Display :: display_confirmation_message($my_msg); - break; - } + switch ($_GET['action']) { + case 'self_reg': + if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $my_group_id)) { + GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $my_group_id); + Display :: display_confirmation_message(get_lang('GroupNowMember')); + } + break; + case 'self_unreg': + if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $my_group_id)) { + GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $my_group_id); + Display :: display_confirmation_message(get_lang('StudentDeletesHimself')); + } + break; + case 'show_msg': + Display :: display_confirmation_message($my_msg); + break; + case 'warning_message': + Display :: display_warning_message($my_msg); + break; + case 'success_message': + Display :: display_confirmation_message($my_msg); + break; + } } /* @@ -104,122 +106,124 @@ if (isset($_GET['action'])) { if (api_is_allowed_to_edit(false, true)) { - // Post-actions - if (isset($_POST['action'])) { - switch ($_POST['action']) { - case 'delete_selected' : - if (is_array($_POST['group'])) { - GroupManager :: delete_groups($my_group); - Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted')); - } - break; - case 'empty_selected' : - if (is_array($_POST['group'])) { + // Post-actions + if (isset($_POST['action'])) { + switch ($_POST['action']) { + case 'delete_selected': + if (is_array($_POST['group'])) { + GroupManager :: delete_groups($my_group); + Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted')); + } + break; + case 'empty_selected': + if (is_array($_POST['group'])) { GroupManager :: unsubscribe_all_users($my_group); Display :: display_confirmation_message(get_lang('SelectedGroupsEmptied')); - } - break; - case 'fill_selected' : - if (is_array($_POST['group'])) { + } + break; + case 'fill_selected': + if (is_array($_POST['group'])) { GroupManager :: fill_groups($my_group); Display :: display_confirmation_message(get_lang('SelectedGroupsFilled')); - } - break; - } - } + } + break; + } + } - // Get-actions - if (isset($_GET['action'])) { - switch ($_GET['action']) { - case 'swap_cat_order': - GroupManager :: swap_category_order($my_get_id1, $my_get_id2); - Display :: display_confirmation_message(get_lang('CategoryOrderChanged')); - break; - case 'delete_one': - GroupManager :: delete_groups($my_get_id); - Display :: display_confirmation_message(get_lang('GroupDel')); - break; - case 'empty_one': - GroupManager :: unsubscribe_all_users($my_get_id); - Display :: display_confirmation_message(get_lang('GroupEmptied')); - break; - case 'fill_one': - GroupManager :: fill_groups($my_get_id); - Display :: display_confirmation_message(get_lang('GroupFilledGroups')); - break; - case 'delete_category': - GroupManager :: delete_category($my_get_id); - Display :: display_confirmation_message(get_lang('CategoryDeleted')); - break; - } - } + // Get-actions + if (isset($_GET['action'])) { + switch ($_GET['action']) { + case 'swap_cat_order': + GroupManager :: swap_category_order($my_get_id1, $my_get_id2); + Display :: display_confirmation_message(get_lang('CategoryOrderChanged')); + break; + case 'delete_one': + GroupManager :: delete_groups($my_get_id); + Display :: display_confirmation_message(get_lang('GroupDel')); + break; + + case 'fill_one': + GroupManager :: fill_groups($my_get_id); + Display :: display_confirmation_message(get_lang('GroupFilledGroups')); + break; + case 'delete_category': + GroupManager :: delete_category($my_get_id); + Display :: display_confirmation_message(get_lang('CategoryDeleted')); + break; + } + } } echo '
'; if (api_is_allowed_to_edit(false, true)) { - echo ''.Display::return_icon('new_group.png', get_lang('NewGroupCreate'),'',ICON_SIZE_MEDIUM).''; - if (CourseManager::count_rows_course_table(Database::get_course_table(TABLE_GROUP),api_get_session_id(), api_get_course_int_id()) > 0) { - echo ''.Display::return_icon('group_summary.png', get_lang('GroupOverview'),'',ICON_SIZE_MEDIUM).''; - } - if (api_get_setting('allow_group_categories') == 'true') { - echo ''.Display::return_icon('new_folder.png', get_lang('AddCategory'),'',ICON_SIZE_MEDIUM).''; - } else { - echo ''.Display::return_icon('settings.png', get_lang('PropModify'),'',ICON_SIZE_MEDIUM).''; - } - echo ''.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).''; - echo ''.Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'),'',ICON_SIZE_MEDIUM).''; -} + echo ''. + Display::return_icon('new_group.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).''; + + if (api_get_setting('allow_group_categories') == 'true') { + echo ''. + Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).''; + } else { + echo ''. + Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).''; + } + + echo ''. + Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).''; + + echo ''. + Display::return_icon('export_csv.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).''; -$group_cats = GroupManager :: get_categories(api_get_course_id()); + echo ''. + Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).''; -if (api_get_setting('allow_group_categories') == 'true' && count($group_cats) > 1) { - echo ' '.Display::return_icon('group.png',get_lang('ShowAll'),'',ICON_SIZE_MEDIUM).''; + echo ''. + Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).''; + + echo ''. + Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).''; + + echo ''. + Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).''; + + echo GroupManager::getSearchForm(); } -echo '
'; -/* - * List all categories - */ +$group_cats = GroupManager::get_categories(api_get_course_id()); +echo ''; +/* List all categories */ if (api_get_setting('allow_group_categories') == 'true') { foreach ($group_cats as $index => $category) { - if (isset ($_GET['show_all']) || (isset ($_GET['category']) && $_GET['category'] == $category['id'])) { - //echo ''; - //echo ''.$category['title'].''; - } else { - //echo ''; - //echo ''.$category['title'].''; - //echo Display::page_header($category['title']); - } - $group_list = GroupManager :: get_group_list($category['id']); + $group_list = GroupManager::get_group_list($category['id']); + $label = Display::label(count($group_list).' '.get_lang('ExistingGroups'), 'info'); $actions = null; if (api_is_allowed_to_edit(false, true)) { - $actions .= ''.Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).''; - $actions .= ''.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).''; + $actions .= ''. + Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).''; + $actions .= ''. + Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).''; if ($index != 0) { - $actions .= ' '.Display::return_icon('up.png',' ','',ICON_SIZE_SMALL).''; + $actions .= ' '. + Display::return_icon('up.png',' ','',ICON_SIZE_SMALL).''; } if ($index != count($group_cats) - 1) { - $actions .= ' '.Display::return_icon('down.png',' ','',ICON_SIZE_SMALL).''; + $actions .= ' '. + Display::return_icon('down.png',' ','',ICON_SIZE_SMALL).''; } } echo Display::page_header($category['title'].' '. $label.' '.$actions); - echo '

'.$category['description'].'

'; - GroupManager ::process_groups($group_list, $category['id']); } } else { - $group_list = GroupManager :: get_group_list(); - GroupManager ::process_groups($group_list); + $group_list = GroupManager::get_group_list(); + GroupManager::process_groups($group_list); } -/* FOOTER */ - if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') { - Display::display_footer(); + Display::display_footer(); } -$_SESSION['_gid'] = 0; \ No newline at end of file +$_SESSION['_gid'] = 0; diff --git a/main/group/group_category.php b/main/group/group_category.php index 346717350a..12191d503a 100644 --- a/main/group/group_category.php +++ b/main/group/group_category.php @@ -22,47 +22,52 @@ if (!api_is_allowed_to_edit(false,true) || !(isset ($_GET['id']) || isset ($_POS /** * 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 == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) { - return true; - } - $max_member = $value['max_member']; - return is_numeric($max_member); +function check_max_number_of_members($value) +{ + $max_member_no_limit = $value['max_member_no_limit']; + if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) { + return true; + } + $max_member = $value['max_member']; + return is_numeric($max_member); } /** * Function to check the number of groups per user */ -function check_groups_per_user($value) { - $groups_per_user = $value['groups_per_user']; - if (isset ($_POST['id']) && intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT && GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) { - return false; - } - return true; +function check_groups_per_user($value) +{ + $groups_per_user = $value['groups_per_user']; + if (isset($_POST['id']) && + intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT && + GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) { + return false; + } + return true; } if (api_get_setting('allow_group_categories') == 'true') { - if (isset ($_GET['id'])) { - $category = GroupManager :: get_category($_GET['id']); - $nameTools = get_lang('EditGroupCategory').': '.$category['title']; - } else { - $nameTools = get_lang('AddCategory'); - // Default values for new category - $category = array( - 'groups_per_user' => 1, - 'doc_state' => GroupManager::TOOL_PRIVATE, - 'work_state' => GroupManager::TOOL_PRIVATE, - 'wiki_state' => GroupManager::TOOL_PRIVATE , - 'chat_state' => GroupManager::TOOL_PRIVATE, - 'calendar_state' => GroupManager::TOOL_PRIVATE, - 'announcements_state'=> GroupManager::TOOL_PRIVATE, - 'forum_state' => GroupManager::TOOL_PRIVATE, - 'max_student' => 0); - } + if (isset ($_GET['id'])) { + $category = GroupManager::get_category($_GET['id']); + $nameTools = get_lang('EditGroupCategory').': '.$category['title']; + } else { + $nameTools = get_lang('AddCategory'); + // Default values for new category + $category = array( + 'groups_per_user' => 1, + 'doc_state' => GroupManager::TOOL_PRIVATE, + 'work_state' => GroupManager::TOOL_PRIVATE, + 'wiki_state' => GroupManager::TOOL_PRIVATE , + 'chat_state' => GroupManager::TOOL_PRIVATE, + 'calendar_state' => GroupManager::TOOL_PRIVATE, + 'announcements_state'=> GroupManager::TOOL_PRIVATE, + 'forum_state' => GroupManager::TOOL_PRIVATE, + 'max_student' => 0 + ); + } } else { - $category = GroupManager :: get_category($_GET['id']); - $nameTools = get_lang('PropModify'); + $category = GroupManager::get_category($_GET['id']); + $nameTools = get_lang('PropModify'); } $htmlHeadXtra[] = ''; - + $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups')); $course_id = api_get_course_int_id(); @@ -87,8 +92,8 @@ if (isset ($_GET['id'])) { } else { // Checks if the field was created in the table Category. It creates it if is neccesary $table_category = Database :: get_course_table(TABLE_GROUP_CATEGORY); - if (!Database::query("SELECT wiki_state FROM $table_category WHERE c_id = $course_id")) { - Database::query("ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1' WHERE c_id = $course_id"); + if (!Database::query("SELECT wiki_state FROM $table_category WHERE c_id = $course_id")) { + Database::query("ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1' WHERE c_id = $course_id"); } // Create a new category $action = 'add_category'; @@ -115,15 +120,13 @@ $group = array (); $group[] = $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartBeforeNumber')); $possible_values = array (); for ($i = 1; $i <= 10; $i ++) { - $possible_values[$i] = $i; + $possible_values[$i] = $i; } $possible_values[GroupManager::GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All'); $group[] = $form->createElement('select', 'groups_per_user', null, $possible_values); $group[] = $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber')); $form->addGroup($group, 'limit_group', get_lang('GroupLimit'), ' ', false); $form->addRule('limit_group', get_lang('MaxGroupsPerUserInvalid'), 'callback', 'check_groups_per_user'); -// Default settings for new groups -//$form->addElement('static', null, ''.get_lang('DefaultSettingsForNewGroups').''); $form->addElement('html', '

'.get_lang('DefaultSettingsForNewGroups')); $form->addElement('html', '
'); @@ -138,41 +141,49 @@ $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_reg_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1); +$icon = Display::return_icon('user.png', get_lang('GroupSelfRegistration') , array(), ICON_SIZE_SMALL).' '; +$form->addElement('checkbox', 'self_reg_allowed', $icon.get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1); $form->addElement('checkbox', 'self_unreg_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1); // Documents settings -$form->addElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$icon = Display::return_icon('folder.png', get_lang('GroupDocument') , array(), ICON_SIZE_SMALL).' '; +$form->addElement('radio', 'doc_state', $icon.get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); $form->addElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); $form->addElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); // Work settings -$form->addElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$icon = Display::return_icon('work.png', get_lang('GroupWork') , array(), ICON_SIZE_SMALL).' '; +$form->addElement('radio', 'work_state', $icon.get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); $form->addElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); $form->addElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); // Calendar settings -$form->addElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$icon = Display::return_icon('agenda.png', get_lang('GroupCalendar') , array(), ICON_SIZE_SMALL).' '; +$form->addElement('radio', 'calendar_state', $icon.get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); $form->addElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); $form->addElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); // Announcements settings -$form->addElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$icon = Display::return_icon('announce.png', get_lang('GroupAnnouncements') , array(), ICON_SIZE_SMALL).' '; +$form->addElement('radio', 'announcements_state', $icon.get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); $form->addElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); $form->addElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); // Forum settings -$form->addElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$icon = Display::return_icon('forum.png', get_lang('GroupForum') , array(), ICON_SIZE_SMALL).' '; +$form->addElement('radio', 'forum_state', $icon.get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); $form->addElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); $form->addElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); // Wiki Settings -$form->addElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$icon = Display::return_icon('wiki.png', get_lang('GroupWiki') , array(), ICON_SIZE_SMALL).' '; +$form->addElement('radio', 'wiki_state', $icon.get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); $form->addElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); $form->addElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); // Chat Settings -$form->addElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$icon = Display::return_icon('chat.png', get_lang('Chat') , array(), ICON_SIZE_SMALL).' '; +$form->addElement('radio', 'chat_state', $icon.get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); $form->addElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); $form->addElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); @@ -181,8 +192,8 @@ $form->addElement('style_submit_button', 'submit', get_lang('PropModify'), 'clas // If form validates -> save data if ($form->validate()) { - $values = $form->exportValues(); - if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) { + $values = $form->exportValues(); + if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) { $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT; } else { $max_member = $values['max_member']; @@ -191,7 +202,22 @@ if ($form->validate()) { $self_unreg_allowed = isset($values['self_unreg_allowed']) ? $values['self_unreg_allowed'] : 0; switch ($values['action']) { case 'update_settings': - GroupManager :: update_category($values['id'], $values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $values['forum_state'], $values['wiki_state'], $values['chat_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']); + GroupManager::update_category( + $values['id'], + $values['title'], + $values['description'], + $values['doc_state'], + $values['work_state'], + $values['calendar_state'], + $values['announcements_state'], + $values['forum_state'], + $values['wiki_state'], + $values['chat_state'], + $self_reg_allowed, + $self_unreg_allowed, + $max_member, + $values['groups_per_user'] + ); $msg = urlencode(get_lang('GroupPropertiesModified')); header('Location: group.php?action=show_msg&msg='.$msg.'&category='.$values['id']); break; diff --git a/main/group/group_creation.php b/main/group/group_creation.php index 4d16847312..e4f165229d 100644 --- a/main/group/group_creation.php +++ b/main/group/group_creation.php @@ -17,53 +17,58 @@ $current_course_tool = TOOL_GROUP; // Notice for unauthorized people. api_protect_course_script(true); - /* Create the groups */ if (isset ($_POST['action'])) { - switch ($_POST['action']) { - case 'create_groups': - $groups = array(); + switch ($_POST['action']) { + case 'create_groups': + $groups = array(); - for ($i = 0; $i < $_POST['number_of_groups']; $i ++) { - $group1['name'] = empty($_POST['group_'.$i.'_name']) ? get_lang('Group').' '.$i : $_POST['group_'.$i.'_name']; - $group1['category'] = isset($_POST['group_'.$i.'_category']) ? $_POST['group_'.$i.'_category'] : null; - $group1['tutor'] = isset($_POST['group_'.$i.'_tutor']) ? $_POST['group_'.$i.'_tutor'] : null; - $group1['places'] = isset($_POST['group_'.$i.'_places']) ? $_POST['group_'.$i.'_places'] : null; - $groups[] = $group1; - } + for ($i = 0; $i < $_POST['number_of_groups']; $i ++) { + $group1['name'] = empty($_POST['group_'.$i.'_name']) ? get_lang('Group').' '.$i : $_POST['group_'.$i.'_name']; + $group1['category'] = isset($_POST['group_'.$i.'_category']) ? $_POST['group_'.$i.'_category'] : null; + $group1['tutor'] = isset($_POST['group_'.$i.'_tutor']) ? $_POST['group_'.$i.'_tutor'] : null; + $group1['places'] = isset($_POST['group_'.$i.'_places']) ? $_POST['group_'.$i.'_places'] : null; + $groups[] = $group1; + } - foreach ($groups as $index => $group) { - if (!empty($_POST['same_tutor'])) { - $group['tutor'] = $_POST['group_0_tutor']; - } - if (!empty($_POST['same_places'])) { - $group['places'] = $_POST['group_0_places']; - } - if (api_get_setting('allow_group_categories') == 'false') { - $group['category'] = GroupManager::DEFAULT_GROUP_CATEGORY; - } elseif ($_POST['same_category']) { - $group['category'] = $_POST['group_0_category']; - } - GroupManager :: create_group($group['name'], $group['category'], $group['tutor'], $group['places']); - } - $msg = urlencode(count($groups).' '.get_lang('GroupsAdded')); - header('Location: group.php?action=show_msg&msg='.$msg); + foreach ($groups as $index => $group) { + if (!empty($_POST['same_tutor'])) { + $group['tutor'] = $_POST['group_0_tutor']; + } + if (!empty($_POST['same_places'])) { + $group['places'] = $_POST['group_0_places']; + } + if (api_get_setting('allow_group_categories') == 'false') { + $group['category'] = GroupManager::DEFAULT_GROUP_CATEGORY; + } elseif ($_POST['same_category']) { + $group['category'] = $_POST['group_0_category']; + } + GroupManager :: create_group($group['name'], $group['category'], $group['tutor'], $group['places']); + } + $msg = urlencode(count($groups).' '.get_lang('GroupsAdded')); + header('Location: group.php?action=show_msg&msg='.$msg); exit; - break; - case 'create_subgroups': - GroupManager :: create_subgroups($_POST['base_group'], $_POST['number_of_groups']); - $msg = urlencode($_POST['number_of_groups'].' '.get_lang('GroupsAdded')); - header('Location: group.php?action=show_msg&msg='.$msg); + break; + case 'create_virtual_groups': + $ids = GroupManager :: create_groups_from_virtual_courses(); + $msg = urlencode(count($ids).' '.get_lang('GroupsAdded')); + header('Location: group.php?action=show_msg&msg='.$msg); exit; - break; - case 'create_class_groups': - $ids = GroupManager :: create_class_groups($_POST['group_category']); - $msg = urlencode(count($ids).' '.get_lang('GroupsAdded')); - header('Location: group.php?action=show_msg&msg='.$msg); + break; + case 'create_subgroups': + GroupManager :: create_subgroups($_POST['base_group'], $_POST['number_of_groups']); + $msg = urlencode($_POST['number_of_groups'].' '.get_lang('GroupsAdded')); + header('Location: group.php?action=show_msg&msg='.$msg); exit; - break; - } + break; + case 'create_class_groups': + $ids = GroupManager :: create_class_groups($_POST['group_category']); + $msg = urlencode(count($ids).' '.get_lang('GroupsAdded')); + header('Location: group.php?action=show_msg&msg='.$msg); + exit; + break; + } } $nameTools = get_lang('GroupCreation'); @@ -71,7 +76,7 @@ $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups')); Display :: display_header($nameTools, 'Group'); if (!api_is_allowed_to_edit(false, true)) { - api_not_allowed(); + api_not_allowed(); } /* MAIN TOOL CODE */ @@ -79,51 +84,46 @@ if (!api_is_allowed_to_edit(false, true)) { /* Show group-settings-form */ elseif (isset($_POST['number_of_groups'])) { - if (!is_numeric($_POST['number_of_groups']) || intval($_POST['number_of_groups']) < 1) { - Display :: display_error_message(get_lang('PleaseEnterValidNumber').'

« '.get_lang('Back').'', false); - } else { - $number_of_groups = intval($_POST['number_of_groups']); - if ($number_of_groups > 1) { -?> - -
« '.get_lang('Back').'', false); + } else { + $number_of_groups = intval($_POST['number_of_groups']); + if ($number_of_groups > 1) { + ?> + + defaultRenderer(); - $form_template = "
\n
\n\n{content}\n
\n
\n
"; + $form_template = '
{content}
'; $renderer->setFormTemplate($form_template); $element_template = << - * {label} + + * {label} - {error}
{element} + + {error}
{element} @@ -154,16 +155,14 @@ EOT; $renderer->setElementTemplate($element_template); $form->addElement('hidden', 'action'); $form->addElement('hidden', 'number_of_groups'); - $defaults = array(); - + $defaults = array (); // Table heading - $group_el = array(); - + $group_el = array (); $group_el[] =$form->createElement('static', null, null, ''.get_lang('GroupName').''); if (api_get_setting('allow_group_categories') == 'true') { $group_el[] = $form->createElement('static', null, null, ''.get_lang('GroupCategory').''); } - //$group_el[] = $form->createElement('static', null, null, ''.get_lang('GroupTutor').''); + $group_el[] = $form->createElement('static', null, null, ''.get_lang('GroupPlacesThis').''); $form->addGroup($group_el, 'groups', null, "\n\n\n", false); // Checkboxes @@ -214,16 +213,16 @@ EOT; * Show form to generate new groups */ $categories = GroupManager :: get_categories(); - //echo '
'; - if (count($categories) > 1 || isset ($categories[0]) && $categories[0]['id'] != GroupManager::VIRTUAL_COURSE_CATEGORY) { + + if (count($categories) > 1 || isset($categories[0]) && $categories[0]['id'] != GroupManager::VIRTUAL_COURSE_CATEGORY) { $create_groups_form = new FormValidator('create_groups', 'post', api_get_self().'?'.api_get_cidreq()); $create_groups_form->addElement('header', '', $nameTools); - $group_el = array (); - $group_el[] = $create_groups_form->createElement('static', null, null, get_lang('Create')); - $group_el[] = $create_groups_form->createElement('text', 'number_of_groups', null, array('class' => 'span1')); - $group_el[] = $create_groups_form->createElement('static', null, null, get_lang('NewGroups')); + $group_el = array(); + //$group_el[] = $create_groups_form->createElement('static', null, null, get_lang('Create')); + $group_el[] = $create_groups_form->createElement('text', 'number_of_groups', array(get_lang('Create'), '1')); + //$group_el[] = $create_groups_form->createElement('static', null, null, get_lang('NewGroups')); $group_el[] = $create_groups_form->createElement('style_submit_button', 'submit', get_lang('ProceedToCreateGroup'), 'class="save"'); - $create_groups_form->addGroup($group_el, 'create_groups', null, ' ', false); + $create_groups_form->addGroup($group_el, 'create_groups', get_lang('NumberOfGroupsToCreate'), ' ', false); $defaults = array(); $defaults['number_of_groups'] = 1; $create_groups_form->setDefaults($defaults); @@ -308,4 +307,4 @@ EOT; } /* FOOTER */ -Display :: display_footer(); \ No newline at end of file +Display :: display_footer(); diff --git a/main/group/group_overview.php b/main/group/group_overview.php index 40608d01fe..c60a53cda8 100644 --- a/main/group/group_overview.php +++ b/main/group/group_overview.php @@ -17,9 +17,9 @@ */ // Name of the language file that needs to be included -$language_file = 'group'; +$language_file = array('group', 'admin'); -require '../inc/global.inc.php'; +require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; $current_course_tool = TOOL_GROUP; @@ -27,97 +27,125 @@ $current_course_tool = TOOL_GROUP; api_protect_course_script(true); $nameTools = get_lang('GroupOverview'); +$courseId = api_get_course_int_id(); +$courseInfo = api_get_course_info(); + +/* Libraries */ +include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; +include_once api_get_path(LIBRARY_PATH).'export.lib.inc.php'; + +$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : null; if (isset($_GET['action'])) { - switch ($_GET['action']) { - case 'export': - $groups = GroupManager::get_group_list(); - $data = array(); - foreach ($groups as $index => $group) { - $users = GroupManager::get_users($group['id']); - foreach ($users as $index => $user) { - $row = array(); - $user = api_get_user_info($user); - $row[] = $group['name']; - $row[] = $user['official_code']; - $row[] = $user['lastName']; - $row[] = $user['firstName']; - $data[] = $row; - } - } - switch ($_GET['type']) { - case 'csv': - Export::export_table_csv($data); - exit; - case 'xls': - Export::export_table_xls($data); - exit; - } - break; + switch ($_GET['action']) { + case 'export_all': + $data = GroupManager::exportCategoriesAndGroupsToArray(); + Export::export_table_csv($data); + exit; + break; + case 'export_pdf': + $content = GroupManager::getOverview($courseId, $keyword); + $pdf = new PDF(); + $extra = '

'.get_lang('GroupList').'

'; + $extra .= ''.get_lang('Course').': '.$courseInfo['title'].' ('.$courseInfo['code'].')'; + + $content = $extra.$content; + $pdf->content_to_pdf($content, null, null, api_get_course_id()); + break; + case 'export': + $groupId = isset($_GET['id']) ? intval($_GET['id']) : null; + $groups = GroupManager::get_group_list(); + + $data = array(); + foreach ($groups as $index => $group) { + if (!empty($groupId)) { + if ($group['id'] != $groupId) { + continue; + } + } + $users = GroupManager::get_users($group['id']); + foreach ($users as $index => $user) { + $row = array(); + $user = api_get_user_info($user); + $row[] = $group['name']; + $row[] = $user['official_code']; + $row[] = $user['lastName']; + $row[] = $user['firstName']; + $data[] = $row; + } + } + switch ($_GET['type']) { + case 'csv': + Export::export_table_csv($data); + exit; + break; + case 'xls': + if (!empty($data)) { + Export::export_table_xls($data); + exit; + } + break; + } + break; } } /* Header */ + $interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups')); if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') { - if (!api_is_allowed_to_edit(false, true)) { - api_not_allowed(true); - } else { - Display::display_header($nameTools, 'Group'); - } + // So we are not in learnpath tool + if (!$is_allowed_in_course) { + api_not_allowed(true); + } + if (!api_is_allowed_to_edit(false, true)) { + api_not_allowed(true); + } else { + Display::display_header($nameTools, 'Group'); + // Tool introduction + Display::display_introduction_section(TOOL_GROUP); + } } else { ?> '; - echo ''.Display::return_icon('new_group.png', get_lang('NewGroupCreate'),'',ICON_SIZE_MEDIUM).''; - echo ''.Display::return_icon('group.png', get_lang('Groups'),'',ICON_SIZE_MEDIUM).''; + echo ''. + Display::return_icon('new_group.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).''; + if (api_get_setting('allow_group_categories') == 'true') { - echo ''.Display::return_icon('new_folder.png', get_lang('AddCategory'),'',ICON_SIZE_MEDIUM).''; + echo ''. + Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).''; } else { - //echo ''.Display::return_icon('edit_group.gif').' '.get_lang('PropModify').' '; - echo ''.Display::return_icon('settings.png', get_lang('PropModify'),'',ICON_SIZE_MEDIUM).''; + echo ''. + Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).''; } - //echo Display::return_icon('csv.gif', get_lang('ExportAsCSV')).''.get_lang('ExportAsCSV').' '; - echo ''.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).''; -echo ''; + echo ''. + Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).''; -$categories = GroupManager::get_categories(); + echo ''. + Display::return_icon('export_csv.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).''; -foreach ($categories as $index => $category) { - if (api_get_setting('allow_group_categories') == 'true') { - echo '

'.$category['title'].'

'; - } - $groups = GroupManager::get_group_list($category['id']); - echo ''; -} + echo ''. + Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).''; + + echo ''. + Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).''; -/* FOOTER */ + echo ''. + Display::return_icon('group.png', get_lang('Groups'),'',ICON_SIZE_MEDIUM).''; + + + echo ''. + Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).''; + + echo GroupManager::getSearchForm(); +echo ''; + +echo GroupManager::getOverview($courseId, $keyword); if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') { - Display::display_footer(); -} \ No newline at end of file + Display::display_footer(); +} diff --git a/main/group/group_space.php b/main/group/group_space.php index ef8372771d..b2cc817963 100644 --- a/main/group/group_space.php +++ b/main/group/group_space.php @@ -8,23 +8,24 @@ * @package chamilo.group * @todo Display error message if no group ID specified */ -/* INIT SECTION */ + +/* INIT SECTION */ // Name of the language file that needs to be included $language_file = 'group'; require_once '../inc/global.inc.php'; -$current_course_tool = TOOL_GROUP; +$current_course_tool = TOOL_GROUP; // Notice for unauthorized people. api_protect_course_script(true); -/* Libraries & config files */ +/* Libraries & config files */ require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php'; -/* MAIN CODE */ +/* MAIN CODE */ $group_id = api_get_group_id(); @@ -33,41 +34,41 @@ $user_id = api_get_user_id(); $current_group = GroupManager :: get_group_properties($group_id); if (empty($current_group)) { - api_not_allowed(true); + api_not_allowed(true); } $this_section = SECTION_COURSES; $nameTools = get_lang('GroupSpace'); -$interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups')); +$interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups')); -/* Ensure all private groups // Juan Carlos Raña Trabado */ +/* Ensure all private groups // Juan Carlos Raña Trabado */ $forums_of_groups = get_forums_of_group($current_group['id']); $forum_state_public = 0; if (is_array($forums_of_groups)) { - foreach ($forums_of_groups as $key => $value) { - if ($value['forum_group_public_private'] == 'public') { - $forum_state_public = 1; - } - } + foreach ($forums_of_groups as $key => $value) { + if ($value['forum_group_public_private'] == 'public') { + $forum_state_public = 1; + } + } } if ($current_group['doc_state'] != 1 && $current_group['calendar_state'] != 1 && $current_group['work_state'] != 1 && $current_group['announcements_state'] != 1 && $current_group['wiki_state'] != 1 && $current_group['chat_state'] != 1 && $forum_state_public != 1) { - if (!api_is_allowed_to_edit(null, true) && !GroupManager :: is_user_in_group($_user['user_id'], $current_group['id'])) { - echo api_not_allowed($print_headers); - } + if (!api_is_allowed_to_edit(null,true) && !GroupManager :: is_user_in_group($_user['user_id'], $current_group['id'])) { + echo api_not_allowed($print_headers); + } } -/* Header */ +/* Header */ Display::display_header($nameTools.' '.Security::remove_XSS($current_group['name']), 'Group'); -/* Introduction section (editable by course admin) */ +/* Introduction section (editable by course admin) */ Display::display_introduction_section(TOOL_GROUP); -/* Actions and Action links */ +/* Actions and Action links */ /* * User wants to register in this group @@ -85,14 +86,14 @@ if (!empty($_GET['selfUnReg']) && GroupManager :: is_self_unregistration_allowed Display::display_normal_message(get_lang('StudentDeletesHimself')); } echo '
'; -echo ''.Display::return_icon('back.png', get_lang('BackToGroupList'), '', ICON_SIZE_MEDIUM).''; +echo ''.Display::return_icon('back.png',get_lang('BackToGroupList'),'',ICON_SIZE_MEDIUM).''; /* * Register to group */ $subscribe_group = ''; if (GroupManager :: is_self_registration_allowed($user_id, $current_group['id'])) { - $subscribe_group = ''.get_lang("RegIntoGroup").''; + $subscribe_group = ''.get_lang("RegIntoGroup").''; } /* @@ -100,36 +101,39 @@ if (GroupManager :: is_self_registration_allowed($user_id, $current_group['id']) */ $unsubscribe_group = ''; if (GroupManager :: is_self_unregistration_allowed($user_id, $current_group['id'])) { - $unsubscribe_group = ''.get_lang("StudentUnsubscribe").''; + $unsubscribe_group = ''.get_lang("StudentUnsubscribe").''; } echo ' 
'; if (isset($_GET['action'])) { - switch ($_GET['action']) { - case 'show_msg': - Display::display_normal_message(Security::remove_XSS($_GET['msg'])); - break; - } + switch ($_GET['action']) { + case 'show_msg': + Display::display_normal_message(Security::remove_XSS($_GET['msg'])); + break; + } } -/* Main Display Area */ +/* Main Display Area */ $course_code = $_course['sysCode']; -$is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course(api_get_user_id(), api_get_course_int_id()); +$is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course(api_get_user_id(), $course_code); -/* + /* * Edit the group */ $edit_url = ''; if (api_is_allowed_to_edit(false, true) or GroupManager :: is_tutor_of_group(api_get_user_id(), api_get_group_id())) { $my_origin = isset($origin) ? $origin : ''; - $edit_url = ''.Display::return_icon('edit.png', get_lang('EditGroup'), '', ICON_SIZE_SMALL).''; + $edit_url = ''. + Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).''; } -echo Display::page_header(Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group); +echo Display::page_header( + Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group +); if (!empty($current_group['description'])) { - echo '

'.Security::remove_XSS($current_group['description']).'

'; + echo '

'.Security::remove_XSS($current_group['description']).'

'; } /* @@ -141,141 +145,144 @@ if (api_is_allowed_to_edit(false, true) OR GroupManager :: is_user_in_group(api_ // Link to the forum of this group $forums_of_groups = get_forums_of_group($current_group['id']); - if (is_array($forums_of_groups)) { - if ($current_group['forum_state'] != GroupManager::TOOL_NOT_AVAILABLE) { - foreach ($forums_of_groups as $key => $value) { - if ($value['forum_group_public_private'] == 'public' || (/* !empty($user_subscribe_to_current_group) && */ $value['forum_group_public_private'] == 'private') || !empty($user_is_tutor) || api_is_allowed_to_edit(false, true)) { + if (is_array($forums_of_groups)) { + if ($current_group['forum_state'] != GroupManager::TOOL_NOT_AVAILABLE ) { + foreach ($forums_of_groups as $key => $value) { + if ($value['forum_group_public_private'] == 'public' || (/*!empty($user_subscribe_to_current_group) && */ $value['forum_group_public_private'] == 'private') || !empty($user_is_tutor) || api_is_allowed_to_edit(false, true)) { $actions_array[] = array( 'url' => '../forum/viewforum.php?forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'&origin=group', - 'content' => Display::return_icon('forum.png', get_lang('Forum').': '.$value['forum_title'], array(), 32) - ); - } - } - } - } - if ($current_group['doc_state'] != GroupManager::TOOL_NOT_AVAILABLE) { - // Link to the documents area of this group + 'content' => Display::return_icon('forum.png', get_lang('Forum').': '.$value['forum_title'] , array(), 32) + ); + } + } + } + } + if ($current_group['doc_state'] != GroupManager::TOOL_NOT_AVAILABLE ) { + // Link to the documents area of this group $actions_array[] = array( 'url' => '../document/document.php?'.api_get_cidreq(), 'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32) ); - } - if ($current_group['calendar_state'] != GroupManager::TOOL_NOT_AVAILABLE) { - // Link to a group-specific part of agenda + } + if ($current_group['calendar_state'] != GroupManager::TOOL_NOT_AVAILABLE) { + // Link to a group-specific part of agenda $actions_array[] = array( 'url' => '../calendar/agenda.php?'.api_get_cidreq(), 'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32) ); - } - if ($current_group['work_state'] != GroupManager::TOOL_NOT_AVAILABLE) { - // Link to the works area of this group - $actions_array[] = array( + } + if ($current_group['work_state'] != GroupManager::TOOL_NOT_AVAILABLE) { + // Link to the works area of this group + $actions_array[] = array( 'url' => '../work/work.php?'.api_get_cidreq(), 'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), 32) - ); - } - if ($current_group['announcements_state'] != GroupManager::TOOL_NOT_AVAILABLE) { - // Link to a group-specific part of announcements + ); + + } + if ($current_group['announcements_state'] != GroupManager::TOOL_NOT_AVAILABLE) { + // Link to a group-specific part of announcements $actions_array[] = array( 'url' => '../announcements/announcements.php?'.api_get_cidreq(), 'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32) ); - } + } - if ($current_group['wiki_state'] != GroupManager::TOOL_NOT_AVAILABLE) { - // Link to the wiki area of this group + if ($current_group['wiki_state'] != GroupManager::TOOL_NOT_AVAILABLE) { + // Link to the wiki area of this group $actions_array[] = array( 'url' => '../wiki/index.php?'.api_get_cidreq().'&action=show&title=index&session_id='.api_get_session_id().'&group_id='.$current_group['id'], 'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32) ); - } - if ($current_group['chat_state'] != GroupManager::TOOL_NOT_AVAILABLE) { - // Link to the chat area of this group - if (api_get_course_setting('allow_open_chat_window')) { + } + if ($current_group['chat_state'] != GroupManager::TOOL_NOT_AVAILABLE) { + // Link to the chat area of this group + if (api_get_course_setting('allow_open_chat_window')) { $actions_array[] = array( 'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"", 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32) ); - } else { + } else { $actions_array[] = array( 'url' => "../chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id'], 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32) ); - } - } + } + } - if (!empty($actions_array)) { - echo Display::actions($actions_array); - } -} else { - $actions_array = array(); + if (!empty($actions_array)) { + echo Display::actions($actions_array); + } - // Link to the forum of this group - $forums_of_groups = get_forums_of_group($current_group['id']); - if (is_array($forums_of_groups)) { - if ($current_group['forum_state'] == GroupManager::TOOL_PUBLIC) { - foreach ($forums_of_groups as $key => $value) { - if ($value['forum_group_public_private'] == 'public') { +} else { + $actions_array = array(); + + // Link to the forum of this group + $forums_of_groups = get_forums_of_group($current_group['id']); + if (is_array($forums_of_groups)) { + if ( $current_group['forum_state'] == GroupManager::TOOL_PUBLIC ) { + foreach ($forums_of_groups as $key => $value) { + if ($value['forum_group_public_private'] == 'public' ) { $actions_array[] = array( 'url' => '../forum/viewforum.php?cidReq='.api_get_course_id().'&forum='.$value['forum_id'].'&gidReq='.Security::remove_XSS($current_group['id']).'&origin=group', 'content' => Display::return_icon('forum.png', get_lang('GroupForum'), array(), ICON_SIZE_MEDIUM) ); - } - } - } - } - if ($current_group['doc_state'] == GroupManager::TOOL_PUBLIC) { - // Link to the documents area of this group + } + } + } + } + if ($current_group['doc_state'] == GroupManager::TOOL_PUBLIC) { + // Link to the documents area of this group $actions_array[] = array( 'url' => '../document/document.php?cidReq='.api_get_course_id().'&origin='.$origin, 'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_MEDIUM) ); - } - if ($current_group['calendar_state'] == GroupManager::TOOL_PUBLIC) { - // Link to a group-specific part of agenda + } + if ($current_group['calendar_state'] == GroupManager::TOOL_PUBLIC) { + // Link to a group-specific part of agenda $actions_array[] = array( 'url' => '../calendar/agenda.php?'.api_get_cidreq(), 'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_MEDIUM) ); - } - if ($current_group['work_state'] == GroupManager::TOOL_PUBLIC) { - // Link to the works area of this group - $actions_array[] = array( + + } + if ($current_group['work_state'] == GroupManager::TOOL_PUBLIC) { + // Link to the works area of this group + $actions_array[] = array( 'url' => '../work/work.php?'.api_get_cidreq(), 'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_MEDIUM) - ); - } - if ($current_group['announcements_state'] == GroupManager::TOOL_PUBLIC) { - // Link to a group-specific part of announcements - $actions_array[] = array( + ); + } + if ($current_group['announcements_state'] == GroupManager::TOOL_PUBLIC) { + // Link to a group-specific part of announcements + $actions_array[] = array( 'url' => '../announcements/announcements.php?'.api_get_cidreq(), 'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_MEDIUM) ); - } - if ($current_group['wiki_state'] == GroupManager::TOOL_PUBLIC) { - // Link to the wiki area of this group - $actions_array[] = array( + } + if ($current_group['wiki_state'] == GroupManager::TOOL_PUBLIC) { + // Link to the wiki area of this group + $actions_array[] = array( 'url' => '../wiki/index.php?'.api_get_cidreq().'&action=show&title=index&session_id='.api_get_session_id().'&group_id='.$current_group['id'], 'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32) ); - } - if ($current_group['chat_state'] == GroupManager::TOOL_PUBLIC) { - // Link to the chat area of this group - if (api_get_course_setting('allow_open_chat_window')) { + } + if ($current_group['chat_state'] == GroupManager::TOOL_PUBLIC ) { + // Link to the chat area of this group + if (api_get_course_setting('allow_open_chat_window')) { $actions_array[] = array( 'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"", 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32) ); - } else { + } else { $actions_array[] = array( 'url' => "../chat/chat.php?".api_get_cidreq()."&toolgroup=".$current_group['id'], 'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32) ); - } - } - if (!empty($actions_array)) { - echo Display::actions($actions_array); - } + } + } + if (!empty($actions_array)) { + echo Display::actions($actions_array); + } } /* @@ -285,54 +292,58 @@ $tutors = GroupManager::get_subscribed_tutors($current_group['id']); $tutor_info = ''; if (count($tutors) == 0) { - $tutor_info = get_lang('GroupNoneMasc'); + $tutor_info = get_lang('GroupNoneMasc'); } else { - isset($origin) ? $my_origin = $origin : $my_origin = ''; - foreach ($tutors as $index => $tutor) { - $tab_user_info = api_get_user_info($tutor['user_id']); - $username = api_htmlentities(sprintf(get_lang('LoginX'), $tab_user_info['username']), ENT_QUOTES); - $image_path = UserManager::get_user_picture_path_by_id($tutor['user_id'], 'web', false, true); - $image_repository = $image_path['dir']; - $existing_image = $image_path['file']; - $photo = ''.api_get_person_name($tutor['firstname'], $tutor['lastname']).''; - $tutor_info .= ''.$photo.' '.Display::tag('span', api_get_person_name($tutor['firstname'], $tutor['lastname']), array('title' => $username)).''; - } + isset($origin) ? $my_origin = $origin:$my_origin=''; + $tutor_info .= ''; } -echo Display::page_subheader2(get_lang('GroupTutors')); +echo Display::page_subheader(get_lang('GroupTutors')); if (!empty($tutor_info)) { - echo $tutor_info; + echo $tutor_info; } echo '
'; /* * List all the members of the current group */ -echo Display::page_subheader2(get_lang('GroupMembers')); +echo Display::page_subheader(get_lang('GroupMembers')); $table = new SortableTable('group_users', 'get_number_of_group_users', 'get_group_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 2 : 1); $my_cidreq = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : ''; $my_origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : ''; $my_gidreq = isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : ''; -$parameters = array('cidReq' => $my_cidreq, 'origin' => $my_origin, 'gidReq' => $my_gidreq); +$parameters = array('cidReq' => $my_cidreq, 'origin'=> $my_origin, 'gidReq' => $my_gidreq); $table->set_additional_parameters($parameters); $table->set_header(0, ''); if (api_is_western_name_order()) { - $table->set_header(1, get_lang('FirstName')); - $table->set_header(2, get_lang('LastName')); + $table->set_header(1, get_lang('FirstName')); + $table->set_header(2, get_lang('LastName')); } else { - $table->set_header(1, get_lang('LastName')); - $table->set_header(2, get_lang('FirstName')); + $table->set_header(1, get_lang('LastName')); + $table->set_header(2, get_lang('FirstName')); } if (api_get_setting('show_email_addresses') == 'true') { - $table->set_header(3, get_lang('Email')); - $table->set_column_filter(3, 'email_filter'); + $table->set_header(3, get_lang('Email')); + $table->set_column_filter(3, 'email_filter'); } else { - if (api_is_allowed_to_edit() == 'true') { - $table->set_header(3, get_lang('Email')); - $table->set_column_filter(3, 'email_filter'); - } + if (api_is_allowed_to_edit() == 'true') { + $table->set_header(3, get_lang('Email')); + $table->set_column_filter(3, 'email_filter'); + } } //the order of these calls is important $table->set_column_filter(1, 'user_name_filter'); @@ -348,20 +359,19 @@ $table->display(); * @author Patrick Cool , Ghent University, Belgium * @version April 2008 */ -function get_number_of_group_users() -{ - global $current_group; +function get_number_of_group_users() { + global $current_group; $course_id = api_get_course_int_id(); - // Database table definition - $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); + // Database table definition + $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); - // Query - $sql = "SELECT count(id) AS number_of_users FROM ".$table_group_user." + // Query + $sql = "SELECT count(id) AS number_of_users FROM ".$table_group_user." WHERE c_id = $course_id AND group_id='".Database::escape_string($current_group['id'])."'"; - $result = Database::query($sql); - $return = Database::fetch_array($result, 'ASSOC'); - return $return['number_of_users']; + $result = Database::query($sql); + $return = Database::fetch_array($result,'ASSOC'); + return $return['number_of_users']; } /** @@ -376,79 +386,80 @@ function get_number_of_group_users() * @author Patrick Cool , Ghent University, Belgium * @version April 2008 */ -function get_group_user_data($from, $number_of_items, $column, $direction) -{ - global $current_group; +function get_group_user_data($from, $number_of_items, $column, $direction) { + global $current_group; - // Database table definition - $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); - $table_user = Database :: get_main_table(TABLE_MAIN_USER); + // Database table definition + $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); + $table_user = Database :: get_main_table(TABLE_MAIN_USER); - $course_id = api_get_course_int_id(); + $course_id = api_get_course_int_id(); - // Query - if (api_get_setting('show_email_addresses') == 'true') { - $sql = "SELECT user.user_id AS col0, + // Query + if (api_get_setting('show_email_addresses') == 'true') { + $sql = "SELECT user.user_id AS col0, ".(api_is_western_name_order() ? - "user.firstname AS col1, - user.lastname AS col2," : - "user.lastname AS col1, + "user.firstname AS col1, + user.lastname AS col2," + : + "user.lastname AS col1, user.firstname AS col2," - )." + )." user.email AS col3 FROM ".$table_user." user, ".$table_group_user." group_rel_user WHERE group_rel_user.c_id = $course_id AND group_rel_user.user_id = user.user_id AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'"; - $sql .= " ORDER BY col$column $direction "; - $sql .= " LIMIT $from,$number_of_items"; - } else { - if (api_is_allowed_to_edit()) { - $sql = "SELECT DISTINCT + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + } else { + if (api_is_allowed_to_edit()) { + $sql = "SELECT DISTINCT u.user_id AS col0, ".(api_is_western_name_order() ? - "u.firstname AS col1, - u.lastname AS col2," : - "u.lastname AS col1, + "u.firstname AS col1, + u.lastname AS col2," + : + "u.lastname AS col1, u.firstname AS col2," - )." + )." u.email AS col3 FROM ".$table_user." u INNER JOIN ".$table_group_user." gu ON (gu.user_id = u.user_id) AND gu.c_id = $course_id WHERE gu.group_id = '".Database::escape_string($current_group['id'])."'"; - $sql .= " ORDER BY col$column $direction "; - $sql .= " LIMIT $from,$number_of_items"; - } else { - $sql = "SELECT DISTINCT + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + } else { + $sql = "SELECT DISTINCT user.user_id AS col0, - ".(api_is_western_name_order() ? - "user.firstname AS col1, - user.lastname AS col2 " : - "user.lastname AS col1, + ". (api_is_western_name_order() ? + "user.firstname AS col1, + user.lastname AS col2 " + : + "user.lastname AS col1, user.firstname AS col2 " - )." + )." FROM ".$table_user." user, ".$table_group_user." group_rel_user WHERE group_rel_user.c_id = $course_id AND group_rel_user.user_id = user.user_id AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'"; - $sql .= " ORDER BY col$column $direction "; - $sql .= " LIMIT $from,$number_of_items"; - } - } - - $return = array(); - $result = Database::query($sql); - while ($row = Database::fetch_row($result)) { - $return[] = $row; - } - return $return; + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + } + } + + $return = array(); + $result = Database::query($sql); + while ($row = Database::fetch_row($result)) { + $return[] = $row; + } + return $return; } /** - * Returns a mailto-link - * @param string $email An email-address - * @return string HTML-code with a mailto-link - */ -function email_filter($email) -{ - return Display :: encrypted_mailto_link($email, $email); +* Returns a mailto-link +* @param string $email An email-address +* @return string HTML-code with a mailto-link +*/ +function email_filter($email) { + return Display :: encrypted_mailto_link($email, $email); } /** @@ -460,15 +471,14 @@ function email_filter($email) * @author Patrick Cool , Ghent University, Belgium * @version April 2008 */ -function user_icon_filter($user_id) -{ - global $origin; - $userinfo = api_get_user_info($user_id); - $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true); - $image_repository = $image_path['dir']; - $existing_image = $image_path['file']; - $photo = '
'.$userinfo['complete_name'].'
'; - return ''.$photo; +function user_icon_filter($user_id) { + global $origin; + $userinfo = Database::get_user_info_from_id($user_id); + $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true); + $image_repository = $image_path['dir']; + $existing_image = $image_path['file']; + $photo = '
'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'
'; + return '
'.$photo; } /** @@ -481,15 +491,14 @@ function user_icon_filter($user_id) * @param array Row of the "sortable table" as it is at the time of function call - we extract the user ID from there * @return string HTML link */ -function user_name_filter($name, $url_params, $row) -{ - global $origin; - $tab_user_info = api_get_user_info($row[0]); +function user_name_filter($name, $url_params, $row) { + $tab_user_info = Database::get_user_info_from_id($row[0]); $username = api_htmlentities(sprintf(get_lang('LoginX'), $tab_user_info['username']), ENT_QUOTES); return ''.$name.''; } + // Footer $orig = isset($origin) ? $origin : ''; if ($orig != 'learnpath') { - Display::display_footer(); -} \ No newline at end of file + Display::display_footer(); +} diff --git a/main/group/import.php b/main/group/import.php new file mode 100644 index 0000000000..e8c503fd4f --- /dev/null +++ b/main/group/import.php @@ -0,0 +1,71 @@ + 'group.php', 'name' => get_lang('Groups')); + +Display::display_header($nameTools, 'Group'); + +$form = new FormValidator('import', 'post', api_get_self().'?'.api_get_cidreq()); +$form->addElement('header', get_lang('ImportGroups')); +$form->addElement('file', 'file', get_lang('File')); +$form->addRule('file', get_lang('ThisFieldIsRequired'), 'required'); +$form->addElement('checkbox', 'delete_not_in_file', null, get_lang('DeleteItemsNotInFile')); +$form->addElement('button', 'submit', get_lang('Import')); + +if ($form->validate()) { + if (isset($_FILES['file']['tmp_name']) && !empty($_FILES['file']['tmp_name'])) { + $groupData = Import::csv_reader($_FILES['file']['tmp_name']); + $deleteNotInArray = $form->getSubmitValue('delete_not_in_file') == 1 ? true : false; + + $result = GroupManager::importCategoriesAndGroupsFromArray($groupData, $deleteNotInArray); + if (!empty($result)) { + $html = null; + foreach ($result as $status => $data) { + + if (empty($data['category']) && empty($data['group'])) { + continue; + } + + $html .= "

".get_lang(ucfirst($status)).'

'; + if (!empty($data['category'])) { + $html .= "

".get_lang('Categories').':

'; + foreach ($data['category'] as $category) { + $html .= "
".$category['category']."
"; + } + } + + if (!empty($data['group'])) { + $html .= "

".get_lang('Groups').':

'; + foreach ($data['group'] as $group) { + $html .= "
".$group['group']."
"; + } + } + } + echo $html; + } + } +} +$form->display(); + +Display::display_footer(); diff --git a/main/group/member_settings.php b/main/group/member_settings.php new file mode 100644 index 0000000000..f1475e8205 --- /dev/null +++ b/main/group/member_settings.php @@ -0,0 +1,222 @@ + '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(); diff --git a/main/group/settings.php b/main/group/settings.php new file mode 100644 index 0000000000..f7614ecd4c --- /dev/null +++ b/main/group/settings.php @@ -0,0 +1,194 @@ + '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); +} + +// Build form +$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq()); +$form->addElement('hidden', 'action'); + +// Group name +$form->addElement('text', 'name', get_lang('GroupName')); + +// Description +$form->addElement('textarea', 'description', get_lang('Description'), array ('class' => 'span6', 'rows' => 6)); + +// Members per group +$group = array( + $form->createElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT), + $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, array('id' => 'max_member_selected')), + $form->createElement('text', 'max_member', null, array('class' => 'span1', 'id' => 'max_member')), + $form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis')) +); +$form->addGroup($group, 'max_member_group', get_lang('GroupLimit'), '', false); +$form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members'); + +$form->addElement('html', '
'); + +// Self registration +$group = array( + $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1), + $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1) +); +$form->addGroup($group, '', Display::return_icon('user.png', get_lang('GroupSelfRegistration') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupSelfRegistration'), '', false); + +// Documents settings +$group = array(); +$group[] = $form->createElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$group[] = $form->createElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); +$group[] = $form->createElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); +$form->addGroup($group, '', Display::return_icon('folder.png', get_lang('GroupDocument') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupDocument'), '', false); + +// Work settings +$group = array(); +$group[] = $form->createElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$group[] = $form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); +$group[] = $form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); +$form->addGroup($group, '', Display::return_icon('work.png', get_lang('GroupWork') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupWork'), '', false); + +// Calendar settings +$group = array(); +$group[] = $form->createElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$group[] = $form->createElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); +$group[] = $form->createElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); +$form->addGroup($group, '', Display::return_icon('agenda.png', get_lang('GroupCalendar') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupCalendar'), '', false); + +$form->addElement('html', '
'); +$form->addElement('html', '
'); + +// Announcements settings +$group = array(); +$group[] = $form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$group[] = $form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); +$group[] = $form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); +$form->addGroup($group, '', Display::return_icon('announce.png', get_lang('GroupAnnouncements') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupAnnouncements'), '', false); + +//Forum settings +$group = array(); +$group[] = $form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE); +$group[] = $form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC); +$group[] = $form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE); +$form->addGroup($group, '', Display::return_icon('forum.png', get_lang('GroupForum') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupForum'), '', false); + +// Wiki settings +$group = array( + $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE), + $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC), + $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE) +); +$form->addGroup($group, '', Display::return_icon('wiki.png', get_lang('GroupWiki') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupWiki'), '', false); + +// Chat settings +$group = array( + $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE), + $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC), + $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE) +); +$form->addGroup($group, '', Display::return_icon('chat.png', get_lang('Chat'), array(), ICON_SIZE_SMALL).' '.get_lang('Chat'), '', false); + +$form->addElement('html', '
'); + +$form->addElement('html', '
'); +// Submit button +$form->addElement('style_submit_button', 'submit', get_lang('SaveSettings'), 'class="save"'); +$form->addElement('html', '
'); + +if ($form->validate()) { + $values = $form->exportValues(); + if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) { + $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT; + } else { + $max_member = $values['max_member']; + } + $self_registration_allowed = isset($values['self_registration_allowed']) ? 1 : 0; + $self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0; + + GroupManager::set_group_properties( + $current_group['id'], + strip_tags($values['name']), + strip_tags($values['description']), + $max_member, + $values['doc_state'], + $values['work_state'], + $values['calendar_state'], + $values['announcements_state'], + $values['forum_state'], + $values['wiki_state'], + $values['chat_state'], + $self_registration_allowed, + $self_unregistration_allowed + ); + 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; +} + +$defaults = $current_group; +$action = isset($_GET['action']) ? $_GET['action'] : ''; +$defaults['action'] = $action; +if ($defaults['maximum_number_of_students'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) { + $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT; +} else { + $defaults['max_member_no_limit'] = 1; + $defaults['max_member'] = $defaults['maximum_number_of_students']; +} + +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('settings'); +echo '
'; +$form->display(); +echo '
'; + +Display :: display_footer(); diff --git a/main/group/tutor_settings.php b/main/group/tutor_settings.php new file mode 100644 index 0000000000..caa1418aa7 --- /dev/null +++ b/main/group/tutor_settings.php @@ -0,0 +1,185 @@ + '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']); + } + } + } +} + + +/* MAIN CODE */ + +$htmlHeadXtra[] = ''; + +// Build form +$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq()); +$form->addElement('hidden', 'action'); + +// 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) { + $selected_tutors[] = $user['user_id']; +} + +$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_tutors_element = $form->addElement('advmultiselect', 'group_tutors', get_lang('GroupTutors'), $possible_users, 'style="width: 280px;"'); +$group_tutors_element->setElementTemplate(' +{javascript} + +{label_2} + {label_3} + + {unselected} + {add}

{remove} + {selected} + + +'); + +$group_tutors_element->setButtonAttributes('add', array('class' => 'btn arrowr')); +$group_tutors_element->setButtonAttributes('remove', array('class' => 'btn arrowl')); + +// submit button +$form->addElement('style_submit_button', 'submit', get_lang('SaveSettings'), 'class="save"'); + +if ($form->validate()) { + $values = $form->exportValues(); + + // Storing the tutors (we first remove all the tutors and then add only those who were selected) + GroupManager :: unsubscribe_all_tutors($current_group['id']); + if (isset ($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) { + GroupManager :: subscribe_tutors($values['group_tutors'], $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; +} + +$defaults = $current_group; +$defaults['group_tutors'] = $selected_tutors; +$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('tutor'); +$form->display(); + +Display :: display_footer(); diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index a46a992deb..3857b91afc 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -92,6 +92,7 @@ define('TOOL_LINK', 'link'); define('TOOL_COURSE_DESCRIPTION', 'course_description'); define('TOOL_SEARCH', 'search'); define('TOOL_LEARNPATH', 'learnpath'); +define('TOOL_AGENDA', 'agenda'); define('TOOL_ANNOUNCEMENT', 'announcement'); define('TOOL_FORUM', 'forum'); define('TOOL_FORUM_CATEGORY','forum_category'); @@ -5013,8 +5014,8 @@ function api_is_course_visible_for_user($userid = null, $cid = null) { * @return boolean true if the element is in the session, false else */ function api_is_element_in_the_session($tool, $element_id, $session_id = null) { - if (is_null($session_id)) { - $session_id = intval($_SESSION['id_session']); + if (empty($session_id)) { + $session_id = api_get_session_id(); } // Get information to build query depending of the tool. @@ -5033,7 +5034,7 @@ function api_is_element_in_the_session($tool, $element_id, $session_id = null) { break; case TOOL_GROUP : $table_tool = Database::get_course_table(TABLE_GROUP); - $key_field = 'id'; + $key_field = 'iid'; break; default: return false; } @@ -5042,7 +5043,8 @@ function api_is_element_in_the_session($tool, $element_id, $session_id = null) { $sql = "SELECT session_id FROM $table_tool WHERE c_id = $course_id AND $key_field = ".intval($element_id); $rs = Database::query($sql); if ($element_session_id = Database::result($rs, 0, 0)) { - if ($element_session_id == intval($session_id)) { // The element belongs to the session. + // The element belongs to the session. + if ($element_session_id == intval($session_id) && !empty($session_id)) { return true; } } diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index 492a5bc0d7..95a017ffc5 100644 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -18,56 +18,60 @@ class GroupManager { //- VIRTUAL_COURSE_CATEGORY: in this category groups are created based on the virtual course of a course - CONST VIRTUAL_COURSE_CATEGORY = 1; + const VIRTUAL_COURSE_CATEGORY = 1; //DEFAULT_GROUP_CATEGORY: When group categories aren't available (platform-setting), all groups are created in this 'dummy'-category - CONST DEFAULT_GROUP_CATEGORY = 2; + const DEFAULT_GROUP_CATEGORY = 2; /** * infinite */ - CONST INFINITE = 99999; + const INFINITE = 99999; /** * No limit on the number of users in a group */ - CONST MEMBER_PER_GROUP_NO_LIMIT = 0; + const MEMBER_PER_GROUP_NO_LIMIT = 0; /** * No limit on the number of groups per user */ - CONST GROUP_PER_MEMBER_NO_LIMIT = 0; + const GROUP_PER_MEMBER_NO_LIMIT = 0; /** * The tools of a group can have 3 states * - not available * - public * - private */ - CONST TOOL_NOT_AVAILABLE = 0; - CONST TOOL_PUBLIC = 1; - CONST TOOL_PRIVATE = 2; + const TOOL_NOT_AVAILABLE = 0; + const TOOL_PUBLIC = 1; + const TOOL_PRIVATE = 2; /** * Constants for the available group tools */ - CONST GROUP_TOOL_FORUM = 0; - CONST GROUP_TOOL_DOCUMENTS = 1; - CONST GROUP_TOOL_CALENDAR = 2; - CONST GROUP_TOOL_ANNOUNCEMENT = 3; - CONST GROUP_TOOL_WORK = 4; - CONST GROUP_TOOL_WIKI = 5; - CONST GROUP_TOOL_CHAT = 6; + const GROUP_TOOL_FORUM = 0; + const GROUP_TOOL_DOCUMENTS = 1; + const GROUP_TOOL_CALENDAR = 2; + const GROUP_TOOL_ANNOUNCEMENT = 3; + const GROUP_TOOL_WORK = 4; + const GROUP_TOOL_WIKI = 5; + const GROUP_TOOL_CHAT = 6; - //GROUP FUNCTIONS + /** + * + */ private function __construct() { } + /** + * @return array + */ public static function get_groups() { - $table_group = Database :: get_course_table(TABLE_GROUP); - $course_id = api_get_course_int_id(); + $table_group = Database :: get_course_table(TABLE_GROUP); + $course_id = api_get_course_int_id(); $sql = "SELECT * FROM $table_group WHERE c_id = $course_id "; $result = Database::query($sql); - return Database::store_result($result, 'ASSOC'); } @@ -81,69 +85,57 @@ class GroupManager public static function get_group_list($category = null, $course_code = null) { $my_user_id = api_get_user_id(); + $course_info = api_get_course_info($course_code); $course_id = $course_info['real_id']; $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); - $table_group = Database :: get_course_table(TABLE_GROUP); + $table_group = Database :: get_course_table(TABLE_GROUP); //condition for the session $session_id = api_get_session_id(); $my_status_of_user_in_course = CourseManager::get_user_in_course_status($my_user_id, $course_info['code']); $is_student_in_session = false; - // User is subscribed in session - if (is_null($my_status_of_user_in_course) || $my_status_of_user_in_course == '') { - if ($session_id > 0) { + if (is_null($my_status_of_user_in_course) || $my_status_of_user_in_course=='') { + if ($session_id>0) { $is_student_in_session = true; } } - $sql = null; - - // @todo fix the conditions below // COURSEMANAGER or STUDENT if ($my_status_of_user_in_course == COURSEMANAGER || api_is_allowed_to_edit(null, true) || api_is_drh()) { - $sql = "SELECT g.id , - g.name , - g.description , - g.category_id, - g.max_student maximum_number_of_members, - g.secret_directory, - g.self_registration_allowed, - g.self_unregistration_allowed, - g.session_id, - ug.user_id is_member - FROM $table_group g - LEFT JOIN $table_group_user ug - ON (ug.group_id = g.id AND ug.user_id = '".api_get_user_id( - )."' AND ug.c_id = $course_id AND g.c_id = $course_id)"; - } elseif ($my_status_of_user_in_course == STUDENT || $is_student_in_session === true) { - $sql = "SELECT g.id, - g.name, - g.description, - g.category_id, - g.max_student maximum_number_of_members, - g.secret_directory, - g.self_registration_allowed, - g.self_unregistration_allowed, - g.session_id, - ug.user_id is_member - FROM $table_group g - LEFT JOIN $table_group_user ug - ON (ug.group_id = g.id AND - ug.user_id = '".api_get_user_id()."' AND - ug.c_id = $course_id AND - g.c_id = $course_id )"; - } - - if (empty($sql)) { - return array(); + $can_see_groups = 1; + $sql = "SELECT g.iid, + g.name, + g.description, + g.category_id, + g.max_student maximum_number_of_members, + g.secret_directory, + g.self_registration_allowed, + g.self_unregistration_allowed, + g.session_id + FROM $table_group g "; + } elseif ($my_status_of_user_in_course == STUDENT || $is_student_in_session === true || $_SESSION['studentview'] == 'studentview') { + $can_see_groups = 1; + $sql = "SELECT g.iid, + g.name, + g.description, + g.category_id, + g.max_student maximum_number_of_members, + g.secret_directory, + g.self_registration_allowed, + g.self_unregistration_allowed, + g.session_id, + ug.user_id is_member + FROM $table_group g + LEFT JOIN $table_group_user ug + ON (ug.group_id = g.iid AND ug.user_id = '".api_get_user_id()."' AND ug.c_id = $course_id AND g.c_id = $course_id)"; } $sql .= " WHERE 1=1 "; if ($category != null) { - $sql .= " AND g.category_id = '".Database::escape_string($category)."' "; + $sql .= " AND g.category_id = '".Database::escape_string($category)."' "; $session_condition = api_get_session_condition($session_id); if (!empty($session_condition)) { $sql .= $session_condition; @@ -157,32 +149,30 @@ class GroupManager if (!empty($session_condition)) { $sql .= $session_condition; } - $sql .= " GROUP BY g.id ORDER BY UPPER(g.name)"; + $sql .= " GROUP BY g.iid ORDER BY UPPER(g.name)"; - if (!api_is_anonymous()) { + if ($can_see_groups == 1) { $groupList = Database::query($sql); } else { return array(); } $groups = array(); - while ($thisGroup = Database::fetch_array($groupList)) { + $thisGroup['id'] = $thisGroup['iid']; + $thisGroup['is_member'] = self::is_subscribed($my_user_id, $thisGroup['id']); $thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['id'])); if ($thisGroup['session_id'] != 0) { - $sql_session = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' - WHERE id='.$thisGroup['session_id']; - $rs_session = Database::query($sql_session); - if (Database::num_rows($rs_session) > 0) { + $sql = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' + WHERE id='.$thisGroup['session_id']; + $rs_session = Database::query($sql); + if (Database::num_rows($rs_session)>0) { $thisGroup['session_name'] = Database::result($rs_session, 0, 0); - } else { - //the session has probably been removed, so the group is now orphaned } } $groups[] = $thisGroup; } - return $groups; } @@ -198,12 +188,13 @@ class GroupManager $table_group = Database :: get_course_table(TABLE_GROUP); $session_id = api_get_session_id(); - $course_id = api_get_course_int_id(); + $course_id = api_get_course_int_id(); $currentCourseRepository = $_course['path']; $category = self :: get_category($category_id); + $places = intval($places); - if (intval($places) == 0) { + if ($places == 0) { //if the amount of users per group is not filled in, use the setting from the category $places = $category['max_student']; } else { @@ -213,44 +204,30 @@ class GroupManager } $sql = "INSERT INTO ".$table_group." SET - c_id = $course_id , - category_id='".Database::escape_string($category_id)."', - max_student = '".$places."', - doc_state = '".$category['doc_state']."', - calendar_state = '".$category['calendar_state']."', - work_state = '".$category['work_state']."', - announcements_state = '".$category['announcements_state']."', - forum_state = '".$category['forum_state']."', - wiki_state = '".$category['wiki_state']."', - chat_state = '".$category['chat_state']."', - self_registration_allowed = '".$category['self_reg_allowed']."', - self_unregistration_allowed = '".$category['self_unreg_allowed']."', - session_id='".Database::escape_string($session_id)."'"; - + c_id = $course_id , + category_id='".Database::escape_string($category_id)."', + max_student = '".$places."', + doc_state = '".$category['doc_state']."', + calendar_state = '".$category['calendar_state']."', + work_state = '".$category['work_state']."', + announcements_state = '".$category['announcements_state']."', + forum_state = '".$category['forum_state']."', + wiki_state = '".$category['wiki_state']."', + chat_state = '".$category['chat_state']."', + self_registration_allowed = '".$category['self_reg_allowed']."', + self_unregistration_allowed = '".$category['self_unreg_allowed']."', + session_id='".Database::escape_string($session_id)."'"; Database::query($sql); $lastId = Database::insert_id(); - //Fixing Id - Database::update($table_group, array('id' => $lastId), array('iid = ? ' => $lastId)); - if ($lastId) { - $desired_dir_name = '/'.api_replace_dangerous_char($name, 'strict').'_groupdocs'; + $desired_dir_name= '/'.api_replace_dangerous_char($name,'strict').'_groupdocs'; $my_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository.'/document'; - $unique_name = FileManager::create_unexisting_directory( - $_course, - api_get_user_id(), - $session_id, - $lastId, - null, - $my_path, - $desired_dir_name - ); + $unique_name = FileManager::create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, NULL, $my_path, $desired_dir_name); /* Stores the directory path into the group table */ - $sql = "UPDATE ".$table_group." SET name = '".Database::escape_string( - $name - )."', secret_directory = '".$unique_name."' - WHERE c_id = $course_id AND id ='".$lastId."'"; + $sql = "UPDATE ".$table_group." SET name = '".Database::escape_string($name)."', secret_directory = '".$unique_name."' + WHERE c_id = $course_id AND iid ='".$lastId."'"; Database::query($sql); @@ -282,14 +259,14 @@ class GroupManager $values['approval_direct_group']['approval_direct'] = 0; $values['allow_attachments_group']['allow_attachments'] = 1; $values['allow_new_threads_group']['allow_new_threads'] = 1; - $values['default_view_type_group']['default_view_type'] = api_get_setting('default_forum_view'); + $values['default_view_type_group']['default_view_type']=api_get_setting('default_forum_view'); $values['group_forum'] = $lastId; if ($category['forum_state'] == '1') { - $values['public_private_group_forum_group']['public_private_group_forum'] = 'public'; + $values['public_private_group_forum_group']['public_private_group_forum']='public'; } elseif ($category['forum_state'] == '2') { - $values['public_private_group_forum_group']['public_private_group_forum'] = 'private'; + $values['public_private_group_forum_group']['public_private_group_forum']='private'; } elseif ($category['forum_state'] == '0') { - $values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable'; + $values['public_private_group_forum_group']['public_private_group_forum']='unavailable'; } store_forum($values); } @@ -297,7 +274,6 @@ class GroupManager return $lastId; } - /** * Create subgroups. * This function creates new groups based on an existing group. It will @@ -312,12 +288,12 @@ class GroupManager $table_group = Database :: get_course_table(TABLE_GROUP); $category_id = self :: create_category('Subgroups', '', self::TOOL_PRIVATE, self::TOOL_PRIVATE, 0, 0, 1, 1); $users = self :: get_users($group_id); - $group_ids = array(); + $group_ids = array (); - for ($group_nr = 1; $group_nr <= $number_of_groups; $group_nr++) { + for ($group_nr = 1; $group_nr <= $number_of_groups; $group_nr ++) { $group_ids[] = self :: create_group('SUBGROUP '.$group_nr, $category_id, 0, 0); } - $members = array(); + $members = array (); foreach ($users as $index => $user_id) { self :: subscribe_users($user_id, $group_ids[$index % $number_of_groups]); $members[$group_ids[$index % $number_of_groups]]++; @@ -328,25 +304,57 @@ class GroupManager } } + /** + * Create groups from all virtual courses in the given course. + * @deprecated + */ + public static function create_groups_from_virtual_courses() + { + self :: delete_category(self::VIRTUAL_COURSE_CATEGORY); + $id = self :: create_category(get_lang('GroupsFromVirtualCourses'), '', self::TOOL_NOT_AVAILABLE, self::TOOL_NOT_AVAILABLE, 0, 0, 1, 1); + $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); + $course_id = api_get_course_int_id(); + + $sql = "UPDATE ".$table_group_cat." SET id=".self::VIRTUAL_COURSE_CATEGORY." WHERE c_id = $course_id AND id=$id"; + Database::query($sql); + $course = api_get_course_info(); + $course['code'] = $course['sysCode']; + $course['title'] = $course['name']; + $virtual_courses = CourseManager :: get_virtual_courses_linked_to_real_course($course['sysCode']); + $group_courses = $virtual_courses; + $group_courses[] = $course; + $ids = array (); + foreach ($group_courses as $index => $group_course) { + $users = CourseManager :: get_user_list_from_course_code($group_course['code']); + $members = array (); + foreach ($users as $index => $user) { + if ($user['status'] == 5 && $user['tutor_id'] == 0) { + $members[] = $user['user_id']; + } + } + $id = self :: create_group($group_course['code'], self::VIRTUAL_COURSE_CATEGORY, 0, count($members)); + self :: subscribe_users($members, $id); + $ids[] = $id; + } + return $ids; + } + /** * Create a group for every class subscribed to the current course - * @param int $category_id The category in which the groups should be - * created + * @param int $category_id The category in which the groups should be created */ public static function create_class_groups($category_id) { - $_course = api_get_course_info(); - $options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id()); + $options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id()); $obj = new UserGroup(); $classes = $obj->get_usergroup_in_course($options); $group_ids = array(); - foreach ($classes as $index => $class) { + foreach ($classes as $class) { $users_ids = $obj->get_users_by_usergroup($class['id']); - $group_id = self::create_group($class['name'], $category_id, 0, count($users_ids)); - self::subscribe_users($users_ids, $group_id); + $group_id = self::create_group($class['name'],$category_id,0,count($users_ids)); + self::subscribe_users($users_ids,$group_id); $group_ids[] = $group_id; } - return $group_ids; } @@ -363,20 +371,20 @@ class GroupManager public static function delete_groups($group_ids, $course_code = null) { $course_info = api_get_course_info($course_code); - $course_id = $course_info['real_id']; + $course_id = $course_info['real_id']; // Database table definitions - $group_table = Database :: get_course_table(TABLE_GROUP); - $forum_table = Database :: get_course_table(TABLE_FORUM); + $group_table = Database :: get_course_table(TABLE_GROUP); + $forum_table = Database :: get_course_table(TABLE_FORUM); - $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); + $group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); $group_ids = array_map('intval', $group_ids); - if (api_is_course_coach()) { - //a coach can only delete courses from his session - for ($i = 0; $i < count($group_ids); $i++) { + if (!api_is_platform_admin() && api_is_course_coach()) { + // A coach can only delete courses from his session + 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); + array_splice($group_ids, $i , 1); $i--; } } @@ -387,21 +395,17 @@ class GroupManager // Unsubscribe all users self :: unsubscribe_all_users($group_ids); - $sql = "SELECT id, secret_directory, session_id FROM $group_table WHERE c_id = $course_id AND id IN (".implode( - ' , ', - $group_ids - ).")"; + + $sql = "SELECT iid, secret_directory, session_id + FROM $group_table + WHERE c_id = $course_id AND iid IN (".implode(' , ', $group_ids).")"; $db_result = Database::query($sql); - $forum_ids = array(); while ($group = Database::fetch_object($db_result)) { // move group-documents to garbage - //$source_directory = api_get_path(SYS_COURSE_PATH).$course['path']."/group/".$group->secret_directory; $source_directory = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory; //File to renamed - $destination_dir = api_get_path( - SYS_COURSE_PATH - ).$course_info['path']."/document".$group->secret_directory.'_DELETED_'.$group->id; + $destination_dir = api_get_path(SYS_COURSE_PATH).$course_info['path']."/document".$group->secret_directory.'_DELETED_'.$group->iid; if (!empty($group->secret_directory)) { //Deleting from document tool @@ -409,26 +413,22 @@ class GroupManager if (file_exists($source_directory)) { if (api_get_setting('permanently_remove_deleted_files') == 'true') { - //Delete - FileManager::my_delete($source_directory); + // Delete + my_delete($source_directory); } else { - //Rename + // Rename rename($source_directory, $destination_dir); } } } - //$forum_ids[] = $group->forum_id; } // delete the groups - $sql = "DELETE FROM ".$group_table." WHERE c_id = $course_id AND id IN ('".implode("' , '", $group_ids)."')"; - Database::query($sql); + $sql = "DELETE FROM ".$group_table." WHERE c_id = $course_id AND iid IN ('".implode("' , '", $group_ids)."')"; + $result = Database::query($sql); - $sql2 = "DELETE FROM ".$forum_table." WHERE c_id = $course_id AND forum_of_group IN ('".implode( - "' , '", - $group_ids - )."')"; - $result = Database::query($sql2); + $sql = "DELETE FROM ".$forum_table." WHERE c_id = $course_id AND forum_of_group IN ('".implode("' , '", $group_ids)."')"; + Database::query($sql); return Database::affected_rows($result); } @@ -447,33 +447,89 @@ class GroupManager $result = array(); $table_group = Database :: get_course_table(TABLE_GROUP); - $sql = "SELECT * FROM $table_group WHERE c_id = $course_id AND id = ".intval($group_id); + $sql = "SELECT * FROM $table_group WHERE c_id = $course_id AND iid = ".intval($group_id); $db_result = Database::query($sql); $db_object = Database::fetch_object($db_result); - $result['id'] = $db_object->id; - $result['name'] = $db_object->name; - $result['tutor_id'] = isset($db_object->tutor_id) ? $db_object->tutor_id : null; - $result['description'] = $db_object->description; - $result['maximum_number_of_students'] = $db_object->max_student; - $result['doc_state'] = $db_object->doc_state; - $result['work_state'] = $db_object->work_state; - $result['calendar_state'] = $db_object->calendar_state; - $result['announcements_state'] = $db_object->announcements_state; - $result['forum_state'] = $db_object->forum_state; - $result['wiki_state'] = $db_object->wiki_state; - $result['chat_state'] = $db_object->chat_state; - $result['directory'] = $db_object->secret_directory; - $result['self_registration_allowed'] = $db_object->self_registration_allowed; - $result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed; - - $result['count_users'] = count(self::get_subscribed_users($group_id)); - $result['count_tutor'] = count(self::get_subscribed_tutors($group_id)); + $result['id'] = $db_object->iid; + $result['name'] = $db_object->name; + $result['tutor_id'] = isset($db_object->tutor_id)?$db_object->tutor_id:null; + $result['description'] = $db_object->description; + $result['maximum_number_of_students'] = $db_object->max_student; + $result['max_student'] = $db_object->max_student; + $result['doc_state'] = $db_object->doc_state; + $result['work_state'] = $db_object->work_state; + $result['calendar_state'] = $db_object->calendar_state; + $result['announcements_state'] = $db_object->announcements_state; + $result['forum_state'] = $db_object->forum_state; + $result['wiki_state'] = $db_object->wiki_state; + $result['chat_state'] = $db_object->chat_state; + $result['directory'] = $db_object->secret_directory; + $result['self_registration_allowed'] = $db_object->self_registration_allowed; + $result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed; + + $result['count_users'] = count(self::get_subscribed_users($group_id)); + $result['count_tutor'] = count(self::get_subscribed_tutors($group_id)); $result['count_all'] = $result['count_users'] + $result['count_tutor']; return $result; } + /** + * @param string $name + * @param string $courseCode + * @return array + */ + public static function getGroupByName($name, $courseCode = null) + { + $name = trim($name); + + if (empty($name)) { + return array(); + } + + $course_info = api_get_course_info($courseCode); + $course_id = $course_info['real_id']; + $name = Database::escape_string($name); + $table_group = Database::get_course_table(TABLE_GROUP); + $sql = "SELECT * FROM $table_group + WHERE c_id = $course_id AND name = '$name' LIMIT 1"; + $res = Database::query($sql); + $group = array(); + if (Database::num_rows($res)) { + $group = Database::fetch_array($res, 'ASSOC'); + } + return $group; + } + + /** + * @param int $courseId + * @param int $categoryId + * @param string $name + * @return array + */ + public static function getGroupListFilterByName($name, $categoryId, $courseId) + { + $name = trim($name); + if (empty($name)) { + return array(); + } + $name = Database::escape_string($name); + $courseId = intval($courseId); + $table_group = Database::get_course_table(TABLE_GROUP); + $sql = "SELECT * FROM $table_group + WHERE c_id = $courseId AND name LIKE '%$name%'"; + + if (!empty($categoryId)) { + $categoryId = intval($categoryId); + $sql .= " AND category_id = $categoryId"; + } + $sql .= " ORDER BY name"; + $result = Database::query($sql); + return Database::store_result($result, 'ASSOC'); + } + + /** * Set group properties * Changes the group's properties. @@ -512,39 +568,36 @@ class GroupManager //$forum_id = get_forums_of_group($group_id); $group_id = Database::escape_string($group_id); $category = self::get_category_from_group($group_id); - if ($maximum_number_of_students > $category['max_student'] && $category['max_student'] != 0) { - $maximum_number_of_students = $category['max_student']; - } + $course_id = api_get_course_int_id(); - $sql = "UPDATE ".$table_group." - SET name='".Database::escape_string(trim($name))."', - doc_state = '".Database::escape_string($doc_state)."', - work_state = '".Database::escape_string($work_state)."', - calendar_state = '".Database::escape_string($calendar_state)."', - announcements_state = '".Database::escape_string($announcements_state)."', - forum_state = '".Database::escape_string($forum_state)."', - wiki_state = '".Database::escape_string($wiki_state)."', - chat_state = '".Database::escape_string($chat_state)."', - description='".Database::escape_string(trim($description))."', - max_student=".Database::escape_string($maximum_number_of_students).", - self_registration_allowed='".Database::escape_string($self_registration_allowed)."', - self_unregistration_allowed='".Database::escape_string($self_unregistration_allowed)."' - WHERE c_id = $course_id AND id=".$group_id; + $sql = "UPDATE ".$table_group." SET + name='".Database::escape_string(trim($name))."', + doc_state = '".Database::escape_string($doc_state)."', + work_state = '".Database::escape_string($work_state)."', + calendar_state = '".Database::escape_string($calendar_state)."', + announcements_state = '".Database::escape_string($announcements_state)."', + forum_state = '".Database::escape_string($forum_state)."', + wiki_state = '".Database::escape_string($wiki_state)."', + chat_state = '".Database::escape_string($chat_state)."', + description='".Database::escape_string(trim($description))."', + max_student= '".Database::escape_string($maximum_number_of_students)."', + self_registration_allowed='".Database::escape_string($self_registration_allowed)."', + self_unregistration_allowed='".Database::escape_string($self_unregistration_allowed)."' + WHERE c_id = $course_id AND id=".$group_id; $result = Database::query($sql); //Here we are updating a field in the table forum_forum that perhaps duplicates the table group_info.forum_state cvargas - $forum_state = (int)$forum_state; + $forum_state = (int) $forum_state; $sql2 = "UPDATE ".$table_forum." SET "; - if ($forum_state === 1) { + if ($forum_state===1) { $sql2 .= " forum_group_public_private='public' "; - } elseif ($forum_state === 2) { + } elseif ($forum_state===2) { $sql2 .= " forum_group_public_private='private' "; - } elseif ($forum_state === 0) { + } elseif ($forum_state===0) { $sql2 .= " forum_group_public_private='unavailable' "; } - $sql2 .= " WHERE c_id = $course_id AND forum_of_group=".$group_id; - $result2 = Database::query($sql2); - + $sql2 .=" WHERE c_id = $course_id AND forum_of_group=".$group_id; + Database::query($sql2); return $result; } @@ -558,28 +611,27 @@ class GroupManager $table_group = Database :: get_course_table(TABLE_GROUP); $res = Database::query("SELECT COUNT(id) AS number_of_groups FROM $table_group WHERE c_id = $course_id "); $obj = Database::fetch_object($res); - return $obj->number_of_groups; } - //GROUPCATEGORY FUNCTIONS + // GROUP CATEGORY FUNCTIONS /** * Get all categories - * @param string $course_code The cours (default = current course) + * @param string $course_code The course (default = current course) + * @return array */ public static function get_categories($course_code = null) { $course_info = api_get_course_info($course_code); - $course_id = $course_info['real_id']; + $course_id = $course_info['real_id']; $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); $sql = "SELECT * FROM $table_group_cat WHERE c_id = $course_id ORDER BY display_order"; $res = Database::query($sql); - $cats = array(); + $cats = array (); while ($cat = Database::fetch_array($res)) { $cats[] = $cat; } - return $cats; } @@ -587,6 +639,7 @@ class GroupManager * Get a group category * @param int $id The category id * @param string $course_code The course (default = current course) + * @return array */ public static function get_category($id, $course_code = null) { @@ -594,15 +647,42 @@ class GroupManager return array(); } $course_info = api_get_course_info($course_code); - $course_id = $course_info['real_id']; + $course_id = $course_info['real_id']; $id = Database::escape_string($id); $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); $sql = "SELECT * FROM $table_group_cat WHERE c_id = $course_id AND id = $id LIMIT 1"; $res = Database::query($sql); - return Database::fetch_array($res); } + /** + * Get a group category + * @param string $title + * @param string $course_code The course (default = current course) + * @return array + */ + public static function getCategoryByTitle($title, $course_code = null) + { + $title = trim($title); + + if (empty($title)) { + return array(); + } + + $course_info = api_get_course_info($course_code); + $course_id = $course_info['real_id']; + $title = Database::escape_string($title); + $table_group_cat = Database::get_course_table(TABLE_GROUP_CATEGORY); + $sql = "SELECT * FROM $table_group_cat + WHERE c_id = $course_id AND title = '$title' LIMIT 1"; + $res = Database::query($sql); + $category = array(); + if (Database::num_rows($res)) { + $category = Database::fetch_array($res, 'ASSOC'); + } + return $category; + } + /** * Get the unique category of a given group * @param int $group_id The id of the group @@ -612,27 +692,26 @@ class GroupManager */ public static function get_category_from_group($group_id, $course_code = null) { - $table_group = Database :: get_course_table(TABLE_GROUP); - $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); + $table_group = Database :: get_course_table(TABLE_GROUP); + $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); if (empty($group_id)) { return array(); } $course_info = api_get_course_info($course_code); - $course_id = $course_info['real_id']; + $course_id = $course_info['real_id']; $group_id = Database::escape_string($group_id); $sql = "SELECT gc.* FROM $table_group_cat gc, $table_group g - WHERE gc.c_id = $course_id AND - g.c_id = $course_id AND - gc.id = g.category_id AND g.id= $group_id LIMIT 1"; + WHERE gc.c_id = $course_id AND + g.c_id = $course_id AND + gc.id = g.category_id AND g.id= $group_id LIMIT 1"; $res = Database::query($sql); $cat = array(); if (Database::num_rows($res)) { $cat = Database::fetch_array($res); } - return $cat; } @@ -645,15 +724,15 @@ class GroupManager public static function delete_category($cat_id, $course_code = null) { $course_info = api_get_course_info($course_code); - $course_id = $course_info['real_id']; + $course_id = $course_info['real_id']; - $table_group = Database :: get_course_table(TABLE_GROUP); - $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); - $cat_id = Database::escape_string($cat_id); + $table_group = Database :: get_course_table(TABLE_GROUP); + $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); + $cat_id = Database::escape_string($cat_id); $sql = "SELECT id FROM $table_group WHERE c_id = $course_id AND category_id='".$cat_id."'"; $res = Database::query($sql); if (Database::num_rows($res) > 0) { - $groups_to_delete = array(); + $groups_to_delete = array (); while ($group = Database::fetch_object($res)) { $groups_to_delete[] = $group->id; } @@ -698,42 +777,48 @@ class GroupManager $obj->new_order = 1; } $sql = "INSERT INTO ".$table_group_category." SET - c_id = $course_id , - title='".Database::escape_string($title)."', - display_order ='".$obj->new_order."', - description='".Database::escape_string($description)."', - doc_state = '".Database::escape_string($doc_state)."', - work_state = '".Database::escape_string($work_state)."', - calendar_state = '".Database::escape_string($calendar_state)."', - announcements_state = '".Database::escape_string($announcements_state)."', - forum_state = '".Database::escape_string($forum_state)."', - wiki_state = '".Database::escape_string($wiki_state)."', - chat_state = '".Database::escape_string($chat_state)."', - groups_per_user = '".Database::escape_string($groups_per_user)."', - self_reg_allowed = '".Database::escape_string($self_registration_allowed)."', - self_unreg_allowed = '".Database::escape_string($self_unregistration_allowed)."', - max_student = '".Database::escape_string($maximum_number_of_students)."' "; + c_id = $course_id , + title='".Database::escape_string($title)."', + display_order ='".$obj->new_order."', + description='".Database::escape_string($description)."', + doc_state = '".Database::escape_string($doc_state)."', + work_state = '".Database::escape_string($work_state)."', + calendar_state = '".Database::escape_string($calendar_state)."', + announcements_state = '".Database::escape_string($announcements_state)."', + forum_state = '".Database::escape_string($forum_state)."', + wiki_state = '".Database::escape_string($wiki_state)."', + chat_state = '".Database::escape_string($chat_state)."', + groups_per_user = '".Database::escape_string($groups_per_user)."', + self_reg_allowed = '".Database::escape_string($self_registration_allowed)."', + self_unreg_allowed = '".Database::escape_string($self_unregistration_allowed)."', + max_student = '".Database::escape_string($maximum_number_of_students)."' "; Database::query($sql); - $id = Database::insert_id(); - if ($id == self::VIRTUAL_COURSE_CATEGORY) { - $sql = "UPDATE ".$table_group_category." SET id = ".($id + 1)." WHERE c_id = $course_id AND id = $id"; + $categoryId = Database::insert_id(); + if ($categoryId == self::VIRTUAL_COURSE_CATEGORY) { + $sql = "UPDATE ".$table_group_category." SET id = ". ($categoryId +1)." WHERE c_id = $course_id AND id = $categoryId"; Database::query($sql); - - return $id + 1; + return $categoryId +1; } - - return $id; + return $categoryId; } /** * Update group category - * @param int $id The id of the category - * @param string $title The title of the new category - * @param string $description The description of the new category - * @param bool $self_registration_allowed - * @param bool $self_unregistration_allowed - * @param int $max_number_of_students - * @param int $groups_per_user + * + * @param int $id + * @param string $title + * @param string $description + * @param $doc_state + * @param $work_state + * @param $calendar_state + * @param $announcements_state + * @param $forum_state + * @param $wiki_state + * @param $chat_state + * @param $self_registration_allowed + * @param $self_unregistration_allowed + * @param $maximum_number_of_students + * @param $groups_per_user */ public static function update_category( $id, @@ -751,41 +836,63 @@ class GroupManager $maximum_number_of_students, $groups_per_user ) { - $table_group_category = Database :: get_course_table(TABLE_GROUP_CATEGORY); + $table_group_category = Database::get_course_table(TABLE_GROUP_CATEGORY); $id = Database::escape_string($id); $course_id = api_get_course_int_id(); - $sql = "UPDATE ".$table_group_category." - SET title='".Database::escape_string($title)."', - description='".Database::escape_string($description)."', - doc_state = '".Database::escape_string($doc_state)."', - work_state = '".Database::escape_string($work_state)."', - calendar_state = '".Database::escape_string($calendar_state)."', - announcements_state = '".Database::escape_string($announcements_state)."', - forum_state = '".Database::escape_string($forum_state)."', - wiki_state = '".Database::escape_string($wiki_state)."', - chat_state = '".Database::escape_string($chat_state)."', - groups_per_user = ".Database::escape_string($groups_per_user).", - self_reg_allowed = '".Database::escape_string($self_registration_allowed)."', - self_unreg_allowed = '".Database::escape_string($self_unregistration_allowed)."', - max_student = ".Database::escape_string($maximum_number_of_students)." - WHERE c_id = $course_id AND id=$id"; + $sql = "UPDATE ".$table_group_category."SET + title='".Database::escape_string($title)."', + description='".Database::escape_string($description)."', + doc_state = '".Database::escape_string($doc_state)."', + work_state = '".Database::escape_string($work_state)."', + calendar_state = '".Database::escape_string($calendar_state)."', + announcements_state = '".Database::escape_string($announcements_state)."', + forum_state = '".Database::escape_string($forum_state)."', + wiki_state = '".Database::escape_string($wiki_state)."', + chat_state = '".Database::escape_string($chat_state)."', + groups_per_user = '".Database::escape_string($groups_per_user)."', + self_reg_allowed = '".Database::escape_string($self_registration_allowed)."', + self_unreg_allowed = '".Database::escape_string($self_unregistration_allowed)."', + max_student = ".Database::escape_string($maximum_number_of_students)." + WHERE c_id = $course_id AND id = $id"; Database::query($sql); - } + // Updating all groups inside this category + $groups = self::get_group_list($id); + + if (!empty($groups)) { + foreach ($groups as $group) { + GroupManager::set_group_properties( + $group['id'], + $group['name'], + $group['description'], + $maximum_number_of_students, + $doc_state, + $work_state, + $calendar_state, + $announcements_state, + $forum_state, + $wiki_state, + $chat_state, + $self_registration_allowed, + $self_unregistration_allowed + ); + } + } + } /** * Returns the number of groups of the user with the greatest number of - * subscribtions in the given category + * subscriptions in the given category */ public static function get_current_max_groups_per_user($category_id = null, $course_code = null) { - $course_info = api_get_course_info($course_code); + $course_info = api_get_course_info ($course_code); $group_table = Database :: get_course_table(TABLE_GROUP); $group_user_table = Database :: get_course_table(TABLE_GROUP_USER); $sql = 'SELECT COUNT(gu.group_id) AS current_max FROM '.$group_user_table.' gu, '.$group_table.' g - WHERE g.c_id = '.$course_info['real_id'].' AND gu.group_id = g.id '; + WHERE g.c_id = '.$course_info['real_id'].' AND gu.group_id = g.id '; if ($category_id != null) { $category_id = Database::escape_string($category_id); $sql .= ' AND g.category_id = '.$category_id; @@ -793,7 +900,6 @@ class GroupManager $sql .= ' GROUP BY gu.user_id ORDER BY current_max DESC LIMIT 1'; $res = Database::query($sql); $obj = Database::fetch_object($res); - return $obj->current_max; } @@ -821,25 +927,22 @@ class GroupManager Database::query($sql); } - //GROUP USERS FUNCTIONS + // GROUP USERS FUNCTIONS /** * Get all users from a given group * @param int $group_id The group + * @param bool $load_extra_info * @return array list of user id */ - public static function get_users($group_id, $load_extra_info = false, $course_id = null) + public static function get_users($group_id, $load_extra_info = false) { $group_user_table = Database :: get_course_table(TABLE_GROUP_USER); $group_id = Database::escape_string($group_id); - if (empty($course_id)) { - $course_id = api_get_course_int_id(); - } else { - $course_id = intval($course_id); - } + $course_id = api_get_course_int_id(); $sql = "SELECT user_id FROM $group_user_table WHERE c_id = $course_id AND group_id = $group_id"; $res = Database::query($sql); - $users = array(); + $users = array (); while ($obj = Database::fetch_object($res)) { if ($load_extra_info) { $users[] = api_get_user_info($obj->user_id); @@ -847,7 +950,6 @@ class GroupManager $users[] = $obj->user_id; } } - return $users; } @@ -855,7 +957,7 @@ class GroupManager * @param int $group_id * @return array */ - public static function get_members_and_tutors($group_id) + public static function getStudentsAndTutors($group_id) { $group_user_table = Database :: get_course_table(TABLE_GROUP_USER); $tutor_user_table = Database :: get_course_table(TABLE_GROUP_TUTOR); @@ -874,7 +976,45 @@ class GroupManager while ($obj = Database::fetch_object($res)) { $users[] = api_get_user_info($obj->user_id); } + return $users; + } + + /** + * Get only tutors from a group + * @param int $group_id + * @return array + */ + public static function getTutors($group_id) + { + $tutor_user_table = Database :: get_course_table(TABLE_GROUP_TUTOR); + $course_id = api_get_course_int_id(); + $group_id = intval($group_id); + $sql = "SELECT user_id FROM $tutor_user_table WHERE c_id = $course_id AND group_id = $group_id"; + $res = Database::query($sql); + while ($obj = Database::fetch_object($res)) { + $users[] = api_get_user_info($obj->user_id); + } + return $users; + } + + /** + * Get only students from a group (not tutors) + * @param int $group_id + * @return array + */ + public static function getStudents($group_id) + { + $group_user_table = Database :: get_course_table(TABLE_GROUP_USER); + $course_id = api_get_course_int_id(); + $group_id = intval($group_id); + $sql = "SELECT user_id FROM $group_user_table WHERE c_id = $course_id AND group_id = $group_id"; + $res = Database::query($sql); + $users = array(); + + while ($obj = Database::fetch_object($res)) { + $users[] = api_get_user_info($obj->user_id); + } return $users; } @@ -891,7 +1031,7 @@ class GroupManager $course_id = api_get_course_int_id(); $groups = array_map('intval', $groups); - $groups = implode(', ', $groups); //protect individual elements with surrounding quotes + $groups = implode(', ', $groups); //protect individual elements with surrounding quotes $sql = "SELECT DISTINCT user_id FROM $tbl_group_user gu WHERE c_id = $course_id AND gu.group_id IN ($groups)"; @@ -899,7 +1039,6 @@ class GroupManager while ($row = Database::fetch_array($rs)) { $result[] = $row['user_id']; } - return $result; } @@ -928,29 +1067,29 @@ class GroupManager */ public static function fill_groups($group_ids) { - $_course = api_get_course_info(); + global $_course; - $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); + $group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); $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); + 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) { + if (count($group_ids)==0) { return false; } } - $category = self::get_category_from_group($group_ids[0]); + $category = self::get_category_from_group($group_ids[0]); - $groups_per_user = $category['groups_per_user']; - $group_table = Database :: get_course_table(TABLE_GROUP); - $group_user_table = Database :: get_course_table(TABLE_GROUP_USER); - $session_id = api_get_session_id(); + $groups_per_user = $category['groups_per_user']; + $group_table = Database :: get_course_table(TABLE_GROUP); + $group_user_table = Database :: get_course_table(TABLE_GROUP_USER); + $session_id = api_get_session_id(); $complete_user_list = CourseManager :: get_real_and_linked_user_list($_course['code'], true, $session_id); $number_groups_per_user = ($groups_per_user == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $groups_per_user); @@ -962,14 +1101,14 @@ class GroupManager $course_id = api_get_course_int_id(); $sql = "SELECT g.id gid, g.max_student-count(ug.user_id) nbPlaces, g.max_student - FROM ".$group_table." g - LEFT JOIN ".$group_user_table." ug ON + FROM ".$group_table." g + LEFT JOIN ".$group_user_table." ug ON g.c_id = $course_id AND ug.c_id = $course_id AND g.id = ug.group_id - WHERE - g.id IN (".implode(',', $group_ids).") - GROUP BY (g.id) - HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.") - ORDER BY nbPlaces DESC"; + WHERE + g.id IN (".implode(',', $group_ids).") + GROUP BY (g.id) + HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.") + ORDER BY nbPlaces DESC"; $sql_result = Database::query($sql); $group_available_place = array(); while ($group = Database::fetch_array($sql_result, 'ASSOC')) { @@ -980,7 +1119,7 @@ class GroupManager * Retrieve course users (reverse) ordered by the number * of group they are already enrolled */ - 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 $number_of_groups = self :: user_in_number_of_groups($complete_user_list[$i]["user_id"], $category['id']); //add # of groups to user list @@ -994,7 +1133,7 @@ class GroupManager //now sort by # of group left $complete_user_list = TableSort :: sort_table($complete_user_list, 'number_groups_left', SORT_DESC); - $userToken = array(); + $userToken = array (); foreach ($complete_user_list as $this_user) { if ($this_user['number_groups_left'] > 0) { $userToken[$this_user['user_id']] = $this_user['number_groups_left']; @@ -1012,10 +1151,8 @@ class GroupManager foreach ($group_available_place as $group_id => $place) { foreach ($userToken as $user_id => $places) { if (self :: can_user_subscribe($user_id, $group_id)) { - self :: subscribe_users($user_id, $group_id); $group_available_place[$group_id]--; - //$userToken[$user_id]--; unset($userToken[$user_id]); $changed = true; break; @@ -1028,7 +1165,6 @@ class GroupManager } } - /** * Get the number of students in a group. * @param int $group_id @@ -1046,7 +1182,6 @@ class GroupManager $sql = "SELECT COUNT(*) AS number_of_students FROM $table_group_user WHERE c_id = $course_id AND group_id = $group_id"; $db_result = Database::query($sql); $db_object = Database::fetch_object($db_result); - return $db_object->number_of_students; } @@ -1065,7 +1200,6 @@ class GroupManager if ($db_object->max_student == 0) { return self::INFINITE; } - return $db_object->max_student; } @@ -1076,10 +1210,10 @@ class GroupManager */ public static function user_in_number_of_groups($user_id, $cat_id = null) { - $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); - $table_group = Database :: get_course_table(TABLE_GROUP); - $user_id = Database::escape_string($user_id); - $cat_id = Database::escape_string($cat_id); + $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); + $table_group = Database :: get_course_table(TABLE_GROUP); + $user_id = Database::escape_string($user_id); + $cat_id = Database::escape_string($cat_id); $course_id = api_get_course_int_id(); $cat_condition = ''; @@ -1088,13 +1222,12 @@ class GroupManager } $sql = "SELECT COUNT(*) AS number_of_groups FROM $table_group_user gu, $table_group g - WHERE gu.c_id = $course_id AND - g.c_id = $course_id AND - gu.user_id = $user_id AND - g.id = gu.group_id $cat_condition"; + WHERE gu.c_id = $course_id AND + g.c_id = $course_id AND + gu.user_id = $user_id AND + g.id = gu.group_id $cat_condition"; $db_result = Database::query($sql); $db_object = Database::fetch_object($db_result); - return $db_object->number_of_groups; } @@ -1113,10 +1246,9 @@ class GroupManager $table_group = Database :: get_course_table(TABLE_GROUP); $group_id = intval($group_id); if (isset($group_id)) { - $sql = "SELECT self_registration_allowed FROM $table_group WHERE c_id = $course_id AND id = $group_id"; + $sql = "SELECT self_registration_allowed FROM $table_group WHERE c_id = $course_id AND iid = $group_id"; $db_result = Database::query($sql); $db_object = Database::fetch_object($db_result); - return $db_object->self_registration_allowed == 1 && self :: can_user_subscribe($user_id, $group_id); } else { return false; @@ -1138,7 +1270,7 @@ class GroupManager $group_id = Database::escape_string($group_id); $course_id = api_get_course_int_id(); $db_result = Database::query( - 'SELECT self_unregistration_allowed FROM '.$table_group.' WHERE c_id = '.$course_id.' AND id = '.$group_id + 'SELECT self_unregistration_allowed FROM '.$table_group.' WHERE c_id = '.$course_id.' AND iid = '.$group_id ); $db_object = Database::fetch_object($db_result); @@ -1196,12 +1328,11 @@ class GroupManager public static function can_user_unsubscribe($user_id, $group_id) { $result = self :: is_subscribed($user_id, $group_id); - return $result; } /** - * Get all subscribed users from a group + * Get all subscribed users (students and tutors) from a group * @param int $group_id * @return array An array with information of all users from the given group. * (user_id, firstname, lastname, email) @@ -1210,8 +1341,7 @@ class GroupManager { $table_user = Database :: get_main_table(TABLE_MAIN_USER); $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); - $order_clause = api_sort_by_first_name( - ) ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname'; + $order_clause = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname'; if (empty($group_id)) { return array(); } @@ -1219,21 +1349,20 @@ class GroupManager $course_id = api_get_course_int_id(); $sql = "SELECT ug.id, u.user_id, u.lastname, u.firstname, u.email, u.username - FROM $table_user u INNER JOIN $table_group_user ug ON (ug.user_id = u.user_id) - WHERE ug.c_id = $course_id AND - ug.group_id = $group_id + FROM $table_user u INNER JOIN $table_group_user ug ON (ug.user_id = u.user_id) + WHERE ug.c_id = $course_id AND + ug.group_id = $group_id $order_clause"; $db_result = Database::query($sql); $users = array(); while ($user = Database::fetch_object($db_result)) { - $member['user_id'] = $user->user_id; + $member['user_id'] = $user->user_id; $member['firstname'] = $user->firstname; - $member['lastname'] = $user->lastname; - $member['email'] = $user->email; - $member['username'] = $user->username; + $member['lastname'] = $user->lastname; + $member['email'] = $user->email; + $member['username'] = $user->username; $users[$member['user_id']] = $member; } - return $users; } @@ -1254,12 +1383,12 @@ class GroupManager $course_id = api_get_course_int_id(); $sql = "SELECT tg.id, u.user_id, u.lastname, u.firstname, u.email - FROM ".$table_user." u, ".$table_group_tutor." tg - WHERE tg.c_id = $course_id AND - tg.group_id='".$group_id."' AND - tg.user_id=u.user_id".$order_clause; + FROM ".$table_user." u, ".$table_group_tutor." tg + WHERE tg.c_id = $course_id AND + tg.group_id='".$group_id."' AND + tg.user_id=u.user_id".$order_clause; $db_result = Database::query($sql); - $users = array(); + $users = array (); while ($user = Database::fetch_object($db_result)) { if (!$id_only) { $member['user_id'] = $user->user_id; @@ -1268,10 +1397,9 @@ class GroupManager $member['email'] = $user->email; $users[] = $member; } else { - $users[] = $user->user_id; + $users[]=$user->user_id; } } - return $users; } @@ -1291,11 +1419,11 @@ class GroupManager foreach ($user_ids as $user_id) { $user_id = Database::escape_string($user_id); $group_id = Database::escape_string($group_id); - $sql = "INSERT INTO ".$table_group_user." (c_id, user_id, group_id) VALUES ('$course_id', '".$user_id."', '".$group_id."')"; + $sql = "INSERT INTO ".$table_group_user." (c_id, user_id, group_id) + VALUES ('$course_id', '".$user_id."', '".$group_id."')"; $result &= Database::query($sql); } } - return $result; } @@ -1314,13 +1442,13 @@ class GroupManager $course_id = api_get_course_int_id(); $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); - foreach ($user_ids as $index => $user_id) { + foreach ($user_ids as $user_id) { $user_id = Database::escape_string($user_id); $group_id = Database::escape_string($group_id); - $sql = "INSERT INTO ".$table_group_tutor." (c_id, user_id, group_id) VALUES ('$course_id', '".$user_id."', '".$group_id."')"; + $sql = "INSERT INTO ".$table_group_tutor." (c_id, user_id, group_id) + VALUES ('$course_id', '".$user_id."', '".$group_id."')"; $result &= Database::query($sql); } - return $result; } @@ -1332,22 +1460,18 @@ class GroupManager */ public static function unsubscribe_users($user_ids, $group_id) { - $user_ids = is_array($user_ids) ? $user_ids : array($user_ids); + $user_ids = is_array($user_ids) ? $user_ids : array ($user_ids); $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); $group_id = Database::escape_string($group_id); $course_id = api_get_course_int_id(); - - $result &= Database::query( - 'DELETE FROM '.$table_group_user.' WHERE c_id = '.$course_id.' AND group_id = '.$group_id.' AND user_id IN ('.implode( - ',', - $user_ids - ).')' - ); + $sql = 'DELETE FROM '.$table_group_user.' + WHERE c_id = '.$course_id.' AND group_id = '.$group_id.' AND user_id IN ('.implode(',', $user_ids).')'; + Database::query($sql); } /** * 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 array $group_id Can be an array with group-id's or a single group-id * @return bool TRUE if successfull */ public static function unsubscribe_all_users($group_ids) @@ -1369,15 +1493,10 @@ class GroupManager } } $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; + $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 true; } @@ -1394,15 +1513,10 @@ class GroupManager $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); if (count($group_ids) > 0) { $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); - $sql = 'DELETE FROM '.$table_group_tutor.' WHERE group_id IN ('.implode( - ',', - $group_ids - ).') AND c_id = '.$course_id; + $sql = 'DELETE FROM '.$table_group_tutor.' WHERE group_id IN ('.implode(',', $group_ids).') AND c_id = '.$course_id; $result = Database::query($sql); - return $result; } - return true; } @@ -1416,8 +1530,6 @@ class GroupManager */ public static function is_tutor_of_group($user_id, $group_id) { - $_course = api_get_course_info(); - $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); $user_id = Database::escape_string($user_id); $group_id = Database::escape_string($group_id); @@ -1472,7 +1584,6 @@ class GroupManager while ($tutor = Database::fetch_array($resultTutor)) { $tutors[] = $tutor; } - return $tutors; } @@ -1540,6 +1651,77 @@ class GroupManager Group functions - these take virtual/linked courses into account when necessary */ + /** + * 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) { + global $_course, $_user; + $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 = Database :: get_course_info($real_course_code); + $real_course_user_list = CourseManager :: get_user_list_from_course_code($real_course_code); + //get list of all virtual courses + $user_subscribed_course_list = CourseManager :: get_list_of_virtual_courses_for_specific_user_and_real_course($_user['user_id'], $real_course_code); + //add real course to the list + $user_subscribed_course_list[] = $real_course_info; + if (!is_array($user_subscribed_course_list)) { + return; + } + //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']; + $tutor_id = $this_user['tutor_id']; + $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['tutor_id'] = $tutor_id; + $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 * by comparing field $compare_field. @@ -1558,10 +1740,8 @@ class GroupManager $user_array_out[$count_out] = $user_array_in[$count_in]; } } - return $user_array_out; } - /** * Filters from the array $user_array_in the users already in the group $group_id. */ @@ -1572,7 +1752,6 @@ class GroupManager $user_array_out[] = $this_user; } } - return $user_array_out; } @@ -1595,7 +1774,6 @@ class GroupManager } } } - return $user_array_out; } @@ -1611,11 +1789,12 @@ class GroupManager public static function user_has_access($user_id, $group_id, $tool) { - //Admin have access everywhere + // Admin have access everywhere if (api_is_platform_admin()) { return true; } - //Course admin also have access to everything + + // Course admin also have access to everything if (api_is_allowed_to_edit()) { return true; } @@ -1648,24 +1827,25 @@ class GroupManager $user_is_in_group = self :: is_user_in_group($user_id, $group_id); - //Check group properties + // Check group properties $group_info = self :: get_group_properties($group_id); - if (api_get_setting('allow_group_categories') == 'true') { - //Check group category if exists + /*if (api_get_setting('allow_group_categories') == 'true') { + + // Check if group category exists $category_group_info = self::get_category_from_group($group_id); if (!empty($category_group_info)) { - //if exists check the category group status first + // If exists check the category group status first if ($category_group_info[$state_key] == self::TOOL_NOT_AVAILABLE) { return false; - } elseif ($category_group_info[$state_key] == self::TOOL_PRIVATE && !$user_is_in_group) { + } elseif($category_group_info[$state_key] == self::TOOL_PRIVATE && !$user_is_in_group) { return false; } } - } + }*/ - //is_user_in_group() is more complete that the is_subscribed() function + // is_user_in_group() is more complete that the is_subscribed() function if ($group_info[$state_key] == self::TOOL_NOT_AVAILABLE) { return false; @@ -1701,24 +1881,23 @@ class GroupManager while ($group = Database::fetch_array($res)) { $groups[] .= $group['name']; } - return $groups; } /** - * fill_groups_list * - * see : fill_groups + * See : fill_groups * Fill the groups with students. * - * note : - * optimize fill_groups_list <--> fill_groups - * + * note : optimize fill_groups_list <--> fill_groups + * @param array $group_ids + * @return array|bool */ public static function fill_groups_list($group_ids) { $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); $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])) { @@ -1732,6 +1911,7 @@ class GroupManager } $_course = api_get_course_info(); + $category = self :: get_category_from_group($group_ids[0]); $groups_per_user = $category['groups_per_user']; @@ -1745,43 +1925,50 @@ class GroupManager * Retrieve all the groups where enrollment is still allowed * (reverse) ordered by the number of place available */ - $sql = "SELECT g.id gid, g.max_student - count(ug.user_id) nbPlaces, g.max_student + $sql = "SELECT g.id gid, count(ug.user_id) count_users, g.max_student FROM ".$group_table." g LEFT JOIN ".$group_user_table." ug ON g.id = ug.group_id WHERE g.c_id = $course_id AND ug.c_id = $course_id AND g.id IN (".implode(',', $group_ids).") - GROUP BY (g.id) - HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.") - ORDER BY nbPlaces DESC"; + GROUP BY (g.id)"; + $sql_result = Database::query($sql); $group_available_place = array(); while ($group = Database::fetch_array($sql_result, 'ASSOC')) { - $group_available_place[$group['gid']] = $group['nbPlaces']; + if (!empty($group['max_student'])) { + $places = intval($group['max_student'] - $group['count_users']); + } else { + $places = self::MEMBER_PER_GROUP_NO_LIMIT; + } + $group_available_place[$group['gid']] = $places; } /* * Retrieve course users (reverse) ordered by the number * of group they are already enrolled */ - 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 - $number_of_groups = self :: user_in_number_of_groups($complete_user_list[$i]["user_id"], $category['id']); + $number_of_groups = self :: user_in_number_of_groups($complete_user_list[$i]["user_id"],$category['id']); //add # of groups to user list $complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups; } //first sort by user_id to filter out duplicates - $complete_user_list = TableSort :: sort_table($complete_user_list, 'user_id'); - $complete_user_list = self :: filter_duplicates($complete_user_list, 'user_id'); - + $complete_user_list = TableSort::sort_table($complete_user_list, 'user_id'); + $complete_user_list = self::filter_duplicates($complete_user_list, 'user_id'); + //$complete_user_list = self :: filter_only_students($complete_user_list); //now sort by # of group left - $complete_user_list = TableSort :: sort_table($complete_user_list, 'number_groups_left', SORT_DESC); - + $complete_user_list = TableSort::sort_table($complete_user_list, 'number_groups_left', SORT_DESC); return $complete_user_list; } + /** + * @param array $group_list + * @param int $category_id + */ static function process_groups($group_list, $category_id = null) { global $origin, $charset; @@ -1797,7 +1984,7 @@ class GroupManager foreach ($group_list as $this_group) { - // Validacion when belongs to a session + // Validation when belongs to a session $session_img = api_get_session_image($this_group['session_id'], $user_info['status']); // All the tutors of this group @@ -1805,6 +1992,7 @@ class GroupManager // Create a new table-row $row = array(); + // Checkbox if (api_is_allowed_to_edit(false, true) && count($group_list) > 1) { $row[] = $this_group['id']; @@ -1812,21 +2000,19 @@ class GroupManager // Group name if ((api_is_allowed_to_edit(false, true) || - in_array($user_id, $tutorsids_of_group) || - $this_group['is_member'] || - self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_FORUM) || - self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_DOCUMENTS) || - self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_CALENDAR) || - self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_ANNOUNCEMENT) || - self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_WORK) || - self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_WIKI)) + in_array($user_id, $tutorsids_of_group) || + $this_group['is_member'] || + self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_FORUM) || + self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_DOCUMENTS) || + self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_CALENDAR) || + self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_ANNOUNCEMENT) || + self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_WORK) || + self::user_has_access($user_id, $this_group['id'], self::GROUP_TOOL_WIKI)) && !(api_is_course_coach() && intval($this_group['session_id']) != $session_id) ) { - $group_name = ''.Security::remove_XSS( - $this_group['name'] - ).' '; + $group_name = ''. + Security::remove_XSS($this_group['name']).' '; if (!empty($user_id) && !empty($this_group['id_tutor']) && $user_id == $this_group['id_tutor']) { $group_name .= Display::label(get_lang('OneMyGroups'), 'success'); } elseif ($this_group['is_member']) { @@ -1850,34 +2036,17 @@ class GroupManager $tutor = api_get_user_info($tutor_id); $username = api_htmlentities(sprintf(get_lang('LoginX'), $tutor['username']), ENT_QUOTES); if (api_get_setting('show_email_addresses') == 'true') { - $tutor_info .= Display::tag( - 'span', - Display::encrypted_mailto_link( - $tutor['mail'], - api_get_person_name($tutor['firstName'], $tutor['lastName']) - ), - array('title' => $username) - ).', '; + $tutor_info .= Display::tag('span', Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])), array('title'=>$username)).', '; } else { if (api_is_allowed_to_edit()) { - $tutor_info .= Display::tag( - 'span', - Display::encrypted_mailto_link( - $tutor['mail'], - api_get_person_name($tutor['firstName'], $tutor['lastName']) - ), - array('title' => $username) - ).', '; + $tutor_info .= Display::tag('span', Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])), array('title'=>$username)).', '; } else { - $tutor_info .= Display::tag( - 'span', - api_get_person_name($tutor['firstName'], $tutor['lastName']), - array('title' => $username) - ).', '; + $tutor_info .= Display::tag('span', api_get_person_name($tutor['firstName'], $tutor['lastName']), array('title'=>$username)).', '; } } } } + $tutor_info = api_substr($tutor_info, 0, api_strlen($tutor_info) - 2); $row[] = $tutor_info; @@ -1890,55 +2059,34 @@ class GroupManager // Self-registration / unregistration if (!api_is_allowed_to_edit(false, true)) { if (self :: is_self_registration_allowed($user_id, $this_group['id'])) { - $row[] = ''.get_lang('GroupSelfRegInf').''; + $row[] = ''.get_lang('GroupSelfRegInf').''; } elseif (self :: is_self_unregistration_allowed($user_id, $this_group['id'])) { - $row[] = ''.get_lang('GroupSelfUnRegInf').''; + $row[] = ''.get_lang('GroupSelfUnRegInf').''; } else { $row[] = '-'; } } - + $url = api_get_path(WEB_CODE_PATH).'group/'; // Edit-links - if (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && intval( - $this_group['session_id'] - ) != $session_id) - ) { - $edit_actions = ''.Display::return_icon( - 'edit.png', - get_lang('EditGroup'), - '', - ICON_SIZE_SMALL - ).' '; - $edit_actions .= ''. - Display::return_icon('clean.png', get_lang('EmptyGroup'), '', ICON_SIZE_SMALL).' '; - $edit_actions .= ''. - Display::return_icon('fill.png', get_lang('FillGroup'), '', ICON_SIZE_SMALL).' '; - $edit_actions .= ''. - Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).' '; + if (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && intval($this_group['session_id']) != $session_id)) { + $edit_actions = ''. + Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).' '; + + $edit_actions .= ''. + Display::return_icon('user.png', get_lang('GroupMembers'), '', ICON_SIZE_SMALL).' '; + + $edit_actions .= ''. + Display::return_icon('export_excel.png', get_lang('Export'), '', ICON_SIZE_SMALL).' '; + + /*$edit_actions .= ''. + Display::return_icon('clean.png',get_lang('EmptyGroup'),'',ICON_SIZE_SMALL).' ';*/ + + $edit_actions .= ''. + Display::return_icon('fill.png',get_lang('FillGroup'),'',ICON_SIZE_SMALL).' '; + + $edit_actions .= ''. + Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).' '; + $row[] = $edit_actions; } if (!empty($this_group['nbMember'])) { @@ -1947,14 +2095,8 @@ class GroupManager $group_data[] = $row; } // end loop - if (isset($_GET['show_all'])) { - $paging_options = array('per_page' => count($group_data)); - } else { - $paging_options = array(); - } $table = new SortableTableFromArrayConfig($group_data, 1, 20, 'group_category_'.$category_id); - //$my_cat = isset($_GET['category']) ? Security::remove_XSS($_GET['category']) : null; $table->set_additional_parameters(array('category' => $category_id)); $column = 0; if (api_is_allowed_to_edit(false, true) and count($group_list) > 1) { @@ -1979,4 +2121,343 @@ class GroupManager } $table->display(); } + + /** + * + * @param array $groupData + * @param bool $deleteNotInArray + * @return array + */ + public static function importCategoriesAndGroupsFromArray($groupData, $deleteNotInArray = false) + { + $result = array(); + $elementsFound = array( + 'categories' => array(), + 'groups' => array() + ); + + foreach ($groupData as $data) { + $isCategory = empty($data['group']) ? true : false; + + if ($isCategory) { + $categoryInfo = self::getCategoryByTitle($data['category']); + $categoryId = $categoryInfo['id']; + if (!empty($categoryInfo)) { + // Update + self::update_category( + $categoryId, + $data['category'], + $data['description'], + $data['doc_state'], + $data['work_state'], + $data['calendar_state'], + $data['announcements_state'], + $data['forum_state'], + $data['wiki_state'], + $data['chat_state'], + $data['self_reg_allowed'], + $data['self_unreg_allowed'], + $data['max_student'], + $data['groups_per_user'] + ); + $data['category_id'] = $categoryId; + $result['updated']['category'][] = $data; + } else { + // Add + $categoryId = self::create_category( + $data['category'], + $data['description'], + $data['doc_state'], + $data['work_state'], + $data['calendar_state'], + $data['announcements_state'], + $data['forum_state'], + $data['wiki_state'], + $data['chat_state'], + $data['self_reg_allowed'], + $data['self_unreg_allowed'], + $data['max_student'], + $data['groups_per_user'] + ); + + if ($categoryId) { + $data['category_id'] = $categoryId; + $result['added']['category'][] = $data; + } + } + $elementsFound['categories'][] = $categoryId; + } else { + + $groupInfo = self::getGroupByName($data['group']); + + if (empty($groupInfo)) { + $categoryInfo = self::getCategoryByTitle($data['category']); + $categoryId = null; + if (!empty($categoryInfo)) { + $categoryId = $categoryInfo['id']; + } + + // Add + $groupId = self::create_group( + $data['group'], + $categoryId, + null, + $data['max_students'] + ); + + if ($groupId) { + self::set_group_properties( + $groupId, + $data['group'], + $data['description'], + $data['max_students'], + $data['doc_state'], + $data['work_state'], + $data['calendar_state'], + $data['announcements_state'], + $data['forum_state'], + $data['wiki_state'], + $data['chat_state'], + $data['self_reg_allowed'], + $data['self_unreg_allowed'] + ); + $data['group_id'] = $groupId; + $result['added']['group'][] = $data; + } + } else { + // Update + $groupId = $groupInfo['id']; + self::set_group_properties( + $groupId, + $data['group'], + $data['description'], + $data['max_students'], + $data['doc_state'], + $data['work_state'], + $data['calendar_state'], + $data['announcements_state'], + $data['forum_state'], + $data['wiki_state'], + $data['chat_state'], + $data['self_reg_allowed'], + $data['self_unreg_allowed'] + ); + + $data['group_id'] = $groupId; + $result['updated']['group'][] = $data; + } + $elementsFound['groups'][] = $groupId; + } + } + + if ($deleteNotInArray) { + // Check categories + $categories = GroupManager::get_categories(); + foreach ($categories as $category) { + if (!in_array($category['id'], $elementsFound['categories'])) { + GroupManager::delete_category($category['id']); + $category['category'] = $category['title']; + $result['deleted']['category'][] = $category; + } + } + + $groups = GroupManager::get_groups(); + foreach ($groups as $group) { + if (!in_array($group['id'], $elementsFound['groups'])) { + GroupManager::delete_groups(array($group['id'])); + $group['group'] = $group['name']; + $result['deleted']['group'][] = $group; + } + } + } + return $result; + } + + /** + * Export all categories/group from a course to an array. + * This function works only in a context of a course. + * @return array + */ + public static function exportCategoriesAndGroupsToArray() + { + $data = array(); + $data[] = array( + 'category', + 'group', + 'description', + 'announcements_state', + 'calendar_state', + 'chat_state', + 'doc_state', + 'forum_state', + 'work_state', + 'wiki_state', + 'max_student', + 'self_reg_allowed', + 'self_unreg_allowed', + 'groups_per_user' + ); + + $categories = GroupManager::get_categories(); + + foreach ($categories as $categoryInfo) { + $data[] = array( + $categoryInfo['title'], + null, + $categoryInfo['description'], + $categoryInfo['announcements_state'], + $categoryInfo['calendar_state'], + $categoryInfo['chat_state'], + $categoryInfo['doc_state'], + $categoryInfo['forum_state'], + $categoryInfo['work_state'], + $categoryInfo['wiki_state'], + $categoryInfo['max_student'], + $categoryInfo['self_reg_allowed'], + $categoryInfo['self_unreg_allowed'], + $categoryInfo['groups_per_user'] + ); + } + + $groups = GroupManager::get_group_list(); + + foreach ($groups as $groupInfo) { + $categoryTitle = null; + $categoryInfo = GroupManager::get_category($groupInfo['category_id']); + $groupSettings = GroupManager::get_group_properties($groupInfo['id']); + if (!empty($categoryInfo)) { + $categoryTitle = $categoryInfo['title']; + } + + $data[] = array( + $categoryTitle, + $groupSettings['name'], + $groupSettings['description'], + $groupSettings['announcements_state'], + $groupSettings['calendar_state'], + $groupSettings['chat_state'], + $groupSettings['doc_state'], + $groupSettings['forum_state'], + $groupSettings['work_state'], + $groupSettings['wiki_state'], + $groupSettings['maximum_number_of_students'], + $groupSettings['self_registration_allowed'], + $groupSettings['self_unregistration_allowed'], + ); + } + return $data; + } + + static function getSettingBar($default) + { + $activeSettings = null; + $activeTutor = null; + $activeMember = null; + + switch($default) { + case 'settings': + $activeSettings = 'active'; + break; + case'tutor': + $activeTutor = 'active'; + break; + case 'member': + $activeMember = 'active'; + break; + } + + $url = api_get_path(WEB_CODE_PATH).'group/%s?'.api_get_cidreq(); + + echo ' + '; + } + + /** + * @param int $courseId + * @param string $keyword + * @return string + */ + public static function getOverview($courseId, $keyword = null) + { + $content = null; + $categories = GroupManager::get_categories(); + if (!empty($categories)) { + + foreach ($categories as $category) { + if (api_get_setting('allow_group_categories') == 'true') { + $content .= '

'.$category['title'].'

'; + } + if (!empty($keyword)) { + $groups = GroupManager::getGroupListFilterByName($keyword, $category['id'], $courseId); + } else { + $groups = GroupManager::get_group_list($category['id']); + } + + $content .= '
    '; + if (!empty($groups)) { + foreach ($groups as $group) { + $content .= '
  • '; + $content .= Display::tag('h3', Security::remove_XSS($group['name'])); + + $users = GroupManager::getTutors($group['id']); + if (!empty($users)) { + $content .= '
      '; + $content .= "
    • ".Display::tag('h4', get_lang('Tutors'))."
      • "; + foreach ($users as $user) { + $user_info = api_get_user_info($user['user_id']); + $content .= '
      • '.$user_info['complete_name_with_username'].'
      • '; + } + $content .= '
      '; + $content .= '
    '; + } + + $users = GroupManager::getStudents($group['id']); + if (!empty($users)) { + $content .= '
      '; + $content .= "
    • ".Display::tag('h4', get_lang('Students'))."
      • "; + foreach ($users as $user) { + $user_info = api_get_user_info($user['user_id']); + $content .= '
      • '.$user_info['complete_name_with_username'].'
      • '; + } + $content .= '
      '; + $content .= '
    '; + } + $content .= '
  • '; + } + } + $content .= '
'; + } + } + + return $content; + } + + /** + * Returns the search form + * @return string + */ + public static function getSearchForm() + { + $url = api_get_path(WEB_CODE_PATH).'group/group_overview.php?'.api_get_cidreq(); + $form = new FormValidator('search_groups', 'get', $url, null, array('class' => 'form-search')); + $form->addElement('text', 'keyword'); + $form->addElement('button', 'submit', get_lang('Search')); + return $form->toHtml(); + } }