--- loncom/interface/loncoursegroups.pm 2009/05/11 16:51:27 1.101 +++ loncom/interface/loncoursegroups.pm 2010/01/26 03:26:02 1.101.4.2 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursegroups.pm,v 1.101 2009/05/11 16:51:27 bisitz Exp $ +# $Id: loncoursegroups.pm,v 1.101.4.2 2010/01/26 03:26:02 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -54,7 +54,7 @@ sub handler { if (! ($env{'request.course.fn'})) { # Not in a course $env{'user.error.msg'}= - "/adm/coursegroups:mdg:0:0:Cannot edit or view course groups"; + "/adm/coursegroups:mdg:0:0:Cannot edit or view course/community groups"; return HTTP_NOT_ACCEPTABLE; } @@ -537,7 +537,7 @@ sub group_administration { if (ref($stored{'autorole'}) eq 'ARRAY') { foreach my $role (@{$stored{'autorole'}}) { - unless ($role eq 'cc') { + unless (($role eq 'cc') || ($role eq 'co')) { $elements{'modify'}{'change_settings'}{'sec_'.$role} = 'selectbox'; } @@ -1086,7 +1086,7 @@ sub display_control { &add_members_form($r,$cdom,$cnum,$action,$state,$page,$startdate, $enddate,$groupname,$description,$granularity, $quota,$sectioncount,$tools,$functions,$stored, - $states,$navbuttons,$gpterm,$ucgpterm); + $states,$navbuttons,$gpterm,$ucgpterm,$crstype); } elsif ($state eq 'pick_members') { &choose_members_form($r,$cdom,$cnum,$action,$state,$page, $groupname,$description,$granularity,$quota, @@ -1119,15 +1119,15 @@ sub display_control { my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action); if ($state eq 'verify') { &verify_delete($r,$groupname,$state,$action,$page,$states, - \%stored); + \%stored,$crstype); } elsif ($state eq 'result') { - &delete_group($r,$cdom,$cnum,$groupname); + &delete_group($r,$cdom,$cnum,$groupname,$crstype); } } elsif ($action eq 'reenable') { my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action); if ($state eq 'verify') { &verify_reenable($r,$groupname,$state,$action,$page,$states, - \%stored); + \%stored,$crstype); } elsif ($state eq 'result') { &reenable_group($r,$cdom,$cnum,$groupname); } @@ -1135,15 +1135,20 @@ sub display_control { } sub verify_delete { - my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_; + my ($r,$groupname,$formname,$action,$page,$states,$stored,$crstype) = @_; $r->print(&Apache::lonhtmlcommon::echo_form_input([])); $r->print(&mt('You have requested deletion of the group [_1].' ,''.$stored->{'description'}.''). '

'.&mt('When a group is deleted the following occurs:').''.&mt('Although a deleted group is no longer accessible, the group name used for the group will be reserved, and will not be available for assignment to a new group in the same course in the future.')); + '
  • '.&mt('The group ceases to be available either for viewing or for modification of group settings and membership.').'
  • '); + if ($crstype eq 'Community') { + $r->print( '
  • '.&mt("The group folder is removed from the folder containing it - normally this is the 'Community Groups' folder which contains folders for all groups in the community.").'
  • '. + ''.&mt("Although a deleted group is no longer accessible, the group name used for the group will be reserved, and will not be available for assignment to a new group in the same community in the future.")); + } else { + $r->print( '
  • '.&mt("The group folder is removed from the folder containing it - normally this is the 'Course Groups' folder which contains folders for all groups in the course.").'
  • '. + ''.&mt("Although a deleted group is no longer accessible, the group name used for the group will be reserved, and will not be available for assignment to a new group in the same course in the future.")); + } my $prevtext = &mt('Go back'); my $nexttext = &mt('Delete group'); my $prev; @@ -1156,7 +1161,7 @@ sub verify_delete { } sub delete_group { - my ($r,$cdom,$cnum,$groupname) = @_; + my ($r,$cdom,$cnum,$groupname,$crstype) = @_; my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum, $groupname); my $now = time; @@ -1198,22 +1203,24 @@ sub delete_group { .&mt('Group deletion failed because deletion of [_1] out of [_2] members failed.' ,$num_fail,$num_users) .''); - } else { my ($result,$message) = &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum, $groupname,'delete'); if ($result eq 'ok') { - my $outcome = &modify_folders($cdom,$cnum,$groupname); + my $outcome = &modify_folders($cdom,$cnum,$groupname,$crstype); if ($outcome eq '') { $r->print('
    ' .&mt('Group successfully deleted.') .'
    '); } else { - $r->print('
    ' - .&mt("Although the group was deleted, an error occurred when removing" - ." the group's folder from the 'Course Groups' folder: [_1]",$outcome) - .'
    '); + $r->print('
    '); + if ($crstype eq 'Community') { + $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Community Groups' folder: [_1]",$outcome)); + } else { + $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Course Groups' folder: [_1]",$outcome)); + } + $r->print('
    '); } } else { $r->print('
    ' @@ -1225,11 +1232,16 @@ sub delete_group { } sub reenable_folder { - my ($cdom,$cnum,$groupname,$description) = @_; + my ($cdom,$cnum,$groupname,$description,$crstype) = @_; my $outcome; my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/'; my $allgrpsmap = $crspath.'group_allfolders.sequence'; - my $foldertitle = &mt('Course Folder -[_1]',$description); + my $foldertitle; + if ($crstype eq 'Community') { + $foldertitle = &mt("Community Folder -[_1]",$description); + } else { + $foldertitle = &mt("Course Folder -[_1]",$description); + } my $mapurl = $crspath.'group_folder_'. $groupname.'.sequence'; my ($errtext,$fatal)=&LONCAPA::map::mapread($allgrpsmap); @@ -1258,14 +1270,19 @@ sub reenable_folder { } sub modify_folders { - my ($cdom,$cnum,$groupname) = @_; + my ($cdom,$cnum,$groupname,$crstype) = @_; my ($outcome,$groupmap,$groupmapres,$map,$id,$src); my $navmap = Apache::lonnavmaps::navmap->new(); if (!defined($navmap)) { - $outcome = '
    '. - &mt('Error reading course contents.').' '. - &mt('You need to re-initialize the course.'). - '
    '; + $outcome = '
    '; + if ($crstype eq 'Community') { + $outcome .= &mt("Error reading community contents.").' '. + &mt("You need to re-initialize the community."); + } else { + $outcome .= &mt("Error reading course contents.").' '. + &mt("You need to re-initialize the course."); + } + $outcome .= '
    '; return $outcome; } $groupmap = '/uploaded/'.$cdom.'/'.$cnum.'/'.'group_folder_'. @@ -1320,13 +1337,18 @@ sub modify_folders { } sub verify_reenable { - my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_; + my ($r,$groupname,$formname,$action,$page,$states,$stored,$crstype) = @_; $r->print(&Apache::lonhtmlcommon::echo_form_input([])); $r->print(&mt('You have requested enabling the previously deleted group [_1].' ,''.$stored->{'description'}.''). '

    '.&mt('When a deleted group is re-enabled the following occurs:').''); + '
  • '.&mt('Group settings and membership at the time the group was deleted are reinstated.').'
  • '); + if ($crstype eq 'Community') { + $r->print(&mt("A group folder is added to the 'Community Groups' folder which contains folders for all groups in the community.")); + } else { + $r->print(&mt("A group folder is added to the 'Course Groups' folder which contains folders for all groups in the course.")); + } + $r->print('
  • '); my $prevtext = &mt('Go back'); my $nexttext = &mt('Reenable group'); my $prev; @@ -1339,7 +1361,7 @@ sub verify_reenable { } sub reenable_group { - my ($r,$cdom,$cnum,$groupname) = @_; + my ($r,$cdom,$cnum,$groupname,$crstype) = @_; my %groups = &Apache::longroup::coursegroups($cdom,$cnum,$groupname, 'deleted_groups'); @@ -1413,15 +1435,19 @@ $context) eq 'ok') { .&mt('There were no group members to reinstate, as none were removed when the group was deleted.') .'
    '); } - my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description); + my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description,$crstype); if ($outcome eq '') { $r->print('
    ' .&mt('Group successfully re-enabled.') .'
    '); } else { - $r->print('
    ' - .&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Course Groups' folder: [_1]",$outcome) - .'
    '); + $r->print('
    '); + if ($crstype eq 'Community') { + $r->print(&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Community Groups' folder: [_1]",$outcome)); + } else { + $r->print(&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Course Groups' folder: [_1]",$outcome)); + } + $r->print('
    '); } } else { $r->print('
    ' @@ -1588,7 +1614,7 @@ sub general_settings_form { @{$tools} = sort(keys(%{$functions})); &privilege_specificity($r,$action,3,$tools,$stored,$toolprivs, $fixedprivs,\@available,$formname, - $gpterm,$ucgpterm,$functions); + $gpterm,$ucgpterm,$functions,$crstype); &mapping_options($r,$action,$formname,$page,$sectioncount, $states,$stored,$navbuttons,4,5, $gpterm,$ucgpterm,$crstype,$cdom,$cnum); @@ -1741,38 +1767,49 @@ sub get_quota_constraints { } sub membership_options { - my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm)=@_; - my $crstype = &Apache::loncommon::course_type(); + my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm,$crstype)=@_; my %lt = &Apache::lonlocal::texthash( 'pipa' => 'Build a list of users for selection of group members', - 'gmem' => "Group membership selection list criteria:", - 'picr' => 'Pick the criteria to use to build a list of '. - lc($crstype).' users from which you will select ', - 'meof' => "members of the new group.", - 'admg' => "additional members of the group.", - 'ifno' => "If you do not wish to add members when you first ". - "create the group, there is no need to pick any criteria.", - 'asub' => "A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section changes in the course.", + 'gmem' => 'Group membership selection list criteria:', + 'picr' => 'Pick the criteria to use to build a list of course users from which you will select members of the new group.', + 'pica' => 'Pick the criteria to use to build a list of course users from which you will select additional members of the group.', + 'ifno' => 'If you do not wish to add members when you first create the group, there is no need to pick any criteria.', 'acty' => 'Access types', - 'coro' => $crstype.' roles', - 'cose' => $crstype.' sections', + 'coro' => 'Course roles', + 'cose' => 'Course sections', ); + if ($crstype eq 'Community') { + $lt{'picr'} = &mt('Pick the criteria to use to build a list of community participants from which you will select '); + $lt{'asub'} = &mt('A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section [_1]changes[_2] in the course.','',''); + $lt{'coro'} = &mt('Community roles'); + $lt{'cose'} = &mt('Community sections'); + } else { + $lt{'asub'} = &mt('A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section [_1]changes[_2] in the course.','',''); + } + my %status_types = ( active => &mt('Currently has access'), previous => &mt('Previously had access'), future => &mt('Will have future access'), ); - my @roles = ('st','cc','in','ta','ep','cr'); + my @roles = ('st'); + if ($crstype eq 'Community') { + push(@roles,'co'); + } else { + push(@roles,'cc'); + } + push (@roles,('in','ta','ep','ad','cr')); my @sections = keys(%{$sectioncount}); $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'pipa'}).' - '.$lt{'gmem'}.'
    '.$lt{'picr'}); + '.$lt{'gmem'}.'
    '); + if ($action eq 'create') { - $r->print($lt{'meof'}.'
    '.$lt{'ifno'}.'
    '.$lt{'asub'}); + $r->print($lt{'picr'}.'
    '.$lt{'ifno'}.'
    '.$lt{'asub'}); } else { - $r->print($lt{'admg'}); + $r->print($lt{'pica'}); } $r->print('
    @@ -1888,7 +1925,8 @@ sub choose_members_form { } } &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs, - $fixedprivs,\@available,$formname,$gpterm,$ucgpterm); + $fixedprivs,\@available,$formname,$gpterm,$ucgpterm, + $functions,$crstype); my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx, $stored,$memimg,$users,$userdata, $granularity,\%origmembers,$gpterm, @@ -2165,7 +2203,7 @@ sub pick_new_members { sub privilege_specificity { my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available, - $formname,$gpterm,$ucgpterm,$functions) = @_; + $formname,$gpterm,$ucgpterm,$functions,$crstype) = @_; my %lt = &Apache::lonlocal::texthash ( 'uprv' => 'User privileges for collaborative tools', 'frty' => 'For each collaborative tool you have chosen to include, '. @@ -2199,6 +2237,9 @@ sub privilege_specificity { 'oppr' => 'Optional privileges', 'defp' => 'The default privileges new members will receive are:', ); + if ($crstype eq 'Community') { + $lt{'thes'} = &mt('These will be the privileges given to members assigned in the future via automatic group assignment for users who receive specific sections/roles in the community '); + } my $totaloptionalprivs = 0; foreach my $tool (@{$tools}) { foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) { @@ -2297,9 +2338,9 @@ sub default_privileges { &Apache::lonhtmlcommon::row_title($lt{'func'},undef, 'LC_groups_functionality')); my @tableHeader; - foreach my $key (sort(keys(%{$functions}))){ - push (@tableHeader,&mt(${$functions}{$key})); - } + if ((ref($functions) eq 'HASH') && (ref($tools) eq 'ARRAY')) { + @tableHeader = map { $functions->{$_}; } @{$tools}; + } $r->print(join('', @tableHeader)); $r->print(&Apache::lonhtmlcommon::row_closure(1)); my $fixed = ''; @@ -2754,7 +2795,7 @@ sub change_privs_form { sub add_members_form { my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname, $description,$granularity,$quota,$sectioncount,$tools,$functions, - $stored,$states,$navbuttons,$gpterm,$ucgpterm)=@_; + $stored,$states,$navbuttons,$gpterm,$ucgpterm,$crstype)=@_; $r->print('
    '); my @available = (); my @unavailable = (); @@ -2763,7 +2804,7 @@ sub add_members_form { $groupname,$description,$granularity,$quota, \@available,\@unavailable,$gpterm,$ucgpterm); &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm, - $ucgpterm); + $ucgpterm,$crstype); my $nexttext = $$navbuttons{'gtns'}; my $prevtext = $$navbuttons{'gtpp'}; &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext, @@ -3094,7 +3135,7 @@ sub process_request { &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools, $enddate,$startdate,$userdata,$idx,$toolprivs, $usertools,$specificity,\@defprivs,$memchg,$gpterm, - $ucgpterm); + $ucgpterm,$crstype); } return; } @@ -3256,17 +3297,28 @@ sub write_group_data { } undef($navmap); } else { - $error = &mt('An error occurred while setting parameters '. + if ($crstype eq 'Community') { + $error = &mt("An error occurred while setting parameters '. + 'for Discussion Boards folder: '. + 'Could not retrieve community information"); + } else { + $error = &mt("An error occurred while setting parameters '. 'for Discussion Boards folder: '. - 'Could not retrieve course information' ); + 'Could not retrieve course information"); + } } } else { $r->print($outcome); } } } else { - $error = &mt("An error occurred while retrieving the contents of the group's folder.").'
    '. - &mt('You need to re-initialize the course.'); + $error = &mt("An error occurred while retrieving the contents of the group's folder.").'
    '; + if ($crstype eq 'Community') { + $error .= &mt("You need to re-initialize the community."); + + } else { + $error .= &mt("You need to re-initialize the course."); + } } if ($error ne '') { $r->print('
    '.$error.'
    '); @@ -3295,7 +3347,7 @@ sub write_group_data { sub process_membership { my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate, $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg, - $gpterm,$ucgpterm)=@_; + $gpterm,$ucgpterm,$crstype)=@_; my %usersettings = (); my %added= (); my %failed = (); @@ -3500,13 +3552,20 @@ sub process_membership { $r->print('
    ' .&mt($ucgpterm.' membership list updated.') .'
    '); - $r->print('

    ' - .&mt('Any currently logged in course users affected by the changes you made' + $r->print('

    '); + if ($crstype eq 'Community') { + $r->print(&mt("Any currently logged in community users affected by the changes you made" + .' to group membership or privileges for the [_1] group will need to log out' + .' and log back in for their LON-CAPA sessions to reflect these changes.' + ,''.$groupname.'')); + + } else { + $r->print(&mt("Any currently logged in course users affected by the changes you made" .' to group membership or privileges for the [_1] group will need to log out' .' and log back in for their LON-CAPA sessions to reflect these changes.' - ,''.$groupname.'') - .'

    ' - ); + ,''.$groupname.'')); + } + $r->print('

    '); } else { $r->print('
    ' .&mt("An error occurred while updating the $gpterm membership list:") @@ -3577,7 +3636,7 @@ sub mapping_settings { @sections = ('all','none'); } $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'pirs'})); - my @roles = &standard_roles(); + my @roles = &standard_roles($crstype); my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum); $r->print(&Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row()); @@ -3620,10 +3679,10 @@ sub print_autorole_item { my ($role,$roletitle,$sections) = @_; my $sections_sel; if (@{$sections} > 0) { - if ($role eq 'cc') { + if (($role eq 'cc') || ($role eq 'co')) { $sections_sel = ''. &mt('all sections').''; + 'name="sec_'.$role.'" value="all" />'; } else { $sections_sel=''. §ions_selection($sections,'sec_'.$role). @@ -3639,7 +3698,13 @@ sub print_autorole_item { } sub standard_roles { - my @roles = ('cc','in','ta','ep','st'); + my ($crstype) = @_; + my @roles = qw(in ta ep ad st); + if ($crstype eq 'Community') { + unshift(@roles,'co'); + } else { + unshift(@roles,'cc'); + } return @roles; } @@ -3778,9 +3843,14 @@ sub add_group_folder { my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo, $gpterm,$ucgpterm,$crstype) = @_; if ($cdom eq '' || $cnum eq '') { - return '' - .&mt('Error: invalid course domain or number - group folder creation failed.') - .''; + my $error = ''; + if ($crstype eq 'Community') { + $error .= &mt("Error: invalid community domain or number - group folder creation failed."); + } else { + $error .= &mt("Error: invalid course domain or number - group folder creation failed."); + } + $error .= ''; + return $error; } my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning); my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/'; @@ -3848,8 +3918,16 @@ sub add_group_folder { my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum); my $navmap = Apache::lonnavmaps::navmap->new(); if (!defined($navmap)) { - return $warning.''.&mt('Error retrieving course contents'). - ' '.&mt('You need to re-initialize the course.').''; + $warning .= ''; + if ($crstype eq 'Community') { + $warning .= &mt("Error retrieving community contents"). + ' '.&mt("You need to re-initialize the community."); + } else { + $warning .= &mt("Error retrieving course contents"). + ' '.&mt("You need to re-initialize the course."); + } + $warning .= ''; + return $warning; } # modify parameters my $parm_result; @@ -3954,14 +4032,18 @@ sub new_map { } sub parm_setter { - my ($navmap,$cdom,$url,$groupname) = @_; - my $allresults; + my ($navmap,$cdom,$url,$groupname,$crstype) = @_; if (!defined($navmap)) { - $allresults = '
    '. - &mt('Parameters not set for [_1] because the contents of the course could not be retrieved.',$url).' '. - &mt('You need to reinitialize the course.'). - '
    '; - return $allresults; + my $allresults; + if ($crstype eq 'Community') { + $allresults = &mt("Parameters not set for [_1] because the contents of the community could not be retrieved.",$url).' '. + &mt("You need to reinitialize the community."); + } else { + $allresults = &mt("Parameters not set for [_1] because the contents of the course could not be retrieved.",$url).' '. + &mt("You need to reinitialize the course."); + + } + return '
    '.$allresults.'
    '; } my %hide_settings = ( 'course' => { @@ -3975,6 +4057,7 @@ sub parm_setter { }, ); my $res = $navmap->getResourceByUrl($url); + my $allresults; if ($res) { my $symb = $res->symb(); foreach my $level (keys(%hide_settings)) { @@ -3991,10 +4074,13 @@ sub parm_setter { } } } else { - $allresults = '
    ' - .&mt('Parameters not set for [_1] because the resource was not recognized' - .' as part of the course.',''.$url.'') - .'
    '; + $allresults = '
    '; + if ($crstype eq 'Community') { + $allresults .= &mt("Parameters not set for [_1] because the resource was not recognized as part of the community.",''.$url.''); + } else { + $allresults .= &mt('Parameters not set for [_1] because the resource was not recognized as part of the course.',''.$url.''); + } + $allresults .= '
    '; } return $allresults; }