--- loncom/interface/loncoursegroups.pm 2006/07/02 12:46:06 1.35 +++ loncom/interface/loncoursegroups.pm 2006/07/04 20:50:52 1.37 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncoursegroups.pm,v 1.35 2006/07/02 12:46:06 raeburn Exp $ +# $Id: loncoursegroups.pm,v 1.37 2006/07/04 20:50:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -368,7 +368,7 @@ sub group_administration { my @member_changes = ('deletion','expire','activate','reenable', 'changefunc','changepriv'); my ($groupname,$description,$startdate,$enddate,$granularity,$specificity, - $quota); + $quota,$validate_script); if (defined($env{'form.groupname'})) { $groupname = $env{'form.groupname'}; @@ -438,47 +438,9 @@ sub group_administration { } } - my %toolprivs = - ( - email => { - sgm => 'Send '.$gpterm.' mail', - sgb => 'Broadcast mail', - }, - discussion => { - cgb => 'Create boards', - pgd => 'Post', - pag => 'Anon. posts', - rgi => 'Get identities', - vgb => 'View boards', - }, - chat => { - pgc => 'Chat', - }, - files => { - rgf => 'Retrieve', - ugf => 'Upload', - mgf => 'Modify', - dgf => 'Delete', - agf => 'Control Access', - }, - roster => { - vgm => 'View', - }, - homepage => { - vgh => 'View page', - mgh => 'Modify page', - }, - ); + my $toolprivs = &Apache::longroup::get_tool_privs($gpterm); - my %fixedprivs = - ( - email => {sgm => 1}, - discussion => {vgb => 1}, - chat => {pgc => 1}, - files => {rgf => 1}, - roster => {vgm => 1}, - homepage => {vgh => 1}, - ); + my $fixedprivs = &Apache::longroup::get_fixed_privs(); my %elements = ( @@ -686,8 +648,8 @@ sub group_administration { } my @currtools = (); if (@userprivs > 0) { - foreach my $tool (sort(keys(%fixedprivs))) { - foreach my $priv (keys(%{$fixedprivs{$tool}})) { + foreach my $tool (sort(keys(%{$fixedprivs}))) { + foreach my $priv (keys(%{$$fixedprivs{$tool}})) { if (grep/^$priv$/,@userprivs) { push(@currtools,$tool); last; @@ -757,19 +719,59 @@ sub group_administration { && ($specificity eq 'Yes')) { foreach my $user (sort(keys(%usertools))) { foreach my $tool (keys(%{$usertools{$user}})) { - foreach my $priv (keys(%{$toolprivs{$tool}})) { - unless (exists($fixedprivs{$tool}{$priv})) { + foreach my $priv (keys(%{$$toolprivs{$tool}})) { + unless (exists($$fixedprivs{$tool}{$priv})) { $elements{$action}{$state}{'userpriv_'.$priv} = 'checkbox'; } } } } } - + + if (($action eq 'create' && $state eq 'pick_name') || + ($action eq 'modify' && $state eq 'change_settings')) { + my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,\%stored); + my $space_trim = '/^\s*|\s*\$/g,""'; + my $float_check = '/^([0-9]*\.?[0-9]*)$/'; + $validate_script = ' + var newquota = document.'.$state.'.quota.value; + newquota.replace('.$space_trim.'); + if (newquota == "" ) { + document.'.$state.'.quota.value = 0; + newquota = 0; + } + var maxposs = '.$maxposs.'; + if (newquota > maxposs) { + alert("The file repository quota you entered for this group ("+newquota+" Mb) exceeds the maximum possible ("+maxposs+" Mb). Please enter a smaller number."); + return; + } + var re_quota = '.$float_check.'; + var check_quota = newquota.match(re_quota); + if (check_quota == null) { + alert("The quota you entered contains invalid characters, the quota should only include numbers, with or without a decimal point."); + return; + } + if (newquota == 0) { + var warn_zero = 0; + for (var i=0; i "Do you want to assign different functionality ". "to different $gpterm members?", ); - my $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'}; - if ($crsquota eq '') { - $crsquota = 20; - } - my $freespace = $crsquota - &Apache::longroup::sum_quotas(); - my $maxposs = $$stored{'quota'} + $freespace; + my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored); &topic_bar($r,$tabcol,$image,$lt{'gnde'}); $r->print(' @@ -1348,6 +1345,22 @@ END return; } +sub get_quota_constraints { + my ($action,$stored) = @_; + my ($crsquota,$freespace,$maxposs); + $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'}; + if ($crsquota eq '') { + $crsquota = 20; + } + $freespace = $crsquota - &Apache::longroup::sum_quotas(); + if ($action eq 'create') { + $maxposs = $freespace; + } else { + $maxposs = $$stored{'quota'} + $freespace; + } + return ($crsquota,$freespace,$maxposs); +} + sub membership_options { my ($r,$action,$state,$tabcol,$sectioncount,$image,$gpterm,$ucgpterm) = @_; my $crstype = &Apache::loncommon::course_type(); @@ -2227,114 +2240,33 @@ sub current_membership { 'curf' => 'Current Functionality', 'chpr' => 'Change Privileges' ); - if (keys(%membership) > 0) { - my %current = (); - my %allnames = (); - my $hastools = 0; - my $addtools = 0; - my $num_reenable = 0; - my $num_activate = 0; - my $num_expire = 0; - foreach my $key (sort(keys(%membership))) { - if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) { - my $uname = $1; - my $udom = $2; - my $user = $uname.':'.$udom; - my($end,$start,@userprivs) = split(/:/,$membership{$key}); - unless ($start == -1) { - $allnames{$udom}{$uname} = 1; - $current{$user} = { - uname => $uname, - udom => $udom, - start => &Apache::lonlocal::locallocaltime($start), - currtools => [], - newtools => [], - }; - - if ($end == 0) { - $current{$user}{end} = 'No end date'; - } else { - $current{$user}{end} = - &Apache::lonlocal::locallocaltime($end); - } - my $now = time; - if (($end > 0) && ($end < $now)) { - $current{$user}{changestate} = 'reenable'; - $num_reenable++; - } elsif (($start > $now)) { - $current{$user}{changestate} = 'activate'; - $num_activate ++; - } else { - $current{$user}{changestate} = 'expire'; - $num_expire ++; - } - if (@userprivs > 0) { - foreach my $tool (sort(keys(%{$fixedprivs}))) { - foreach my $priv (keys(%{$$fixedprivs{$tool}})) { - if (grep/^$priv$/,@userprivs) { - push(@{$current{$user}{currtools}},$tool); - last; - } - } - } - $hastools = 1; - } - if (@{$available} > 0) { - if (@{$current{$user}{currtools}} > 0) { - if ("@{$available}" ne "@{$current{$user}{currtools}}") { - foreach my $tool (@{$available}) { - unless (grep/^$tool$/,@{$current{$user}{currtools}}) { - push(@{$current{$user}{newtools}},$tool); - } - } - } - } else { - @{$current{$user}{newtools}} = @{$available}; - } - if (@{$current{$user}{newtools}} > 0) { - $addtools = 1; - } - } - } - } - } - if (keys(%current) > 0) { - my %idhash; - foreach my $udom (keys(%allnames)) { - %{$idhash{$udom}} = &Apache::lonnet::idrget($udom, - keys(%{$allnames{$udom}})); - foreach my $uname (keys(%{$idhash{$udom}})) { - $current{$uname.':'.$udom}{'id'} = $idhash{$udom}{$uname}; - } - foreach my $uname (keys(%{$allnames{$udom}})) { - $current{$uname.':'.$udom}{'fullname'} = - &Apache::loncommon::plainname($uname,$udom, - 'lastname'); - } - } - $r->print(' + my ($current,$hastools,$addtools,$num_reenable,$num_activate,$num_expire) = + &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs, + $available); + if (keys(%{$current}) > 0) { + $r->print('   '); - if ($num_expire) { - &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'}); - } - if ($num_reenable) { - &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'}); - } - if ($num_activate) { - &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'}); + if ($num_expire) { + &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'}); + } + if ($num_reenable) { + &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'}); + } + if ($num_activate) { + &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'}); + } + &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'}); + if (@{$available} > 0) { + if ($specificity eq 'Yes') { + &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'}); } - &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'}); - if (@{$available} > 0) { - if ($specificity eq 'Yes') { - &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'}); - } - if ($granularity eq 'Yes') { - $r->print(&check_uncheck_tools($r,$available)); - $r->print(' + if ($granularity eq 'Yes') { + $r->print(&check_uncheck_tools($r,$available)); + $r->print(' '); - } } - $r->print(<<"END"); + } + $r->print(<<"END");
'.$lt{'curf'}.' @@ -2347,9 +2279,9 @@ sub current_membership {
@@ -2362,8 +2294,8 @@ sub current_membership {   END - $r->print(&Apache::lonhtmlcommon::start_pick_box()); - $r->print(<<"END"); + $r->print(&Apache::lonhtmlcommon::start_pick_box()); + $r->print(<<"END"); @@ -2375,135 +2307,134 @@ END END - my $colspan = 0; - if ($hastools) { - $r->print(''); - $colspan ++; - } - if ($addtools) { - $r->print(''); - $colspan ++; - } - $r->print(''); - if ($colspan) { - if ($granularity eq 'Yes') { - $r->print(' + my $colspan = 0; + if ($hastools) { + $r->print(''); + $colspan ++; + } + if ($addtools) { + $r->print(''); + $colspan ++; + } + $r->print(''); + if ($colspan) { + if ($granularity eq 'Yes') { + $r->print(''); } + $r->print(''); } - my %Sortby = (); - foreach my $user (sort(keys(%current))) { - if ($env{'form.sortby'} eq 'fullname') { - push(@{$Sortby{$current{$user}{fullname}}},$user); - } elsif ($env{'form.sortby'} eq 'username') { - push(@{$Sortby{$current{$user}{uname}}},$user); - } elsif ($env{'form.sortby'} eq 'domain') { - push(@{$Sortby{$current{$user}{udom}}},$user); - } elsif ($env{'form.sortby'} eq 'id') { - push(@{$Sortby{$current{$user}{id}}},$user); + } + my %Sortby = (); + foreach my $user (sort(keys(%{$current}))) { + if ($env{'form.sortby'} eq 'fullname') { + push(@{$Sortby{$$current{$user}{fullname}}},$user); + } elsif ($env{'form.sortby'} eq 'username') { + push(@{$Sortby{$$current{$user}{uname}}},$user); + } elsif ($env{'form.sortby'} eq 'domain') { + push(@{$Sortby{$$current{$user}{udom}}},$user); + } elsif ($env{'form.sortby'} eq 'id') { + push(@{$Sortby{$$current{$user}{id}}},$user); + } else { + push(@{$Sortby{$$current{$user}{fullname}}},$user); + } + } + my $rowNum = 0; + my $rowColor; + foreach my $key (sort(keys(%Sortby))) { + foreach my $user (@{$Sortby{$key}}) { + if ($rowNum %2 == 1) { + $rowColor = $rowColor1; } else { - push(@{$Sortby{$current{$user}{fullname}}},$user); + $rowColor = $rowColor2; } - } - my $rowNum = 0; - my $rowColor; - foreach my $key (sort(keys(%Sortby))) { - foreach my $user (@{$Sortby{$key}}) { - if ($rowNum %2 == 1) { - $rowColor = $rowColor1; - } else { - $rowColor = $rowColor2; - } - my $id = $current{$user}{id}; - my $fullname = $current{$user}{fullname}; - my $udom = $current{$user}{udom}; - my $uname = $current{$user}{uname}; - my $start = $current{$user}{start}; - my $end = $current{$user}{end}; - $r->print(' - + '); - if ($hastools) { - $r->print(''); + } + $r->print('   '); } - if ($addtools) { - $r->print(''); + } + if ($addtools) { + $r->print(''); } - $r->print(''."\n"); - $rowNum ++; + $r->print(''); } + $r->print(''."\n"); + $rowNum ++; } - $r->print(&Apache::lonhtmlcommon::end_pick_box()); - $r->print(' + } + $r->print(&Apache::lonhtmlcommon::end_pick_box()); + $r->print(' '); - } } return; } @@ -2995,6 +2926,22 @@ sub write_group_data { 'specificity','autoadd','autodrop','quota'); my @mult_attributes = ('roles','types','sectionpick','defpriv'); + my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action, + $stored); + my $quota = $env{'form.quota'}; + + $quota =~ s/^\s*([^\s]*)\s*$/$1/; + if ($quota eq '') { + $quota = 0; + } + if ($quota !~ /^\d*\.?\d*$/) { + $quota = 0; + $r->print(&mt('The value you entered for the quota for the file repository in this [_1] contained invalid characters, so it has been set to 0 Mb. You can change this by modifying the [_1] settings.
',$gpterm)); + } + if ($quota > $maxposs) { + $quota = $maxposs; + $r->print(&mt('The value you entered for the quota for the file repository in this [_1] exceeded the maximum possible value, so it has been set to [_2] Mb (the maximum possible value).
',$gpterm,$maxposs)); + } my %groupinfo = ( description => $esc_description, startdate => $startdate, @@ -3006,8 +2953,9 @@ sub write_group_data { specificity => $specificity, autoadd => $env{'form.autoadd'}, autodrop => $env{'form.autodrop'}, - quota => $env{'form.quota'}, + quota => $quota, ); + foreach my $func (keys(%{$functions})) { my $status; if (grep(/^$func$/,@{$tools})) { @@ -3058,7 +3006,7 @@ sub write_group_data { $description,$tools,\%groupinfo, $gpterm,$ucgpterm,$crstype); if ($result ne 'ok') { - $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].',$gpterm,$result)); + $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].
',$gpterm,$result)); } $r->print(&mt('[_1] [_2] was created.
',$ucgpterm,$groupname)); } else { @@ -3072,7 +3020,7 @@ sub write_group_data { &Apache::lonnet::logthis("Failed to store $gpterm $groupname ". 'in '.lc($crstype).': '.$cnum. ' in domain: '.$cdom); - $r->print(&mt('An error occurred when [_1] the new [_2]. '. + $r->print(&mt('An error occurred when [_1] the [_2]. '. 'Please try again.',$actiontype{$action},$gpterm)); } return $result; @@ -3675,12 +3623,12 @@ sub map_updater { my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname, $newfile); if ($newmapurl !~ m|^/uploaded|) { - $outcome = "Error uploading new folder ($newfile): $newmapurl"; + $outcome = &mt('Error uploading new folder.')." ($newfile): $newmapurl".'
'; return $outcome; } my ($errtext,$fatal)=&Apache::lonratedt::mapread($parentmap); if ($fatal) { - $outcome = "Error reading contents of parent folder ($parentmap): $errtext\n"; + $outcome = &mt('Error reading contents of parent folder')." ($parentmap): $errtext".'
'; return $outcome; } else { my $newidx=&Apache::lonratedt::getresidx($newmapurl); @@ -3689,7 +3637,7 @@ sub map_updater { $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx; my ($outtext,$errtext) = &Apache::lonratedt::storemap($parentmap,1); if ($errtext) { - $outcome = "Error storing updated parent folder ($parentmap): $errtext\n"; + $outcome = &mt('Error storing updated parent folder')." ($parentmap): $errtext".'
'; return $outcome; } } @@ -3710,7 +3658,7 @@ sub new_map { sub parm_setter { my ($navmap,$cdom,$url,$groupname) = @_; - my %parmresult; + my $allresults; my %hide_settings = ( 'course' => { 'num' => 13, @@ -3725,15 +3673,18 @@ sub parm_setter { my $res = $navmap->getResourceByUrl($url); my $symb = $res->symb(); foreach my $level (keys(%hide_settings)) { - $parmresult{$level} = &Apache::lonparmset::storeparm_by_symb($symb, + my $parmresult = &Apache::lonparmset::storeparm_by_symb($symb, '0_hiddenresource', $hide_settings{$level}{'num'}, $hide_settings{$level}{'set'}, 'string_yesno',undef,$cdom, undef,undef, $hide_settings{$level}{'extra'}); + if ($parmresult) { + $allresults .= $level.': '.$parmresult; + } } - return %parmresult; + return $allresults; } sub create_homepage {
$lt{'actn'}$lt{'stda'} $lt{'enda'}'.$lt{'curf'}.'Additional Functionality
'.$lt{'curf'}.'Additional Functionality
  '.&mt('All:'). ' '); - foreach my $tool (@{$available}) { - $r->print('
'); - if ($current{$user}{changestate} eq 'reenable') { - $r->print('
'); + if ($$current{$user}{changestate} eq 'reenable') { + $r->print('
'); - } elsif ($current{$user}{changestate} eq 'expire') { - $r->print('
'); - } elsif ($current{$user}{changestate} eq 'activate') { - $r->print('
'); - } - $r->print(''); - if ($specificity eq 'Yes') { - $r->print('
'); - } - $r->print(' + } + $r->print('
'. $fullname.''.$uname.''. $udom.''.$id.''.$start. ''.$end.''. + if ($hastools) { + $r->print(''. '      '); - foreach my $tool (@{$current{$user}{currtools}}) { - if ($granularity eq 'Yes') { - $r->print(''); - if ($granularity eq 'Yes') { - foreach my $tool (@{$current{$user}{newtools}}) { - $r->print(''); + if ($granularity eq 'Yes') { + foreach my $tool (@{$$current{$user}{newtools}}) { + $r->print('   '); - } - } else { - foreach my $tool (@{$current{$user}{newtools}}) { - $r->print('print(''.$tool. '   '); - } } - $r->print('