Actualización

This commit is contained in:
Xes
2025-04-10 12:49:05 +02:00
parent 4aff98e77b
commit 1cdd00920f
9151 changed files with 1800913 additions and 0 deletions

5
main/group/example.csv Normal file
View File

@@ -0,0 +1,5 @@
"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";"students";"tutors"
"Category 1";"";"This is a category";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0";"0";
"";"Group 1";"This is a group with no category";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0";"";"username1,username2";"username3,username4"
"Category 1";"Group 2";"This is a group in a category 1";"2";"2";"2";"2";"2";"2";"2";"0";"0";"0";"";"username1,username2";"username3,username4"
1 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 students tutors
2 Category 1 This is a category 2 2 2 2 2 2 2 0 0 0 0
3 Group 1 This is a group with no category 2 2 2 2 2 2 2 0 0 0 username1,username2 username3,username4
4 Category 1 Group 2 This is a group in a category 1 2 2 2 2 2 2 2 0 0 0 username1,username2 username3,username4

275
main/group/group.php Normal file
View File

@@ -0,0 +1,275 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* Main page for the group module.
* This script displays the general group settings,
* and a list of groups with buttons to view, edit...
*
* @author Thomas Depraetere, Hugues Peeters, Christophe Gesche: initial versions
* @author Bert Vanderkimpen, improved self-unsubscribe for cvs
* @author Patrick Cool, show group comment under the group name
* @author Roan Embrechts, initial self-unsubscribe code, code cleaning, virtual course support
* @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
* @author Isaac Flores, code cleaning and improvements
*/
require_once __DIR__.'/../inc/global.inc.php';
$is_allowed_in_course = api_is_allowed_in_course();
$userId = api_get_user_id();
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
$course_id = api_get_course_int_id();
$sessionId = api_get_session_id();
// Notice for unauthorized people.
api_protect_course_script(true, false, 'group');
$htmlHeadXtra[] = '<script>
$(function() {
var i;
for (i=0; i<$(".actions").length; i++) {
if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
$(".actions:eq("+i+")").hide();
}
}
});
</script>';
$nameTools = get_lang('GroupManagement');
/*
* Self-registration and un-registration
*/
$my_group_id = isset($_GET['group_id']) ? (int) $_GET['group_id'] : null;
$my_group = isset($_REQUEST['group']) ? Security::remove_XSS($_REQUEST['group']) : null;
$my_get_id1 = isset($_GET['id1']) ? Security::remove_XSS($_GET['id1']) : null;
$my_get_id2 = isset($_GET['id2']) ? Security::remove_XSS($_GET['id2']) : null;
$my_get_id = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
$currentUrl = api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq();
$groupInfo = GroupManager::get_group_properties($my_group_id);
if (isset($_GET['action']) && $is_allowed_in_course) {
switch ($_GET['action']) {
case 'set_visible':
if (api_is_allowed_to_edit()) {
GroupManager::setVisible($my_get_id);
Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
header("Location: $currentUrl");
exit;
}
break;
case 'set_invisible':
if (api_is_allowed_to_edit()) {
GroupManager::setInvisible($my_get_id);
Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
header("Location: $currentUrl");
exit;
}
break;
case 'self_reg':
if (GroupManager::is_self_registration_allowed($userId, $groupInfo)) {
GroupManager::subscribe_users($userId, $groupInfo);
Display::addFlash(Display::return_message(get_lang('GroupNowMember')));
header("Location: $currentUrl");
exit;
} else {
Display::addFlash(Display::return_message(get_lang('Error')));
header("Location: $currentUrl");
exit;
}
break;
case 'self_unreg':
if (GroupManager::is_self_unregistration_allowed($userId, $groupInfo)) {
GroupManager::unsubscribe_users($userId, $groupInfo);
Display::addFlash(Display::return_message(get_lang('StudentDeletesHimself')));
header("Location: $currentUrl");
exit;
}
break;
}
}
/*
* Group-admin functions
*/
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'])) {
foreach ($_POST['group'] as $myGroupId) {
$groupInfo = GroupManager::get_group_properties($myGroupId);
GroupManager::deleteGroup($groupInfo);
}
Display::addFlash(Display::return_message(get_lang('SelectedGroupsDeleted')));
header("Location: $currentUrl");
exit;
}
break;
case 'empty_selected':
if (is_array($_POST['group'])) {
foreach ($_POST['group'] as $myGroupId) {
$groupInfo = GroupManager::get_group_properties($myGroupId);
GroupManager::unsubscribe_all_users($groupInfo);
}
Display::addFlash(Display::return_message(get_lang('SelectedGroupsEmptied')));
header("Location: $currentUrl");
exit;
}
break;
case 'fill_selected':
if (is_array($_POST['group'])) {
foreach ($_POST['group'] as $myGroupId) {
$groupInfo = GroupManager::get_group_properties($myGroupId);
GroupManager::fillGroupWithUsers($groupInfo);
}
Display::addFlash(Display::return_message(get_lang('SelectedGroupsFilled')));
header("Location: $currentUrl");
exit;
}
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::addFlash(Display::return_message(get_lang('CategoryOrderChanged')));
header("Location: $currentUrl");
exit;
break;
case 'delete_one':
$groupInfo = GroupManager::get_group_properties($my_get_id);
GroupManager::deleteGroup($groupInfo);
Display::addFlash(Display::return_message(get_lang('GroupDel')));
header("Location: $currentUrl");
exit;
break;
case 'fill_one':
$groupInfo = GroupManager::get_group_properties($my_get_id);
GroupManager::fillGroupWithUsers($groupInfo);
Display::addFlash(Display::return_message(get_lang('GroupFilledGroups')));
header("Location: $currentUrl");
exit;
break;
case 'delete_category':
if (empty($sessionId)) {
GroupManager::delete_category($my_get_id);
Display::addFlash(
Display::return_message(get_lang('CategoryDeleted'))
);
header("Location: $currentUrl");
exit;
}
break;
}
}
}
Display::display_header(get_lang('Groups'));
Display::display_introduction_section(TOOL_GROUP);
$actionsLeft = '';
if (api_is_allowed_to_edit(false, true)) {
$actionsLeft .= '<a href="group_creation.php?'.api_get_cidreq().'">'.
Display::return_icon('add-groups.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
if (empty($sessionId) && 'true' === api_get_setting('allow_group_categories')) {
$actionsLeft .= '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.
Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>';
}
$actionsLeft .= '<a href="import.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=xls">'.
Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'">'.
Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';
}
$actionsRight = GroupManager::getSearchForm();
$toolbar = Display::toolbarAction('toolbar-groups', [$actionsLeft, $actionsRight]);
$group_cats = GroupManager::get_categories(api_get_course_id());
echo $toolbar;
echo UserManager::getUserSubscriptionTab(3);
/* List all categories */
if (api_get_setting('allow_group_categories') === 'true') {
$defaultCategory = [
'id' => 0,
'iid' => 0,
'description' => '',
'title' => get_lang('DefaultGroupCategory'),
];
$group_cats = array_merge([$defaultCategory], $group_cats);
foreach ($group_cats as $index => $category) {
$categoryId = $category['id'];
$group_list = GroupManager::get_group_list($categoryId);
$groupToShow = GroupManager::process_groups($group_list, $categoryId);
if (empty($categoryId) && empty($group_list)) {
continue;
}
$label = Display::label(count($group_list).' '.get_lang('ExistingGroups'), 'info');
$actions = null;
if (api_is_allowed_to_edit(false, true) && !empty($categoryId) && empty($sessionId)) {
// Edit
$actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$categoryId.'" title="'.get_lang('Edit').'">'.
Display::return_icon('edit.png', get_lang('EditCategory'), '', ICON_SIZE_SMALL).'</a>';
// Delete
$actions .= Display::url(
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL),
'group.php?'.api_get_cidreq().'&action=delete_category&id='.$categoryId,
[
'onclick' => 'javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;',
]
);
// Move
if ($index != 0) {
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$categoryId.'&id2='.$group_cats[$index - 1]['id'].'">'.
Display::return_icon('up.png', '&nbsp;', '', ICON_SIZE_SMALL).'</a>';
}
if ($index != count($group_cats) - 1) {
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$categoryId.'&id2='.$group_cats[$index + 1]['id'].'">'.
Display::return_icon('down.png', '&nbsp;', '', ICON_SIZE_SMALL).'</a>';
}
}
echo Display::page_header(
Security::remove_XSS($category['title'].' '.$label.' ').$actions,
null,
'h4',
false
);
echo Security::remove_XSS($category['description']);
echo $groupToShow;
}
} else {
echo GroupManager::process_groups(GroupManager::get_group_list());
}
if (!isset($_GET['origin']) || $_GET['origin'] != 'learnpath') {
Display::display_footer();
}
Session::write('_gid', 0);

View File

@@ -0,0 +1,458 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
api_protect_course_script(true);
$sessionId = api_get_session_id();
if (!api_is_allowed_to_edit(false, true) ||
!(isset($_GET['id']) ||
isset($_POST['id']) ||
isset($_GET['action']) ||
isset($_POST['action']))
) {
api_not_allowed(true);
}
if (!empty($sessionId)) {
api_not_allowed(true);
}
/**
* 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 to check the number of groups per user.
*
* @param $value
*
* @return bool
*/
function check_groups_per_user($value)
{
$groups_per_user = (int) $value['groups_per_user'];
if (isset($_POST['id']) &&
$groups_per_user != GroupManager::GROUP_PER_MEMBER_NO_LIMIT &&
GroupManager::get_current_max_groups_per_user($_POST['id']) > $groups_per_user) {
return false;
}
return 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 = [
'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,
'document_access' => 0,
];
}
$htmlHeadXtra[] = '<script>
$(function() {
$("#max_member").on("focus", function() {
$("#max_member_selected").attr("checked", true);
});
});
</script>';
$interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
$course_id = api_get_course_int_id();
// Build the form
if (isset($_GET['id'])) {
// Update settings of existing category
$action = 'update_settings';
$form = new FormValidator(
'group_category',
'post',
api_get_self().'?id='.$category['id'].'&'.api_get_cidreq()
);
$form->addElement('hidden', '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")) {
$sql = "ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1'
WHERE c_id = $course_id";
Database::query($sql);
}
// Create a new category
$action = 'add_category';
$form = new FormValidator('group_category');
}
$form->addElement('header', $nameTools);
$form->addElement('html', '<div class="row"><div class="col-md-6">');
$form->addText('title', get_lang('Title'));
// Groups per user
$possible_values = [];
for ($i = 1; $i <= 10; $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, ['id' => 'groups_per_user']),
$form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber')),
];
$form->addGroup($group, 'limit_group', get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'), null, false);
$form->addRule('limit_group', get_lang('MaxGroupsPerUserInvalid'), 'callback', 'check_groups_per_user');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
$form->addElement('textarea', 'description', get_lang('Description'), ['rows' => 6]);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', '');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Members per group
$group = [
$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,
['id' => 'max_member_selected']
),
$form->createElement('text', 'max_member', null, ['class' => 'span1', 'id' => 'max_member']),
$form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis')),
];
$form->addGroup($group, 'max_member_group', get_lang('GroupLimit'), null, false);
$form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Self registration
$group = [
$form->createElement(
'checkbox',
'self_reg_allowed',
get_lang('GroupSelfRegistration'),
get_lang('GroupAllowStudentRegistration'),
1
),
$form->createElement('checkbox', 'self_unreg_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1),
];
$form->addGroup(
$group,
'',
Display::return_icon('user.png', get_lang('GroupSelfRegistration')).' '.get_lang('GroupSelfRegistration'),
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('hidden', 'action');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', get_lang('DefaultSettingsForNewGroups'));
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Documents settings.
$group = [
$form->createElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
$form->addGroup(
$group,
'',
Display::return_icon('folder.png', get_lang('GroupDocument')).' '.get_lang('GroupDocument'),
null,
false
);
$allowDocumentGroupAccess = api_get_configuration_value('group_category_document_access');
if ($allowDocumentGroupAccess) {
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
$group = [
$form->createElement(
'radio',
'document_access',
null,
get_lang('DocumentGroupShareMode'),
GroupManager::DOCUMENT_MODE_SHARE
),
$form->createElement(
'radio',
'document_access',
get_lang('GroupDocument'),
get_lang('DocumentGroupCollaborationMode'),
GroupManager::DOCUMENT_MODE_COLLABORATION
),
$form->createElement(
'radio',
'document_access',
null,
get_lang('DocumentGroupReadOnlyMode'),
GroupManager::DOCUMENT_MODE_READ_ONLY
),
];
$form->addGroup(
$group,
'',
Display::return_icon(
'folder.png',
get_lang('GroupDocumentAccess')
).'<span>'.get_lang('GroupDocumentAccess').'</span>',
null,
false
);
$form->addElement('html', '</div>');
}
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', '');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Work settings.
$group = [
$form->createElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
$form->addGroup(
$group,
'',
Display::return_icon('work.png', get_lang('GroupWork'), [], ICON_SIZE_SMALL).' '.get_lang('GroupWork'),
'',
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Calendar settings.
$group = [
$form->createElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
$form->addGroup(
$group,
'',
Display::return_icon('agenda.png', get_lang('GroupCalendar')).' '.get_lang('GroupCalendar'),
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', '');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Announcements settings.
$group = [
$form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
$form->createElement('radio', 'announcements_state', null, get_lang('PrivateBetweenUsers'), GroupManager::TOOL_PRIVATE_BETWEEN_USERS),
];
$form->addGroup(
$group,
'',
Display::return_icon('announce.png', get_lang('GroupAnnouncements')).' '.get_lang('GroupAnnouncements'),
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Forum settings.
$group = [
$form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
$form->addGroup(
$group,
'',
Display::return_icon('forum.png', get_lang('GroupForum')).' '.get_lang('GroupForum'),
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', '');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Wiki settings.
$group = [
$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')).' '.get_lang('GroupWiki'),
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Chat settings.
$group = [
$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')).' '.get_lang('Chat'),
null,
false
);
$form->addElement('html', '</div>');
// Submit
if (isset($_GET['id'])) {
$form->addButtonUpdate(get_lang('Edit'), 'submit');
} else {
$form->addButtonSave(get_lang('Add'), 'submit');
}
$currentUrl = api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq();
// If form validates -> save data
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_reg_allowed = isset($values['self_reg_allowed']) ? $values['self_reg_allowed'] : 0;
$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'],
isset($values['document_access']) ? $values['document_access'] : 0
);
Display::addFlash(Display::return_message(get_lang('GroupPropertiesModified')));
header("Location: ".$currentUrl."&category=".$values['id']);
exit;
case 'add_category':
GroupManager::create_category(
$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'],
isset($values['document_access']) ? $values['document_access'] : 0
);
Display::addFlash(Display::return_message(get_lang('CategoryCreated')));
header("Location: ".$currentUrl);
exit;
break;
}
}
// Else display the form
Display::display_header($nameTools, 'Group');
// actions bar
echo '<div class="actions">';
echo '<a href="group.php">'.
Display::return_icon('back.png', get_lang('BackToGroupList'), '', ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
$defaults = $category;
$defaults['action'] = $action;
if ($defaults['max_student'] == 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['max_student'];
}
$form->setDefaults($defaults);
$form->display();
Display::display_footer();

View File

@@ -0,0 +1,346 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true);
if (!api_is_allowed_to_edit(false, true)) {
api_not_allowed(true);
}
$currentUrl = api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq();
$sessionId = api_get_session_id();
/* Create the groups */
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'create_groups':
$groups = [];
$useOnlyFirstCategory = false;
$firstCategory = isset($_POST['group_0_category']) ? $_POST['group_0_category'] : 0;
if (isset($_POST['same_category']) && $_POST['same_category']) {
$useOnlyFirstCategory = true;
}
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;
if ($useOnlyFirstCategory) {
$group1['category'] = $firstCategory;
}
$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'];
}
GroupManager::create_group(
$group['name'],
$group['category'],
$group['tutor'],
$group['places']
);
}
Display::addFlash(Display::return_message(get_lang('GroupsAdded')));
header('Location: '.$currentUrl);
exit;
break;
case 'create_subgroups':
GroupManager::create_subgroups(
$_POST['base_group'],
$_POST['number_of_groups']
);
Display::addFlash(Display::return_message(get_lang('GroupsAdded')));
header('Location: '.$currentUrl);
exit;
break;
case 'create_class_groups':
GroupManager::create_class_groups($_POST['group_category']);
Display::addFlash(Display::return_message(get_lang('GroupsAdded')));
header('Location: '.$currentUrl);
exit;
break;
}
}
$nameTools = get_lang('GroupCreation');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
];
Display::display_header($nameTools, 'Group');
if (isset($_POST['number_of_groups'])) {
if (!is_numeric($_POST['number_of_groups']) || intval($_POST['number_of_groups']) < 1) {
echo Display::return_message(
get_lang('PleaseEnterValidNumber').'<br /><br />
<a href="group_creation.php?'.api_get_cidreq().'">&laquo; '.get_lang('Back').'</a>',
'error',
false
);
} else {
$number_of_groups = intval($_POST['number_of_groups']);
if ($number_of_groups > 1) {
?>
<script>
var number_of_groups = <?php echo $number_of_groups; ?>;
function switch_state(key) {
ref = document.getElementById(key+'_0');
for(i=1; i<number_of_groups; i++) {
var id = "#"+key+'_'+i;
element = document.getElementById(key+'_'+i);
element.disabled = !element.disabled;
disabled = element.disabled;
$(id).prop('disabled', disabled);
$(id).prop('value', ref.value);
$(id).selectpicker('refresh');
}
if (disabled) {
ref.addEventListener("change", copy, false);
} else {
ref.removeEventListener("change", copy, false);
}
copy_value(key);
}
function copy(e) {
key = e.currentTarget.id;
var re = new RegExp ('_0', '') ;
var key = key.replace(re, '') ;
copy_value(key);
}
function copy_value(key) {
ref = document.getElementById(key+'_0');
for( i=1; i<number_of_groups; i++) {
element = document.getElementById(key+'_'+i);
element.value = ref.value;
}
}
</script>
<?php
}
$group_categories = GroupManager::get_categories();
$group_id = GroupManager::get_number_of_groups() + 1;
$cat_options = [];
foreach ($group_categories as $index => $category) {
$cat_options[$category['id']] = $category['title'];
}
$form = new FormValidator('create_groups_step2', 'POST', api_get_self().'?'.api_get_cidreq());
// Modify the default templates
$renderer = $form->defaultRenderer();
$form_template = "<form {attributes}>\n<div class='create-groups'>\n<table>\n{content}\n</table>\n</div>\n</form>";
$renderer->setFormTemplate($form_template);
$element_template = <<<EOT
<tr class="separate">
<td>
<!-- BEGIN required -->
<span class="form_required">*</span> <!-- END required -->{label}
</td>
<td>
<!-- BEGIN error -->
<span class="form_error">{error}</span><br /><!-- END error --> {element}
</td>
</tr>
EOT;
$renderer->setCustomElementTemplate($element_template);
$form->addElement('header', $nameTools);
$form->addElement('hidden', 'action');
$form->addElement('hidden', 'number_of_groups');
$defaults = [];
// Table heading
$group_el = [];
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('GroupName').'</b>');
if (api_get_setting('allow_group_categories') === 'true') {
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('GroupCategory').'</b>');
}
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('GroupPlacesThis').'</b>');
$form->addGroup($group_el, 'groups', null, "</td><td>", false);
// Checkboxes
if ($_POST['number_of_groups'] > 1) {
$group_el = [];
$group_el[] = $form->createElement('static', null, null, ' ');
if (api_get_setting('allow_group_categories') === 'true') {
$group_el[] = $form->createElement(
'checkbox',
'same_category',
null,
get_lang('SameForAll'),
['onclick' => "javascript: switch_state('category');"]
);
}
$group_el[] = $form->createElement(
'checkbox',
'same_places',
null,
get_lang('SameForAll'),
['onclick' => "javascript: switch_state('places');"]
);
$form->addGroup($group_el, 'groups', null, '</td><td>', false);
}
// Properties for all groups
for ($group_number = 0; $group_number < $_POST['number_of_groups']; $group_number++) {
$group_el = [];
$group_el[] = $form->createElement('text', 'group_'.$group_number.'_name');
if (api_get_setting('allow_group_categories') === 'true') {
$group_el[] = $form->createElement(
'select',
'group_'.$group_number.'_category',
null,
$cat_options,
['id' => 'category_'.$group_number]
);
} else {
$group_el[] = $form->createElement('hidden', 'group_'.$group_number.'_category', 0);
$defaults['group_'.$group_number.'_category'] = array_keys($cat_options)[0];
}
$group_el[] = $form->createElement(
'text',
'group_'.$group_number.'_places',
null,
['class' => 'span1', 'id' => 'places_'.$group_number]
);
if ($_POST['number_of_groups'] < 10000) {
if ($group_id < 10) {
$prev = '000';
} elseif ($group_id < 100) {
$prev = '00';
} elseif ($group_id < 1000) {
$prev = '0';
} else {
$prev = '';
}
}
$defaults['group_'.$group_number.'_name'] = get_lang('GroupSingle').' '.$prev.$group_id++;
$form->addGroup($group_el, 'group_'.$group_number, null, '</td><td>', false);
}
$defaults['action'] = 'create_groups';
$defaults['number_of_groups'] = (int) $_POST['number_of_groups'];
$form->setDefaults($defaults);
$form->addButtonCreate(get_lang('CreateGroup'), 'submit');
$form->display();
}
} else {
/*
* Show form to generate new groups
*/
$create_groups_form = new FormValidator('create_groups', 'post', api_get_self().'?'.api_get_cidreq());
$create_groups_form->addElement('header', $nameTools);
$create_groups_form->addText('number_of_groups', get_lang('NumberOfGroupsToCreate'), null, ['value' => '1']);
$create_groups_form->addButton('submit', get_lang('ProceedToCreateGroup'), 'plus', 'primary');
$defaults = [];
$defaults['number_of_groups'] = 1;
$create_groups_form->setDefaults($defaults);
$create_groups_form->display();
/*
* Show form to generate subgroups
*/
if (api_get_setting('allow_group_categories') === 'true') {
$groups = GroupManager::get_group_list();
if (!empty($groups)) {
$base_group_options = [];
foreach ($groups as $index => $group) {
$number_of_students = GroupManager::number_of_students($group['id']);
if ($number_of_students > 0) {
$base_group_options[$group['id']] =
$group['name'].' ('.$number_of_students.' '.get_lang('Users').')';
}
}
if (count($base_group_options) > 0) {
$create_subgroups_form = new FormValidator(
'create_subgroups',
'post',
api_get_self().'?'.api_get_cidreq()
);
$create_subgroups_form->addElement('header', get_lang('CreateSubgroups'));
$create_subgroups_form->addElement('html', get_lang('CreateSubgroupsInfo'));
$create_subgroups_form->addElement('hidden', 'action');
$group_el = [];
$group_el[] = $create_subgroups_form->createElement(
'static',
null,
null,
get_lang('CreateNumberOfGroups')
);
$group_el[] = $create_subgroups_form->createElement('text', 'number_of_groups', null, ['size' => 3]);
$group_el[] = $create_subgroups_form->createElement('static', null, null, get_lang('WithUsersFrom'));
$group_el[] = $create_subgroups_form->createElement('select', 'base_group', null, $base_group_options);
$group_el[] = $create_subgroups_form->addButtonSave(get_lang('Ok'), 'submit', true);
$create_subgroups_form->addGroup($group_el, 'create_groups', null, null, false);
$defaults = [];
$defaults['action'] = 'create_subgroups';
$create_subgroups_form->setDefaults($defaults);
$create_subgroups_form->display();
}
}
}
/*
* Show form to generate groups from classes subscribed to the course
*/
if (empty($sessionId)) {
$options['where'] = [' usergroup.course_id = ? ' => api_get_course_int_id()];
} else {
$options['session_id'] = $sessionId;
$options['where'] = [' usergroup.session_id = ? ' => $sessionId];
}
$obj = new UserGroup();
$classes = $obj->getUserGroupInCourse($options);
if (count($classes) > 0) {
$description = '<p>'.get_lang('GroupsFromClassesInfo').'</p>';
$description .= '<ul>';
foreach ($classes as $index => $class) {
$number_of_users = count($obj->get_users_by_usergroup($class['id']));
$description .= '<li>';
$description .= $class['name'];
$description .= ' ('.$number_of_users.' '.get_lang('Users').')';
$description .= '</li>';
}
$description .= '</ul>';
$classForm = new FormValidator(
'create_class_groups_form',
'post',
api_get_self().'?'.api_get_cidreq()
);
$classForm->addHeader(get_lang('GroupsFromClasses'));
$classForm->addHtml($description);
$classForm->addElement('hidden', 'action');
if (api_get_setting('allow_group_categories') === 'true') {
$group_categories = GroupManager::get_categories();
$cat_options = [];
foreach ($group_categories as $index => $category) {
$cat_options[$category['id']] = $category['title'];
}
$classForm->addElement('select', 'group_category', null, $cat_options);
} else {
$classForm->addElement('hidden', 'group_category');
}
$classForm->addButtonSave(get_lang('Ok'));
$defaults['group_category'] = GroupManager::DEFAULT_GROUP_CATEGORY;
$defaults['action'] = 'create_class_groups';
$classForm->setDefaults($defaults);
$classForm->display();
}
}
Display::display_footer();

View File

@@ -0,0 +1,175 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Main page for the group module.
* This script displays the general group settings,
* and a list of groups with buttons to view, edit...
*
* @author Thomas Depraetere, Hugues Peeters, Christophe Gesche: initial versions
* @author Bert Vanderkimpen, improved self-unsubscribe for cvs
* @author Patrick Cool, show group comment under the group name
* @author Roan Embrechts, initial self-unsubscribe code, code cleaning, virtual course support
* @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
*/
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true);
$nameTools = get_lang('GroupOverview');
$courseId = api_get_course_int_id();
$courseInfo = api_get_course_info();
$groupId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '';
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'export_surveys':
$extraFieldValue = new ExtraFieldValue('survey');
$surveyList = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
'group_id',
$groupId,
false,
false,
true
);
if (!empty($surveyList)) {
$exportList = [];
foreach ($surveyList as $data) {
$surveyId = $data['item_id'];
$surveyData = SurveyManager::get_survey($surveyId, 0, api_get_course_id());
if (!empty($surveyData)) {
$filename = $surveyData['code'].'.xlsx';
$exportList[] = @SurveyUtil::export_complete_report_xls($surveyData, $filename, 0, true);
}
}
if (!empty($exportList)) {
$tempZipFile = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().'.zip';
$zip = new PclZip($tempZipFile);
foreach ($exportList as $file) {
$zip->add($file, PCLZIP_OPT_REMOVE_ALL_PATH);
}
DocumentManager::file_send_for_download(
$tempZipFile,
true,
get_lang('SurveysWordInASCII').'-'.api_get_course_id().'-'.api_get_local_time().'.zip'
);
unlink($tempZipFile);
exit;
}
}
Display::addFlash(Display::return_message(get_lang('NoSurveyAvailable')));
header('Location: '.api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq());
exit;
break;
case 'export_all':
$data = GroupManager::exportCategoriesAndGroupsToArray(null, true);
switch ($_GET['type']) {
case 'csv':
Export::arrayToCsv($data);
exit;
break;
case 'xls':
if (!empty($data)) {
Export::arrayToXls($data);
exit;
}
break;
}
exit;
break;
case 'export_pdf':
$content = GroupManager::getOverview($courseId, $keyword);
$pdf = new PDF();
$extra = '<div style="text-align:center"><h2>'.get_lang('GroupList').'</h2></div>';
$extra .= '<strong>'.get_lang('Course').': </strong>'.$courseInfo['title'].' ('.$courseInfo['code'].')';
$content = $extra.$content;
$pdf->content_to_pdf($content, null, null, api_get_course_id());
break;
case 'export':
$data = GroupManager::exportCategoriesAndGroupsToArray($groupId, true);
switch ($_GET['type']) {
case 'csv':
Export::arrayToCsv($data);
exit;
break;
case 'xls':
if (!empty($data)) {
Export::arrayToXls($data);
exit;
}
break;
}
break;
case 'export_users':
$data = GroupManager::exportStudentsToArray($groupId, true);
Export::arrayToCsv($data);
exit;
break;
}
}
$interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
$origin = api_get_origin();
if ('learnpath' != $origin) {
// So we are not in learnpath tool
if (!api_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');
Display::display_introduction_section(TOOL_GROUP);
}
} else {
Display::display_reduced_header();
}
$actions = '<a href="group_creation.php?'.api_get_cidreq().'">'.
Display::return_icon('add.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
if (api_get_setting('allow_group_categories') === 'true') {
$actions .= '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.
Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>';
} else {
$actions .= '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
}
$actions .= '<a href="import.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
$actions .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
Display::return_icon('export_csv.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
$actions .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.
Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
$actions .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
$actions .= '<a href="group.php?'.api_get_cidreq().'">'.
Display::return_icon('group.png', get_lang('Groups'), '', ICON_SIZE_MEDIUM).'</a>';
$actions .= '<a href="../user/user.php?'.api_get_cidreq().'">'.
Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).'</a>';
// Action links
echo Display::toolbarAction('actions', [$actions, GroupManager::getSearchForm()]);
echo GroupManager::getOverview($courseId, $keyword);
if ('learnpath' !== $origin) {
Display::display_footer();
}

583
main/group/group_space.php Normal file
View File

@@ -0,0 +1,583 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script shows the group space for one specific group, possibly displaying
* a list of users in the group, subscribe or unsubscribe option, tutors...
*
* @todo Display error message if no group ID specified
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true, false, 'group');
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
$group_id = api_get_group_id();
$user_id = api_get_user_id();
$current_group = GroupManager::get_group_properties($group_id);
$group_id = $current_group['iid'];
if (empty($current_group)) {
api_not_allowed(true);
}
$this_section = SECTION_COURSES;
$nameTools = get_lang('GroupSpace');
$interbreadcrumb[] = [
'url' => 'group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
];
/* Ensure all private groups // Juan Carlos Raña Trabado */
$forums_of_groups = get_forums_of_group($current_group);
if (!GroupManager::userHasAccessToBrowse($user_id, $current_group, api_get_session_id())) {
api_not_allowed(true);
}
/*
* User wants to register in this group
*/
if (!empty($_GET['selfReg']) &&
GroupManager::is_self_registration_allowed($user_id, $current_group)
) {
GroupManager::subscribe_users($user_id, $current_group);
Display::addFlash(Display::return_message(get_lang('GroupNowMember')));
}
/*
* User wants to unregister from this group
*/
if (!empty($_GET['selfUnReg']) &&
GroupManager::is_self_unregistration_allowed($user_id, $current_group)
) {
GroupManager::unsubscribe_users($user_id, $current_group);
Display::addFlash(
Display::return_message(get_lang('StudentDeletesHimself'), 'normal')
);
}
Display::display_header(
$nameTools.' '.Security::remove_XSS($current_group['name']),
'Group'
);
Display::display_introduction_section(TOOL_GROUP);
echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq().'">'.
Display::return_icon(
'back.png',
get_lang('BackToGroupList'),
'',
ICON_SIZE_MEDIUM
).
'</a>';
/*
* Register to group
*/
$subscribe_group = '';
if (GroupManager::is_self_registration_allowed($user_id, $current_group)) {
$subscribe_group = '<a class="btn btn-default" href="'.api_get_self().'?selfReg=1&group_id='.$current_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;">'.
get_lang('RegIntoGroup').'</a>';
}
/*
* Unregister from group
*/
$unsubscribe_group = '';
if (GroupManager::is_self_unregistration_allowed($user_id, $current_group)) {
$unsubscribe_group = '<a class="btn btn-default" href="'.api_get_self().'?selfUnReg=1" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;">'.
get_lang('StudentUnsubscribe').'</a>';
}
echo '&nbsp;</div>';
/* Main Display Area */
$edit_url = '';
if (api_is_allowed_to_edit(false, true) ||
GroupManager::is_tutor_of_group($user_id, $current_group)
) {
$edit_url = '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?'.api_get_cidreq().'">'.
Display::return_icon('edit.png', get_lang('EditGroup'), '', ICON_SIZE_SMALL).'</a>';
}
echo Display::page_header(
Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group
);
if (!empty($current_group['description'])) {
echo '<p>'.Security::remove_XSS($current_group['description']).'</p>';
}
// If the user is subscribed to the group or the user is a tutor of the group then
if (api_is_allowed_to_edit(false, true) ||
GroupManager::userHasAccessToBrowse($user_id, $current_group, api_get_session_id())
) {
$actions_array = [];
if (is_array($forums_of_groups)) {
if (GroupManager::TOOL_NOT_AVAILABLE != $current_group['forum_state']) {
foreach ($forums_of_groups as $key => $value) {
if ('public' === $value['forum_group_public_private'] ||
('private' === $value['forum_group_public_private']) ||
!empty($user_is_tutor) ||
api_is_allowed_to_edit(false, true)
) {
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?forum='.$value['forum_id'].'&'.api_get_cidreq().'&origin=group',
'content' => Display::return_icon(
'forum.png',
get_lang('Forum').': '.$value['forum_title'],
[],
32
),
];
}
}
}
}
if (GroupManager::TOOL_NOT_AVAILABLE != $current_group['doc_state']) {
// Link to the documents area of this group
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(),
'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), [], 32),
];
}
if (GroupManager::TOOL_NOT_AVAILABLE != $current_group['calendar_state']) {
$groupFilter = '';
if (!empty($group_id)) {
$groupFilter = "&type=course&user_id=GROUP:$group_id";
}
// Link to a group-specific part of agenda
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?'.api_get_cidreq().$groupFilter,
'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), [], 32),
];
}
if (GroupManager::TOOL_NOT_AVAILABLE != $current_group['work_state']) {
// Link to the works area of this group
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
'content' => Display::return_icon('work.png', get_lang('GroupWork'), [], 32),
];
}
if (GroupManager::TOOL_NOT_AVAILABLE != $current_group['announcements_state']) {
// Link to a group-specific part of announcements
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), [], 32),
];
}
if (GroupManager::TOOL_NOT_AVAILABLE != $current_group['wiki_state']) {
// Link to the wiki area of this group
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'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'), [], 32),
];
}
if (GroupManager::TOOL_NOT_AVAILABLE != $current_group['chat_state']) {
// Link to the chat area of this group
if (api_get_course_setting('allow_open_chat_window')) {
$actions_array[] = [
'url' => 'javascript: void(0);',
'content' => Display::return_icon('chat.png', get_lang('Chat'), [], 32),
'url_attributes' => [
'onclick' => " window.open('../chat/chat.php?".api_get_cidreq().'&toolgroup='.$current_group['id']."','window_chat_group_".api_get_course_id().'_'.api_get_group_id()."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')",
],
];
} else {
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'chat/chat.php?'.api_get_cidreq().'&toolgroup='.$current_group['id'],
'content' => Display::return_icon('chat.png', get_lang('Chat'), [], 32),
];
}
}
$enabled = api_get_plugin_setting('bbb', 'tool_enable');
if ('true' === $enabled) {
$bbb = new bbb();
if ($bbb->hasGroupSupport()) {
$actions_array[] = [
'url' => api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?'.api_get_cidreq(),
'content' => Display::return_icon('bbb.png', get_lang('VideoConference'), [], 32),
];
}
}
$enabled = api_get_plugin_setting('zoom', 'tool_enable');
if ('true' === $enabled) {
$actions_array[] = [
'url' => api_get_path(WEB_PLUGIN_PATH).'zoom/start.php?'.api_get_cidreq(),
'content' => Display::return_icon('bbb.png', get_lang('VideoConference'), [], 32),
];
}
if (!empty($actions_array)) {
echo Display::actions($actions_array);
}
} else {
$actions_array = [];
if (is_array($forums_of_groups)) {
if (GroupManager::TOOL_PUBLIC == $current_group['forum_state']) {
foreach ($forums_of_groups as $key => $value) {
if ('public' === $value['forum_group_public_private']) {
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'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'),
[],
ICON_SIZE_MEDIUM
),
];
}
}
}
}
if (GroupManager::TOOL_PUBLIC == $current_group['doc_state']) {
// Link to the documents area of this group
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(),
'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), [], ICON_SIZE_MEDIUM),
];
}
if (GroupManager::TOOL_PUBLIC == $current_group['calendar_state']) {
$groupFilter = '';
if (!empty($group_id)) {
$groupFilter = "&type=course&user_id=GROUP:$group_id";
}
// Link to a group-specific part of agenda
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?'.api_get_cidreq().$groupFilter,
'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), [], 32),
];
}
if (GroupManager::TOOL_PUBLIC == $current_group['work_state']) {
// Link to the works area of this group
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
'content' => Display::return_icon('work.png', get_lang('GroupWork'), [], ICON_SIZE_MEDIUM),
];
}
if (GroupManager::TOOL_PUBLIC == $current_group['announcements_state']) {
// Link to a group-specific part of announcements
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), [], ICON_SIZE_MEDIUM),
];
}
if (GroupManager::TOOL_PUBLIC == $current_group['wiki_state']) {
// Link to the wiki area of this group
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'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'), [], 32),
];
}
if (GroupManager::TOOL_PUBLIC == $current_group['chat_state']) {
// Link to the chat area of this group
if (api_get_course_setting('allow_open_chat_window')) {
$actions_array[] = [
'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq().'&toolgroup='.$current_group['id']."','window_chat_group_".api_get_course_id().'_'.api_get_group_id()."','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'), [], 32),
];
} else {
$actions_array[] = [
'url' => api_get_path(WEB_CODE_PATH).'chat/chat.php?'.api_get_cidreq().'&toolgroup='.$current_group['id'],
'content' => Display::return_icon('chat.png', get_lang('Chat'), [], 32),
];
}
}
if (!empty($actions_array)) {
echo Display::actions($actions_array);
}
}
/*
* List all the tutors of the current group
*/
$tutors = GroupManager::get_subscribed_tutors($current_group);
$tutor_info = '';
if (0 == count($tutors)) {
$tutor_info = get_lang('GroupNoneMasc');
} else {
$tutor_info .= '<ul class="thumbnails">';
foreach ($tutors as $index => $tutor) {
$userInfo = api_get_user_info($tutor['user_id']);
$username = api_htmlentities(sprintf(get_lang('LoginX'), $userInfo['username']), ENT_QUOTES);
$completeName = $userInfo['complete_name'];
$photo = '<img src="'.$userInfo['avatar'].'" alt="'.$completeName.'" width="32" height="32" title="'.$completeName.'" />';
$tutor_info .= '<li>';
$tutor_info .= $userInfo['complete_name_with_message_link'];
$tutor_info .= '</li>';
}
$tutor_info .= '</ul>';
}
echo Display::page_subheader(get_lang('GroupTutors'));
if (!empty($tutor_info)) {
echo $tutor_info;
}
echo '<br />';
/*
* List all the members of the current group
*/
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
);
$origin = api_get_origin();
$my_cidreq = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
$my_gidreq = isset($_GET['gidReq']) ? Security::remove_XSS($_GET['gidReq']) : '';
$parameters = ['cidReq' => $my_cidreq, 'origin' => $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'));
} else {
$table->set_header(1, get_lang('LastName'));
$table->set_header(2, get_lang('FirstName'));
}
if ('true' == api_get_setting('show_email_addresses') || 'true' == api_is_allowed_to_edit()) {
$table->set_header(3, get_lang('Email'));
$table->set_column_filter(3, 'email_filter');
$table->set_header(4, get_lang('Active'));
$table->set_column_filter(4, 'activeFilter');
} else {
$table->set_header(3, get_lang('Active'));
$table->set_column_filter(3, 'activeFilter');
}
//the order of these calls is important
//$table->set_column_filter(1, 'user_name_filter');
//$table->set_column_filter(2, 'user_name_filter');
$table->set_column_filter(0, 'user_icon_filter');
$table->display();
/**
* Get the number of subscribed users to the group.
*
* @return int
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
*
* @version April 2008
*/
function get_number_of_group_users()
{
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
$course_id = api_get_course_int_id();
if (empty($groupInfo) || empty($course_id)) {
return 0;
}
// Database table definition
$table = Database::get_course_table(TABLE_GROUP_USER);
// Query
$sql = "SELECT count(iid) AS number_of_users
FROM $table
WHERE
c_id = $course_id AND
group_id = '".intval($groupInfo['iid'])."'";
$result = Database::query($sql);
$return = Database::fetch_array($result, 'ASSOC');
return $return['number_of_users'];
}
/**
* Get the details of the users in a group.
*
* @param int $from starting row
* @param int $number_of_items number of items to be displayed
* @param int $column sorting colum
* @param int $direction sorting direction
*
* @return array
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
*
* @version April 2008
*/
function get_group_user_data($from, $number_of_items, $column, $direction)
{
$direction = !in_array(strtolower(trim($direction)), ['asc', 'desc']) ? 'asc' : $direction;
$groupInfo = GroupManager::get_group_properties(api_get_group_id());
$course_id = api_get_course_int_id();
$column = (int) $column;
if (empty($groupInfo) || empty($course_id)) {
return 0;
}
// Database table definition
$table_group_user = Database::get_course_table(TABLE_GROUP_USER);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$tableGroup = Database::get_course_table(TABLE_GROUP);
// Query
if ('true' === api_get_setting('show_email_addresses')) {
$sql = 'SELECT user.id AS col0,
'.(
api_is_western_name_order() ?
'user.firstname AS col1,
user.lastname AS col2,'
:
'user.lastname AS col1,
user.firstname AS col2,'
)."
user.email AS col3
, user.active AS col4
FROM $table_user user
INNER JOIN $table_group_user group_rel_user
ON (group_rel_user.user_id = user.id)
INNER JOIN $tableGroup g
ON (group_rel_user.group_id = g.iid)
WHERE
group_rel_user.c_id = $course_id AND
g.iid = '".$groupInfo['iid']."'
ORDER BY col$column $direction
LIMIT $from, $number_of_items";
} else {
if (api_is_allowed_to_edit()) {
$sql = 'SELECT DISTINCT
u.id AS col0,
'.(api_is_western_name_order() ?
'u.firstname AS col1,
u.lastname AS col2,'
:
'u.lastname AS col1,
u.firstname AS col2,')."
u.email AS col3
, u.active AS col4
FROM $table_user u
INNER JOIN $table_group_user gu
ON (gu.user_id = u.id)
INNER JOIN $tableGroup g
ON (gu.group_id = g.iid)
WHERE
g.iid = '".$groupInfo['iid']."' AND
gu.c_id = $course_id
ORDER BY col$column $direction
LIMIT $from, $number_of_items";
} else {
$sql = 'SELECT DISTINCT
user.id AS col0,
'.(
api_is_western_name_order() ?
'user.firstname AS col1,
user.lastname AS col2 '
:
'user.lastname AS col1,
user.firstname AS col2 '
)."
, user.active AS col3
FROM $table_user user
INNER JOIN $table_group_user group_rel_user
ON (group_rel_user.user_id = user.id)
INNER JOIN $tableGroup g
ON (group_rel_user.group_id = g.iid)
WHERE
g.iid = '".$groupInfo['iid']."' AND
group_rel_user.c_id = $course_id AND
group_rel_user.user_id = user.id AND
g.iid = '".$groupInfo['iid']."'
ORDER BY col$column $direction
LIMIT $from, $number_of_items";
}
}
$return = [];
$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);
}
function activeFilter($isActive)
{
if ($isActive) {
return Display::return_icon('accept.png', get_lang('Active'), [], ICON_SIZE_TINY);
}
return Display::return_icon('error.png', get_lang('Inactive'), [], ICON_SIZE_TINY);
}
/**
* Display a user icon that links to the user page.
*
* @param int $user_id the id of the user
*
* @return string code
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
*
* @version April 2008
*/
function user_icon_filter($user_id)
{
$userInfo = api_get_user_info($user_id);
$photo = '<img src="'.$userInfo['avatar'].'" alt="'.$userInfo['complete_name'].'" width="22" height="22" title="'.$userInfo['complete_name'].'" />';
return Display::url($photo, $userInfo['profile_url']);
}
/**
* Return user profile link around the given user name.
*
* The parameters use a trick of the sorteable table, where the first param is
* the original value of the column
*
* @param string User name (value of the column at the time of calling)
* @param string URL parameters
* @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)
{
$userInfo = api_get_user_info($row[0]);
return UserManager::getUserProfileLink($userInfo);
}
if ('learnpath' !== $origin) {
Display::display_footer();
}

109
main/group/import.php Normal file
View File

@@ -0,0 +1,109 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true);
if (!api_is_allowed_to_edit(false, true)) {
api_not_allowed(true);
}
$nameTools = get_lang('Import');
$interbreadcrumb[] = [
'url' => 'group.php?'.api_get_cidreq(),
'name' => get_lang('Groups'),
];
$form = new FormValidator(
'import',
'post',
api_get_self().'?'.api_get_cidreq()
);
$form->addElement('header', get_lang('ImportGroups'));
$form->addElement('file', 'file', get_lang('ImportCSVFileLocation'));
$form->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement(
'checkbox',
'delete_not_in_file',
null,
get_lang('DeleteItemsNotInFile')
);
$form->addElement(
'label',
null,
Display::url(
get_lang('ExampleCSVFile'),
api_get_path(WEB_CODE_PATH).'group/example.csv',
['download' => 'example.csv']
)
);
$form->addButtonImport(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 ($status != 'error') {
if (empty($data['category']) && empty($data['group'])) {
continue;
}
}
$html .= " <h3>".get_lang(ucfirst($status)).' </h3>';
if (!empty($data['category'])) {
$html .= "<h4> ".get_lang('Categories').':</h4>';
foreach ($data['category'] as $category) {
$html .= "<div>".$category['category']."</div>";
}
}
if (!empty($data['group'])) {
$html .= "<h4> ".get_lang('Groups').':</h4>';
foreach ($data['group'] as $group) {
$html .= "<div>".$group['group']."</div>";
}
}
if ($status == 'error') {
if (!empty($data)) {
foreach ($data as $message) {
if (!empty($message)) {
$html .= "<div>".$message."</div>";
}
}
}
}
}
Display::addFlash(
Display::return_message($html, 'information', false)
);
header('Location: '.api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq());
exit;
}
}
}
Display::display_header($nameTools, 'Group');
$form->display();
Display::display_footer();

7
main/group/index.html Normal file
View File

@@ -0,0 +1,7 @@
<html>
<head>
<meta http-equiv="refresh" content="0; url=group.php">
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,236 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script displays an area where teachers can edit the group properties and member list.
* Groups are also often called "teams" in the Dokeos code.
*
* @author various contributors
* @author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
*
* @todo course admin functionality to create groups based on who is in which course (or class).
*/
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true);
$group_id = api_get_group_id();
$current_group = GroupManager::get_group_properties($group_id);
$nameTools = get_lang('EditGroup');
$interbreadcrumb[] = ['url' => 'group.php', 'name' => get_lang('Groups')];
$interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']];
$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
api_not_allowed(true);
}
/**
* 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)
{
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
if ($orderListByOfficialCode === 'true') {
$cmp = api_strcmp($user_a['official_code'], $user_b['official_code']);
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']);
}
}
}
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 ['group_members' => get_lang('GroupTooMuchMembers')];
}
return true;
}
$htmlHeadXtra[] = '<script>
$(function() {
$("#max_member").on("focus", function() {
$("#max_member_selected").attr("checked", true);
});
});
</script>';
// 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 = CourseManager::get_user_list_from_course_code(
api_get_course_id(),
api_get_session_id()
);
$subscribedTutors = GroupManager::getTutors($current_group);
if ($subscribedTutors) {
$subscribedTutors = array_column($subscribedTutors, 'user_id');
}
$orderUserListByOfficialCode = api_get_setting('order_user_list_by_official_code');
$possible_users = [];
$userGroup = new UserGroup();
if (!empty($complete_user_list)) {
usort($complete_user_list, 'sort_users');
foreach ($complete_user_list as $index => $user) {
if (in_array($user['user_id'], $subscribedTutors)) {
continue;
}
//prevent invitee users add to groups or tutors - see #8091
if ($user['status'] != INVITEE) {
$officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null;
$groups = $userGroup->getUserGroupListByUser($user['user_id']);
$groupNameListToString = '';
if (!empty($groups)) {
$groupNameList = array_column($groups, 'name');
$groupNameListToString = ' - ['.implode(', ', $groupNameList).']';
}
$name = api_get_person_name($user['firstname'], $user['lastname']).
' ('.$user['username'].')'.$officialCode;
if ($orderUserListByOfficialCode === 'true') {
$officialCode = !empty($user['official_code']) ? $user['official_code']." - " : '? - ';
$name = $officialCode.' '.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
}
$possible_users[$user['user_id']] = $name.$groupNameListToString;
}
}
}
// Group members
$group_member_list = GroupManager::get_subscribed_users($current_group);
$selected_users = [];
if (!empty($group_member_list)) {
foreach ($group_member_list as $index => $user) {
$selected_users[] = $user['user_id'];
}
}
$group_members_element = $form->addElement(
'advmultiselect',
'group_members',
get_lang('GroupMembers'),
$possible_users
);
$form->addFormRule('check_group_members');
// submit button
$form->addButtonSave(get_lang('SaveSettings'));
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);
if (isset($_POST['group_members']) && count($_POST['group_members']) > 0) {
GroupManager::subscribe_users(
$values['group_members'],
$current_group
);
}
// Returning to the group area (note: this is inconsistent with the rest of chamilo)
$cat = GroupManager::get_category_from_group($current_group['iid']);
$max_member = $current_group['max_student'];
if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member &&
$max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
) {
Display::addFlash(Display::return_message(get_lang('GroupTooMuchMembers'), 'warning'));
header('Location: group.php?'.api_get_cidreq(true, false));
} else {
Display::addFlash(Display::return_message(get_lang('GroupSettingsModified'), 'success'));
header('Location: group.php?'.api_get_cidreq(true, false).'&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($current_group);
echo Display::return_message(get_lang('GroupEmptied'), 'confirm');
}
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 '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}
Display::display_header($nameTools, 'Group');
$form->setDefaults($defaults);
echo GroupManager::getSettingBar('member');
$form->display();
Display::display_footer();

392
main/group/settings.php Normal file
View File

@@ -0,0 +1,392 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script displays an area where teachers can edit the group properties and member list.
*
* @author various contributors
* @author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
*
* @todo course admin functionality to create groups based on who is in which course (or class).
*/
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true);
$group_id = api_get_group_id();
$current_group = GroupManager::get_group_properties($group_id);
if (empty($current_group)) {
api_not_allowed(true);
}
$nameTools = get_lang('EditGroup');
$interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
$interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']];
$groupMember = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
if (!$groupMember && !api_is_allowed_to_edit(false, true)) {
api_not_allowed(true);
}
// Build form
$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
$form->addElement('hidden', 'action');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', $nameTools);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Group name
$form->addElement('text', 'name', get_lang('GroupName'));
if (api_get_setting('allow_group_categories') == 'true') {
$groupCategories = GroupManager::get_categories();
$categoryList = [];
//$categoryList[] = null;
foreach ($groupCategories as $category) {
$categoryList[$category['id']] = $category['title'];
}
$form->addElement('select', 'category_id', get_lang('Category'), $categoryList);
} else {
$form->addHidden('category_id', 0);
}
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
$form->addElement('textarea', 'description', get_lang('Description'));
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', '');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Members per group
$group = [
$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,
['id' => 'max_member_selected']
),
$form->createElement('text', 'max_member', null, ['class' => 'span1', 'id' => 'max_member']),
$form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis')),
];
$form->addGroup($group, 'max_member_group', get_lang('GroupLimit'), null, false);
$form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Self registration
$group = [
$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')).
'<span>'.get_lang('GroupSelfRegistration').'</span>',
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', get_lang('DefaultSettingsForNewGroups'));
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Documents settings
$group = [
$form->createElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
$form->addGroup(
$group,
'',
Display::return_icon('folder.png', get_lang('GroupDocument')).'<span>'.get_lang('GroupDocument').'</span>',
null,
false
);
$allowDocumentGroupAccess = api_get_configuration_value('group_document_access');
if ($allowDocumentGroupAccess) {
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
$group = [
$form->createElement(
'radio',
'document_access',
null,
get_lang('DocumentGroupShareMode'),
GroupManager::DOCUMENT_MODE_SHARE
),
$form->createElement(
'radio',
'document_access',
get_lang('GroupDocument'),
get_lang('DocumentGroupCollaborationMode'),
GroupManager::DOCUMENT_MODE_COLLABORATION
),
$form->createElement(
'radio',
'document_access',
null,
get_lang('DocumentGroupReadOnlyMode'),
GroupManager::DOCUMENT_MODE_READ_ONLY
),
];
$form->addGroup(
$group,
'',
Display::return_icon(
'folder.png',
get_lang('GroupDocumentAccess')
).'<span>'.get_lang('GroupDocumentAccess').'</span>',
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', '');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
}
// Work settings
$group = [
$form->createElement(
'radio',
'work_state',
get_lang('GroupWork'),
get_lang('NotAvailable'),
GroupManager::TOOL_NOT_AVAILABLE
),
$form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
$form->addGroup(
$group,
'',
Display::return_icon('works.png', get_lang('GroupWork')).'<span>'.get_lang('GroupWork').'</span>',
null,
false
);
// Calendar settings
$group = [
$form->createElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
$form->addGroup(
$group,
'',
Display::return_icon('agenda.png', get_lang('GroupCalendar')).'<span>'.get_lang('GroupCalendar').'</span>',
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', '');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Announcements settings
$group = [
$form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
$form->createElement('radio', 'announcements_state', null, get_lang('PrivateBetweenUsers'), GroupManager::TOOL_PRIVATE_BETWEEN_USERS),
];
$form->addGroup(
$group,
'',
Display::return_icon('announce.png', get_lang('GroupAnnouncements')).'<span>'.get_lang('GroupAnnouncements').'</span>',
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Forum settings
$group = [
$form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
$form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
$form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
];
$form->addGroup(
$group,
'',
Display::return_icon('forum.png', get_lang('GroupForum')).'<span>'.get_lang('GroupForum').'</span>',
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
$form->addElement('header', '');
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Wiki settings
$group = [
$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')).'<span>'.get_lang('GroupWiki').'</span>',
'',
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-6">');
// Chat settings
$group = [
$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')).'<span>'.get_lang('Chat').'</span>',
null,
false
);
$form->addElement('html', '</div>');
$form->addElement('html', '<div class="col-md-12">');
// Submit button
$form->addButtonSave(get_lang('SaveSettings'));
$form->addElement('html', '</div>');
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;
$categoryId = isset($values['category_id']) ? $values['category_id'] : null;
GroupManager::set_group_properties(
$current_group['id'],
$values['name'],
$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,
$categoryId,
isset($values['document_access']) ? $values['document_access'] : 0
);
if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member &&
$max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
) {
Display::addFlash(Display::return_message(get_lang('GroupTooMuchMembers'), 'warning'));
header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$categoryId);
} else {
Display::addFlash(Display::return_message(get_lang('GroupSettingsModified'), 'success'));
header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$categoryId);
}
exit;
}
$defaults = $current_group;
$category = GroupManager::get_category_from_group($current_group['iid']);
if (!empty($category)) {
$defaults['category_id'] = $category['id'];
}
$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 '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}
Display::display_header($nameTools, 'Group');
$form->setDefaults($defaults);
echo GroupManager::getSettingBar('settings');
echo '<div class="row">';
$form->display();
echo '</div>';
Display::display_footer();

View File

@@ -0,0 +1,203 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This script displays an area where teachers can edit the group properties and member list.
* Groups are also often called "teams" in the Dokeos code.
*
* @author various contributors
* @author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
*
* @todo course admin functionality to create groups based on who is in which course (or class).
*/
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true);
$group_id = api_get_group_id();
$current_group = GroupManager::get_group_properties($group_id);
$nameTools = get_lang('EditGroup');
$interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
$interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']];
$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
api_not_allowed(true);
}
/**
* 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)
{
$orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
if ($orderListByOfficialCode === 'true') {
$cmp = api_strcmp($user_a['official_code'], $user_b['official_code']);
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']);
}
}
}
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']);
}
}
}
}
$htmlHeadXtra[] = '<script>
$(function() {
$("#max_member").on("focus", function() {
$("#max_member_selected").attr("checked", true);
});
});
</script>';
// 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);
$selected_tutors = [];
foreach ($group_tutor_list as $index => $user) {
$selected_tutors[] = $user['user_id'];
}
$complete_user_list = CourseManager::get_user_list_from_course_code(
api_get_course_id(),
api_get_session_id()
);
$possible_users = [];
$userGroup = new UserGroup();
$subscribedUsers = GroupManager::get_subscribed_users($current_group);
if ($subscribedUsers) {
$subscribedUsers = array_column($subscribedUsers, 'user_id');
}
$orderUserListByOfficialCode = api_get_setting('order_user_list_by_official_code');
if (!empty($complete_user_list)) {
usort($complete_user_list, 'sort_users');
foreach ($complete_user_list as $index => $user) {
if (in_array($user['user_id'], $subscribedUsers)) {
continue;
}
//prevent invitee users add to groups or tutors - see #8091
if ($user['status'] != INVITEE) {
$officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null;
$groups = $userGroup->getUserGroupListByUser($user['user_id']);
$groupNameListToString = '';
if (!empty($groups)) {
$groupNameList = array_column($groups, 'name');
$groupNameListToString = ' - ['.implode(', ', $groupNameList).']';
}
$name = api_get_person_name(
$user['firstname'],
$user['lastname']
).' ('.$user['username'].')'.$officialCode;
if ($orderUserListByOfficialCode === 'true') {
$officialCode = !empty($user['official_code']) ? $user['official_code']." - " : '? - ';
$name = $officialCode.' '.api_get_person_name(
$user['firstname'],
$user['lastname']
).' ('.$user['username'].')';
}
$possible_users[$user['user_id']] = $name.$groupNameListToString;
}
}
}
$group_tutors_element = $form->addElement(
'advmultiselect',
'group_tutors',
get_lang('GroupTutors'),
$possible_users,
'style="width: 280px;"'
);
// submit button
$form->addButtonSave(get_lang('SaveSettings'));
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['iid']);
if (isset($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
GroupManager::subscribe_tutors($values['group_tutors'], $current_group);
}
// Returning to the group area (note: this is inconsistent with the rest of chamilo)
$cat = GroupManager::get_category_from_group($current_group['iid']);
if (isset($_POST['group_members']) &&
count($_POST['group_members']) > $max_member &&
$max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
) {
Display::addFlash(Display::return_message(get_lang('GroupTooMuchMembers'), 'warning'));
header('Location: group.php?'.api_get_cidreq(true, false));
} else {
Display::addFlash(Display::return_message(get_lang('GroupSettingsModified'), 'success'));
header('Location: group.php?'.api_get_cidreq(true, false).'&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 '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}
Display::display_header($nameTools, 'Group');
$form->setDefaults($defaults);
echo GroupManager::getSettingBar('tutor');
$form->display();
Display::display_footer();