--- loncom/interface/loncreateuser.pm 2008/12/15 00:54:54 1.268.2.2 +++ loncom/interface/loncreateuser.pm 2009/02/03 05:28:00 1.276 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.268.2.2 2008/12/15 00:54:54 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.276 2009/02/03 05:28:00 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -123,18 +123,10 @@ sub portfolio_quota { my ($ccuname,$ccdomain) = @_; my %lt = &Apache::lonlocal::texthash( 'usrt' => "User Tools", - 'blog' => "Personal User Blog", - 'aboutme' => "Personal Information Page", - 'portfolio' => "Personal User Portfolio", - 'avai' => "Available", - 'cusa' => "availability", - 'chse' => "Change setting", 'disk' => "Disk space allocated to user's portfolio files", 'cuqu' => "Current quota", 'cust' => "Custom quota", 'defa' => "Default", - 'usde' => "Use default", - 'uscu' => "Use custom", 'chqu' => "Change quota", ); my ($currquota,$quotatype,$inststatus,$defquota) = @@ -190,51 +182,7 @@ END_SCRIPT &Apache::loncommon::start_data_table(); if (&Apache::lonnet::allowed('mut',$ccdomain)) { - my %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, - 'tools.aboutme','tools.portfolio','tools.blog'); - my @usertools = ('aboutme','blog','portfolio'); - foreach my $item (@usertools) { - my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off); - $cust_off = 'checked="checked" '; - $tool_on = 'checked="checked" '; - $curr_access = &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item); - if ($userenv{'tools.'.$item} eq '') { - $custom_access = 'default'; - if (!$curr_access) { - $tool_off = 'checked="checked" '; - $tool_on = ''; - } - } else { - $custom_access = 'custom'; - $cust_on = ' checked="checked" '; - $cust_off = ''; - if ($userenv{'tools.'.$item} == 0) { - $tool_off = 'checked="checked" '; - $tool_on = ''; - } - } - $curr_access = &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item); - $output .= ' '."\n". - ' '.$lt{$item}.''."\n". - ' '."\n". - &Apache::loncommon::start_data_table_row()."\n". - ' '.&mt('Availability determined currently from [_1] setting.',$custom_access). - '     '.$lt{'avai'}.': '. - ($curr_access?&mt('Yes'):&mt('No')).''."\n". - &Apache::loncommon::end_data_table_row()."\n". - &Apache::loncommon::start_data_table_row()."\n". - ' '.$lt{'chse'}.':    '. - '  --  '. - $lt{'cusa'}.':  '."\n". - &Apache::loncommon::end_data_table_row()."\n"; - } + $output .= &build_tools_display($ccuname,$ccdomain,'tools'); } if (&Apache::lonnet::allowed('mpq',$ccdomain)) { $output .= ''."\n". @@ -263,6 +211,76 @@ END_SCRIPT return $output; } +sub build_tools_display { + my ($ccuname,$ccdomain,$context) = @_; + my (@usertools,%userenv,$output); + my %lt = &Apache::lonlocal::texthash ( + 'blog' => "Personal User Blog", + 'aboutme' => "Personal Information Page", + 'portfolio' => "Personal User Portfolio", + 'avai' => "Available", + 'cusa' => "availability", + 'chse' => "Change setting", + 'usde' => "Use default", + 'uscu' => "Use custom", + 'official' => 'Can request creation of official courses', + 'unofficial' => 'Can request creation of unofficial courses', + ); + if ($context eq 'requestcourse') { + %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname, + 'requestcourse.official','requestcourse.unofficial'); + @usertools = ('official','unofficial'); + } 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); + $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 = 'default'; + if (!$curr_access) { + $tool_off = 'checked="checked" '; + $tool_on = ''; + } + } else { + $custom_access = 'custom'; + $cust_on = ' checked="checked" '; + $cust_off = ''; + if ($userenv{$context.'.'.$item} == 0) { + $tool_off = 'checked="checked" '; + $tool_on = ''; + } + } + $output .= ' '."\n". + ' '.$lt{$item}.''."\n". + ' '."\n". + &Apache::loncommon::start_data_table_row()."\n". + ' '.&mt('Availability determined currently from [_1] setting.',$custom_access). + '     '.$lt{'avai'}.': '. + ($curr_access?&mt('Yes'):&mt('No')).''."\n". + &Apache::loncommon::end_data_table_row()."\n". + &Apache::loncommon::start_data_table_row()."\n". + ' '.$lt{'chse'}.':    '. + '  --  '. + $lt{'cusa'}.':  '."\n". + &Apache::loncommon::end_data_table_row()."\n"; + } + return $output; +} + # =================================================================== Phase one sub print_username_entry_form { @@ -772,6 +790,7 @@ $lt{'hs'}: $home_server_pick $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc)); } else { my $authparm = $rules->{$matchedrule}{'authparm'}; + $authmsg = $rules->{$matchedrule}{'authmsg'}; if ($authtype =~ /^krb(4|5)$/) { my $ver = $1; if ($authparm ne '') { @@ -780,7 +799,6 @@ $lt{'hs'}: $home_server_pick KERB - $authmsg = $rules->{$matchedrule}{'authmsg'}; } } else { $fixedauth = @@ -789,8 +807,16 @@ KERB $fixedauth .= ''."\n"; } else { - $varauth = + if ($authtype eq 'int') { + $varauth = '
'. +&mt('[_1] Internally authenticated (with initial password [_2])','','')."'; + } elsif ($authtype eq 'loc') { + $varauth = '
'. +&mt('[_1] Local Authentication with argument [_2]','','')."\n"; + } else { + $varauth = ''."\n"; + } } } } @@ -840,9 +866,15 @@ ENDCHANGEUSER if ($showforceid) { $r->print(&Apache::lonuserutils::forceid_change($context)); } + if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) { + $r->print('

'.&mt('User Can Request Creation of Courses?').'

'. + &Apache::loncommon::start_data_table(). + &build_tools_display($ccuname,$ccdomain,'requestcourse'). + &Apache::loncommon::end_data_table()); + } $r->print(''); my $user_auth_text = &user_authentication($ccuname,$ccdomain,$formname); - my ($user_quota_text,$user_tools_text); + my ($user_quota_text,$user_tools_text,$user_reqcrs_text); if ((&Apache::lonnet::allowed('mpq',$ccdomain)) || (&Apache::lonnet::allowed('mut',$ccdomain))) { # Current user has quota modification privileges @@ -1740,6 +1772,7 @@ sub update_user_data { $env{'form.ccuname'}, $env{'form.ccdomain'}).''); my (%alerts,%rulematch,%inst_results,%curr_rules); my @usertools = ('aboutme','blog','portfolio'); + my @requestcourses = ('official','unofficial'); if ($env{'form.makeuser'}) { $r->print('

'.&mt('Creating new account.').'

'); # Check for the authentication mode and password @@ -1813,7 +1846,15 @@ sub update_user_data { foreach my $item (@usertools) { if ($env{'form.custom'.$item} == 1) { $newcustom{$item} = $env{'form.tools_'.$item}; - $changed{$item} = &tool_admin($item,$newcustom{$item},\%changeHash); + $changed{$item} = &tool_admin($item,$newcustom{$item}, + \%changeHash,'tools'); + } + } + if (&Apache::lonnet::allowed('ccc',$env{'request.domain'})) { + foreach my $item (@requestcourses) { + $newcustom{$item} = $env{'form.requestcourse_'.$item}; + $changed{$item} = &tool_admin($item,$newcustom{$item}, + \%changeHash,'requestcourse'); } } if (keys(%changed)) { @@ -1860,7 +1901,8 @@ sub update_user_data { my %userenv = &Apache::lonnet::get ('environment',['firstname','middlename','lastname','generation', 'id','permanentemail','portfolioquota','inststatus','tools.aboutme', - 'tools.blog','tools.portfolio'], + 'tools.blog','tools.portfolio','requestcourse.official', + 'requestcourse.unofficial'], $env{'form.ccdomain'},$env{'form.ccuname'}); my ($tmp) = keys(%userenv); if ($tmp =~ /^(con_lost|error)/i) { @@ -1988,13 +2030,16 @@ sub update_user_data { $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext); my ($defquota,$settingstatus) = &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus); - my ($showquota,$showtools); + my ($showquota,$showtools,$showrequestcourses); if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) { $showquota = 1; } if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) { $showtools = 1; } + if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) { + $showrequestcourses = 1; + } my (%changeHash,%changed); $changeHash{'portfolioquota'} = $userenv{'portfolioquota'}; if ($userenv{'portfolioquota'} ne '') { @@ -2036,74 +2081,10 @@ sub update_user_data { if ($newisdefault) { $newdefquotatext = &get_defaultquota_text($settingstatus); } - - foreach my $tool (@usertools) { - if ($userenv{'tools.'.$tool} ne '') { - $oldaccess{$tool} = &mt('custom'); - if ($userenv{'tools_'.$tool}) { - $oldaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $oldaccesstext{$tool} = &mt("availability set to 'off'"); - } - $changeHash{'tools.'.$tool} = $userenv{'tools.'.$tool}; - if ($env{'form.custom'.$tool} == 1) { - if ($env{'form.tools_'.$tool} ne $userenv{'tools.'.$tool}) { - $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool}, - \%changeHash); - if ($changed{$tool}) { - $newaccess{$tool} = &mt('custom'); - if ($env{'form.tools_'.$tool}) { - $newaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $newaccesstext{$tool} = &mt("availability set to 'off'"); - } - } else { - $newaccess{$tool} = $oldaccess{$tool}; - if ($userenv{'tools.'.$tool}) { - $newaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $newaccesstext{$tool} = &mt("availability set to 'off'"); - } - } - } else { - $newaccess{$tool} = $oldaccess{$tool}; - $newaccesstext{$tool} = $oldaccesstext{$tool}; - } - } else { - $changed{$tool} = &tool_admin($tool,'',\%changeHash); - print STDERR "for $tool - changed is $changed{$tool}\n"; - if ($changed{$tool}) { - $newaccess{$tool} = &mt('default'); - } else { - $newaccess{$tool} = $oldaccess{$tool}; - if ($userenv{'tools.'.$tool}) { - $newaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $newaccesstext{$tool} = &mt("availability set to 'off'"); - } - } - } - } else { - $oldaccess{$tool} = &mt('default'); - if ($env{'form.custom'.$tool} == 1) { - $changed{$tool} = &tool_admin($tool,$env{'form.tools_'.$tool}, - \%changeHash); - if ($changed{$tool}) { - $newaccess{$tool} = &mt('custom'); - if ($env{'form.tools_'.$tool}) { - $newaccesstext{$tool} = &mt("availability set to 'on'"); - } else { - $newaccesstext{$tool} = &mt("availability set to 'off'"); - } - } else { - $newaccess{$tool} = $oldaccess{$tool}; - } - } else { - $newaccess{$tool} = $oldaccess{$tool}; - } - } - } - + &tool_changes('tools',\@usertools,\%oldaccess,\%oldaccesstext,\%userenv, + \%changeHash,\%changed,\%newaccess,\%newaccesstext); + &tool_changes('requestcourse',\@requestcourses,\%oldaccess,\%oldaccesstext, + \%userenv, \%changeHash,\%changed,\%newaccess,\%newaccesstext); if ($env{'form.cfirstname'} ne $userenv{'firstname'} || $env{'form.cmiddlename'} ne $userenv{'middlename'} || $env{'form.clastname'} ne $userenv{'lastname'} || @@ -2125,18 +2106,26 @@ sub update_user_data { &Apache::lonnet::put('environment',\%changeHash, $env{'form.ccdomain'},$env{'form.ccuname'}); if ($chgresult eq 'ok') { - my %newenvhash; - my $hashid="$env{'form.ccuname'}:$env{'form.ccdomain'}"; - foreach my $key (keys(%changed)) { - if ($key ne 'quota') { - &Apache::lonnet::devalidate_cache_new('usertools.'.$key,$hashid); - $newenvhash{'environment.tools.'.$key} = - $changeHash{'tools.'.$key}; - } - } if (($env{'user.name'} eq $env{'form.ccuname'}) && ($env{'user.domain'} eq $env{'form.ccdomain'})) { - &Apache::lonnet::appenv(\%newenvhash); + my %newenvhash; + foreach my $key (keys(%changed)) { + if (($key eq 'official') || ($key eq 'unofficial')) { + $newenvhash{'environment.canrequest.'.$key} = + $changeHash{'requestcourse.'.$key}; + $newenvhash{'environment.canrequest.'.$key} = + $changeHash{'requestcourse.'.$key}; + + } elsif ($key ne 'quota') { + $newenvhash{'environment.tools.'.$key} = + $changeHash{'tools.'.$key}; + $newenvhash{'environment.availabletools.'.$key} = + $changeHash{'tools.'.$key}; + } + } + if (keys(%newenvhash)) { + &Apache::lonnet::appenv(\%newenvhash); + } } } } @@ -2160,19 +2149,21 @@ sub update_user_data { ((keys(%changed) > 0) && $chgresult eq 'ok')) { # Tell the user we changed the name my %lt=&Apache::lonlocal::texthash( - 'uic' => "User Information Changed", - 'frst' => "First", - 'mddl' => "Middle", - 'lst' => "Last", - 'gen' => "Generation", - 'id' => "Student/Employee ID", - 'mail' => "Permanent E-mail", - 'disk' => "Disk space allocated to portfolio files", - 'blog' => "Blog Availability", - 'aboutme' => "Home Page Availability", - 'portfolio' => "Portfolio Availability", - 'prvs' => "Previous", - 'chto' => "Changed To" + 'uic' => "User Information Changed", + 'frst' => "First", + 'mddl' => "Middle", + 'lst' => "Last", + 'gen' => "Generation", + 'id' => "Student/Employee ID", + 'mail' => "Permanent E-mail", + 'disk' => "Disk space allocated to portfolio files", + 'blog' => "Blog Availability", + 'aboutme' => "Home Page Availability", + 'portfolio' => "Portfolio Availability", + 'official' => "Can Request Official Courses", + 'unofficial' => "Can Request Unofficial Courses", + 'prvs' => "Previous", + 'chto' => "Changed To" ); $r->print('

'.$lt{'uic'}.'

'. &Apache::loncommon::start_data_table(). @@ -2186,6 +2177,12 @@ sub update_user_data { $lt{'id'} $lt{'mail'} END + if ($showrequestcourses) { + foreach my $item (@requestcourses) { + $r->print(" + $lt{$item}\n"); + } + } if ($showquota) { $r->print(" $lt{'disk'}\n"); @@ -2207,6 +2204,12 @@ END $userenv{'id'} $userenv{'permanentemail'} END + if ($showrequestcourses) { + foreach my $item (@requestcourses) { + $r->print(" + $oldaccess{$item} $oldaccesstext{$item}\n"); + } + } if ($showquota) { $r->print(" $oldportfolioquota Mb $olddefquotatext \n"); @@ -2228,6 +2231,12 @@ END $env{'form.cid'} $env{'form.cpermanentemail'} END + if ($showrequestcourses) { + foreach my $item (@requestcourses) { + $r->print(" + $newaccess{$item} $newaccesstext{$item} \n"); + } + } if ($showquota) { $r->print(" $newportfolioquota Mb $newdefquotatext \n"); @@ -2266,15 +2275,18 @@ END $env{'form.ccdomain'}.'
'); } } else { # End of if ($env ... ) logic - # They did not want to change the users name, quota or tool availability, + # They did not want to change the users name, quota, tool availability, + # or ability to request creation of courses, # but we can still tell them what the name and quota and availabilities are my %lt=&Apache::lonlocal::texthash( - 'id' => "Student/Employee ID", - 'mail' => "Permanent e-mail", - 'disk' => "Disk space allocated to user's portfolio files", - 'blog' => "Blog Availability", - 'aboutme' => "Home Page Availability", - 'portfolio' => "Portfolio Availability", + 'id' => "Student/Employee ID", + 'mail' => "Permanent e-mail", + 'disk' => "Disk space allocated to user's portfolio files", + 'blog' => "Blog Availability", + 'aboutme' => "Home Page Availability", + 'portfolio' => "Portfolio Availability", + 'official' => "Can Request Official Courses", + 'unofficial' => "Can Request Unofficial Course", ); $r->print(<<"END");

$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'} @@ -2283,6 +2295,12 @@ END $r->print('
['.$lt{'mail'}.': '. $userenv{'permanentemail'}.']'); } + if ($showrequestcourses) { + foreach my $item (@requestcourses) { + $r->print('
['.$lt{$item}.': '.$newaccess{$item}.' '. + $newaccesstext{$item}.']'."\n"); + } + } if ($showtools) { foreach my $item (@usertools) { $r->print('
['.$lt{$item}.': '.$newaccess{$item}.' '. @@ -2361,6 +2379,83 @@ END $r->print(&Apache::loncommon::end_page()); } +sub tool_changes { + my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash, + $changed,$newaccess,$newaccesstext) = @_; + if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') && + (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') && + (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') && + (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) { + return; + } + foreach my $tool (@{$usertools}) { + if ($userenv->{$context.'.'.$tool} ne '') { + $oldaccess->{$tool} = &mt('custom'); + if ($userenv->{$context.'.'.$tool}) { + $oldaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $oldaccesstext->{$tool} = &mt("availability set to 'off'"); + } + $changeHash->{$context.'.'.$tool} = $userenv->{'tools.'.$tool}; + if ($env{'form.custom'.$tool} == 1) { + if ($env{'form.'.$context.'_'.$tool} ne $userenv->{'tools.'.$tool}) { + $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool}, + $changeHash,$context); + if ($changed->{$tool}) { + $newaccess->{$tool} = &mt('custom'); + if ($env{'form.'.$context.'_'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + if ($userenv->{$context.'.'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } + } + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + $newaccesstext->{$tool} = $oldaccesstext->{$tool}; + } + } else { + $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context); + if ($changed->{$tool}) { + $newaccess->{$tool} = &mt('default'); + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + if ($userenv->{$context.'.'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } + } + } + } else { + $oldaccess->{$tool} = &mt('default'); + if ($env{'form.custom'.$tool} == 1) { + $changed->{$tool} = &tool_admin($tool,$env{'form.'.$context.'_'.$tool}, + $changeHash,$context); + if ($changed->{$tool}) { + $newaccess->{$tool} = &mt('custom'); + if ($env{'form.'.$context.'_'.$tool}) { + $newaccesstext->{$tool} = &mt("availability set to 'on'"); + } else { + $newaccesstext->{$tool} = &mt("availability set to 'off'"); + } + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + } + } else { + $newaccess->{$tool} = $oldaccess->{$tool}; + } + } + } + return; +} + sub update_roles { my ($r,$context) = @_; my $now=time; @@ -2603,12 +2698,18 @@ sub update_roles { $r->print('

'.&mt('ERROR').': '.&mt('Unknown command').' '.$key.'


'); } foreach my $key (sort(keys(%disallowed))) { + $r->print('

'); if (($key eq 'none') || ($key eq 'all')) { - $r->print('

'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key)); + $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.',''.$key.'')); } else { - $r->print('

'.&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',$key)); + $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',''.$key.'')); } - $r->print(' '.&mt('Please go back and choose a different section name.').'


'); + $r->print('

' + .&mt('Please [_1]go back[_2] and choose a different section name.' + ,''; - if (exists($menu_item->{'url'})) { - $menu_html.=qq{}; - } else { - $menu_html.= - qq{}; } - $menu_html.= &mt($menu_item->{'text'}).''; - $menu_html.='

'; - } - return $menu_html; } sub restore_prev_selections { @@ -3817,6 +3952,95 @@ ENDSCRIPT ''."\n". ''."\n". ''."\n"; + } elsif ($item eq 'approval') { + my ($appon,$appoff); + my $cid = $env{'request.course.id'}; + my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'}; + if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) { + $appon = ' checked="checked" '; + $appoff = ' '; + } else { + $appon = ' '; + $appoff = ' checked="checked" '; + } + $output .= '  '; + my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1); + my (@ccs,%notified); + if ($advhash{'cc'}) { + @ccs = split(/,/,$advhash{'cc'}); + } + if ($currnotified) { + foreach my $current (split(/,/,$currnotified)) { + $notified{$current} = 1; + if (!grep(/^\Q$current\E$/,@ccs)) { + push(@ccs,$current); + } + } + } + if (@ccs) { + $output .= '
'.&mt('Personnel to be notified when a self-enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_row(); + my $count = 0; + my $numcols = 4; + foreach my $cc (sort(@ccs)) { + my $notifyon; + my ($ccuname,$ccudom) = split(/:/,$cc); + if ($notified{$cc}) { + $notifyon = ' checked="checked" '; + } + if ($count && !$count%$numcols) { + $output .= &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::start_data_table_row() + } + $output .= ''; + $count; + } + my $rem = $count%$numcols; + if ($rem) { + my $emptycols = $numcols - $rem; + for (my $i=0; $i<$emptycols; $i++) { + $output .= ' '; + } + } + $output .= &Apache::loncommon::end_data_table_row(). + &Apache::loncommon::end_data_table(); + } + } elsif ($item eq 'limit') { + my ($crslimit,$selflimit,$nolimit); + my $cid = $env{'request.course.id'}; + my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'}; + my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'}; + my $nolimit = ' checked="checked" '; + if ($currlim eq 'allstudents') { + $crslimit = ' checked="checked" '; + $selflimit = ' '; + $nolimit = ' '; + } elsif ($currlim eq 'selfenrolled') { + $crslimit = ' '; + $selflimit = ' checked="checked" '; + $nolimit = ' '; + } else { + $crslimit = ' '; + $selflimit = ' '; + } + $output .= ''. + '
 '. + (' 'x3).&mt('Maximum number allowed: '). + '
'; } $output .= &Apache::lonhtmlcommon::row_closure(1); } @@ -5024,6 +5248,74 @@ sub update_selfenroll_config { $changes{'internal.selfenroll_types'} = $selfenroll_types; } } + } elsif ($item eq 'limit') { + my $newlimit = $env{'form.selfenroll_limit'}; + my $newcap = $env{'form.selfenroll_cap'}; + $newcap =~s/\s+//g; + my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'}; + $currlimit = 'none' if ($currlimit eq ''); + my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'}; + if ($newlimit ne $currlimit) { + if ($newlimit ne 'none') { + if ($newcap =~ /^\d+$/) { + if ($newcap ne $currcap) { + $changes{'internal.selfenroll_cap'} = $newcap; + } + $changes{'internal.selfenroll_limit'} = $newlimit; + } else { + $warning{$item} = &mt('Maximum enrollment setting unchanged.').'
'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.'); + } + } elsif ($currcap ne '') { + $changes{'internal.selfenroll_cap'} = ''; + $changes{'internal.selfenroll_limit'} = $newlimit; + } + } elsif ($currlimit ne 'none') { + if ($newcap =~ /^\d+$/) { + if ($newcap ne $currcap) { + $changes{'internal.selfenroll_cap'} = $newcap; + } + } else { + $warning{$item} = &mt('Maximum enrollment setting unchanged.').'
'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.'); + } + } + } elsif ($item eq 'approval') { + my (@currnotified,@newnotified); + my $currapproval = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}; + my $currnotifylist = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'}; + if ($currnotifylist ne '') { + @currnotified = split(/,/,$currnotifylist); + @currnotified = sort(@currnotified); + } + my $newapproval = $env{'form.selfenroll_approval'}; + @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify'); + @newnotified = sort(@newnotified); + if ($newapproval ne $currapproval) { + $changes{'internal.selfenroll_approval'} = $newapproval; + if (!$newapproval) { + if ($currnotifylist ne '') { + $changes{'internal.selfenroll_notifylist'} = ''; + } + } else { + my @differences = + &compare_arrays(\@currnotified,\@newnotified); + if (@differences > 0) { + if (@newnotified > 0) { + $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified); + } else { + $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified); + } + } + } + } else { + my @differences = &compare_arrays(\@currnotified,\@newnotified); + if (@differences > 0) { + if (@newnotified > 0) { + $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified); + } else { + $changes{'internal.selfenroll_notifylist'} = ''; + } + } + } } else { my $curr_val = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item}; @@ -5035,7 +5327,7 @@ sub update_selfenroll_config { $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'
'.&mt('Group names and section names must be distinct'); } elsif ($newval eq 'all') { $newval = $curr_val; - $warning{$item} = &mt("Section for self-enrolled users unchanged, as 'all' is a reserved section name."); + $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.'); } if ($newval eq '') { $newval = 'none'; @@ -5096,6 +5388,62 @@ sub update_selfenroll_config { $title,$type,$newdate).''); } } + } elsif ($item eq 'limit') { + if ((exists($changes{'internal.selfenroll_limit'})) || + (exists($changes{'internal.selfenroll_cap'}))) { + my ($newval,$newcap); + if ($changes{'internal.selfenroll_cap'} ne '') { + $newcap = $changes{'internal.selfenroll_cap'} + } else { + $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'}; + } + if ($changes{'internal.selfenroll_limit'} eq 'none') { + $newval = &mt('No limit'); + } elsif ($changes{'internal.selfenroll_limit'} eq + 'allstudents') { + $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap); + } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') { + $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap); + } else { + my $currlimit = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_limit'}; + if ($currlimit eq 'allstudents') { + $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap); + } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') { + $newval = &mt('New self-enrollment no longer allowed when total umber of self-enrolled students reaches [_1].',$newcap); + } + } + $r->print('
  • '.&mt('"[_1]" set to "[_2]".',$title,$newval).'
  • '."\n"); + } + } elsif ($item eq 'approval') { + if ((exists($changes{'internal.selfenroll_approval'})) || + (exists($changes{'internal.selfenroll_notifylist'}))) { + my ($newval,$newnotify); + if (exists($changes{'internal.selfenroll_notifylist'})) { + $newnotify = $changes{'internal.selfenroll_notifylist'}; + } else { + $newnotify = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_notifylist'}; + } + if ($changes{'internal.selfenroll_approval'}) { + $newval = &mt('Yes'); + } elsif ($changes{'internal.selfenroll_approval'} eq '0') { + $newval = &mt('No'); + } else { + my $currapproval = + $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}; + if ($currapproval) { + $newval = &mt('Yes'); + } else { + $newval = &mt('No'); + } + } + $r->print('
  • '.&mt('"[_1]" set to "[_2]".',$title,$newval)); + if ($newnotify) { + $r->print('
    '.&mt('The following will be notified when a self-enrollment request needs approval, or has been approved: [_1].',$newnotify)); + } else { + $r->print('
    '.&mt('No notifications sent when a self-enrollment request needs approval, or has been approved.')); + } + $r->print('
  • '."\n"); + } } else { if (exists($changes{'internal.selfenroll_'.$item})) { my $newval = $changes{'internal.selfenroll_'.$item}; @@ -5149,14 +5497,33 @@ sub update_selfenroll_config { return; } +sub compare_arrays { + my ($arrayref1,$arrayref2) = @_; + my (@difference,%count); + @difference = (); + %count = (); + if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) { + foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; } + foreach my $element (keys(%count)) { + if ($count{$element} == 1) { + push(@difference,$element); + } + } + } + return @difference; +} + sub get_selfenroll_titles { - my @row = ('types','registered','enroll_dates','access_dates','section'); + my @row = ('types','registered','enroll_dates','access_dates','section', + 'approval','limit'); my %lt = &Apache::lonlocal::texthash ( types => 'Users allowed to self-enroll in this course', registered => 'Restrict self-enrollment to students officially registered for the course', enroll_dates => 'Dates self-enrollment available', access_dates => 'Course access dates assigned to self-enrolling users', section => 'Section assigned to self-enrolling users', + approval => 'Self-enrollment requests need approval?', + limit => 'Enrollment limit', ); return (\@row,\%lt); }