--- loncom/interface/lonparmset.pm 2015/03/12 02:44:51 1.522.2.17 +++ loncom/interface/lonparmset.pm 2017/06/21 19:54:58 1.522.2.23.4.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set parameters for assessments # -# $Id: lonparmset.pm,v 1.522.2.17 2015/03/12 02:44:51 raeburn Exp $ +# $Id: lonparmset.pm,v 1.522.2.23.4.1 2017/06/21 19:54:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -752,7 +752,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') { @@ -766,7 +766,17 @@ sub valout { } } else { if ($type eq 'date_interval') { - my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($value); + my ($totalsecs,$donesuffix) = split(/_/,$value,2); + my ($usesdone,$donebuttontext,$proctor,$secretkey); + if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) { + $donebuttontext = $1; + (undef,$proctor,$secretkey) = split(/_/,$2); + $usesdone = 'done'; + } elsif ($donesuffix =~ /^done(|_.+)$/) { + $donebuttontext = &mt('Done'); + ($usesdone,$proctor,$secretkey) = split(/_/,$donesuffix); + } + my ($sec,$min,$hour,$mday,$mon,$year)=gmtime($totalsecs); my @timer; $year=$year-70; $mday--; @@ -799,6 +809,13 @@ sub valout { push(@timer,&mt('[quant,_1,sec]',0)); } $result.=join(", ",@timer); + if ($usesdone eq 'done') { + if ($secretkey) { + $result .= ' '.&mt('+ "[_1]" with proctor key: [_2]',$donebuttontext,$secretkey); + } else { + $result .= ' + "'.$donebuttontext.'"'; + } + } } elsif (&isdateparm($type)) { $result = &Apache::lonlocal::locallocaltime($value). &date_sanity_info($value); @@ -825,7 +842,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) { @@ -905,6 +922,31 @@ function showHide_courseContent() { COURSECONTENTSCRIPT } +sub done_proctor_js { + return <<"END"; +function toggleSecret(form,radio,key) { + var radios = form[radio+key]; + if (radios.length) { + for (var i=0; iprint($othergrp); } - &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); - &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); - &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display); + &print_td($r,3,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display,'',$readonly); + &print_td($r,2,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display,'',$readonly); + &print_td($r,1,$defbgone,$result,\@outpar,$mprefix,$_,\@typeoutpar,$display,'',$readonly); } } # end of $parmlev if/else @@ -1073,7 +1116,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(''); @@ -1081,23 +1124,27 @@ 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,$readonly)=@_; $r->print(''); my $nolink = 0; - if ($which == 11 || $which == 12) { + if ($readonly) { $nolink = 1; - } elsif ($mprefix =~ /availablestudent\&$/) { - if ($which > 3) { - $nolink = 1; - } - } elsif ($mprefix =~ /examcode\&$/) { - unless ($which == 2) { + } else { + if ($which == 11 || $which == 12) { $nolink = 1; + } elsif ($mprefix =~ /availablestudent\&$/) { + if ($which > 3) { + $nolink = 1; + } + } elsif ($mprefix =~ /examcode\&$/) { + unless ($which == 2) { + $nolink = 1; + } } } 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], @@ -1122,9 +1169,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; @@ -1977,8 +2024,7 @@ sub standardkeyorder { sub assessparms { - my $r=shift; - + my ($r,$parm_permission) = @_; # -------------------------------------------------------- Variable declaration @@ -2022,6 +2068,15 @@ sub assessparms { $csec=$env{'form.csec'}; $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'}) { @@ -2129,7 +2184,7 @@ sub assessparms { $symbp{'0.0'} = ''; # ---------------------------------------------------------- Anything to store? - if ($env{'form.pres_marker'}) { + if ($env{'form.pres_marker'} && $parm_permission->{'edit'}) { my @markers=split(/\&\&\&/,$env{'form.pres_marker'}); my @values=split(/\&\&\&/,$env{'form.pres_value'}); my @types=split(/\&\&\&/,$env{'form.pres_type'}); @@ -2354,6 +2409,10 @@ ENDPARMSELSCRIPT my @catmarker=map { tr|.|_|; 'parameter_'.$_; } @pscat; my $csuname=$env{'user.name'}; my $csudom=$env{'user.domain'}; + my $readonly = 1; + if ($parm_permission->{'edit'}) { + undef($readonly); + } if ($parmlev eq 'full') { # @@ -2539,7 +2598,7 @@ ENDTABLEHEADFOUR &print_row($r,$_,\%part,\%name,\%symbp,$rid,\%default, \%type,\%display,$defbgone,$defbgtwo, $defbgthree,$parmlev,$uname,$udom,$csec, - $cgroup,\@usersgroups); + $cgroup,\@usersgroups,$noeditgrp,$readonly); } } } @@ -2662,7 +2721,8 @@ ENDTABLEHEADFOUR $r->print(&Apache::loncommon::start_data_table_row()); &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default, \%type,\%display,$defbgone,$defbgtwo,$defbgthree, - $parmlev,$uname,$udom,$csec,$cgroup); + $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp, + $readonly); } $r->print(&Apache::loncommon::end_data_table().'

' .'' @@ -2752,8 +2812,9 @@ ENDMAPONE foreach (&keysinorder(\%name,\%keyorder)) { $r->print(&Apache::loncommon::start_data_table_row()); &print_row($r,$_,\%part,\%name,\%symbp,$mapid,\%default, - \%type,\%display,$defbgone,$defbgtwo,$defbgthree, - $parmlev,$uname,$udom,$csec,$cgroup); + \%type,\%display,$defbgone,$defbgtwo,$defbgthree, + $parmlev,$uname,$udom,$csec,$cgroup,'',$noeditgrp, + $readonly); } $r->print(&Apache::loncommon::end_data_table() .'

' @@ -2771,12 +2832,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; } } @@ -2809,7 +2877,11 @@ sub readdata { } } } - return $resourcedata; + if (wantarray) { + return ($resourcedata,$classlist); + } else { + return $resourcedata; + } } @@ -2943,7 +3015,7 @@ sub storedata { if (&Apache::lonnet::del('resourcedata',\@deldata,$dom,$crs) eq 'ok') { my %loghash=map { $_ => '' } @deldata; &log_parmset(\%loghash,1); - $r->print('

'.&mt('Deleted quant,_1,parameter]',$delentries/2).'

'); + $r->print('

'.&mt('Deleted [quant,_1,parameter]',$delentries/2).'

'); } else { $r->print('
'. &mt('Error deleting parameters').'
'); @@ -2988,7 +3060,7 @@ sub parse_listdata_key { } sub listdata { - my ($r,$resourcedata,$listdata,$sortorder)=@_; + my ($r,$resourcedata,$listdata,$sortorder,$caller,$classlist,$readonly)=@_; # Start list output my $oldsection=''; @@ -3098,36 +3170,49 @@ 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()); } } @@ -3136,8 +3221,9 @@ sub listdata { sub date_interval_selector { - my ($thiskey, $showval) = @_; - my $result; + my ($thiskey, $pname, $showval, $readonly) = @_; + my ($result,%skipval); + my $currval = $showval; foreach my $which (['days', 86400, 31], ['hours', 3600, 23], ['minutes', 60, 59], @@ -3148,10 +3234,57 @@ sub date_interval_selector { my %select = ((map {$_ => $_} (0..$max)), 'select_form_order' => [0..$max]); $result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey, - \%select); + \%select,'',$readonly); $result .= ' '.&mt($name); } - $result .= ''; + if ($pname eq 'interval') { + unless ($skipval{'done'}) { + my $checkedon = ''; + my $checkedproc = ''; + my $currproctorkey = ''; + my $currprocdisplay = 'hidden'; + my $currdonetext = &mt('Done'); + my $checkedoff = ' checked="checked"'; + if ($currval =~ /^(?:\d+)_done$/) { + $checkedon = ' checked="checked"'; + $checkedoff = ''; + } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:$/) { + $currdonetext = $1; + $checkedon = ' checked="checked"'; + $checkedoff = ''; + } elsif ($currval =~ /^(?:\d+)_done_proctor_(.+)$/) { + $currproctorkey = $1; + $checkedproc = ' checked="checked"'; + $checkedoff = ''; + $currprocdisplay = 'text'; + } elsif ($currval =~ /^(?:\d+)_done\:([^\:]+)\:_proctor_(.+)$/) { + $currdonetext = $1; + $currproctorkey = $2; + $checkedproc = ' checked="checked"'; + $checkedoff = ''; + $currprocdisplay = 'text'; + } + my $onclick = ' onclick="toggleSecret(this.form,'."'done_','$thiskey'".');"'; + my $disabled; + if ($readonly) { + $disabled = ' disabled="disabled"'; + } + $result .= '
'.&mt('Include "done" button'). + ''.(' 'x2). + ''.(' 'x2). + ''. + '&').'"'.$disabled.' />
'. + ''.&mt('Button text').': '. + '&').'"'.$disabled.' />'; + } + } + unless ($readonly) { + $result .= ''; + } return $result; } @@ -3173,8 +3306,12 @@ sub get_date_interval_from_form { sub default_selector { - my ($thiskey, $showval) = @_; - return ''; + my ($thiskey, $showval, $readonly) = @_; + my $disabled; + if ($readonly) { + $disabled = ' disabled="disabled"'; + } + return ''; } my %strings = @@ -3215,10 +3352,10 @@ sub standard_string_options { } 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; @@ -3244,9 +3381,12 @@ sub string_selector { } } } - + + my ($result,$disabled); - my $result; + if ($readonly) { + $disabled = ' disabled="disabled"'; + } my $numinrow = 3; if ($thistype eq 'string_problemstatus') { $numinrow = 2; @@ -3272,7 +3412,7 @@ sub string_selector { $result .= ''. '