--- loncom/interface/loncreateuser.pm 2014/01/08 17:18:11 1.385 +++ loncom/interface/loncreateuser.pm 2016/08/11 00:09:39 1.406.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.385 2014/01/08 17:18:11 bisitz Exp $ +# $Id: loncreateuser.pm,v 1.406.2.1 2016/08/11 00:09:39 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -126,9 +126,7 @@ sub user_quotas { my ($ccuname,$ccdomain) = @_; my %lt = &Apache::lonlocal::texthash( 'usrt' => "User Tools", - 'cuqu' => "Current quota", 'cust' => "Custom quota", - 'defa' => "Default", 'chqu' => "Change quota", ); @@ -211,8 +209,8 @@ END_SCRIPT ' <td>'.$titles{$name}.'</td>'."\n". ' </tr>'."\n". &Apache::loncommon::start_data_table_row()."\n". - ' <td>'.$lt{'cuqu'}.': '. - $currquota.' MB. '. + ' <td><span class="LC_nobreak">'. + &mt('Current quota: [_1] MB',$currquota).'</span> '. $defaultinfo.'</td>'."\n". &Apache::loncommon::end_data_table_row()."\n". &Apache::loncommon::start_data_table_row()."\n". @@ -220,13 +218,14 @@ END_SCRIPT ': <label>'. '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '. 'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'. - ' />'.$lt{'defa'}.' ('.$defquota.' MB).</label> '. + ' /><span class="LC_nobreak">'. + &mt('Default ([_1] MB)',$defquota).'</span></label> '. ' <label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '. 'value="1" '.$custom_on.' onchange="javascript:quota_changes('."'custom','$name'".');"'. ' />'.$lt{'cust'}.':</label> '. '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '. 'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'. - ' /> MB</span></td>'."\n". + ' /> '.&mt('MB').'</span></td>'."\n". &Apache::loncommon::end_data_table_row()."\n"; } } @@ -1230,6 +1229,7 @@ ENDFORMINFO } } } + my $title = ''; if ($newuser) { my ($portfolioform,$domroleform); if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) || @@ -1243,10 +1243,6 @@ ENDFORMINFO } &initialize_authen_forms($ccdomain,$formname); my %lt=&Apache::lonlocal::texthash( - 'cnu' => 'Create New User', - 'ast' => 'as a student', - 'ame' => 'as a member', - 'ind' => 'in domain', 'lg' => 'Login Data', 'hs' => "Home Server", ); @@ -1260,20 +1256,24 @@ $loginscript // ]]> </script> <input type='hidden' name='makeuser' value='1' /> -<h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain ENDTITLE if ($env{'form.action'} eq 'singlestudent') { if ($crstype eq 'Community') { - $r->print(' ('.$lt{'ame'}.')'); + $title = &mt('Create New User [_1] in domain [_2] as a member', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } else { - $r->print(' ('.$lt{'ast'}.')'); + $title = &mt('Create New User [_1] in domain [_2] as a student', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } + } else { + $title = &mt('Create New User [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } - $r->print('</h2>'."\n".'<div class="LC_left_float">'); - my $personal_table = - &personal_data_display($ccuname,$ccdomain,$newuser,$context, - $inst_results{$ccuname.':'.$ccdomain}); - $r->print($personal_table); + $r->print('<h2>'.$title.'</h2>'."\n"); + $r->print('<div class="LC_left_float">'); + $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context, + $inst_results{$ccuname.':'.$ccdomain})); + # Option to disable student/employee ID conflict checking not offerred for new users. my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($ccdomain,'hserver', 'default','hide'); @@ -1359,35 +1359,23 @@ ENDAUTH } $r->print('</div><div class="LC_clear_float_footer"></div>'); } else { # user already exists - my %lt=&Apache::lonlocal::texthash( - 'cup' => "Modify existing user: ", - 'ens' => "Enroll one student: ", - 'enm' => "Enroll one member: ", - 'id' => "in domain", - ); - $r->print(<<ENDCHANGEUSER); -$start_page -$forminfo -<h2> -ENDCHANGEUSER + $r->print($start_page.$forminfo); if ($env{'form.action'} eq 'singlestudent') { if ($crstype eq 'Community') { - $r->print($lt{'enm'}); + $title = &mt('Enroll one member: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } else { - $r->print($lt{'ens'}); + $title = &mt('Enroll one student: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } } else { - $r->print($lt{'cup'}); - } - $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'. - "\n".'<div class="LC_left_float">'); - my ($personal_table,$showforceid) = - &personal_data_display($ccuname,$ccdomain,$newuser,$context, - $inst_results{$ccuname.':'.$ccdomain}); - $r->print($personal_table); - if ($showforceid) { - $r->print('<table>'.&Apache::lonuserutils::forceid_change($context).'</table>'); + $title = &mt('Modify existing user: [_1] in domain [_2]', + '"'.$ccuname.'"','"'.$ccdomain.'"'); } + $r->print('<h2>'.$title.'</h2>'."\n"); + $r->print('<div class="LC_left_float">'); + $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context, + $inst_results{$ccuname.':'.$ccdomain})); if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) { $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'. &Apache::loncommon::start_data_table()); @@ -1483,7 +1471,8 @@ ENDNOTOOLSPRIV } $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n"); } else { - $r->print('<fieldset><legend>'.&mt('Add Roles').'</legend>'); + $r->print('<div class="LC_left_float">'. + '<fieldset><legend>'.&mt('Add Roles').'</legend>'); my $addrolesdisplay = 0; if ($context eq 'domain' || $context eq 'author') { $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain); @@ -1494,27 +1483,32 @@ ENDNOTOOLSPRIV $addrolesdisplay = $add_domainroles; } $r->print(&course_level_dc($env{'request.role.domain'},$showcredits)); - $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n"); + $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'. + '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n"); } elsif ($context eq 'author') { if ($addrolesdisplay) { - $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'"'); + $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'. + '<br /><input type="button" value="'.&mt('Save').'"'); if ($newuser) { $r->print(' onclick="auth_check()" \>'."\n"); } else { $r->print('onclick="this.form.submit()" \>'."\n"); } } else { - $r->print('</fieldset><br /><a href="javascript:backPage(document.cu)">'. + $r->print('</fieldset></div>'. + '<div class="LC_clear_float_footer"></div>'. + '<br /><a href="javascript:backPage(document.cu)">'. &mt('Back to previous page').'</a>'); } } else { $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits)); - $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n"); + $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'. + '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n"); } } $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain'])); $r->print('<input type="hidden" name="currstate" value="" />'); - $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>'); + $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />'); return; } @@ -1819,7 +1813,7 @@ sub display_existing_roles { } } else { $plaintext= - &mt('Customrole [_1][_2]defined by [_3]', + &mt('Custom role [_1][_2]defined by [_3]', '"'.$croletitle.'"', '<br />', $croleuname.':'.$croleudom); @@ -1869,7 +1863,7 @@ sub display_existing_roles { } else { $contextrole = &mt('Existing Roles in this Domain'); } - $r->print('<div>'. + $r->print('<div class="LC_left_float">'. '<fieldset><legend>'.$contextrole.'</legend>'. &Apache::loncommon::start_data_table("LC_createuser"). &Apache::loncommon::start_data_table_header_row(). @@ -2169,13 +2163,37 @@ sub modify_login_block { } sub personal_data_display { - my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_; - my ($output,$showforceid,%userenv,%canmodify,%canmodify_status); + my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray, + $now,$captchaform,$emailusername,$usertype) = @_; + my ($output,%userenv,%canmodify,%canmodify_status); my @userinfo = ('firstname','middlename','lastname','generation', 'permanentemail','id'); my $rowcount = 0; my $editable = 0; - %canmodify_status = + my %textboxsize = ( + firstname => '15', + middlename => '15', + lastname => '15', + generation => '5', + permanentemail => '25', + id => '15', + ); + + my %lt=&Apache::lonlocal::texthash( + 'pd' => "Personal Data", + 'firstname' => "First Name", + 'middlename' => "Middle Name", + 'lastname' => "Last Name", + 'generation' => "Generation", + 'permanentemail' => "Permanent e-mail address", + 'id' => "Student/Employee ID", + 'lg' => "Login Data", + 'inststatus' => "Affiliation", + 'email' => 'E-mail address', + 'valid' => 'Validation', + ); + + %canmodify_status = &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain, ['inststatus'],$rolesarray); if (!$newuser) { @@ -2187,31 +2205,58 @@ sub personal_data_display { &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain, \@userinfo,$rolesarray); } elsif ($context eq 'selfcreate') { - %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo, - $inst_results,$rolesarray); + if ($newuser eq 'email') { + if (ref($emailusername) eq 'HASH') { + if (ref($emailusername->{$usertype}) eq 'HASH') { + my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info(); + @userinfo = (); + if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) { + foreach my $field (@{$infofields}) { + if ($emailusername->{$usertype}->{$field}) { + push(@userinfo,$field); + $canmodify{$field} = 1; + unless ($textboxsize{$field}) { + $textboxsize{$field} = 25; + } + unless ($lt{$field}) { + $lt{$field} = $infotitles->{$field}; + } + if ($emailusername->{$usertype}->{$field} eq 'required') { + $lt{$field} .= '<b>*</b>'; + } + } + } + } + } + } + } else { + %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo, + $inst_results,$rolesarray); + } } - my %lt=&Apache::lonlocal::texthash( - 'pd' => "Personal Data", - 'firstname' => "First Name", - 'middlename' => "Middle Name", - 'lastname' => "Last Name", - 'generation' => "Generation", - 'permanentemail' => "Permanent e-mail address", - 'id' => "Student/Employee ID", - 'lg' => "Login Data", - 'inststatus' => "Affiliation", - ); - my %textboxsize = ( - firstname => '15', - middlename => '15', - lastname => '15', - generation => '5', - permanentemail => '25', - id => '15', - ); + my $genhelp=&Apache::loncommon::help_open_topic('Generation'); $output = '<h3>'.$lt{'pd'}.'</h3>'. &Apache::lonhtmlcommon::start_pick_box(); + if (($context eq 'selfcreate') && ($newuser eq 'email')) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef, + 'LC_oddrow_value')."\n". + '<input type="text" name="uname" size="25" value="" autocomplete="off" />'; + $rowcount ++; + $output .= &Apache::lonhtmlcommon::row_closure(1); + my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />'; + my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />'; + $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>', + 'LC_pick_box_title', + 'LC_oddrow_value')."\n". + $upassone."\n". + &Apache::lonhtmlcommon::row_closure(1)."\n". + &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>', + 'LC_pick_box_title', + 'LC_oddrow_value')."\n". + $upasstwo. + &Apache::lonhtmlcommon::row_closure()."\n"; + } foreach my $item (@userinfo) { my $rowtitle = $lt{$item}; my $hiderow = 0; @@ -2225,8 +2270,8 @@ sub personal_data_display { $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item}; } else { if ($context eq 'selfcreate') { - if ($canmodify{$item}) { - $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />'; + if ($canmodify{$item}) { + $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />'; $editable ++; } else { $hiderow = 1; @@ -2237,15 +2282,15 @@ sub personal_data_display { } } else { if ($context eq 'selfcreate') { - if (($item eq 'permanentemail') && ($newuser eq 'email')) { - $row .= $ccuname; - } else { - if ($canmodify{$item}) { - $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />'; - $editable ++; + if ($canmodify{$item}) { + if ($newuser eq 'email') { + $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />'; } else { - $hiderow = 1; + $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />'; } + $editable ++; + } else { + $hiderow = 1; } } else { $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />'; @@ -2254,12 +2299,12 @@ sub personal_data_display { } else { if ($canmodify{$item}) { $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />'; + if (($item eq 'id') && (!$newuser)) { + $row .= '<br />'.&Apache::lonuserutils::forceid_change($context); + } } else { $row .= $userenv{$item}; } - if ($item eq 'id') { - $showforceid = $canmodify{$item}; - } } $row .= &Apache::lonhtmlcommon::row_closure(1); if (!$hiderow) { @@ -2294,7 +2339,7 @@ sub personal_data_display { } } if (!$hiderow) { - my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n". + my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n". $shown.&Apache::lonhtmlcommon::row_closure(1); if ($context eq 'selfcreate') { $rowcount ++; @@ -2304,12 +2349,27 @@ sub personal_data_display { } } } + if (($context eq 'selfcreate') && ($newuser eq 'email')) { + if ($captchaform) { + $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}, + 'LC_pick_box_title')."\n". + $captchaform."\n".'<br /><br />'. + &Apache::lonhtmlcommon::row_closure(1); + $rowcount ++; + } + my $submit_text = &mt('Create account'); + $output .= &Apache::lonhtmlcommon::row_title()."\n". + '<br /><input type="submit" name="createaccount" value="'. + $submit_text.'" />'. + '<input type="hidden" name="type" value="'.$usertype.'" />'. + &Apache::lonhtmlcommon::row_closure(1); + } $output .= &Apache::lonhtmlcommon::end_pick_box(); if (wantarray) { if ($context eq 'selfcreate') { return($output,$rowcount,$editable); } else { - return ($output,$showforceid); + return $output; } } else { return $output; @@ -2474,9 +2534,12 @@ sub update_user_data { if (! exists($env{'form.makeuser'})) { # Modifying an existing user, so check the validity of the name if ($uhome eq 'no_host') { - $r->print($error.&mt('Unable to determine home server for '). - $env{'form.ccuname'}.&mt(' in domain '). - $env{'form.ccdomain'}.'.'); + $r->print( + $error + .'<p class="LC_error">' + .&mt('Unable to determine home server for [_1] in domain [_2].', + '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"') + .'</p>'); return; } } @@ -2654,7 +2717,7 @@ sub update_user_data { $r->print($error.'Invalid login mode or password'.$end.$rtnlink); return; } - # Only allow authentification modification if the person has authority + # Only allow authentication modification if the person has authority if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) { $r->print('Modifying authentication: '. &Apache::lonnet::modifyuserauth( @@ -2664,7 +2727,7 @@ sub update_user_data { ($env{'form.ccuname'},$env{'form.ccdomain'})); } else { # Okay, this is a non-fatal error. - $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end); + $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end); } } $r->rflush(); # Finish display of header before time consuming actions start @@ -2966,8 +3029,8 @@ sub update_user_data { } } foreach my $name ('portfolio','author') { - $oldsettings{'quota'}{$name} = $oldquota{$name}.' MB'; - $newsettings{'quota'}{$name} = $newquota{$name}.' MB'; + $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name}); + $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name}); } if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) { my ($chgresult,$namechgresult); @@ -2981,7 +3044,7 @@ sub update_user_data { my %newenvhash; foreach my $key (keys(%changed)) { if (($key eq 'official') || ($key eq 'unofficial') - || ($key eq 'community')) { + || ($key eq 'community') || ($key eq 'textbook')) { $newenvhash{'environment.requestcourses.'.$key} = $changeHash{'requestcourses.'.$key}; if ($changeHash{'requestcourses.'.$key}) { @@ -3066,9 +3129,12 @@ sub update_user_data { &Apache::lonnet::appenv(\%newenvhash); } } else { # error occurred - $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '. - $env{'form.ccuname'}.' '.&mt('in domain').' '. - $env{'form.ccdomain'}.'</span><br />'); + $r->print( + '<p class="LC_error">' + .&mt('Unable to successfully change environment for [_1] in domain [_2].', + '"'.$env{'form.ccuname'}.'"', + '"'.$env{'form.ccdomain'}.'"') + .'</p>'); } } else { # End of if ($env ... ) logic # They did not want to change the users name, quota, tool availability, @@ -3086,9 +3152,9 @@ sub update_user_data { $rolestr = &mt('No roles'); } if ($context eq 'course') { - $contextname = &mt('course'); + $contextname = 'course'; } elsif ($context eq 'author') { - $contextname = &mt('co-author'); + $contextname = 'co-author'; } $r->print(&mt('The following fields were not updated: ').'<ul>'); my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles(); @@ -3097,9 +3163,9 @@ sub update_user_data { } $r->print('</ul>'); if (@mod_disallowed == 1) { - $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname)); + $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future $contextname roles:")); } else { - $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname)); + $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future $contextname roles:")); } my $helplink = 'javascript:helpMenu('."'display'".')'; $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />' @@ -3116,13 +3182,14 @@ sub update_user_data { if ($env{'form.action'} eq 'singlestudent') { &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context, $crstype,$showcredits,$defaultcredits); - $r->print('<p><a href="javascript:backPage(document.userupdate)">'); - if ($crstype eq 'Community') { - $r->print(&mt('Enroll Another Member')); - } else { - $r->print(&mt('Enroll Another Student')); - } - $r->print('</a></p>'); + my $linktext = ($crstype eq 'Community' ? + &mt('Enroll Another Member') : &mt('Enroll Another Student')); + $r->print( + &Apache::lonhtmlcommon::actionbox([ + '<a href="javascript:backPage(document.userupdate)">' + .($crstype eq 'Community' ? + &mt('Enroll Another Member') : &mt('Enroll Another Student')) + .'</a>'])); } else { my @rolechanges = &update_roles($r,$context,$showcredits); if (keys(%namechanged) > 0) { @@ -3558,7 +3625,7 @@ sub update_roles { my @rolechanges; my %disallowed; $r->print('<h3>'.&mt('Modifying Roles').'</h3>'); - foreach my $key (keys (%env)) { + foreach my $key (keys(%env)) { next if (! $env{$key}); next if ($key eq 'form.action'); # Revoke roles @@ -3740,7 +3807,7 @@ sub update_roles { } else { my %curr_groups = &Apache::longroup::coursegroups($one,$two); - foreach my $sec (sort {$a cmp $b} keys %sections) { + foreach my $sec (sort {$a cmp $b} keys(%sections)) { if (($sec eq 'none') || ($sec eq 'all') || exists($curr_groups{$sec})) { $disallowed{$sec} = $url; @@ -3786,7 +3853,7 @@ sub update_roles { my %curr_groups = &Apache::longroup::coursegroups($one,$two); my $emptysec = 0; - foreach my $sec (sort {$a cmp $b} keys %sections) { + foreach my $sec (sort {$a cmp $b} keys(%sections)) { $sec =~ s/\W//g; if ($sec ne '') { if (($sec eq 'none') || ($sec eq 'all') || @@ -3826,7 +3893,7 @@ sub update_roles { $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context)); } else { my $emptysec = 0; - foreach my $sec (sort {$a cmp $b} keys %sections) { + foreach my $sec (sort {$a cmp $b} keys(%sections)) { if ($sec ne '') { my $securl = $url.'/'.$sec; $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context)); @@ -3944,11 +4011,11 @@ sub enroll_single_student { } $r->print('.<br />'.$showstart.'; '.$showend); if ($startdate <= $now && !$newuser) { - $r->print('<p> '); + $r->print('<p class="LC_info">'); if ($crstype eq 'Community') { - $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.')); + $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.')); } else { - $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')); + $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.')); } $r->print('</p>'); } @@ -4114,6 +4181,7 @@ sub custom_role_editor { my $dompriv=''; my $coursepriv=''; my $body_top; + my $newrole; my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); # ------------------------------------------------------- Does this role exist? @@ -4126,6 +4194,7 @@ sub custom_role_editor { $syspriv =~ s/bre\&S//; } } else { + $newrole = 1; $body_top .= &mt('New Role').' "'; $roledef=''; } @@ -4395,6 +4464,7 @@ sub set_custom_role { bread_crumbs_component => 'User Management'}; $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args)); + my $newrole; my ($rdummy,$roledef)= &Apache::lonnet::get('roles',["rolesdef_$rolename"]); @@ -4405,6 +4475,7 @@ sub set_custom_role { } else { $r->print(&mt('New Role').' "'); $roledef=''; + $newrole = 1; } $r->print($rolename.'"</h3>'); # ------------------------------------------------------- What can be assigned? @@ -4435,25 +4506,43 @@ sub set_custom_role { $sysrole.=':'.$item; } } - $r->print('<br />Defining Role: '. - &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole)); + # Assign role; Compile and show result + my $errmsg; + my $result = + &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole); + if ($result ne 'ok') { + $errmsg = ': '.$result; + } + my $message = + &Apache::lonhtmlcommon::confirm_success( + &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1)); if ($env{'request.course.id'}) { my $url='/'.$env{'request.course.id'}; $url=~s/\_/\//g; - $r->print('<br />'.&mt('Assigning Role to Self').': '. - &Apache::lonnet::assigncustomrole($env{'user.domain'}, - $env{'user.name'}, - $url, - $env{'user.domain'}, - $env{'user.name'}, - $rolename,undef,undef,undef,$context)); + $result = + &Apache::lonnet::assigncustomrole( + $env{'user.domain'},$env{'user.name'}, + $url, + $env{'user.domain'},$env{'user.name'}, + $rolename,undef,undef,undef,$context); + if ($result ne 'ok') { + $errmsg = ': '.$result; + } + $message .= + '<br />' + .&Apache::lonhtmlcommon::confirm_success( + &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1)); } $r->print( - '<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">' - .&mt('Create or edit another custom role') - .'</a></p>' + &Apache::loncommon::confirmwrapper($message) + .'<br />' + .&Apache::lonhtmlcommon::actionbox([ + '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">' + .&mt('Create or edit another custom role') + .'</a>']) .'<form name="customresult" method="post" action="">' - .&Apache::lonhtmlcommon::echo_form_input([]).'</form>' + .&Apache::lonhtmlcommon::echo_form_input([]) + .'</form>' ); } @@ -4477,12 +4566,12 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['action','state','callingform','roletype','showrole','bulkaction','popup','phase', - 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']); + 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']); &Apache::lonhtmlcommon::clear_breadcrumbs(); my $args; my $brcrum = []; my $bread_crumbs_component = 'User Management'; - if ($env{'form.action'} ne 'dateselect') { + if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) { $brcrum = [{href=>"/adm/createuser", text=>"User Management", help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'} @@ -4649,7 +4738,8 @@ sub handler { } $args = { bread_crumbs => $brcrum, bread_crumbs_component => $bread_crumbs_component}; - $r->print(&header(undef,$args)); + my $js = &usernamerequest_javascript(); + $r->print(&header(&add_script($js),$args)); if (!exists($env{'form.state'})) { $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor', $env{'request.role.domain'})); @@ -4658,6 +4748,124 @@ sub handler { $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor', $env{'request.role.domain'})); } + } elsif (($env{'form.action'} eq 'processusernamereq') && + ($permission->{'cusr'}) && + (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) { + push(@{$brcrum}, + {href => '/adm/createuser?action=processusernamereq', + text => 'LON-CAPA account requests', + help => 'Domain_Username_Approvals'}); + $bread_crumbs_component = 'Account requests'; + if ($env{'form.state'} eq 'done') { + push(@{$brcrum}, + {href => '/adm/createuser?action=usernamereqqueue', + text => 'Result', + help => 'Domain_Username_Approvals'}); + $bread_crumbs_component = 'LON-CAPA account request result'; + } + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => $bread_crumbs_component}; + my $js = &usernamerequest_javascript(); + $r->print(&header(&add_script($js),$args)); + if (!exists($env{'form.state'})) { + $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername', + $env{'request.role.domain'})); + } elsif ($env{'form.state'} eq 'done') { + $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n"); + $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername', + $env{'request.role.domain'})); + } + } elsif (($env{'form.action'} eq 'displayuserreq') && + ($permission->{'cusr'})) { + my $dom = $env{'form.domain'}; + my $uname = $env{'form.username'}; + my $warning; + if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) { + if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) { + if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) { + my $uhome = &Apache::lonnet::homeserver($uname,$dom); + if ($uhome eq 'no_host') { + my $queue = $env{'form.queue'}; + my $reqkey = &escape($uname).'_'.$queue; + my $namespace = 'usernamequeue'; + my $domconfig = &Apache::lonnet::get_domainconfiguser($dom); + my %queued = + &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig); + unless ($queued{$reqkey}) { + $warning = &mt('No information was found for this LON-CAPA account request.'); + } + } else { + $warning = &mt('A LON-CAPA account already exists for the requested username and domain.'); + } + } else { + $warning = &mt('LON-CAPA account request status check is for an invalid username.'); + } + } else { + $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.'); + } + } else { + $warning = &mt('LON-CAPA account request status check is for an invalid domain.'); + } + my $args = { only_body => 1 }; + $r->print(&header(undef,$args). + '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>'); + if ($warning ne '') { + $r->print('<div class="LC_warning">'.$warning.'</div>'); + } else { + my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info(); + my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom); + my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom); + if (ref($domconfig{'usercreation'}) eq 'HASH') { + if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { + if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') { + my %info = + &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser); + if (ref($info{$uname}) eq 'HASH') { + my $usertype = $info{$uname}{'inststatus'}; + unless ($usertype) { + $usertype = 'default'; + } + if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') { + if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) { + $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box()); + my ($num,$count,$showstatus); + $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}})); + unless ($usertype eq 'default') { + my ($othertitle,$usertypes,$types) = + &Apache::loncommon::sorted_inst_types($dom); + if (ref($usertypes) eq 'HASH') { + if ($usertypes->{$usertype}) { + $showstatus = $usertypes->{$usertype}; + $count ++; + } + } + } + foreach my $field (@{$infofields}) { + next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field}); + next unless ($infotitles->{$field}); + $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}). + $info{$uname}{$field}); + $num ++; + if ($count == $num) { + $r->print(&Apache::lonhtmlcommon::row_closure(1)); + } else { + $r->print(&Apache::lonhtmlcommon::row_closure()); + } + } + if ($showstatus) { + $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')). + $showstatus. + &Apache::lonhtmlcommon::row_closure(1)); + } + $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>'); + } + } + } + } + } + } + $r->print(&close_popup_form()); + } } elsif (($env{'form.action'} eq 'listusers') && ($permission->{'view'} || $permission->{'cusr'})) { if ($env{'form.phase'} eq 'bulkchange') { @@ -4763,25 +4971,49 @@ sub handler { '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>'); } } elsif ($env{'form.action'} eq 'selfenroll') { - push(@{$brcrum}, - {href => '/adm/createuser?action=selfenroll', - text => "Configure Self-enrollment", - help => 'Course_Self_Enrollment'}); - if (!exists($env{'form.state'})) { - $args = { bread_crumbs => $brcrum, - bread_crumbs_component => 'Configure Self-enrollment'}; - $r->print(&header(undef,$args)); - $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n"); - &print_selfenroll_menu($r,$context,$permission); - } elsif ($env{'form.state'} eq 'done') { - push (@{$brcrum}, - {href=>'/adm/createuser?action=selfenroll', - text=>"Result"}); - $args = { bread_crumbs => $brcrum, - bread_crumbs_component => 'Self-enrollment result'}; - $r->print(&header(undef,$args)); - $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n"); - &update_selfenroll_config($r,$context,$permission); + if ($permission->{selfenrolladmin}) { + my $cid = $env{'request.course.id'}; + my $cdom = $env{'course.'.$cid.'.domain'}; + my $cnum = $env{'course.'.$cid.'.num'}; + my %currsettings = ( + selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'}, + selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'}, + selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'}, + selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'}, + selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'}, + selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'}, + selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'}, + selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'}, + selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'}, + selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'}, + selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'}, + default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'}, + default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'}, + uniquecode => $env{'course.'.$cid.'.internal.uniquecode'}, + ); + push(@{$brcrum}, + {href => '/adm/createuser?action=selfenroll', + text => "Configure Self-enrollment", + help => 'Course_Self_Enrollment'}); + if (!exists($env{'form.state'})) { + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => 'Configure Self-enrollment'}; + $r->print(&header(undef,$args)); + $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n"); + &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings); + } elsif ($env{'form.state'} eq 'done') { + push (@{$brcrum}, + {href=>'/adm/createuser?action=selfenroll', + text=>"Result"}); + $args = { bread_crumbs => $brcrum, + bread_crumbs_component => 'Self-enrollment result'}; + $r->print(&header(undef,$args)); + $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n"); + &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings); + } + } else { + $r->print(&header(undef,{'no_nav_bar' => 1}). + '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>'); } } elsif ($env{'form.action'} eq 'selfenrollqueue') { push(@{$brcrum}, @@ -4857,6 +5089,32 @@ sub add_script { .'</script>'."\n"; } +sub usernamerequest_javascript { + my $js = <<ENDJS; + +function openusernamereqdisplay(dom,uname,queue) { + var url = '/adm/createuser?action=displayuserreq'; + url += '&domain='+dom+'&username='+uname+'&queue='+queue; + var title = 'Account_Request_Browser'; + var options = 'scrollbars=1,resizable=1,menubar=0'; + options += ',width=700,height=600'; + var stdeditbrowser = open(url,title,options,'1'); + stdeditbrowser.focus(); + return; +} + +ENDJS +} + +sub close_popup_form { + my $close= &mt('Close Window'); + return << "END"; +<p><form name="displayreq" action="" method="post"> +<input type="button" name="closeme" value="$close" onclick="javascript:self.close();" /> +</form></p> +END +} + sub verify_user_display { my ($context) = @_; my %lt = &Apache::lonlocal::texthash ( @@ -5110,6 +5368,14 @@ sub print_main_menu { linktitle => 'Approve or reject author role requests', }, { + linktext => 'LON-CAPA Account Requests', + icon => 'list-add.png', + #help => 'Domain_Username_Approvals', + url => '/adm/createuser?action=processusernamereq', + permission => $permission->{'cusr'}, + linktitle => 'Approve or reject LON-CAPA account requests', + }, + { linktext => 'Change Log', icon => 'document-properties.png', #help => 'Course_User_Logs', @@ -5197,12 +5463,12 @@ sub print_main_menu { ); if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) { push(@{ $menu[2]->{items} }, - { + { linktext => 'Enrollment Requests', icon => 'selfenrl-queue.png', #help => 'Course_Approve_Selfenroll', url => '/adm/createuser?action=selfenrollqueue', - permission => $permission->{'cusr'}, + permission => $permission->{'selfenrolladmin'}, linktitle =>'Approve or reject enrollment requests.', }, ); @@ -5228,7 +5494,7 @@ sub print_main_menu { icon => 'self_enroll.png', #help => 'Course_Self_Enrollment', url => '/adm/createuser?action=selfenroll', - permission => $permission->{'cusr'}, + permission => $permission->{'selfenrolladmin'}, linktitle => 'Configure user self-enrollment.', }, ); @@ -5265,11 +5531,11 @@ sub restore_prev_selections { } sub print_selfenroll_menu { - my ($r,$context,$permission) = @_; + my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional) = @_; my $crstype = &Apache::loncommon::course_type(); - my $formname = 'enrollstudent'; + my $formname = 'selfenroll'; my $nolink = 1; - my ($row,$lt) = &get_selfenroll_titles(); + my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles(); my $groupslist = &Apache::lonuserutils::get_groupslist(); my $setsec_js = &Apache::lonuserutils::setsections_javascript($formname,$groupslist); @@ -5278,6 +5544,7 @@ sub print_selfenroll_menu { butn => 'but no user types have been checked.', wilf => "Please uncheck 'activate' or check at least one type.", ); + &js_escape(\%alerts); my $selfenroll_js = <<"ENDSCRIPT"; function update_types(caller,num) { var delidx = getIndexByName('selfenroll_delete'); @@ -5388,7 +5655,7 @@ function validate_types(form) { } } else { if (document.$formname.selfenroll_activate.checked) { - var num = document.enrollstudent.selfenroll_activate.value; + var num = document.$formname.selfenroll_activate.value; countfail = check_types(num,countfail,needaction) } } @@ -5435,6 +5702,26 @@ function check_types(num,countfail,needa return countfail; } +function toggleNotify() { + var selfenrollApproval = 0; + if (document.$formname.selfenroll_approval.length) { + for (var i=0; i<document.$formname.selfenroll_approval.length; i++) { + if (document.$formname.selfenroll_approval[i].checked) { + selfenrollApproval = document.$formname.selfenroll_approval[i].value; + break; + } + } + } + if (document.getElementById('notified')) { + if (selfenrollApproval == 0) { + document.getElementById('notified').style.display='none'; + } else { + document.getElementById('notified').style.display='block'; + } + } + return; +} + function getIndexByName(item) { for (var i=0;i<document.$formname.elements.length;i++) { if (document.$formname.elements[i].name == item) { @@ -5444,8 +5731,6 @@ function getIndexByName(item) { return -1; } ENDSCRIPT - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; my $output = '<script type="text/javascript">'."\n". '// <![CDATA['."\n". @@ -5453,25 +5738,71 @@ ENDSCRIPT '// ]]>'."\n". '</script>'."\n". '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n"; - my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum); - if (ref($visactions) eq 'HASH') { - if ($visible) { - $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>'; + + my $visactions = &cat_visibility(); + my ($cathash,%cattype); + my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom); + if (ref($domconfig{'coursecategories'}) eq 'HASH') { + $cathash = $domconfig{'coursecategories'}{'cats'}; + $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'}; + $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'}; + if ($cattype{'auth'} eq '') { + $cattype{'auth'} = 'std'; + } + if ($cattype{'unauth'} eq '') { + $cattype{'unauth'} = 'std'; + } + } else { + $cathash = {}; + $cattype{'auth'} = 'std'; + $cattype{'unauth'} = 'std'; + } + if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) { + $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}. + '<br />'. + '<br />'.$visactions->{'take'}.'<ul>'. + '<li>'.$visactions->{'dc_chgconf'}.'</li>'. + '</ul>'); + } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) { + if ($currsettings->{'uniquecode'}) { + $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>'); } else { - $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>' - .$visactions->{'yous'}. - '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'}; - if (ref($vismsgs) eq 'ARRAY') { - $output .= '<br />'.$visactions->{'make'}.'<ul>'; - foreach my $item (@{$vismsgs}) { - $output .= '<li>'.$visactions->{$item}.'</li>'; + $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}. + '<br />'. + '<br />'.$visactions->{'take'}.'<ul>'. + '<li>'.$visactions->{'dc_setcode'}.'</li>'. + '</ul><br />'); + } + } else { + my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig); + if (ref($visactions) eq 'HASH') { + if ($visible) { + $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>'; + } else { + $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>' + .$visactions->{'yous'}. + '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'}; + if (ref($vismsgs) eq 'ARRAY') { + $output .= '<br />'.$visactions->{'make'}.'<ul>'; + foreach my $item (@{$vismsgs}) { + $output .= '<li>'.$visactions->{$item}.'</li>'; + } + $output .= '</ul>'; } - $output .= '</ul>'; + $output .= '</p>'; } - $output .= '</p>'; } } - $output .= '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n". + my $actionhref = '/adm/createuser'; + if ($context eq 'domain') { + $actionhref = '/adm/modifycourse'; + } + + my %noedit; + unless ($context eq 'domain') { + %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row); + } + $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n". &Apache::lonhtmlcommon::start_pick_box(); if (ref($row) eq 'ARRAY') { foreach my $item (@{$row}) { @@ -5481,7 +5812,41 @@ ENDSCRIPT } $output .= &Apache::lonhtmlcommon::row_title($title); if ($item eq 'types') { - my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'}; + my $curr_types; + if (ref($currsettings) eq 'HASH') { + $curr_types = $currsettings->{'selfenroll_types'}; + } + if ($noedit{$item}) { + if ($curr_types eq '*') { + $output .= &mt('Any user in any domain'); + } else { + my @entries = split(/;/,$curr_types); + if (@entries > 0) { + $output .= '<ul>'; + foreach my $entry (@entries) { + my ($currdom,$typestr) = split(/:/,$entry); + next if ($typestr eq ''); + my $domdesc = &Apache::lonnet::domain($currdom); + my @currinsttypes = split(',',$typestr); + my ($othertitle,$usertypes,$types) = + &Apache::loncommon::sorted_inst_types($currdom); + if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) { + $usertypes->{'any'} = &mt('any user'); + if (keys(%{$usertypes}) > 0) { + $usertypes->{'other'} = &mt('other users'); + } + my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes; + $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>'; + } + } + $output .= '</ul>'; + } else { + $output .= &mt('None'); + } + } + $output .= '<br />'.&mt('(Set by Domain Coordinator)'); + next; + } my $showdomdesc = 1; my $includeempty = 1; my $num = 0; @@ -5546,7 +5911,20 @@ ENDSCRIPT .&Apache::loncommon::end_data_table(); } elsif ($item eq 'registered') { my ($regon,$regoff); - if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) { + my $registered; + if (ref($currsettings) eq 'HASH') { + $registered = $currsettings->{'selfenroll_registered'}; + } + if ($noedit{$item}) { + if ($registered) { + $output .= &mt('Must be registered in course'); + } else { + $output .= &mt('No requirement'); + } + $output .= '<br />'.&mt('(Set by Domain Coordinator)'); + next; + } + if ($registered) { $regon = ' checked="checked" '; $regoff = ' '; } else { @@ -5559,13 +5937,22 @@ ENDSCRIPT '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.'/>'. &mt('No').'</label>'; } elsif ($item eq 'enroll_dates') { - my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_date'}; - my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_date'}; - if ($starttime eq '') { - $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'}; - } - if ($endtime eq '') { - $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'}; + my ($starttime,$endtime); + if (ref($currsettings) eq 'HASH') { + $starttime = $currsettings->{'selfenroll_start_date'}; + $endtime = $currsettings->{'selfenroll_end_date'}; + if ($starttime eq '') { + $starttime = $currsettings->{'default_enrollment_start_date'}; + } + if ($endtime eq '') { + $endtime = $currsettings->{'default_enrollment_end_date'}; + } + } + if ($noedit{$item}) { + $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime), + &Apache::lonlocal::locallocaltime($endtime)); + $output .= '<br />'.&mt('(Set by Domain Coordinator)'); + next; } my $startform = &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime, @@ -5575,13 +5962,22 @@ ENDSCRIPT undef,undef,undef,undef,undef,undef,undef,$nolink); $output .= &selfenroll_date_forms($startform,$endform); } elsif ($item eq 'access_dates') { - my $starttime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_start_access'}; - my $endtime = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_end_access'}; - if ($starttime eq '') { - $starttime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'}; - } - if ($endtime eq '') { - $endtime = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'}; + my ($starttime,$endtime); + if (ref($currsettings) eq 'HASH') { + $starttime = $currsettings->{'selfenroll_start_access'}; + $endtime = $currsettings->{'selfenroll_end_access'}; + if ($starttime eq '') { + $starttime = $currsettings->{'default_enrollment_start_date'}; + } + if ($endtime eq '') { + $endtime = $currsettings->{'default_enrollment_end_date'}; + } + } + if ($noedit{$item}) { + $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime), + &Apache::lonlocal::locallocaltime($endtime)); + $output .= '<br />'.&mt('(Set by Domain Coordinator)'); + next; } my $startform = &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime, @@ -5591,7 +5987,10 @@ ENDSCRIPT undef,undef,undef,undef,undef,undef,undef,$nolink); $output .= &selfenroll_date_forms($startform,$endform); } elsif ($item eq 'section') { - my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'}; + my $currsec; + if (ref($currsettings) eq 'HASH') { + $currsec = $currsettings->{'selfenroll_section'}; + } my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); my $newsecval; if ($currsec ne 'none' && $currsec ne '') { @@ -5599,6 +5998,15 @@ ENDSCRIPT $newsecval = $currsec; } } + if ($noedit{$item}) { + if ($currsec ne '') { + $output .= $currsec; + } else { + $output .= &mt('No specific section'); + } + $output .= '<br />'.&mt('(Set by Domain Coordinator)'); + next; + } my $sections_select = &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec); $output .= '<table class="LC_createuser">'."\n". @@ -5608,24 +6016,29 @@ ENDSCRIPT &mt('New section').'<br />'."\n". '<input type="text" name="newsec" size="15" value="'.$newsecval.'" />'."\n". '<input type="hidden" name="sections" value="" />'."\n". - '<input type="hidden" name="state" value="done" />'."\n". '</td></tr></table>'."\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" '; + my ($currnotified,$currapproval,%appchecked); + my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs(); + if (ref($currsettings) eq 'HASH') { + $currnotified = $currsettings->{'selfenroll_notifylist'}; + $currapproval = $currsettings->{'selfenroll_approval'}; + } + if ($currapproval !~ /^[012]$/) { + $currapproval = 0; + } + if ($noedit{$item}) { + $output .= $selfdescs{'approval'}{$currapproval}. + '<br />'.&mt('(Set by Domain Coordinator)'); + next; + } + $appchecked{$currapproval} = ' checked="checked"'; + for my $i (0..2) { + $output .= '<label>'. + '<input type="radio" name="selfenroll_approval" value="'.$i.'"'. + $appchecked{$i}.' onclick="toggleNotify();" />'.$selfdescs{'approval'}{$i}. + '</label>'.(' 'x2); } - $output .= '<label>'. - '<input type="radio" name="selfenroll_approval" value="1"'.$appon.'/>'. - &mt('Yes').'</label> <label>'. - '<input type="radio" name="selfenroll_approval" value="0"'.$appoff.'/>'. - &mt('No').'</label>'; my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1); my (@ccs,%notified); my $ccrole = 'cc'; @@ -5644,7 +6057,13 @@ ENDSCRIPT } } if (@ccs) { - $output .= '<br />'.&mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table(). + my $style; + unless ($currapproval) { + $style = ' style="display: none;"'; + } + $output .= '<br /><div id="notified"'.$style.'>'. + &mt('Personnel to be notified when an 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; @@ -5672,14 +6091,29 @@ ENDSCRIPT } } $output .= &Apache::loncommon::end_data_table_row(). - &Apache::loncommon::end_data_table(); + &Apache::loncommon::end_data_table(). + '</div>'; } } 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'}; - $nolimit = ' checked="checked" '; + my ($crslimit,$selflimit,$nolimit,$currlim,$currcap); + if (ref($currsettings) eq 'HASH') { + $currlim = $currsettings->{'selfenroll_limit'}; + $currcap = $currsettings->{'selfenroll_cap'}; + } + if ($noedit{$item}) { + if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) { + if ($currlim eq 'allstudents') { + $output .= &mt('Limit by total students'); + } elsif ($currlim eq 'selfenrolled') { + $output .= &mt('Limit by total self-enrolled students'); + } + $output .= ' '.&mt('Maximum: [_1]',$currcap). + '<br />'.&mt('(Set by Domain Coordinator)'); + } else { + $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)'); + } + next; + } if ($currlim eq 'allstudents') { $crslimit = ' checked="checked" '; $selflimit = ' '; @@ -5691,6 +6125,7 @@ ENDSCRIPT } else { $crslimit = ' '; $selflimit = ' '; + $nolimit = ' checked="checked" '; } $output .= '<table><tr><td><label>'. '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.'/>'. @@ -5710,42 +6145,51 @@ ENDSCRIPT $output .= &Apache::lonhtmlcommon::end_pick_box(). '<br /><input type="button" name="selfenrollconf" value="' .&mt('Save').'" onclick="validate_types(this.form);" />' - .'<input type="hidden" name="action" value="selfenroll" /></form>'; + .'<input type="hidden" name="action" value="selfenroll" />' + .'<input type="hidden" name="state" value="done" />'."\n". + $additional.'</form>'; $r->print($output); return; } -sub visible_in_cat { - my ($cdom,$cnum) = @_; - my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom); - my ($cathash,%settable,@vismsgs,$cansetvis); - my %visactions = &Apache::lonlocal::texthash( - vis => 'Your course/community currently appears in the Course/Community Catalog for this domain.', - gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.', - miss => 'Your course/community does not currently appear in the Course/Community Catalog for this domain.', - yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.', - coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.', - make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:', - take => 'Take the following action to ensure the course appears in the Catalog:', - dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.', - dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".', - dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).', - dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.', - dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.', - dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain', - dc_addcat => 'Ask a domain coordinator to assign a category to the course.', - ); - $visactions{'unhide'} = &mt('Use [_1]Categorize course[_2] to change the "Exclude from course catalog" setting.','<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"'); - $visactions{'chgcat'} = &mt('Use [_1]Categorize course[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"'); - $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"'); - if (ref($domconf{'coursecategories'}) eq 'HASH') { - if ($domconf{'coursecategories'}{'togglecats'} eq 'crs') { +sub get_noedit_fields { + my ($cdom,$cnum,$crstype,$row) = @_; + my %noedit; + if (ref($row) eq 'ARRAY') { + my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook', + 'internal.selfenrollmgrdc', + 'internal.selfenrollmgrcc'],$cdom,$cnum); + my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings); + my (%specific_managebydc,%specific_managebycc,%default_managebydc); + map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'})); + map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'})); + my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom); + map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'})); + + foreach my $item (@{$row}) { + next if ($specific_managebycc{$item}); + if (($specific_managebydc{$item}) || ($default_managebydc{$item})) { + $noedit{$item} = 1; + } + } + } + return %noedit; +} + +sub visible_in_stdcat { + my ($cdom,$cnum,$domconf) = @_; + my ($cathash,%settable,@vismsgs,$cansetvis,$visible); + unless (ref($domconf) eq 'HASH') { + return ($visible,$cansetvis,\@vismsgs); + } + if (ref($domconf->{'coursecategories'}) eq 'HASH') { + if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') { $settable{'togglecats'} = 1; } - if ($domconf{'coursecategories'}{'categorize'} eq 'crs') { + if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') { $settable{'categorize'} = 1; } - $cathash = $domconf{'coursecategories'}{'cats'}; + $cathash = $domconf->{'coursecategories'}{'cats'}; } if ($settable{'togglecats'} && $settable{'categorize'}) { $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.'); @@ -5760,10 +6204,10 @@ sub visible_in_cat { my %currsettings = &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'], $cdom,$cnum); - my $visible = 0; + $visible = 0; if ($currsettings{'internal.coursecode'} ne '') { - if (ref($domconf{'coursecategories'}) eq 'HASH') { - $cathash = $domconf{'coursecategories'}{'cats'}; + if (ref($domconf->{'coursecategories'}) eq 'HASH') { + $cathash = $domconf->{'coursecategories'}{'cats'}; if (ref($cathash) eq 'HASH') { if ($cathash->{'instcode::0'} eq '') { push(@vismsgs,'dc_addinst'); @@ -5787,8 +6231,8 @@ sub visible_in_cat { } if ($currsettings{'categories'} ne '') { my $cathash; - if (ref($domconf{'coursecategories'}) eq 'HASH') { - $cathash = $domconf{'coursecategories'}{'cats'}; + if (ref($domconf->{'coursecategories'}) eq 'HASH') { + $cathash = $domconf->{'coursecategories'}{'cats'}; if (ref($cathash) eq 'HASH') { if (keys(%{$cathash}) == 0) { push(@vismsgs,'dc_catalog'); @@ -5834,7 +6278,33 @@ sub visible_in_cat { unshift(@vismsgs,'dc_unhide') } } - return ($visible,$cansetvis,\@vismsgs,\%visactions); + return ($visible,$cansetvis,\@vismsgs); +} + +sub cat_visibility { + my %visactions = &Apache::lonlocal::texthash( + vis => 'This course/community currently appears in the Course/Community Catalog for this domain.', + gen => 'Courses can be both self-cataloging, based on an institutional code (e.g., fs08phy231), or can be assigned categories from a hierarchy defined for the domain.', + miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.', + none => 'Display of a course catalog is disabled for this domain.', + yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.', + coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.', + make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:', + take => 'Take the following action to ensure the course appears in the Catalog:', + dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.', + dc_setcode => 'Ask a domain coordinator to assign a six character code to the course', + dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.', + dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".', + dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).', + dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.', + dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.', + dc_chgcat => 'Ask a domain coordinator to change the category assigned to the course, as the one currently assigned is no longer used in the domain', + dc_addcat => 'Ask a domain coordinator to assign a category to the course.', + ); + $visactions{'unhide'} = &mt('Use [_1]Categorize course[_2] to change the "Exclude from course catalog" setting.','<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"'); + $visactions{'chgcat'} = &mt('Use [_1]Categorize course[_2] to change the category assigned to the course, as the one currently assigned is no longer used in the domain.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"'); + $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"'); + return \%visactions; } sub new_selfenroll_dom_row { @@ -6847,13 +7317,13 @@ sub course_level_table { ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) { $table .= &course_level_row($protectedcourse,$role,$area,$domain, $plrole,\%sections_count,\%lt, - $defaultcredits,$crstype); + $showcredits,$defaultcredits,$crstype); } elsif ($env{'request.course.sec'} ne '') { if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'. $env{'request.course.sec'})) { $table .= &course_level_row($protectedcourse,$role,$area,$domain, $plrole,\%sections_count,\%lt, - $defaultcredits,$crstype); + $showcredits,$defaultcredits,$crstype); } } } @@ -6862,7 +7332,8 @@ sub course_level_table { next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/); my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust; $table .= &course_level_row($protectedcourse,$role,$area,$domain, - $cust,\%sections_count,\%lt); + $cust,\%sections_count,\%lt, + $showcredits,$defaultcredits,$crstype); } } } @@ -6876,7 +7347,11 @@ sub course_level_table { &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n". -'<th>'.$lt{'ext'}.'</th><th>'.$lt{'crd'}.'</th>'."\n". +'<th>'.$lt{'ext'}.'</th><th>'."\n"; + if ($showcredits) { + $result .= $lt{'crd'}.'</th>'; + } + $result .= '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n". '<th>'.$lt{'end'}.'</th>'. &Apache::loncommon::end_data_table_header_row(). @@ -6887,14 +7362,14 @@ $table. sub course_level_row { my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count, - $lt,$defaultcredits,$crstype) = @_; + $lt,$showcredits,$defaultcredits,$crstype) = @_; my $creditem; my $row = &Apache::loncommon::start_data_table_row(). ' <td><input type="checkbox" name="act_'. $protectedcourse.'_'.$role.'" /></td>'."\n". ' <td>'.$plrole.'</td>'."\n". ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n"; - if (($role eq 'st') && ($crstype eq 'Course')) { + if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) { $row .= '<td><input type="text" name="credits_'.$protectedcourse.'_'. $role.'" size="3" value="'.$defaultcredits.'" /></td>'; @@ -6971,28 +7446,29 @@ sub course_level_dc { &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(). '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n". - '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n". - '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n". + '<th>'.$lt{'grs'}.'</th>'."\n"; + $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits); + $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n". &Apache::loncommon::end_data_table_header_row(); my $otheritems = &Apache::loncommon::start_data_table_row()."\n". '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'. $courseform.(' ' x4).'</span></td>'."\n". - '<td valign><br /><select name="role">'."\n"; + '<td valign="top"><br /><select name="role">'."\n"; foreach my $role (@roles) { my $plrole=&Apache::lonnet::plaintext($role); - $otheritems .= ' <option value="'.$role.'">'.$plrole; + $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>'; } - if ( keys %customroles > 0) { - foreach my $cust (sort keys %customroles) { + if ( keys(%customroles) > 0) { + foreach my $cust (sort(keys(%customroles))) { my $custrole='cr_cr_'.$env{'user.domain'}. '_'.$env{'user.name'}.'_'.$cust; - $otheritems .= ' <option value="'.$custrole.'">'.$cust; + $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>'; } } $otheritems .= '</select></td><td>'. '<table border="0" cellspacing="0" cellpadding="0">'. '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'. - ' <option value=""><--'.&mt('Pick course first').'</select></td>'. + ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'. '<td> </td>'. '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'. '<input type="text" name="newsec" value="" />'. @@ -7002,7 +7478,7 @@ sub course_level_dc { '</tr></table></td>'."\n"; if ($showcredits) { $otheritems .= '<td><br />'."\n". - '<input type="text" size="3" name="credits" value="" />'."\n"; + '<input type="text" size="3" name="credits" value="" /></td>'."\n"; } $otheritems .= <<ENDTIMEENTRY; <td><br /><input type="hidden" name="start" value='' /> @@ -7018,19 +7494,23 @@ ENDTIMEENTRY } sub update_selfenroll_config { - my ($r,$context,$permission) = @_; - my ($row,$lt) = &get_selfenroll_titles(); - my %curr_groups = &Apache::longroup::coursegroups(); + my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_; + return unless (ref($currsettings) eq 'HASH'); + my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles(); + my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum); my (%changes,%warning); - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; my $curr_types; + my %noedit; + unless ($context eq 'domain') { + %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row); + } if (ref($row) eq 'ARRAY') { foreach my $item (@{$row}) { + next if ($noedit{$item}); if ($item eq 'enroll_dates') { my (%currenrolldate,%newenrolldate); foreach my $type ('start','end') { - $currenrolldate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_date'}; + $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'}; $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date'); if ($newenrolldate{$type} ne $currenrolldate{$type}) { $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type}; @@ -7039,15 +7519,14 @@ sub update_selfenroll_config { } elsif ($item eq 'access_dates') { my (%currdate,%newdate); foreach my $type ('start','end') { - $currdate{$type} = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$type.'_access'}; + $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'}; $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access'); if ($newdate{$type} ne $currdate{$type}) { $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type}; } } } elsif ($item eq 'types') { - $curr_types = - $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item}; + $curr_types = $currsettings->{'selfenroll_'.$item}; if ($env{'form.selfenroll_all'}) { if ($curr_types ne '*') { $changes{'internal.selfenroll_types'} = '*'; @@ -7116,9 +7595,9 @@ sub update_selfenroll_config { 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'}; + my $currlimit = $currsettings->{'selfenroll_limit'}; $currlimit = 'none' if ($currlimit eq ''); - my $currcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'}; + my $currcap = $currsettings->{'selfenroll_cap'}; if ($newlimit ne $currlimit) { if ($newlimit ne 'none') { if ($newcap =~ /^\d+$/) { @@ -7127,7 +7606,8 @@ sub update_selfenroll_config { } $changes{'internal.selfenroll_limit'} = $newlimit; } else { - $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.'); + $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'. + &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.'); } } elsif ($currcap ne '') { $changes{'internal.selfenroll_cap'} = ''; @@ -7139,13 +7619,14 @@ sub update_selfenroll_config { $changes{'internal.selfenroll_cap'} = $newcap; } } else { - $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.&mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.'); + $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'. + &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'}; + my $currapproval = $currsettings->{'selfenroll_approval'}; + my $currnotifylist = $currsettings->{'selfenroll_notifylist'}; if ($currnotifylist ne '') { @currnotified = split(/,/,$currnotifylist); @currnotified = sort(@currnotified); @@ -7181,14 +7662,14 @@ sub update_selfenroll_config { } } } else { - my $curr_val = - $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item}; + my $curr_val = $currsettings->{'selfenroll_'.$item}; my $newval = $env{'form.selfenroll_'.$item}; if ($item eq 'section') { $newval = $env{'form.sections'}; if (defined($curr_groups{$newval})) { $newval = $curr_val; - $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.&mt('Group names and section names must be distinct'); + $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'. + &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.'); @@ -7218,11 +7699,10 @@ sub update_selfenroll_config { my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.', $cnum,undef,undef,'Course'); my $chome = &Apache::lonnet::homeserver($cnum,$cdom); - if (ref($crsinfo{$env{'request.course.id'}}) eq 'HASH') { + if (ref($crsinfo{$cid}) eq 'HASH') { foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') { if (exists($changes{'internal.'.$item})) { - $crsinfo{$env{'request.course.id'}}{$item} = - $changes{'internal.'.$item}; + $crsinfo{$cid}{$item} = $changes{'internal.'.$item}; } } my $crsputresult = @@ -7259,7 +7739,7 @@ sub update_selfenroll_config { if ($changes{'internal.selfenroll_cap'} ne '') { $newcap = $changes{'internal.selfenroll_cap'} } else { - $newcap = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_cap'}; + $newcap = $currsettings->{'selfenroll_cap'}; } if ($changes{'internal.selfenroll_limit'} eq 'none') { $newval = &mt('No limit'); @@ -7269,7 +7749,7 @@ sub update_selfenroll_config { } 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'}; + my $currlimit = $currsettings->{'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') { @@ -7281,24 +7761,24 @@ sub update_selfenroll_config { } elsif ($item eq 'approval') { if ((exists($changes{'internal.selfenroll_approval'})) || (exists($changes{'internal.selfenroll_notifylist'}))) { + my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs(); 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'}; + $newnotify = $currsettings->{'selfenroll_notifylist'}; } - if ($changes{'internal.selfenroll_approval'}) { - $newval = &mt('Yes'); - } elsif ($changes{'internal.selfenroll_approval'} eq '0') { - $newval = &mt('No'); + if (exists($changes{'internal.selfenroll_approval'})) { + if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) { + $changes{'internal.selfenroll_approval'} = '0'; + } + $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}}; } else { - my $currapproval = - $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}; - if ($currapproval) { - $newval = &mt('Yes'); - } else { - $newval = &mt('No'); + my $currapproval = $currsettings->{'selfenroll_approval'}; + if ($currapproval !~ /^[012]$/) { + $currapproval = 0; } + $newval = $selfdescs{'approval'}{$currapproval}; } $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval)); if ($newnotify) { @@ -7329,13 +7809,16 @@ sub update_selfenroll_config { } } $r->print('</ul>'); - my %newenvhash; - foreach my $key (keys(%changes)) { - $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $changes{$key}; + if ($env{'course.'.$cid.'.description'} ne '') { + my %newenvhash; + foreach my $key (keys(%changes)) { + $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key}; + } + &Apache::lonnet::appenv(\%newenvhash); } - &Apache::lonnet::appenv(\%newenvhash); } else { - $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.&mt('The error was: [_1].',$putresult)); + $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'. + &mt('The error was: [_1].',$putresult)); } } else { $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.')); @@ -7343,39 +7826,54 @@ sub update_selfenroll_config { } else { $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.')); } - my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum); - if (ref($visactions) eq 'HASH') { - if (!$visible) { + my $visactions = &cat_visibility(); + my ($cathash,%cattype); + my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom); + if (ref($domconfig{'coursecategories'}) eq 'HASH') { + $cathash = $domconfig{'coursecategories'}{'cats'}; + $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'}; + $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'}; + } else { + $cathash = {}; + $cattype{'auth'} = 'std'; + $cattype{'unauth'} = 'std'; + } + if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) { + $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}. + '<br />'. + '<br />'.$visactions->{'take'}.'<ul>'. + '<li>'.$visactions->{'dc_chgconf'}.'</li>'. + '</ul>'); + } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) { + if ($currsettings->{'uniquecode'}) { + $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>'); + } else { $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}. - '<br />'); - if (ref($vismsgs) eq 'ARRAY') { - $r->print('<br />'.$visactions->{'take'}.'<ul>'); - foreach my $item (@{$vismsgs}) { - $r->print('<li>'.$visactions->{$item}.'</li>'); + '<br />'. + '<br />'.$visactions->{'take'}.'<ul>'. + '<li>'.$visactions->{'dc_setcode'}.'</li>'. + '</ul><br />'); + } + } else { + my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig); + if (ref($visactions) eq 'HASH') { + if (!$visible) { + $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}. + '<br />'); + if (ref($vismsgs) eq 'ARRAY') { + $r->print('<br />'.$visactions->{'take'}.'<ul>'); + foreach my $item (@{$vismsgs}) { + $r->print('<li>'.$visactions->{$item}.'</li>'); + } + $r->print('</ul>'); } - $r->print('</ul>'); + $r->print($cansetvis); } - $r->print($cansetvis); } } return; } -sub get_selfenroll_titles { - 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); -} - #---------------------------------------------- end functions for &phase_two #--------------------------------- functions for &phase_two and &phase_three