--- loncom/interface/lonparmset.pm 2014/12/12 02:12:18 1.548 +++ loncom/interface/lonparmset.pm 2016/01/31 21:25:38 1.555 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.548 2014/12/12 02:12:18 raeburn Exp $ +# $Id: lonparmset.pm,v 1.555 2016/01/31 21:25:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -777,7 +777,7 @@ sub storeparm_by_symb_inner { sub valout { - my ($value,$type,$editable)=@_; + my ($value,$type,$name,$editable)=@_; my $result = ''; # Values of zero are valid. if (! $value && $value ne '0') { @@ -791,7 +791,8 @@ sub valout { } } else { if ($type eq 'date_interval') { - my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value); + my ($totalsecs,$donebutton) = split(/_/,$value); + my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($totalsecs); my @timer; $year=$year-70; $mday--; @@ -824,6 +825,9 @@ sub valout { push(@timer,&mt('[quant,_1,sec]',0)); } $result.=join(", ",@timer); + if ($donebutton eq 'done') { + $result .= ' '.&mt('+ "done"'); + } } elsif (&isdateparm($type)) { $result = &Apache::lonlocal::locallocaltime($value). &date_sanity_info($value); @@ -850,7 +854,7 @@ sub plink { my ($parmname)=((split(/\&/,$marker))[1]=~/\_([^\_]+)$/); my ($hour,$min,$sec,$val)=&preset_defaults($parmname); unless (defined($winvalue)) { $winvalue=$val; } - my $valout = &valout($value,$type,1); + my $valout = &valout($value,$type,$parmname,1); my $unencmarker = $marker; foreach my $item (\$type, \$dis, \$winvalue, \$marker, \$return, \$call, \$hour, \$min, \$sec) { @@ -932,6 +936,162 @@ function showHide_courseContent() { COURSECONTENTSCRIPT } +sub toggleparmtextbox_js { + return <<"ENDSCRIPT"; + +if (!document.getElementsByClassName) { + function getElementsByClassName(node, classname) { + var a = []; + var re = new RegExp('(^| )'+classname+'( |$)'); + var els = node.getElementsByTagName("*"); + for(var i=0,j=els.length; i$remove'); + }); + + \$(wrapper).delegate(".LC_remove_ipacc","click", function(e){ + e.preventDefault(); \$(this).closest("div").remove(); + }) +}); + + +END +} + sub startpage { my ($r,$psymb,$crstype) = @_; @@ -982,10 +1142,11 @@ ENDHEAD sub print_row { my ($r,$which,$part,$name,$symbp,$rid,$default,$defaulttype,$display,$defbgone, - $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups)=@_; + $defbgtwo,$defbgthree,$parmlev,$uname,$udom,$csec,$cgroup,$usersgroups,$noeditgrp)=@_; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom); + # get the values for the parameter in cascading order # empty levels will remain empty my ($result,@outpar)=&parmval($$part{$which}.'.'.$$name{$which}, @@ -1021,14 +1182,14 @@ sub print_row { my $thismarker=$which; $thismarker=~s/^parameter\_//; my $mprefix=$rid.'&'.$thismarker.'&'; - my $effective_parm = &valout($outpar[$result],$typeoutpar[$result]); + my $effective_parm = &valout($outpar[$result],$typeoutpar[$result],$thismarker); my ($othergrp,$grp_parm,$controlgrp); if ($parmlev eq 'general') { if ($uname) { &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); } elsif ($cgroup) { - &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); + &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp); } elsif ($csec) { &print_td($r,9,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); } else { @@ -1039,7 +1200,7 @@ sub print_row { if ($uname) { &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); } elsif ($cgroup) { - &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); + &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp); } elsif ($csec) { &print_td($r,8,$defbgtwo,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); } else { @@ -1076,9 +1237,9 @@ sub print_row { } if ($cgroup) { - &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); - &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); - &print_td($r,4,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display); + &print_td($r,6,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp); + &print_td($r,5,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp); + &print_td($r,4,$defbgthree,$result,\@outpar,$mprefix,$which,\@typeoutpar,$display,$noeditgrp); } if ($uname) { @@ -1099,7 +1260,7 @@ sub print_row { my $sessionvaltype=$typeoutpar[$result]; if (!defined($sessionvaltype)) { $sessionvaltype=$$defaulttype{$which}; } $r->print(''. - &valout($sessionval,$sessionvaltype).' '. + &valout($sessionval,$sessionvaltype,$$name{$which}).' '. ''); } $r->print(''); @@ -1107,12 +1268,18 @@ sub print_row { } sub print_td { - my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display)=@_; + my ($r,$which,$defbg,$result,$outpar,$mprefix,$value,$typeoutpar,$display,$noeditgrp)=@_; $r->print(''); my $nolink = 0; if ($which == 11 || $which == 12) { $nolink = 1; + } elsif (($env{'request.course.sec'} ne '') && ($which > 9)) { + $nolink = 1; + } elsif ($which == 4 || $which == 5 || $which == 6) { + if ($noeditgrp) { + $nolink = 1; + } } elsif ($mprefix =~ /availablestudent\&$/) { if ($which > 3) { $nolink = 1; @@ -1123,7 +1290,7 @@ sub print_td { } } if ($nolink) { - $r->print(&valout($$outpar[$which],$$typeoutpar[$which])); + $r->print(&valout($$outpar[$which],$$typeoutpar[$which],$mprefix)); } else { $r->print(&plink($$typeoutpar[$which], $$display{$value},$$outpar[$which], @@ -1148,9 +1315,9 @@ sub print_usergroups { if (($coursereply) && ($cgroup ne $resultgroup)) { if ($result > 3) { $bgcolor = '#AAFFAA'; - $grp_parm = &valout($coursereply,$resulttype); + $grp_parm = &valout($coursereply,$resulttype,$what); } - $grp_parm = &valout($coursereply,$resulttype); + $grp_parm = &valout($coursereply,$resulttype,$what); $output = ''; if ($resultgroup && $resultlevel) { $output .= ''.$resultgroup.' ('.$resultlevel.'): '.$grp_parm; @@ -1598,7 +1765,7 @@ sub partmenu { } sub usermenu { - my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups)=@_; + my ($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,$usersgroups,$pssymb)=@_; my $chooseopt=&Apache::loncommon::select_dom_form($udom,'udom').' '. &Apache::loncommon::selectstudent_link('parmform','uname','udom'); my $selscript=&Apache::loncommon::studentbrowser_javascript(); @@ -1607,12 +1774,23 @@ sub usermenu { my %sectionhash = &Apache::loncommon::get_sections(); my $groups; - my %grouphash = &Apache::longroup::coursegroups(); + my %grouphash; + if (($pssymb) || &Apache::lonnet::allowed('mdg',$env{'request.course.id'})) { + %grouphash = &Apache::longroup::coursegroups(); + } elsif ($env{'request.course.groups'} ne '') { + map { $grouphash{$_} = 1; } split(/,/,$env{'request.course.groups'}); + } my $g_s_header=''; my $g_s_footer=''; - if (%sectionhash) { + my $currsec = $env{'request.course.sec'}; + if ($currsec) { + $sections=&mt('Section:').' '.$currsec; + if (%grouphash) { + $sections .= ';'.(' ' x2); + } + } elsif (%sectionhash && $currsec eq '') { $sections=&mt('Section:').' print(&Apache::lonhtmlcommon::row_title(&mt('Group/Section'))); $r->print($sections.$groups); $r->print(&Apache::lonhtmlcommon::row_closure()); + } else { + $r->print($sections); } $r->print(&Apache::lonhtmlcommon::row_title(&mt('User'))); @@ -1884,44 +2064,52 @@ sub levelmenu { sub sectionmenu { - my ($r,$selectedsections)=@_; + my ($selectedsections)=@_; my %sectionhash = &Apache::loncommon::get_sections(); - return if (!%sectionhash); + return '' if (!%sectionhash); - $r->print(''; + foreach my $s (@possibles) { + $output .= ' \n"); + $output .= '>'."$s\n"; } - $r->print("\n"); + $output .= "\n"; + return $output; } sub groupmenu { - my ($r,$selectedgroups)=@_; - my %grouphash = &Apache::longroup::coursegroups(); - return if (!%grouphash); + my ($selectedgroups)=@_; + my %grouphash; + if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) { + %grouphash = &Apache::longroup::coursegroups(); + } elsif ($env{'request.course.groups'} ne '') { + map { $grouphash{$_} = 1; } split(/,/,$env{'request.course.groups'}); + } + return '' if (!%grouphash); - $r->print(''; foreach my $group (sort(keys(%grouphash))) { - $r->print(' \n"); + $output .= '>'."$group\n"; } - $r->print("\n"); + $output .= "\n"; + return $output; } - sub keysplit { my $keyp=shift; return (split(/\,/,$keyp)); @@ -2041,7 +2229,21 @@ sub assessparms { my $message=''; $csec=$env{'form.csec'}; + if ($env{'request.course.sec'} ne '') { + $csec = $env{'request.course.sec'}; + } + +# Check group privs. $cgroup=$env{'form.cgroup'}; + my $noeditgrp; + if ($cgroup ne '') { + unless (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) { + if (($env{'request.course.groups'} eq '') || + (!grep(/^\Q$cgroup\E$/,split(/,/,$env{'request.course.groups'})))) { + $noeditgrp = 1; + } + } + } if ($udom=$env{'form.udom'}) { } elsif ($udom=$env{'request.role.domain'}) { @@ -2089,7 +2291,7 @@ sub assessparms { my $id=$env{'form.id'}; if (($id) && ($udom)) { - $uname=(&Apache::lonnet::idget($udom,$id))[1]; + $uname=(&Apache::lonnet::idget($udom,[$id],'ids'))[1]; if ($uname) { $id=''; } else { @@ -2165,9 +2367,14 @@ sub assessparms { my ($got_chostname,$chostname,$cmajor,$cminor); my $totalstored = 0; my $now = time; - for (my $i=0;$i<=$#markers;$i++) { my ($needsrelease,$needsnewer,$name); + if (($env{'request.course.sec'} ne '') && ($markers[$i] =~ /\&(7|8|9)$/)) { + next if ($csec ne $env{'request.course.sec'}); + } + if ($markers[$i] =~ /\&(6|5|4)$/) { + next if ($noeditgrp); + } if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3)$/) { my (@ok_slots,@fail_slots,@del_slots); my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom); @@ -2198,9 +2405,10 @@ sub assessparms { } } } - } elsif ($markers[$i] =~ /_(type|lenient|retrypartial|discussvote|examcode|printstartdate|printenddate)\&\d+$/) { + } elsif ($markers[$i] =~ /_(type|lenient|retrypartial|discussvote|examcode|printstartdate|printenddate|acc|interval)\&\d+$/) { $name = $1; my $val = $values[$i]; + my $valmatch = ''; if ($name eq 'examcode') { if (&Apache::lonnet::validCODE($values[$i])) { $val = 'valid'; @@ -2217,15 +2425,49 @@ sub assessparms { $val = 'past'; } } + } elsif (($name eq 'lenient') || ($name eq 'acc')) { + my $stringtype = &get_stringtype($name); + my $stringmatch = &standard_string_matches($stringtype); + if (ref($stringmatch) eq 'ARRAY') { + foreach my $item (@{$stringmatch}) { + if (ref($item) eq 'ARRAY') { + my ($regexpname,$pattern) = @{$item}; + if ($pattern ne '') { + if ($val =~ /$pattern/) { + $valmatch = $regexpname; + $val = ''; + last; + } + } + } + } + } + } elsif ($name eq 'interval') { + my $intervaltype = &get_intervaltype($name); + my $intervalmatch = &standard_interval_matches($intervaltype); + if (ref($intervalmatch) eq 'ARRAY') { + foreach my $item (@{$intervalmatch}) { + if (ref($item) eq 'ARRAY') { + my ($regexpname,$pattern) = @{$item}; + if ($pattern ne '') { + if ($val =~ /$pattern/) { + $valmatch = $regexpname; + $val = ''; + last; + } + } + } + } + } } $needsrelease = - $Apache::lonnet::needsrelease{"parameter:$name:$val"}; + $Apache::lonnet::needsrelease{"parameter:$name:$val:$valmatch"}; if ($needsrelease) { unless ($got_chostname) { ($chostname,$cmajor,$cminor) = ¶meter_release_vars(); $got_chostname = 1; } - $needsnewer = ¶meter_releasecheck($name,$val, + $needsnewer = ¶meter_releasecheck($name,$val,$valmatch, $needsrelease, $cmajor,$cminor); } @@ -2313,7 +2555,7 @@ ENDPARMSELSCRIPT # Step 3 $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('User Specification (optional)'),'parmstep3')); $r->print(&Apache::lonhtmlcommon::start_pick_box()); - &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups); + &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb); $r->print(&Apache::lonhtmlcommon::row_closure(1)); $r->print(&Apache::lonhtmlcommon::end_pick_box()); @@ -2345,7 +2587,7 @@ ENDPARMSELSCRIPT '
'); $r->print(&Apache::lonhtmlcommon::topic_bar('',&mt('Additional Display Specification (optional)'))); $r->print(&Apache::lonhtmlcommon::start_pick_box()); - &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups); + &usermenu($r,$uname,$id,$udom,$csec,$cgroup,$parmlev,\@usersgroups,$pssymb); $r->print(&Apache::lonhtmlcommon::row_closure(1)); $r->print(&Apache::lonhtmlcommon::end_pick_box()); $r->print('

' @@ -2557,7 +2799,7 @@ ENDTABLEHEADFOUR &print_row($r,$item,\%part,\%name,\%symbp,$rid,\%default, \%type,\%display,$defbgone,$defbgtwo, $defbgthree,$parmlev,$uname,$udom,$csec, - $cgroup,\@usersgroups); + $cgroup,\@usersgroups,$noeditgrp); } } } @@ -2679,7 +2921,7 @@ ENDTABLEHEADFOUR $r->print(&Apache::loncommon::start_data_table_row()); &print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default, \%type,\%display,$defbgone,$defbgtwo,$defbgthree, - $parmlev,$uname,$udom,$csec,$cgroup); + $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp); } $r->print(&Apache::loncommon::end_data_table().'

' .'' @@ -2769,7 +3011,7 @@ ENDMAPONE $r->print(&Apache::loncommon::start_data_table_row()); &print_row($r,$item,\%part,\%name,\%symbp,$mapid,\%default, \%type,\%display,$defbgone,$defbgtwo,$defbgthree, - $parmlev,$uname,$udom,$csec,$cgroup); + $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp); } $r->print(&Apache::loncommon::end_data_table() .'

' @@ -2788,12 +3030,19 @@ ENDMAPONE my $tableopen; sub tablestart { + my ($readonly) = @_; if ($tableopen) { - return ''; + return ''; } else { - $tableopen=1; - return &Apache::loncommon::start_data_table().''.&mt('Parameter').''. - &mt('Delete').''.&mt('Set to ...').''; + $tableopen=1; + my $output = &Apache::loncommon::start_data_table().''.&mt('Parameter').''; + if ($readonly) { + $output .= ''.&mt('Current value').''; + } else { + $output .= ''.&mt('Delete').''.&mt('Set to ...').''; + } + $output .= ''; + return $output; } } @@ -2826,7 +3075,11 @@ sub readdata { } } } - return $resourcedata; + if (wantarray) { + return ($resourcedata,$classlist); + } else { + return $resourcedata; + } } @@ -2847,15 +3100,17 @@ sub storedata { if ($key =~ /^form\.([a-z]+)\_(.+)$/) { my $cmd=$1; my $thiskey=$2; + next if ($cmd eq 'settext' || $cmd eq 'setipallow' || $cmd eq 'setipdeny'); my ($tuname,$tudom)=&extractuser($thiskey); my $tkey=$thiskey; if ($tuname) { $tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./; } if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') { - my ($data, $typeof, $text, $name, $valchk); + my ($data, $typeof, $text, $name, $valchk, $valmatch); if ($cmd eq 'set') { $data=$env{$key}; + $valmatch = ''; $valchk = $data; $typeof=$env{'form.typeof_'.$thiskey}; $text = &mt('Saved modified parameter for'); @@ -2863,6 +3118,21 @@ sub storedata { $name = 'type'; } elsif ($typeof eq 'string_lenient') { $name = 'lenient'; + my $stringmatch = &standard_string_matches($typeof); + if (ref($stringmatch) eq 'ARRAY') { + foreach my $item (@{$stringmatch}) { + if (ref($item) eq 'ARRAY') { + my ($regexpname,$pattern) = @{$item}; + if ($pattern ne '') { + if ($data =~ /$pattern/) { + $valmatch = $regexpname; + $valchk = ''; + last; + } + } + } + } + } } elsif ($typeof eq 'string_discussvote') { $name = 'discussvote'; } elsif ($typeof eq 'string_examcode') { @@ -2896,18 +3166,37 @@ sub storedata { } } elsif ($cmd eq 'dateinterval') { $data=&get_date_interval_from_form($thiskey); + if ($thiskey =~ /\.interval$/) { + $name = 'interval'; + my $intervaltype = &get_intervaltype($name); + my $intervalmatch = &standard_interval_matches($intervaltype); + if (ref($intervalmatch) eq 'ARRAY') { + foreach my $item (@{$intervalmatch}) { + if (ref($item) eq 'ARRAY') { + my ($regexpname,$pattern) = @{$item}; + if ($pattern ne '') { + if ($data =~ /$pattern/) { + $valmatch = $regexpname; + $valchk = ''; + last; + } + } + } + } + } + } $typeof=$env{'form.typeof_'.$thiskey}; $text = &mt('Saved modified date for'); } if ($name ne '') { my ($needsrelease,$needsnewer); - $needsrelease = $Apache::lonnet::needsrelease{"parameter:$name:$valchk"}; + $needsrelease = $Apache::lonnet::needsrelease{"parameter:$name:$valchk:$valmatch"}; if ($needsrelease) { unless ($got_chostname) { ($chostname,$cmajor,$cminor)=¶meter_release_vars(); $got_chostname = 1; } - $needsnewer = ¶meter_releasecheck($name,$valchk, + $needsnewer = ¶meter_releasecheck($name,$valchk,$valmatch, $needsrelease, $cmajor,$cminor); if ($needsnewer) { @@ -3005,7 +3294,8 @@ sub parse_listdata_key { } sub listdata { - my ($r,$resourcedata,$listdata,$sortorder)=@_; + my ($r,$resourcedata,$listdata,$sortorder,$caller,$classlist)=@_; + # Start list output my $oldsection=''; @@ -3016,6 +3306,16 @@ sub listdata { my $foundkeys=0; my %keyorder=&standardkeyorder(); + my ($secidx,%grouphash); + if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) { + $secidx = &Apache::loncoursedata::CL_SECTION(); + if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) { + %grouphash = &Apache::longroup::coursegroups(); + } elsif ($env{'request.course.groups'} ne '') { + map { $grouphash{$_} = 1; } split(/,/,$env{'request.course.groups'}); + } + } + foreach my $thiskey (sort { my ($astudent,$ares,$apart,$aparm) = &parse_listdata_key($a,$listdata); my ($bstudent,$bres,$bpart,$bparm) = &parse_listdata_key($b,$listdata); @@ -3057,22 +3357,43 @@ sub listdata { $result; } keys(%{$listdata})) { + my $readonly; if ($$listdata{$thiskey.'.type'}) { - my $thistype=$$listdata{$thiskey.'.type'}; - if ($$resourcedata{$thiskey.'.type'}) { - $thistype=$$resourcedata{$thiskey.'.type'}; + my $thistype=$$listdata{$thiskey.'.type'}; + if ($$resourcedata{$thiskey.'.type'}) { + $thistype=$$resourcedata{$thiskey.'.type'}; } my ($middle,$part,$name)= ($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/); my $section=&mt('All Students'); if ($middle=~/^\[(.*)\]/) { - my $issection=$1; - if ($issection=~/^useropt\:($match_username)\:($match_domain)/) { - $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2); - } else { - $section=&mt('Group/Section').': '.$issection; - } - $middle=~s/^\[(.*)\]//; + my $issection=$1; + if ($issection=~/^useropt\:($match_username)\:($match_domain)/) { + my ($stuname,$studom) = ($1,$2); + if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) { + if (ref($classlist) eq 'HASH') { + if (ref($classlist->{$stuname.':'.$studom}) eq 'ARRAY') { + next unless ($classlist->{$stuname.':'.$studom}->[$secidx] eq $env{'request.course.sec'}); + } + } + } + $section=&mt('User').": ".&Apache::loncommon::plainname($stuname,$studom); + } else { + if (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) { + if (exists($grouphash{$issection})) { + $section=&mt('Group').': '.$issection; + } elsif ($issection eq $env{'request.course.sec'}) { + $section = &mt('Section').': '.$issection; + } else { + next; + } + } else { + $section=&mt('Group/Section').': '.$issection; + } + } + $middle=~s/^\[(.*)\]//; + } elsif (($env{'request.course.sec'} ne '') && ($caller eq 'overview')) { + $readonly = 1; } $middle=~s/\.+$//; $middle=~s/^\.+//; @@ -3115,64 +3436,55 @@ sub listdata { # Ready to print # my $parmitem = &standard_parameter_names($name); - $r->print(&tablestart(). + $r->print(&tablestart($readonly). &Apache::loncommon::start_data_table_row(). ''.&mt($parmitem). - ''); + ''); + unless ($readonly) { + $r->print(''); + } + $r->print(''); $foundkeys++; if (&isdateparm($thistype)) { - my $jskey='key_'.$pointer; - $pointer++; - $r->print( - &Apache::lonhtmlcommon::date_setter('parmform', - $jskey, - $$resourcedata{$thiskey}, - '',1,'',''). + my $jskey='key_'.$pointer; + my $state; + $pointer++; + if ($readonly) { + $state = 'disabled'; + } + $r->print( + &Apache::lonhtmlcommon::date_setter('parmform', + $jskey, + $$resourcedata{$thiskey}, + '',1,$state)); + unless ($readonly) { + $r->print( ''. (($$resourcedata{$thiskey}!=0)?''. &mt('Shift all dates based on this date').'':''). &date_sanity_info($$resourcedata{$thiskey}) - ); + ); + } } elsif ($thistype eq 'date_interval') { - $r->print(&date_interval_selector($thiskey, - $$resourcedata{$thiskey})); + $r->print(&date_interval_selector($thiskey,$name, + $$resourcedata{$thiskey},$readonly)); } elsif ($thistype =~ m/^string/) { - $r->print(&string_selector($thistype,$thiskey, - $$resourcedata{$thiskey},$name)); + $r->print(&string_selector($thistype,$thiskey, + $$resourcedata{$thiskey},$name,$readonly)); } else { - $r->print(&default_selector($thiskey,$$resourcedata{$thiskey})); + $r->print(&default_selector($thiskey,$$resourcedata{$thiskey},$readonly)); + } + unless ($readonly) { + $r->print(''); } - $r->print(''); $r->print(''.&Apache::loncommon::end_data_table_row()); } } return $foundkeys; } - -sub date_interval_selector { - my ($thiskey, $showval) = @_; - my $result; - foreach my $which (['days', 86400, 31], - ['hours', 3600, 23], - ['minutes', 60, 59], - ['seconds', 1, 59]) { - my ($name, $factor, $max) = @{ $which }; - my $amount = int($showval/$factor); - $showval %= $factor; - my %select = ((map {$_ => $_} (0..$max)), - 'select_form_order' => [0..$max]); - $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey, - \%select); - $result .= ' '.&mt($name); - } - $result .= ''; - return $result; - -} - sub get_date_interval_from_form { my ($key) = @_; my $seconds = 0; @@ -3185,15 +3497,83 @@ sub get_date_interval_from_form { $seconds += $env{'form.'.$name.'_'.$key} * $factor; } } + if (($key =~ /\.interval$/) && ($env{'form.done_'.$key} eq '_done')) { + $seconds .= $env{'form.done_'.$key}; + } return $seconds; } sub default_selector { - my ($thiskey, $showval) = @_; - return ''; + my ($thiskey, $showval, $readonly) = @_; + my $disabled; + if ($readonly) { + $disabled = ' disabled="disabled"'; + } + return ''; +} + +sub string_ip_selector { + my ($thiskey, $showval, $readonly) = @_; + my %access = ( + allow => [], + deny => [], + ); + if ($showval ne '') { + my @current; + if ($showval =~ /,/) { + @current = split(/,/,$showval); + } else { + @current = ($showval); + } + foreach my $item (@current) { + if ($item =~ /^\!([\[\]a-zA-Z\.\d\*\-]+)$/) { + push(@{$access{'deny'}},$1); + } elsif ($item =~ /^([\[\]a-zA-Z\.\d\*\-]+)$/) { + push(@{$access{'allow'}},$item); + } + } + } + if (!@{$access{'allow'}}) { + @{$access{'allow'}} = (''); + } + if (!@{$access{'deny'}}) { + @{$access{'deny'}} = (''); + } + my ($disabled,$addmore); + if ($disabled) { + $disabled=' disabled="disabled"'; + } else { + $addmore = "\n".''; + } + my $output = ' +'; + foreach my $acctype ('allow','deny') { + $output .= ' +'; + } + $output .= ' + +
'.&mt('Allow from').''.&mt('Deny from').'
+
+
'."\n"; + my $num = 0; + foreach my $curr (@{$access{$acctype}}) { + $output .= '
'; + if ($num > 0) { + $output .= ''.&mt('Remove').''; + } + $output .= '
'."\n"; + $num ++; + } + $output .= ' +
'.$addmore.' +
+
'."\n"; + return $output; } +{ my %strings = ( 'string_yesno' @@ -3216,13 +3596,34 @@ my %strings = 'string_lenient' => [['yes', 'Yes' ], [ 'no', 'No' ], - [ 'default', 'Default - only bubblesheet grading is lenient' ]], + [ 'default', 'Default - only bubblesheet grading is lenient' ], + [ 'weighted', 'Yes, weighted (optionresponse in checkbox mode)' ]], 'string_discussvote' => [['yes','Yes'], ['notended','Yes, unless discussion ended'], ['no','No']], + 'string_ip' + => [['_allowfrom_','Hostname(s), or IP(s) from which access is allowed'], + ['_denyfrom_',], 'Hostname(s) or IP(s) from which access is disallowed'], ); +my %stringmatches = ( + 'string_lenient' + => [['weighted','^\-?[.\d]+,\-?[.\d]+,\-?[.\d]+,\-?[.\d]+$'],], + 'string_ip' + => [['_allowfrom_','[^\!]+'], + ['_denyfrom_','\!']], + ); + +my %stringtypes = ( + type => 'string_questiontype', + lenient => 'string_lenient', + retrypartial => 'string_yesno', + discussvote => 'string_discussvote', + examcode => 'string_examcode', + acc => 'string_ip', + ); + sub standard_string_options { my ($string_type) = @_; if (ref($strings{$string_type}) eq 'ARRAY') { @@ -3231,39 +3632,79 @@ sub standard_string_options { return; } +sub standard_string_matches { + my ($string_type) = @_; + if (ref($stringmatches{$string_type}) eq 'ARRAY') { + return $stringmatches{$string_type}; + } + return; +} + +sub get_stringtype { + my ($name) = @_; + if (exists($stringtypes{$name})) { + return $stringtypes{$name}; + } + return; +} + sub string_selector { - my ($thistype, $thiskey, $showval, $name) = @_; + my ($thistype, $thiskey, $showval, $name, $readonly) = @_; if (!exists($strings{$thistype})) { - return &default_selector($thiskey,$showval); + return &default_selector($thiskey,$showval,$readonly); } my %skiptype; if (($thistype eq 'string_questiontype') || ($thistype eq 'string_lenient') || ($thistype eq 'string_discussvote') || + ($thistype eq 'string_ip') || ($name eq 'retrypartial')) { my ($got_chostname,$chostname,$cmajor,$cminor); foreach my $possibilities (@{ $strings{$thistype} }) { next unless (ref($possibilities) eq 'ARRAY'); my ($parmval, $description) = @{ $possibilities }; - my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval"}; + my $parmmatch; + if (ref($stringmatches{$thistype}) eq 'ARRAY') { + foreach my $item (@{$stringmatches{$thistype}}) { + if (ref($item) eq 'ARRAY') { + if ($parmval eq $item->[0]) { + $parmmatch = $parmval; + $parmval = ''; + last; + } + } + } + } + my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval:$parmmatch"}; if ($needsrelease) { unless ($got_chostname) { ($chostname,$cmajor,$cminor)=¶meter_release_vars(); $got_chostname = 1; } - my $needsnewer=¶meter_releasecheck($name,$parmval,$needsrelease, - $cmajor,$cminor); + my $needsnewer=¶meter_releasecheck($name,$parmval,$parmmatch, + $needsrelease,$cmajor,$cminor); if ($needsnewer) { - $skiptype{$parmval} = 1; + if ($parmmatch ne '') { + $skiptype{$parmmatch} = 1; + } elsif ($parmval ne '') { + $skiptype{$parmval} = 1; + } } } } } - - my $result; + if ($thistype eq 'string_ip') { + return &string_ip_selector($thiskey,$showval,$readonly); + } + + my ($result,$disabled); + + if ($readonly) { + $disabled = ' disabled="disabled"'; + } my $numinrow = 3; if ($thistype eq 'string_problemstatus') { $numinrow = 2; @@ -3278,7 +3719,7 @@ sub string_selector { foreach my $possibilities (@{ $strings{$thistype} }) { next unless (ref($possibilities) eq 'ARRAY'); my ($name, $description) = @{ $possibilities }; - next if ($skiptype{$name}); + next if ($skiptype{$name}); $rem = $i%($numinrow); if ($rem == 0) { if ($i > 0) { @@ -3286,24 +3727,66 @@ sub string_selector { } $result .= ''; } - $result .= ''. + my $colspan; + if ($i == @{ $strings{$thistype} }-1) { + $rem = @{ $strings{$thistype} }%($numinrow); + if ($rem) { + my $colsleft = $numinrow - $rem; + if ($colsleft) { + $colspan = $colsleft+1; + $colspan = ' colspan="'.$colspan.'"'; + } + } + } + my ($add,$onchange,$css_class); + if ($thistype eq 'string_lenient') { + if ($name eq 'weighted') { + my $display; + my %relatives = &Apache::lonlocal::texthash( + corrchkd => 'Correct (checked)', + corrunchkd => 'Correct (unchecked)', + incorrchkd => 'Incorrect (checked)', + incorrunchkd => 'Incorrect (unchecked)', + ); + my %textval = ( + corrchkd => '1.0', + corrunchkd => '1.0', + incorrchkd => '0.0', + incorrunchkd => '0.0', + ); + if ($showval =~ /^([\-\d\.]+)\,([\-\d\.]+)\,([\-\d\.]+)\,([\-\d\.]+)$/) { + $textval{'corrchkd'} = $1; + $textval{'corrunchkd'} = $2; + $textval{'incorrchkd'} = $3; + $textval{'incorrunchkd'} = $4; + $display = 'inline'; + $showval = $name; + } else { + $display = 'none'; + } + $add = '
'. + ''; + foreach my $reltype ('corrchkd','corrunchkd','incorrchkd','incorrunchkd') { + $add .= ''."\n". + ''; + } + $add .= '
'.&mt("Foil's submission status").''.&mt('Points').'
 '.$relatives{$reltype}.''. + '
'."\n"; + } + $onchange = ' onclick="javascript:toggleParmTextbox(this.form,'."'$thiskey'".');"'; + $css_class = ' class="LC_lenient_radio"'; + } + $result .= ''. ''; + $result .= ' />'.&mt($description).''.$add.''; $i++; } - $rem = @{ $strings{$thistype} }%($numinrow); - my $colsleft = $numinrow - $rem; - if ($colsleft > 1 ) { - $result .= ''. - ' '; - } elsif ($colsleft == 1) { - $result .= ' '; - } $result .= ''; } if ($result) { @@ -3312,6 +3795,179 @@ sub string_selector { return $result; } +my %intervals = + ( + 'date_interval' + => [[ 'done', 'Yes' ], + [ '', 'No' ]], + ); + +my %intervalmatches = ( + 'date_interval' + => [['done','\d+_done$'],], + ); + +my %intervaltypes = ( + interval => 'date_interval', + ); + +sub standard_interval_matches { + my ($interval_type) = @_; + if (ref($intervalmatches{$interval_type}) eq 'ARRAY') { + return $intervalmatches{$interval_type}; + } + return; +} + +sub get_intervaltype { + my ($name) = @_; + if (exists($intervaltypes{$name})) { + return $intervaltypes{$name}; + } + return; +} + +sub standard_interval_options { + my ($interval_type) = @_; + if (ref($intervals{$interval_type}) eq 'ARRAY') { + return $intervals{$interval_type}; + } + return; +} + +sub date_interval_selector { + my ($thiskey, $name, $showval, $readonly) = @_; + my ($result,%skipval); + if ($name eq 'interval') { + my $intervaltype = &get_intervaltype($name); + my ($got_chostname,$chostname,$cmajor,$cminor); + foreach my $possibilities (@{ $intervals{$intervaltype} }) { + next unless (ref($possibilities) eq 'ARRAY'); + my ($parmval, $description) = @{ $possibilities }; + my $parmmatch; + if (ref($intervalmatches{$intervaltype}) eq 'ARRAY') { + foreach my $item (@{$intervalmatches{$intervaltype}}) { + if (ref($item) eq 'ARRAY') { + if ($parmval eq $item->[0]) { + $parmmatch = $parmval; + $parmval = ''; + last; + } + } + } + } + my $needsrelease=$Apache::lonnet::needsrelease{"parameter:$name:$parmval:$parmmatch"}; + if ($needsrelease) { + unless ($got_chostname) { + ($chostname,$cmajor,$cminor)=¶meter_release_vars(); + $got_chostname = 1; + } + my $needsnewer=¶meter_releasecheck($name,$parmval,$parmmatch, + $needsrelease,$cmajor,$cminor); + if ($needsnewer) { + if ($parmmatch ne '') { + $skipval{$parmmatch} = 1; + } elsif ($parmval ne '') { + $skipval{$parmval} = 1; + } + } + } + } + } + + my $currval = $showval; + foreach my $which (['days', 86400, 31], + ['hours', 3600, 23], + ['minutes', 60, 59], + ['seconds', 1, 59]) { + my ($name, $factor, $max) = @{ $which }; + my $amount = int($showval/$factor); + $showval %= $factor; + my %select = ((map {$_ => $_} (0..$max)), + 'select_form_order' => [0..$max]); + $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey, + \%select,'',$readonly); + $result .= ' '.&mt($name); + } + if ($name eq 'interval') { + unless ($skipval{'done'}) { + my $checkedon = ''; + my $checkedoff = ' checked="checked"'; + if ($currval =~ /^(\d+)_done$/) { + $checkedon = ' checked="checked"'; + $checkedoff = ''; + } + $result .= ''.(' ' x 3).'('.&mt('Include "done" button'). + ''. + ')'; + } + } + unless ($readonly) { + $result .= ''; + } + return $result; +} + +sub oldversion_warning { + my ($name,$value,$chostname,$cmajor,$cminor,$needsrelease) = @_; + my $desc; + my $stringtype = &get_stringtype($name); + if ($stringtype ne '') { + if ($name eq 'examcode') { + $desc = $value; + } elsif (ref($strings{$stringtypes{$name}}) eq 'ARRAY') { + foreach my $possibilities (@{ $strings{$stringtypes{$name}} }) { + next unless (ref($possibilities) eq 'ARRAY'); + my ($parmval, $description) = @{ $possibilities }; + my $parmmatch; + if (ref($stringmatches{$stringtypes{$name}}) eq 'ARRAY') { + foreach my $item (@{$stringmatches{$stringtypes{$name}}}) { + if (ref($item) eq 'ARRAY') { + my ($regexpname,$pattern) = @{$item}; + if ($parmval eq $regexpname) { + if ($value =~ /$pattern/) { + $desc = $description; + $parmmatch = 1; + last; + } + } + } + } + last if ($parmmatch); + } elsif ($parmval eq $value) { + $desc = $description; + last; + } + } + } + } elsif (($name eq 'printstartdate') || ($name eq 'printenddate')) { + my $now = time; + if ($value =~ /^\d+$/) { + if ($name eq 'printstartdate') { + if ($value > $now) { + $desc = &Apache::lonlocal::locallocaltime($value); + } + } elsif ($name eq 'printenddate') { + if ($value < $now) { + $desc = &Apache::lonlocal::locallocaltime($value); + } + } + } + } + my $standard_name = &standard_parameter_names($name); + return '

'. + &mt('[_1] was [_2]not[_3] set to [_4].', + $standard_name,'','','"'.$desc.'"').'
'. + &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).', + $cmajor.'.'.$cminor,$chostname, + $needsrelease). + '

'; +} + +} + # # Shift all start and end dates by $shift # @@ -3357,7 +4013,7 @@ sub newoverview { text=>"Overview Mode"}); my %loaditems = ( - 'onload' => "showHide_courseContent(); resize_scrollbox('mapmenuscroll','1','1');", + 'onload' => "showHide_courseContent(); resize_scrollbox('mapmenuscroll','1','1'); showHideLenient();", ); my $js = ' '; + my $start_page = &Apache::loncommon::start_page('Set Parameters',$js, {'add_entries' => \%loaditems,}); my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview'); $r->print($start_page.$breadcrumbs); &startSettingsScreen($r,'parmset',$crstype); $r->print(< +
ENDOVER my @ids=(); my %typep=(); @@ -3411,6 +4071,9 @@ ENDOVER @selected_sections = ('all'); } } + if ($env{'request.course.sec'} ne '') { + @selected_sections = ($env{'request.course.sec'}); + } my @selected_groups = &Apache::loncommon::get_env_multiple('form.Group'); @@ -3450,16 +4113,26 @@ ENDOVER &displaymenu($r,\%allparms,\@pscat,\%keyorder); $r->print(&Apache::lonhtmlcommon::start_pick_box()); $r->print(&Apache::lonhtmlcommon::row_title(&mt('Select Parts to View'))); + my $sectionselector = §ionmenu(\@selected_sections); + my $groupselector = &groupmenu(\@selected_groups); $r->print(''. - ''); + if ($sectionselector) { + $r->print(''); + } + if ($groupselector) { + $r->print(''); + } + $r->print('
'.&mt('Parts').''.&mt('Section(s)'). - ''.&mt('Group(s)').'
'); + '
'.&mt('Parts').''.&mt('Section(s)').''.&mt('Group(s)').'
'); &partmenu($r,\%allparts,\@psprt); - $r->print(''); - §ionmenu($r,\@selected_sections); - $r->print(''); - &groupmenu($r,\@selected_groups); - $r->print('
'); - #$r->print(''); + $r->print(''); + if ($sectionselector) { + $r->print(''.$sectionselector.''); + } + if ($groupselector) { + $r->print(''.$groupselector.''); + } + $r->print(''); $r->print(&Apache::lonhtmlcommon::row_closure(1)); $r->print(&Apache::lonhtmlcommon::end_pick_box()); $r->print(''); @@ -3493,7 +4166,7 @@ ENDOVER # List data - &listdata($r,$resourcedata,$listdata,$sortorder); + &listdata($r,$resourcedata,$listdata,$sortorder,'newoverview'); } $r->print(&tableend(). ((($env{'form.store'}) || ($env{'form.dis'}))?'

':''). @@ -3542,14 +4215,24 @@ sub overview { my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'}; - + my $js = ''."\n"; &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/parmset?action=setoverview', text=>"Overview Mode"}); - my $start_page=&Apache::loncommon::start_page('Modify Parameters'); + my %loaditems = ( + 'onload' => "showHideLenient();", + ); + + my $start_page=&Apache::loncommon::start_page('Modify Parameters',$js,{'add_entries' => \%loaditems,}); my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Overview'); $r->print($start_page.$breadcrumbs); &startSettingsScreen($r,'parmset',$crstype); - $r->print(''); + $r->print(''); # Store modified @@ -3557,7 +4240,7 @@ sub overview { # Read modified data - my $resourcedata=&readdata($crs,$dom); + my ($resourcedata,$classlist)=&readdata($crs,$dom); my $sortorder=$env{'form.sortorder'}; @@ -3566,8 +4249,7 @@ sub overview { # List data - my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder); - + my $foundkeys=&listdata($r,$resourcedata,$resourcedata,$sortorder,'overview',$classlist); $r->print(&tableend().'

'. ($foundkeys?'':''.&mt('There are no parameters.').'').'

'. &Apache::loncommon::end_page()); @@ -4521,6 +5203,13 @@ sub parm_change_log { !exists($parmlog{$id}{'logentry'}{$changed.'.type'})); my ($realm,$section,$parmname,$part,$what,$middle,$uname,$udom,$issection,$realmdescription)= &components($changed,$parmlog{$id}{'uname'},$parmlog{$id}{'udom'},undef,undef,$typeflag); + if ($env{'request.course.sec'} ne '') { + next if (($issection ne '') && ($issection ne $env{'request.course.sec'})); + if ($uname ne '') { + my $stusection = &Apache::lonnet::getsection($uname,$udom,$env{'request.course.id'}); + next if (($stusection ne '-1') && ($stusection ne $env{'request.course.sec'})); + } + } if ($env{'form.displayfilter'} eq 'currentfolder') { if ($folder) { if ($middle!~/^\Q$folder\E/) { next; } @@ -4722,65 +5411,20 @@ sub parameter_release_vars { } sub parameter_releasecheck { - my ($name,$value,$needsrelease,$cmajor,$cminor) = @_; + my ($name,$value,$valmatch,$needsrelease,$cmajor,$cminor) = @_; my $needsnewer; my ($needsmajor,$needsminor) = split(/\./,$needsrelease); if (($cmajor < $needsmajor) || ($cmajor == $needsmajor && $cminor < $needsminor)) { $needsnewer = 1; - } else { - &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.':'.$value}); + } elsif ($valmatch) { + &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.'::'.$valmatch}); + } elsif ($value) { + &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:'.$name.':'.$value.':'}); } return $needsnewer; } -sub oldversion_warning { - my ($name,$value,$chostname,$cmajor,$cminor,$needsrelease) = @_; - my $desc; - my %stringtypes = ( - type => 'string_questiontype', - lenient => 'string_lenient', - retrypartial => 'string_yesno', - discussvote => 'string_discussvote', - examcode => 'string_examcode', - ); - if (exists($stringtypes{$name})) { - if ($name eq 'examcode') { - $desc = $value; - } elsif (ref($strings{$stringtypes{$name}}) eq 'ARRAY') { - foreach my $possibilities (@{ $strings{$stringtypes{$name}} }) { - next unless (ref($possibilities) eq 'ARRAY'); - my ($parmval, $description) = @{ $possibilities }; - if ($parmval eq $value) { - $desc = $description; - last; - } - } - } - } elsif (($name eq 'printstartdate') || ($name eq 'printenddate')) { - my $now = time; - if ($value =~ /^\d+$/) { - if ($name eq 'printstartdate') { - if ($value > $now) { - $desc = &Apache::lonlocal::locallocaltime($value); - } - } elsif ($name eq 'printenddate') { - if ($value < $now) { - $desc = &Apache::lonlocal::locallocaltime($value); - } - } - } - } - my $standard_name = &standard_parameter_names($name); - return '

'. - &mt('[_1] was [_2]not[_3] set to [_4].', - $standard_name,'','','"'.$desc.'"').'
'. - &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).', - $cmajor.'.'.$cminor,$chostname, - $needsrelease). - '

'; -} - sub handler { my $r=shift;