--- loncom/interface/domainprefs.pm 2013/02/25 17:43:41 1.191
+++ loncom/interface/domainprefs.pm 2013/03/01 04:17:15 1.192
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.191 2013/02/25 17:43:41 raeburn Exp $
+# $Id: domainprefs.pm,v 1.192 2013/03/01 04:17:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -417,7 +417,8 @@ sub handler {
if ($phase eq 'process') {
&Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
} elsif ($phase eq 'display') {
- my $js = &recaptcha_js();
+ my $js = &recaptcha_js().
+ &credits_js();
if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
my ($othertitle,$usertypes,$types) =
&Apache::loncommon::sorted_inst_types($dom);
@@ -2372,7 +2373,8 @@ sub print_helpsettings {
}
sub radiobutton_prefs {
- my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
+ my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
+ $additional) = @_;
return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
(ref($choices) eq 'HASH'));
@@ -2398,17 +2400,22 @@ sub radiobutton_prefs {
}
}
}
+ if ($onclick) {
+ $onclick = ' onclick="'.$onclick.'"';
+ }
foreach my $item (@{$toggles}) {
$css_class = $itemcount%2?' class="LC_odd_row"':'';
$datatable .=
- '
'.$choices->{$item}.
+ ''.
+ ''.$choices->{$item}.
' | '.
''.
' '.
- ' | '.
+ $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').''.
+ ''.$additional.
+ ''.
' ';
$itemcount ++;
}
@@ -2417,28 +2424,31 @@ sub radiobutton_prefs {
sub print_coursedefaults {
my ($position,$dom,$settings,$rowtotal) = @_;
- my ($css_class,$datatable);
+ my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
my $itemcount = 1;
+ my %choices = &Apache::lonlocal::texthash (
+ canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
+ anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
+ coursecredits => 'Credits can be specified for courses',
+ );
if ($position eq 'top') {
- my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
- %choices =
- &Apache::lonlocal::texthash (
- canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
- );
%defaultchecked = ('canuse_pdfforms' => 'off');
- @toggles = ('canuse_pdfforms',);
+ @toggles = ('canuse_pdfforms');
($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
\%choices,$itemcount);
- $$rowtotal += $itemcount;
} else {
$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
- my %choices =
- &Apache::lonlocal::texthash (
- anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
- );
- my $currdefresponder;
+ my ($currdefresponder,$def_official_credits,$def_unofficial_credits);
+ my $currusecredits = 0;
if (ref($settings) eq 'HASH') {
$currdefresponder = $settings->{'anonsurvey_threshold'};
+ if (ref($settings->{'coursecredits'}) eq 'HASH') {
+ $def_official_credits = $settings->{'coursecredits'}->{'official'};
+ $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
+ if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
+ $currusecredits = 1;
+ }
+ }
}
if (!$currdefresponder) {
$currdefresponder = 10;
@@ -2446,13 +2456,41 @@ sub print_coursedefaults {
$currdefresponder = 1;
}
$datatable .=
- ''.$choices{'anonsurvey_threshold'}.
+ ''.
+ $choices{'anonsurvey_threshold'}.
' | '.
''.
''.
- ' | ';
+ ' | '."\n";
+ $itemcount ++;
+ my $onclick = 'toggleCredits(this.form);';
+ my $display = 'none';
+ if ($currusecredits) {
+ $display = 'block';
+ }
+ my $additional = ''.
+ ''.
+ &mt('Default credits for official courses [_1]',
+ '').
+ ' '.
+ ''.
+ &mt('Default credits for unofficial courses [_1]',
+ '').
+ ' '."\n";
+ %defaultchecked = ('coursecredits' => 'off');
+ @toggles = ('coursecredits');
+ my $current = {
+ 'coursecredits' => $currusecredits,
+ };
+ (my $table,$itemcount) =
+ &radiobutton_prefs($current,\@toggles,\%defaultchecked,
+ \%choices,$itemcount,$onclick,$additional);
+ $datatable .= $table;
}
+ $$rowtotal += $itemcount;
return $datatable;
}
@@ -7811,7 +7849,6 @@ sub modify_coursedefaults {
my ($dom,%domconfig) = @_;
my ($resulttext,$errors,%changes,%defaultshash);
my %defaultchecked = ('canuse_pdfforms' => 'off');
- my @offon = ('off','on');
my @toggles = ('canuse_pdfforms');
$defaultshash{'coursedefaults'} = {};
@@ -7828,7 +7865,7 @@ sub modify_coursedefaults {
if (($domconfig{'coursedefaults'}{$item} eq '') &&
($env{'form.'.$item} eq '0')) {
$changes{$item} = 1;
- } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
+ } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
$changes{$item} = 1;
}
} elsif ($defaultchecked{$item} eq 'off') {
@@ -7853,14 +7890,42 @@ sub modify_coursedefaults {
$changes{'anonsurvey_threshold'} = 1;
}
}
+ my $officialcreds = $env{'form.official_credits'};
+ $officialcreds =~ s/^[^\d\.]//g;
+ my $unofficialcreds = $env{'form.unofficial_credits'};
+ $unofficialcreds =~ s/^[^\d\.]//g;
+ if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
+ ($env{'form.coursecredits'} eq '1')) {
+ $changes{'coursecredits'} = 1;
+ } else {
+ if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
+ ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
+ $changes{'coursecredits'} = 1;
+ }
+ }
+ $defaultshash{'coursedefaults'}{'coursecredits'} = {
+ official => $officialcreds,
+ unofficial => $unofficialcreds,
+ }
}
my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
$dom);
if ($putresult eq 'ok') {
+ my %domdefaults;
if (keys(%changes) > 0) {
- if ($changes{'canuse_pdfforms'}) {
- my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
- $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
+ if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'})) {
+ %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+ if ($changes{'canuse_pdfforms'}) {
+ $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
+ }
+ if ($changes{'coursecredits'}) {
+ if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+ $domdefaults{'officialcredits'} =
+ $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
+ $domdefaults{'unofficialcredits'} =
+ $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
+ }
+ }
my $cachetime = 24*60*60;
&Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
}
@@ -7873,7 +7938,22 @@ sub modify_coursedefaults {
$resulttext .= ''.&mt('Course/Community users can create/upload PDF forms set to "off"').'';
}
} elsif ($item eq 'anonsurvey_threshold') {
- $resulttext .= ''.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'';
+ $resulttext .= ''.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'';
+ } elsif ($item eq 'coursecredits') {
+ if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
+ if (($domdefaults{'officialcredits'} eq '') &&
+ ($domdefaults{'unofficialcredits'} eq '')) {
+ $resulttext .= ''.&mt('Student credits not in use for courses in this domain').'';
+ } else {
+ $resulttext .= ''.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').''.
+ '- '.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'
'.
+ '- '.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'
'.
+ ' '.
+ '';
+ }
+ } else {
+ $resulttext .= ''.&mt('Student credits not in use for courses in this domain').'';
+ }
}
}
$resulttext .= '';
@@ -9006,6 +9086,40 @@ function updateCaptcha(caller,context) {
}
}
return;
+}
+
+// ]]>
+
+
+END
+
+}
+
+sub credits_js {
+ return <<"END";
+
+ |