diff --git a/main/announcements/announcements.inc.php b/main/announcements/announcements.inc.php index c044bcf1d9..fd6721795a 100644 --- a/main/announcements/announcements.inc.php +++ b/main/announcements/announcements.inc.php @@ -1,4 +1,4 @@ - $category) } $group_list = GroupManager :: get_group_list($category['id']); echo ' ('.count($group_list).' '.get_lang('ExistingGroups').')'; - if (api_is_allowed_to_edit()) + if (api_is_allowed_to_edit(false,true)) { echo ''.get_lang('Edit').' '; echo ''.get_lang('Delete').' '; @@ -266,13 +266,13 @@ foreach ($group_cats as $index => $category) // create a new table-row $row = array (); // checkbox - if (api_is_allowed_to_edit() && count($group_list) > 1) + if (api_is_allowed_to_edit(false,true) && count($group_list) > 1) { $row[] = $this_group['id']; } // group name - if (api_is_allowed_to_edit() || + if (api_is_allowed_to_edit(false,true) || in_array($_user['user_id'],$tutorsids_of_group) || $this_group['is_member'] || GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_DOCUMENTS) || @@ -290,6 +290,10 @@ foreach ($group_cats as $index => $category) { $group_name .= ' ('.get_lang('MyGroup').')'; } + if(api_is_allowed_to_edit() && !empty($this_group['session_name'])) + { + $group_name .= ' ('.$this_group['session_name'].')'; + } $row[] = $group_name.'
'.stripslashes(trim($this_group['description'])); } else @@ -297,7 +301,7 @@ foreach ($group_cats as $index => $category) $row[] = $this_group['name'].'
'.stripslashes(trim($this_group['description'])); } // self-registration / unregistration - if (!api_is_allowed_to_edit()) + if (!api_is_allowed_to_edit(false,true)) { if (GroupManager :: is_self_registration_allowed($_user['user_id'], $this_group['id'])) { @@ -329,7 +333,7 @@ foreach ($group_cats as $index => $category) $tutor_info = substr($tutor_info,0,strlen($tutor_info)-2); $row[] = $tutor_info; // edit-links - if (api_is_allowed_to_edit()) + if (api_is_allowed_to_edit(false,true)) { $edit_actions = ''.get_lang('Edit').' '; $edit_actions .= ''.get_lang('Delete').' '; @@ -351,19 +355,19 @@ foreach ($group_cats as $index => $category) $table = new SortableTableFromArray($group_data, 1); $table->set_additional_parameters(array('category'=>$_GET['category'])); $column = 0; - if (api_is_allowed_to_edit() and count($group_list) > 1) + if (api_is_allowed_to_edit(false,true) and count($group_list) > 1) { $table->set_header($column++,'', false); } $table->set_header($column++,get_lang('ExistingGroups')); - if (!api_is_allowed_to_edit()) // If self-registration allowed + if (!api_is_allowed_to_edit(false,true)) // If self-registration allowed { $table->set_header($column++,get_lang('GroupSelfRegistration')); } $table->set_header($column++,get_lang('Registered')); $table->set_header($column++,get_lang('Max')); $table->set_header($column++,get_lang('GroupTutor')); - if (api_is_allowed_to_edit()) // only for course administrator + if (api_is_allowed_to_edit(false,true)) // only for course administrator { $table->set_header($column++,get_lang('Modify'), false); $form_actions = array(); diff --git a/main/group/group_category.php b/main/group/group_category.php index 278d2156d7..85391308c2 100644 --- a/main/group/group_category.php +++ b/main/group/group_category.php @@ -1,5 +1,5 @@ "group.php", "name" => get_lang('GroupManagement')); Display :: display_header($nameTools, "Group"); api_display_tool_title($nameTools); -if (!is_allowed_to_edit()) +if (!api_is_allowed_to_edit(false,true)) { api_not_allowed(); } diff --git a/main/group/group_edit.php b/main/group/group_edit.php index 38b63ff640..4fb2d9f868 100644 --- a/main/group/group_edit.php +++ b/main/group/group_edit.php @@ -65,7 +65,7 @@ $current_group = GroupManager :: get_group_properties($_SESSION['_gid']); $nameTools = get_lang('EditGroup'); $interbreadcrumb[] = array ("url" => "group.php", "name" => get_lang('GroupManagement')); -if (!api_is_allowed_to_edit()) +if (!api_is_allowed_to_edit(false,true)) { api_not_allowed(true); } diff --git a/main/group/group_space.php b/main/group/group_space.php index 7c9750e8fb..c06db198c9 100644 --- a/main/group/group_space.php +++ b/main/group/group_space.php @@ -1,4 +1,4 @@ -".get_lang("EditGroup")."

"; } @@ -153,7 +153,7 @@ if (!empty($current_group['description'])) * Group Tools */ // If the user is subscribed to the group or the user is a tutor of the group then -if (api_is_allowed_to_edit() OR GroupManager :: is_user_in_group($_SESSION['_user']['user_id'], $current_group['id'])) +if (api_is_allowed_to_edit(false,true) OR GroupManager :: is_user_in_group($_SESSION['_user']['user_id'], $current_group['id'])) { $tools = ''; $forums_of_groups = get_forums_of_group($current_group['id']); @@ -161,7 +161,7 @@ if (api_is_allowed_to_edit() OR GroupManager :: is_user_in_group($_SESSION['_use { foreach ($forums_of_groups as $key => $value) { - if($value['forum_group_public_private'] == 'public' || ($user_subscribe_to_current_group && $value['forum_group_public_private'] == 'private') || $user_is_tutor || api_is_allowed_to_edit()) + if($value['forum_group_public_private'] == 'public' || ($user_subscribe_to_current_group && $value['forum_group_public_private'] == 'private') || $user_is_tutor || api_is_allowed_to_edit(false,true)) { $tools.= Display::return_icon('forum.gif') . ' '.$value['forum_title'].'
'; } diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index 1b029ae5e4..61abccc626 100644 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -881,8 +881,10 @@ function update_Db_course($courseDbName) secret_directory varchar(255) default NULL, self_registration_allowed tinyint unsigned NOT NULL default '0', self_unregistration_allowed tinyint unsigned NOT NULL default '0', + session_id smallint unsigned NOT NULL default 0, PRIMARY KEY (id) )", __FILE__, __LINE__); + api_sql_query("ALTER TABLE `".$TABLEGROUPS . "` ADD INDEX ( session_id )", __FILE__,__LINE__); api_sql_query("CREATE TABLE `".$TABLEGROUPCATEGORIES . "` ( id int unsigned NOT NULL auto_increment, diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index 9dc068d93c..8f1a2004cb 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -1331,16 +1331,19 @@ class CourseManager ============================================================================== */ - function get_group_list_of_course($course_code) + function get_group_list_of_course($course_code, $session_id=0) { $course_info = Database :: get_course_info($course_code); $database_name = $course_info['db_name']; $group_table = Database :: get_course_table(TABLE_GROUP, $database_name); $group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $database_name); + $session_condition = $session_id==0 ? '' : ' WHERE g.session_id IN(0,'.intval($session_id).')'; + $sql = "SELECT g.id, g.name, COUNT(gu.id) userNb FROM $group_table AS g LEFT JOIN $group_user_table gu ON g.id = gu.group_id + $session_condition GROUP BY g.id ORDER BY g.name"; diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index df90648365..43d03a044e 100644 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -109,6 +109,9 @@ class GroupManager $table_user = Database :: get_main_table(TABLE_MAIN_USER); $table_course = Database :: get_main_table(TABLE_MAIN_COURSE); $table_group_user = Database :: get_course_table(TABLE_GROUP_USER, $course_db); + + $session_condition = intval($_SESSION['id_session'])==0 ? '' : ' g.session_id IN (0,'.intval($_SESSION['id_session']).') '; + $sql = "SELECT g.id , g.name , g.description , @@ -117,6 +120,7 @@ class GroupManager g.secret_directory, g.self_registration_allowed, g.self_unregistration_allowed, + g.session_id, ug.user_id is_member, COUNT(ug2.id) number_of_members FROM ".$table_group." `g` @@ -124,8 +128,14 @@ class GroupManager ON `ug`.`group_id` = `g`.`id` AND `ug`.`user_id` = '".$_user['user_id']."' LEFT JOIN ".$table_group_user." `ug2` ON `ug2`.`group_id` = `g`.`id`"; - if ($category != null) + + if ($category != null){ $sql .= " WHERE `g`.`category_id` = '".$category."' "; + $sql .= 'AND '.$session_condition; + } + else if(!empty($session_condition)) + $sql .= 'WHERE '.$session_condition; + $sql .= " GROUP BY `g`.`id` ORDER BY UPPER(g.name)"; $groupList = api_sql_query($sql,__FILE__,__LINE__); $groups = array (); @@ -137,6 +147,12 @@ class GroupManager $obj = mysql_fetch_object(api_sql_query($sql,__FILE__,__LINE__)); $thisGroup['name'] = $obj->title; } + if($thisGroup['session_id']!=0) + { + $sql_session = 'SELECT name FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$thisGroup['session_id']; + $rs_session = api_sql_query($sql_session,__FILE__,__LINE__); + $thisGroup['session_name'] = Database::result($rs_session,0,0); + } $groups[] = $thisGroup; } return $groups; @@ -160,7 +176,7 @@ class GroupManager { $places = $category['max_student']; } - $sql = "INSERT INTO ".$table_group." SET category_id='".$category_id."', max_student = '".$places."', doc_state = '".$category['doc_state']."', calendar_state = '".$category['calendar_state']."', work_state = '".$category['work_state']."', announcements_state = '".$category['announcements_state']."', wiki_state = '".$category['wiki_state']."', self_registration_allowed = '".$category['self_reg_allowed']."', self_unregistration_allowed = '".$category['self_unreg_allowed']."'"; + $sql = "INSERT INTO ".$table_group." SET category_id='".$category_id."', max_student = '".$places."', doc_state = '".$category['doc_state']."', calendar_state = '".$category['calendar_state']."', work_state = '".$category['work_state']."', announcements_state = '".$category['announcements_state']."', wiki_state = '".$category['wiki_state']."', self_registration_allowed = '".$category['self_reg_allowed']."', self_unregistration_allowed = '".$category['self_unreg_allowed']."', session_id=".intval($_SESSION['id_session']); api_sql_query($sql,__FILE__,__LINE__); $lastId = mysql_insert_id(); /*$secret_directory = uniqid("")."_team_".$lastId; @@ -1358,7 +1374,7 @@ class GroupManager { return true; } - elseif (api_is_allowed_to_edit()) + elseif (api_is_allowed_to_edit(false,true)) { return true; } diff --git a/main/install/migrate-db-1.8.5-1.8.6-pre.sql b/main/install/migrate-db-1.8.5-1.8.6-pre.sql index 25167136f8..8a64662159 100644 --- a/main/install/migrate-db-1.8.5-1.8.6-pre.sql +++ b/main/install/migrate-db-1.8.5-1.8.6-pre.sql @@ -62,3 +62,5 @@ ALTER TABLE student_publication ADD session_id SMALLINT UNSIGNED NOT NULL defaul ALTER TABLE student_publication ADD INDEX ( session_id ) ; ALTER TABLE calendar_event ADD session_id SMALLINT UNSIGNED NOT NULL default 0 ; ALTER TABLE calendar_event ADD INDEX ( session_id ) ; +ALTER TABLE group_info ADD session_id SMALLINT UNSIGNED NOT NULL DEFAULT 0; +ALTER TABLE group_info ADD INDEX ( session_id ) ;