--- loncom/interface/loncoursegroups.pm 2006/07/02 17:08:42 1.36 +++ 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.36 2006/07/02 17:08:42 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'}; @@ -727,11 +727,51 @@ sub group_administration { } } } - + + 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(' @@ -1310,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(); @@ -2875,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, @@ -2886,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})) { @@ -2938,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 { @@ -2952,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; @@ -3555,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); @@ -3569,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; } } @@ -3590,7 +3658,7 @@ sub new_map { sub parm_setter { my ($navmap,$cdom,$url,$groupname) = @_; - my %parmresult; + my $allresults; my %hide_settings = ( 'course' => { 'num' => 13, @@ -3605,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 {