[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm
raeburn
raeburn@source.lon-capa.org
Tue, 21 Dec 2010 14:14:55 -0000
This is a MIME encoded message
--raeburn1292940895
Content-Type: text/plain
raeburn Tue Dec 21 14:14:55 2010 EDT
Modified files:
/loncom/interface lonparmset.pm
Log:
- Do not allow question type parameter to be set to value unsupported in LON-CAPA
version on the course's home server. Display warning.
- Add string_questiontype to parameters set via radio buttons in overview mode
to improve usability.
- In overview mode do not offer values for question type parameter as options
if unsupported in LON-CAPA version on course's home server.
- Setting questiontype to a type with a version requirement updates course's
environment in overview mode (previously was only doing this for table mode).
--raeburn1292940895
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20101221141455.txt"
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.503 loncom/interface/lonparmset.pm:1.504
--- loncom/interface/lonparmset.pm:1.503 Sat Dec 18 23:18:39 2010
+++ loncom/interface/lonparmset.pm Tue Dec 21 14:14:55 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.503 2010/12/18 23:18:39 raeburn Exp $
+# $Id: lonparmset.pm,v 1.504 2010/12/21 14:14:55 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2119,7 +2119,11 @@
my @types=split(/\&\&\&/,$env{'form.pres_type'});
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
+ my ($got_chostname,$chostname,$cmajor,$cminor);
+ my $totalstored = 0;
for (my $i=0;$i<=$#markers;$i++) {
+ my ($needsrelease,$needsnewer);
if ($markers[$i] =~ /^[\d.]+\&0_availablestudent\&(1|2|3)$/) {
my (@ok_slots,@fail_slots,@del_slots);
my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
@@ -2151,20 +2155,37 @@
}
}
} elsif ($markers[$i] =~ /_type\&\d+$/) {
- if (($values[$i] eq 'anonsurvey') || ($values[$i] eq 'anonsurveycred') || ($values[$i] eq 'randomizetry')) {
- &Apache::lonnet::update_released_required($Apache::lonnet::needsrelease{'parameter:type:'.$values[$i]});
+ $needsrelease =
+ $Apache::lonnet::needsrelease{'parameter:type:'.$values[$i]};
+ if ($needsrelease) {
+ unless ($got_chostname) {
+ ($chostname,$cmajor,$cminor) = &questiontype_release_vars();
+ $got_chostname = 1;
+ }
+ $needsnewer = &questiontype_releasecheck($values[$i],
+ $needsrelease,
+ $chostname,
+ $cmajor,$cminor);
}
}
- $message.=&storeparm(split(/\&/,$markers[$i]),
- $values[$i],
- $types[$i],
- $uname,$udom,$csec,$cgroup);
+ if ($needsnewer) {
+ $message .= &oldversion_warning($values[$i],$chostname,$cmajor,
+ $cminor,$needsrelease);
+ } else {
+ $message.=&storeparm(split(/\&/,$markers[$i]),
+ $values[$i],
+ $types[$i],
+ $uname,$udom,$csec,$cgroup);
+ $totalstored ++;
+ }
}
# ---------------------------------------------------------------- Done storing
- $message.='<p class="LC_warning">'
- .&mt('Changes can take up to 10 minutes before being active for all students.')
- .&Apache::loncommon::help_open_topic('Caching')
- .'</p>';
+ if ($totalstored) {
+ $message.='<p class="LC_warning">'
+ .&mt('Changes can take up to 10 minutes before being active for all students.')
+ .&Apache::loncommon::help_open_topic('Caching')
+ .'</p>';
+ }
}
#----------------------------------------------- if all selected, fill in array
if ($pscat[0] eq "all") {@pscat = (keys %allparms);}
@@ -2762,8 +2783,9 @@
undef %newdata;
my @deldata=();
undef @deldata;
- foreach (keys %env) {
- if ($_=~/^form\.([a-z]+)\_(.+)$/) {
+ my ($got_chostname,$chostname,$cmajor,$cminor);
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.([a-z]+)\_(.+)$/) {
my $cmd=$1;
my $thiskey=$2;
my ($tuname,$tudom)=&extractuser($thiskey);
@@ -2774,11 +2796,29 @@
if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
my ($data, $typeof, $text);
if ($cmd eq 'set') {
- $data=$env{$_};
+ $data=$env{$key};
$typeof=$env{'form.typeof_'.$thiskey};
$text = &mt('Saved modified parameter for');
+ if ($typeof eq 'string_questiontype') {
+ my ($needsrelease,$needsnewer);
+ $needsrelease = $Apache::lonnet::needsrelease{'parameter:type:'.$data};
+ if ($needsrelease) {
+ unless ($got_chostname) {
+ ($chostname,$cmajor,$cminor)=&questiontype_release_vars();
+ $got_chostname = 1;
+ }
+ $needsnewer = &questiontype_releasecheck($data,$needsrelease,
+ $chostname,$cmajor,
+ $cminor);
+ }
+ if ($needsnewer) {
+ $r->print('<br />'.&oldversion_warning($data,$chostname,$cmajor,
+ $cminor,$needsrelease));
+ next;
+ }
+ }
} elsif ($cmd eq 'datepointer') {
- $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
+ $data=&Apache::lonhtmlcommon::get_date_from_form($env{$key});
$typeof=$env{'form.typeof_'.$thiskey};
$text = &mt('Saved modified date for');
} elsif ($cmd eq 'dateinterval') {
@@ -3072,6 +3112,15 @@
[ 'answer', 'Yes, and show correct answer if they exceed the maximum number of tries.' ],
[ 'no', 'No, don\'t show correct/incorrect feedback.' ],
[ 'no_feedback_ever', 'No, show no feedback at all.' ]],
+ 'string_questiontype'
+ => [[ 'problem', 'Standard Problem'],
+ [ 'survey', 'Survey'],
+ [ 'anonsurveycred', 'Anonymous Survey (credit for submission)'],
+ [ 'exam', 'Exam'],
+ [ 'anonsurvey', 'Anonymous Survey'],
+ [ 'randomizetry', 'New Randomization Each N Tries (default N=1)'],
+ [ 'practice', 'Practice'],
+ [ 'surveycred', 'Survey (credit for submission)']],
);
@@ -3082,15 +3131,73 @@
return &default_selector($thiskey,$showval);
}
+ my %skiptype;
+ if ($thistype eq 'string_questiontype') {
+ my ($got_chostname,$chostname,$cmajor,$cminor);
+ foreach my $possibilities (@{ $strings{$thistype} }) {
+ next unless (ref($possibilities) eq 'ARRAY');
+ my ($name, $description) = @{ $possibilities };
+ my $needsrelease=$Apache::lonnet::needsrelease{'parameter:type:'.$name};
+ if ($needsrelease) {
+ unless ($got_chostname) {
+ ($chostname,$cmajor,$cminor)=&questiontype_release_vars();
+ $got_chostname = 1;
+ }
+ my $needsnewer=&questiontype_releasecheck($name,$needsrelease,
+ $chostname,$cmajor,
+ $cminor);
+ if ($needsnewer) {
+ $skiptype{$name} = 1;
+ }
+ }
+ }
+ }
+
my $result;
- foreach my $possibilities (@{ $strings{$thistype} }) {
- my ($name, $description) = @{ $possibilities };
- $result .= '<label><input type="radio" name="set_'.$thiskey.
- '" value="'.$name.'"';
- if ($showval eq $name) {
- $result .= ' checked="checked"';
+ my $numinrow = 3;
+ if ($thistype eq 'string_problemstatus') {
+ $numinrow = 2;
+ } elsif ($thistype eq 'string_questiontype') {
+ if (keys(%skiptype) > 0) {
+ $numinrow = 4;
+ }
+ }
+ my $rem;
+ if (ref($strings{$thistype}) eq 'ARRAY') {
+ my $i=0;
+ foreach my $possibilities (@{ $strings{$thistype} }) {
+ next unless (ref($possibilities) eq 'ARRAY');
+ my ($name, $description) = @{ $possibilities };
+ next if ($skiptype{$name});
+ $rem = $i%($numinrow);
+ if ($rem == 0) {
+ if ($i > 0) {
+ $result .= '</tr>';
+ }
+ $result .= '<tr>';
+ }
+ $result .= '<td class="LC_left_item">'.
+ '<span class="LC_nobreak"><label>'.
+ '<input type="radio" name="set_'.$thiskey.
+ '" value="'.$name.'"';
+ if ($showval eq $name) {
+ $result .= ' checked="checked"';
+ }
+ $result .= ' />'.&mt($description).'</label></span></td>';
+ $i++;
+ }
+ $rem = @{ $strings{$thistype} }%($numinrow);
+ my $colsleft = $numinrow - $rem;
+ if ($colsleft > 1 ) {
+ $result .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
+ ' </td>';
+ } elsif ($colsleft == 1) {
+ $result .= '<td class="LC_left_item"> </td>';
+ }
+ $result .= '</tr>';
}
- $result .= ' />'.&mt($description).'</label> ';
+ if ($result) {
+ $result = '<table border="0">'.$result.'</table>';
}
return $result;
}
@@ -4442,6 +4549,49 @@
return 0;
}
+sub questiontype_release_vars {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
+ my $chostname = &Apache::lonnet::hostname($chome);
+ my ($cmajor,$cminor) =
+ split(/\./,&Apache::lonnet::get_server_loncaparev($cdom,$chome));
+ return ($chostname,$cmajor,$cminor);
+}
+
+sub questiontype_releasecheck {
+ my ($questiontype,$needsrelease,$chostname,$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:type:'.$questiontype});
+ }
+ return $needsnewer;
+}
+
+sub oldversion_warning {
+ my ($questiontype,$chostname,$cmajor,$cminor,$needsrelease) = @_;
+ my $desc;
+ if (ref($strings{'string_questiontype'}) eq 'ARRAY') {
+ foreach my $possibilities (@{ $strings{'string_questiontype'} }) {
+ next unless (ref($possibilities) eq 'ARRAY');
+ my ($name, $description) = @{ $possibilities };
+ if ($name eq $questiontype) {
+ $desc = $description;
+ last;
+ }
+ }
+ }
+ return '<p class="LC_warning">'.
+ &mt('Question Type was [_1]not[_2] set to [_3].',
+ '<b>','</b>','"'.$desc.'"').'<br />'.
+ &mt('LON-CAPA version ([_1]) installed on home server ([_2]) does not meet version requirements ([_3] or newer).',
+ $cmajor.'.'.$cminor,$chostname,
+ $needsrelease).
+ '</p>';
+}
sub handler {
my $r=shift;
--raeburn1292940895--