--- loncom/interface/loncreateuser.pm 2009/08/06 20:40:59 1.305
+++ loncom/interface/loncreateuser.pm 2009/08/08 00:36:00 1.306
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.305 2009/08/06 20:40:59 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.306 2009/08/08 00:36:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -216,7 +216,8 @@ END_SCRIPT
sub build_tools_display {
my ($ccuname,$ccdomain,$context) = @_;
- my (@usertools,%userenv,$output);
+ my (@usertools,%userenv,$output,@options,%validations,%reqtitles,%reqdisplay,
+ $colspan);
my %lt = &Apache::lonlocal::texthash (
'blog' => "Personal User Blog",
'aboutme' => "Personal Information Page",
@@ -235,53 +236,123 @@ sub build_tools_display {
'requestcourses.official','requestcourses.unofficial',
'requestcourses.community');
@usertools = ('official','unofficial','community');
+ @options =('norequest','approve','autolimit','validate');
+ %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
+ %reqtitles = &courserequest_titles();
+ %reqdisplay = &courserequest_display();
+ $colspan = ' colspan="2"';
} else {
%userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
'tools.aboutme','tools.portfolio','tools.blog');
@usertools = ('aboutme','blog','portfolio');
}
foreach my $item (@usertools) {
- my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off);
+ my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
+ $currdisp,$custdisp,$custradio);
$cust_off = 'checked="checked" ';
$tool_on = 'checked="checked" ';
$curr_access =
&Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
$context);
- if ($userenv{$context.'.'.$item} eq '') {
- $custom_access =
- &mt('Availability determined currently from default setting.');
- if (!$curr_access) {
- $tool_off = 'checked="checked" ';
- $tool_on = '';
- }
- } else {
- $custom_access =
- &mt('Availability determined currently from custom setting.');
+ if ($userenv{$context.'.'.$item} ne '') {
$cust_on = ' checked="checked" ';
$cust_off = '';
- if ($userenv{$context.'.'.$item} == 0) {
- $tool_off = 'checked="checked" ';
- $tool_on = '';
+ }
+ if ($context eq 'requestcourses') {
+ if ($userenv{$context.'.'.$item} eq '') {
+ $custom_access = &mt('Currently from default setting.');
+ } else {
+ $custom_access = &mt('Currently from custom setting.');
+ }
+ } else {
+ if ($userenv{$context.'.'.$item} eq '') {
+ $custom_access =
+ &mt('Availability determined currently from default setting.');
+ if (!$curr_access) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ } else {
+ $custom_access =
+ &mt('Availability determined currently from custom setting.');
+ if ($userenv{$context.'.'.$item} == 0) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
}
}
$output .= '
'."\n".
- ' '.$lt{$item}.' | '."\n".
+ ' '.$lt{$item}.' | '."\n".
'
'."\n".
- &Apache::loncommon::start_data_table_row()."\n".
- ' '.$custom_access.(' 'x5).$lt{'avai'}.': '.
- ($curr_access?&mt('Yes'):&mt('No')).' | '."\n".
+ &Apache::loncommon::start_data_table_row()."\n";
+ if ($context eq 'requestcourses') {
+ my ($curroption,$currlimit);
+ $curroption = $userenv{$context.'.'.$item};
+ if (!$curroption) {
+ $curroption = 'norequest';
+ }
+ if ($curroption =~ /^autolimit=(\d*)$/) {
+ $currlimit = $1;
+ $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
+ } else {
+ $currdisp = $reqdisplay{$curroption};
+ }
+ $custdisp = '';
+ $custradio = ''.&mt('Custom setting').' '.$custdisp;
+ } else {
+ $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
+ $custdisp = ' ';
+ $custradio = (' 'x2).'--'.$lt{'cusa'}.': '.$custdisp.
+ '';
+ }
+ $output .= ' | '.$custom_access.(' 'x4).
+ $lt{'avai'}.': '.$currdisp.' | '."\n".
&Apache::loncommon::end_data_table_row()."\n".
&Apache::loncommon::start_data_table_row()."\n".
- ' '.$lt{'chse'}.': '.(' ' x3).
+ ''.$lt{'uscu'}.''.$custradio.' | '.
&Apache::loncommon::end_data_table_row()."\n";
}
return $output;
@@ -289,7 +360,7 @@ sub build_tools_display {
sub coursereq_externaluser {
my ($ccuname,$ccdomain,$cdom) = @_;
- my (@usertools,%userenv,$output);
+ my (@usertools,@options,%validations,%userenv,$output);
my %lt = &Apache::lonlocal::texthash (
'official' => 'Can request creation of official courses',
'unofficial' => 'Can request creation of unofficial courses',
@@ -300,27 +371,83 @@ sub coursereq_externaluser {
'reqcrsotherdom.official','reqcrsotherdom.unofficial',
'reqcrsotherdom.community');
@usertools = ('official','unofficial','community');
+ @options = ('approve','validate','autolimit');
+ %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
+ my $optregex = join('|',@options);
+ my %reqtitles = &courserequest_titles();
foreach my $item (@usertools) {
- my ($tool_on,$tool_off);
- $tool_off = 'checked="checked" ';
+ my ($curroption,$currlimit,$tooloff);
if ($userenv{'reqcrsotherdom.'.$item} ne '') {
my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
- if (grep(/^\Q$cdom\E$/,@curr)) {
- $tool_on = 'checked="checked" ';
- $tool_off = '';
+ if (grep(/^\Q$cdom\E:($optregex)=?(\d*)$/,@curr)) {
+ $curroption = $1;
+ $currlimit = $2;
+ if (!$curroption) {
+ $curroption = 'norequest';
+ }
}
+ } else {
+ $curroption = 'norequest';
+ $tooloff = ' checked="checked"';
+ }
+ $output.= &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{$item}.': '.
+ ''.$reqtitles{'norequest'}.
+ ' ';
+ foreach my $option (@options) {
+ if ($option eq 'validate') {
+ my $canvalidate = 0;
+ if (ref($validations{$item}) eq 'HASH') {
+ if ($validations{$item}{'_external_'}) {
+ $canvalidate = 1;
+ }
+ }
+ next if (!$canvalidate);
+ }
+ my $checked = '';
+ if ($option eq $curroption) {
+ $checked = ' checked="checked"';
+ }
+ $output .= ''.
+ ''.
+ $reqtitles{$option}.' ';
+ if ($option eq 'autolimit') {
+ $output .= '';
+ }
+ $output .= ' '
}
- $output .= &Apache::loncommon::start_data_table_row()."\n".
- ' | '.$lt{$item}.': '.
- ''.&mt('Yes').' '.
- ''.&mt('No').' | '."\n".
+ $output .= ''."\n".
&Apache::loncommon::end_data_table_row()."\n";
}
return $output;
}
+sub courserequest_titles {
+ my %titles = &Apache::lonlocal::texthash (
+ official => 'Official',
+ unofficial => 'Unofficial',
+ community => 'Communities',
+ norequest => 'Not allowed',
+ approve => 'Approval by Dom. Coord.',
+ validate => 'With validation',
+ autolimit => 'Numerical limit',
+ );
+ return %titles;
+}
+
+sub courserequest_display {
+ my %titles = &Apache::lonlocal::texthash (
+ approve => 'Yes, need approval',
+ validate => 'Yes, with validation',
+ norequest => 'No',
+ );
+ return %titles;
+}
+
# =================================================================== Phase one
sub print_username_entry_form {
@@ -2031,7 +2158,13 @@ sub update_user_data {
}
}
foreach my $item (@requestcourses) {
- $newcustom{$item} = $env{'form.requestcourses_'.$item};
+ $newcustom{$item} = $env{'form.crsreq_'.$item};
+ if ($env{'form.crsreq_'.$item} eq 'autolimit') {
+ $newcustom{$item} .= '=';
+ unless ($env{'form.crsreq_'.$item.'_limit'} =~ /\D/) {
+ $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
+ }
+ }
$changed{$item} = &tool_admin($item,$newcustom{$item},
\%changeHash,'requestcourses');
}
@@ -2677,6 +2810,9 @@ sub tool_changes {
return;
}
if ($context eq 'reqcrsotherdom') {
+ my @options = ('approve','validate','autolimit');
+ my $optregex = join('|',@options);
+ my %reqdisplay = &courserequest_display();
my $cdom = $env{'request.role.domain'};
foreach my $tool (@{$usertools}) {
$oldaccesstext->{$tool} = &mt('no');
@@ -2695,19 +2831,31 @@ sub tool_changes {
my @curr = split(',',$userenv->{$context.'.'.$tool});
my @new;
my $changedoms;
- if (grep(/^\Q$cdom\E$/,@curr)) {
+ my $newop = $env{'form.'.$context.'_'.$tool};
+ if ($newop eq 'autolimit') {
+ $newop .= '=';
+ unless ($env{'form.'.$context.'_'.$tool.'_limit'} =~ /\D/) {
+ $newop .= $env{'form.'.$context.'_'.$tool.'_limit'};
+ }
+ }
+ if (grep(/^\Q$cdom:($optregex\=?\d*)\E$/,@curr)) {
$oldaccesstext->{$tool} = &mt('yes');
- unless ($env{'form.'.$context.'_'.$tool}) {
+ my $oldop = $1;
+ if ($oldop ne $newop) {
$changedoms = 1;
foreach my $dom (@curr) {
unless ($dom eq $cdom) {
push(@new,$dom);
}
}
+ if ($newop) {
+ push(@new,$cdom.':'.$newop);
+ }
+ @new = sort(@new);
}
} elsif ($env{'form.'.$context.'_'.$tool}) {
$changedoms = 1;
- @new = sort(@curr,$cdom);
+ @new = sort(@curr,$cdom.':'.$newop);
}
$newaccesstext->{$tool} = $oldaccesstext->{$tool};
if ($changedoms) {
@@ -2719,9 +2867,17 @@ sub tool_changes {
$context);
if ($changed->{$tool}) {
if ($env{'form.'.$context.'_'.$tool}) {
- $newaccesstext->{$tool} = &mt('yes');
+ if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
+ if ($env{'form.'.$context.'_'.$tool.'_limit'} =~ /\D/) {
+ $newaccesstext->{$tool} = &mt('Yes, processed automatically');
+ } else {
+ $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user).',$env{'form.'.$context.'_'.$tool.'_limit'});
+ }
+ } else {
+ $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
+ }
} else {
- $newaccesstext->{$tool} = &mt('no');
+ $newaccesstext->{$tool} = &mt('No');
}
}
}
@@ -2730,6 +2886,15 @@ sub tool_changes {
return;
}
foreach my $tool (@{$usertools}) {
+ my $newval;
+ if ($context eq 'requestcourses') {
+ $newval = $env{'form.crsreq_'.$tool};
+ if ($newval eq 'autolimit') {
+ $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'};
+ }
+ } else {
+ $newval = $env{'form.'.$context.'_'.$tool};
+ }
if ($userenv->{$context.'.'.$tool} ne '') {
$oldaccess->{$tool} = &mt('custom');
if ($userenv->{$context.'.'.$tool}) {
@@ -2739,12 +2904,12 @@ sub tool_changes {
}
$changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
if ($env{'form.custom'.$tool} == 1) {
- if ($env{'form.'.$context.'_'.$tool} ne $userenv->{$context.'.'.$tool}) {
- $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool},
- $changeHash,$context);
+ if ($newval ne $userenv->{$context.'.'.$tool}) {
+ $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
+ $context);
if ($changed->{$tool}) {
$newaccess->{$tool} = &mt('custom');
- if ($env{'form.'.$context.'_'.$tool}) {
+ if ($newval) {
$newaccesstext->{$tool} = &mt("availability set to 'on'");
} else {
$newaccesstext->{$tool} = &mt("availability set to 'off'");
@@ -2777,11 +2942,11 @@ sub tool_changes {
} else {
$oldaccess->{$tool} = &mt('default');
if ($env{'form.custom'.$tool} == 1) {
- $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool},
- $changeHash,$context);
+ $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
+ $context);
if ($changed->{$tool}) {
$newaccess->{$tool} = &mt('custom');
- if ($env{'form.'.$context.'_'.$tool}) {
+ if ($newval) {
$newaccesstext->{$tool} = &mt("availability set to 'on'");
} else {
$newaccesstext->{$tool} = &mt("availability set to 'off'");