--- loncom/interface/loncoursegroups.pm 2006/05/01 19:37:33 1.14 +++ loncom/interface/loncoursegroups.pm 2006/05/09 14:38:09 1.15 @@ -37,7 +37,7 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - + if ($r->header_only) { return OK; } @@ -154,8 +154,8 @@ sub display_groups { if (!defined($action)) { $action = 'view'; } - my %curr_groups; - if (&Apache::loncommon::coursegroups(\%curr_groups,$cdom,$cnum)) { + my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum); + if (%curr_groups) { $r->print('

'); $r->print(&Apache::lonhtmlcommon::start_pick_box()); $r->print(<<"END"); @@ -267,8 +267,8 @@ END my @coursegroups = split(/:/,$env{'request.course.groups'}); if (@coursegroups > 0) { $r->print('

'); - my %curr_groups; - if (&Apache::loncommon::coursegroups(\%curr_groups,$cdom,$cnum)) { + my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum); + if (%curr_groups) { foreach my $group (@coursegroups) { my %group_info = &Apache::loncommon::get_group_settings( $curr_groups{$group}); @@ -688,7 +688,7 @@ function changeSort(caller) { document.$state.sortby.value = caller; document.$state.submit(); } - + |; $jscript .= &Apache::lonhtmlcommon::set_form_elements( \%{$elements{$action}{$state}},\%stored); @@ -808,55 +808,55 @@ function changeSort(caller) { sub retrieve_settings { my ($cdom,$cnum,$groupname) = @_; - my %groupinfo; + my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum,$groupname); + + return if (!%curr_groups); + + my %groupinfo = + &Apache::loncommon::get_group_settings($curr_groups{$groupname}); + my %stored; - my %curr_groups; - my $numgroups = &Apache::loncommon::coursegroups(\%curr_groups,$cdom, - $cnum,$groupname); - if ($numgroups > 0) { - %groupinfo = &Apache::loncommon::get_group_settings( - $curr_groups{$groupname}); - $stored{'description'} = &Apache::lonnet::unescape( - $groupinfo{'description'}); - $stored{'startdate'} = $groupinfo{'startdate'}; - $stored{'enddate'} = $groupinfo{'enddate'}; - if ($stored{'enddate'} == 0) { - $stored{'no_end_date'} = 1; - } - $stored{'granularity'} = $groupinfo{'granularity'}; - $stored{'specificity'} = $groupinfo{'specificity'}; - $stored{'creation'} = $groupinfo{'creation'}; - $stored{'creator'} = $groupinfo{'creator'}; - - foreach my $tool (sort(keys(%{$groupinfo{'functions'}}))) { - if ($groupinfo{functions}{$tool} eq 'on') { - push(@{$stored{tool}},$tool); - } - } - foreach my $role (@{$groupinfo{'roles'}}) { - push(@{$stored{roles}},$role); - } - foreach my $type (@{$groupinfo{'types'}}) { - push(@{$stored{types}},$type); - } - foreach my $section (@{$groupinfo{'sectionpick'}}) { - push(@{$stored{sectionpick}},$section); - } - foreach my $defpriv (@{$groupinfo{'defpriv'}}) { - push(@{$stored{defpriv}},$defpriv); - } - $stored{'autoadd'} = $groupinfo{'autoadd'}; - $stored{'autodrop'} = $groupinfo{'autodrop'}; - if (exists($groupinfo{'autosec'})) { - foreach my $role (sort(keys(%{$groupinfo{'autosec'}}))) { - foreach my $section (@{$groupinfo{'autosec'}{$role}}) { - push (@{$stored{'sec_'.$role}},$section); - } - if (@{$groupinfo{'autosec'}{$role}} > 0) { - push(@{$stored{'autorole'}},$role); - } - } - } + + $stored{'description'} = + &Apache::lonnet::unescape($groupinfo{'description'}); + $stored{'startdate'} = $groupinfo{'startdate'}; + $stored{'enddate'} = $groupinfo{'enddate'}; + if ($stored{'enddate'} == 0) { + $stored{'no_end_date'} = 1; + } + $stored{'granularity'} = $groupinfo{'granularity'}; + $stored{'specificity'} = $groupinfo{'specificity'}; + $stored{'creation'} = $groupinfo{'creation'}; + $stored{'creator'} = $groupinfo{'creator'}; + + foreach my $tool (sort(keys(%{$groupinfo{'functions'}}))) { + if ($groupinfo{functions}{$tool} eq 'on') { + push(@{$stored{tool}},$tool); + } + } + foreach my $role (@{$groupinfo{'roles'}}) { + push(@{$stored{roles}},$role); + } + foreach my $type (@{$groupinfo{'types'}}) { + push(@{$stored{types}},$type); + } + foreach my $section (@{$groupinfo{'sectionpick'}}) { + push(@{$stored{sectionpick}},$section); + } + foreach my $defpriv (@{$groupinfo{'defpriv'}}) { + push(@{$stored{defpriv}},$defpriv); + } + $stored{'autoadd'} = $groupinfo{'autoadd'}; + $stored{'autodrop'} = $groupinfo{'autodrop'}; + if (exists($groupinfo{'autosec'})) { + foreach my $role (sort(keys(%{$groupinfo{'autosec'}}))) { + foreach my $section (@{$groupinfo{'autosec'}{$role}}) { + push (@{$stored{'sec_'.$role}},$section); + } + if (@{$groupinfo{'autosec'}{$role}} > 0) { + push(@{$stored{'autorole'}},$role); + } + } } return %stored; } @@ -1212,7 +1212,7 @@ sub membership_options { previous => &mt('Previously had access'), future => &mt('Will have future access'), ); - + my @roles = ('st','cc','in','ta','ep','cr'); my @sections = keys(%{$sectioncount}); @@ -2308,7 +2308,7 @@ END $r->print(''); if ($granularity eq 'Yes') { foreach my $tool (@{$current{$user}{newtools}}) { - $r->print('   '); @@ -2711,7 +2711,6 @@ END '
'); &display_defprivs($r,$tabcol,$rowColor1,$rowColor2,$tools, $toolprivs,\@defprivs); - } } else { if (keys(%{$usertools}) > 0) { @@ -2810,7 +2809,7 @@ sub write_group_data { 'creation','modified','creator','granularity', 'specificity','autoadd','autodrop'); my @mult_attributes = ('roles','types','sectionpick','defpriv'); - + my %groupinfo = ( description => $esc_description, startdate => $startdate, @@ -2849,7 +2848,7 @@ sub write_group_data { } my $autosec; my @autorole = &Apache::loncommon::get_env_multiple('form.autorole'); - + foreach my $role (@autorole) { if (defined($env{'form.sec_'.$role})) { my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'. @@ -3413,9 +3412,8 @@ sub validate_groupname { my ($groupname,$action,$cdom,$cnum) = @_; my %sectioncount; my $numsec=&Apache::loncommon::get_sections($cdom,$cnum,\%sectioncount); - my %curr_groups; - my $numgroups=&Apache::loncommon::coursegroups(\%curr_groups,$cdom,$cnum); - + my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum); + my %lt = &Apache::lonlocal::texthash ( igna => 'Invalid group name', tgne => 'The group name entered ', @@ -3429,7 +3427,7 @@ sub validate_groupname { thgr => '- does not correspond to the name of an existing'. ' group ', ); - + my $exitmsg = ''.$lt{'igna'}.'

'.$lt{'tgne'}.' "'. $groupname.'" '; my $dupmsg = $lt{'grna'}; @@ -3445,14 +3443,12 @@ sub validate_groupname { return $earlyout; } } - if ($action eq 'create') { - if ($numgroups) { - if (exists($curr_groups{$groupname})) { - $earlyout = $exitmsg.$lt{'cnnb'}.&mt('an existing group'). - $lt{'inth'}.'
'.$lt{'grna'}; - return $earlyout; - } - } + if ($action eq 'create' + && exists($curr_groups{$groupname})) { + + return $exitmsg.$lt{'cnnb'}.&mt('an existing group'). + $lt{'inth'}.'
'.$lt{'grna'}; + } elsif ($action eq 'modify') { unless(exists($curr_groups{$groupname})) { $earlyout = &mt('Group name:').' '.$groupname.$lt{'thgr'}.$lt{'inth'};