Updating group files from 1.9.x using iid instead of id see BT#5768

1.10.x
Julio Montoya 12 years ago
parent 7f76f70cec
commit 387ceda90e
  1. 256
      main/group/group.php
  2. 124
      main/group/group_category.php
  3. 207
      main/group/group_creation.php
  4. 174
      main/group/group_overview.php
  5. 425
      main/group/group_space.php
  6. 71
      main/group/import.php
  7. 222
      main/group/member_settings.php
  8. 194
      main/group/settings.php
  9. 185
      main/group/tutor_settings.php
  10. 10
      main/inc/lib/api.lib.php
  11. 1427
      main/inc/lib/groupmanager.lib.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[] = '<script>
$(document).ready( function() {
for (i=0;i<$(".actions").length;i++) {
$(document).ready(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');
$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 '<div class="actions">';
if (api_is_allowed_to_edit(false, true)) {
echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('new_group.png', get_lang('NewGroupCreate'),'',ICON_SIZE_MEDIUM).'</a>';
if (CourseManager::count_rows_course_table(Database::get_course_table(TABLE_GROUP),api_get_session_id(), api_get_course_int_id()) > 0) {
echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group_summary.png', get_lang('GroupOverview'),'',ICON_SIZE_MEDIUM).'</a>';
}
if (api_get_setting('allow_group_categories') == 'true') {
echo '<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 {
echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('settings.png', get_lang('PropModify'),'',ICON_SIZE_MEDIUM).'</a>';
}
echo '<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>';
echo '<a href="../user/user.php?'.api_get_cidreq().'">'.Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'),'',ICON_SIZE_MEDIUM).'</a>';
}
echo '<a href="group_creation.php?'.api_get_cidreq().'">'.
Display::return_icon('new_group.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
if (api_get_setting('allow_group_categories') == 'true') {
echo '<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 {
echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
}
echo '<a href="import.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<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>';
$group_cats = GroupManager :: get_categories(api_get_course_id());
echo '<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>';
if (api_get_setting('allow_group_categories') == 'true' && count($group_cats) > 1) {
echo ' <a href="?'.api_get_cidreq().'&show_all=1">'.Display::return_icon('group.png',get_lang('ShowAll'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'">'.
Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="../user/user.php?'.api_get_cidreq().'">'.
Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).'</a>';
echo GroupManager::getSearchForm();
}
echo '</div>';
/*
* List all categories
*/
$group_cats = GroupManager::get_categories(api_get_course_id());
echo '</div>';
/* 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 '<img src="../img/folder_group_category.gif" alt=""/>';
//echo '<a href="group.php?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'">'.$category['title'].'</a>';
} else {
//echo '<img src="../img/folder_document.gif" alt=""/>';
//echo '<a href="group.php?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&amp;category='.$category['id'].'">'.$category['title'].'</a>';
//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 .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'" title="'.get_lang('Edit').'">'.Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
$actions .= '<a href="group.php?'.api_get_cidreq().'&action=delete_category&amp;id='.$category['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
$actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'" title="'.get_lang('Edit').'">'.
Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
$actions .= '<a href="group.php?'.api_get_cidreq().'&action=delete_category&amp;id='.$category['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'">'.
Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
if ($index != 0) {
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index -1]['id'].'">'.Display::return_icon('up.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;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&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'">'.Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
$actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'">'.
Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
}
}
echo Display::page_header($category['title'].' '. $label.' '.$actions);
echo '<p style="margin: 0px;margin-left: 50px;">'.$category['description'].'</p><p/>';
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;
$_SESSION['_gid'] = 0;

@ -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[] = '<script>
@ -72,7 +77,7 @@ $(document).ready( function() {
});
});
</script>';
$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, '<b>'.get_lang('DefaultSettingsForNewGroups').'</b>');
$form->addElement('html', '<br /><br /><div class="sectiontitle" >'.get_lang('DefaultSettingsForNewGroups'));
$form->addElement('html', '</div>');
@ -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;

@ -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').'<br /><br /><a href="group_creation.php?'.api_get_cidreq().'">&laquo; '.get_lang('Back').'</a>', 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)
{
for( i=1; i<number_of_groups; i++)
{
element = document.getElementById(key+'_'+i);
element.disabled = !element.disabled;
disabled = element.disabled;
}
ref = document.getElementById(key+'_0');
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
if (!is_numeric($_POST['number_of_groups']) || intval($_POST['number_of_groups']) < 1) {
Display :: display_error_message(get_lang('PleaseEnterValidNumber').'<br /><br /><a href="group_creation.php?'.api_get_cidreq().'">&laquo; '.get_lang('Back').'</a>', false);
} else {
$number_of_groups = intval($_POST['number_of_groups']);
if ($number_of_groups > 1) {
?>
<script type="text/javascript">
var number_of_groups = <?php echo $number_of_groups; ?>;
function switch_state(key) {
for( i=1; i<number_of_groups; i++) {
element = document.getElementById(key+'_'+i);
element.disabled = !element.disabled;
disabled = element.disabled;
}
ref = document.getElementById(key+'_0');
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;
@ -133,20 +133,21 @@ elseif (isset($_POST['number_of_groups'])) {
$cat_options[$category['id']] = $category['title'];
}
}
$form = new FormValidator('create_groups_step2', 'POST', api_get_self().'?'.api_get_cidreq());
$form = new FormValidator('create_groups_step2', 'post', api_get_self().'?'.api_get_cidreq());
// Modify the default templates
// Modify the default templates.
$renderer = $form->defaultRenderer();
$form_template = "<form {attributes}>\n<div>\n<table>\n{content}\n</table>\n</div>\n</form>";
$form_template = '<form {attributes}> <div><table class="table table-stripped">{content}</table></div></form>';
$renderer->setFormTemplate($form_template);
$element_template = <<<EOT
<tr>
<td>
<!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}
<!-- BEGIN required -->
<span class="form_required">*</span> <!-- END required -->{label}
</td>
<td>
<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> {element}
<!-- BEGIN error -->
<span class="form_error">{error}</span><br /><!-- END error --> {element}
</td>
</tr>
@ -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, '<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('GroupTutor').'</b>');
$group_el[] = $form->createElement('static', null, null, '<b>'.get_lang('GroupPlacesThis').'</b>');
$form->addGroup($group_el, 'groups', null, "\n</td>\n<td>\n", false);
// Checkboxes
@ -214,16 +213,16 @@ EOT;
* Show form to generate new groups
*/
$categories = GroupManager :: get_categories();
//echo '<blockquote>';
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();
Display :: display_footer();

@ -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 = '<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':
$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 {
?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CSS_PATH); ?>default.css" /> <?php
}
// Action links
echo '<div class="actions">';
echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('new_group.png', get_lang('NewGroupCreate'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group.php?'.api_get_cidreq().'">'.Display::return_icon('group.png', get_lang('Groups'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_creation.php?'.api_get_cidreq().'">'.
Display::return_icon('new_group.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
if (api_get_setting('allow_group_categories') == 'true') {
echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.Display::return_icon('new_folder.png', get_lang('AddCategory'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<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 {
//echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('edit_group.gif').'&nbsp;'.get_lang('PropModify').'</a>&nbsp;';
echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('settings.png', get_lang('PropModify'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
}
//echo Display::return_icon('csv.gif', get_lang('ExportAsCSV')).'<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=csv">'.get_lang('ExportAsCSV').'</a> ';
echo '<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>';
echo '</div>';
echo '<a href="import.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
$categories = GroupManager::get_categories();
echo '<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>';
foreach ($categories as $index => $category) {
if (api_get_setting('allow_group_categories') == 'true') {
echo '<h2>'.$category['title'].'</h2>';
}
$groups = GroupManager::get_group_list($category['id']);
echo '<ul>';
if (!empty($groups)) {
foreach ($groups as $index => $group) {
echo '<li>';
echo Display::tag('h3', Security::remove_XSS($group['name']));
echo '<ul>';
$users = GroupManager::get_users($group['id']);
if (!empty($users)) {
foreach ($users as $index => $user) {
$user_info = api_get_user_info($user);
$username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
echo '<li title="'.$username.'">'.api_get_person_name($user_info['firstName'], $user_info['lastName']).'</li>';
}
} else {
//echo Display::tag('li', get_lang('NoStudents'));
}
echo '</ul>';
echo '</li>';
}
} else {
//echo Display::tag('li', get_lang('NoData'));
}
echo '</ul>';
}
echo '<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>';
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
/* FOOTER */
echo '<a href="group.php?'.api_get_cidreq().'">'.
Display::return_icon('group.png', get_lang('Groups'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="../user/user.php?'.api_get_cidreq().'">'.
Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).'</a>';
echo GroupManager::getSearchForm();
echo '</div>';
echo GroupManager::getOverview($courseId, $keyword);
if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
Display::display_footer();
}
Display::display_footer();
}

@ -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 '<div class="actions">';
echo '<a href="group.php">'.Display::return_icon('back.png', get_lang('BackToGroupList'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group.php">'.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['id'])) {
$subscribe_group = '<a class="btn" href="'.api_get_self().'?selfReg=1&amp;group_id='.$current_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.get_lang("RegIntoGroup").'</a>';
$subscribe_group = '<a class="btn" href="'.api_get_self().'?selfReg=1&amp;group_id='.$current_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.get_lang("RegIntoGroup").'</a>';
}
/*
@ -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 = '<a class="btn" href="'.api_get_self().'?selfUnReg=1" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.get_lang("StudentUnsubscribe").'</a>';
$unsubscribe_group = '<a class="btn" 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>';
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 = '<a href="group_edit.php?cidReq='.api_get_course_id().'&origin='.$my_origin.'&gidReq='.api_get_group_id().'">'.Display::return_icon('edit.png', get_lang('EditGroup'), '', ICON_SIZE_SMALL).'</a>';
$edit_url = '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?cidReq='.api_get_course_id().'&origin='.$my_origin.'&gidReq='.api_get_group_id().'">'.
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);
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>';
echo '<p>'.Security::remove_XSS($current_group['description']).'</p>';
}
/*
@ -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']).'&amp;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().'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;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()."&amp;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()."&amp;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']).'&amp;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().'&amp;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().'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;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()."&amp;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()."&amp;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 = '<img src="'.$image_repository.$existing_image.'" align="absbottom" alt="'.api_get_person_name($tutor['firstname'], $tutor['lastname']).'" width="32" height="32" title="'.api_get_person_name($tutor['firstname'], $tutor['lastname']).'" />';
$tutor_info .= '<a href="../user/userInfo.php?origin='.$my_origin.'&amp;uInfo='.$tutor['user_id'].'">'.$photo.'&nbsp;'.Display::tag('span', api_get_person_name($tutor['firstname'], $tutor['lastname']), array('title' => $username)).'</a>';
}
isset($origin) ? $my_origin = $origin:$my_origin='';
$tutor_info .= '<ul class="thumbnails">';
foreach ($tutors as $index => $tutor) {
$tab_user_info = Database::get_user_info_from_id($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'];
$completeName = api_get_person_name($tutor['firstname'], $tutor['lastname']);
$photo = '<img src="'.$image_repository.$existing_image.'" alt="'.$completeName.'" width="32" height="32" title="'.$completeName.'" />';
$tutor_info .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'user/userInfo.php?origin='.$my_origin.'&amp;uInfo='.$tutor['user_id'].'">'.
$photo.'&nbsp;'.$completeName.'</a></li>';
}
$tutor_info .= '</ul>';
}
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 '<br />';
/*
* 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 <patrick.cool@UGent.be>, 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 <patrick.cool@UGent.be>, 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 <patrick.cool@UGent.be>, 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 = '<center><img src="'.$image_repository.$existing_image.'" alt="'.$userinfo['complete_name'].'" width="22" height="22" title="'.$userinfo['complete_name'].'" /></center>';
return '<a href="../user/userInfo.php?origin='.$origin.'&amp;uInfo='.$user_id.'">'.$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 = '<center><img src="'.$image_repository.$existing_image.'" alt="'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'" width="22" height="22" title="'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'" /></center>';
return '<a href="../user/userInfo.php?origin='.$origin.'&amp;uInfo='.$user_id.'">'.$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 '<a href="../user/userInfo.php?uInfo='.$row[0].'&amp;'.$url_params.'" title="'.$username.'">'.$name.'</a>';
}
// Footer
$orig = isset($origin) ? $origin : '';
if ($orig != 'learnpath') {
Display::display_footer();
}
Display::display_footer();
}

@ -0,0 +1,71 @@
<?php
/* For licensing terms, see /license.txt */
// Name of the language file that needs to be included
$language_file = 'group';
require_once '../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');
/* Libraries */
include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
include_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
$interbreadcrumb[] = array('url' => '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 .= " <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>";
}
}
}
echo $html;
}
}
}
$form->display();
Display::display_footer();

@ -0,0 +1,222 @@
<?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
* @package chamilo.group
* @todo course admin functionality to create groups based on who is in which course (or class).
*/
/* INIT SECTION */
// Name of the language file that needs to be included
$language_file = 'group';
require_once '../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[] = array ('url' => '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[] = '<script>
$(document).ready( 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 = 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}
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
<tr>
<td valign="top">{unselected}</td>
<td align="center">{add}<br /><br />{remove}</td>
<td valign="top">{selected}</td>
</tr>
</table>');
$group_members_element->setButtonAttributes('add', array('class' => 'btn arrowr'));
$group_members_element->setButtonAttributes('remove', array('class' => 'btn arrowl'));
$form->addFormRule('check_group_members');
/*$url = '<a class="btn btn-danger" href="'.api_get_self().'?'.api_get_cidreq(true, false).'&action=empty&amp;id='.$group_id.'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('EmptyGroup').'">'.
get_lang('EmptyGroup').'</a>&nbsp;';
$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 '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}
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();

@ -0,0 +1,194 @@
<?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
* @package chamilo.group
* @todo course admin functionality to create groups based on who is in which course (or class).
*/
/* INIT SECTION */
// Name of the language file that needs to be included
$language_file = 'group';
require_once '../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[] = array ('url' => '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', '<div class="span6">');
// 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', '</div>');
$form->addElement('html', '<div class="span6">');
// 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', '</div>');
$form->addElement('html', '<div class="span12">');
// Submit button
$form->addElement('style_submit_button', 'submit', get_lang('SaveSettings'), 'class="save"');
$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;
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 '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}
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 '<div class="row">';
$form->display();
echo '</div>';
Display :: display_footer();

@ -0,0 +1,185 @@
<?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
* @package chamilo.group
* @todo course admin functionality to create groups based on who is in which course (or class).
*/
/* INIT SECTION */
// Name of the language file that needs to be included
$language_file = 'group';
require_once '../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[] = array ('url' => '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[] = '<script>
$(document).ready( 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['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}
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
<tr>
<td valign="top">{unselected}</td>
<td align="center">{add}<br /><br />{remove}</td>
<td valign="top">{selected}</td>
</tr>
</table>
');
$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 '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
}
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();

@ -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;
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save