[svn r16491] the coachs can now delete only groups of his sessions (FS#2864)

skala
Eric Marguin 16 years ago
parent 2091267527
commit 86ea51a639
  1. 6
      main/group/group.php
  2. 50
      main/inc/lib/groupmanager.lib.php
  3. 4
      main/inc/lib/main_api.lib.php

@ -272,7 +272,7 @@ foreach ($group_cats as $index => $category)
}
// group name
if (api_is_allowed_to_edit(false,true) ||
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) ||
@ -280,7 +280,9 @@ foreach ($group_cats as $index => $category)
GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_ANNOUNCEMENT) ||
GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_WORK) ||
GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_WIKI))
&& !(api_is_course_coach() && intval($this_group['session_id'])!=intval($_SESSION['id_session'])))
{
$group_name = '<a href="group_space.php?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;gidReq='.$this_group['id'].'">'.stripslashes($this_group['name']).'</a>';
if ($_SESSION['_user']['user_id'] && $_SESSION['_user']['user_id'] == $this_group['id_tutor'])
{
@ -333,7 +335,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(false,true))
if (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && intval($this_group['session_id'])!=intval($_SESSION['id_session'])))
{
$edit_actions = '<a href="group_edit.php?'.api_get_cidreq().'&gidReq='.$this_group['id'].'" title="'.get_lang('Edit').'"><img src="../img/edit.gif" alt="'.get_lang('Edit').'"/></a>&nbsp;';
$edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&category='.$category['id'].'&amp;action=delete_one&amp;id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang('ConfirmYourChoice')))."'".')) return false;" title="'.get_lang('Delete').'"><img src="../img/delete.gif" alt="'.get_lang('Delete').'"/></a>&nbsp;';

@ -351,6 +351,22 @@ class GroupManager
$forum_topic_table = Database :: get_course_table(TABLE_FORUM_POST, $course_db);
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids);
if(api_is_course_coach())
{ //a coach can only delete courses from his session
for($i=0 ; $i<count($group_ids) ; $i++)
{
if(!api_is_element_in_the_session(TOOL_GROUP,$group_ids[$i]))
{
array_splice($group_ids,$i,1);
$i--;
}
}
if(count($group_ids)==0)
return 0;
}
// define repository for deleted element
$group_garbage = api_get_path(GARBAGE_PATH).$course['path']."/group/";
$perm = api_get_setting('permissions_for_new_directories');
@ -359,7 +375,7 @@ class GroupManager
FileManager :: mkdirs($group_garbage, $perm);
// Unsubscribe all users
GroupManager :: unsubscribe_all_users($group_ids);
$sql = 'SELECT id, secret_directory FROM '.$group_table.' WHERE id IN ('.implode(' , ', $group_ids).')';
$sql = 'SELECT id, secret_directory, session_id FROM '.$group_table.' WHERE id IN ('.implode(' , ', $group_ids).')';
$db_result = api_sql_query($sql,__FILE__,__LINE__);
$forum_ids = array ();
while ($group = mysql_fetch_object($db_result))
@ -714,6 +730,21 @@ class GroupManager
function fill_groups($group_ids)
{
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids);
if(api_is_course_coach())
{
for($i=0 ; $i<count($group_ids) ; $i++)
{
if(!api_is_element_in_the_session(TOOL_GROUP,$group_ids[$i]))
{
array_splice($group_ids,$i,1);
$i--;
}
}
if(count($group_ids)==0)
return false;
}
global $_course;
$category = GroupManager :: get_category_from_group($group_ids[0]);
$groups_per_user = $category['groups_per_user'];
@ -1054,6 +1085,23 @@ class GroupManager
$group_ids = is_array($group_ids) ? $group_ids : array ($group_ids);
if( count($group_ids) > 0)
{
if(api_is_course_coach())
{
for($i=0 ; $i<count($group_ids) ; $i++)
{
if(!api_is_element_in_the_session(TOOL_GROUP,$group_ids[$i]))
{
array_splice($group_ids,$i,1);
$i--;
}
}
if(count($group_ids)==0)
{
return false;
}
}
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
$sql = 'DELETE FROM '.$table_group_user.' WHERE group_id IN ('.implode(',', $group_ids).')';
$result = api_sql_query($sql,__FILE__,__LINE__);

@ -3127,6 +3127,10 @@ function api_is_element_in_the_session($tool, $element_id, $session_id=null)
$table_tool = Database::get_course_table(TABLE_AGENDA);
$key_field = 'id';
break;
case TOOL_GROUP :
$table_tool = Database::get_course_table(TABLE_GROUP);
$key_field = 'id';
break;
default: return false;
}

Loading…
Cancel
Save